JVM_IR KT-50277 skip temporary var elimination on inline suspend lambda
This commit is contained in:
@@ -637,6 +637,9 @@ internal fun isBeforeFakeContinuationConstructorCallMarker(insn: AbstractInsnNod
|
|||||||
internal fun isAfterFakeContinuationConstructorCallMarker(insn: AbstractInsnNode) =
|
internal fun isAfterFakeContinuationConstructorCallMarker(insn: AbstractInsnNode) =
|
||||||
isSuspendMarker(insn, INLINE_MARKER_AFTER_FAKE_CONTINUATION_CONSTRUCTOR_CALL)
|
isSuspendMarker(insn, INLINE_MARKER_AFTER_FAKE_CONTINUATION_CONSTRUCTOR_CALL)
|
||||||
|
|
||||||
|
internal fun isSuspendInlineMarker(insn: AbstractInsnNode) =
|
||||||
|
isInlineMarker(insn, "mark")
|
||||||
|
|
||||||
private fun isSuspendMarker(insn: AbstractInsnNode, id: Int) =
|
private fun isSuspendMarker(insn: AbstractInsnNode, id: Int) =
|
||||||
isInlineMarker(insn, "mark") && insn.previous.intConstant == id
|
isInlineMarker(insn, "mark") && insn.previous.intConstant == id
|
||||||
|
|
||||||
|
|||||||
+4
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.codegen.optimization.temporaryVals
|
package org.jetbrains.kotlin.codegen.optimization.temporaryVals
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.codegen.inline.isSuspendInlineMarker
|
||||||
import org.jetbrains.kotlin.codegen.optimization.common.InsnSequence
|
import org.jetbrains.kotlin.codegen.optimization.common.InsnSequence
|
||||||
import org.jetbrains.kotlin.codegen.optimization.common.isMeaningful
|
import org.jetbrains.kotlin.codegen.optimization.common.isMeaningful
|
||||||
import org.jetbrains.kotlin.codegen.optimization.common.removeUnusedLocalVariables
|
import org.jetbrains.kotlin.codegen.optimization.common.removeUnusedLocalVariables
|
||||||
@@ -23,6 +24,9 @@ class TemporaryVariablesEliminationTransformer(private val state: GenerationStat
|
|||||||
override fun transform(internalClassName: String, methodNode: MethodNode) {
|
override fun transform(internalClassName: String, methodNode: MethodNode) {
|
||||||
if (!state.isIrBackend) return
|
if (!state.isIrBackend) return
|
||||||
|
|
||||||
|
// If there are any suspend inline markers, don't touch anything now.
|
||||||
|
if (methodNode.instructions.any { isSuspendInlineMarker(it) }) return
|
||||||
|
|
||||||
simplifyTrivialInstructions(methodNode)
|
simplifyTrivialInstructions(methodNode)
|
||||||
|
|
||||||
val cfg = ControlFlowGraph(methodNode)
|
val cfg = ControlFlowGraph(methodNode)
|
||||||
|
|||||||
+6
@@ -9899,6 +9899,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
|||||||
runTest("compiler/testData/codegen/box/coroutines/kt49645.kt");
|
runTest("compiler/testData/codegen/box/coroutines/kt49645.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt50277.kt")
|
||||||
|
public void testKt50277() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/coroutines/kt50277.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("lastExpressionIsLoop.kt")
|
@TestMetadata("lastExpressionIsLoop.kt")
|
||||||
public void testLastExpressionIsLoop() throws Exception {
|
public void testLastExpressionIsLoop() throws Exception {
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
// WITH_STDLIB
|
||||||
|
// WITH_COROUTINES
|
||||||
|
// TARGET_BACKEND: JVM
|
||||||
|
|
||||||
|
import helpers.*
|
||||||
|
import kotlin.coroutines.*
|
||||||
|
|
||||||
|
fun builder(c: suspend () -> Unit) {
|
||||||
|
c.startCoroutine(EmptyContinuation)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun g(): Int = 42
|
||||||
|
|
||||||
|
suspend fun f(block: suspend (a: Int) -> Unit) {
|
||||||
|
listOf(0).map { block(g()) }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
var result = "Failed"
|
||||||
|
builder {
|
||||||
|
f { result = "OK" }
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
+6
@@ -9797,6 +9797,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
runTest("compiler/testData/codegen/box/coroutines/kt49645.kt");
|
runTest("compiler/testData/codegen/box/coroutines/kt49645.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt50277.kt")
|
||||||
|
public void testKt50277() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/coroutines/kt50277.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("lastExpressionIsLoop.kt")
|
@TestMetadata("lastExpressionIsLoop.kt")
|
||||||
public void testLastExpressionIsLoop() throws Exception {
|
public void testLastExpressionIsLoop() throws Exception {
|
||||||
|
|||||||
+6
@@ -9899,6 +9899,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
runTest("compiler/testData/codegen/box/coroutines/kt49645.kt");
|
runTest("compiler/testData/codegen/box/coroutines/kt49645.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt50277.kt")
|
||||||
|
public void testKt50277() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/coroutines/kt50277.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("lastExpressionIsLoop.kt")
|
@TestMetadata("lastExpressionIsLoop.kt")
|
||||||
public void testLastExpressionIsLoop() throws Exception {
|
public void testLastExpressionIsLoop() throws Exception {
|
||||||
|
|||||||
+5
@@ -7682,6 +7682,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
runTest("compiler/testData/codegen/box/coroutines/kt49645.kt");
|
runTest("compiler/testData/codegen/box/coroutines/kt49645.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt50277.kt")
|
||||||
|
public void testKt50277() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/coroutines/kt50277.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("lastExpressionIsLoop.kt")
|
@TestMetadata("lastExpressionIsLoop.kt")
|
||||||
public void testLastExpressionIsLoop() throws Exception {
|
public void testLastExpressionIsLoop() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt");
|
runTest("compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user