fix: interaction between simp and backward.whnf.reducibleClassField (#12622)

This PR fixes a bug where `simp` made no progress on class projection
reductions when `backward.whnf.reducibleClassField` is `true`.

- In `reduceProjFn?`, for class projections applied to constructor
instances (`Class.projFn (Class.mk ...)`), the code called
`reduceProjCont? (← unfoldDefinitionAny? e)`. The helper
`reduceProjCont?` expects the unfolded result to have a `.proj` head so
it can apply `reduceProj?`. However, when `reducibleClassField` is
enabled, `unfoldDefault` in WHNF.lean already reduces the `.proj` node
during unfolding, so `reduceProjCont?` discards the fully-reduced
result.
- The fix uses `unfoldDefinitionAny?` directly, bypassing
`reduceProjCont?`. The dsimp traversal revisits the result (via
`.visit`) and handles any remaining `.proj` nodes naturally.

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

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Leonardo de Moura 2026-02-20 08:37:11 -08:00 committed by GitHub
parent 0520de7374
commit 73751bbb27
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 1 deletions

View file

@ -109,7 +109,17 @@ private def reduceProjFn? (e : Expr) : SimpM (Option Expr) := do
let major := e.getArg! projInfo.numParams
unless (← isConstructorApp major) do
return none
reduceProjCont? (← unfoldDefinitionAny? e)
if backward.whnf.reducibleClassField.get (← getOptions) then
/-
When `backward.whnf.reducibleClassField` is `true`, `unfoldDefault` (in WHNF.lean)
already reduces the `.proj` node during `unfoldDefinitionAny?`, so `reduceProjCont?`
would discard the fully-reduced result because it expects a `.proj` head.
We return the unfolded result directly; the dsimp traversal will revisit it
(via `.visit`) and handle any remaining `.proj` nodes naturally.
-/
unfoldDefinitionAny? e
else
reduceProjCont? (← unfoldDefinitionAny? e)
else
-- `structure` projections
reduceProjCont? (← unfoldDefinition? e)

View file

@ -0,0 +1,9 @@
set_option backward.whnf.reducibleClassField true in
example [Ord α] {a b : α} :
(letI : Ord α := ⟨fun a b => compare b a⟩; compare a b) = compare b a := by
simp only
set_option backward.whnf.reducibleClassField true in
example [Ord α] {a b : α} :
(letI : Ord α := ⟨fun a b => compare b a⟩; compare a b) = compare b a := by
simp