Skip to content

Commit

Permalink
[FIR-TEST] Add tests for contracts resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
demiurg906 committed Apr 15, 2020
1 parent 17c6122 commit d808f3e
Show file tree
Hide file tree
Showing 21 changed files with 1,077 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
digraph atLeastOnce_kt {
graph [nodesep=3]
node [shape=box penwidth=2]
edge [penwidth=2]

subgraph cluster_0 {
color=red
0 [label="Enter function inlineRun" style="filled" fillcolor=red];
2 [label="Function call: R|<local>/block|.R|FakeOverride<kotlin/Function0.invoke: R|kotlin/Unit|>|()"];
1 [label="Exit function inlineRun" style="filled" fillcolor=red];
}
0 -> {2};
2 -> {1};

subgraph cluster_1 {
color=red
3 [label="Enter function myRun" style="filled" fillcolor=red];
5 [label="Function call: R|<local>/block|.R|FakeOverride<kotlin/Function0.invoke: R|kotlin/Unit|>|()"];
4 [label="Exit function myRun" style="filled" fillcolor=red];
}
3 -> {5};
5 -> {4};

subgraph cluster_2 {
color=red
6 [label="Enter function test_1" style="filled" fillcolor=red];
8 [label="Variable declaration: lval x: R|kotlin/Int|"];
9 [label="Postponed enter to lambda"];
subgraph cluster_3 {
color=blue
14 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
16 [label="Const: Int(1)"];
17 [label="Assignment: R|<local>/x|"];
15 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
}
10 [label="Postponed exit from lambda"];
11 [label="Function call: R|/inlineRun|(...)"];
12 [label="Access variable R|<local>/x|"];
13 [label="Function call: R|<local>/x|.R|kotlin/Int.inc|()"];
7 [label="Exit function test_1" style="filled" fillcolor=red];
}
6 -> {8};
8 -> {9};
9 -> {14};
9 -> {10} [color=red];
10 -> {11};
11 -> {12};
12 -> {13};
13 -> {7};
14 -> {16};
15 -> {14};
15 -> {10} [color=green];
16 -> {17};
17 -> {15};

subgraph cluster_4 {
color=red
18 [label="Enter function test_2" style="filled" fillcolor=red];
20 [label="Variable declaration: lval x: R|kotlin/Int|"];
21 [label="Postponed enter to lambda"];
subgraph cluster_5 {
color=blue
26 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
28 [label="Const: Int(1)"];
29 [label="Assignment: R|<local>/x|"];
27 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
}
22 [label="Postponed exit from lambda"];
23 [label="Function call: R|/myRun|(...)"];
24 [label="Access variable R|<local>/x|"];
25 [label="Function call: R|<local>/x|.R|kotlin/Int.inc|()"];
19 [label="Exit function test_2" style="filled" fillcolor=red];
}
18 -> {20};
20 -> {21};
21 -> {26};
21 -> {22} [color=red];
22 -> {23};
23 -> {24};
24 -> {25};
25 -> {19};
26 -> {28};
27 -> {26};
27 -> {22} [color=green];
28 -> {29};
29 -> {27};

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// !DUMP_CFG

import kotlin.contracts.*

inline fun inlineRun(block: () -> Unit) {
contract {
callsInPlace(block, InvocationKind.AT_LEAST_ONCE)
}
block()
}

fun myRun(block: () -> Unit) {
contract {
callsInPlace(block, InvocationKind.AT_LEAST_ONCE)
}
block()
}

fun test_1() {
val x: Int
inlineRun {
x = 1
}
x.inc()
}

fun test_2() {
val x: Int
myRun {
x = 1
}
x.inc()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
FILE: atLeastOnce.kt
public final inline fun inlineRun(block: R|() -> kotlin/Unit|): R|kotlin/Unit|
[R|Contract description]
<
CallsInPlace(block, AT_LEAST_ONCE)
>
{
[StubStatement]
R|<local>/block|.R|FakeOverride<kotlin/Function0.invoke: R|kotlin/Unit|>|()
}
public final fun myRun(block: R|() -> kotlin/Unit|): R|kotlin/Unit|
[R|Contract description]
<
CallsInPlace(block, AT_LEAST_ONCE)
>
{
[StubStatement]
R|<local>/block|.R|FakeOverride<kotlin/Function0.invoke: R|kotlin/Unit|>|()
}
public final fun test_1(): R|kotlin/Unit| {
lval x: R|kotlin/Int|
R|/inlineRun|(<L> = inlineRun@fun <anonymous>(): R|kotlin/Unit| <kind=AT_LEAST_ONCE> {
R|<local>/x| = Int(1)
}
)
R|<local>/x|.R|kotlin/Int.inc|()
}
public final fun test_2(): R|kotlin/Unit| {
lval x: R|kotlin/Int|
R|/myRun|(<L> = myRun@fun <anonymous>(): R|kotlin/Unit| <kind=AT_LEAST_ONCE> {
R|<local>/x| = Int(1)
}
)
R|<local>/x|.R|kotlin/Int.inc|()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
digraph atMostOnce_kt {
graph [nodesep=3]
node [shape=box penwidth=2]
edge [penwidth=2]

subgraph cluster_0 {
color=red
0 [label="Enter function inlineRun" style="filled" fillcolor=red];
2 [label="Function call: R|<local>/block|.R|FakeOverride<kotlin/Function0.invoke: R|kotlin/Unit|>|()"];
1 [label="Exit function inlineRun" style="filled" fillcolor=red];
}
0 -> {2};
2 -> {1};

subgraph cluster_1 {
color=red
3 [label="Enter function myRun" style="filled" fillcolor=red];
5 [label="Function call: R|<local>/block|.R|FakeOverride<kotlin/Function0.invoke: R|kotlin/Unit|>|()"];
4 [label="Exit function myRun" style="filled" fillcolor=red];
}
3 -> {5};
5 -> {4};

subgraph cluster_2 {
color=red
6 [label="Enter function test_1" style="filled" fillcolor=red];
8 [label="Variable declaration: lval x: R|kotlin/Int|"];
9 [label="Postponed enter to lambda"];
subgraph cluster_3 {
color=blue
14 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
16 [label="Const: Int(1)"];
17 [label="Assignment: R|<local>/x|"];
15 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
}
10 [label="Postponed exit from lambda"];
11 [label="Function call: R|/inlineRun|(...)"];
12 [label="Access variable R|<local>/x|"];
13 [label="Function call: R|<local>/x|.R|kotlin/Int.inc|()"];
7 [label="Exit function test_1" style="filled" fillcolor=red];
}
6 -> {8};
8 -> {9};
9 -> {14};
9 -> {10} [color=red];
10 -> {11};
11 -> {12};
12 -> {13};
13 -> {7};
14 -> {15 16};
15 -> {10} [color=green];
16 -> {17};
17 -> {15};

subgraph cluster_4 {
color=red
18 [label="Enter function test_2" style="filled" fillcolor=red];
20 [label="Variable declaration: lval x: R|kotlin/Int|"];
21 [label="Postponed enter to lambda"];
subgraph cluster_5 {
color=blue
26 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
28 [label="Const: Int(1)"];
29 [label="Assignment: R|<local>/x|"];
27 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
}
22 [label="Postponed exit from lambda"];
23 [label="Function call: R|/myRun|(...)"];
24 [label="Access variable R|<local>/x|"];
25 [label="Function call: R|<local>/x|.R|kotlin/Int.inc|()"];
19 [label="Exit function test_2" style="filled" fillcolor=red];
}
18 -> {20};
20 -> {21};
21 -> {26};
21 -> {22} [color=red];
22 -> {23};
23 -> {24};
24 -> {25};
25 -> {19};
26 -> {27 28};
27 -> {22} [color=green];
28 -> {29};
29 -> {27};

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// !DUMP_CFG

import kotlin.contracts.*

inline fun inlineRun(block: () -> Unit) {
contract {
callsInPlace(block, InvocationKind.AT_MOST_ONCE)
}
block()
}

fun myRun(block: () -> Unit) {
contract {
callsInPlace(block, InvocationKind.AT_MOST_ONCE)
}
block()
}

fun test_1() {
val x: Int
inlineRun {
x = 1
}
x.inc()
}

fun test_2() {
val x: Int
myRun {
x = 1
}
x.inc()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
FILE: atMostOnce.kt
public final inline fun inlineRun(block: R|() -> kotlin/Unit|): R|kotlin/Unit|
[R|Contract description]
<
CallsInPlace(block, AT_MOST_ONCE)
>
{
[StubStatement]
R|<local>/block|.R|FakeOverride<kotlin/Function0.invoke: R|kotlin/Unit|>|()
}
public final fun myRun(block: R|() -> kotlin/Unit|): R|kotlin/Unit|
[R|Contract description]
<
CallsInPlace(block, AT_MOST_ONCE)
>
{
[StubStatement]
R|<local>/block|.R|FakeOverride<kotlin/Function0.invoke: R|kotlin/Unit|>|()
}
public final fun test_1(): R|kotlin/Unit| {
lval x: R|kotlin/Int|
R|/inlineRun|(<L> = inlineRun@fun <anonymous>(): R|kotlin/Unit| <kind=AT_MOST_ONCE> {
R|<local>/x| = Int(1)
}
)
R|<local>/x|.R|kotlin/Int.inc|()
}
public final fun test_2(): R|kotlin/Unit| {
lval x: R|kotlin/Int|
R|/myRun|(<L> = myRun@fun <anonymous>(): R|kotlin/Unit| <kind=AT_MOST_ONCE> {
R|<local>/x| = Int(1)
}
)
R|<local>/x|.R|kotlin/Int.inc|()
}
Loading

0 comments on commit d808f3e

Please sign in to comment.