Skip to content

Commit 601d72c

Browse files
committed
The change to do compareAlias early caused a dramatic slowdown of compilation
compileStdLib went from 45 sec to 230 sec. The problem were many redundant tests when every member of an alias chain was compared to every other. The new scheme follows alias chains to their end before doing anything else.
1 parent 2bb73c3 commit 601d72c

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

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

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -140,35 +140,35 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
140140

141141
private def firstTry(tp1: Type, tp2: Type): Boolean = tp2 match {
142142
case tp2: NamedType =>
143-
def compareAlias(info1: Type) = tp2.info match {
144-
case info2: TypeAlias => isSubType(tp1, info2.alias)
145-
case _ => info1 match {
146-
case info1: TypeAlias => isSubType(info1.alias, tp2)
147-
case _ => false
148-
}
149-
}
150143
def compareNamed = {
151-
implicit val ctx: Context = this.ctx // Dotty deviation: implicits need explicit type
152-
tp1 match {
153-
case tp1: NamedType =>
154-
val sym1 = tp1.symbol
155-
compareAlias(tp1.info) ||
156-
(if ((sym1 ne NoSymbol) && (sym1 eq tp2.symbol))
157-
ctx.erasedTypes || sym1.isStaticOwner || isSubType(tp1.prefix, tp2.prefix)
158-
else
159-
(tp1.name eq tp2.name) &&
160-
isSubType(tp1.prefix, tp2.prefix) &&
161-
(tp1.signature == tp2.signature) &&
162-
!tp1.isInstanceOf[WithFixedSym] &&
163-
!tp2.isInstanceOf[WithFixedSym]
164-
) ||
165-
compareHK(tp1, tp2, inOrder = true) ||
166-
compareHK(tp2, tp1, inOrder = false) ||
167-
thirdTryNamed(tp1, tp2)
168-
case _ =>
169-
compareHK(tp2, tp1, inOrder = false) ||
170-
compareAlias(NoType) ||
171-
secondTry(tp1, tp2)
144+
implicit val ctx: Context = this.ctx
145+
tp2.info match {
146+
case info2: TypeAlias => firstTry(tp1, info2.alias)
147+
case _ => tp1 match {
148+
case tp1: NamedType =>
149+
tp1.info match {
150+
case info1: TypeAlias => firstTry(info1.alias, tp2)
151+
case _ =>
152+
val sym1 = tp1.symbol
153+
(if ((sym1 ne NoSymbol) && (sym1 eq tp2.symbol))
154+
ctx.erasedTypes ||
155+
sym1.isStaticOwner ||
156+
isSubType(tp1.prefix, tp2.prefix) ||
157+
thirdTryNamed(tp1, tp2)
158+
else
159+
(tp1.name eq tp2.name) &&
160+
isSubType(tp1.prefix, tp2.prefix) &&
161+
(tp1.signature == tp2.signature) &&
162+
!tp1.isInstanceOf[WithFixedSym] &&
163+
!tp2.isInstanceOf[WithFixedSym] ||
164+
compareHK(tp1, tp2, inOrder = true) ||
165+
compareHK(tp2, tp1, inOrder = false) ||
166+
thirdTryNamed(tp1, tp2))
167+
}
168+
case _ =>
169+
compareHK(tp2, tp1, inOrder = false) ||
170+
secondTry(tp1, tp2)
171+
}
172172
}
173173
}
174174
compareNamed

0 commit comments

Comments
 (0)