From 08074bb60e8d3647681314e7903fea66e952f996 Mon Sep 17 00:00:00 2001 From: pyos Date: Thu, 6 Feb 2020 10:19:16 +0100 Subject: [PATCH] JVM_IR: wrap inline suspend references in suspend lambdas --- .../kotlin/backend/jvm/codegen/CoroutineCodegen.kt | 1 + .../kotlin/backend/jvm/lower/AddContinuationLowering.kt | 1 + .../backend/jvm/lower/InlineCallableReferenceToLambda.kt | 6 +++--- .../box/coroutines/simpleSuspendCallableReference.kt | 2 +- .../codegen/boxInline/suspend/callableReference/simple.kt | 2 -- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/CoroutineCodegen.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/CoroutineCodegen.kt index 3c738c73c3e..ad339d0c7f8 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/CoroutineCodegen.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/CoroutineCodegen.kt @@ -119,6 +119,7 @@ internal fun IrFunction.isKnownToBeTailCall(): Boolean = JvmLoweredDeclarationOrigin.SYNTHETIC_ACCESSOR, JvmLoweredDeclarationOrigin.DEFAULT_IMPLS_BRIDGE, JvmLoweredDeclarationOrigin.DEFAULT_IMPLS_BRIDGE_TO_SYNTHETIC, + JvmLoweredDeclarationOrigin.GENERATED_MEMBER_IN_CALLABLE_REFERENCE, IrDeclarationOrigin.BRIDGE, IrDeclarationOrigin.BRIDGE_SPECIAL, IrDeclarationOrigin.DELEGATED_MEMBER -> true diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AddContinuationLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AddContinuationLowering.kt index d2b277b958d..9ec9225a3e5 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AddContinuationLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AddContinuationLowering.kt @@ -653,6 +653,7 @@ private class AddContinuationLowering(private val context: JvmBackendContext) : function.body == null || function.parentAsClass.origin == JvmLoweredDeclarationOrigin.FUNCTION_REFERENCE_IMPL || function.origin == IrDeclarationOrigin.FUNCTION_FOR_DEFAULT_PARAMETER || + function.origin == JvmLoweredDeclarationOrigin.GENERATED_MEMBER_IN_CALLABLE_REFERENCE || function.origin == JvmLoweredDeclarationOrigin.DEFAULT_IMPLS_BRIDGE private fun skip(function: IrFunction) = diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InlineCallableReferenceToLambda.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InlineCallableReferenceToLambda.kt index 2ee95d92a21..6464c4398a8 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InlineCallableReferenceToLambda.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InlineCallableReferenceToLambda.kt @@ -127,7 +127,7 @@ internal class InlineCallableReferenceToLambdaPhase(val context: JvmBackendConte name = Name.identifier("stub_for_inlining") visibility = Visibilities.LOCAL returnType = referencedFunction.returnType - isSuspend = false + isSuspend = referencedFunction.isSuspend }.apply { for ((index, argumentType) in argumentTypes.withIndex()) { addValueParameter { @@ -137,12 +137,12 @@ internal class InlineCallableReferenceToLambdaPhase(val context: JvmBackendConte } body = this@InlineCallableReferenceToLambdaPhase.context.createJvmIrBuilder( - this.symbol, + symbol, expression.startOffset, expression.endOffset ).run { irExprBody(irCall(referencedFunction).apply { - this@apply.symbol.owner.allTypeParameters.forEach { + symbol.owner.allTypeParameters.forEach { putTypeArgument(it.index, expression.getTypeArgument(it.index)) } diff --git a/compiler/testData/codegen/box/coroutines/simpleSuspendCallableReference.kt b/compiler/testData/codegen/box/coroutines/simpleSuspendCallableReference.kt index c286cb24528..7658be3dd6c 100644 --- a/compiler/testData/codegen/box/coroutines/simpleSuspendCallableReference.kt +++ b/compiler/testData/codegen/box/coroutines/simpleSuspendCallableReference.kt @@ -1,6 +1,6 @@ // !LANGUAGE: +ReleaseCoroutines // IGNORE_BACKEND_FIR: JVM_IR -// IGNORE_BACKEND: JVM_IR, JS_IR, NATIVE +// IGNORE_BACKEND: JS_IR, NATIVE // WITH_RUNTIME // WITH_COROUTINES import helpers.* diff --git a/compiler/testData/codegen/boxInline/suspend/callableReference/simple.kt b/compiler/testData/codegen/boxInline/suspend/callableReference/simple.kt index 02adba37490..071bd8d88dc 100644 --- a/compiler/testData/codegen/boxInline/suspend/callableReference/simple.kt +++ b/compiler/testData/codegen/boxInline/suspend/callableReference/simple.kt @@ -1,6 +1,4 @@ // !LANGUAGE: +ReleaseCoroutines -// IGNORE_BACKEND: JVM_IR -// IGNORE_BACKEND_MULTI_MODULE: JVM_IR // NO_CHECK_LAMBDA_INLINING // FILE: test.kt