lean4-htt/tests/lean/run/issue10678.lean
Leonardo de Moura 4606c35c40
feat: @[instance_reducible] (#12247)
This PR adds the new transparency setting `@[instance_reducible]`. We
used to check whether a declaration had `instance` reducibility by using
the `isInstance` predicate. However, this was not a robust solution
because:

- We have scoped instances, and `isInstance` returns `true` only if the
scope is active.

- We have auxiliary declarations used to construct instances manually,
such as:

```lean
    def lt_wfRel : WellFoundedRelation Nat
```
    
`isInstance` also returns `false` for this kind of declaration.

In both cases, the declaration may be (or may have been) used to
construct an instance, but `isInstance`
returns `false`. Thus, we claim it is a mistake to check the
reducibility status using `isInstance`.
`isInstance` indicates whether a declaration is available for the type
class resolution mechanism,
not its transparency status.

**We are decoupling whether a declaration is available for type class
resolution from its transparency status.**

**Remak**: We need a update stage0 to complete this feature.

---------

Co-authored-by: Sebastian Ullrich <sebasti@nullri.ch>
2026-02-01 03:03:16 +00:00

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

import Lean
namespace A
structure A (α : Type u) where
a : α
deriving Lean.ToExpr, Inhabited
-- same namespace for instance and aux decls
/--
info: @[instance_reducible] def A.instToExprA.{u} : {α : Type u} → [Lean.ToExpr α] → [Lean.ToLevel] → Lean.ToExpr (A α) :=
fun {α} [Lean.ToExpr α] [inst_1 : Lean.ToLevel] =>
{ toExpr := instToExprA.toExpr inst_1, toTypeExpr := (Lean.Expr.const `A.A [Lean.toLevel]).app (Lean.toTypeExpr α) }
-/
#guard_msgs in #print A.instToExprA
/--
info: @[instance_reducible] def A.instInhabitedA.{u_1} : {a : Type u_1} → [Inhabited a] → Inhabited (A a) :=
fun {a} [Inhabited a] => { default := instInhabitedA.default }
-/
#guard_msgs in #print A.instInhabitedA
end A
mutual
inductive B (α : Type u) : Type _ where
| leaf
| mk (a : C α)
deriving Lean.ToExpr, Inhabited
inductive C (α : Type u) : Type _ where
| mk (b : B α)
deriving Lean.ToExpr, Inhabited
end
/--
info: @[instance_reducible] def instToExprB.{u} : {α : Type u} → [Lean.ToExpr α] → [Lean.ToLevel] → Lean.ToExpr (B α) :=
fun {α} [Lean.ToExpr α] [inst_1 : Lean.ToLevel] =>
{ toExpr := instToExprB.toExpr_1 inst_1, toTypeExpr := (Lean.Expr.const `B [Lean.toLevel]).app (Lean.toTypeExpr α) }
-/
#guard_msgs in
#print instToExprB
/--
info: @[instance_reducible] def instToExprC.{u} : {α : Type u} → [Lean.ToExpr α] → [Lean.ToLevel] → Lean.ToExpr (C α) :=
fun {α} [Lean.ToExpr α] [inst_1 : Lean.ToLevel] =>
{ toExpr := instToExprB.toExpr_2 inst_1, toTypeExpr := (Lean.Expr.const `C [Lean.toLevel]).app (Lean.toTypeExpr α) }
-/
#guard_msgs in
#print instToExprC
/--
info: @[instance_reducible] def instInhabitedB.{u_1} : {a : Type u_1} → Inhabited (B a) :=
fun {a} => { default := instInhabitedB.default_1 }
-/
#guard_msgs in
#print instInhabitedB
/--
info: @[instance_reducible] def instInhabitedC.{u_1} : {a : Type u_1} → Inhabited (C a) :=
fun {a} => { default := instInhabitedC.default_1 }
-/
#guard_msgs in
#print instInhabitedC