[K/N] Fix default argument lambda in suspend function code generation

This commit is contained in:
Pavel Kunyavskiy
2023-03-15 19:02:36 +01:00
committed by Space Team
parent 484d3ad273
commit e655e0a809
15 changed files with 156 additions and 0 deletions
@@ -10249,6 +10249,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr
runTest("compiler/testData/codegen/box/coroutines/defaultParametersInSuspendWithJvmOverloads.kt");
}
@Test
@TestMetadata("defaultParamterLambdaInSuspend.kt")
public void testDefaultParamterLambdaInSuspend() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/defaultParamterLambdaInSuspend.kt");
}
@Test
@TestMetadata("delegatedSuspendMember.kt")
public void testDelegatedSuspendMember() throws Exception {
@@ -10249,6 +10249,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo
runTest("compiler/testData/codegen/box/coroutines/defaultParametersInSuspendWithJvmOverloads.kt");
}
@Test
@TestMetadata("defaultParamterLambdaInSuspend.kt")
public void testDefaultParamterLambdaInSuspend() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/defaultParamterLambdaInSuspend.kt");
}
@Test
@TestMetadata("delegatedSuspendMember.kt")
public void testDelegatedSuspendMember() throws Exception {
@@ -0,0 +1,71 @@
// WITH_STDLIB
// WITH_COROUTINES
// lowered IR can be dependent on file order here, so we will test both
// FILE: A.kt
import helpers.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
class Controller1 {
suspend fun suspendHere(block : () -> String = { "DEF" }): String = suspendCoroutineUninterceptedOrReturn { x ->
x.resume(block())
COROUTINE_SUSPENDED
}
}
fun builder1(c: suspend Controller1.() -> Unit) {
c.startCoroutine(Controller1(), EmptyContinuation)
}
// FILE: B.kt
import helpers.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
fun box(): String {
var result = "FAIL 1"
builder1 {
if (suspendHere() != "DEF") {
result = "FAIL"
return@builder1
}
result = suspendHere { "OK" }
}
if (result != "OK") return result
result = "FAIL 2"
builder2 {
if (suspendHere() != "DEF") {
result = "FAIL"
return@builder2
}
result = suspendHere { "OK" }
}
return result
}
// FILE: C.kt
import helpers.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
class Controller2 {
suspend fun suspendHere(block : () -> String = { "DEF" }): String = suspendCoroutineUninterceptedOrReturn { x ->
x.resume(block())
COROUTINE_SUSPENDED
}
}
fun builder2(c: suspend Controller2.() -> Unit) {
c.startCoroutine(Controller2(), EmptyContinuation)
}
@@ -10009,6 +10009,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/coroutines/defaultParametersInSuspendWithJvmOverloads.kt");
}
@Test
@TestMetadata("defaultParamterLambdaInSuspend.kt")
public void testDefaultParamterLambdaInSuspend() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/defaultParamterLambdaInSuspend.kt");
}
@Test
@TestMetadata("delegatedSuspendMember.kt")
public void testDelegatedSuspendMember() throws Exception {
@@ -10249,6 +10249,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/coroutines/defaultParametersInSuspendWithJvmOverloads.kt");
}
@Test
@TestMetadata("defaultParamterLambdaInSuspend.kt")
public void testDefaultParamterLambdaInSuspend() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/defaultParamterLambdaInSuspend.kt");
}
@Test
@TestMetadata("delegatedSuspendMember.kt")
public void testDelegatedSuspendMember() throws Exception {
@@ -10249,6 +10249,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack
runTest("compiler/testData/codegen/box/coroutines/defaultParametersInSuspendWithJvmOverloads.kt");
}
@Test
@TestMetadata("defaultParamterLambdaInSuspend.kt")
public void testDefaultParamterLambdaInSuspend() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/defaultParamterLambdaInSuspend.kt");
}
@Test
@TestMetadata("delegatedSuspendMember.kt")
public void testDelegatedSuspendMember() throws Exception {
@@ -7877,6 +7877,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/coroutines/defaultParametersInSuspendWithJvmOverloads.kt");
}
@TestMetadata("defaultParamterLambdaInSuspend.kt")
public void testDefaultParamterLambdaInSuspend() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/defaultParamterLambdaInSuspend.kt");
}
@TestMetadata("delegatedSuspendMember.kt")
public void testDelegatedSuspendMember() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/delegatedSuspendMember.kt");
@@ -7029,6 +7029,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/coroutines/defaultParametersInSuspend.kt");
}
@Test
@TestMetadata("defaultParamterLambdaInSuspend.kt")
public void testDefaultParamterLambdaInSuspend() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/defaultParamterLambdaInSuspend.kt");
}
@Test
@TestMetadata("delegatedSuspendMember.kt")
public void testDelegatedSuspendMember() throws Exception {
@@ -7125,6 +7125,12 @@ public class FirJsCodegenBoxTestGenerated extends AbstractFirJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/coroutines/defaultParametersInSuspend.kt");
}
@Test
@TestMetadata("defaultParamterLambdaInSuspend.kt")
public void testDefaultParamterLambdaInSuspend() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/defaultParamterLambdaInSuspend.kt");
}
@Test
@TestMetadata("delegatedSuspendMember.kt")
public void testDelegatedSuspendMember() throws Exception {
@@ -7125,6 +7125,12 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/coroutines/defaultParametersInSuspend.kt");
}
@Test
@TestMetadata("defaultParamterLambdaInSuspend.kt")
public void testDefaultParamterLambdaInSuspend() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/defaultParamterLambdaInSuspend.kt");
}
@Test
@TestMetadata("delegatedSuspendMember.kt")
public void testDelegatedSuspendMember() throws Exception {
@@ -7125,6 +7125,12 @@ public class IrJsES6CodegenBoxTestGenerated extends AbstractIrJsES6CodegenBoxTes
runTest("compiler/testData/codegen/box/coroutines/defaultParametersInSuspend.kt");
}
@Test
@TestMetadata("defaultParamterLambdaInSuspend.kt")
public void testDefaultParamterLambdaInSuspend() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/defaultParamterLambdaInSuspend.kt");
}
@Test
@TestMetadata("delegatedSuspendMember.kt")
public void testDelegatedSuspendMember() throws Exception {
@@ -316,6 +316,12 @@ private class DeclarationsGeneratorVisitor(override val generationState: NativeG
return KotlinObjCClassLlvmDeclarations(classInfoGlobal, bodyOffsetGlobal)
}
override fun visitValueParameter(declaration: IrValueParameter) {
// In some cases because of inconsistencies of previous lowerings, default values can be not removed.
// If they contain class or function, they would not be processed by code generator
// So we are skipping them here too.
}
private tailrec fun gcd(a: Long, b: Long) : Long = if (b == 0L) a else gcd(b, a % b)
override fun visitField(declaration: IrField) {
@@ -392,6 +398,9 @@ private class DeclarationsGeneratorVisitor(override val generationState: NativeG
else -> LLVMLinkage.LLVMInternalLinkage
}
val proto = LlvmFunctionProto(declaration, symbolName, this, linkage)
context.log {
"Creating llvm function ${symbolName} for ${declaration.render()}"
}
proto.createLlvmFunction(context, llvm.module)
}
@@ -8082,6 +8082,12 @@ public class K2NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTes
runTest("compiler/testData/codegen/box/coroutines/defaultParametersInSuspend.kt");
}
@Test
@TestMetadata("defaultParamterLambdaInSuspend.kt")
public void testDefaultParamterLambdaInSuspend() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/defaultParamterLambdaInSuspend.kt");
}
@Test
@TestMetadata("delegatedSuspendMember.kt")
public void testDelegatedSuspendMember() throws Exception {
@@ -7993,6 +7993,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest
runTest("compiler/testData/codegen/box/coroutines/defaultParametersInSuspend.kt");
}
@Test
@TestMetadata("defaultParamterLambdaInSuspend.kt")
public void testDefaultParamterLambdaInSuspend() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/defaultParamterLambdaInSuspend.kt");
}
@Test
@TestMetadata("delegatedSuspendMember.kt")
public void testDelegatedSuspendMember() throws Exception {
@@ -6272,6 +6272,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
runTest("compiler/testData/codegen/box/coroutines/defaultParametersInSuspend.kt");
}
@TestMetadata("defaultParamterLambdaInSuspend.kt")
public void testDefaultParamterLambdaInSuspend() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/defaultParamterLambdaInSuspend.kt");
}
@TestMetadata("delegatedSuspendMember.kt")
public void testDelegatedSuspendMember() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/delegatedSuspendMember.kt");