[K/JS] Fix coroutines but turn back the fix for coroutines intrinsics intercepted and releaseIntercepted

This commit is contained in:
Artem Kobzar
2023-11-22 18:10:08 +00:00
committed by Space Team
parent d8ee74222f
commit 33ab1871c7
12 changed files with 18 additions and 13 deletions
@@ -34,7 +34,8 @@ import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
* TODO: consider making this visitor non-recursive to make it more general.
*/
abstract class AbstractValueUsageTransformer(
protected val irBuiltIns: IrBuiltIns
protected val irBuiltIns: IrBuiltIns,
private val replaceTypesInsideInlinedFunctionBlock: Boolean = false
) : IrElementTransformerVoid() {
protected open fun IrExpression.useAs(type: IrType): IrExpression = this
@@ -120,7 +121,7 @@ abstract class AbstractValueUsageTransformer(
}
override fun visitContainerExpression(expression: IrContainerExpression): IrExpression {
if (expression is IrInlinedFunctionBlock) {
if (!replaceTypesInsideInlinedFunctionBlock && expression is IrInlinedFunctionBlock) {
expression.transformChildrenVoid(this)
return expression
}
@@ -429,8 +429,7 @@ private val innerClassConstructorCallsLoweringPhase = makeIrModulePhase<JsIrBack
private val suspendFunctionsLoweringPhase = makeIrModulePhase(
::JsSuspendFunctionsLowering,
name = "SuspendFunctionsLowering",
description = "Transform suspend functions into CoroutineImpl instance and build state machine",
prerequisite = setOf(returnableBlockLoweringPhase)
description = "Transform suspend functions into CoroutineImpl instance and build state machine"
)
private val addContinuationToNonLocalSuspendFunctionsLoweringPhase = makeIrModulePhase(
@@ -642,7 +641,7 @@ private val inlineClassUsageLoweringPhase = makeIrModulePhase(
)
private val autoboxingTransformerPhase = makeIrModulePhase<JsIrBackendContext>(
::AutoboxingTransformer,
{ AutoboxingTransformer(it, replaceTypesInsideInlinedFunctionBlock = true) },
name = "AutoboxingTransformer",
description = "Insert box/unbox intrinsics"
)
@@ -827,7 +826,6 @@ val loweringList = listOf<SimpleNamedCompilerPhase<JsIrBackendContext, IrModuleF
enumUsageLoweringPhase,
externalEnumUsageLoweringPhase,
enumEntryRemovalLoweringPhase,
returnableBlockLoweringPhase,
suspendFunctionsLoweringPhase,
propertyReferenceLoweringPhase,
interopCallableReferenceLoweringPhase,
@@ -835,6 +833,7 @@ val loweringList = listOf<SimpleNamedCompilerPhase<JsIrBackendContext, IrModuleF
addContinuationToNonLocalSuspendFunctionsLoweringPhase,
addContinuationToLocalSuspendFunctionsLoweringPhase,
addContinuationToFunctionCallsLoweringPhase,
returnableBlockLoweringPhase,
rangeContainsLoweringPhase,
forLoopsLoweringPhase,
primitiveCompanionLoweringPhase,
@@ -31,7 +31,10 @@ import org.jetbrains.kotlin.ir.util.render
// Copied and adapted from Kotlin/Native
abstract class AbstractValueUsageLowering(val context: JsCommonBackendContext) : AbstractValueUsageTransformer(context.irBuiltIns),
abstract class AbstractValueUsageLowering(
val context: JsCommonBackendContext,
replaceTypesInsideInlinedFunctionBlock: Boolean = false
) : AbstractValueUsageTransformer(context.irBuiltIns, replaceTypesInsideInlinedFunctionBlock),
BodyLoweringPass {
val icUtils = context.inlineClassesUtils
@@ -120,7 +123,8 @@ abstract class AbstractValueUsageLowering(val context: JsCommonBackendContext) :
)
}
class AutoboxingTransformer(context: JsCommonBackendContext) : AbstractValueUsageLowering(context) {
class AutoboxingTransformer(context: JsCommonBackendContext, replaceTypesInsideInlinedFunctionBlock: Boolean = false) :
AbstractValueUsageLowering(context, replaceTypesInsideInlinedFunctionBlock) {
private var processingReturnStack = mutableListOf<IrReturn>()
private fun IrExpression.useReturnableExpressionAsType(expectedType: IrType): IrExpression {