The compiler tries to generate code for `let rec`s inside a proof
Nobody has claimed this yet.
- Dominant language
- Lean
- Stars
- 9.2k
- Forks
- 990
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 175
Description
Prerequisites
Please put an X between the brackets as you perform the following steps:
- Check that your issue is not already filed:
https://github.com/leanprover/lean4/issues - Reduce the issue to a minimal, self-contained, reproducible test case.
Avoid dependencies to Mathlib or Batteries. - Test your test case against the latest nightly release, for example on
https://live.lean-lang.org/#project=lean-nightly
(You can also use the settings there to switch to “Lean nightly”)
Description
Declaring a non-computable function within a proof with let rec ends up with an error that the function should be marked noncomputable, but:
- There is no place to mark a
let recasnoncomputable. - There is no point making a
let reccomputable anyway, since we're inside a proof.
Context
This came up in APAP when doing a measure theoretic argument requiring to define a simple function recursively.
Steps to Reproduce
noncomputable def foo (n : Nat) : Nat := n
-- Uncomment the next line to fix
-- noncomputable section
example : True := by
-- Always works fine
let bar : Nat → Nat := foo
-- Works iff `noncomputable section` is uncommented
let rec baz : Nat → Nat
| 0 => 0
| n + 1 => foo n + 1
/-
failed to compile definition, compiler IR check failed at '_example.baz'. Error: depends on declaration 'foo', which has no executable code; consider marking definition as 'noncomputable'
-/
trivial
Expected behavior: The let rec works
Actual behavior: The let rec doesn't work
Additional information
If a variant of #2719 were implemented for noncomputable, then we could work around this issue by using noncomputable let rec instead of let rec.
Versions
Lean 4.18.0
Target: x86_64-unknown-linux-gnu
Impact
Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the minimal reproducer in the issue and inspect the compiler path that emits _example.baz and performs the compiler IR check. Confirm the behavior for a recursive let inside a proof, then verify that the example compiles without requiring a noncomputable section.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100