KT-54784 Fix function inlining in init sections
This commit is contained in:
committed by
teamcity
parent
af4308e634
commit
252e97663b
+6
@@ -9169,6 +9169,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/controlStructures/breakContinueInExpressions/inlinedBreakContinue"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("initializerBlock.kt")
|
||||
public void testInitializerBlock() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/controlStructures/breakContinueInExpressions/inlinedBreakContinue/initializerBlock.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("inlineFunctionWithMultipleParameters.kt")
|
||||
public void testInlineFunctionWithMultipleParameters() throws Exception {
|
||||
|
||||
@@ -359,6 +359,7 @@ private val jvmFilePhases = listOf(
|
||||
objectClassPhase,
|
||||
readResolveForDataObjectsPhase,
|
||||
staticInitializersPhase,
|
||||
uniqueLoopLabelsPhase,
|
||||
initializersPhase,
|
||||
initializersCleanupPhase,
|
||||
functionNVarargBridgePhase,
|
||||
@@ -409,8 +410,6 @@ private fun buildJvmLoweringPhases(
|
||||
buildLoweringsPhase(phases) then
|
||||
generateMultifileFacadesPhase then
|
||||
resolveInlineCallsPhase then
|
||||
// should be last transformation
|
||||
prepareForBytecodeInlining then
|
||||
validateIrAfterLowering
|
||||
)
|
||||
}
|
||||
|
||||
+5
-5
@@ -6,7 +6,7 @@
|
||||
package org.jetbrains.kotlin.backend.jvm.lower
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.FileLoweringPass
|
||||
import org.jetbrains.kotlin.backend.common.phaser.makeIrModulePhase
|
||||
import org.jetbrains.kotlin.backend.common.phaser.makeIrFilePhase
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationWithName
|
||||
@@ -14,13 +14,13 @@ import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.ir.expressions.IrLoop
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||
|
||||
internal val prepareForBytecodeInlining = makeIrModulePhase(
|
||||
::BytecodeInliningPreparationLowering,
|
||||
name = "BytecodeInliningPreparation",
|
||||
internal val uniqueLoopLabelsPhase = makeIrFilePhase(
|
||||
::UniqueLoopLabelsLowering,
|
||||
name = "UniqueLoopLabels",
|
||||
description = "Label all loops for non-local break/continue"
|
||||
)
|
||||
|
||||
private class BytecodeInliningPreparationLowering(val context: JvmBackendContext) : FileLoweringPass {
|
||||
private class UniqueLoopLabelsLowering(val context: JvmBackendContext) : FileLoweringPass {
|
||||
override fun lower(irFile: IrFile) {
|
||||
irFile.accept(object : IrElementVisitor<Unit, String> {
|
||||
// This counter is intentionally not local to every declaration because their names might clash.
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
// LANGUAGE: +BreakContinueInInlineLambdas
|
||||
// IGNORE_BACKEND: JVM, JVM_OLD
|
||||
// WITH_STDLIB
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class C {
|
||||
companion object {
|
||||
val visited = mutableListOf<Int>()
|
||||
|
||||
init {
|
||||
for (i in 1..5) {
|
||||
run {
|
||||
if (i == 2) continue
|
||||
if (i == 4) break
|
||||
}
|
||||
C.visited.add(i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val visited = mutableListOf<Int>()
|
||||
|
||||
init {
|
||||
for (i in 1..5) {
|
||||
run {
|
||||
if (i == 1) continue
|
||||
if (i == 4) break
|
||||
}
|
||||
visited.add(i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val c = C()
|
||||
assertEquals(listOf(1, 3), C.visited)
|
||||
assertEquals(listOf(2, 3), c.visited)
|
||||
return "OK"
|
||||
}
|
||||
+6
@@ -9018,6 +9018,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
public void testAllFilesPresentInInlinedBreakContinue() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/controlStructures/breakContinueInExpressions/inlinedBreakContinue"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("initializerBlock.kt")
|
||||
public void testInitializerBlock() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/controlStructures/breakContinueInExpressions/inlinedBreakContinue/initializerBlock.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
@@ -9169,6 +9169,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/controlStructures/breakContinueInExpressions/inlinedBreakContinue"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("initializerBlock.kt")
|
||||
public void testInitializerBlock() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/controlStructures/breakContinueInExpressions/inlinedBreakContinue/initializerBlock.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("inlineFunctionWithMultipleParameters.kt")
|
||||
public void testInlineFunctionWithMultipleParameters() throws Exception {
|
||||
|
||||
+5
@@ -6977,6 +6977,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class InlinedBreakContinue extends AbstractLightAnalysisModeTest {
|
||||
@TestMetadata("initializerBlock.kt")
|
||||
public void ignoreInitializerBlock() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/controlStructures/breakContinueInExpressions/inlinedBreakContinue/initializerBlock.kt");
|
||||
}
|
||||
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath);
|
||||
}
|
||||
|
||||
+6
@@ -6128,6 +6128,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
public void testAllFilesPresentInInlinedBreakContinue() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/controlStructures/breakContinueInExpressions/inlinedBreakContinue"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("initializerBlock.kt")
|
||||
public void testInitializerBlock() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/controlStructures/breakContinueInExpressions/inlinedBreakContinue/initializerBlock.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
@@ -6189,6 +6189,12 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/controlStructures/breakContinueInExpressions/inlinedBreakContinue"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("initializerBlock.kt")
|
||||
public void testInitializerBlock() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/controlStructures/breakContinueInExpressions/inlinedBreakContinue/initializerBlock.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("inlineFunctionWithMultipleParameters.kt")
|
||||
public void testInlineFunctionWithMultipleParameters() throws Exception {
|
||||
|
||||
+5
@@ -5450,6 +5450,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/controlStructures/breakContinueInExpressions/inlinedBreakContinue"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.WASM, true);
|
||||
}
|
||||
|
||||
@TestMetadata("initializerBlock.kt")
|
||||
public void testInitializerBlock() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/controlStructures/breakContinueInExpressions/inlinedBreakContinue/initializerBlock.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inlineFunctionWithMultipleParameters.kt")
|
||||
public void testInlineFunctionWithMultipleParameters() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/controlStructures/breakContinueInExpressions/inlinedBreakContinue/inlineFunctionWithMultipleParameters.kt");
|
||||
|
||||
+6
@@ -7031,6 +7031,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/controlStructures/breakContinueInExpressions/inlinedBreakContinue"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.NATIVE, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("initializerBlock.kt")
|
||||
public void testInitializerBlock() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/controlStructures/breakContinueInExpressions/inlinedBreakContinue/initializerBlock.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("inlineFunctionWithMultipleParameters.kt")
|
||||
public void testInlineFunctionWithMultipleParameters() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user