Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#eval on let rec causes error in kernel #2374

Closed
1 task done
Vierkantor opened this issue Aug 1, 2023 · 0 comments · Fixed by #5663
Closed
1 task done

#eval on let rec causes error in kernel #2374

Vierkantor opened this issue Aug 1, 2023 · 0 comments · Fixed by #5663

Comments

@Vierkantor
Copy link

Prerequisites

  • Put an X between the brackets on this line if you have done all of the following:
    • Checked that your issue isn't already filed.
    • Reduced the issue to a self-contained, reproducible test case.

Description

Running #eval on an expression that contains a let rec cause the kernel to report an error: "(kernel) declaration has metavariables". I understand the (kernel) in this message indicates a bug where the evaluator sends an incorrect term to the kernel. Ideally evaluation would succeed for these expressions, or failing that, at least the evaluator would report an error instead of the kernel.

It seems the presence of let rec itself is the cause, not actual recursion or even using the let-introduced binding. When the same expression is instead used in the body as a def and then the def is given to #eval, evaluation succeeds. Similarly, when the let rec becomes a simple let, everything works.

Original Zulip thread.

I found a similar but seemingly distinct issue #2071.

Steps to Reproduce

Minimized reproduction:

def foo :=
  let rec bar : Nat := 1
  37
#eval foo -- works, evaluates to 37

#eval -- error: (kernel) declaration has metavariables '_eval'
  let rec bar : Nat := 1
  37

Expected behavior: Both #evals should return 37. Or the error in the kernel reported by the second #eval should become an error in the elaborator.

Actual behavior: Error in the kernel.

Reproduces how often: Always: all occurrences of let rec in #eval I could think of caused this error. Removing the rec keyword causes #eval to succeed.

Versions

$ lean --version
Lean (version 4.0.0-nightly-2023-07-30, commit 2eaa400b8e64, Release)
$ uname -a
Linux vouwvervorming 6.1.35-1-lts #1 SMP PREEMPT_DYNAMIC Wed, 21 Jun 2023 15:54:02 +0000 x86_64 GNU/Linux
kmill added a commit to kmill/lean4 that referenced this issue Oct 9, 2024
Makes `#eval` use the `elabMutualDef` machinery to process all the `let rec`s that might appear in the expression. This now works:
```lean
#eval
  let rec fact (n : Nat) : Nat :=
    match n with
    | 0 => 1
    | n' + 1 => n * fact n'
  fact 5
```

Closes leanprover#2374
kmill added a commit to kmill/lean4 that referenced this issue Oct 9, 2024
Makes `#eval` use the `elabMutualDef` machinery to process all the `let rec`s that might appear in the expression. This now works:
```lean
  let rec fact (n : Nat) : Nat :=
    match n with
    | 0 => 1
    | n' + 1 => n * fact n'
  fact 5
```

Closes leanprover#2374
kmill added a commit to kmill/lean4 that referenced this issue Oct 11, 2024
Makes `#eval` use the `elabMutualDef` machinery to process all the `let rec`s that might appear in the expression. This now works:
```lean
  let rec fact (n : Nat) : Nat :=
    match n with
    | 0 => 1
    | n' + 1 => n * fact n'
  fact 5
```

Closes leanprover#2374
github-merge-queue bot pushed a commit that referenced this issue Oct 11, 2024
Makes `#eval` use the `elabMutualDef` machinery to process all the `let
rec`s that might appear in the expression. This now works:
```lean
#eval
  let rec fact (n : Nat) : Nat :=
    match n with
    | 0 => 1
    | n' + 1 => n * fact n'
  fact 5
```

Closes #2374
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant