Skip to content

Commit 817018d

Browse files
committed
Optimizer: Make special subtyping checks for RuntimeLong explicit
To enable the IRChecker, we only want to consider RuntimeLong equivalent to BoxedLong when we'll end up removing that type information from the IR. In practice, this is during instance checks. As a result, we can also see that some of the cases were unnecessary: - The instance checks already handle nullability. - We never emit an instance check for RuntimeLong, so that direction is unnecessary.
1 parent 17380ed commit 817018d

File tree

1 file changed

+11
-22
lines changed

1 file changed

+11
-22
lines changed

linker/shared/src/main/scala/org/scalajs/linker/frontend/optimizer/OptimizerCore.scala

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -272,27 +272,8 @@ private[optimizer] abstract class OptimizerCore(
272272

273273
private val isSubclassFun = isSubclass _
274274

275-
private def isSubtype(lhs: Type, rhs: Type): Boolean = {
276-
assert(lhs != VoidType)
277-
assert(rhs != VoidType)
278-
279-
Types.isSubtype(lhs, rhs)(isSubclassFun) || {
280-
(lhs, rhs) match {
281-
case (LongType, ClassType(LongImpl.RuntimeLongClass, _)) =>
282-
true
283-
case (ClassType(BoxedLongClass, lhsNullable),
284-
ClassType(LongImpl.RuntimeLongClass, rhsNullable)) =>
285-
rhsNullable || !lhsNullable
286-
287-
case (ClassType(LongImpl.RuntimeLongClass, lhsNullable),
288-
ClassType(BoxedLongClass, rhsNullable)) =>
289-
rhsNullable || !lhsNullable
290-
291-
case _ =>
292-
false
293-
}
294-
}
295-
}
275+
private def isSubtype(lhs: Type, rhs: Type): Boolean =
276+
Types.isSubtype(lhs, rhs)(isSubclassFun)
296277

297278
/** Transforms a statement.
298279
*
@@ -564,8 +545,16 @@ private[optimizer] abstract class OptimizerCore(
564545
case IsInstanceOf(expr, testType) =>
565546
trampoline {
566547
pretransformExpr(expr) { texpr =>
548+
val texprType = texpr.tpe.base.toNonNullable
549+
550+
val staticSubtype = isSubtype(texprType, testType) || {
551+
useRuntimeLong &&
552+
texprType == ClassType(LongImpl.RuntimeLongClass, false) &&
553+
testType == ClassType(BoxedLongClass, false)
554+
}
555+
567556
val result = {
568-
if (isSubtype(texpr.tpe.base.toNonNullable, testType)) {
557+
if (staticSubtype) {
569558
if (texpr.tpe.isNullable)
570559
BinaryOp(BinaryOp.!==, finishTransformExpr(texpr), Null())
571560
else

0 commit comments

Comments
 (0)