lean4-htt/tests/lean/run/test_proj_hints.lean
Leonardo de Moura c2ec2ecab1
fix: handle class projections in isNonTrivialRegular for backward.whnf.reducibleClassField (#12639)
This PR fixes the interaction between
`backward.whnf.reducibleClassField` and `isDefEqDelta`'s
argument-comparison heuristic.

When `backward.whnf.reducibleClassField` is enabled, `unfoldDefault`
reduces class field projections past the `.proj` form at `.instances`
transparency. This causes `isDefEqDelta` to lose the instance structure
that `isDefEqProj` needs to bump transparency for instance-implicit
parameters. The fix adds an `.abbrev` branch in `isNonTrivialRegular`
that classifies class field projections as nontrivial when the option is
enabled, so `tryHeuristic` applies the argument-comparison heuristic
(with the correct transparency bump) instead of unfolding.

Key insight: all projection functions receive `.abbrev` kernel hints
(not `.regular`), regardless of their reducibility status. Structure
projections default to `.reducible` status, while class projections
default to `.semireducible` status. The old code only handled the
`.regular` case and treated everything else (including `.abbrev`) as
trivial.

Also fixes two minor comment issues in `tryHeuristic`: "non-trivial
regular definition" → "non-trivial definition" (since `.abbrev`
definitions can now be nontrivial too), and "when `f` is not simple" →
"when `f` is simple" (logic inversion in the original comment).

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

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 21:20:33 +00:00

48 lines
1.5 KiB
Text

import Lean
/-!
# Test: projection functions have `.abbrev` kernel hints
All projection functions receive `.abbrev` kernel hints at creation time.
Structure projections default to `.reducible` status, while class projections
default to `.semireducible` status. The `@[reducible]` attribute changes the
reducibility status but does **not** change the kernel hint.
These properties are relied upon by `isNonTrivialRegular` in `ExprDefEq.lean`.
That function uses the `.abbrev` branch to detect class projections and treat
them as nontrivial when `backward.whnf.reducibleClassField` is enabled, so that
`tryHeuristic` applies the argument-comparison heuristic (with the correct
transparency bump for instance-implicit parameters) instead of unfolding past
the `.proj` form. If the kernel hints or default reducibility status for
projections change, `isNonTrivialRegular` must be updated accordingly.
-/
structure Y where
x : Nat
class X where
x : Nat
open Lean
deriving instance Repr for ReducibilityHints
def showHintAndReduceAttr (declName : Name) : CoreM Unit := do
let info ← getConstInfo declName
IO.println (repr info.hints)
IO.println (repr (← getReducibilityStatus declName))
-- Structure projection: `.abbrev` hint, `.reducible` status
/--
info: Lean.ReducibilityHints.abbrev
Lean.ReducibilityStatus.reducible
-/
#guard_msgs in
#eval showHintAndReduceAttr ``Y.x
-- Class projection: `.abbrev` hint, `.semireducible` status
/--
info: Lean.ReducibilityHints.abbrev
Lean.ReducibilityStatus.semireducible
-/
#guard_msgs in
#eval showHintAndReduceAttr ``X.x