From 537ce05bc97c1a1f712e17f9ec1b186eeafc9f67 Mon Sep 17 00:00:00 2001 From: pyos Date: Thu, 17 Jun 2021 09:40:04 +0200 Subject: [PATCH] JVM_IR: assume function reference adapters are tail-call Meaning, they never need continuation objects. This shouldn't affect correctness (if the assumption is valid, the continuation object should always have been removed in the end), but the phantom continuation sometimes left behind unused accessors (and in case of inline function references, those accessors would refer to non-existent functions) - see the modified test and Kotlin/kotlinx.coroutines#2769. --- .../jetbrains/kotlin/backend/jvm/codegen/CoroutineCodegen.kt | 2 ++ .../box/coroutines/suspendConversion/onInlineArgument_ir.txt | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) 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 72fcdae73a5..9efd745a1a1 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 @@ -151,6 +151,8 @@ private val BRIDGE_ORIGINS = setOf( JvmLoweredDeclarationOrigin.SUPER_INTERFACE_METHOD_BRIDGE, IrDeclarationOrigin.BRIDGE, IrDeclarationOrigin.BRIDGE_SPECIAL, + IrDeclarationOrigin.ADAPTER_FOR_CALLABLE_REFERENCE, + IrDeclarationOrigin.ADAPTER_FOR_SUSPEND_CONVERSION ) // These functions contain a single `suspend` tail call, the value of which should be returned as is diff --git a/compiler/testData/codegen/box/coroutines/suspendConversion/onInlineArgument_ir.txt b/compiler/testData/codegen/box/coroutines/suspendConversion/onInlineArgument_ir.txt index 706a082c98a..6c9913ff606 100644 --- a/compiler/testData/codegen/box/coroutines/suspendConversion/onInlineArgument_ir.txt +++ b/compiler/testData/codegen/box/coroutines/suspendConversion/onInlineArgument_ir.txt @@ -8,7 +8,6 @@ final class OnInlineArgumentKt$box$1 { field label: int inner (anonymous) class OnInlineArgumentKt$box$1 method (p0: kotlin.jvm.internal.Ref$ObjectRef, p1: kotlin.jvm.functions.Function1, p2: kotlin.coroutines.Continuation): void - public synthetic final static method access$invokeSuspend$suspendConversion0(p0: kotlin.jvm.functions.Function1, p1: java.lang.String, p2: kotlin.coroutines.Continuation): java.lang.Object public final @org.jetbrains.annotations.NotNull method create(@org.jetbrains.annotations.NotNull p0: kotlin.coroutines.Continuation): kotlin.coroutines.Continuation public final @org.jetbrains.annotations.Nullable method invoke(@org.jetbrains.annotations.Nullable p0: kotlin.coroutines.Continuation): java.lang.Object public synthetic bridge method invoke(p0: java.lang.Object): java.lang.Object