From 8886e1b8b4b38506144da6e8952edeef304bc3ab Mon Sep 17 00:00:00 2001 From: Pavel Kunyavskiy Date: Fri, 2 Sep 2022 12:30:26 +0200 Subject: [PATCH] Move Js suspend functions lowerings to common code --- .../kotlin/backend/common/Mappings.kt | 4 +- .../jetbrains/kotlin/backend/common/ir/Ir.kt | 4 +- .../AddContinuationToFunctionCallsLowering.kt | 75 +++++++++++++++++ .../AddContinuationToFunctionsLowering.kt | 27 ++++--- .../ir/backend/js/JsIrBackendContext.kt | 4 +- .../kotlin/ir/backend/js/JsLoweringPhases.kt | 4 +- .../kotlin/ir/backend/js/JsMapping.kt | 5 +- .../AddContinuationToFunctionCallsLowering.kt | 80 ++++--------------- .../coroutines/JsSuspendFunctionsLowering.kt | 3 +- .../lower/coroutines/SuspendLoweringUtils.kt | 5 +- .../kotlin/backend/jvm/JvmSymbols.kt | 4 +- .../kotlin/backend/wasm/WasmLoweringPhases.kt | 4 +- .../kotlin/backend/wasm/WasmSymbols.kt | 4 +- .../jetbrains/kotlin/backend/konan/ir/Ir.kt | 2 + 14 files changed, 130 insertions(+), 95 deletions(-) create mode 100644 compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/coroutines/AddContinuationToFunctionCallsLowering.kt rename compiler/ir/{backend.js/src/org/jetbrains/kotlin/ir/backend/js => backend.common/src/org/jetbrains/kotlin/backend/common}/lower/coroutines/AddContinuationToFunctionsLowering.kt (85%) diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/Mappings.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/Mappings.kt index 2e0830f547f..0d6794e9374 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/Mappings.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/Mappings.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -19,6 +19,7 @@ interface Mapping { val capturedFields: Delegate> val capturedConstructors: Delegate val reflectedNameAccessor: Delegate + val suspendFunctionsToFunctionWithContinuations: Delegate abstract class Delegate { abstract operator fun get(key: K): V? @@ -75,6 +76,7 @@ open class DefaultMapping(delegateFactory: DelegateFactory = DefaultDelegateFact override val capturedFields: Mapping.Delegate> = delegateFactory.newDeclarationToDeclarationCollectionMapping() override val capturedConstructors: Mapping.Delegate = delegateFactory.newDeclarationToDeclarationMapping() override val reflectedNameAccessor: Mapping.Delegate = delegateFactory.newDeclarationToDeclarationMapping() + override val suspendFunctionsToFunctionWithContinuations: Mapping.Delegate = delegateFactory.newDeclarationToDeclarationMapping() } fun KMutableProperty0.getOrPut(fn: () -> V) = this.get() ?: fn().also { diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/ir/Ir.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/ir/Ir.kt index c5fe75998bf..c46b62373f1 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/ir/Ir.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/ir/Ir.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -224,6 +224,8 @@ abstract class Symbols( abstract val getContinuation: IrSimpleFunctionSymbol + abstract val continuationClass: IrClassSymbol + abstract val coroutineContextGetter: IrSimpleFunctionSymbol abstract val suspendCoroutineUninterceptedOrReturn: IrSimpleFunctionSymbol diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/coroutines/AddContinuationToFunctionCallsLowering.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/coroutines/AddContinuationToFunctionCallsLowering.kt new file mode 100644 index 00000000000..55bcd46d367 --- /dev/null +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/coroutines/AddContinuationToFunctionCallsLowering.kt @@ -0,0 +1,75 @@ +/* + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.backend.common.lower.coroutines + +import org.jetbrains.kotlin.backend.common.BodyLoweringPass +import org.jetbrains.kotlin.backend.common.CommonBackendContext +import org.jetbrains.kotlin.backend.common.lower.createIrBuilder +import org.jetbrains.kotlin.backend.common.runOnFilePostfix +import org.jetbrains.kotlin.ir.builders.irGet +import org.jetbrains.kotlin.ir.declarations.* +import org.jetbrains.kotlin.ir.expressions.IrBody +import org.jetbrains.kotlin.ir.expressions.IrCall +import org.jetbrains.kotlin.ir.expressions.IrExpression +import org.jetbrains.kotlin.ir.util.irCall +import org.jetbrains.kotlin.ir.util.isSuspend +import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid +import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid + +/** + * Add continuation to suspend function calls. + * + * Additionally materialize continuation for `getContinuation` intrinsic calls. + */ +abstract class AbstractAddContinuationToFunctionCallsLowering : BodyLoweringPass { + abstract val context: CommonBackendContext + override fun lower(irFile: IrFile) { + runOnFilePostfix(irFile, withLocalDeclarations = true) + } + + abstract fun IrSimpleFunction.getContinuationParameter() : IrValueParameter + + + override fun lower(irBody: IrBody, container: IrDeclaration) { + val continuation: IrValueParameter by lazy { + (container as IrSimpleFunction).getContinuationParameter() + } + + val builder by lazy { context.createIrBuilder(container.symbol) } + fun getContinuation() = builder.irGet(continuation) + + irBody.transformChildrenVoid(object : IrElementTransformerVoid() { + override fun visitBody(body: IrBody): IrBody { + // Nested bodies are covered by separate `lower` invocation + return body + } + + override fun visitCall(expression: IrCall): IrExpression { + expression.transformChildrenVoid() + + if (!expression.isSuspend) { + if (expression.symbol == context.ir.symbols.getContinuation) + return getContinuation() + return expression + } + + val oldFun = expression.symbol.owner + val newFun: IrSimpleFunction = oldFun.getOrCreateFunctionWithContinuationStub(context) + + return irCall( + expression, + newFun.symbol, + newReturnType = newFun.returnType, + newSuperQualifierSymbol = expression.superQualifierSymbol + ).also { + it.putValueArgument(it.valueArgumentsCount - 1, getContinuation()) + } + } + }) + } +} + + diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/coroutines/AddContinuationToFunctionsLowering.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/coroutines/AddContinuationToFunctionsLowering.kt similarity index 85% rename from compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/coroutines/AddContinuationToFunctionsLowering.kt rename to compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/coroutines/AddContinuationToFunctionsLowering.kt index 285bd72cd7b..57265470295 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/coroutines/AddContinuationToFunctionsLowering.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/coroutines/AddContinuationToFunctionsLowering.kt @@ -1,17 +1,18 @@ /* - * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ -package org.jetbrains.kotlin.ir.backend.js.lower.coroutines +package org.jetbrains.kotlin.backend.common.lower.coroutines import org.jetbrains.kotlin.backend.common.BodyLoweringPass +import org.jetbrains.kotlin.backend.common.CommonBackendContext import org.jetbrains.kotlin.backend.common.DeclarationTransformer import org.jetbrains.kotlin.backend.common.getOrPut import org.jetbrains.kotlin.backend.common.ir.* import org.jetbrains.kotlin.backend.common.lower.createIrBuilder +import org.jetbrains.kotlin.ir.IrBuiltIns import org.jetbrains.kotlin.ir.IrStatement -import org.jetbrains.kotlin.ir.backend.js.JsCommonBackendContext import org.jetbrains.kotlin.ir.builders.declarations.addValueParameter import org.jetbrains.kotlin.ir.builders.declarations.buildFun import org.jetbrains.kotlin.ir.builders.irReturnUnit @@ -21,6 +22,7 @@ import org.jetbrains.kotlin.ir.expressions.IrBody import org.jetbrains.kotlin.ir.expressions.IrReturn import org.jetbrains.kotlin.ir.symbols.IrValueSymbol import org.jetbrains.kotlin.ir.types.IrType +import org.jetbrains.kotlin.ir.types.isNullable import org.jetbrains.kotlin.ir.types.typeWith import org.jetbrains.kotlin.ir.util.* import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid @@ -34,7 +36,7 @@ import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid * functions can return special values like [kotlin.coroutines.intrinsics.COROUTINE_SUSPENDED] * which might not be a subtype of original return type. */ -class AddContinuationToNonLocalSuspendFunctionsLowering(val context: JsCommonBackendContext) : DeclarationTransformer { +class AddContinuationToNonLocalSuspendFunctionsLowering(val context: CommonBackendContext) : DeclarationTransformer { override fun transformFlat(declaration: IrDeclaration): List? = if (declaration is IrSimpleFunction && declaration.isSuspend) { listOf(transformSuspendFunction(context, declaration)) @@ -47,7 +49,7 @@ class AddContinuationToNonLocalSuspendFunctionsLowering(val context: JsCommonBac * Similar to [AddContinuationToNonLocalSuspendFunctionsLowering] but processes local functions. * Useful for Kotlin/JS IR backend which keeps local declarations up until code generation. */ -class AddContinuationToLocalSuspendFunctionsLowering(val context: JsCommonBackendContext) : BodyLoweringPass { +class AddContinuationToLocalSuspendFunctionsLowering(val context: CommonBackendContext) : BodyLoweringPass { override fun lower(irBody: IrBody, container: IrDeclaration) { irBody.transformChildrenVoid(object : IrElementTransformerVoid() { override fun visitSimpleFunction(declaration: IrSimpleFunction): IrStatement { @@ -63,7 +65,7 @@ class AddContinuationToLocalSuspendFunctionsLowering(val context: JsCommonBacken } -private fun transformSuspendFunction(context: JsCommonBackendContext, function: IrSimpleFunction): IrSimpleFunction { +private fun transformSuspendFunction(context: CommonBackendContext, function: IrSimpleFunction): IrSimpleFunction { val newFunctionWithContinuation = function.getOrCreateFunctionWithContinuationStub(context) // Using custom mapping because number of parameters doesn't match val parameterMapping = function.explicitParameters.zip(newFunctionWithContinuation.explicitParameters).toMap() @@ -84,13 +86,13 @@ private fun transformSuspendFunction(context: JsCommonBackendContext, function: } -fun IrSimpleFunction.getOrCreateFunctionWithContinuationStub(context: JsCommonBackendContext): IrSimpleFunction { +fun IrSimpleFunction.getOrCreateFunctionWithContinuationStub(context: CommonBackendContext): IrSimpleFunction { return context.mapping.suspendFunctionsToFunctionWithContinuations.getOrPut(this) { createSuspendFunctionStub(context) } } -private fun IrSimpleFunction.createSuspendFunctionStub(context: JsCommonBackendContext): IrSimpleFunction { +private fun IrSimpleFunction.createSuspendFunctionStub(context: CommonBackendContext): IrSimpleFunction { require(this.isSuspend) return factory.buildFun { updateFrom(this@createSuspendFunctionStub) @@ -127,6 +129,9 @@ private fun IrSimpleFunction.createSuspendFunctionStub(context: JsCommonBackendC } } -private fun IrFunction.continuationType(context: JsCommonBackendContext): IrType { - return context.coroutineSymbols.continuationClass.typeWith(returnType) -} \ No newline at end of file +private fun IrFunction.continuationType(context: CommonBackendContext): IrType { + return context.ir.symbols.continuationClass.typeWith(returnType) +} + +fun loweredSuspendFunctionReturnType(function: IrFunction, irBuiltIns: IrBuiltIns): IrType = + if (function.returnType.isNullable()) irBuiltIns.anyNType else irBuiltIns.anyType \ No newline at end of file diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIrBackendContext.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIrBackendContext.kt index 3c877ce4828..767082ec79c 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIrBackendContext.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIrBackendContext.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -243,6 +243,8 @@ class JsIrBackendContext( override val getContinuation = symbolTable.referenceSimpleFunction(getJsInternalFunction("getContinuation")) + override val continuationClass = context.coroutineSymbols.continuationClass + override val coroutineContextGetter = symbolTable.referenceSimpleFunction(context.coroutineSymbols.coroutineContextProperty.getter!!) diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsLoweringPhases.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsLoweringPhases.kt index 09f1ead9517..8b0e6493c7e 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsLoweringPhases.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsLoweringPhases.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -7,6 +7,8 @@ package org.jetbrains.kotlin.ir.backend.js import org.jetbrains.kotlin.backend.common.* import org.jetbrains.kotlin.backend.common.lower.* +import org.jetbrains.kotlin.backend.common.lower.coroutines.AddContinuationToLocalSuspendFunctionsLowering +import org.jetbrains.kotlin.backend.common.lower.coroutines.AddContinuationToNonLocalSuspendFunctionsLowering import org.jetbrains.kotlin.backend.common.lower.inline.FunctionInlining import org.jetbrains.kotlin.backend.common.lower.inline.LocalClassesExtractionFromInlineFunctionsLowering import org.jetbrains.kotlin.backend.common.lower.inline.LocalClassesInInlineFunctionsLowering diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsMapping.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsMapping.kt index 2e0b9915c48..2587d1ef160 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsMapping.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsMapping.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -31,9 +31,6 @@ class JsMapping : DefaultMapping() { val fieldToEnumEntry = DefaultDelegateFactory.newDeclarationToDeclarationMapping() val enumClassToInitEntryInstancesFun = DefaultDelegateFactory.newDeclarationToDeclarationMapping() - val suspendFunctionsToFunctionWithContinuations = - DefaultDelegateFactory.newDeclarationToDeclarationMapping() - val suspendArityStore = DefaultDelegateFactory.newDeclarationToDeclarationCollectionMapping>() // Wasm mappings diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/coroutines/AddContinuationToFunctionCallsLowering.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/coroutines/AddContinuationToFunctionCallsLowering.kt index 64266950a1c..5a71c7608eb 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/coroutines/AddContinuationToFunctionCallsLowering.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/coroutines/AddContinuationToFunctionCallsLowering.kt @@ -1,79 +1,27 @@ /* - * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.ir.backend.js.lower.coroutines -import org.jetbrains.kotlin.backend.common.BodyLoweringPass -import org.jetbrains.kotlin.backend.common.lower.createIrBuilder -import org.jetbrains.kotlin.backend.common.runOnFilePostfix +import org.jetbrains.kotlin.backend.common.lower.coroutines.AbstractAddContinuationToFunctionCallsLowering import org.jetbrains.kotlin.ir.backend.js.JsCommonBackendContext -import org.jetbrains.kotlin.ir.builders.irGet -import org.jetbrains.kotlin.ir.declarations.* -import org.jetbrains.kotlin.ir.expressions.IrBody -import org.jetbrains.kotlin.ir.expressions.IrCall -import org.jetbrains.kotlin.ir.expressions.IrExpression -import org.jetbrains.kotlin.ir.util.irCall -import org.jetbrains.kotlin.ir.util.isSuspend -import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid -import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid +import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction +import org.jetbrains.kotlin.ir.declarations.IrValueParameter /** - * Add continuation to suspend function calls. Requires [AddContinuationToLocalSuspendFunctionsLowering] and + * Requires [AddContinuationToLocalSuspendFunctionsLowering] and * [AddContinuationToNonLocalSuspendFunctionsLowering] to transform function declarations first. - * - * Additionally materialize continuation for `getContinuation` intrinsic calls. */ -class AddContinuationToFunctionCallsLowering(val context: JsCommonBackendContext) : BodyLoweringPass { - override fun lower(irFile: IrFile) { - runOnFilePostfix(irFile, withLocalDeclarations = true) - } - - override fun lower(irBody: IrBody, container: IrDeclaration) { - val continuation: IrValueParameter by lazy { - val function = container as IrSimpleFunction - if (function.overriddenSymbols - .any { it.owner.name.asString() == "doResume" && it.owner.parent == context.coroutineSymbols.coroutineImpl.owner } - ) { - function.dispatchReceiverParameter!! - } else { - function.valueParameters.last() +class AddContinuationToFunctionCallsLowering(override val context: JsCommonBackendContext) : AbstractAddContinuationToFunctionCallsLowering() { + override fun IrSimpleFunction.getContinuationParameter(): IrValueParameter = + if (overriddenSymbols.any { + it.owner.name.asString() == "doResume" && it.owner.parent == context.coroutineSymbols.coroutineImpl.owner } + ) { + dispatchReceiverParameter!! + } else { + valueParameters.last() } - - val builder by lazy { context.createIrBuilder(container.symbol) } - fun getContinuation() = builder.irGet(continuation) - - irBody.transformChildrenVoid(object : IrElementTransformerVoid() { - override fun visitBody(body: IrBody): IrBody { - // Nested bodies are covered by separate `lower` invocation - return body - } - - override fun visitCall(expression: IrCall): IrExpression { - expression.transformChildrenVoid() - - if (!expression.isSuspend) { - if (expression.symbol == context.ir.symbols.getContinuation) - return getContinuation() - return expression - } - - val oldFun = expression.symbol.owner - // TODO: investigate why mapping might be unavailable for SuspendFunction4.invoke - val newFun: IrSimpleFunction = oldFun.getOrCreateFunctionWithContinuationStub(context) - - return irCall( - expression, - newFun.symbol, - newReturnType = newFun.returnType, - newSuperQualifierSymbol = expression.superQualifierSymbol - ).also { - it.putValueArgument(it.valueArgumentsCount - 1, getContinuation()) - } - } - }) - } -} - +} \ No newline at end of file diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/coroutines/JsSuspendFunctionsLowering.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/coroutines/JsSuspendFunctionsLowering.kt index ae53168985c..e7c9f26c6c0 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/coroutines/JsSuspendFunctionsLowering.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/coroutines/JsSuspendFunctionsLowering.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -9,6 +9,7 @@ import org.jetbrains.kotlin.backend.common.descriptors.synthesizedName import org.jetbrains.kotlin.backend.common.lower.FinallyBlocksLowering import org.jetbrains.kotlin.ir.backend.js.JsStatementOrigins import org.jetbrains.kotlin.backend.common.lower.ReturnableBlockTransformer +import org.jetbrains.kotlin.backend.common.lower.coroutines.loweredSuspendFunctionReturnType import org.jetbrains.kotlin.ir.backend.js.JsCommonBackendContext import org.jetbrains.kotlin.ir.backend.js.ir.JsIrBuilder import org.jetbrains.kotlin.ir.builders.* diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/coroutines/SuspendLoweringUtils.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/coroutines/SuspendLoweringUtils.kt index 306e86fb772..652ab343d16 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/coroutines/SuspendLoweringUtils.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/coroutines/SuspendLoweringUtils.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -111,6 +111,3 @@ class LiveLocalsTransformer( } } } - -fun loweredSuspendFunctionReturnType(function: IrFunction, irBuiltIns: IrBuiltIns): IrType = - if (function.returnType.isNullable()) irBuiltIns.anyNType else irBuiltIns.anyType \ No newline at end of file diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmSymbols.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmSymbols.kt index b55f24dc606..38c911d4e88 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmSymbols.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmSymbols.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -284,7 +284,7 @@ class JvmSymbols( val noSuchFieldErrorType = javaLangNoSuchFieldError.defaultType - val continuationClass: IrClassSymbol = + override val continuationClass: IrClassSymbol = createClass(StandardNames.CONTINUATION_INTERFACE_FQ_NAME, ClassKind.INTERFACE) { klass -> klass.addTypeParameter("T", irBuiltIns.anyNType, Variance.IN_VARIANCE) } diff --git a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/WasmLoweringPhases.kt b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/WasmLoweringPhases.kt index 3f345070944..b2848922b29 100644 --- a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/WasmLoweringPhases.kt +++ b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/WasmLoweringPhases.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -16,7 +16,7 @@ import org.jetbrains.kotlin.backend.common.toMultiModuleAction import org.jetbrains.kotlin.backend.wasm.lower.* import org.jetbrains.kotlin.ir.backend.js.lower.* import org.jetbrains.kotlin.ir.backend.js.lower.coroutines.AddContinuationToFunctionCallsLowering -import org.jetbrains.kotlin.ir.backend.js.lower.coroutines.AddContinuationToNonLocalSuspendFunctionsLowering +import org.jetbrains.kotlin.backend.common.lower.coroutines.AddContinuationToNonLocalSuspendFunctionsLowering import org.jetbrains.kotlin.ir.backend.js.lower.coroutines.JsSuspendFunctionsLowering import org.jetbrains.kotlin.ir.backend.js.lower.inline.RemoveInlineDeclarationsWithReifiedTypeParametersLowering import org.jetbrains.kotlin.ir.backend.wasm.lower.generateMainFunctionCalls diff --git a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/WasmSymbols.kt b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/WasmSymbols.kt index 0487dd5b830..b6e9868ae30 100644 --- a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/WasmSymbols.kt +++ b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/WasmSymbols.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -96,6 +96,8 @@ class WasmSymbols( context.coroutineSymbols.coroutineSuspendedGetter override val getContinuation = getInternalFunction("getContinuation") + override val continuationClass = + context.coroutineSymbols.continuationClass override val coroutineContextGetter = symbolTable.referenceSimpleFunction(context.coroutineSymbols.coroutineContextProperty.getter!!) override val suspendCoroutineUninterceptedOrReturn = diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/Ir.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/Ir.kt index 554fc0af69f..764ad775e4c 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/Ir.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/Ir.kt @@ -320,6 +320,8 @@ internal class KonanSymbols( override val getContinuation = internalFunction("getContinuation") + override val continuationClass = irBuiltIns.findClass(Name.identifier("Continuation"), StandardNames.COROUTINES_PACKAGE_FQ_NAME)!! + override val returnIfSuspended = internalFunction("returnIfSuspended") val coroutineLaunchpad = internalFunction("coroutineLaunchpad")