lean4-htt/tests/lean/run/usesOfNoncomputable.lean
Sebastian Ullrich 85341d02ac
feat: immediate noncomputable check (#12028)
This PR gives a simpler semantics to `noncomputable`, improving
predictability as well as preparing codegen to be moved into a separate
build step without breaking immediate generation of error messages.

Specifically, `noncomputable` is now needed whenever an axiom or another
`noncomputable` def is used by a def except for the following special
cases:
* uses inside proofs, types, type formers, and constructor arguments
corresponding to (fixed) inductive parameters are ignored
* uses of functions marked `@[extern]/@[implemented_by]/@[csimp]` are
ignored
* for applications of a function marked `@[macro_inline]`,
noncomputability of the inlining is instead inspected

# Breaking change

After this change, more `noncomputable` annotations than before may be
required in exchange for improved future stability.
2026-01-30 16:07:25 +00:00

69 lines
1.9 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

noncomputable def badPair : Nat × (Nat × Nat) := ⟨1, ⟨2, 3⟩⟩
noncomputable def badFun (a : Nat) : Nat := a
structure S (n : Nat)
structure T where
n : Nat
def test1 : S badPair.2.1 := {}
/--
error: failed to compile definition, consider marking it as 'noncomputable' because it depends on 'badPair', which is 'noncomputable'
-/
#guard_msgs in
def test2 : T := { n := badPair.2.1 }
def test3 (a : Nat) : S (badFun a) := {}
def test4 (a : Nat) : S ((badFun a) + 1) := {}
/--
error: failed to compile definition, consider marking it as 'noncomputable' because it depends on 'badFun', which is 'noncomputable'
-/
#guard_msgs in
def test5 (a : Nat) : T := { n := badFun a }
/--
error: failed to compile definition, consider marking it as 'noncomputable' because it depends on 'badFun', which is 'noncomputable'
-/
#guard_msgs in
def test6 (a : Nat) : T := { n := 2 * (badFun a) }
structure U (a : Nat × Nat)
structure V where
a : Nat × Nat
def test7 (a : Nat) : U (⟨badFun a, 0⟩) := {}
def test8 (a : Nat) : U ((V.mk ⟨badFun a, 1⟩).a) := {}
/--
error: failed to compile definition, consider marking it as 'noncomputable' because it depends on 'badFun', which is 'noncomputable'
-/
#guard_msgs in
def test9 (a : Nat) : V := ⟨a, badFun a⟩
universe u
def Erased (α : Sort u) : Sort max 1 u :=
{ s : α → Prop // ∃ a, (a = ·) = s }
@[macro_inline] def Erased.mk {α} (a : α) : Erased α :=
⟨fun b => a = b, a, rfl⟩
noncomputable def Erased.out {α} : Erased αα
| ⟨_, h⟩ => Classical.choose h
structure Foo where
spec : Erased Nat
data : Nat
def test10 : Foo where
spec := Erased.mk (Erased.mk 0).out
data := 0
/--
error: failed to compile definition, consider marking it as 'noncomputable' because it depends on 'Erased.out', which is 'noncomputable'
-/
#guard_msgs in
def test11 : Foo where
spec := Erased.mk 0
data := (Erased.mk 0).out