[Wasm] Fix for ReturnableBlockLowering invalid ir type for converted inlined blocks

This commit is contained in:
Igor Yakovlev
2023-04-11 15:32:36 +02:00
committed by Space Team
parent 08273623e6
commit edf4e80165
17 changed files with 126 additions and 6 deletions
@@ -10375,6 +10375,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr
runTest("compiler/testData/codegen/box/coroutines/infiniteLoopInNextMeaningful.kt");
}
@Test
@TestMetadata("inlineCallWithReturns.kt")
public void testInlineCallWithReturns() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/inlineCallWithReturns.kt");
}
@Test
@TestMetadata("inlineFunInGenericClass.kt")
public void testInlineFunInGenericClass() throws Exception {
@@ -10375,6 +10375,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo
runTest("compiler/testData/codegen/box/coroutines/infiniteLoopInNextMeaningful.kt");
}
@Test
@TestMetadata("inlineCallWithReturns.kt")
public void testInlineCallWithReturns() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/inlineCallWithReturns.kt");
}
@Test
@TestMetadata("inlineFunInGenericClass.kt")
public void testInlineFunInGenericClass() throws Exception {
@@ -127,14 +127,20 @@ class ReturnableBlockTransformer(val context: CommonBackendContext, val containe
}
}
val newStatements = expression.statements.mapIndexed { i, s ->
if (expression.statements.size == 1 && s is IrInlinedFunctionBlock) {
for ((j, statement) in s.statements.withIndex()) {
s.statements[j] = transformSingleStatement(statement, j == s.statements.lastIndex)
val newStatements = expression.statements.mapIndexed { i, currentStatement ->
if (expression.statements.size == 1 && currentStatement is IrInlinedFunctionBlock) {
val lastIndex = currentStatement.statements.lastIndex
for ((j, statement) in currentStatement.statements.withIndex()) {
val lastInList = j == lastIndex
val transformedStatement = transformSingleStatement(statement, lastInList)
currentStatement.statements[j] = transformedStatement
if (lastInList) {
currentStatement.type = (transformedStatement as? IrExpression)?.type ?: context.irBuiltIns.unitType
}
}
s
currentStatement
} else {
transformSingleStatement(s, i == expression.statements.lastIndex)
transformSingleStatement(currentStatement, i == expression.statements.lastIndex)
}
}
@@ -164,6 +170,7 @@ class ReturnableBlockTransformer(val context: CommonBackendContext, val containe
// In case of Unit return type we don't need to return an explicit value. This will not be optimized by JVM backend and
// may result in exceptions in `MethodVerifier` before optimizations.
// Also note that `UNDEFINED_OFFSET` is needed to make proper line number for JVM.
expression.type = context.irBuiltIns.unitType
+at(UNDEFINED_OFFSET, UNDEFINED_OFFSET).irGet(variable)
}
}
@@ -0,0 +1,25 @@
// WITH_STDLIB
import kotlin.coroutines.*
suspend fun <T> withCorutine(block: suspend () -> Unit): Unit {
block()
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(Continuation(EmptyCoroutineContext) {
it.getOrThrow()
})
}
inline fun f(): Int {
if (42 != 42) return 12345
return 67890
}
fun box(): String {
builder {
check(f() == 67890)
}
return "OK"
}
@@ -10117,6 +10117,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/coroutines/infiniteLoopInNextMeaningful.kt");
}
@Test
@TestMetadata("inlineCallWithReturns.kt")
public void testInlineCallWithReturns() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/inlineCallWithReturns.kt");
}
@Test
@TestMetadata("inlineFunInGenericClass.kt")
public void testInlineFunInGenericClass() throws Exception {
@@ -10375,6 +10375,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/coroutines/infiniteLoopInNextMeaningful.kt");
}
@Test
@TestMetadata("inlineCallWithReturns.kt")
public void testInlineCallWithReturns() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/inlineCallWithReturns.kt");
}
@Test
@TestMetadata("inlineFunInGenericClass.kt")
public void testInlineFunInGenericClass() throws Exception {
@@ -10375,6 +10375,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack
runTest("compiler/testData/codegen/box/coroutines/infiniteLoopInNextMeaningful.kt");
}
@Test
@TestMetadata("inlineCallWithReturns.kt")
public void testInlineCallWithReturns() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/inlineCallWithReturns.kt");
}
@Test
@TestMetadata("inlineFunInGenericClass.kt")
public void testInlineFunInGenericClass() throws Exception {
@@ -7967,6 +7967,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/coroutines/infiniteLoopInNextMeaningful.kt");
}
@TestMetadata("inlineCallWithReturns.kt")
public void testInlineCallWithReturns() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/inlineCallWithReturns.kt");
}
@TestMetadata("inlineFunInGenericClass.kt")
public void testInlineFunInGenericClass() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/inlineFunInGenericClass.kt");
@@ -7125,6 +7125,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/coroutines/infiniteLoopInNextMeaningful.kt");
}
@Test
@TestMetadata("inlineCallWithReturns.kt")
public void testInlineCallWithReturns() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/inlineCallWithReturns.kt");
}
@Test
@TestMetadata("inlineFunInGenericClass.kt")
public void testInlineFunInGenericClass() throws Exception {
@@ -7221,6 +7221,12 @@ public class FirJsCodegenBoxTestGenerated extends AbstractFirJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/coroutines/infiniteLoopInNextMeaningful.kt");
}
@Test
@TestMetadata("inlineCallWithReturns.kt")
public void testInlineCallWithReturns() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/inlineCallWithReturns.kt");
}
@Test
@TestMetadata("inlineFunInGenericClass.kt")
public void testInlineFunInGenericClass() throws Exception {
@@ -7221,6 +7221,12 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/coroutines/infiniteLoopInNextMeaningful.kt");
}
@Test
@TestMetadata("inlineCallWithReturns.kt")
public void testInlineCallWithReturns() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/inlineCallWithReturns.kt");
}
@Test
@TestMetadata("inlineFunInGenericClass.kt")
public void testInlineFunInGenericClass() throws Exception {
@@ -7221,6 +7221,12 @@ public class IrJsES6CodegenBoxTestGenerated extends AbstractIrJsES6CodegenBoxTes
runTest("compiler/testData/codegen/box/coroutines/infiniteLoopInNextMeaningful.kt");
}
@Test
@TestMetadata("inlineCallWithReturns.kt")
public void testInlineCallWithReturns() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/inlineCallWithReturns.kt");
}
@Test
@TestMetadata("inlineFunInGenericClass.kt")
public void testInlineFunInGenericClass() throws Exception {
@@ -8266,6 +8266,12 @@ public class FirNativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTe
runTest("compiler/testData/codegen/box/coroutines/infiniteLoopInNextMeaningful.kt");
}
@Test
@TestMetadata("inlineCallWithReturns.kt")
public void testInlineCallWithReturns() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/inlineCallWithReturns.kt");
}
@Test
@TestMetadata("inlineFunInGenericClass.kt")
public void testInlineFunInGenericClass() throws Exception {
@@ -8444,6 +8444,12 @@ public class FirNativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenB
runTest("compiler/testData/codegen/box/coroutines/infiniteLoopInNextMeaningful.kt");
}
@Test
@TestMetadata("inlineCallWithReturns.kt")
public void testInlineCallWithReturns() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/inlineCallWithReturns.kt");
}
@Test
@TestMetadata("inlineFunInGenericClass.kt")
public void testInlineFunInGenericClass() throws Exception {
@@ -8177,6 +8177,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest
runTest("compiler/testData/codegen/box/coroutines/infiniteLoopInNextMeaningful.kt");
}
@Test
@TestMetadata("inlineCallWithReturns.kt")
public void testInlineCallWithReturns() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/inlineCallWithReturns.kt");
}
@Test
@TestMetadata("inlineFunInGenericClass.kt")
public void testInlineFunInGenericClass() throws Exception {
@@ -8355,6 +8355,12 @@ public class NativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenBoxT
runTest("compiler/testData/codegen/box/coroutines/infiniteLoopInNextMeaningful.kt");
}
@Test
@TestMetadata("inlineCallWithReturns.kt")
public void testInlineCallWithReturns() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/inlineCallWithReturns.kt");
}
@Test
@TestMetadata("inlineFunInGenericClass.kt")
public void testInlineFunInGenericClass() throws Exception {
@@ -6352,6 +6352,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
runTest("compiler/testData/codegen/box/coroutines/infiniteLoopInNextMeaningful.kt");
}
@TestMetadata("inlineCallWithReturns.kt")
public void testInlineCallWithReturns() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/inlineCallWithReturns.kt");
}
@TestMetadata("inlineFunInGenericClass.kt")
public void testInlineFunInGenericClass() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/inlineFunInGenericClass.kt");