diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/optimizations/EscapeAnalysis.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/optimizations/EscapeAnalysis.kt index 3b11d81e9af..291f690b7db 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/optimizations/EscapeAnalysis.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/optimizations/EscapeAnalysis.kt @@ -556,6 +556,7 @@ internal object EscapeAnalysis { } else { context.log { "Escape analysis was refined:\n$endResult" } if (numberOfRuns[function]!! > 1) { + // TODO: suboptimal. May be it is possible somehow handle the entire component at once? context.log { "WARNING: Escape analysis for $function seems not to be converging." + " Assuming conservative results." @@ -571,7 +572,9 @@ internal object EscapeAnalysis { } } - for (graph in pointsToGraphs.values) { + pointsToGraphs.forEach { (function, graph) -> + // TODO: suboptimal. + if (function !in nodes) return@forEach for (node in graph.nodes.keys) { node.ir?.let { val lifetime = graph.lifetimeOf(node) diff --git a/backend.native/tests/build.gradle b/backend.native/tests/build.gradle index 3f471cece2c..68aa39e37ca 100644 --- a/backend.native/tests/build.gradle +++ b/backend.native/tests/build.gradle @@ -2779,6 +2779,10 @@ task codegen_escapeAnalysis_zeroOutObjectOnAlloc(type: KonanLocalTest) { source = "codegen/escapeAnalysis/zeroOutObjectOnAlloc.kt" } +task codegen_escapeAnalysis_recursion(type: KonanLocalTest) { + source = "codegen/escapeAnalysis/recursion.kt" +} + task memory_var1(type: KonanLocalTest) { source = "runtime/memory/var1.kt" } diff --git a/backend.native/tests/codegen/escapeAnalysis/recursion.kt b/backend.native/tests/codegen/escapeAnalysis/recursion.kt new file mode 100644 index 00000000000..08015939f1f --- /dev/null +++ b/backend.native/tests/codegen/escapeAnalysis/recursion.kt @@ -0,0 +1,24 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the LICENSE file. + */ + +package codegen.escapeAnalysis.recursion + +import kotlin.test.* + +class A { + var f: A? = null +} + +fun foo(k: Int, a1: A, a2: A): A { + val a3 = A() + if (k == 0) + return a1 + a3.f = a1 + return foo(k - 1, a2, a3) +} + +@Test fun runTest() { + foo(3, A(), A()).toString() +} \ No newline at end of file