Do not mangle functions with inline classes when the only inline class
in arguments is kotlin.Result. Fix returnTarget for suspend function views.
This commit is contained in:
+1
-1
@@ -402,7 +402,7 @@ class ExpressionCodegen(
|
||||
expression
|
||||
)
|
||||
|
||||
val returnType = callee.returnType.substitute(typeSubstitutionMap)
|
||||
val returnType = callee.returnType
|
||||
|
||||
if (callee.isSuspend && !irFunction.isInvokeSuspendInContinuation()) {
|
||||
addSuspendMarker(mv, isStartNotEnd = false)
|
||||
|
||||
+16
-1
@@ -349,6 +349,7 @@ private class AddContinuationLowering(private val context: JvmBackendContext) :
|
||||
private fun addContinuationParameter(irFile: IrFile, suspendLambdas: Set<IrFunction>): Set<IrFunction> {
|
||||
val views = hashSetOf<IrFunction>()
|
||||
|
||||
// Collect all suspend functions
|
||||
irFile.acceptVoid(object : IrElementVisitorVoid {
|
||||
override fun visitElement(element: IrElement) {
|
||||
element.acceptChildrenVoid(this)
|
||||
@@ -363,6 +364,20 @@ private class AddContinuationLowering(private val context: JvmBackendContext) :
|
||||
}
|
||||
}
|
||||
})
|
||||
// fix return targets
|
||||
for (view in views) {
|
||||
view.transformChildrenVoid(object : IrElementTransformerVoid() {
|
||||
override fun visitReturn(expression: IrReturn): IrExpression {
|
||||
val owner = expression.returnTargetSymbol.owner as? IrSimpleFunction
|
||||
?: return super.visitReturn(expression)
|
||||
val ownerView = owner.getOrCreateView()
|
||||
if (ownerView == owner) return super.visitReturn(expression)
|
||||
val result =
|
||||
IrReturnImpl(expression.startOffset, expression.endOffset, ownerView.returnType, ownerView.symbol, expression.value)
|
||||
return super.visitReturn(result)
|
||||
}
|
||||
})
|
||||
}
|
||||
return views
|
||||
}
|
||||
|
||||
@@ -416,7 +431,7 @@ private class AddContinuationLowering(private val context: JvmBackendContext) :
|
||||
override fun visitCall(expression: IrCall): IrExpression {
|
||||
if (!expression.isSuspend) return super.visitCall(expression)
|
||||
val view = (expression.symbol.owner as IrSimpleFunction).getOrCreateView()
|
||||
val res = IrCallImpl(expression.startOffset, expression.endOffset, expression.type, view.symbol).apply {
|
||||
val res = IrCallImpl(expression.startOffset, expression.endOffset, view.returnType, view.symbol).apply {
|
||||
copyTypeArgumentsFrom(expression)
|
||||
dispatchReceiver = expression.dispatchReceiver
|
||||
for (i in 0 until expression.valueArgumentsCount) {
|
||||
|
||||
+8
-1
@@ -18,10 +18,14 @@ import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFunctionImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrValueParameterSymbol
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.getClass
|
||||
import org.jetbrains.kotlin.ir.util.constructedClass
|
||||
import org.jetbrains.kotlin.ir.util.defaultType
|
||||
import org.jetbrains.kotlin.ir.util.explicitParameters
|
||||
import org.jetbrains.kotlin.ir.util.fqNameWhenAvailable
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
||||
|
||||
class IrReplacementFunction(
|
||||
@@ -49,7 +53,10 @@ class MemoizedInlineClassReplacements {
|
||||
}
|
||||
|
||||
private val IrFunction.hasInlineClassParameters: Boolean
|
||||
get() = explicitParameters.any { it.type.erasedUpperBound.isInline } || (this is IrConstructor && constructedClass.isInline)
|
||||
get() = explicitParameters.any { it.type.erasedUpperBound.isInline && !it.type.isDontMangleType() }
|
||||
|| (this is IrConstructor && constructedClass.isInline)
|
||||
|
||||
private fun IrType.isDontMangleType() = getClass()?.fqNameWhenAvailable == DescriptorUtils.RESULT_FQ_NAME
|
||||
|
||||
private val IrFunction.hasStaticReplacement: Boolean
|
||||
get() = origin != IrDeclarationOrigin.FAKE_OVERRIDE &&
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_RUNTIME
|
||||
// FULL_JDK
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// WITH_RUNTIME
|
||||
// WITH_COROUTINES
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// WITH_RUNTIME
|
||||
// WITH_COROUTINES
|
||||
// COMMON_COROUTINES_TEST
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// KJS_WITH_FULL_RUNTIME
|
||||
// WITH_RUNTIME
|
||||
// WITH_COROUTINES
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// WITH_RUNTIME
|
||||
// WITH_COROUTINES
|
||||
// COMMON_COROUTINES_TEST
|
||||
|
||||
Reference in New Issue
Block a user