Skip to content

Commit e8d4fcd

Browse files
committed
Perform subtype comparisons in same order as before.
Interestingly, swapping the order in which argument subtypes were tested in `isSubArg` caused one exhaustivity failure (patmat/i9631.scala) and one failed compile in the community build (libretto). We should find out why at some point, when we have the time.
1 parent 2165c4f commit e8d4fcd

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

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

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,9 +1566,9 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
15661566
&& defn.isByNameFunction(arg2.dealias) =>
15671567
isSubArg(arg1res, arg2.argInfos.head)
15681568
case _ =>
1569-
if v > 0 then isSubType(arg1, arg2)
1570-
else if v < 0 then isSubType(arg2, arg1)
1571-
else isSameType(arg1, arg2)
1569+
if v < 0 then isSubType(arg2, arg1)
1570+
else if v > 0 then isSubType(arg1, arg2)
1571+
else isSameType(arg2, arg1)
15721572

15731573
isSubArg(args1.head, args2.head)
15741574
} && recurArgs(args1.tail, args2.tail, tparams2.tail)
@@ -2034,22 +2034,20 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
20342034
def isSameType(tp1: Type, tp2: Type): Boolean =
20352035
if tp1 eq NoType then false
20362036
else if tp1 eq tp2 then true
2037+
else if sames != null && (sames.nn.lookup(tp1) eq tp2) then true
20372038
else
2038-
sames != null && (sames.nn.lookup(tp1) eq tp2)
2039-
|| {
2040-
val savedSames = sames
2041-
sameLevel += 1
2042-
if sameLevel >= startSameTypeTrackingLevel then
2043-
Stats.record("cache same type")
2044-
sames = new util.EqHashMap()
2045-
val res =
2046-
try isSubType(tp1, tp2) && isSubType(tp2, tp1)
2047-
finally
2048-
sameLevel -= 1
2049-
sames = savedSames
2050-
if res && sames != null then sames.nn(tp2) = tp1
2051-
res
2052-
}
2039+
val savedSames = sames
2040+
sameLevel += 1
2041+
if sameLevel >= startSameTypeTrackingLevel then
2042+
Stats.record("cache same type")
2043+
sames = new util.EqHashMap()
2044+
val res =
2045+
try isSubType(tp1, tp2) && isSubType(tp2, tp1)
2046+
finally
2047+
sameLevel -= 1
2048+
sames = savedSames
2049+
if res && sames != null then sames.nn(tp2) = tp1
2050+
res
20532051

20542052
override protected def isSame(tp1: Type, tp2: Type)(using Context): Boolean = isSameType(tp1, tp2)
20552053

0 commit comments

Comments
 (0)