Detect inline cycles faster

E.g. in the following code

    fun x() {}
    inline fun f() { x(); g() }
    inline fun g() { x(); f() }

the old implementation of inline cycle detection bailed out after
generating 3 calls of x() in each function, while the new one stops
after 2. In other words, code generation for a single function is no
longer reentered.
This commit is contained in:
pyos
2020-03-17 16:48:58 +01:00
committed by max-kammerer
parent 39372c06cf
commit 72b80ef158
17 changed files with 122 additions and 132 deletions
@@ -0,0 +1,6 @@
/indirectInlineCycle.kt:8:24: error: the 'inlineFun2' invocation is a part of inline cycle
fun method() { inlineFun2(p) }
^
/indirectInlineCycle.kt:13:5: error: the 'inlineFun1' invocation is a part of inline cycle
inlineFun1(p)
^
@@ -0,0 +1,11 @@
// !RENDER_DIAGNOSTICS_FULL_TEXT
inline fun inlineFun1(crossinline p: () -> Unit) {
object {
fun method() { <!INLINE_CALL_CYCLE, INLINE_CALL_CYCLE!>inlineFun2(p)<!> }
}
}
inline fun inlineFun2(crossinline p: () -> Unit) {
<!INLINE_CALL_CYCLE, INLINE_CALL_CYCLE!>inlineFun1(p)<!>
}
@@ -0,0 +1,4 @@
package
public inline fun inlineFun1(/*0*/ crossinline p: () -> kotlin.Unit): kotlin.Unit
public inline fun inlineFun2(/*0*/ crossinline p: () -> kotlin.Unit): kotlin.Unit
@@ -0,0 +1,6 @@
/suspendInlineCycle.kt:8:5: error: the 'inlineFun2' invocation is a part of inline cycle
inlineFun2(p)
^
/suspendInlineCycle.kt:13:5: error: the 'inlineFun1' invocation is a part of inline cycle
inlineFun1(p)
^
@@ -0,0 +1,11 @@
// !RENDER_DIAGNOSTICS_FULL_TEXT
// Note: 4 diagnostics per call because there are 2 synthetic $$forInline methods.
suspend inline fun inlineFun1(p: () -> Unit) {
p()
<!INLINE_CALL_CYCLE, INLINE_CALL_CYCLE, INLINE_CALL_CYCLE, INLINE_CALL_CYCLE!>inlineFun2(p)<!>
}
suspend inline fun inlineFun2(p: () -> Unit) {
p()
<!INLINE_CALL_CYCLE, INLINE_CALL_CYCLE, INLINE_CALL_CYCLE, INLINE_CALL_CYCLE!>inlineFun1(p)<!>
}
@@ -0,0 +1,4 @@
package
public suspend inline fun inlineFun1(/*0*/ p: () -> kotlin.Unit): kotlin.Unit
public suspend inline fun inlineFun2(/*0*/ p: () -> kotlin.Unit): kotlin.Unit