[K/JS] Fix corutines build for 1.9.20

This reverts commit f0d6471a8bcbdfc52ddc840a6383032ef86976d1.
This commit is contained in:
Artem Kobzar
2023-08-31 14:24:45 +02:00
parent 1a36a06a07
commit 857c07fa25
7 changed files with 6 additions and 77 deletions
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.backend.common.lower.inline.LocalClassesInInlineFunc
import org.jetbrains.kotlin.backend.common.lower.inline.LocalClassesInInlineLambdasLowering
import org.jetbrains.kotlin.backend.common.lower.loops.ForLoopsLowering
import org.jetbrains.kotlin.backend.common.phaser.*
import org.jetbrains.kotlin.config.CommonConfigurationKeys
import org.jetbrains.kotlin.ir.backend.js.lower.*
import org.jetbrains.kotlin.ir.backend.js.lower.calls.CallsLowering
import org.jetbrains.kotlin.ir.backend.js.lower.cleanup.CleanupLowering
@@ -22,6 +23,7 @@ import org.jetbrains.kotlin.ir.backend.js.lower.coroutines.AddContinuationToFunc
import org.jetbrains.kotlin.ir.backend.js.lower.coroutines.JsSuspendArityStoreLowering
import org.jetbrains.kotlin.ir.backend.js.lower.coroutines.JsSuspendFunctionsLowering
import org.jetbrains.kotlin.ir.backend.js.lower.inline.*
import org.jetbrains.kotlin.ir.backend.js.transformers.irToJs.JsGenerationGranularity
import org.jetbrains.kotlin.ir.declarations.IrFile
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
import org.jetbrains.kotlin.ir.interpreter.IrInterpreterConfiguration
@@ -736,7 +738,7 @@ private val inlineClassUsageLoweringPhase = makeBodyLoweringPhase(
)
private val autoboxingTransformerPhase = makeBodyLoweringPhase(
{ AutoboxingTransformer(it, shouldCalculateActualTypeForInlinedFunction = true) },
::AutoboxingTransformer,
name = "AutoboxingTransformer",
description = "Insert box/unbox intrinsics"
)
@@ -31,10 +31,7 @@ import org.jetbrains.kotlin.ir.util.render
// Copied and adapted from Kotlin/Native
abstract class AbstractValueUsageLowering(
val context: JsCommonBackendContext,
private val shouldCalculateActualTypeForInlinedFunction: Boolean = false
) : AbstractValueUsageTransformer(context.irBuiltIns),
abstract class AbstractValueUsageLowering(val context: JsCommonBackendContext) : AbstractValueUsageTransformer(context.irBuiltIns),
BodyLoweringPass {
val icUtils = context.inlineClassesUtils
@@ -55,19 +52,11 @@ abstract class AbstractValueUsageLowering(
abstract fun IrExpression.useExpressionAsType(actualType: IrType, expectedType: IrType): IrExpression
protected fun IrExpression.getActualType(): IrType = when (this) {
protected fun IrExpression.getActualType() = when (this) {
is IrConstructorCall -> symbol.owner.returnType
is IrCall -> symbol.owner.realOverrideTarget.returnType
is IrGetField -> this.symbol.owner.type
is IrInlinedFunctionBlock -> {
if (shouldCalculateActualTypeForInlinedFunction) {
inlineCall.getActualType()
} else {
this.type
}
}
is IrTypeOperatorCall -> {
if (operator == IrTypeOperator.REINTERPRET_CAST) {
this.typeOperand
@@ -131,10 +120,7 @@ abstract class AbstractValueUsageLowering(
)
}
class AutoboxingTransformer(
context: JsCommonBackendContext,
shouldCalculateActualTypeForInlinedFunction: Boolean = false
) : AbstractValueUsageLowering(context, shouldCalculateActualTypeForInlinedFunction) {
class AutoboxingTransformer(context: JsCommonBackendContext) : AbstractValueUsageLowering(context) {
private var processingReturnStack = mutableListOf<IrReturn>()
private fun IrExpression.useReturnableExpressionAsType(expectedType: IrType): IrExpression {
@@ -872,12 +872,6 @@ public class FirJsBoxTestGenerated extends AbstractFirJsBoxTest {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/coroutines"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true);
}
@Test
@TestMetadata("boxingUnboxingInsideTheSuspendFunction.kt")
public void testBoxingUnboxingInsideTheSuspendFunction() throws Exception {
runTest("js/js.translator/testData/box/coroutines/boxingUnboxingInsideTheSuspendFunction.kt");
}
@Test
@TestMetadata("debugStatement.kt")
public void testDebugStatement() throws Exception {
@@ -872,12 +872,6 @@ public class FirJsES6BoxTestGenerated extends AbstractFirJsES6BoxTest {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/coroutines"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR_ES6, true);
}
@Test
@TestMetadata("boxingUnboxingInsideTheSuspendFunction.kt")
public void testBoxingUnboxingInsideTheSuspendFunction() throws Exception {
runTest("js/js.translator/testData/box/coroutines/boxingUnboxingInsideTheSuspendFunction.kt");
}
@Test
@TestMetadata("debugStatement.kt")
public void testDebugStatement() throws Exception {
@@ -872,12 +872,6 @@ public class IrBoxJsES6TestGenerated extends AbstractIrBoxJsES6Test {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/coroutines"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR_ES6, true);
}
@Test
@TestMetadata("boxingUnboxingInsideTheSuspendFunction.kt")
public void testBoxingUnboxingInsideTheSuspendFunction() throws Exception {
runTest("js/js.translator/testData/box/coroutines/boxingUnboxingInsideTheSuspendFunction.kt");
}
@Test
@TestMetadata("debugStatement.kt")
public void testDebugStatement() throws Exception {
@@ -872,12 +872,6 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/coroutines"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true);
}
@Test
@TestMetadata("boxingUnboxingInsideTheSuspendFunction.kt")
public void testBoxingUnboxingInsideTheSuspendFunction() throws Exception {
runTest("js/js.translator/testData/box/coroutines/boxingUnboxingInsideTheSuspendFunction.kt");
}
@Test
@TestMetadata("debugStatement.kt")
public void testDebugStatement() throws Exception {
@@ -1,35 +0,0 @@
// WITH_STDLIB
// EXPECTED_REACHABLE_NODES: 1292
// KT-60785
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
value class SomeValue(val a: String) {
override fun toString() = when (a) {
"fa" -> "O"
"il" -> "K"
else -> ""
}
}
suspend fun foo() = mapOf(SomeValue("fa") to SomeValue("il"))
fun builder(c: suspend () -> Unit) {
c.startCoroutine(object : Continuation<Unit> {
override val context = EmptyCoroutineContext
override fun resumeWith(result: Result<Unit>) {}
})
}
fun box(): String {
var result = ""
builder {
for ((k, v) in foo()) {
result += "$k$v"
}
}
return result
}