JVM IR: Use language feature for inline class mangling rules
This commit is contained in:
committed by
Dmitry Petrov
parent
a41b746774
commit
7ea71a17f0
@@ -116,7 +116,7 @@ class JvmBackendContext(
|
|||||||
|
|
||||||
val staticDefaultStubs = mutableMapOf<IrFunctionSymbol, IrFunction>()
|
val staticDefaultStubs = mutableMapOf<IrFunctionSymbol, IrFunction>()
|
||||||
|
|
||||||
val inlineClassReplacements = MemoizedInlineClassReplacements()
|
val inlineClassReplacements = MemoizedInlineClassReplacements(state.functionsWithInlineClassReturnTypesMangled)
|
||||||
|
|
||||||
internal fun referenceClass(descriptor: ClassDescriptor): IrClassSymbol =
|
internal fun referenceClass(descriptor: ClassDescriptor): IrClassSymbol =
|
||||||
symbolTable.lazyWrapper.referenceClass(descriptor)
|
symbolTable.lazyWrapper.referenceClass(descriptor)
|
||||||
|
|||||||
+1
-1
@@ -370,7 +370,7 @@ internal class FunctionReferenceLowering(private val context: JvmBackendContext)
|
|||||||
private fun createInvokeMethod(receiverVar: IrValueDeclaration?): IrSimpleFunction =
|
private fun createInvokeMethod(receiverVar: IrValueDeclaration?): IrSimpleFunction =
|
||||||
functionReferenceClass.addFunction {
|
functionReferenceClass.addFunction {
|
||||||
setSourceRange(if (isLambda) callee else irFunctionReference)
|
setSourceRange(if (isLambda) callee else irFunctionReference)
|
||||||
name = if (callee.returnType.erasedUpperBound.isInline) {
|
name = if (callee.returnType.erasedUpperBound.isInline && context.state.functionsWithInlineClassReturnTypesMangled) {
|
||||||
// For functions with inline class return type we need to mangle the invoke method.
|
// For functions with inline class return type we need to mangle the invoke method.
|
||||||
// Otherwise, bridge lowering may fail to generate bridges for inline class types erasing to Any.
|
// Otherwise, bridge lowering may fail to generate bridges for inline class types erasing to Any.
|
||||||
val suffix = InlineClassAbi.returnHashSuffix(callee)
|
val suffix = InlineClassAbi.returnHashSuffix(callee)
|
||||||
|
|||||||
+2
-3
@@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.backend.jvm.lower.inlineclasses
|
package org.jetbrains.kotlin.backend.jvm.lower.inlineclasses
|
||||||
|
|
||||||
import org.jetbrains.kotlin.backend.jvm.codegen.fileParent
|
|
||||||
import org.jetbrains.kotlin.backend.jvm.ir.erasedUpperBound
|
import org.jetbrains.kotlin.backend.jvm.ir.erasedUpperBound
|
||||||
import org.jetbrains.kotlin.codegen.state.md5base64
|
import org.jetbrains.kotlin.codegen.state.md5base64
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
@@ -63,7 +62,7 @@ object InlineClassAbi {
|
|||||||
* Returns a mangled name for a function taking inline class arguments
|
* Returns a mangled name for a function taking inline class arguments
|
||||||
* to avoid clashes between overloaded methods.
|
* to avoid clashes between overloaded methods.
|
||||||
*/
|
*/
|
||||||
fun mangledNameFor(irFunction: IrFunction): Name {
|
fun mangledNameFor(irFunction: IrFunction, mangleReturnTypes: Boolean): Name {
|
||||||
if (irFunction is IrConstructor) {
|
if (irFunction is IrConstructor) {
|
||||||
// Note that we might drop this convention and use standard mangling for constructors too, see KT-37186.
|
// Note that we might drop this convention and use standard mangling for constructors too, see KT-37186.
|
||||||
assert(irFunction.constructedClass.isInline) {
|
assert(irFunction.constructedClass.isInline) {
|
||||||
@@ -75,7 +74,7 @@ object InlineClassAbi {
|
|||||||
val suffix = when {
|
val suffix = when {
|
||||||
irFunction.fullValueParameterList.any { it.type.requiresMangling } ->
|
irFunction.fullValueParameterList.any { it.type.requiresMangling } ->
|
||||||
hashSuffix(irFunction)
|
hashSuffix(irFunction)
|
||||||
irFunction.hasMangledReturnType ->
|
mangleReturnTypes && irFunction.hasMangledReturnType ->
|
||||||
returnHashSuffix(irFunction)
|
returnHashSuffix(irFunction)
|
||||||
(irFunction.parent as? IrClass)?.isInline == true -> "impl"
|
(irFunction.parent as? IrClass)?.isInline == true -> "impl"
|
||||||
else -> return irFunction.name
|
else -> return irFunction.name
|
||||||
|
|||||||
+3
-4
@@ -10,7 +10,6 @@ import org.jetbrains.kotlin.backend.common.ir.copyTypeParameters
|
|||||||
import org.jetbrains.kotlin.backend.common.ir.copyTypeParametersFrom
|
import org.jetbrains.kotlin.backend.common.ir.copyTypeParametersFrom
|
||||||
import org.jetbrains.kotlin.backend.common.ir.createDispatchReceiverParameter
|
import org.jetbrains.kotlin.backend.common.ir.createDispatchReceiverParameter
|
||||||
import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin
|
import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin
|
||||||
import org.jetbrains.kotlin.backend.jvm.ir.erasedUpperBound
|
|
||||||
import org.jetbrains.kotlin.backend.jvm.lower.inlineclasses.InlineClassAbi.mangledNameFor
|
import org.jetbrains.kotlin.backend.jvm.lower.inlineclasses.InlineClassAbi.mangledNameFor
|
||||||
import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper
|
import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper
|
||||||
import org.jetbrains.kotlin.ir.builders.declarations.addValueParameter
|
import org.jetbrains.kotlin.ir.builders.declarations.addValueParameter
|
||||||
@@ -33,7 +32,7 @@ import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
|||||||
/**
|
/**
|
||||||
* Keeps track of replacement functions and inline class box/unbox functions.
|
* Keeps track of replacement functions and inline class box/unbox functions.
|
||||||
*/
|
*/
|
||||||
class MemoizedInlineClassReplacements {
|
class MemoizedInlineClassReplacements(private val mangleReturnTypes: Boolean) {
|
||||||
private val storageManager = LockBasedStorageManager("inline-class-replacements")
|
private val storageManager = LockBasedStorageManager("inline-class-replacements")
|
||||||
private val propertyMap = mutableMapOf<IrPropertySymbol, IrProperty>()
|
private val propertyMap = mutableMapOf<IrPropertySymbol, IrProperty>()
|
||||||
|
|
||||||
@@ -55,7 +54,7 @@ class MemoizedInlineClassReplacements {
|
|||||||
createStaticReplacement(it)
|
createStaticReplacement(it)
|
||||||
|
|
||||||
// Otherwise, mangle functions with mangled parameters, ignoring constructors
|
// Otherwise, mangle functions with mangled parameters, ignoring constructors
|
||||||
it is IrSimpleFunction && (it.hasMangledParameters || it.hasMangledReturnType) ->
|
it is IrSimpleFunction && (it.hasMangledParameters || mangleReturnTypes && it.hasMangledReturnType) ->
|
||||||
if (it.dispatchReceiverParameter != null) createMethodReplacement(it) else createStaticReplacement(it)
|
if (it.dispatchReceiverParameter != null) createMethodReplacement(it) else createStaticReplacement(it)
|
||||||
|
|
||||||
else ->
|
else ->
|
||||||
@@ -190,7 +189,7 @@ class MemoizedInlineClassReplacements {
|
|||||||
if (noFakeOverride) {
|
if (noFakeOverride) {
|
||||||
isFakeOverride = false
|
isFakeOverride = false
|
||||||
}
|
}
|
||||||
name = mangledNameFor(function)
|
name = mangledNameFor(function, mangleReturnTypes)
|
||||||
returnType = function.returnType
|
returnType = function.returnType
|
||||||
}.apply {
|
}.apply {
|
||||||
parent = function.parent
|
parent = function.parent
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
// !LANGUAGE: +InlineClasses -MangleClassMembersReturningInlineClasses
|
// !LANGUAGE: +InlineClasses -MangleClassMembersReturningInlineClasses
|
||||||
// IGNORE_BACKEND: JVM_IR
|
|
||||||
|
|
||||||
inline class S(val x: String)
|
inline class S(val x: String)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user