FIR DFA: add more called-in-place tests

This commit is contained in:
pyos
2022-11-17 00:05:43 +01:00
committed by teamcity
parent f485413cfd
commit 3392e066df
9 changed files with 1928 additions and 639 deletions
File diff suppressed because it is too large Load Diff
@@ -1,5 +1,42 @@
FILE: flowFromInplaceLambda.kt
public final fun takeInt(x: R|kotlin/Int|): R|kotlin/Unit| {
public final fun <T> unknown(x: R|() -> T|): R|T|
[R|Contract description]
<
CallsInPlace(x, UNKNOWN)
>
{
[StubStatement]
^unknown R|<local>/x|.R|SubstitutionOverride<kotlin/Function0.invoke: R|T|>|()
}
public final fun <T> atLeastOnce(x: R|() -> T|): R|T|
[R|Contract description]
<
CallsInPlace(x, AT_LEAST_ONCE)
>
{
[StubStatement]
^atLeastOnce R|<local>/x|.R|SubstitutionOverride<kotlin/Function0.invoke: R|T|>|()
}
public final fun <T> exactlyOnce(x: R|() -> T|): R|T|
[R|Contract description]
<
CallsInPlace(x, EXACTLY_ONCE)
>
{
[StubStatement]
^exactlyOnce R|<local>/x|.R|SubstitutionOverride<kotlin/Function0.invoke: R|T|>|()
}
public final fun <T> atMostOnce(x: R|() -> T|): R|T|
[R|Contract description]
<
CallsInPlace(x, AT_MOST_ONCE)
>
{
[StubStatement]
^atMostOnce R|<local>/x|.R|SubstitutionOverride<kotlin/Function0.invoke: R|T|>|()
}
public final fun <T> noContract(x: R|() -> T|): R|T| {
^noContract R|<local>/x|.R|SubstitutionOverride<kotlin/Function0.invoke: R|T|>|()
}
public final fun <K> select(vararg x: R|kotlin/Array<out K>|): R|K| {
^select R|<local>/x|.R|SubstitutionOverride<kotlin/Array.get: R|CapturedType(out K)|>|(Int(0))
@@ -10,64 +47,169 @@ FILE: flowFromInplaceLambda.kt
public final fun <K> materialize(): R|K| {
^materialize Null(null)!!
}
public final fun <R> myRun(block: R|() -> R|): R|R| {
^myRun R|<local>/block|.R|SubstitutionOverride<kotlin/Function0.invoke: R|R|>|()
}
public final fun test_1(x: R|kotlin/Any|): R|kotlin/Unit| {
R|kotlin/run|<R|kotlin/Int|>(<L> = run@fun <anonymous>(): R|kotlin/Int| <inline=Inline, kind=EXACTLY_ONCE> {
public final fun basic(x: R|kotlin/Any?|): R|kotlin/Unit| {
R|/exactlyOnce|<R|kotlin/Int|>(<L> = exactlyOnce@fun <anonymous>(): R|kotlin/Int| <inline=NoInline, kind=EXACTLY_ONCE> {
^ (R|<local>/x| as R|kotlin/Int|)
}
)
R|/takeInt|(R|<local>/x|)
R|<local>/x|.R|kotlin/Int.inc|()
}
public final fun test_2(x: R|kotlin/Any|, y: R|kotlin/Any|): R|kotlin/Unit| {
lval a: R|kotlin/Int| = R|/select|<R|kotlin/Int|>(vararg(R|/id|<R|kotlin/Int|>(R|kotlin/run|<R|kotlin/Int|>(<L> = run@fun <anonymous>(): R|kotlin/Int| <inline=Inline, kind=EXACTLY_ONCE> {
public final fun completedCallExactlyOnce(x: R|kotlin/Any?|, y: R|kotlin/Any?|): R|kotlin/Unit| {
R|/select|<R|kotlin/Int|>(vararg(R|/id|<R|kotlin/Int|>(R|/exactlyOnce|<R|kotlin/Int|>(<L> = exactlyOnce@fun <anonymous>(): R|kotlin/Int| <inline=NoInline, kind=EXACTLY_ONCE> {
R|<local>/y|.<Unresolved name: inc>#()
^ (R|<local>/x| as R|kotlin/Int|)
}
)), (R|<local>/y| as R|kotlin/Int|), R|kotlin/run|<R|kotlin/Int|>(<L> = run@fun <anonymous>(): R|kotlin/Int| <inline=Inline, kind=EXACTLY_ONCE> {
)), (R|<local>/y| as R|kotlin/Int|), R|/exactlyOnce|<R|kotlin/Int|>(<L> = exactlyOnce@fun <anonymous>(): R|kotlin/Int| <inline=NoInline, kind=EXACTLY_ONCE> {
R|<local>/x|.R|kotlin/Int.inc|()
R|<local>/y|.R|kotlin/Int.inc|()
^ Int(1)
}
)))
R|/takeInt|(R|<local>/x|)
R|/takeInt|(R|<local>/y|)
R|/takeInt|(R|<local>/a|)
))).R|kotlin/Int.inc|()
R|<local>/x|.R|kotlin/Int.inc|()
R|<local>/y|.R|kotlin/Int.inc|()
}
public final fun test_3(x: R|kotlin/Any|, y: R|kotlin/Any|): R|kotlin/Unit| {
lval a: R|kotlin/Int| = R|/select|<R|kotlin/Int|>(vararg(R|/id|<R|kotlin/Int|>(R|kotlin/run|<R|kotlin/Int|>(<L> = run@fun <anonymous>(): R|kotlin/Int| <inline=Inline, kind=EXACTLY_ONCE> {
public final fun completedCallAtLeastOnce(x: R|kotlin/Any?|, y: R|kotlin/Any?|): R|kotlin/Unit| {
R|/select|<R|kotlin/Int|>(vararg(R|/id|<R|kotlin/Int|>(R|/atLeastOnce|<R|kotlin/Int|>(<L> = atLeastOnce@fun <anonymous>(): R|kotlin/Int| <inline=NoInline, kind=AT_LEAST_ONCE> {
R|<local>/y|.<Unresolved name: inc>#()
^ (R|<local>/x| as R|kotlin/Int|)
}
)), (R|<local>/y| as R|kotlin/Int|), R|/atLeastOnce|<R|kotlin/Int|>(<L> = atLeastOnce@fun <anonymous>(): R|kotlin/Int| <inline=NoInline, kind=AT_LEAST_ONCE> {
R|<local>/x|.R|kotlin/Int.inc|()
R|<local>/y|.R|kotlin/Int.inc|()
^ Int(1)
}
))).R|kotlin/Int.inc|()
R|<local>/x|.R|kotlin/Int.inc|()
R|<local>/y|.R|kotlin/Int.inc|()
}
public final fun completedCallAtMostOnce(x: R|kotlin/Any?|, y: R|kotlin/Any?|): R|kotlin/Unit| {
R|/select|<R|kotlin/Int|>(vararg(R|/id|<R|kotlin/Int|>(R|/atMostOnce|<R|kotlin/Int|>(<L> = atMostOnce@fun <anonymous>(): R|kotlin/Int| <inline=NoInline, kind=AT_MOST_ONCE> {
R|<local>/y|.<Unresolved name: inc>#()
^ (R|<local>/x| as R|kotlin/Int|)
}
)), (R|<local>/y| as R|kotlin/Int|), R|/atMostOnce|<R|kotlin/Int|>(<L> = atMostOnce@fun <anonymous>(): R|kotlin/Int| <inline=NoInline, kind=AT_MOST_ONCE> {
R|<local>/x|.<Unresolved name: inc>#()
R|<local>/y|.R|kotlin/Int.inc|()
^ Int(1)
}
))).R|kotlin/Int.inc|()
R|<local>/x|.<Unresolved name: inc>#()
R|<local>/y|.R|kotlin/Int.inc|()
}
public final fun completedCallUnknown(x: R|kotlin/Any?|, y: R|kotlin/Any?|): R|kotlin/Unit| {
R|/select|<R|kotlin/Int|>(vararg(R|/id|<R|kotlin/Int|>(R|/unknown|<R|kotlin/Int|>(<L> = unknown@fun <anonymous>(): R|kotlin/Int| <inline=NoInline, kind=UNKNOWN> {
R|<local>/y|.<Unresolved name: inc>#()
^ (R|<local>/x| as R|kotlin/Int|)
}
)), (R|<local>/y| as R|kotlin/Int|), R|/unknown|<R|kotlin/Int|>(<L> = unknown@fun <anonymous>(): R|kotlin/Int| <inline=NoInline, kind=UNKNOWN> {
R|<local>/x|.<Unresolved name: inc>#()
R|<local>/y|.R|kotlin/Int.inc|()
^ Int(1)
}
))).R|kotlin/Int.inc|()
R|<local>/x|.<Unresolved name: inc>#()
R|<local>/y|.R|kotlin/Int.inc|()
}
public final fun completedCallNoContract(x: R|kotlin/Any|, y: R|kotlin/Any|): R|kotlin/Unit| {
R|/select|<R|kotlin/Int|>(vararg(R|/id|<R|kotlin/Int|>(R|/noContract|<R|kotlin/Int|>(<L> = noContract@fun <anonymous>(): R|kotlin/Int| <inline=NoInline> {
R|<local>/y|.<Unresolved name: inc>#()
^ (R|<local>/x| as R|kotlin/Int|)
}
)), (R|<local>/y| as R|kotlin/Int|), R|/noContract|<R|kotlin/Int|>(<L> = noContract@fun <anonymous>(): R|kotlin/Int| <inline=NoInline> {
R|<local>/x|.<Unresolved name: inc>#()
R|<local>/y|.R|kotlin/Int.inc|()
^ Int(1)
}
))).R|kotlin/Int.inc|()
R|<local>/x|.<Unresolved name: inc>#()
R|<local>/y|.R|kotlin/Int.inc|()
}
public final fun incompleteCallExactlyOnce(x: R|kotlin/Any|, y: R|kotlin/Any|): R|kotlin/Unit| {
R|/select|<R|kotlin/Int|>(vararg(R|/id|<R|kotlin/Int|>(R|/exactlyOnce|<R|kotlin/Int|>(<L> = exactlyOnce@fun <anonymous>(): R|kotlin/Int| <inline=NoInline, kind=EXACTLY_ONCE> {
(R|<local>/x| as R|kotlin/Int|)
R|<local>/y|.<Unresolved name: inc>#()
R|<local>/x|.R|kotlin/Int.inc|()
^ R|/materialize|<R|kotlin/Int|>()
}
)), R|kotlin/run|<R|kotlin/Int|>(<L> = run@fun <anonymous>(): R|kotlin/Int| <inline=Inline, kind=EXACTLY_ONCE> {
)), R|/exactlyOnce|<R|kotlin/Int|>(<L> = exactlyOnce@fun <anonymous>(): R|kotlin/Int| <inline=NoInline, kind=EXACTLY_ONCE> {
(R|<local>/y| as R|kotlin/Int|)
R|<local>/x|.<Unresolved name: inc>#()
R|<local>/y|.R|kotlin/Int.inc|()
^ Int(1)
}
)))
R|/takeInt|(R|<local>/x|)
R|/takeInt|(R|<local>/y|)
R|/takeInt|(R|<local>/a|)
))).R|kotlin/Int.inc|()
R|<local>/x|.R|kotlin/Int.inc|()
R|<local>/y|.R|kotlin/Int.inc|()
}
public final fun test_4(x: R|kotlin/Any|, y: R|kotlin/Any|): R|kotlin/Unit| {
lval a: R|kotlin/Int| = R|/select|<R|kotlin/Int|>(vararg(R|/id|<R|kotlin/Int|>(R|/myRun|<R|kotlin/Int|>(<L> = myRun@fun <anonymous>(): R|kotlin/Int| <inline=NoInline> {
public final fun incompleteCallAtLeastOnce(x: R|kotlin/Any|, y: R|kotlin/Any|): R|kotlin/Unit| {
R|/select|<R|kotlin/Int|>(vararg(R|/id|<R|kotlin/Int|>(R|/atLeastOnce|<R|kotlin/Int|>(<L> = atLeastOnce@fun <anonymous>(): R|kotlin/Int| <inline=NoInline, kind=AT_LEAST_ONCE> {
(R|<local>/x| as R|kotlin/Int|)
R|<local>/y|.<Unresolved name: inc>#()
^ (R|<local>/x| as R|kotlin/Int|)
R|<local>/x|.R|kotlin/Int.inc|()
^ R|/materialize|<R|kotlin/Int|>()
}
)), (R|<local>/y| as R|kotlin/Int|), R|/myRun|<R|kotlin/Int|>(<L> = myRun@fun <anonymous>(): R|kotlin/Int| <inline=NoInline> {
)), R|/atLeastOnce|<R|kotlin/Int|>(<L> = atLeastOnce@fun <anonymous>(): R|kotlin/Int| <inline=NoInline, kind=AT_LEAST_ONCE> {
(R|<local>/y| as R|kotlin/Int|)
R|<local>/x|.<Unresolved name: inc>#()
R|<local>/y|.R|kotlin/Int.inc|()
^ Int(1)
}
)))
<Inapplicable(INAPPLICABLE): /takeInt>#(R|<local>/x|)
R|/takeInt|(R|<local>/y|)
R|/takeInt|(R|<local>/a|)
))).R|kotlin/Int.inc|()
R|<local>/x|.R|kotlin/Int.inc|()
R|<local>/y|.R|kotlin/Int.inc|()
}
public final fun test_5(): R|kotlin/Unit| {
public final fun incompleteCallAtMostOnce(x: R|kotlin/Any|, y: R|kotlin/Any|): R|kotlin/Unit| {
R|/select|<R|kotlin/Int|>(vararg(R|/id|<R|kotlin/Int|>(R|/atMostOnce|<R|kotlin/Int|>(<L> = atMostOnce@fun <anonymous>(): R|kotlin/Int| <inline=NoInline, kind=AT_MOST_ONCE> {
(R|<local>/x| as R|kotlin/Int|)
R|<local>/y|.<Unresolved name: inc>#()
R|<local>/x|.R|kotlin/Int.inc|()
^ R|/materialize|<R|kotlin/Int|>()
}
)), R|/atMostOnce|<R|kotlin/Int|>(<L> = atMostOnce@fun <anonymous>(): R|kotlin/Int| <inline=NoInline, kind=AT_MOST_ONCE> {
(R|<local>/y| as R|kotlin/Int|)
R|<local>/x|.<Unresolved name: inc>#()
R|<local>/y|.R|kotlin/Int.inc|()
^ Int(1)
}
))).R|kotlin/Int.inc|()
R|<local>/x|.<Unresolved name: inc>#()
R|<local>/y|.<Unresolved name: inc>#()
}
public final fun incompleteCallUnknown(x: R|kotlin/Any|, y: R|kotlin/Any|): R|kotlin/Unit| {
R|/select|<R|kotlin/Int|>(vararg(R|/id|<R|kotlin/Int|>(R|/unknown|<R|kotlin/Int|>(<L> = unknown@fun <anonymous>(): R|kotlin/Int| <inline=NoInline, kind=UNKNOWN> {
(R|<local>/x| as R|kotlin/Int|)
R|<local>/y|.<Unresolved name: inc>#()
R|<local>/x|.R|kotlin/Int.inc|()
^ R|/materialize|<R|kotlin/Int|>()
}
)), R|/unknown|<R|kotlin/Int|>(<L> = unknown@fun <anonymous>(): R|kotlin/Int| <inline=NoInline, kind=UNKNOWN> {
(R|<local>/y| as R|kotlin/Int|)
R|<local>/x|.<Unresolved name: inc>#()
R|<local>/y|.R|kotlin/Int.inc|()
^ Int(1)
}
))).R|kotlin/Int.inc|()
R|<local>/x|.<Unresolved name: inc>#()
R|<local>/y|.<Unresolved name: inc>#()
}
public final fun incompleteCallNoContract(x: R|kotlin/Any|, y: R|kotlin/Any|): R|kotlin/Unit| {
R|/select|<R|kotlin/Int|>(vararg(R|/id|<R|kotlin/Int|>(R|/noContract|<R|kotlin/Int|>(<L> = noContract@fun <anonymous>(): R|kotlin/Int| <inline=NoInline> {
(R|<local>/x| as R|kotlin/Int|)
R|<local>/y|.<Unresolved name: inc>#()
R|<local>/x|.R|kotlin/Int.inc|()
^ R|/materialize|<R|kotlin/Int|>()
}
)), R|/noContract|<R|kotlin/Int|>(<L> = noContract@fun <anonymous>(): R|kotlin/Int| <inline=NoInline> {
(R|<local>/y| as R|kotlin/Int|)
R|<local>/x|.<Unresolved name: inc>#()
R|<local>/y|.R|kotlin/Int.inc|()
^ Int(1)
}
))).R|kotlin/Int.inc|()
R|<local>/x|.<Unresolved name: inc>#()
R|<local>/y|.<Unresolved name: inc>#()
}
public final fun expectedType(): R|kotlin/Unit| {
lval x: R|kotlin/Int| = R|/select|<R|kotlin/Int|>(vararg(R|kotlin/run|<R|kotlin/Int|>(<L> = run@fun <anonymous>(): R|kotlin/Int| <inline=Inline, kind=EXACTLY_ONCE> {
^ R|/materialize|<R|kotlin/Int|>()
}
@@ -75,14 +217,15 @@ FILE: flowFromInplaceLambda.kt
^ R|/materialize|<R|kotlin/Int|>()
}
)))
R|/takeInt|(R|<local>/x|)
R|<local>/x|.R|kotlin/Int.inc|()
}
public final fun test_6(): R|kotlin/Unit| {
lval x: R|kotlin/String| = R|/id|<R|kotlin/String|>(R|/myRun|<R|kotlin/String|>(<L> = myRun@fun <anonymous>(): R|kotlin/String| <inline=NoInline> {
^ R|kotlin/run|<R|kotlin/String|>(<L> = run@fun <anonymous>(): R|kotlin/String| <inline=Inline, kind=EXACTLY_ONCE> {
^ R|/materialize|<R|kotlin/String|>()
public final fun expectedTypeNested(): R|kotlin/Unit| {
lval x: R|kotlin/Int| = R|/id|<R|kotlin/Int|>(R|/noContract|<R|kotlin/Int|>(<L> = noContract@fun <anonymous>(): R|kotlin/Int| <inline=NoInline> {
^ R|kotlin/run|<R|kotlin/Int|>(<L> = run@fun <anonymous>(): R|kotlin/Int| <inline=Inline, kind=EXACTLY_ONCE> {
^ R|/materialize|<R|kotlin/Int|>()
}
)
}
))
R|<local>/x|.R|kotlin/Int.inc|()
}
@@ -1,93 +1,141 @@
// !DUMP_CFG
fun takeInt(x: Int) {}
import kotlin.contracts.*
fun <T> unknown(x: () -> T): T {
contract { callsInPlace(x, InvocationKind.UNKNOWN) }
return x()
}
fun <T> atLeastOnce(x: () -> T): T {
contract { callsInPlace(x, InvocationKind.AT_LEAST_ONCE) }
return x()
}
fun <T> exactlyOnce(x: () -> T): T {
contract { callsInPlace(x, InvocationKind.EXACTLY_ONCE) }
return x()
}
fun <T> atMostOnce(x: () -> T): T {
contract { callsInPlace(x, InvocationKind.AT_MOST_ONCE) }
return x()
}
fun <T> noContract(x: () -> T): T = x()
fun <K> select(vararg x: K): K = x[0]
fun <T> id(x: T): T = x
fun <K> materialize(): K = null!!
fun <R> myRun(block: () -> R): R = block()
fun test_1(x: Any) {
run {
x as Int
}
takeInt(x) // OK
fun basic(x: Any?) {
exactlyOnce { x as Int }
x.inc() // OK
}
fun test_2(x: Any, y: Any) {
val a = select(
id(
run {
y.<!UNRESOLVED_REFERENCE!>inc<!>() // Bad
x as Int
}
),
fun completedCallExactlyOnce(x: Any?, y: Any?) {
select(
// The value of the type argument is known, so the call is complete and the data can flow.
id(exactlyOnce { y.<!UNRESOLVED_REFERENCE!>inc<!>(); x as Int }),
y as Int,
run {
x.inc() // Should be "Bad" but "OK" is fine
y.inc() // OK
1
}
)
takeInt(x) // OK
takeInt(y) // OK
takeInt(a) // OK
exactlyOnce { x.inc(); y.inc(); 1 }
).inc() // OK
x.inc() // OK
y.inc() // OK
}
fun test_3(x: Any, y: Any) {
val a = select(
id(
run {
y.<!UNRESOLVED_REFERENCE!>inc<!>() // Bad
x as Int
materialize()
}
),
run {
y as Int
x.<!UNRESOLVED_REFERENCE!>inc<!>() // Bad
y.inc() // OK
1
}
)
takeInt(x) // OK
takeInt(y) // OK
takeInt(a) // OK
}
fun test_4(x: Any, y: Any) {
val a = select(
id(
myRun {
y.<!UNRESOLVED_REFERENCE!>inc<!>() // Bad
x as Int
}
),
fun completedCallAtLeastOnce(x: Any?, y: Any?) {
select(
id(atLeastOnce { y.<!UNRESOLVED_REFERENCE!>inc<!>(); x as Int }),
y as Int,
myRun {
x.<!UNRESOLVED_REFERENCE!>inc<!>() // Bad
y.inc() // OK
1
}
)
takeInt(<!ARGUMENT_TYPE_MISMATCH!>x<!>) // Bad
takeInt(y) // OK
takeInt(a) // Bad
atLeastOnce { x.inc(); y.inc(); 1 }
).inc() // OK
x.inc() // OK
y.inc() // OK
}
fun test_5() {
fun completedCallAtMostOnce(x: Any?, y: Any?) {
select(
id(atMostOnce { y.<!UNRESOLVED_REFERENCE!>inc<!>(); x as Int }),
y as Int,
atMostOnce { x.<!UNRESOLVED_REFERENCE!>inc<!>(); y.inc(); 1 }
).inc() // OK
x.<!UNRESOLVED_REFERENCE!>inc<!>() // Bad: x as Int might not have executed
y.inc() // OK
}
fun completedCallUnknown(x: Any?, y: Any?) {
select(
id(unknown { y.<!UNRESOLVED_REFERENCE!>inc<!>(); x as Int }),
y as Int,
unknown { x.<!UNRESOLVED_REFERENCE!>inc<!>(); y.inc(); 1 }
).inc() // OK
x.<!UNRESOLVED_REFERENCE!>inc<!>() // Bad: x as Int might not have executed
y.inc() // OK
}
fun completedCallNoContract(x: Any, y: Any) {
select(
id(noContract { y.<!UNRESOLVED_REFERENCE!>inc<!>(); x as Int }),
y as Int,
noContract { x.<!UNRESOLVED_REFERENCE!>inc<!>(); y.inc(); 1 }
).inc() // OK
x.<!UNRESOLVED_REFERENCE!>inc<!>() // Bad: x as Int might not have executed
y.inc() // OK
}
fun incompleteCallExactlyOnce(x: Any, y: Any) {
select(
// The type argument is uninferred, so the two lambdas are concurrent by data flow.
id(exactlyOnce { x as Int; y.<!UNRESOLVED_REFERENCE!>inc<!>(); x.inc(); materialize() }),
exactlyOnce { y as Int; x.<!UNRESOLVED_REFERENCE!>inc<!>(); y.inc(); 1 }
).inc() // OK
x.inc() // OK
y.inc() // OK
}
fun incompleteCallAtLeastOnce(x: Any, y: Any) {
select(
id(atLeastOnce { x as Int; y.<!UNRESOLVED_REFERENCE!>inc<!>(); x.inc(); materialize() }),
atLeastOnce { y as Int; x.<!UNRESOLVED_REFERENCE!>inc<!>(); y.inc(); 1 }
).inc() // OK
x.inc() // OK
y.inc() // OK
}
fun incompleteCallAtMostOnce(x: Any, y: Any) {
select(
id(atMostOnce { x as Int; y.<!UNRESOLVED_REFERENCE!>inc<!>(); x.inc(); materialize() }),
atMostOnce { y as Int; x.<!UNRESOLVED_REFERENCE!>inc<!>(); y.inc(); 1 }
).inc() // OK
x.<!UNRESOLVED_REFERENCE!>inc<!>() // Bad: x as Int might not have executed
y.<!UNRESOLVED_REFERENCE!>inc<!>() // Bad: y as Int might not have executed
}
fun incompleteCallUnknown(x: Any, y: Any) {
select(
id(unknown { x as Int; y.<!UNRESOLVED_REFERENCE!>inc<!>(); x.inc(); materialize() }),
unknown { y as Int; x.<!UNRESOLVED_REFERENCE!>inc<!>(); y.inc(); 1 }
).inc() // OK
x.<!UNRESOLVED_REFERENCE!>inc<!>() // Bad: x as Int might not have executed
y.<!UNRESOLVED_REFERENCE!>inc<!>() // Bad: y as Int might not have executed
}
fun incompleteCallNoContract(x: Any, y: Any) {
select(
id(noContract { x as Int; y.<!UNRESOLVED_REFERENCE!>inc<!>(); x.inc(); materialize() }),
noContract { y as Int; x.<!UNRESOLVED_REFERENCE!>inc<!>(); y.inc(); 1 }
).inc() // OK
x.<!UNRESOLVED_REFERENCE!>inc<!>() // Bad: x as Int might not have executed
y.<!UNRESOLVED_REFERENCE!>inc<!>() // Bad: y as Int might not have executed
}
fun expectedType() {
val x: Int = select(run { materialize() }, run { materialize() })
takeInt(x)
x.inc()
}
fun test_6() {
val x: String = id(
myRun {
run {
materialize()
}
}
)
fun expectedTypeNested() {
val x: Int = id(noContract { run { materialize() } })
x.inc()
}
@@ -127,7 +127,7 @@ digraph flowFromInplaceLambda3_kt {
subgraph cluster_12 {
color=red
42 [label="Enter function test2" style="filled" fillcolor=red];
42 [label="Enter function test1m" style="filled" fillcolor=red];
subgraph cluster_13 {
color=blue
43 [label="Enter block"];
@@ -140,28 +140,23 @@ digraph flowFromInplaceLambda3_kt {
50 [label="Postponed enter to lambda"];
subgraph cluster_14 {
color=blue
62 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
57 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
subgraph cluster_15 {
color=blue
63 [label="Enter block"];
64 [label="Const: Int(1)"];
65 [label="Assignment: R|<local>/x|"];
66 [label="Exit block"];
58 [label="Enter block"];
59 [label="Const: String()"];
60 [label="Assignment: R|<local>/x|"];
61 [label="Exit block"];
}
67 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
62 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
}
51 [label="Call arguments union" style="filled" fillcolor=yellow];
52 [label="Postponed exit from lambda"];
53 [label="Function call: R|/atLeastOnce|(...)"];
54 [label="Access variable R|<local>/x|"];
55 [label="Smart cast: R|<local>/x|"];
56 [label="Access variable <Unresolved name: length>#"];
57 [label="Access variable R|<local>/x|"];
58 [label="Smart cast: R|<local>/x|"];
59 [label="Function call: R|<local>/x|.R|kotlin/Int.inc|()"];
60 [label="Exit block"];
51 [label="Postponed exit from lambda"];
52 [label="Function call: R|/unknown|(...)"];
53 [label="Access variable R|<local>/x|"];
54 [label="Access variable <Unresolved name: length>#"];
55 [label="Exit block"];
}
61 [label="Exit function test2" style="filled" fillcolor=red];
56 [label="Exit function test1m" style="filled" fillcolor=red];
}
42 -> {43};
43 -> {44};
@@ -171,157 +166,217 @@ digraph flowFromInplaceLambda3_kt {
47 -> {48};
48 -> {49};
49 -> {50};
50 -> {62};
50 -> {52} [color=red];
50 -> {62} [style=dashed];
51 -> {53} [color=red];
52 -> {53} [color=green];
50 -> {51 57};
50 -> {57} [style=dashed];
51 -> {52};
52 -> {53};
53 -> {54};
54 -> {55};
55 -> {56};
56 -> {57};
57 -> {58};
57 -> {62 58};
58 -> {59};
59 -> {60};
60 -> {61};
62 -> {63};
61 -> {62};
62 -> {51};
62 -> {57} [color=green style=dashed];
subgraph cluster_16 {
color=red
63 [label="Enter function test2" style="filled" fillcolor=red];
subgraph cluster_17 {
color=blue
64 [label="Enter block"];
65 [label="Variable declaration: lvar x: R|kotlin/Any?|"];
66 [label="Const: String()"];
67 [label="Assignment: R|<local>/x|"];
68 [label="Access variable R|<local>/x|"];
69 [label="Smart cast: R|<local>/x|"];
70 [label="Access variable R|kotlin/String.length|"];
71 [label="Postponed enter to lambda"];
subgraph cluster_18 {
color=blue
83 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
subgraph cluster_19 {
color=blue
84 [label="Enter block"];
85 [label="Const: Int(1)"];
86 [label="Assignment: R|<local>/x|"];
87 [label="Exit block"];
}
88 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
}
72 [label="Call arguments union" style="filled" fillcolor=yellow];
73 [label="Postponed exit from lambda"];
74 [label="Function call: R|/atLeastOnce|(...)"];
75 [label="Access variable R|<local>/x|"];
76 [label="Smart cast: R|<local>/x|"];
77 [label="Access variable <Unresolved name: length>#"];
78 [label="Access variable R|<local>/x|"];
79 [label="Smart cast: R|<local>/x|"];
80 [label="Function call: R|<local>/x|.R|kotlin/Int.inc|()"];
81 [label="Exit block"];
}
82 [label="Exit function test2" style="filled" fillcolor=red];
}
63 -> {64};
64 -> {65};
65 -> {66};
66 -> {67};
67 -> {51} [color=red];
67 -> {52} [color=green];
67 -> {62} [color=green style=dashed];
subgraph cluster_16 {
color=red
68 [label="Enter function test3" style="filled" fillcolor=red];
subgraph cluster_17 {
color=blue
69 [label="Enter block"];
70 [label="Variable declaration: lvar x: R|kotlin/Any?|"];
71 [label="Const: String()"];
72 [label="Assignment: R|<local>/x|"];
73 [label="Access variable R|<local>/x|"];
74 [label="Smart cast: R|<local>/x|"];
75 [label="Access variable R|kotlin/String.length|"];
76 [label="Postponed enter to lambda"];
subgraph cluster_18 {
color=blue
88 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
subgraph cluster_19 {
color=blue
89 [label="Enter block"];
90 [label="Const: Int(1)"];
91 [label="Assignment: R|<local>/x|"];
92 [label="Exit block"];
}
93 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
}
77 [label="Call arguments union" style="filled" fillcolor=yellow];
78 [label="Postponed exit from lambda"];
79 [label="Function call: R|/exactlyOnce|(...)"];
80 [label="Access variable R|<local>/x|"];
81 [label="Smart cast: R|<local>/x|"];
82 [label="Access variable <Unresolved name: length>#"];
83 [label="Access variable R|<local>/x|"];
84 [label="Smart cast: R|<local>/x|"];
85 [label="Function call: R|<local>/x|.R|kotlin/Int.inc|()"];
86 [label="Exit block"];
}
87 [label="Exit function test3" style="filled" fillcolor=red];
}
67 -> {68};
68 -> {69};
69 -> {70};
70 -> {71};
71 -> {72};
72 -> {73};
73 -> {74};
71 -> {83};
71 -> {73} [color=red];
71 -> {83} [style=dashed];
72 -> {74} [color=red];
73 -> {74} [color=green];
74 -> {75};
75 -> {76};
76 -> {88};
76 -> {78} [color=red];
76 -> {88} [style=dashed];
77 -> {79} [color=red];
78 -> {79} [color=green];
76 -> {77};
77 -> {78};
78 -> {79};
79 -> {80};
80 -> {81};
81 -> {82};
82 -> {83};
83 -> {84};
84 -> {85};
85 -> {86};
86 -> {87};
88 -> {89};
87 -> {88};
88 -> {72} [color=red];
88 -> {73} [color=green];
88 -> {83} [color=green style=dashed];
subgraph cluster_20 {
color=red
89 [label="Enter function test3" style="filled" fillcolor=red];
subgraph cluster_21 {
color=blue
90 [label="Enter block"];
91 [label="Variable declaration: lvar x: R|kotlin/Any?|"];
92 [label="Const: String()"];
93 [label="Assignment: R|<local>/x|"];
94 [label="Access variable R|<local>/x|"];
95 [label="Smart cast: R|<local>/x|"];
96 [label="Access variable R|kotlin/String.length|"];
97 [label="Postponed enter to lambda"];
subgraph cluster_22 {
color=blue
109 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
subgraph cluster_23 {
color=blue
110 [label="Enter block"];
111 [label="Const: Int(1)"];
112 [label="Assignment: R|<local>/x|"];
113 [label="Exit block"];
}
114 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
}
98 [label="Call arguments union" style="filled" fillcolor=yellow];
99 [label="Postponed exit from lambda"];
100 [label="Function call: R|/exactlyOnce|(...)"];
101 [label="Access variable R|<local>/x|"];
102 [label="Smart cast: R|<local>/x|"];
103 [label="Access variable <Unresolved name: length>#"];
104 [label="Access variable R|<local>/x|"];
105 [label="Smart cast: R|<local>/x|"];
106 [label="Function call: R|<local>/x|.R|kotlin/Int.inc|()"];
107 [label="Exit block"];
}
108 [label="Exit function test3" style="filled" fillcolor=red];
}
89 -> {90};
90 -> {91};
91 -> {92};
92 -> {93};
93 -> {77} [color=red];
93 -> {78} [color=green];
93 -> {88} [color=green style=dashed];
subgraph cluster_20 {
color=red
94 [label="Enter function test4" style="filled" fillcolor=red];
subgraph cluster_21 {
color=blue
95 [label="Enter block"];
96 [label="Variable declaration: lvar x: R|kotlin/Any?|"];
97 [label="Const: String()"];
98 [label="Assignment: R|<local>/x|"];
99 [label="Access variable R|<local>/x|"];
100 [label="Smart cast: R|<local>/x|"];
101 [label="Access variable R|kotlin/String.length|"];
102 [label="Postponed enter to lambda"];
subgraph cluster_22 {
color=blue
113 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
subgraph cluster_23 {
color=blue
114 [label="Enter block"];
115 [label="Const: Int(1)"];
116 [label="Assignment: R|<local>/x|"];
117 [label="Exit block"];
}
118 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
}
103 [label="Postponed exit from lambda"];
104 [label="Function call: R|/atMostOnce|(...)"];
105 [label="Access variable R|<local>/x|"];
106 [label="Smart cast: R|<local>/x|"];
107 [label="Access variable <Unresolved name: length>#"];
108 [label="Access variable R|<local>/x|"];
109 [label="Smart cast: R|<local>/x|"];
110 [label="Function call: R|<local>/x|.<Unresolved name: inc>#()"];
111 [label="Exit block"];
}
112 [label="Exit function test4" style="filled" fillcolor=red];
}
93 -> {94};
94 -> {95};
95 -> {96};
96 -> {97};
97 -> {98};
98 -> {99};
99 -> {100};
97 -> {109};
97 -> {99} [color=red];
97 -> {109} [style=dashed];
98 -> {100} [color=red];
99 -> {100} [color=green];
100 -> {101};
101 -> {102};
102 -> {103 113};
102 -> {113} [style=dashed];
102 -> {103};
103 -> {104};
104 -> {105};
105 -> {106};
106 -> {107};
107 -> {108};
108 -> {109};
109 -> {110};
110 -> {111};
111 -> {112};
113 -> {118 114};
114 -> {115};
112 -> {113};
113 -> {114};
114 -> {98} [color=red];
114 -> {99} [color=green];
subgraph cluster_24 {
color=red
115 [label="Enter function test4" style="filled" fillcolor=red];
subgraph cluster_25 {
color=blue
116 [label="Enter block"];
117 [label="Variable declaration: lvar x: R|kotlin/Any?|"];
118 [label="Const: String()"];
119 [label="Assignment: R|<local>/x|"];
120 [label="Access variable R|<local>/x|"];
121 [label="Smart cast: R|<local>/x|"];
122 [label="Access variable R|kotlin/String.length|"];
123 [label="Postponed enter to lambda"];
subgraph cluster_26 {
color=blue
134 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
subgraph cluster_27 {
color=blue
135 [label="Enter block"];
136 [label="Const: Int(1)"];
137 [label="Assignment: R|<local>/x|"];
138 [label="Exit block"];
}
139 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
}
124 [label="Postponed exit from lambda"];
125 [label="Function call: R|/atMostOnce|(...)"];
126 [label="Access variable R|<local>/x|"];
127 [label="Smart cast: R|<local>/x|"];
128 [label="Access variable <Unresolved name: length>#"];
129 [label="Access variable R|<local>/x|"];
130 [label="Smart cast: R|<local>/x|"];
131 [label="Function call: R|<local>/x|.<Unresolved name: inc>#()"];
132 [label="Exit block"];
}
133 [label="Exit function test4" style="filled" fillcolor=red];
}
115 -> {116};
116 -> {117};
117 -> {118};
118 -> {103};
118 -> {119};
119 -> {120};
120 -> {121};
121 -> {122};
122 -> {123};
123 -> {124 134};
123 -> {134} [style=dashed];
124 -> {125};
125 -> {126};
126 -> {127};
127 -> {128};
128 -> {129};
129 -> {130};
130 -> {131};
131 -> {132};
132 -> {133};
134 -> {139 135};
135 -> {136};
136 -> {137};
137 -> {138};
138 -> {139};
139 -> {124};
}
@@ -20,7 +20,7 @@ FILE: flowFromInplaceLambda3.kt
public final fun exactlyOnce(x: R|() -> kotlin/Unit|): R|kotlin/Unit|
[R|Contract description]
<
CallsInPlace(x, AT_LEAST_ONCE)
CallsInPlace(x, EXACTLY_ONCE)
>
{
[StubStatement]
@@ -45,6 +45,16 @@ FILE: flowFromInplaceLambda3.kt
R|<local>/x|.<Unresolved name: length>#
R|<local>/x|.<Unresolved name: inc>#()
}
public final fun test1m(): R|kotlin/Unit| {
lvar x: R|kotlin/Any?|
R|<local>/x| = String()
R|<local>/x|.R|kotlin/String.length|
R|/unknown|(<L> = unknown@fun <anonymous>(): R|kotlin/Unit| <inline=NoInline, kind=UNKNOWN> {
R|<local>/x| = String()
}
)
R|<local>/x|.<Unresolved name: length>#
}
public final fun test2(): R|kotlin/Unit| {
lvar x: R|kotlin/Any?|
R|<local>/x| = String()
@@ -60,7 +70,7 @@ FILE: flowFromInplaceLambda3.kt
lvar x: R|kotlin/Any?|
R|<local>/x| = String()
R|<local>/x|.R|kotlin/String.length|
R|/exactlyOnce|(<L> = exactlyOnce@fun <anonymous>(): R|kotlin/Unit| <inline=NoInline, kind=AT_LEAST_ONCE> {
R|/exactlyOnce|(<L> = exactlyOnce@fun <anonymous>(): R|kotlin/Unit| <inline=NoInline, kind=EXACTLY_ONCE> {
R|<local>/x| = Int(1)
}
)
@@ -13,7 +13,7 @@ fun atLeastOnce(x: () -> Unit) {
}
fun exactlyOnce(x: () -> Unit) {
contract { callsInPlace(x, InvocationKind.AT_LEAST_ONCE) }
contract { callsInPlace(x, InvocationKind.EXACTLY_ONCE) }
x()
}
@@ -30,6 +30,14 @@ fun test1() {
x.<!UNRESOLVED_REFERENCE!>inc<!>()
}
fun test1m() {
var x: Any?
x = ""
x.length
unknown { x = "" }
x.<!UNRESOLVED_REFERENCE!>length<!>
}
fun test2() {
var x: Any?
x = ""
@@ -682,4 +682,192 @@ digraph flowFromTwoInplaceLambdas_kt {
248 -> {220} [color=red];
248 -> {223} [color=green];
subgraph cluster_48 {
color=red
249 [label="Enter function test6" style="filled" fillcolor=red];
subgraph cluster_49 {
color=blue
250 [label="Enter block"];
251 [label="Variable declaration: lval x: R|kotlin/String|"];
252 [label="Postponed enter to lambda"];
subgraph cluster_50 {
color=blue
262 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
subgraph cluster_51 {
color=blue
263 [label="Enter block"];
264 [label="Const: String()"];
265 [label="Assignment: R|<local>/x|"];
266 [label="Access variable R|<local>/x|"];
267 [label="Access variable R|kotlin/String.length|"];
268 [label="Exit block"];
}
269 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
}
254 [label="Postponed exit from lambda"];
255 [label="Postponed enter to lambda"];
subgraph cluster_52 {
color=blue
270 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
subgraph cluster_53 {
color=blue
271 [label="Enter block"];
272 [label="Access variable R|<local>/x|"];
273 [label="Access variable R|kotlin/String.length|"];
274 [label="Exit block"];
}
275 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
}
253 [label="Call arguments union" style="filled" fillcolor=yellow];
256 [label="Postponed exit from lambda"];
257 [label="Function call: R|/run2|<R|kotlin/Int|>(...)"];
258 [label="Access variable R|<local>/x|"];
259 [label="Access variable R|kotlin/String.length|"];
260 [label="Exit block"];
}
261 [label="Exit function test6" style="filled" fillcolor=red];
}
249 -> {250};
250 -> {251};
251 -> {252};
252 -> {262};
252 -> {254} [color=red];
252 -> {262} [style=dashed];
253 -> {257} [color=red];
254 -> {255};
255 -> {270};
255 -> {256} [color=red];
255 -> {270} [style=dashed];
256 -> {257} [color=green];
257 -> {258};
258 -> {259};
259 -> {260};
260 -> {261};
262 -> {263};
263 -> {264};
264 -> {265};
265 -> {266};
266 -> {267};
267 -> {268};
268 -> {269};
269 -> {253} [color=red];
269 -> {254} [color=green];
270 -> {271};
271 -> {272};
272 -> {273};
273 -> {274};
274 -> {275};
275 -> {253} [color=red];
275 -> {256} [color=green];
subgraph cluster_54 {
color=red
276 [label="Enter function test7" style="filled" fillcolor=red];
subgraph cluster_55 {
color=blue
277 [label="Enter block"];
278 [label="Const: String()"];
279 [label="Variable declaration: lval x: R|kotlin/Any?|"];
280 [label="Variable declaration: lval y: R|kotlin/Any?|"];
281 [label="Postponed enter to lambda"];
subgraph cluster_56 {
color=blue
302 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
subgraph cluster_57 {
color=blue
303 [label="Enter block"];
304 [label="Access variable R|<local>/x|"];
305 [label="Assignment: R|<local>/y|"];
306 [label="Exit block"];
}
307 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
}
283 [label="Postponed exit from lambda"];
284 [label="Postponed enter to lambda"];
subgraph cluster_58 {
color=blue
308 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
subgraph cluster_59 {
color=blue
309 [label="Enter block"];
310 [label="Jump: ^@run2 Unit"];
311 [label="Stub" style="filled" fillcolor=gray];
312 [label="Exit block" style="filled" fillcolor=gray];
}
313 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
}
282 [label="Call arguments union" style="filled" fillcolor=yellow];
285 [label="Postponed exit from lambda"];
286 [label="Function call: R|/run2|<R|kotlin/Unit|>(...)"];
subgraph cluster_60 {
color=blue
287 [label="Enter when"];
subgraph cluster_61 {
color=blue
288 [label="Enter when branch condition "];
289 [label="Access variable R|<local>/y|"];
290 [label="Type operator: (R|<local>/y| is R|kotlin/String|)"];
291 [label="Exit when branch condition"];
}
292 [label="Synthetic else branch"];
293 [label="Enter when branch result"];
subgraph cluster_62 {
color=blue
294 [label="Enter block"];
295 [label="Access variable R|<local>/x|"];
296 [label="Access variable <Unresolved name: length>#"];
297 [label="Exit block"];
}
298 [label="Exit when branch result"];
299 [label="Exit when"];
}
300 [label="Exit block"];
}
301 [label="Exit function test7" style="filled" fillcolor=red];
}
276 -> {277};
277 -> {278};
278 -> {279};
279 -> {280};
280 -> {281};
281 -> {302};
281 -> {283} [color=red];
281 -> {302} [style=dashed];
282 -> {286} [color=red];
283 -> {284};
284 -> {308};
284 -> {285} [color=red];
284 -> {308} [style=dashed];
285 -> {286} [color=green];
286 -> {287};
287 -> {288};
288 -> {289};
289 -> {290};
290 -> {291};
291 -> {293 292};
292 -> {299};
293 -> {294};
294 -> {295};
295 -> {296};
296 -> {297};
297 -> {298};
298 -> {299};
299 -> {300};
300 -> {301};
302 -> {303};
303 -> {304};
304 -> {305};
305 -> {306};
306 -> {307};
307 -> {282} [color=red];
307 -> {283} [color=green];
308 -> {309};
309 -> {310};
310 -> {313};
310 -> {311} [style=dotted];
311 -> {312} [style=dotted];
312 -> {313} [style=dotted];
313 -> {282} [color=red];
313 -> {285} [color=green];
}
@@ -121,3 +121,32 @@ FILE: flowFromTwoInplaceLambdas.kt
R|<local>/p|.<Inapplicable(UNSAFE_CALL): kotlin/String.length>#
R|<local>/p|?.{ $subj$.R|kotlin/String.length| }
}
public final fun test6(): R|kotlin/Unit| {
lval x: R|kotlin/String|
R|/run2|<R|kotlin/Int|>(run2@fun <anonymous>(): R|kotlin/Int| <inline=NoInline, kind=EXACTLY_ONCE> {
R|<local>/x| = String()
^ R|<local>/x|.R|kotlin/String.length|
}
, run2@fun <anonymous>(): R|kotlin/Int| <inline=NoInline, kind=EXACTLY_ONCE> {
^ R|<local>/x|.R|kotlin/String.length|
}
)
R|<local>/x|.R|kotlin/String.length|
}
public final fun test7(): R|kotlin/Unit| {
lval x: R|kotlin/Any?| = String()
lval y: R|kotlin/Any?|
R|/run2|<R|kotlin/Unit|>(run2@fun <anonymous>(): R|kotlin/Unit| <inline=NoInline, kind=EXACTLY_ONCE> {
R|<local>/y| = R|<local>/x|
}
, run2@fun <anonymous>(): R|kotlin/Unit| <inline=NoInline, kind=EXACTLY_ONCE> {
^@run2 Unit
}
)
when () {
(R|<local>/y| is R|kotlin/String|) -> {
R|<local>/x|.<Unresolved name: length>#
}
}
}
@@ -71,3 +71,19 @@ fun test5(x: Any?, q: String?) {
p<!UNSAFE_CALL!>.<!>length // Bad: p is String? | (String? & Int) = String?
p?.length // OK: p is String?
}
fun test6() {
val x: String
// not necessarily initialized in second lambda (may call in any order)
run2({ x = ""; x.length }, { x.length })
x.length // initialized here
}
fun test7() {
val x: Any? = ""
val y: Any?
run2({ y = x }, { })
if (y is String) {
x.<!UNRESOLVED_REFERENCE!>length<!> // ok - aliased
}
}