`noncomputable` error on definitions without data
Nobody has claimed this yet.
- Dominant language
- Lean
- Stars
- 9.2k
- Forks
- 990
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 175
Description
Prerequisites
- 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
The error lean.dependsOnNoncomputable is thrown on definitions of a type whose elements contain no data at runtime. For example, def setoid : Setoid Nat := Classical.choice ⟨Setoid.trivial Nat⟩ fails, even though elements of Setoid Nat consist of a pair r : Nat → Nat → Prop which is a predicate and so is erased a runtime and a iseqv : Equivalence r which is a proof and so is also erased at runtime.
Context
I encountered this error after upgrading my Setoid theorems from an earlier version of Lean. See Zulip.
Steps to Reproduce
def prop : Prop := Classical.choice ⟨True⟩
def subtype : { p : Prop // p } := Classical.choice ⟨⟨True, trivial⟩⟩
def setoid : Setoid Nat := Classical.choice ⟨Setoid.trivial Nat⟩
def unit : Unit := Classical.choice ⟨()⟩
Expected behavior: prop, subtype, setoid, and unit will behave similarly, since their types do not contain any data at runtime
Actual behavior: only prop is fine, but the other three throw "error: Classical.choice not supported by code generator; consider marking definition as noncomputable"
Versions
I tested versions v4.31.0, v4.30.0, v.4.29.0, ..., v4.17.0
propworks on all the versions I testedsubtypefails on v4.21.0 and below but works on v4.22.0 up to v4.28.0 and fails on v4.29.0 and abovesetoidfails on all the versions I testedunitfails on all the versions I tested
Target: x86_64-w64-windows-gnu Windows
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 four minimal definitions in the issue and reproduce the Classical.choice code-generation errors on the current Lean version, comparing prop, subtype, setoid, and unit. Trace the compiler's treatment of erased predicates, proofs, and data-free types; done means these definitions receive consistent behavior without incorrectly requiring noncomputable.
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
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100