Skip to content

Commit b9ecea2

Browse files
dwijnandsmarter
andcommitted
Avoid generating skolems just to return true
Co-authored-by: Guillaume Martres <[email protected]>
1 parent 404d53c commit b9ecea2

File tree

3 files changed

+7
-24
lines changed

3 files changed

+7
-24
lines changed

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

-14
Original file line numberDiff line numberDiff line change
@@ -1731,20 +1731,6 @@ class Definitions {
17311731
else sys.error(s"Not a primitive value type: $tp")
17321732
}.typeRef
17331733

1734-
def unboxedType(tp: Type)(using Context): TypeRef = {
1735-
val cls = tp.classSymbol
1736-
if (cls eq BoxedByteClass) ByteType
1737-
else if (cls eq BoxedShortClass) ShortType
1738-
else if (cls eq BoxedCharClass) CharType
1739-
else if (cls eq BoxedIntClass) IntType
1740-
else if (cls eq BoxedLongClass) LongType
1741-
else if (cls eq BoxedFloatClass) FloatType
1742-
else if (cls eq BoxedDoubleClass) DoubleType
1743-
else if (cls eq BoxedUnitClass) UnitType
1744-
else if (cls eq BoxedBooleanClass) BooleanType
1745-
else sys.error(s"Not a boxed primitive value type: $tp")
1746-
}
1747-
17481734
/** The JVM tag for `tp` if it's a primitive, `java.lang.Object` otherwise. */
17491735
def typeTag(tp: Type)(using Context): Name = typeTags(scalaClassName(tp))
17501736

compiler/src/dotty/tools/dotc/transform/patmat/Space.scala

+5-8
Original file line numberDiff line numberDiff line change
@@ -512,18 +512,15 @@ class SpaceEngine(using Context) extends SpaceLogic {
512512
if converted == null then tp else ConstantType(converted)
513513
case _ => tp
514514

515-
def adaptType(tp1: Type, tp2: Type): Type = trace(i"adaptType($tp1, $tp2)", show = true) {
516-
def isPrimToBox(tp: Type, pt: Type) =
517-
tp.classSymbol.isPrimitiveValueClass && (defn.boxedType(tp).classSymbol eq pt.classSymbol)
518-
if isPrimToBox(tp1, tp2) then defn.boxedType(tp1).narrow // 1 <:< Integer => (<skolem> : Integer) <:< Integer = true
519-
else if isPrimToBox(tp2, tp1) then defn.unboxedType(tp1).narrow // ONE <:< Int => (<skolem> : Int) <:< Int = true
520-
else convertConstantType(tp1, tp2)
521-
}
515+
def isPrimToBox(tp: Type, pt: Type) =
516+
tp.classSymbol.isPrimitiveValueClass && (defn.boxedType(tp).classSymbol eq pt.classSymbol)
522517

523518
/** Is `tp1` a subtype of `tp2`? */
524519
def isSubType(tp1: Type, tp2: Type): Boolean = trace(i"$tp1 <:< $tp2", debug, show = true) {
525520
if tp1 == constantNullType && !ctx.explicitNulls then tp2 == constantNullType
526-
else adaptType(tp1, tp2) <:< tp2
521+
else
522+
isPrimToBox(tp1, tp2) || isPrimToBox(tp2, tp1) ||
523+
convertConstantType(tp1, tp2) <:< tp2
527524
}
528525

529526
def isSameUnapply(tp1: TermRef, tp2: TermRef): Boolean =

compiler/test/dotty/tools/dotc/transform/SpaceEngineTest.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ class SpaceEngineTest extends DottyTest:
1515

1616
val BoxedIntType = BoxedIntClass.typeRef
1717

18-
assertEquals(BoxedIntType, e.adaptType(IntType, BoxedIntType).widenSingleton)
19-
assertEquals(IntType, e.adaptType(BoxedIntType, IntType).widenSingleton)
18+
assertTrue(e.isPrimToBox(IntType, BoxedIntType))
19+
assertFalse(e.isPrimToBox(BoxedIntType, IntType))

0 commit comments

Comments
 (0)