JVM IR: Fix inline class mangling for calls to internal functions

...in a different module, e.g., using -Xfriend-paths.
This commit is contained in:
Steven Schäfer
2021-01-28 14:20:21 +01:00
committed by Ilmir Usmanov
parent 6747084fe2
commit 482e217b5e
8 changed files with 48 additions and 3 deletions
@@ -245,6 +245,11 @@ public class FirCompileKotlinAgainstKotlinTestGenerated extends AbstractFirCompi
runTest("compiler/testData/compileKotlinAgainstKotlin/internalWithDefaultArgs.kt");
}
@TestMetadata("internalWithInlineClass.kt")
public void testInternalWithInlineClass() throws Exception {
runTest("compiler/testData/compileKotlinAgainstKotlin/internalWithInlineClass.kt");
}
@TestMetadata("internalWithOtherModuleName.kt")
public void testInternalWithOtherModuleName() throws Exception {
runTest("compiler/testData/compileKotlinAgainstKotlin/internalWithOtherModuleName.kt");
@@ -134,7 +134,10 @@ class MethodSignatureMapper(private val context: JvmBackendContext) {
origin != JvmLoweredDeclarationOrigin.SYNTHETIC_METHOD_FOR_PROPERTY_OR_TYPEALIAS_ANNOTATIONS &&
!isPublishedApi()
) {
return this
return originalFunction.takeIf { it != this }
?.safeAs<IrSimpleFunction>()
?.getInternalFunctionForManglingIfNeeded()
?: this
}
originalForDefaultAdapter?.getInternalFunctionForManglingIfNeeded()?.let { return it }
return null
@@ -383,12 +383,13 @@ fun IrSimpleType.isRawType(): Boolean =
hasAnnotation(JvmGeneratorExtensions.RAW_TYPE_ANNOTATION_FQ_NAME)
internal fun classFileContainsMethod(classId: ClassId, function: IrFunction, context: JvmBackendContext): Boolean? {
val originalDescriptor = context.methodSignatureMapper.mapSignatureWithGeneric(function).asmMethod.descriptor
val originalSignature = context.methodSignatureMapper.mapSignatureWithGeneric(function).asmMethod
val originalDescriptor = originalSignature.descriptor
val descriptor = if (function.isSuspend)
listOf(*Type.getArgumentTypes(originalDescriptor), Type.getObjectType("kotlin/coroutines/Continuation"))
.joinToString(prefix = "(", postfix = ")", separator = "") + AsmTypes.OBJECT_TYPE
else originalDescriptor
return classFileContainsMethod(classId, context.state, Method(function.name.asString(), descriptor))
return classFileContainsMethod(classId, context.state, Method(originalSignature.name, descriptor))
}
val IrMemberWithContainerSource.parentClassId: ClassId?
@@ -0,0 +1,16 @@
// IGNORE_BACKEND_FIR: JVM_IR
// FILE: A.kt
package a
inline class Message(val value: String)
class Box {
internal fun result(msg: Message): String = msg.value
}
// FILE: B.kt
fun box(): String {
return a.Box().result(a.Message("OK"))
}
@@ -244,6 +244,11 @@ public class CompileKotlinAgainstKotlinTestGenerated extends AbstractCompileKotl
runTest("compiler/testData/compileKotlinAgainstKotlin/internalWithDefaultArgs.kt");
}
@TestMetadata("internalWithInlineClass.kt")
public void testInternalWithInlineClass() throws Exception {
runTest("compiler/testData/compileKotlinAgainstKotlin/internalWithInlineClass.kt");
}
@TestMetadata("internalWithOtherModuleName.kt")
public void testInternalWithOtherModuleName() throws Exception {
runTest("compiler/testData/compileKotlinAgainstKotlin/internalWithOtherModuleName.kt");
@@ -245,6 +245,11 @@ public class IrCompileKotlinAgainstKotlinTestGenerated extends AbstractIrCompile
runTest("compiler/testData/compileKotlinAgainstKotlin/internalWithDefaultArgs.kt");
}
@TestMetadata("internalWithInlineClass.kt")
public void testInternalWithInlineClass() throws Exception {
runTest("compiler/testData/compileKotlinAgainstKotlin/internalWithInlineClass.kt");
}
@TestMetadata("internalWithOtherModuleName.kt")
public void testInternalWithOtherModuleName() throws Exception {
runTest("compiler/testData/compileKotlinAgainstKotlin/internalWithOtherModuleName.kt");
@@ -245,6 +245,11 @@ public class JvmIrAgainstOldBoxTestGenerated extends AbstractJvmIrAgainstOldBoxT
runTest("compiler/testData/compileKotlinAgainstKotlin/internalWithDefaultArgs.kt");
}
@TestMetadata("internalWithInlineClass.kt")
public void testInternalWithInlineClass() throws Exception {
runTest("compiler/testData/compileKotlinAgainstKotlin/internalWithInlineClass.kt");
}
@TestMetadata("internalWithOtherModuleName.kt")
public void testInternalWithOtherModuleName() throws Exception {
runTest("compiler/testData/compileKotlinAgainstKotlin/internalWithOtherModuleName.kt");
@@ -245,6 +245,11 @@ public class JvmOldAgainstIrBoxTestGenerated extends AbstractJvmOldAgainstIrBoxT
runTest("compiler/testData/compileKotlinAgainstKotlin/internalWithDefaultArgs.kt");
}
@TestMetadata("internalWithInlineClass.kt")
public void testInternalWithInlineClass() throws Exception {
runTest("compiler/testData/compileKotlinAgainstKotlin/internalWithInlineClass.kt");
}
@TestMetadata("internalWithOtherModuleName.kt")
public void testInternalWithOtherModuleName() throws Exception {
runTest("compiler/testData/compileKotlinAgainstKotlin/internalWithOtherModuleName.kt");