Do not generate ACONST_NULL as continuation of crossinline suspend lambda

This commit is contained in:
Ilmir Usmanov
2018-03-01 17:50:18 +03:00
parent 6b7173ba13
commit 81f3e39f29
7 changed files with 76 additions and 2 deletions
@@ -1103,7 +1103,11 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
if (closure.isSuspend()) {
// resultContinuation
if (closure.isSuspendLambda()) {
v.aconst(null);
boolean isCrossinlineLambda = (callGenerator instanceof InlineCodegen<?>) &&
Objects.requireNonNull(((InlineCodegen) callGenerator).getActiveLambda()).isCrossInline;
if (!isCrossinlineLambda) {
v.aconst(null);
}
}
else {
assert context.getFunctionDescriptor().isSuspend() : "Coroutines closure must be created only inside suspend functions";
@@ -87,7 +87,7 @@ abstract class InlineCodegen<out T: BaseExpressionCodegen>(
protected val expressionMap = linkedMapOf<Int, LambdaInfo>()
protected var activeLambda: LambdaInfo? = null
var activeLambda: LambdaInfo? = null; protected set
private val defaultSourceMapper = sourceCompiler.lazySourceMapper
@@ -0,0 +1,46 @@
// FILE: inlined.kt
// WITH_RUNTIME
// NO_CHECK_LAMBDA_INLINING
import kotlin.coroutines.experimental.*
import kotlin.coroutines.experimental.intrinsics.*
inline suspend fun suspendThere(v: String): String = suspendCoroutineOrReturn { x ->
x.resume(v)
COROUTINE_SUSPENDED
}
suspend inline fun complexSuspend(crossinline c: suspend () -> String): String {
return run {
c()
}
}
// FILE: inleneSite.kt
import kotlin.coroutines.experimental.*
import kotlin.coroutines.experimental.intrinsics.*
fun builder(c: suspend () -> Unit) {
c.startCoroutine(object: Continuation<Unit> {
override val context: CoroutineContext
get() = EmptyCoroutineContext
override fun resume(value: Unit) {
}
override fun resumeWithException(exception: Throwable) {
throw exception
}
})
}
suspend fun suspendHere(): String = suspendThere("O")
fun box(): String {
var result = ""
builder {
result = suspendHere() + complexSuspend { suspendThere("K") }
}
return result
}
@@ -3477,6 +3477,12 @@ public class IrBlackBoxInlineCodegenTestGenerated extends AbstractIrBlackBoxInli
doTest(fileName);
}
@TestMetadata("returnValue.kt")
public void testReturnValue() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/suspend/returnValue.kt");
doTest(fileName);
}
@TestMetadata("tryCatchStackTransform.kt")
public void testTryCatchStackTransform() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/suspend/tryCatchStackTransform.kt");
@@ -3477,6 +3477,12 @@ public class IrCompileKotlinAgainstInlineKotlinTestGenerated extends AbstractIrC
doTest(fileName);
}
@TestMetadata("returnValue.kt")
public void testReturnValue() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/suspend/returnValue.kt");
doTest(fileName);
}
@TestMetadata("tryCatchStackTransform.kt")
public void testTryCatchStackTransform() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/suspend/tryCatchStackTransform.kt");
@@ -3477,6 +3477,12 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo
doTest(fileName);
}
@TestMetadata("returnValue.kt")
public void testReturnValue() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/suspend/returnValue.kt");
doTest(fileName);
}
@TestMetadata("tryCatchStackTransform.kt")
public void testTryCatchStackTransform() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/suspend/tryCatchStackTransform.kt");
@@ -3477,6 +3477,12 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
doTest(fileName);
}
@TestMetadata("returnValue.kt")
public void testReturnValue() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/suspend/returnValue.kt");
doTest(fileName);
}
@TestMetadata("tryCatchStackTransform.kt")
public void testTryCatchStackTransform() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/suspend/tryCatchStackTransform.kt");