Skip to content

Commit a24fb91

Browse files
committed
Print subcapturing steps in -explain traces
1 parent e0427ff commit a24fb91

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

compiler/src/dotty/tools/dotc/cc/CaptureSet.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,9 @@ object CaptureSet:
343343
opaque type Type = CaptureSet
344344
val OK: Type = Const(emptySet)
345345
def fail(cs: CaptureSet): Type = cs
346-
extension (result: Type) def blocking: CaptureSet = result
346+
extension (result: Type)
347+
def blocking: CaptureSet = result
348+
def show: String = if result == OK then "OK" else result.toString
347349

348350
class VarState:
349351
private val elemsMap: util.EqHashMap[Var, Refs] = new util.EqHashMap

compiler/src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
491491
// under -Ycheck. Test case is i7965.scala.
492492

493493
case CapturingType(parent1, refs1, _) =>
494-
if refs1.subCaptures(tp2.captureSet, frozenConstraint) == CaptureSet.CompareResult.OK then
494+
if subCaptures(refs1, tp2.captureSet, frozenConstraint) == CaptureSet.CompareResult.OK then
495495
recur(parent1, tp2)
496496
else
497497
thirdTry
@@ -2396,7 +2396,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
23962396
case tp1: TypeVar if tp1.isInstantiated =>
23972397
tp1.underlying & tp2
23982398
case CapturingType(parent1, refs1, _) =>
2399-
if tp2.captureSet.subCaptures(refs1, frozenConstraint) == CaptureSet.CompareResult.OK then
2399+
if subCaptures(tp2.captureSet, refs1, frozenConstraint) == CaptureSet.CompareResult.OK then
24002400
parent1 & tp2
24012401
else
24022402
tp1.derivedCapturingType(parent1 & tp2, refs1)
@@ -2462,6 +2462,9 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
24622462
false
24632463
}
24642464

2465+
protected def subCaptures(refs1: CaptureSet, refs2: CaptureSet, frozen: Boolean)(using Context): CaptureSet.CompareResult.Type =
2466+
refs1.subCaptures(refs2, frozen)
2467+
24652468
// ----------- Diagnostics --------------------------------------------------
24662469

24672470
/** A hook for showing subtype traces. Overridden in ExplainingTypeComparer */
@@ -2730,6 +2733,7 @@ object TypeComparer {
27302733
else res match
27312734
case ClassInfo(_, cls, _, _, _) => cls.showLocated
27322735
case bounds: TypeBounds => i"type bounds [$bounds]"
2736+
case CaptureSet.CompareResult.OK => "OK"
27332737
case res: printing.Showable => res.show
27342738
case _ => String.valueOf(res)
27352739

@@ -3059,5 +3063,10 @@ class ExplainingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
30593063
super.addConstraint(param, bound, fromBelow)
30603064
}
30613065

3066+
override def subCaptures(refs1: CaptureSet, refs2: CaptureSet, frozen: Boolean)(using Context): CaptureSet.CompareResult.Type =
3067+
traceIndented(i"subcaptures $refs1 <:< $refs2 ${if frozen then "frozen" else ""}") {
3068+
super.subCaptures(refs1, refs2, frozen)
3069+
}
3070+
30623071
def lastTrace(header: String): String = header + { try b.toString finally b.clear() }
30633072
}

0 commit comments

Comments
 (0)