Skip to content

Commit edd40bc

Browse files
committed
Avoid using ExplainingTypeComparer in regular code
The operations of an ExplainingTypeComparer are expensive. So we should only run it when producing an error message.
1 parent 02aae43 commit edd40bc

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

Diff for: compiler/src/dotty/tools/dotc/core/TypeOps.scala

+12-14
Original file line numberDiff line numberDiff line change
@@ -691,20 +691,18 @@ object TypeOps:
691691
val hiBound = instantiate(bounds.hi, skolemizedArgTypes)
692692
val loBound = instantiate(bounds.lo, skolemizedArgTypes)
693693

694-
def check(tp1: Type, tp2: Type, which: String, bound: Type)(using Context) = {
695-
val isSub = TypeComparer.explaining { cmp =>
696-
val isSub = cmp.isSubType(tp1, tp2)
697-
if !isSub then
698-
if !ctx.typerState.constraint.domainLambdas.isEmpty then
699-
typr.println(i"${ctx.typerState.constraint}")
700-
if !ctx.gadt.symbols.isEmpty then
701-
typr.println(i"${ctx.gadt}")
702-
typr.println(cmp.lastTrace(i"checkOverlapsBounds($lo, $hi, $arg, $bounds)($which)"))
703-
//trace.dumpStack()
704-
isSub
705-
}//(using ctx.fresh.setSetting(ctx.settings.verbose, true)) // uncomment to enable moreInfo in ExplainingTypeComparer recur
706-
if !isSub then violations += ((arg, which, bound))
707-
}
694+
def check(tp1: Type, tp2: Type, which: String, bound: Type)(using Context) =
695+
val isSub = TypeComparer.isSubType(tp1, tp2)
696+
if !isSub then
697+
// inContext(ctx.fresh.setSetting(ctx.settings.verbose, true)): // uncomment to enable moreInfo in ExplainingTypeComparer
698+
TypeComparer.explaining: cmp =>
699+
if !ctx.typerState.constraint.domainLambdas.isEmpty then
700+
typr.println(i"${ctx.typerState.constraint}")
701+
if !ctx.gadt.symbols.isEmpty then
702+
typr.println(i"${ctx.gadt}")
703+
typr.println(cmp.lastTrace(i"checkOverlapsBounds($lo, $hi, $arg, $bounds)($which)"))
704+
violations += ((arg, which, bound))
705+
708706
check(lo, hiBound, "upper", hiBound)(using checkCtx)
709707
check(loBound, hi, "lower", loBound)(using checkCtx)
710708
}

0 commit comments

Comments
 (0)