JVM IR: Do not unbox Results in suspend lambda invoke methods (KT-46813)
This commit is contained in:
committed by
Ilmir Usmanov
parent
ff3f3d2f9b
commit
984e912f8d
+6
@@ -9240,6 +9240,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
|||||||
runTest("compiler/testData/codegen/box/coroutines/kt45377.kt");
|
runTest("compiler/testData/codegen/box/coroutines/kt45377.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt46813.kt")
|
||||||
|
public void testKt46813() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/coroutines/kt46813.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("lastExpressionIsLoop.kt")
|
@TestMetadata("lastExpressionIsLoop.kt")
|
||||||
public void testLastExpressionIsLoop() throws Exception {
|
public void testLastExpressionIsLoop() throws Exception {
|
||||||
|
|||||||
+9
-1
@@ -59,6 +59,7 @@ import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterKind
|
|||||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
|
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
|
||||||
import org.jetbrains.kotlin.types.TypeSystemCommonBackendContext
|
import org.jetbrains.kotlin.types.TypeSystemCommonBackendContext
|
||||||
import org.jetbrains.kotlin.types.model.TypeParameterMarker
|
import org.jetbrains.kotlin.types.model.TypeParameterMarker
|
||||||
|
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||||
import org.jetbrains.kotlin.utils.keysToMap
|
import org.jetbrains.kotlin.utils.keysToMap
|
||||||
@@ -628,7 +629,7 @@ class ExpressionCodegen(
|
|||||||
|
|
||||||
val initializer = declaration.initializer
|
val initializer = declaration.initializer
|
||||||
if (initializer != null) {
|
if (initializer != null) {
|
||||||
var value = initializer.accept(this, data)
|
val value = initializer.accept(this, data)
|
||||||
initializer.markLineNumber(startOffset = true)
|
initializer.markLineNumber(startOffset = true)
|
||||||
value.materializeAt(varType, declaration.type)
|
value.materializeAt(varType, declaration.type)
|
||||||
declaration.markLineNumber(startOffset = true)
|
declaration.markLineNumber(startOffset = true)
|
||||||
@@ -676,6 +677,13 @@ class ExpressionCodegen(
|
|||||||
// Result parameter of SAM-wrapper to Java SAM is already unboxed in visitGetValue, do not unbox it anymore
|
// Result parameter of SAM-wrapper to Java SAM is already unboxed in visitGetValue, do not unbox it anymore
|
||||||
if (irFunction.parentAsClass.superTypes.any { it.getClass()?.isFromJava() == true }) return
|
if (irFunction.parentAsClass.superTypes.any { it.getClass()?.isFromJava() == true }) return
|
||||||
|
|
||||||
|
// Do not unbox Results in suspend lambda `invoke` methods. These just forward to `invokeSuspend`,
|
||||||
|
// where the arguments are unboxed.
|
||||||
|
if (
|
||||||
|
irFunction.parentAsClass.origin == JvmLoweredDeclarationOrigin.SUSPEND_LAMBDA &&
|
||||||
|
irFunction.name == OperatorNameConventions.INVOKE
|
||||||
|
) return
|
||||||
|
|
||||||
StackValue.unboxInlineClass(OBJECT_TYPE, arg.type.erasedUpperBound.defaultType, mv, typeMapper)
|
StackValue.unboxInlineClass(OBJECT_TYPE, arg.type.erasedUpperBound.defaultType, mv, typeMapper)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
import kotlin.coroutines.*
|
||||||
|
|
||||||
|
fun <T, R> T.map(transform: suspend (T) -> R): suspend () -> R =
|
||||||
|
{ transform(this) }
|
||||||
|
|
||||||
|
fun runs(f: suspend () -> String?): String {
|
||||||
|
var result: String? = ""
|
||||||
|
f.startCoroutine(Continuation(EmptyCoroutineContext) { result = it.getOrThrow() })
|
||||||
|
return result ?: "Fail"
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
return runs {
|
||||||
|
Result.success("OK").map<Result<String>, String?> { it.getOrNull() }()
|
||||||
|
}
|
||||||
|
}
|
||||||
+6
@@ -9240,6 +9240,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
runTest("compiler/testData/codegen/box/coroutines/kt45377.kt");
|
runTest("compiler/testData/codegen/box/coroutines/kt45377.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt46813.kt")
|
||||||
|
public void testKt46813() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/coroutines/kt46813.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("lastExpressionIsLoop.kt")
|
@TestMetadata("lastExpressionIsLoop.kt")
|
||||||
public void testLastExpressionIsLoop() throws Exception {
|
public void testLastExpressionIsLoop() throws Exception {
|
||||||
|
|||||||
+6
@@ -9240,6 +9240,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
runTest("compiler/testData/codegen/box/coroutines/kt45377.kt");
|
runTest("compiler/testData/codegen/box/coroutines/kt45377.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt46813.kt")
|
||||||
|
public void testKt46813() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/coroutines/kt46813.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("lastExpressionIsLoop.kt")
|
@TestMetadata("lastExpressionIsLoop.kt")
|
||||||
public void testLastExpressionIsLoop() throws Exception {
|
public void testLastExpressionIsLoop() throws Exception {
|
||||||
|
|||||||
+5
@@ -7209,6 +7209,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
runTest("compiler/testData/codegen/box/coroutines/kt45377.kt");
|
runTest("compiler/testData/codegen/box/coroutines/kt45377.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt46813.kt")
|
||||||
|
public void testKt46813() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/coroutines/kt46813.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("lastExpressionIsLoop.kt")
|
@TestMetadata("lastExpressionIsLoop.kt")
|
||||||
public void testLastExpressionIsLoop() throws Exception {
|
public void testLastExpressionIsLoop() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt");
|
runTest("compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt");
|
||||||
|
|||||||
js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java
Generated
+5
@@ -6423,6 +6423,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
|
|||||||
runTest("compiler/testData/codegen/box/coroutines/kt45377.kt");
|
runTest("compiler/testData/codegen/box/coroutines/kt45377.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt46813.kt")
|
||||||
|
public void testKt46813() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/coroutines/kt46813.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("lastExpressionIsLoop.kt")
|
@TestMetadata("lastExpressionIsLoop.kt")
|
||||||
public void testLastExpressionIsLoop() throws Exception {
|
public void testLastExpressionIsLoop() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt");
|
runTest("compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt");
|
||||||
|
|||||||
Generated
+5
@@ -5829,6 +5829,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/coroutines/kt45377.kt");
|
runTest("compiler/testData/codegen/box/coroutines/kt45377.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt46813.kt")
|
||||||
|
public void testKt46813() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/coroutines/kt46813.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("lastExpressionIsLoop.kt")
|
@TestMetadata("lastExpressionIsLoop.kt")
|
||||||
public void testLastExpressionIsLoop() throws Exception {
|
public void testLastExpressionIsLoop() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt");
|
runTest("compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt");
|
||||||
|
|||||||
Generated
+5
@@ -5829,6 +5829,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/coroutines/kt45377.kt");
|
runTest("compiler/testData/codegen/box/coroutines/kt45377.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt46813.kt")
|
||||||
|
public void testKt46813() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/coroutines/kt46813.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("lastExpressionIsLoop.kt")
|
@TestMetadata("lastExpressionIsLoop.kt")
|
||||||
public void testLastExpressionIsLoop() throws Exception {
|
public void testLastExpressionIsLoop() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt");
|
runTest("compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user