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:
@@ -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
|
||||
)
|
||||
|
||||
|
||||
+2
-2
@@ -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"
|
||||
|
||||
+19
@@ -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() }
|
||||
+5
@@ -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");
|
||||
|
||||
+5
@@ -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");
|
||||
|
||||
+5
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user