JVM IR: Fix mangling for suspend functions with inline class params (KT-41374)
This commit is contained in:
committed by
Alexander Udalov
parent
48a3d4b8e0
commit
78ab957bfe
+11
-2
@@ -100,8 +100,17 @@ object InlineClassAbi {
|
||||
fun returnHashSuffix(irFunction: IrFunction) =
|
||||
md5base64(":${irFunction.returnType.eraseToString()}")
|
||||
|
||||
private fun hashSuffix(irFunction: IrFunction) =
|
||||
md5base64(irFunction.fullValueParameterList.joinToString { it.type.eraseToString() })
|
||||
private fun hashSuffix(irFunction: IrFunction): String {
|
||||
val signatureElementsForMangling =
|
||||
irFunction.fullValueParameterList.mapTo(mutableListOf()) { it.type.eraseToString() }
|
||||
if (irFunction.isSuspend) {
|
||||
// The JVM backend computes mangled names after creating suspend function views, but before default argument
|
||||
// stub insertion. It would be nice if this part of the continuation lowering happened earlier in the pipeline.
|
||||
// TODO: Move suspend function view creation before JvmInlineClassLowering.
|
||||
signatureElementsForMangling += "Lkotlin.coroutines.Continuation;"
|
||||
}
|
||||
return md5base64(signatureElementsForMangling.joinToString())
|
||||
}
|
||||
|
||||
private fun IrType.eraseToString() = buildString {
|
||||
append('L')
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// KT-41374
|
||||
// !LANGUAGE: +InlineClasses
|
||||
// FILE: test.kt
|
||||
|
||||
package a
|
||||
|
||||
inline class P(val i: Int)
|
||||
|
||||
suspend fun foo(p: P = P(1)) {}
|
||||
|
||||
suspend fun bar(p: P) {}
|
||||
|
||||
// The mangled name for a suspend function includes the continuation parameter in the hash computation, but not the
|
||||
// default argument mask and handler.
|
||||
|
||||
// 1 public final static foo-zMJ7EWY\(ILkotlin/coroutines/Continuation;\)Ljava/lang/Object;
|
||||
// 1 public static synthetic foo-zMJ7EWY\$default\(ILkotlin/coroutines/Continuation;ILjava/lang/Object;\)Ljava/lang/Object;
|
||||
// 1 INVOKESTATIC a/TestKt.foo-zMJ7EWY \(ILkotlin/coroutines/Continuation;\)Ljava/lang/Object;
|
||||
// 1 public final static bar-zMJ7EWY\(ILkotlin/coroutines/Continuation;\)Ljava/lang/Object;
|
||||
@@ -3157,6 +3157,11 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest {
|
||||
runTest("compiler/testData/codegen/bytecodeText/inlineClasses/skipCallToUnderlyingValueOfInlineClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("suspendFunctionMangling.kt")
|
||||
public void testSuspendFunctionMangling() throws Exception {
|
||||
runTest("compiler/testData/codegen/bytecodeText/inlineClasses/suspendFunctionMangling.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("toStringIsCalledByInlineClass.kt")
|
||||
public void testToStringIsCalledByInlineClass() throws Exception {
|
||||
runTest("compiler/testData/codegen/bytecodeText/inlineClasses/toStringIsCalledByInlineClass.kt");
|
||||
|
||||
+5
@@ -3252,6 +3252,11 @@ public class IrBytecodeTextTestGenerated extends AbstractIrBytecodeTextTest {
|
||||
runTest("compiler/testData/codegen/bytecodeText/inlineClasses/skipCallToUnderlyingValueOfInlineClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("suspendFunctionMangling.kt")
|
||||
public void testSuspendFunctionMangling() throws Exception {
|
||||
runTest("compiler/testData/codegen/bytecodeText/inlineClasses/suspendFunctionMangling.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("toStringIsCalledByInlineClass.kt")
|
||||
public void testToStringIsCalledByInlineClass() throws Exception {
|
||||
runTest("compiler/testData/codegen/bytecodeText/inlineClasses/toStringIsCalledByInlineClass.kt");
|
||||
|
||||
Reference in New Issue
Block a user