JVM IR: make RemoveInlinedDeclarations a final module phase

Code in inline lambdas can call multifile part members. These calls are
replaced in GenerateMultifileFacades with the call to the facade member.
Previously this didn't happen though because the lambda body was removed
before the GenerateMultifileFacades phase, which led to
IllegalAccessError in the -Xmultifile-parts-inherit mode (because the
part class is package private in another package).
This commit is contained in:
Alexander Udalov
2019-11-15 00:41:45 +01:00
parent cdb7703947
commit 0daab88f97
6 changed files with 38 additions and 4 deletions
@@ -304,8 +304,6 @@ private val jvmFilePhases =
mainMethodGenerationPhase then mainMethodGenerationPhase then
// should be last transformation
removeDeclarationsThatWouldBeInlined then
makePatchParentsPhase(3) makePatchParentsPhase(3)
val jvmPhases = namedIrModulePhase( val jvmPhases = namedIrModulePhase(
@@ -316,6 +314,8 @@ val jvmPhases = namedIrModulePhase(
fileClassPhase then fileClassPhase then
performByIrFile(lower = jvmFilePhases) then performByIrFile(lower = jvmFilePhases) then
generateMultifileFacadesPhase then generateMultifileFacadesPhase then
// should be last transformation
removeDeclarationsThatWouldBeInlined then
validateIrAfterLowering validateIrAfterLowering
) )
@@ -6,7 +6,7 @@
package org.jetbrains.kotlin.backend.jvm.lower package org.jetbrains.kotlin.backend.jvm.lower
import org.jetbrains.kotlin.backend.common.FileLoweringPass 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.JvmBackendContext
import org.jetbrains.kotlin.backend.jvm.ir.isLambda import org.jetbrains.kotlin.backend.jvm.ir.isLambda
import org.jetbrains.kotlin.ir.IrElement 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.expressions.IrFunctionReference
import org.jetbrains.kotlin.ir.visitors.* import org.jetbrains.kotlin.ir.visitors.*
internal val removeDeclarationsThatWouldBeInlined = makeIrFilePhase( internal val removeDeclarationsThatWouldBeInlined = makeIrModulePhase(
::RemoveDeclarationsThatWouldBeInlinedLowering, ::RemoveDeclarationsThatWouldBeInlinedLowering,
name = "RemoveInlinedDeclarations", name = "RemoveInlinedDeclarations",
description = "Rename declaration that should be inlined" description = "Rename declaration that should be inlined"
@@ -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() }
@@ -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); 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") @TestMetadata("callableRefToConstVal.kt")
public void testCallableRefToConstVal() throws Exception { public void testCallableRefToConstVal() throws Exception {
runTest("compiler/testData/codegen/box/multifileClasses/optimized/callableRefToConstVal.kt"); runTest("compiler/testData/codegen/box/multifileClasses/optimized/callableRefToConstVal.kt");
@@ -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); 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") @TestMetadata("callableRefToConstVal.kt")
public void testCallableRefToConstVal() throws Exception { public void testCallableRefToConstVal() throws Exception {
runTest("compiler/testData/codegen/box/multifileClasses/optimized/callableRefToConstVal.kt"); runTest("compiler/testData/codegen/box/multifileClasses/optimized/callableRefToConstVal.kt");
@@ -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); 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") @TestMetadata("callableRefToConstVal.kt")
public void testCallableRefToConstVal() throws Exception { public void testCallableRefToConstVal() throws Exception {
runTest("compiler/testData/codegen/box/multifileClasses/optimized/callableRefToConstVal.kt"); runTest("compiler/testData/codegen/box/multifileClasses/optimized/callableRefToConstVal.kt");