Skip to content

Commit

Permalink
[K/JS] Fix coroutines but turn back the fix for coroutines intrinsics…
Browse files Browse the repository at this point in the history
… `intercepted` and `releaseIntercepted`
  • Loading branch information
JSMonk authored and qodana-bot committed Nov 22, 2023
1 parent 8293c8f commit 5d6520c
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,8 +526,7 @@ private val innerClassConstructorCallsLoweringPhase = makeBodyLoweringPhase(
private val suspendFunctionsLoweringPhase = makeBodyLoweringPhase(
::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 = makeDeclarationTransformerPhase(
Expand Down Expand Up @@ -739,7 +738,7 @@ private val inlineClassUsageLoweringPhase = makeBodyLoweringPhase(
)

private val autoboxingTransformerPhase = makeBodyLoweringPhase(
::AutoboxingTransformer,
{ AutoboxingTransformer(it, replaceTypesInsideInlinedFunctionBlock = true) },
name = "AutoboxingTransformer",
description = "Insert box/unbox intrinsics"
)
Expand Down Expand Up @@ -922,14 +921,14 @@ val loweringList = listOf<Lowering>(
enumUsageLoweringPhase,
externalEnumUsageLoweringPhase,
enumEntryRemovalLoweringPhase,
returnableBlockLoweringPhase,
suspendFunctionsLoweringPhase,
propertyReferenceLoweringPhase,
interopCallableReferenceLoweringPhase,
jsSuspendArityStorePhase,
addContinuationToNonLocalSuspendFunctionsLoweringPhase,
addContinuationToLocalSuspendFunctionsLoweringPhase,
addContinuationToFunctionCallsLoweringPhase,
returnableBlockLoweringPhase,
rangeContainsLoweringPhase,
forLoopsLoweringPhase,
primitiveCompanionLoweringPhase,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// WITH_STDLIB
// WITH_COROUTINES
// IGNORE_BACKEND: JS_IR, JS_IR_ES6
import helpers.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// WITH_STDLIB
// IGNORE_BACKEND: JS_IR, JS_IR_ES6
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@ suspend fun box() {
// test.kt:12 doResume:
// test.kt:8 h: $completion=$boxCOROUTINE$0
// test.kt:4 doResume:
// test.kt:5 doResume: x=41:number
// test.kt:4 doResume: x=41:number
// test.kt:5 doResume: x=41:number, x=41:number
// test.kt:19 doResume: x=41:number, x=41:number
1 change: 0 additions & 1 deletion compiler/testData/debug/localVariables/suspend/mergeLvt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,5 @@ suspend fun box() {
// test.kt:12 <get-a>:
// test.kt:38 doResume:
// test.kt:38 doResume:
// test.kt:38 doResume:
// test.kt:27 doResume:
// test.kt:28 doResume: a=Unit
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,5 @@ suspend fun box() {
// test.kt:7 id: obj=2:number
// test.kt:38 doResume: c=1:number, b=2:number
// test.kt:38 doResume: c=1:number, b=2:number
// test.kt:39 doResume: c=1:number, b=2:number
// test.kt:30 doResume: c=1:number, b=2:number
// test.kt:31 doResume: c=1:number, b=2:number, a=Unit
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,5 @@ suspend fun box() {
// EXPECTATIONS JS_IR
// test.kt:31 doResume:
// test.kt:31 doResume:
// test.kt:31 doResume:
// test.kt:22 doResume:
// test.kt:23 doResume: a=Unit
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,5 @@ suspend fun box() {
// test.kt:7 id: obj=5:number
// test.kt:44 doResume: b=2:number, e=5:number
// test.kt:44 doResume: b=2:number, e=5:number
// test.kt:45 doResume: b=2:number, e=5:number
// test.kt:33 doResume: b=2:number, e=5:number
// test.kt:37 doResume: b=2:number, e=5:number, result=Unit
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// IGNORE_BACKEND: JS_IR, JS_IR_ES6
// DONT_TARGET_EXACT_BACKEND: JS

var demoCallCounter = 0
Expand Down
2 changes: 1 addition & 1 deletion js/js.translator/testData/lineNumbers/coroutine.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ suspend fun bar(): Unit {
}

// LINES(JS): 39 4 4 4 7 5 5 45 45 5 93 45 5 5 6 4 4 4 9 15 9 9 9 * 9 15 10 10 11 11 11 11 11 * 11 12 12 13 13 13 13 13 13 13 14 14 * 9 15 9 9 9 9
// LINES(JS_IR): 4 4 * 9 9 * 4 * 4 * 19 5 5 * 19 * 19 19 * 19 19 * 6 6 * 19 * 19 * 4 * 9 * 9 * 10 10 * 11 * 11 12 12 * 13 * 13 14 14 15 15
// LINES(JS_IR): 4 4 * 93 3 45 45 7 7 6 9 9 * 9 * 9 * 10 10 * 11 * 11 12 12 * 13 * 13 14 14 15 15

0 comments on commit 5d6520c

Please sign in to comment.