diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmLower.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmLower.kt index b33f8c3be3a..28ee3d65dbf 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmLower.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmLower.kt @@ -304,8 +304,6 @@ private val jvmFilePhases = mainMethodGenerationPhase then - // should be last transformation - removeDeclarationsThatWouldBeInlined then makePatchParentsPhase(3) val jvmPhases = namedIrModulePhase( @@ -316,6 +314,8 @@ val jvmPhases = namedIrModulePhase( fileClassPhase then performByIrFile(lower = jvmFilePhases) then generateMultifileFacadesPhase then + // should be last transformation + removeDeclarationsThatWouldBeInlined then validateIrAfterLowering ) diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/RemoveDeclarationsThatWouldBeInlinedLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/RemoveDeclarationsThatWouldBeInlinedLowering.kt index a1b6b300860..b4f1dc0cce8 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/RemoveDeclarationsThatWouldBeInlinedLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/RemoveDeclarationsThatWouldBeInlinedLowering.kt @@ -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.makeIrFilePhase +import org.jetbrains.kotlin.backend.common.phaser.makeIrModulePhase import org.jetbrains.kotlin.backend.jvm.JvmBackendContext import org.jetbrains.kotlin.backend.jvm.ir.isLambda import org.jetbrains.kotlin.ir.IrElement @@ -17,7 +17,7 @@ import org.jetbrains.kotlin.ir.declarations.IrFunction import org.jetbrains.kotlin.ir.expressions.IrFunctionReference import org.jetbrains.kotlin.ir.visitors.* -internal val removeDeclarationsThatWouldBeInlined = makeIrFilePhase( +internal val removeDeclarationsThatWouldBeInlined = makeIrModulePhase( ::RemoveDeclarationsThatWouldBeInlinedLowering, name = "RemoveInlinedDeclarations", description = "Rename declaration that should be inlined" diff --git a/compiler/testData/codegen/box/multifileClasses/optimized/callInInlineLambda.kt b/compiler/testData/codegen/box/multifileClasses/optimized/callInInlineLambda.kt new file mode 100644 index 00000000000..6eaacfc3209 --- /dev/null +++ b/compiler/testData/codegen/box/multifileClasses/optimized/callInInlineLambda.kt @@ -0,0 +1,19 @@ +// TARGET_BACKEND: JVM +// IGNORE_LIGHT_ANALYSIS +// WITH_RUNTIME +// !INHERIT_MULTIFILE_PARTS +// FILE: result.kt + +@file:JvmName("Util") +@file:JvmMultifileClass +package test + +fun result(): String = "OK" + +// FILE: test.kt + +import test.result + +private inline fun id(f: () -> String): String = f() + +fun box(): String = id { result() } diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index c3aab349ab1..3ee69fe82bf 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -16497,6 +16497,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/multifileClasses/optimized"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); } + @TestMetadata("callInInlineLambda.kt") + public void testCallInInlineLambda() throws Exception { + runTest("compiler/testData/codegen/box/multifileClasses/optimized/callInInlineLambda.kt"); + } + @TestMetadata("callableRefToConstVal.kt") public void testCallableRefToConstVal() throws Exception { runTest("compiler/testData/codegen/box/multifileClasses/optimized/callableRefToConstVal.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 27f89252ed0..c7d1a6a6621 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -16497,6 +16497,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/multifileClasses/optimized"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); } + @TestMetadata("callInInlineLambda.kt") + public void testCallInInlineLambda() throws Exception { + runTest("compiler/testData/codegen/box/multifileClasses/optimized/callInInlineLambda.kt"); + } + @TestMetadata("callableRefToConstVal.kt") public void testCallableRefToConstVal() throws Exception { runTest("compiler/testData/codegen/box/multifileClasses/optimized/callableRefToConstVal.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index e6cf5de2f1f..77ff25dd2e6 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -15372,6 +15372,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/multifileClasses/optimized"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM_IR, true); } + @TestMetadata("callInInlineLambda.kt") + public void testCallInInlineLambda() throws Exception { + runTest("compiler/testData/codegen/box/multifileClasses/optimized/callInInlineLambda.kt"); + } + @TestMetadata("callableRefToConstVal.kt") public void testCallableRefToConstVal() throws Exception { runTest("compiler/testData/codegen/box/multifileClasses/optimized/callableRefToConstVal.kt");