Skip to content

Commit 2a27986

Browse files
committed
feat: add congrConsts
1 parent 5ea3afe commit 2a27986

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

src/Init/MetaTypes.lean

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,15 +240,23 @@ structure Config where
240240
-/
241241
implicitDefEqProofs : Bool := true
242242
/--
243-
When `true` (default : `true`), then simps will remove unused let-declarations:
243+
When `true` (default : `true`), `simp` removes unused let-declarations:
244244
`let x := v; e` simplifies to `e` when `x` does not occur in `e`.
245245
-/
246246
zetaUnused : Bool := true
247247
/--
248-
When `true` (default : `true`), then simps will catch runtime exceptions and
249-
convert them into `simp` exceptions.
248+
When `true` (default : `true`), `simp` catches runtime exceptions and
249+
converts them into `simp` exceptions.
250250
-/
251251
catchRuntime : Bool := true
252+
/--
253+
When `true` (default : `true`), `simp` tries to realize constant `f.congr_simp`
254+
when constructing an auxiliary congruence proof for `f`.
255+
This option exists because the termination prover uses `simp` and `withoutModifyingEnv`
256+
while constructing the termination proof. Thus, any constant realized by `simp`
257+
is deleted.
258+
-/
259+
congrConsts : Bool := true
252260
deriving Inhabited, BEq
253261

254262
-- Configuration object for `simp_all`

src/Lean/Elab/PreDefinition/WF/Preprocess.lean

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ private def getSimpContext : MetaM Simp.Context := do
7373
Simp.mkContext
7474
(simpTheorems := #[simpTheorems])
7575
(congrTheorems := {})
76-
(config := { Simp.neutralConfig with dsimp := true })
76+
-- Remark: we use `congrConsts` because this module uses `withoutModifyingEnv`
77+
-- which would erase any congruence lemmas realized in the `withoutModifyingEnv` block.
78+
(config := { Simp.neutralConfig with dsimp := true, congrConsts := false })
7779

7880
def isWfParam? (e : Expr) : Option Expr :=
7981
if e.isAppOfArity ``wfParam 2 then

src/Lean/Meta/Tactic/Simp/Types.lean

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,9 @@ def mkCongrSimp? (f : Expr) : SimpM (Option CongrTheorem) := do
650650
match (← get).congrCache[f]? with
651651
| some thm? => return thm?
652652
| none =>
653-
let thm? ← if let .const declName us := f then
653+
let thm? ← if !(← getConfig).congrConsts then
654+
mkCongrSimpCore? f info kinds
655+
else if let .const declName us := f then
654656
mkCongrSimpForConst? declName us
655657
else
656658
mkCongrSimpCore? f info kinds

0 commit comments

Comments
 (0)