@@ -53,6 +53,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
53
53
needsGc = false
54
54
maxErrorLevel = - 1
55
55
errorNotes = Nil
56
+ logSize = 0
56
57
if Config .checkTypeComparerReset then checkReset()
57
58
58
59
private var pendingSubTypes : util.MutableSet [(Type , Type )] | Null = null
@@ -62,6 +63,9 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
62
63
private var maxErrorLevel : Int = - 1
63
64
protected var errorNotes : List [(Int , ErrorNote )] = Nil
64
65
66
+ private val undoLog = mutable.ArrayBuffer [() => Unit ]()
67
+ private var logSize = 0
68
+
65
69
private var needsGc = false
66
70
67
71
private var canCompareAtoms : Boolean = true // used for internal consistency checking
@@ -1579,15 +1583,25 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
1579
1583
&& tp1.derivesFrom(defn.Caps_CapSet )
1580
1584
&& tp2.derivesFrom(defn.Caps_CapSet )
1581
1585
1586
+ def rollBack (prevSize : Int ): Unit =
1587
+ var i = prevSize
1588
+ while i < undoLog.size do
1589
+ undoLog(i)()
1590
+ i += 1
1591
+ undoLog.takeInPlace(prevSize)
1592
+
1582
1593
// begin recur
1583
1594
if tp2 eq NoType then false
1584
1595
else if tp1 eq tp2 then true
1585
1596
else
1586
1597
val savedCstr = constraint
1587
1598
val savedGadt = ctx.gadt
1599
+ val savedLogSize = logSize
1588
1600
inline def restore () =
1589
1601
state.constraint = savedCstr
1590
1602
ctx.gadtState.restore(savedGadt)
1603
+ if undoLog.size != savedLogSize then
1604
+ rollBack(savedLogSize)
1591
1605
val savedSuccessCount = successCount
1592
1606
try
1593
1607
val result = inNestedLevel :
@@ -2885,6 +2899,9 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
2885
2899
(tp1.isBoxedCapturing == tp2.isBoxedCapturing)
2886
2900
|| refs1.subCaptures(CaptureSet .empty, makeVarState())
2887
2901
2902
+ protected def logUndoAction (action : () => Unit ) =
2903
+ undoLog += action
2904
+
2888
2905
// ----------- Diagnostics --------------------------------------------------
2889
2906
2890
2907
/** A hook for showing subtype traces. Overridden in ExplainingTypeComparer */
@@ -3504,6 +3521,9 @@ object TypeComparer {
3504
3521
def subCaptures (refs1 : CaptureSet , refs2 : CaptureSet , vs : CaptureSet .VarState )(using Context ): Boolean =
3505
3522
comparing(_.subCaptures(refs1, refs2, vs))
3506
3523
3524
+ def logUndoAction (action : () => Unit )(using Context ): Unit =
3525
+ comparer.logUndoAction(action)
3526
+
3507
3527
def inNestedLevel (op : => Boolean )(using Context ): Boolean =
3508
3528
comparer.inNestedLevel(op)
3509
3529
0 commit comments