JVM_IR: Also check attributes for suspendImpls when generating continuation

Otherwise, it would not generate continuations for overloads.
This commit is contained in:
Ilmir Usmanov
2019-12-27 16:04:36 +01:00
parent d17afddaa9
commit 4d9d62ad12
9 changed files with 94 additions and 3 deletions
@@ -134,12 +134,14 @@ open class FunctionCodegen(
// This is just a template for inliner
origin != JvmLoweredDeclarationOrigin.FOR_INLINE_STATE_MACHINE_TEMPLATE_CAPTURES_CROSSINLINE &&
// Continuations are generated for suspendImpls
parentAsClass.functions.none { it.name.asString() == name.asString() + SUSPEND_IMPL_NAME_SUFFIX } &&
parentAsClass.functions.none {
it.name.asString() == name.asString() + SUSPEND_IMPL_NAME_SUFFIX &&
it.attributeOwnerId == (this as? IrAttributeContainer)?.attributeOwnerId
} &&
// $$forInline functions never have a continuation
origin != JvmLoweredDeclarationOrigin.FOR_INLINE_STATE_MACHINE_TEMPLATE
private fun continuationClass(): IrClass =
irFunction.body!!.statements.firstIsInstance() ?: error("No continuation class generated for ${irFunction.name}")
private fun continuationClass() = irFunction.body!!.statements.firstIsInstance<IrClass>()
private fun IrFunction.getVisibilityForDefaultArgumentStub(): Int =
when (visibility) {
@@ -524,6 +524,7 @@ private class AddContinuationLowering(private val context: JvmBackendContext) :
}
})
}
static.copyAttributes(irFunction)
return static
}
@@ -0,0 +1,43 @@
// IGNORE_BACKEND_FIR: JVM_IR
// WITH_RUNTIME
// WITH_COROUTINES
// COMMON_COROUTINES_TEST
import helpers.*
import COROUTINES_PACKAGE.*
import COROUTINES_PACKAGE.intrinsics.*
open class A(val v: String) {
suspend fun suspendThere(v: String): String = suspendCoroutineUninterceptedOrReturn { x ->
x.resume(v)
COROUTINE_SUSPENDED
}
open suspend fun suspendHere(): String = suspendThere("O") + suspendThere(v)
}
class B(v: String) : A(v) {
override suspend fun suspendHere(): String = super.suspendHere() + suspendThere("56")
suspend fun suspendHere(s: String): String = super.suspendHere() + suspendThere(s)
}
fun builder(c: suspend A.() -> Unit) {
c.startCoroutine(B("K"), EmptyContinuation)
}
fun box(): String {
var result = ""
builder {
result = suspendHere()
}
if (result != "OK56") return "fail 1: $result"
builder {
result = (this as B).suspendHere("OK")
}
if (result != "OKOK") return "fail 2: $result"
return "OK"
}
@@ -8458,6 +8458,16 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/superCallInterface.kt", "kotlin.coroutines");
}
@TestMetadata("superCallOverload.kt")
public void testSuperCallOverload_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/superCallOverload.kt", "kotlin.coroutines.experimental");
}
@TestMetadata("superCallOverload.kt")
public void testSuperCallOverload_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/superCallOverload.kt", "kotlin.coroutines");
}
@TestMetadata("superCall.kt")
public void testSuperCall_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/superCall.kt", "kotlin.coroutines.experimental");
@@ -8458,6 +8458,16 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/superCallInterface.kt", "kotlin.coroutines");
}
@TestMetadata("superCallOverload.kt")
public void testSuperCallOverload_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/superCallOverload.kt", "kotlin.coroutines.experimental");
}
@TestMetadata("superCallOverload.kt")
public void testSuperCallOverload_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/superCallOverload.kt", "kotlin.coroutines");
}
@TestMetadata("superCall.kt")
public void testSuperCall_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/superCall.kt", "kotlin.coroutines.experimental");
@@ -7418,6 +7418,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/superCallInterface.kt", "kotlin.coroutines");
}
@TestMetadata("superCallOverload.kt")
public void testSuperCallOverload_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/superCallOverload.kt", "kotlin.coroutines");
}
@TestMetadata("superCall.kt")
public void testSuperCall_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/superCall.kt", "kotlin.coroutines");
@@ -7418,6 +7418,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/superCallInterface.kt", "kotlin.coroutines");
}
@TestMetadata("superCallOverload.kt")
public void testSuperCallOverload_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/superCallOverload.kt", "kotlin.coroutines");
}
@TestMetadata("superCall.kt")
public void testSuperCall_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/superCall.kt", "kotlin.coroutines");
@@ -6348,6 +6348,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/superCallInterface.kt", "kotlin.coroutines");
}
@TestMetadata("superCallOverload.kt")
public void testSuperCallOverload_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/superCallOverload.kt", "kotlin.coroutines");
}
@TestMetadata("superCall.kt")
public void testSuperCall_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/superCall.kt", "kotlin.coroutines");
@@ -7313,6 +7313,16 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/superCallInterface.kt", "kotlin.coroutines");
}
@TestMetadata("superCallOverload.kt")
public void testSuperCallOverload_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/superCallOverload.kt", "kotlin.coroutines.experimental");
}
@TestMetadata("superCallOverload.kt")
public void testSuperCallOverload_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/superCallOverload.kt", "kotlin.coroutines");
}
@TestMetadata("superCall.kt")
public void testSuperCall_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/superCall.kt", "kotlin.coroutines.experimental");