JVM IR: Fix value class mangling in SAM wrappers from different modules
KT-49659
This commit is contained in:
committed by
Alexander Udalov
parent
771b79d045
commit
a6dae0b37b
+6
@@ -19788,6 +19788,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
|||||||
runTest("compiler/testData/codegen/box/inlineClasses/safeAsOfTypeParameterWithInlineClassBound.kt");
|
runTest("compiler/testData/codegen/box/inlineClasses/safeAsOfTypeParameterWithInlineClassBound.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("samWrapperDifferentModule.kt")
|
||||||
|
public void testSamWrapperDifferentModule() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/inlineClasses/samWrapperDifferentModule.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("secondaryConstructorWithVararg.kt")
|
@TestMetadata("secondaryConstructorWithVararg.kt")
|
||||||
public void testSecondaryConstructorWithVararg() throws Exception {
|
public void testSecondaryConstructorWithVararg() throws Exception {
|
||||||
|
|||||||
@@ -353,6 +353,7 @@ private val jvmFilePhases = listOf(
|
|||||||
rangeContainsLoweringPhase,
|
rangeContainsLoweringPhase,
|
||||||
forLoopsPhase,
|
forLoopsPhase,
|
||||||
collectionStubMethodLowering,
|
collectionStubMethodLowering,
|
||||||
|
singleAbstractMethodPhase,
|
||||||
jvmInlineClassPhase,
|
jvmInlineClassPhase,
|
||||||
tailrecPhase,
|
tailrecPhase,
|
||||||
makePatchParentsPhase(1),
|
makePatchParentsPhase(1),
|
||||||
@@ -360,7 +361,6 @@ private val jvmFilePhases = listOf(
|
|||||||
enumWhenPhase,
|
enumWhenPhase,
|
||||||
singletonReferencesPhase,
|
singletonReferencesPhase,
|
||||||
|
|
||||||
singleAbstractMethodPhase,
|
|
||||||
assertionPhase,
|
assertionPhase,
|
||||||
returnableBlocksPhase,
|
returnableBlocksPhase,
|
||||||
sharedVariablesPhase,
|
sharedVariablesPhase,
|
||||||
|
|||||||
+2
-1
@@ -47,7 +47,8 @@ val jvmInlineClassPhase = makeIrFilePhase(
|
|||||||
// forLoopsPhase may produce UInt and ULong which are inline classes.
|
// forLoopsPhase may produce UInt and ULong which are inline classes.
|
||||||
// Standard library replacements are done on the unmangled names for UInt and ULong classes.
|
// Standard library replacements are done on the unmangled names for UInt and ULong classes.
|
||||||
// Collection stubs may require mangling by inline class rules.
|
// Collection stubs may require mangling by inline class rules.
|
||||||
prerequisite = setOf(forLoopsPhase, jvmBuiltInsPhase, collectionStubMethodLowering)
|
// SAM wrappers may require mangling for fun interfaces with inline class parameters
|
||||||
|
prerequisite = setOf(forLoopsPhase, jvmBuiltInsPhase, collectionStubMethodLowering, singleAbstractMethodPhase),
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+3
-2
@@ -19,7 +19,6 @@ import org.jetbrains.kotlin.ir.builders.declarations.IrFunctionBuilder
|
|||||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
|
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrTypeOperatorCall
|
import org.jetbrains.kotlin.ir.expressions.IrTypeOperatorCall
|
||||||
import org.jetbrains.kotlin.ir.types.IrType
|
import org.jetbrains.kotlin.ir.types.IrType
|
||||||
import org.jetbrains.kotlin.ir.types.getClass
|
import org.jetbrains.kotlin.ir.types.getClass
|
||||||
@@ -29,7 +28,9 @@ import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
|||||||
internal val singleAbstractMethodPhase = makeIrFilePhase(
|
internal val singleAbstractMethodPhase = makeIrFilePhase(
|
||||||
::JvmSingleAbstractMethodLowering,
|
::JvmSingleAbstractMethodLowering,
|
||||||
name = "SingleAbstractMethod",
|
name = "SingleAbstractMethod",
|
||||||
description = "Replace SAM conversions with instances of interface-implementing classes"
|
description = "Replace SAM conversions with instances of interface-implementing classes",
|
||||||
|
// FunctionReferenceLowering produces optimized SAM wrappers.
|
||||||
|
prerequisite = setOf(functionReferencePhase),
|
||||||
)
|
)
|
||||||
|
|
||||||
private class JvmSingleAbstractMethodLowering(context: JvmBackendContext) : SingleAbstractMethodLowering(context) {
|
private class JvmSingleAbstractMethodLowering(context: JvmBackendContext) : SingleAbstractMethodLowering(context) {
|
||||||
|
|||||||
+2
-2
@@ -54,11 +54,11 @@ class MemoizedInlineClassReplacements(
|
|||||||
val getReplacementFunction: (IrFunction) -> IrSimpleFunction? =
|
val getReplacementFunction: (IrFunction) -> IrSimpleFunction? =
|
||||||
storageManager.createMemoizedFunctionWithNullableValues {
|
storageManager.createMemoizedFunctionWithNullableValues {
|
||||||
when {
|
when {
|
||||||
// Don't mangle anonymous or synthetic functions
|
// Don't mangle anonymous or synthetic functions, except for generated SAM wrapper methods
|
||||||
(it.isLocal && it is IrSimpleFunction && it.overriddenSymbols.isEmpty()) ||
|
(it.isLocal && it is IrSimpleFunction && it.overriddenSymbols.isEmpty()) ||
|
||||||
(it.origin == IrDeclarationOrigin.DELEGATED_PROPERTY_ACCESSOR && it.visibility == DescriptorVisibilities.LOCAL) ||
|
(it.origin == IrDeclarationOrigin.DELEGATED_PROPERTY_ACCESSOR && it.visibility == DescriptorVisibilities.LOCAL) ||
|
||||||
it.isStaticInlineClassReplacement ||
|
it.isStaticInlineClassReplacement ||
|
||||||
it.origin.isSynthetic ->
|
it.origin.isSynthetic && it.origin != IrDeclarationOrigin.SYNTHETIC_GENERATED_SAM_IMPLEMENTATION ->
|
||||||
null
|
null
|
||||||
|
|
||||||
it.isInlineClassFieldGetter ->
|
it.isInlineClassFieldGetter ->
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
// See KT-49659
|
||||||
|
// WITH_RUNTIME
|
||||||
|
// MODULE: lib
|
||||||
|
// FILE: lib.kt
|
||||||
|
@Suppress("OPTIONAL_DECLARATION_USAGE_IN_NON_COMMON_SOURCE")
|
||||||
|
@kotlin.jvm.JvmInline
|
||||||
|
value class A(val value: String)
|
||||||
|
|
||||||
|
fun interface B {
|
||||||
|
fun f(a: A): String
|
||||||
|
}
|
||||||
|
|
||||||
|
// MODULE: main(lib)
|
||||||
|
// FILE: test.kt
|
||||||
|
fun get(b: B) = b.f(A("OK"))
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val l = { a: A -> a.value }
|
||||||
|
return get(l)
|
||||||
|
}
|
||||||
+6
@@ -19626,6 +19626,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
runTest("compiler/testData/codegen/box/inlineClasses/safeAsOfTypeParameterWithInlineClassBound.kt");
|
runTest("compiler/testData/codegen/box/inlineClasses/safeAsOfTypeParameterWithInlineClassBound.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("samWrapperDifferentModule.kt")
|
||||||
|
public void testSamWrapperDifferentModule() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/inlineClasses/samWrapperDifferentModule.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("secondaryConstructorWithVararg.kt")
|
@TestMetadata("secondaryConstructorWithVararg.kt")
|
||||||
public void testSecondaryConstructorWithVararg() throws Exception {
|
public void testSecondaryConstructorWithVararg() throws Exception {
|
||||||
|
|||||||
+6
@@ -19788,6 +19788,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
runTest("compiler/testData/codegen/box/inlineClasses/safeAsOfTypeParameterWithInlineClassBound.kt");
|
runTest("compiler/testData/codegen/box/inlineClasses/safeAsOfTypeParameterWithInlineClassBound.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("samWrapperDifferentModule.kt")
|
||||||
|
public void testSamWrapperDifferentModule() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/inlineClasses/samWrapperDifferentModule.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("secondaryConstructorWithVararg.kt")
|
@TestMetadata("secondaryConstructorWithVararg.kt")
|
||||||
public void testSecondaryConstructorWithVararg() throws Exception {
|
public void testSecondaryConstructorWithVararg() throws Exception {
|
||||||
|
|||||||
+5
@@ -16298,6 +16298,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
runTest("compiler/testData/codegen/box/inlineClasses/resultRunCatchingOrElse.kt");
|
runTest("compiler/testData/codegen/box/inlineClasses/resultRunCatchingOrElse.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("samWrapperDifferentModule.kt")
|
||||||
|
public void testSamWrapperDifferentModule() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/inlineClasses/samWrapperDifferentModule.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("secondaryConstructorWithVararg.kt")
|
@TestMetadata("secondaryConstructorWithVararg.kt")
|
||||||
public void testSecondaryConstructorWithVararg() throws Exception {
|
public void testSecondaryConstructorWithVararg() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/inlineClasses/secondaryConstructorWithVararg.kt");
|
runTest("compiler/testData/codegen/box/inlineClasses/secondaryConstructorWithVararg.kt");
|
||||||
|
|||||||
+6
@@ -15500,6 +15500,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/inlineClasses/safeAsOfTypeParameterWithInlineClassBound.kt");
|
runTest("compiler/testData/codegen/box/inlineClasses/safeAsOfTypeParameterWithInlineClassBound.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("samWrapperDifferentModule.kt")
|
||||||
|
public void testSamWrapperDifferentModule() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/inlineClasses/samWrapperDifferentModule.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("secondaryConstructorWithVararg.kt")
|
@TestMetadata("secondaryConstructorWithVararg.kt")
|
||||||
public void testSecondaryConstructorWithVararg() throws Exception {
|
public void testSecondaryConstructorWithVararg() throws Exception {
|
||||||
|
|||||||
+6
@@ -15464,6 +15464,12 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/inlineClasses/safeAsOfTypeParameterWithInlineClassBound.kt");
|
runTest("compiler/testData/codegen/box/inlineClasses/safeAsOfTypeParameterWithInlineClassBound.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("samWrapperDifferentModule.kt")
|
||||||
|
public void testSamWrapperDifferentModule() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/inlineClasses/samWrapperDifferentModule.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("secondaryConstructorWithVararg.kt")
|
@TestMetadata("secondaryConstructorWithVararg.kt")
|
||||||
public void testSecondaryConstructorWithVararg() throws Exception {
|
public void testSecondaryConstructorWithVararg() throws Exception {
|
||||||
|
|||||||
+5
@@ -12949,6 +12949,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
|
|||||||
runTest("compiler/testData/codegen/box/inlineClasses/safeAsOfTypeParameterWithInlineClassBound.kt");
|
runTest("compiler/testData/codegen/box/inlineClasses/safeAsOfTypeParameterWithInlineClassBound.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("samWrapperDifferentModule.kt")
|
||||||
|
public void testSamWrapperDifferentModule() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/inlineClasses/samWrapperDifferentModule.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("secondaryConstructorWithVararg.kt")
|
@TestMetadata("secondaryConstructorWithVararg.kt")
|
||||||
public void testSecondaryConstructorWithVararg() throws Exception {
|
public void testSecondaryConstructorWithVararg() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/inlineClasses/secondaryConstructorWithVararg.kt");
|
runTest("compiler/testData/codegen/box/inlineClasses/secondaryConstructorWithVararg.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user