Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 474d6bb

Browse files
committed
Fix #5231: Partial revert of "Fail if we cannot inline RuntimeLong".
This commit partially reverts 3a253e3. It turns out that an expanded `RuntimeLong` *can* be canceled, in some corner case scenarios. There might be a proper fix to the underlying issue, but in the meantime, let the cancellation happen.
1 parent 07c8a01 commit 474d6bb

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3617,14 +3617,11 @@ private[optimizer] abstract class OptimizerCore(
36173617
implicit val scope = scope1
36183618
val tRef = VarRef(tName)(rtLongClassType)
36193619

3620-
val lo = Apply(ApplyFlags.empty, tRef, MethodIdent(LongImpl.lo), Nil)(IntType)
3621-
val hi = Apply(ApplyFlags.empty, tRef, MethodIdent(LongImpl.hi), Nil)(IntType)
3622-
3623-
pretransformExprs(lo, hi) { (tlo, thi) =>
3624-
inlineClassConstructor(AllocationSite.Anonymous, LongImpl.RuntimeLongClass,
3625-
inlinedRTLongStructure, MethodIdent(LongImpl.initFromParts), List(tlo, thi),
3626-
() => throw new AssertionError(s"rolled-back RuntimeLong inlining at $pos"))(cont1)
3627-
}
3620+
val newTree = New(LongImpl.RuntimeLongClass,
3621+
MethodIdent(LongImpl.initFromParts),
3622+
List(Apply(ApplyFlags.empty, tRef, MethodIdent(LongImpl.lo), Nil)(IntType),
3623+
Apply(ApplyFlags.empty, tRef, MethodIdent(LongImpl.hi), Nil)(IntType)))
3624+
pretransformExpr(newTree)(cont1)
36283625
} (cont)
36293626
}
36303627

test-suite/js/src/test/scala/org/scalajs/testsuite/compiler/OptimizerTest.scala

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,28 @@ class OptimizerTest {
666666

667667
assertTrue(called)
668668
}
669+
670+
@Test def expandedRTAssertionOriginal_Issue5231(): Unit = {
671+
def expandedRTLongBug: (Array[Int], Long) => Long = { (array, z) =>
672+
array.foldRight(z)(_ - _)
673+
}
674+
675+
assertEquals(-3L, expandedRTLongBug(Array(1, 2, 3), 5L))
676+
}
677+
678+
@Test def expandedRTAssertionMinimal_Issue5231(): Unit = {
679+
@noinline def hideLong(x: Long): Long = x
680+
@noinline def hide(x: Any): Any = x
681+
682+
val z0: Long = hideLong(5L)
683+
var i = 0
684+
var z: Any = z0
685+
while (i < 2) {
686+
z = hide(i.toLong)
687+
i += 1
688+
}
689+
assertEquals(1L, z)
690+
}
669691
}
670692

671693
object OptimizerTest {

0 commit comments

Comments
 (0)