Skip to content

Commit c75d37f

Browse files
authored
fix: no model-based theory combination on instances (#10314)
This PR skips model based theory combination on instances.
1 parent dd87739 commit c75d37f

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

src/Lean/Meta/Tactic/Grind/MBTC.lean

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ private def mkCandidate (a b : ArgInfo) (i : Nat) : GoalM SplitInfo := do
4747
let eq ← shareCommon (← canon eq)
4848
return .arg a.app b.app i eq (.mbtc a.app b.app i)
4949

50+
/-- Returns `true` if `f` is a type class instance -/
51+
private def isFnInstance (f : Expr) : CoreM Bool := do
52+
let .const declName _ := f | return false
53+
isInstance declName
54+
5055
/-- Model-based theory combination. -/
5156
def mbtc (ctx : MBTC.Context) : GoalM Bool := do
5257
unless (← getConfig).mbtc do return false
@@ -59,22 +64,27 @@ def mbtc (ctx : MBTC.Context) : GoalM Bool := do
5964
if (← isCongrRoot e) then
6065
unless (← ctx.isInterpreted e) do
6166
let f := e.getAppFn
62-
let mut i := 0
63-
for arg in e.getAppArgs do
64-
let some arg ← getRoot? arg | pure ()
65-
if (← ctx.hasTheoryVar arg) then
66-
trace[grind.debug.mbtc] "{arg} @ {f}:{i}"
67-
let argInfo : ArgInfo := { arg, app := e }
68-
if let some otherInfos := map[(f, i)]? then
69-
unless otherInfos.any fun info => isSameExpr arg info.arg do
70-
for otherInfo in otherInfos do
71-
if (← ctx.eqAssignment arg otherInfo.arg) then
72-
if (← hasSameType arg otherInfo.arg) then
73-
candidates := candidates.insert (← mkCandidate argInfo otherInfo i)
74-
map := map.insert (f, i) (argInfo :: otherInfos)
75-
else
76-
map := map.insert (f, i) [argInfo]
77-
i := i + 1
67+
/-
68+
Remark: we ignore type class instances in model-based theory combination.
69+
`grind` treats instances as support elements, and they are handled by the canonicalizer.
70+
-/
71+
unless (← isFnInstance f) do
72+
let mut i := 0
73+
for arg in e.getAppArgs do
74+
let some arg ← getRoot? arg | pure ()
75+
if (← ctx.hasTheoryVar arg) then
76+
trace[grind.debug.mbtc] "{arg} @ {f}:{i}"
77+
let argInfo : ArgInfo := { arg, app := e }
78+
if let some otherInfos := map[(f, i)]? then
79+
unless otherInfos.any fun info => isSameExpr arg info.arg do
80+
for otherInfo in otherInfos do
81+
if (← ctx.eqAssignment arg otherInfo.arg) then
82+
if (← hasSameType arg otherInfo.arg) then
83+
candidates := candidates.insert (← mkCandidate argInfo otherInfo i)
84+
map := map.insert (f, i) (argInfo :: otherInfos)
85+
else
86+
map := map.insert (f, i) [argInfo]
87+
i := i + 1
7888
if candidates.isEmpty then
7989
return false
8090
if (← get).split.num > (← getConfig).splits then

0 commit comments

Comments
 (0)