lean4-htt/tests/lean/run/derivingRepr.lean
Leonardo de Moura b668a18a9d
refactor: rename instance_reducible to implicit_reducible (#12567)
This PR renames `instance_reducible` to `implicit_reducible` and adds a
new
`backward.isDefEq.implicitBump` option to prepare for treating all
implicit
arguments uniformly during definitional equality checking.

## Changes

**Rename `instance_reducible` → `implicit_reducible`:**
- Rename `ReducibilityStatus.instanceReducible` constructor to
`implicitReducible`
- Register new `[implicit_reducible]` attribute, keep
`[instance_reducible]` as alias
- Rename `isInstanceReducible` → `isImplicitReducible` (with deprecated
aliases)
- Update all references across src/ and tests/

The rename reflects that this reducibility level is used not just for
instances
but for any definition that needs unfolding during implicit argument
resolution
(e.g., `Nat.add`, `Array.size`).

**Add `backward.isDefEq.implicitBump` option:**
- When `true` (+ `respectTransparency`), bumps transparency to
`.instances` for
ALL implicit arguments in `isDefEqArgs`, not just instance-implicit ones
- Defaults to `false` for staging compatibility — will be flipped to
`true` after
  stage0 update
- Adds `// update me!` to `stage0/src/stdlib_flags.h` to trigger CI
stage0 update

## Follow-up (after stage0 update)
- Flip `backward.isDefEq.implicitBump` default to `true`
- Fix resulting test/module failures

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 22:19:16 +00:00

154 lines
3.6 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.

module
public section
structure Foo where
name : String
val : List Nat
lower : Nat := List.length val
inv : val.length >= lower
flag : Bool
deriving Repr
/--
info: { name := "Joe",
val := [40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14,
13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],
lower := 40,
inv := _,
flag := true }
-/
#guard_msgs in
#eval { name := "Joe", val := (List.range' 1 40).reverse, flag := true, inv := by decide : Foo }
inductive Tree (α : Type) where
| node : List (Tree α) → Bool → Tree α
| leaf : α → Tree α
deriving Repr
/--
info: Tree.node
[Tree.node [Tree.leaf 10] true,
Tree.node [Tree.leaf 9] false,
Tree.node [Tree.leaf 8] true,
Tree.node [Tree.leaf 7] false,
Tree.node [Tree.leaf 6] true,
Tree.node [Tree.leaf 5] false,
Tree.node [Tree.leaf 4] true,
Tree.node [Tree.leaf 3] false,
Tree.node [Tree.leaf 2] true,
Tree.node [Tree.leaf 1] false]
true
-/
#guard_msgs in
#eval Tree.node ((List.range' 1 10).reverse |>.map fun i => Tree.node [Tree.leaf i] (i%2==0)) true
inductive StructureLikeInductive where
| field : Nat -> StructureLikeInductive
deriving Repr
/-- info: StructureLikeInductive.field 5 -/
#guard_msgs in
#eval StructureLikeInductive.field 5
namespace Foo
mutual
inductive Tree (α : Type u) where
| node : TreeList α → Tree α
| leaf : α → Tree α
deriving Repr
inductive TreeList (α : Type u) where
| nil : TreeList α
| cons : Tree α → TreeList α → TreeList α
deriving Repr
end
/--
info: Foo.Tree.node
(Foo.TreeList.cons
(Foo.Tree.leaf 30)
(Foo.TreeList.cons (Foo.Tree.leaf 20) (Foo.TreeList.cons (Foo.Tree.leaf 10) (Foo.TreeList.nil))))
-/
#guard_msgs in
#eval Tree.node (TreeList.cons (Tree.leaf 30) (TreeList.cons (Tree.leaf 20) (TreeList.cons (Tree.leaf 10) TreeList.nil)))
end Foo
/-!
Check that types and proofs are erased for both `inductive` and `structure`.
-/
inductive test1 : Type 1 where
| wrap : Type → 2 < 3 → test1
deriving Repr
structure test2 : Type 1 where
ty : Type
wrap : 2 < 3
deriving Repr
/-- info: test1.wrap _ _ -/
#guard_msgs in #eval test1.wrap Nat (by simp)
/-- info: { ty := _, wrap := _ } -/
#guard_msgs in #eval test2.mk Nat (by simp)
/-!
Indices promoted to parameters are still explicit. Need to include them as arguments.
-/
inductive Promote : (loc : Int) -> (state : Nat) -> Type where
| mk : (loc : Int) -> (state : Nat) -> (id : Nat) -> Promote loc state
deriving Repr
/-- info: Promote.mk 3 2 1 -/
#guard_msgs in #eval Promote.mk 3 2 1
/-!
Promoted indices that are types are represented as `_`.
-/
inductive Promote2 : Type → Type where
| mk : (α : Type) → Promote2 α
deriving Repr
/-- info: Promote2.mk _ -/
#guard_msgs in #eval Promote2.mk Nat
/-! Private fields should yield public, no-expose instances. -/
structure PrivField where
private a : Nat
deriving Repr
/-- info: fun a => instReprPrivField.repr a 0 -/
#guard_msgs in
#with_exporting
#reduce fun (a : PrivField) => repr a
end
-- Try again without `public section`
public structure PrivField2 where
private a : Nat
deriving Repr
/-- info: fun a => instReprPrivField2.repr a 0 -/
#guard_msgs in
#with_exporting
#reduce fun (a : PrivField2) => repr a
/-! Public structures should yield public instances independent of `public section`. -/
public structure Public where
deriving Repr
/--
info: @[implicit_reducible, expose] def instReprPublic : Repr Public :=
{ reprPrec := instReprPublic.repr }
-/
#guard_msgs in
#with_exporting
#print instReprPublic