From 4f250ed498ce772bf847ed4856bed9b4adac189f Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Mon, 22 Mar 2021 21:22:11 +0300 Subject: [PATCH] JVM_IR KT-45377 rewrite constants again after AddContinuationLowering --- .../FirBlackBoxCodegenTestGenerated.java | 6 +++ .../jetbrains/kotlin/backend/jvm/JvmLower.kt | 3 +- .../kotlin/backend/jvm/lower/ConstLowering.kt | 10 ++++- .../codegen/box/coroutines/kt45377.kt | 42 +++++++++++++++++++ .../codegen/BlackBoxCodegenTestGenerated.java | 6 +++ .../IrBlackBoxCodegenTestGenerated.java | 6 +++ .../LightAnalysisModeTestGenerated.java | 5 +++ .../IrJsCodegenBoxES6TestGenerated.java | 5 +++ .../IrJsCodegenBoxTestGenerated.java | 5 +++ .../semantics/JsCodegenBoxTestGenerated.java | 5 +++ 10 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 compiler/testData/codegen/box/coroutines/kt45377.kt diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java index 21635203491..25c62856109 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java @@ -9066,6 +9066,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/coroutines/kt44221.kt"); } + @Test + @TestMetadata("kt45377.kt") + public void testKt45377() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/kt45377.kt"); + } + @Test @TestMetadata("lastExpressionIsLoop.kt") public void testLastExpressionIsLoop() throws Exception { diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmLower.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmLower.kt index 52348a947ee..6d5713ad716 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmLower.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmLower.kt @@ -336,7 +336,7 @@ private val jvmFilePhases = listOf( functionReferencePhase, suspendLambdaPhase, propertyReferencePhase, - constPhase, + constPhase1, // TODO: merge the next three phases together, as visitors behave incorrectly between them // (backing fields moved out of companion objects are reachable by two paths): moveOrCopyCompanionObjectFieldsPhase, @@ -386,6 +386,7 @@ private val jvmFilePhases = listOf( tailCallOptimizationPhase, addContinuationPhase, + constPhase2, // handle const properties in default arguments of "original" suspend funs innerClassesPhase, innerClassesMemberBodyPhase, diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/ConstLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/ConstLowering.kt index ed42b23eba1..9f57b5dc3d8 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/ConstLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/ConstLowering.kt @@ -20,9 +20,15 @@ import org.jetbrains.kotlin.ir.types.isPrimitiveType import org.jetbrains.kotlin.ir.types.isStringClassType import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid -internal val constPhase = makeIrFilePhase( +internal val constPhase1 = makeIrFilePhase( ::ConstLowering, - name = "Const", + name = "Const1", + description = "Substitute calls to const properties with constant values" +) + +internal val constPhase2 = makeIrFilePhase( + ::ConstLowering, + name = "Const2", description = "Substitute calls to const properties with constant values" ) diff --git a/compiler/testData/codegen/box/coroutines/kt45377.kt b/compiler/testData/codegen/box/coroutines/kt45377.kt new file mode 100644 index 00000000000..c759b9cd381 --- /dev/null +++ b/compiler/testData/codegen/box/coroutines/kt45377.kt @@ -0,0 +1,42 @@ +// WITH_RUNTIME +// FILE: kt45377.kt + +import kotlin.coroutines.* + +fun runs(f: suspend () -> String): String { + var result = "" + f.startCoroutine(Continuation(EmptyCoroutineContext) { result = it.getOrThrow() }) + return result +} + +fun box(): String { + val b = B("O") + + val s1 = runs { b.foo() } + if (s1 != "OK") return "Failed: s1=$s1" + + var s2 = runs { b.foo("K") } + if (s2 != "OK") return "Failed: s2=$s2" + + val a: A = b + + val s3 = runs { a.foo() } + if (s3 != "OK") return "Failed: s3=$s3" + + val s4 = runs { a.foo("K")} + if (s4 != "OK") return "Failed: s4=$s4" + + return "OK" +} + +// FILE: file1.kt +private const val K = "K" + +interface A { + suspend fun foo(k: String = K): String +} + +// FILE: file2.kt +class B(val o: String) : A { + override suspend fun foo(k: String) = o + k +} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java index b993ffad915..bcdc974af52 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java @@ -9066,6 +9066,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/coroutines/kt44221.kt"); } + @Test + @TestMetadata("kt45377.kt") + public void testKt45377() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/kt45377.kt"); + } + @Test @TestMetadata("lastExpressionIsLoop.kt") public void testLastExpressionIsLoop() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java index 88fe2c26ef6..411e14995c4 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java @@ -9066,6 +9066,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/coroutines/kt44221.kt"); } + @Test + @TestMetadata("kt45377.kt") + public void testKt45377() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/kt45377.kt"); + } + @Test @TestMetadata("lastExpressionIsLoop.kt") public void testLastExpressionIsLoop() throws Exception { diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index fe71e0d5f1f..5ff075730f1 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -7079,6 +7079,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/coroutines/kt44221.kt"); } + @TestMetadata("kt45377.kt") + public void testKt45377() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/kt45377.kt"); + } + @TestMetadata("lastExpressionIsLoop.kt") public void testLastExpressionIsLoop() throws Exception { runTest("compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java index f752cc7b269..fc94c3436ab 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java @@ -6328,6 +6328,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes runTest("compiler/testData/codegen/box/coroutines/kt44221.kt"); } + @TestMetadata("kt45377.kt") + public void testKt45377() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/kt45377.kt"); + } + @TestMetadata("lastExpressionIsLoop.kt") public void testLastExpressionIsLoop() throws Exception { runTest("compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java index 533f1e5e59b..0e68391fdd0 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java @@ -5749,6 +5749,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/coroutines/kt44221.kt"); } + @TestMetadata("kt45377.kt") + public void testKt45377() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/kt45377.kt"); + } + @TestMetadata("lastExpressionIsLoop.kt") public void testLastExpressionIsLoop() throws Exception { runTest("compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index aa9bc8aeec9..c7432d3e7be 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -5749,6 +5749,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/coroutines/kt44221.kt"); } + @TestMetadata("kt45377.kt") + public void testKt45377() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/kt45377.kt"); + } + @TestMetadata("lastExpressionIsLoop.kt") public void testLastExpressionIsLoop() throws Exception { runTest("compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt");