From 54f10434728a4a88b7dcf986babf68491d269e03 Mon Sep 17 00:00:00 2001 From: odersky Date: Fri, 13 Sep 2024 11:05:21 +0200 Subject: [PATCH] Avoid using ExplainingTypeComparer in regular code The operations of an ExplainingTypeComparer are expensive. So we should only run it when producing an error message. --- .../src/dotty/tools/dotc/core/TypeOps.scala | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/TypeOps.scala b/compiler/src/dotty/tools/dotc/core/TypeOps.scala index 46738dc3a3e1..91378b756e39 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeOps.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeOps.scala @@ -704,20 +704,18 @@ object TypeOps: val hiBound = instantiate(bounds.hi, skolemizedArgTypes) val loBound = instantiate(bounds.lo, skolemizedArgTypes) - def check(tp1: Type, tp2: Type, which: String, bound: Type)(using Context) = { - val isSub = TypeComparer.explaining { cmp => - val isSub = cmp.isSubType(tp1, tp2) - if !isSub then - if !ctx.typerState.constraint.domainLambdas.isEmpty then - typr.println(i"${ctx.typerState.constraint}") - if !ctx.gadt.symbols.isEmpty then - typr.println(i"${ctx.gadt}") - typr.println(cmp.lastTrace(i"checkOverlapsBounds($lo, $hi, $arg, $bounds)($which)")) - //trace.dumpStack() - isSub - }//(using ctx.fresh.setSetting(ctx.settings.verbose, true)) // uncomment to enable moreInfo in ExplainingTypeComparer recur - if !isSub then violations += ((arg, which, bound)) - } + def check(tp1: Type, tp2: Type, which: String, bound: Type)(using Context) = + val isSub = TypeComparer.isSubType(tp1, tp2) + if !isSub then + // inContext(ctx.fresh.setSetting(ctx.settings.verbose, true)): // uncomment to enable moreInfo in ExplainingTypeComparer + TypeComparer.explaining: cmp => + if !ctx.typerState.constraint.domainLambdas.isEmpty then + typr.println(i"${ctx.typerState.constraint}") + if !ctx.gadt.symbols.isEmpty then + typr.println(i"${ctx.gadt}") + typr.println(cmp.lastTrace(i"checkOverlapsBounds($lo, $hi, $arg, $bounds)($which)")) + violations += ((arg, which, bound)) + check(lo, hiBound, "upper", hiBound)(using checkCtx) check(loBound, hi, "lower", loBound)(using checkCtx) }