From daa76cbf1e43fbe0b8fd37e8fe249e08cd1c1295 Mon Sep 17 00:00:00 2001 From: Ilmir Usmanov Date: Mon, 9 Dec 2019 18:51:57 +0300 Subject: [PATCH] JVM_IR: Support inner objects with multiple suspend functions Do not clean `functionsToAdd` --- .../kotlin/backend/jvm/lower/AddContinuationLowering.kt | 8 ++++++-- .../suspend/stateMachine/innerObjectSeveralFunctions.kt | 2 -- .../suspend/stateMachine/oneInlineTwoCaptures.kt | 2 -- 3 files changed, 6 insertions(+), 6 deletions(-) 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 5e9b54469ed..67ad8abcc87 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 @@ -560,13 +560,13 @@ private class AddContinuationLowering(private val context: JvmBackendContext) : copyBodyFrom(function) copyAttributes(function) } - functionsToAdd[function.parentAsClass] = mutableSetOf(newFunction) + registerNewFunction(function.parentAsClass, newFunction) } val newFunction = if (function.isOverridable) { // Create static method for the suspend state machine method so that reentering the method // does not lead to virtual dispatch to the wrong method. - functionsToAdd.getOrPut(function.parentAsClass) { mutableSetOf() }.add(function) + registerNewFunction(function.parentAsClass, function) createStaticSuspendImpl(function) } else function @@ -602,6 +602,10 @@ private class AddContinuationLowering(private val context: JvmBackendContext) : }) } + private fun registerNewFunction(container: IrClass, function: IrFunction) { + functionsToAdd.getOrPut(container) { mutableSetOf() }.add(function) + } + private fun markSuspendLambdas(irElement: IrElement): Pair, List> { val suspendLambdas = arrayListOf() val inlineLambdas = mutableSetOf() diff --git a/compiler/testData/codegen/boxInline/suspend/stateMachine/innerObjectSeveralFunctions.kt b/compiler/testData/codegen/boxInline/suspend/stateMachine/innerObjectSeveralFunctions.kt index bc882d77405..d3ae1435f04 100644 --- a/compiler/testData/codegen/boxInline/suspend/stateMachine/innerObjectSeveralFunctions.kt +++ b/compiler/testData/codegen/boxInline/suspend/stateMachine/innerObjectSeveralFunctions.kt @@ -1,5 +1,3 @@ -// IGNORE_BACKEND: JVM_IR -// IGNORE_BACKEND_MULTI_MODULE: JVM_IR // FILE: inlined.kt // COMMON_COROUTINES_TEST // WITH_RUNTIME diff --git a/compiler/testData/codegen/boxInline/suspend/stateMachine/oneInlineTwoCaptures.kt b/compiler/testData/codegen/boxInline/suspend/stateMachine/oneInlineTwoCaptures.kt index 24978d8f08f..85fce7eea6a 100644 --- a/compiler/testData/codegen/boxInline/suspend/stateMachine/oneInlineTwoCaptures.kt +++ b/compiler/testData/codegen/boxInline/suspend/stateMachine/oneInlineTwoCaptures.kt @@ -1,5 +1,3 @@ -// IGNORE_BACKEND: JVM_IR -// IGNORE_BACKEND_MULTI_MODULE: JVM_IR // COMMON_COROUTINES_TEST // WITH_RUNTIME // WITH_COROUTINES