JVM_IR KT-46189 lower tailrec functions after local declarations
This commit is contained in:
committed by
TeamCityServer
parent
645014092c
commit
f519150c08
+12
@@ -12292,6 +12292,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
|||||||
runTest("compiler/testData/codegen/box/defaultArguments/kt36853.kt");
|
runTest("compiler/testData/codegen/box/defaultArguments/kt36853.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt36853_fibonacci.kt")
|
||||||
|
public void testKt36853_fibonacci() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/defaultArguments/kt36853_fibonacci.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kt36853_nestedObject.kt")
|
@TestMetadata("kt36853_nestedObject.kt")
|
||||||
public void testKt36853_nestedObject() throws Exception {
|
public void testKt36853_nestedObject() throws Exception {
|
||||||
@@ -12316,6 +12322,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
|||||||
runTest("compiler/testData/codegen/box/defaultArguments/kt36972_object.kt");
|
runTest("compiler/testData/codegen/box/defaultArguments/kt36972_object.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt46189.kt")
|
||||||
|
public void testKt46189() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/defaultArguments/kt46189.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kt6382.kt")
|
@TestMetadata("kt6382.kt")
|
||||||
public void testKt6382() throws Exception {
|
public void testKt6382() throws Exception {
|
||||||
|
|||||||
@@ -266,7 +266,8 @@ private val syntheticAccessorPhase = makeIrFilePhase(
|
|||||||
private val tailrecPhase = makeIrFilePhase(
|
private val tailrecPhase = makeIrFilePhase(
|
||||||
::JvmTailrecLowering,
|
::JvmTailrecLowering,
|
||||||
name = "Tailrec",
|
name = "Tailrec",
|
||||||
description = "Handle tailrec calls"
|
description = "Handle tailrec calls",
|
||||||
|
prerequisite = setOf(localDeclarationsPhase)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val kotlinNothingValueExceptionPhase = makeIrFilePhase<CommonBackendContext>(
|
private val kotlinNothingValueExceptionPhase = makeIrFilePhase<CommonBackendContext>(
|
||||||
@@ -342,17 +343,13 @@ private val jvmFilePhases = listOf(
|
|||||||
propertiesPhase,
|
propertiesPhase,
|
||||||
remapObjectFieldAccesses,
|
remapObjectFieldAccesses,
|
||||||
anonymousObjectSuperConstructorPhase,
|
anonymousObjectSuperConstructorPhase,
|
||||||
tailrecPhase,
|
|
||||||
makePatchParentsPhase(1),
|
|
||||||
|
|
||||||
jvmStandardLibraryBuiltInsPhase,
|
jvmStandardLibraryBuiltInsPhase,
|
||||||
|
|
||||||
rangeContainsLoweringPhase,
|
rangeContainsLoweringPhase,
|
||||||
forLoopsPhase,
|
forLoopsPhase,
|
||||||
collectionStubMethodLowering,
|
collectionStubMethodLowering,
|
||||||
jvmInlineClassPhase,
|
jvmInlineClassPhase,
|
||||||
|
makePatchParentsPhase(1),
|
||||||
makePatchParentsPhase(2),
|
|
||||||
|
|
||||||
enumWhenPhase,
|
enumWhenPhase,
|
||||||
singletonReferencesPhase,
|
singletonReferencesPhase,
|
||||||
@@ -362,6 +359,10 @@ private val jvmFilePhases = listOf(
|
|||||||
returnableBlocksPhase,
|
returnableBlocksPhase,
|
||||||
sharedVariablesPhase,
|
sharedVariablesPhase,
|
||||||
localDeclarationsPhase,
|
localDeclarationsPhase,
|
||||||
|
|
||||||
|
tailrecPhase,
|
||||||
|
makePatchParentsPhase(2),
|
||||||
|
|
||||||
jvmLocalClassExtractionPhase,
|
jvmLocalClassExtractionPhase,
|
||||||
staticCallableReferencePhase,
|
staticCallableReferencePhase,
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
// IGNORE_BACKEND_FIR: JVM_IR
|
||||||
|
// java.lang.StackOverflowError
|
||||||
|
// at Nat$Companion$invoke$1.next(kt36853_fibonacci.kt:40) ...
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
Nat<Int>(
|
||||||
|
nil = 0,
|
||||||
|
next = { this + 1 }
|
||||||
|
).run {
|
||||||
|
val fib = fibonacci(10)
|
||||||
|
if (fib != 89)
|
||||||
|
return "Failed: $fib"
|
||||||
|
}
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T> Nat<T>.fibonacci(
|
||||||
|
n: T,
|
||||||
|
seed: Pair<T, T> = nil to one,
|
||||||
|
fib: (Pair<T, T>) -> Pair<T, T> = { (a, b) -> b to a + b },
|
||||||
|
i: T = nil,
|
||||||
|
): T =
|
||||||
|
if (i == n) fib(seed).first
|
||||||
|
else fibonacci(n = n, seed = fib(seed), i = i.next())
|
||||||
|
|
||||||
|
|
||||||
|
tailrec fun <T> Nat<T>.plus(l: T, r: T, acc: T = l, i: T = nil): T =
|
||||||
|
if (i == r) acc else plus(l, r, acc.next(), i.next())
|
||||||
|
|
||||||
|
interface Nat<T> {
|
||||||
|
val nil: T
|
||||||
|
val one: T get() = nil.next()
|
||||||
|
|
||||||
|
fun T.next(): T
|
||||||
|
operator fun T.plus(t: T) = plus(this, t)
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
operator fun <T> invoke(nil: T, next: T.() -> T): Nat<T> =
|
||||||
|
object: Nat<T> {
|
||||||
|
override val nil: T = nil
|
||||||
|
override fun T.next(): T = next()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
// IGNORE_BACKEND: WASM
|
||||||
|
// IGNORE_BACKEND: JS_IR
|
||||||
|
|
||||||
|
class C
|
||||||
|
|
||||||
|
fun box(): String =
|
||||||
|
C().foo("O")
|
||||||
|
|
||||||
|
tailrec fun C.foo(
|
||||||
|
x: String,
|
||||||
|
f: (String) -> String = { bar(it) }
|
||||||
|
): String =
|
||||||
|
if (x.length < 2) foo(f(x)) else x
|
||||||
|
|
||||||
|
fun C.bar(s: String): String =
|
||||||
|
s + "K"
|
||||||
+12
@@ -12292,6 +12292,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
runTest("compiler/testData/codegen/box/defaultArguments/kt36853.kt");
|
runTest("compiler/testData/codegen/box/defaultArguments/kt36853.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt36853_fibonacci.kt")
|
||||||
|
public void testKt36853_fibonacci() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/defaultArguments/kt36853_fibonacci.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kt36853_nestedObject.kt")
|
@TestMetadata("kt36853_nestedObject.kt")
|
||||||
public void testKt36853_nestedObject() throws Exception {
|
public void testKt36853_nestedObject() throws Exception {
|
||||||
@@ -12316,6 +12322,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
runTest("compiler/testData/codegen/box/defaultArguments/kt36972_object.kt");
|
runTest("compiler/testData/codegen/box/defaultArguments/kt36972_object.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt46189.kt")
|
||||||
|
public void testKt46189() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/defaultArguments/kt46189.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kt6382.kt")
|
@TestMetadata("kt6382.kt")
|
||||||
public void testKt6382() throws Exception {
|
public void testKt6382() throws Exception {
|
||||||
|
|||||||
+12
@@ -12292,6 +12292,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
runTest("compiler/testData/codegen/box/defaultArguments/kt36853.kt");
|
runTest("compiler/testData/codegen/box/defaultArguments/kt36853.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt36853_fibonacci.kt")
|
||||||
|
public void testKt36853_fibonacci() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/defaultArguments/kt36853_fibonacci.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kt36853_nestedObject.kt")
|
@TestMetadata("kt36853_nestedObject.kt")
|
||||||
public void testKt36853_nestedObject() throws Exception {
|
public void testKt36853_nestedObject() throws Exception {
|
||||||
@@ -12316,6 +12322,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
runTest("compiler/testData/codegen/box/defaultArguments/kt36972_object.kt");
|
runTest("compiler/testData/codegen/box/defaultArguments/kt36972_object.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt46189.kt")
|
||||||
|
public void testKt46189() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/defaultArguments/kt46189.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kt6382.kt")
|
@TestMetadata("kt6382.kt")
|
||||||
public void testKt6382() throws Exception {
|
public void testKt6382() throws Exception {
|
||||||
|
|||||||
+10
@@ -9944,6 +9944,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
runTest("compiler/testData/codegen/box/defaultArguments/kt36853.kt");
|
runTest("compiler/testData/codegen/box/defaultArguments/kt36853.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt36853_fibonacci.kt")
|
||||||
|
public void testKt36853_fibonacci() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/defaultArguments/kt36853_fibonacci.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt36853_nestedObject.kt")
|
@TestMetadata("kt36853_nestedObject.kt")
|
||||||
public void testKt36853_nestedObject() throws Exception {
|
public void testKt36853_nestedObject() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/defaultArguments/kt36853_nestedObject.kt");
|
runTest("compiler/testData/codegen/box/defaultArguments/kt36853_nestedObject.kt");
|
||||||
@@ -9964,6 +9969,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
runTest("compiler/testData/codegen/box/defaultArguments/kt36972_object.kt");
|
runTest("compiler/testData/codegen/box/defaultArguments/kt36972_object.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt46189.kt")
|
||||||
|
public void testKt46189() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/defaultArguments/kt46189.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt6382.kt")
|
@TestMetadata("kt6382.kt")
|
||||||
public void testKt6382() throws Exception {
|
public void testKt6382() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/defaultArguments/kt6382.kt");
|
runTest("compiler/testData/codegen/box/defaultArguments/kt6382.kt");
|
||||||
|
|||||||
js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java
Generated
+10
@@ -8883,6 +8883,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
|
|||||||
runTest("compiler/testData/codegen/box/defaultArguments/kt36853.kt");
|
runTest("compiler/testData/codegen/box/defaultArguments/kt36853.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt36853_fibonacci.kt")
|
||||||
|
public void testKt36853_fibonacci() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/defaultArguments/kt36853_fibonacci.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt36853_nestedObject.kt")
|
@TestMetadata("kt36853_nestedObject.kt")
|
||||||
public void testKt36853_nestedObject() throws Exception {
|
public void testKt36853_nestedObject() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/defaultArguments/kt36853_nestedObject.kt");
|
runTest("compiler/testData/codegen/box/defaultArguments/kt36853_nestedObject.kt");
|
||||||
@@ -8893,6 +8898,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
|
|||||||
runTest("compiler/testData/codegen/box/defaultArguments/kt36853a.kt");
|
runTest("compiler/testData/codegen/box/defaultArguments/kt36853a.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt46189.kt")
|
||||||
|
public void testKt46189() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/defaultArguments/kt46189.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt6382.kt")
|
@TestMetadata("kt6382.kt")
|
||||||
public void testKt6382() throws Exception {
|
public void testKt6382() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/defaultArguments/kt6382.kt");
|
runTest("compiler/testData/codegen/box/defaultArguments/kt6382.kt");
|
||||||
|
|||||||
Generated
+10
@@ -8294,6 +8294,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/defaultArguments/kt36853.kt");
|
runTest("compiler/testData/codegen/box/defaultArguments/kt36853.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt36853_fibonacci.kt")
|
||||||
|
public void testKt36853_fibonacci() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/defaultArguments/kt36853_fibonacci.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt36853_nestedObject.kt")
|
@TestMetadata("kt36853_nestedObject.kt")
|
||||||
public void testKt36853_nestedObject() throws Exception {
|
public void testKt36853_nestedObject() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/defaultArguments/kt36853_nestedObject.kt");
|
runTest("compiler/testData/codegen/box/defaultArguments/kt36853_nestedObject.kt");
|
||||||
@@ -8304,6 +8309,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/defaultArguments/kt36853a.kt");
|
runTest("compiler/testData/codegen/box/defaultArguments/kt36853a.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt46189.kt")
|
||||||
|
public void testKt46189() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/defaultArguments/kt46189.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt6382.kt")
|
@TestMetadata("kt6382.kt")
|
||||||
public void testKt6382() throws Exception {
|
public void testKt6382() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/defaultArguments/kt6382.kt");
|
runTest("compiler/testData/codegen/box/defaultArguments/kt6382.kt");
|
||||||
|
|||||||
Generated
+10
@@ -8294,6 +8294,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/defaultArguments/kt36853.kt");
|
runTest("compiler/testData/codegen/box/defaultArguments/kt36853.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt36853_fibonacci.kt")
|
||||||
|
public void testKt36853_fibonacci() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/defaultArguments/kt36853_fibonacci.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt36853_nestedObject.kt")
|
@TestMetadata("kt36853_nestedObject.kt")
|
||||||
public void testKt36853_nestedObject() throws Exception {
|
public void testKt36853_nestedObject() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/defaultArguments/kt36853_nestedObject.kt");
|
runTest("compiler/testData/codegen/box/defaultArguments/kt36853_nestedObject.kt");
|
||||||
@@ -8304,6 +8309,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/defaultArguments/kt36853a.kt");
|
runTest("compiler/testData/codegen/box/defaultArguments/kt36853a.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt46189.kt")
|
||||||
|
public void testKt46189() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/defaultArguments/kt46189.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt6382.kt")
|
@TestMetadata("kt6382.kt")
|
||||||
public void testKt6382() throws Exception {
|
public void testKt6382() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/defaultArguments/kt6382.kt");
|
runTest("compiler/testData/codegen/box/defaultArguments/kt6382.kt");
|
||||||
|
|||||||
js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java
Generated
+10
@@ -3904,6 +3904,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
|
|||||||
runTest("compiler/testData/codegen/box/defaultArguments/kt36853.kt");
|
runTest("compiler/testData/codegen/box/defaultArguments/kt36853.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt36853_fibonacci.kt")
|
||||||
|
public void testKt36853_fibonacci() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/defaultArguments/kt36853_fibonacci.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt36853_nestedObject.kt")
|
@TestMetadata("kt36853_nestedObject.kt")
|
||||||
public void testKt36853_nestedObject() throws Exception {
|
public void testKt36853_nestedObject() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/defaultArguments/kt36853_nestedObject.kt");
|
runTest("compiler/testData/codegen/box/defaultArguments/kt36853_nestedObject.kt");
|
||||||
@@ -3914,6 +3919,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
|
|||||||
runTest("compiler/testData/codegen/box/defaultArguments/kt36853a.kt");
|
runTest("compiler/testData/codegen/box/defaultArguments/kt36853a.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt46189.kt")
|
||||||
|
public void testKt46189() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/defaultArguments/kt46189.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt6382.kt")
|
@TestMetadata("kt6382.kt")
|
||||||
public void testKt6382() throws Exception {
|
public void testKt6382() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/defaultArguments/kt6382.kt");
|
runTest("compiler/testData/codegen/box/defaultArguments/kt6382.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user