Skip to content

Commit

Permalink
feat: allow users to disable simpCtorEq simproc
Browse files Browse the repository at this point in the history
The simproc is renamed to `reduceCtorEq`.

closes #5046
  • Loading branch information
leodemoura committed Aug 26, 2024
1 parent b54a9ec commit 51f81fa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
11 changes: 11 additions & 0 deletions src/Lean/Meta/Tactic/Simp/BuiltinSimprocs/Core.lean
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,14 @@ builtin_dsimproc ↓ [simp, seval] dreduceDIte (dite _ _ _) := fun e => do
| Decidable.isFalse _ h => return .visit (mkApp eb h).headBeta
| _ => return .continue
return .continue

builtin_simproc [simp, seval] reduceCtorEq (_ = _) := fun e => withReducibleAndInstances do
let_expr Eq _ lhs rhs ← e | return .continue
match (← constructorApp'? lhs), (← constructorApp'? rhs) with
| some (c₁, _), some (c₂, _) =>
if c₁.name != c₂.name then
withLocalDeclD `h e fun h =>
return .done { expr := mkConst ``False, proof? := (← withDefault <| mkEqFalse' (← mkLambdaFVars #[h] (← mkNoConfusion (mkConst ``False) h))) }
else
return .continue
| _, _ => return .continue
17 changes: 1 addition & 16 deletions src/Lean/Meta/Tactic/Simp/Rewrite.lean
Original file line number Diff line number Diff line change
Expand Up @@ -255,19 +255,6 @@ where
inErasedSet (thm : SimpTheorem) : Bool :=
erased.contains thm.origin

def simpCtorEq : Simproc := fun e => withReducibleAndInstances do
match e.eq? with
| none => return .continue
| some (_, lhs, rhs) =>
match (← constructorApp'? lhs), (← constructorApp'? rhs) with
| some (c₁, _), some (c₂, _) =>
if c₁.name != c₂.name then
withLocalDeclD `h e fun h =>
return .done { expr := mkConst ``False, proof? := (← withDefault <| mkEqFalse' (← mkLambdaFVars #[h] (← mkNoConfusion (mkConst ``False) h))) }
else
return .continue
| _, _ => return .continue

@[inline] def simpUsingDecide : Simproc := fun e => do
unless (← getConfig).decide do
return .continue
Expand Down Expand Up @@ -446,8 +433,7 @@ partial def preSEval (s : SimprocsArray) : Simproc :=
def postSEval (s : SimprocsArray) : Simproc :=
rewritePost >>
userPostSimprocs s >>
sevalGround >>
simpCtorEq
sevalGround

def mkSEvalMethods : CoreM Methods := do
let s ← getSEvalSimprocs
Expand Down Expand Up @@ -515,7 +501,6 @@ def postDefault (s : SimprocsArray) : Simproc :=
userPostSimprocs s >>
simpGround >>
simpArith >>
simpCtorEq >>
simpUsingDecide

/--
Expand Down

0 comments on commit 51f81fa

Please sign in to comment.