Skip to content

Commit 2fb548a

Browse files
committed
Revert to keeping approx as TypeComparer state
Passing it as an additional parameter seemed to cause a slight (~2%) performance degradation.
1 parent 4697e49 commit 2fb548a

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

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

+11-4
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,18 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
107107
assert(isSatisfiable, constraint.show)
108108
}
109109

110+
private[this] var approx: ApproxState = NoApprox
111+
protected def approxState = approx
112+
113+
protected def isSubType(tp1: Type, tp2: Type, a: ApproxState): Boolean = {
114+
val saved = approx
115+
this.approx = a
116+
try recur(tp1, tp2) finally this.approx = saved
117+
}
118+
110119
protected def isSubType(tp1: Type, tp2: Type): Boolean = isSubType(tp1, tp2, NoApprox)
111120

112-
protected def isSubType(tp1: Type, tp2: Type, approx: ApproxState): Boolean = trace(s"isSubType ${traceInfo(tp1, tp2)} $approx", subtyping) {
121+
protected def recur(tp1: Type, tp2: Type): Boolean = trace(s"isSubType ${traceInfo(tp1, tp2)} $approx", subtyping) {
113122

114123
def monitoredIsSubType = {
115124
if (pendingSubTypes == null) {
@@ -817,9 +826,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
817826
false
818827
} else isSubType(tp1, tp2, approx.addLow)
819828

820-
def recur(tp1: Type, tp2: Type) = isSubType(tp1, tp2, approx)
821-
822-
// begin isSubType
829+
// begin recur
823830
if (tp2 eq NoType) false
824831
else if (tp1 eq tp2) true
825832
else {

0 commit comments

Comments
 (0)