Skip to content

Commit

Permalink
Perform subtype comparisons in same order as before.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
odersky committed Jun 30, 2022
1 parent 2165c4f commit e8d4fcd
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1566,9 +1566,9 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
&& defn.isByNameFunction(arg2.dealias) =>
isSubArg(arg1res, arg2.argInfos.head)
case _ =>
if v > 0 then isSubType(arg1, arg2)
else if v < 0 then isSubType(arg2, arg1)
else isSameType(arg1, arg2)
if v < 0 then isSubType(arg2, arg1)
else if v > 0 then isSubType(arg1, arg2)
else isSameType(arg2, arg1)

isSubArg(args1.head, args2.head)
} && recurArgs(args1.tail, args2.tail, tparams2.tail)
Expand Down Expand Up @@ -2034,22 +2034,20 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
def isSameType(tp1: Type, tp2: Type): Boolean =
if tp1 eq NoType then false
else if tp1 eq tp2 then true
else if sames != null && (sames.nn.lookup(tp1) eq tp2) then true
else
sames != null && (sames.nn.lookup(tp1) eq tp2)
|| {
val savedSames = sames
sameLevel += 1
if sameLevel >= startSameTypeTrackingLevel then
Stats.record("cache same type")
sames = new util.EqHashMap()
val res =
try isSubType(tp1, tp2) && isSubType(tp2, tp1)
finally
sameLevel -= 1
sames = savedSames
if res && sames != null then sames.nn(tp2) = tp1
res
}
val savedSames = sames
sameLevel += 1
if sameLevel >= startSameTypeTrackingLevel then
Stats.record("cache same type")
sames = new util.EqHashMap()
val res =
try isSubType(tp1, tp2) && isSubType(tp2, tp1)
finally
sameLevel -= 1
sames = savedSames
if res && sames != null then sames.nn(tp2) = tp1
res

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

Expand Down

0 comments on commit e8d4fcd

Please sign in to comment.