IC mangling: Use old mangling scheme for stdlib
This way, new stdlib can still be usable in 1.4.20
This commit is contained in:
@@ -7,8 +7,10 @@ package org.jetbrains.kotlin.codegen.state
|
||||
|
||||
import org.jetbrains.kotlin.codegen.coroutines.unwrapInitialDescriptorForSuspendFunction
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.InlineClassDescriptorResolver
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
|
||||
import org.jetbrains.kotlin.resolve.jvm.requiresFunctionNameManglingForParameterTypes
|
||||
import org.jetbrains.kotlin.resolve.jvm.requiresFunctionNameManglingForReturnType
|
||||
@@ -19,6 +21,8 @@ import java.util.*
|
||||
|
||||
const val NOT_INLINE_CLASS_PARAMETER_PLACEHOLDER = "_"
|
||||
|
||||
private fun FunctionDescriptor.isFunctionFromStdlib(): Boolean = fqNameSafe.startsWith(Name.identifier("kotlin"))
|
||||
|
||||
fun getManglingSuffixBasedOnKotlinSignature(
|
||||
descriptor: CallableMemberDescriptor,
|
||||
shouldMangleByReturnType: Boolean,
|
||||
@@ -34,9 +38,9 @@ fun getManglingSuffixBasedOnKotlinSignature(
|
||||
|
||||
val unwrappedDescriptor = descriptor.unwrapInitialDescriptorForSuspendFunction()
|
||||
|
||||
if (useOldManglingRules) {
|
||||
if (useOldManglingRules || descriptor.isFunctionFromStdlib()) {
|
||||
if (requiresFunctionNameManglingForParameterTypes(descriptor)) {
|
||||
return "-" + md5base64(collectSignatureForMangling(descriptor, useOldManglingRules))
|
||||
return "-" + md5base64(collectSignatureForMangling(descriptor, true))
|
||||
}
|
||||
|
||||
// If a class member function returns inline class value, mangle its name.
|
||||
@@ -46,7 +50,7 @@ fun getManglingSuffixBasedOnKotlinSignature(
|
||||
if (requiresFunctionNameManglingForReturnType(unwrappedDescriptor)) {
|
||||
return "-" + md5base64(
|
||||
":" + getSignatureElementForMangling(
|
||||
unwrappedDescriptor.returnType!!, useOldManglingRules
|
||||
unwrappedDescriptor.returnType!!, true
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -59,9 +63,9 @@ fun getManglingSuffixBasedOnKotlinSignature(
|
||||
// If a class member function returns inline class value, mangle its name.
|
||||
// NB here function can be a suspend function JVM view with return type replaced with 'Any',
|
||||
// should unwrap it and take original return type instead.
|
||||
val signature = collectSignatureForMangling(descriptor, useOldManglingRules) +
|
||||
val signature = collectSignatureForMangling(descriptor, false) +
|
||||
if (shouldMangleByReturnType && requiresFunctionNameManglingForReturnType(unwrappedDescriptor))
|
||||
":" + getSignatureElementForMangling(unwrappedDescriptor.returnType!!, useOldManglingRules)
|
||||
":" + getSignatureElementForMangling(unwrappedDescriptor.returnType!!, false)
|
||||
else ""
|
||||
return "-" + md5base64(signature)
|
||||
}
|
||||
|
||||
+5
-3
@@ -59,6 +59,8 @@ object InlineClassAbi {
|
||||
return irClass.primaryConstructor!!.valueParameters[0].type
|
||||
}
|
||||
|
||||
private fun IrFunction.isFunctionFromStdlib(): Boolean = fqNameForIrSerialization.startsWith(Name.identifier("kotlin"))
|
||||
|
||||
/**
|
||||
* Returns a mangled name for a function taking inline class arguments
|
||||
* to avoid clashes between overloaded methods.
|
||||
@@ -72,10 +74,10 @@ object InlineClassAbi {
|
||||
return Name.identifier("constructor-impl")
|
||||
}
|
||||
|
||||
val suffix = if (useOldMangleRules) {
|
||||
val suffix = if (useOldMangleRules || irFunction.isFunctionFromStdlib()) {
|
||||
when {
|
||||
irFunction.fullValueParameterList.any { it.type.requiresMangling } ->
|
||||
hashSuffix(irFunction, false, useOldMangleRules)
|
||||
hashSuffix(irFunction, mangleReturnTypes = false, useOldMangleRules = true)
|
||||
mangleReturnTypes && irFunction.hasMangledReturnType ->
|
||||
returnHashSuffix(irFunction)
|
||||
(irFunction.parent as? IrClass)?.isInline == true &&
|
||||
@@ -87,7 +89,7 @@ object InlineClassAbi {
|
||||
} else {
|
||||
when {
|
||||
irFunction.fullValueParameterList.any { it.type.requiresMangling } || (mangleReturnTypes && irFunction.hasMangledReturnType) ->
|
||||
hashSuffix(irFunction, mangleReturnTypes, useOldMangleRules)
|
||||
hashSuffix(irFunction, mangleReturnTypes, false)
|
||||
(irFunction.parent as? IrClass)?.isInline == true &&
|
||||
irFunction.origin != IrDeclarationOrigin.IR_BUILTINS_STUB ->
|
||||
"impl"
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package test
|
||||
|
||||
inline class IC(val i: Int)
|
||||
|
||||
fun foo(i: Int, ic: IC) {}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
@kotlin.Metadata
|
||||
public final class test/IC {
|
||||
// source: 'new.kt'
|
||||
private final field i: int
|
||||
private synthetic method <init>(p0: int): void
|
||||
public synthetic final static method box-impl(p0: int): test.IC
|
||||
public static method constructor-impl(p0: int): int
|
||||
public method equals(p0: java.lang.Object): boolean
|
||||
public static method equals-impl(p0: int, p1: java.lang.Object): boolean
|
||||
public final static method equals-impl0(p0: int, p1: int): boolean
|
||||
public final method getI(): int
|
||||
public method hashCode(): int
|
||||
public static method hashCode-impl(p0: int): int
|
||||
public method toString(): java.lang.String
|
||||
public static method toString-impl(p0: int): java.lang.String
|
||||
public synthetic final method unbox-impl(): int
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class test/NewKt {
|
||||
// source: 'new.kt'
|
||||
public final static method foo-WsYm_fY(p0: int, p1: int): void
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// FILE: 1.kt
|
||||
package test
|
||||
|
||||
inline class IC(val i: Int)
|
||||
|
||||
// FILE: 2.kt
|
||||
package kotlin
|
||||
|
||||
import test.*
|
||||
|
||||
fun foo(i: Int, ic: IC) {}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
@kotlin.Metadata
|
||||
public final class kotlin/_2Kt {
|
||||
// source: '2.kt'
|
||||
public final static method foo-wfSZ3cc(p0: int, p1: int): void
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class test/IC {
|
||||
// source: '1.kt'
|
||||
private final field i: int
|
||||
private synthetic method <init>(p0: int): void
|
||||
public synthetic final static method box-impl(p0: int): test.IC
|
||||
public static method constructor-impl(p0: int): int
|
||||
public method equals(p0: java.lang.Object): boolean
|
||||
public static method equals-impl(p0: int, p1: java.lang.Object): boolean
|
||||
public final static method equals-impl0(p0: int, p1: int): boolean
|
||||
public final method getI(): int
|
||||
public method hashCode(): int
|
||||
public static method hashCode-impl(p0: int): int
|
||||
public method toString(): java.lang.String
|
||||
public static method toString-impl(p0: int): java.lang.String
|
||||
public synthetic final method unbox-impl(): int
|
||||
}
|
||||
+23
@@ -1187,6 +1187,29 @@ public class BytecodeListingTestGenerated extends AbstractBytecodeListingTest {
|
||||
runTest("compiler/testData/codegen/bytecodeListing/inlineClasses/inlineCollectionOfInlineClass/set.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/bytecodeListing/inlineClasses/stdlibManglingIn1430")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class StdlibManglingIn1430 extends AbstractBytecodeListingTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInStdlibManglingIn1430() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/bytecodeListing/inlineClasses/stdlibManglingIn1430"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
|
||||
}
|
||||
|
||||
@TestMetadata("new.kt")
|
||||
public void testNew() throws Exception {
|
||||
runTest("compiler/testData/codegen/bytecodeListing/inlineClasses/stdlibManglingIn1430/new.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("old.kt")
|
||||
public void testOld() throws Exception {
|
||||
runTest("compiler/testData/codegen/bytecodeListing/inlineClasses/stdlibManglingIn1430/old.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/bytecodeListing/jvm8")
|
||||
|
||||
+23
@@ -1157,6 +1157,29 @@ public class IrBytecodeListingTestGenerated extends AbstractIrBytecodeListingTes
|
||||
runTest("compiler/testData/codegen/bytecodeListing/inlineClasses/inlineCollectionOfInlineClass/set.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/bytecodeListing/inlineClasses/stdlibManglingIn1430")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class StdlibManglingIn1430 extends AbstractIrBytecodeListingTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM_IR, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInStdlibManglingIn1430() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/bytecodeListing/inlineClasses/stdlibManglingIn1430"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
|
||||
}
|
||||
|
||||
@TestMetadata("new.kt")
|
||||
public void testNew() throws Exception {
|
||||
runTest("compiler/testData/codegen/bytecodeListing/inlineClasses/stdlibManglingIn1430/new.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("old.kt")
|
||||
public void testOld() throws Exception {
|
||||
runTest("compiler/testData/codegen/bytecodeListing/inlineClasses/stdlibManglingIn1430/old.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/bytecodeListing/jvm8")
|
||||
|
||||
Reference in New Issue
Block a user