Skip to content

Lean Repl unable to run with canonical #115

@FrederickPu

Description

@FrederickPu

I have a lean project that is dependent on both canonical and lean repl. But when I try to call the canonical tactic in lean repl it fails.

import json
import subprocess
import os
import sys
from typing import List, Any

process = subprocess.Popen(
    ["lake", "exe", "repl", "--load-dynlib=./.lake/packages/Canonical/.lake/build/lib/canonical_lean.dll"],
    stdin=subprocess.PIPE,
    stdout=subprocess.PIPE,
    text=True,
    bufsize=1,
    env=os.environ,
)

def send_command(command):
    json_command = json.dumps(command, ensure_ascii=False) + "\n\n"
    process.stdin.write(json_command)
    process.stdin.flush()

    response_lines = []
    while True:
        stdout_line = process.stdout.readline()
        if stdout_line.strip() == "":
            break
        response_lines.append(stdout_line)

    return json.loads("".join(response_lines))

lol = send_command({ "cmd" : "import Canonical\nimport Mathlib\ntheorem womp : (2:Nat) + 2 = 4 := by canonical" })
print(lol)
env_import = lol["env"]
print(env_import)

The above code produces the following error:

{'sorries': [{'proofState': 0, 'pos': {'line': 3, 'column': 37}, 'goal': '⊢ 2 + 2 = 4', 'endPos': {'line': 3, 'column': 42}}], 'messages': [{'severity': 'warning', 'pos': {'line': 3, 'column': 8}, 'endPos': {'line': 3, 'column': 12}, 'data': "declaration uses 'sorry'"}], 'env': 0}
0
PS C:\Users\pufre\Downloads\CodingProjects\CanonicalDrafter> python .\canonical_repl_broken_mwe.py
libc++abi: terminating due to uncaught exception of type lean::exception: Could not find native implementation of external declaration 'Canonical.canonical' (symbols 'l_Canonical_canonical___boxed' or 'l_Canonical_canonical').
For declarations from `Init`, `Std`, or `Lean`, you need to set `supportInterpreter := true` in the relevant `lean_exe` statement in your `lakefile.lean`.
Traceback (most recent call last):
  File "C:\Users\pufre\Downloads\CodingProjects\CanonicalDrafter\canonical_repl_broken_mwe.py", line 30, in <module>
    lol = send_command({ "cmd" : "import Canonical\nimport Mathlib\ntheorem womp : (2:Nat) + 2 = 4 := by canonical" })
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\pufre\Downloads\CodingProjects\CanonicalDrafter\canonical_repl_broken_mwe.py", line 28, in send_command
    return json.loads("".join(response_lines))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\pufre\.pyenv\pyenv-win\versions\3.11.0b4\Lib\json\__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\pufre\.pyenv\pyenv-win\versions\3.11.0b4\Lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\pufre\.pyenv\pyenv-win\versions\3.11.0b4\Lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions