leanprover / leanprover/lean4

`noncomputable` error on definitions without data

Open
#14,084 1 comment 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P-medium
Dominant language
Lean
Stars
9.2k
Forks
990
Avg merge
1d 17h
Merged PRs (30d)
175

Description

Prerequisites
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

  • prop works on all the versions I tested
  • subtype fails on v4.21.0 and below but works on v4.22.0 up to v4.28.0 and fails on v4.29.0 and above
  • setoid fails on all the versions I tested
  • unit fails 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

Open the contributing guide

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.