leanprover-community / leanprover-community/repl

Lean Repl unable to run with canonical

Open
#115 16 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Lean
Stars
228
Forks
69
Avg merge
15m
Merged PRs (30d)
4

Description

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)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the canonical_repl_broken_mwe.py reproduction and run the lake exe repl command with its --load-dynlib argument. Investigate the native implementation lookup for the imported Canonical tactic; done means the tactic runs in the REPL without an exception and the Python client receives valid JSON.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli, devtools, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.