FIR CFG: merge data flow if called-in-place lambda may not be called

This commit is contained in:
pyos
2022-06-30 11:26:32 +02:00
committed by Dmitriy Novozhilov
parent 06c7572ee5
commit 5a2ec4a0d5
23 changed files with 594 additions and 129 deletions
@@ -0,0 +1,58 @@
// !DUMP_CFG
import kotlin.contracts.*
fun unknown(x: () -> Unit) {
contract { callsInPlace(x, InvocationKind.UNKNOWN) }
x()
}
fun atLeastOnce(x: () -> Unit) {
contract { callsInPlace(x, InvocationKind.AT_LEAST_ONCE) }
x()
}
fun exactlyOnce(x: () -> Unit) {
contract { callsInPlace(x, InvocationKind.AT_LEAST_ONCE) }
x()
}
fun atMostOnce(x: () -> Unit) {
contract { callsInPlace(x, InvocationKind.AT_MOST_ONCE) }
}
fun test1() {
var x: Any?
x = ""
x.length
unknown { x = 1 }
x.<!UNRESOLVED_REFERENCE!>length<!>
x.<!UNRESOLVED_REFERENCE!>inc<!>()
}
fun test2() {
var x: Any?
x = ""
x.length
atLeastOnce { x = 1 }
x.<!UNRESOLVED_REFERENCE!>length<!>
x.inc()
}
fun test3() {
var x: Any?
x = ""
x.length
exactlyOnce { x = 1 }
x.<!UNRESOLVED_REFERENCE!>length<!>
x.inc()
}
fun test4() {
var x: Any?
x = ""
x.length
atMostOnce { x = 1 }
x.<!UNRESOLVED_REFERENCE!>length<!>
x.<!UNRESOLVED_REFERENCE!>inc<!>()
}