Files
kotlin-fork/compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromLibrary/conditionalEffects.dot
T
pyos a9be27e330 FIR CFG: add union nodes
Quick quiz:

 Q: In a CFG, what does `a -> b -> c -> d` mean?
 A: `a`, then `b`, then `c`, then `d`.

 Q: In a CFG, what does `a -> b -> d; a -> c -> d` mean?
 A: `a`, then `b` or `c`, then `d`.

 Q: So how do you encode "a, then (b, then c) or (c, then b), then d`?
 A: You can't.

Problem is, you need to, because that's what `a; run2({ b }, { c }); d`
does when `run2` has a contract that it calls both its lambda arguments
in-place: `shuffle(listOf(block1, block2)).forEach { it() }` is a
perfectly valid implementation for it, as little sense as that makes.

So that's what union nodes solve. When a node implements
`UnionNodeMarker`, its inputs are interpreted as "all visited in some
order" instead of the normal "one of the inputs is visited".

Currently this is used for data flow. It *should* also be used for
control flow, but it isn't. But it should be. But that's not so easy.

BTW, `try` exit is NOT a union node; although lambdas in one branch can
be completed according to types' of lambdas in another, data does not
flow between the branches anyway (since we don't know how much of the
`try` executed before jumping into `catch`, and `catch`es are mutually
exclusive) so a `try` expression is more like `when` than a function
call with called-in-place-exactly-once arguments. The fact that
`exitTryExpression` used `processUnionOfArguments` in a weird way
should've hinted at that, but now we know for certain.
2022-12-08 10:19:29 +00:00

302 lines
10 KiB
Plaintext
Vendored

digraph conditionalEffects_kt {
graph [nodesep=3]
node [shape=box penwidth=2]
edge [penwidth=2]
subgraph cluster_0 {
color=red
0 [label="Enter function test_1" style="filled" fillcolor=red];
subgraph cluster_1 {
color=blue
1 [label="Enter block"];
2 [label="Access variable R|<local>/x|"];
3 [label="Type operator: (R|<local>/x| is R|kotlin/Int|)"];
4 [label="Function call: R|kotlin/require|(...)" style="filled" fillcolor=yellow];
5 [label="Access variable R|<local>/x|"];
6 [label="Smart cast: R|<local>/x|"];
7 [label="Function call: R|<local>/x|.R|kotlin/Int.inc|()" style="filled" fillcolor=yellow];
8 [label="Exit block"];
}
9 [label="Exit function test_1" style="filled" fillcolor=red];
}
0 -> {1};
1 -> {2};
2 -> {3};
3 -> {4};
4 -> {5};
5 -> {6};
6 -> {7};
7 -> {8};
8 -> {9};
subgraph cluster_2 {
color=red
10 [label="Enter function test_2" style="filled" fillcolor=red];
subgraph cluster_3 {
color=blue
11 [label="Enter block"];
12 [label="Access variable R|<local>/x|"];
13 [label="Function call: R|kotlin/requireNotNull|<R|kotlin/String|>(...)" style="filled" fillcolor=yellow];
14 [label="Access variable R|<local>/x|"];
15 [label="Smart cast: R|<local>/x|"];
16 [label="Access variable R|kotlin/String.length|"];
17 [label="Exit block"];
}
18 [label="Exit function test_2" style="filled" fillcolor=red];
}
10 -> {11};
11 -> {12};
12 -> {13};
13 -> {14};
14 -> {15};
15 -> {16};
16 -> {17};
17 -> {18};
subgraph cluster_4 {
color=red
19 [label="Enter function test_3" style="filled" fillcolor=red];
subgraph cluster_5 {
color=blue
20 [label="Enter block"];
21 [label="Access variable R|<local>/x|"];
22 [label="Const: Null(null)"];
23 [label="Equality operator !="];
24 [label="Function call: R|kotlin/require|(...)" style="filled" fillcolor=yellow];
25 [label="Access variable R|<local>/x|"];
26 [label="Smart cast: R|<local>/x|"];
27 [label="Access variable R|kotlin/String.length|"];
28 [label="Exit block"];
}
29 [label="Exit function test_3" style="filled" fillcolor=red];
}
19 -> {20};
20 -> {21};
21 -> {22};
22 -> {23};
23 -> {24};
24 -> {25};
25 -> {26};
26 -> {27};
27 -> {28};
28 -> {29};
subgraph cluster_6 {
color=red
30 [label="Enter function test_4" style="filled" fillcolor=red];
subgraph cluster_7 {
color=blue
31 [label="Enter block"];
subgraph cluster_8 {
color=blue
32 [label="Enter &&"];
33 [label="Access variable R|<local>/x|"];
34 [label="Type operator: (R|<local>/x| is R|kotlin/String|)"];
35 [label="Exit left part of &&"];
36 [label="Enter right part of &&"];
37 [label="Access variable R|<local>/y|"];
38 [label="Const: Null(null)"];
39 [label="Equality operator !="];
40 [label="Exit &&"];
}
41 [label="Function call: R|kotlin/require|(...)" style="filled" fillcolor=yellow];
42 [label="Access variable R|<local>/x|"];
43 [label="Smart cast: R|<local>/x|"];
44 [label="Access variable R|kotlin/String.length|"];
45 [label="Access variable R|<local>/y|"];
46 [label="Smart cast: R|<local>/y|"];
47 [label="Access variable R|kotlin/String.length|"];
48 [label="Exit block"];
}
49 [label="Exit function test_4" style="filled" fillcolor=red];
}
30 -> {31};
31 -> {32};
32 -> {33};
33 -> {34};
34 -> {35};
35 -> {40 36};
36 -> {37};
37 -> {38};
38 -> {39};
39 -> {40};
40 -> {41};
41 -> {42};
42 -> {43};
43 -> {44};
44 -> {45};
45 -> {46};
46 -> {47};
47 -> {48};
48 -> {49};
subgraph cluster_9 {
color=red
50 [label="Enter function test_5" style="filled" fillcolor=red];
subgraph cluster_10 {
color=blue
51 [label="Enter block"];
subgraph cluster_11 {
color=blue
52 [label="Enter when"];
subgraph cluster_12 {
color=blue
53 [label="Enter when branch condition "];
54 [label="Access variable R|<local>/b|"];
55 [label="Exit when branch condition"];
}
subgraph cluster_13 {
color=blue
56 [label="Enter when branch condition else"];
57 [label="Exit when branch condition"];
}
58 [label="Enter when branch result"];
subgraph cluster_14 {
color=blue
59 [label="Enter block"];
60 [label="Access variable R|<local>/x|"];
61 [label="Access variable <Unresolved name: length>#"];
62 [label="Exit block"];
}
63 [label="Exit when branch result"];
64 [label="Enter when branch result"];
subgraph cluster_15 {
color=blue
65 [label="Enter block"];
66 [label="Access variable R|<local>/x|"];
67 [label="Type operator: (R|<local>/x| is R|kotlin/String|)"];
68 [label="Function call: R|kotlin/require|(...)" style="filled" fillcolor=yellow];
69 [label="Access variable R|<local>/x|"];
70 [label="Smart cast: R|<local>/x|"];
71 [label="Access variable R|kotlin/String.length|"];
72 [label="Exit block"];
}
73 [label="Exit when branch result"];
74 [label="Exit when"];
}
75 [label="Access variable R|<local>/x|"];
76 [label="Access variable <Unresolved name: length>#"];
77 [label="Exit block"];
}
78 [label="Exit function test_5" style="filled" fillcolor=red];
}
50 -> {51};
51 -> {52};
52 -> {53};
53 -> {54};
54 -> {55};
55 -> {64 56};
56 -> {57};
57 -> {58};
58 -> {59};
59 -> {60};
60 -> {61};
61 -> {62};
62 -> {63};
63 -> {74};
64 -> {65};
65 -> {66};
66 -> {67};
67 -> {68};
68 -> {69};
69 -> {70};
70 -> {71};
71 -> {72};
72 -> {73};
73 -> {74};
74 -> {75};
75 -> {76};
76 -> {77};
77 -> {78};
subgraph cluster_16 {
color=red
79 [label="Enter function test_6" style="filled" fillcolor=red];
subgraph cluster_17 {
color=blue
80 [label="Enter block"];
subgraph cluster_18 {
color=blue
81 [label="Enter when"];
subgraph cluster_19 {
color=blue
82 [label="Enter when branch condition "];
83 [label="Access variable R|<local>/b|"];
84 [label="Exit when branch condition"];
}
subgraph cluster_20 {
color=blue
85 [label="Enter when branch condition else"];
86 [label="Exit when branch condition"];
}
87 [label="Enter when branch result"];
subgraph cluster_21 {
color=blue
88 [label="Enter block"];
89 [label="Access variable R|<local>/x|"];
90 [label="Type operator: (R|<local>/x| is R|kotlin/String|)"];
91 [label="Function call: R|kotlin/require|(...)" style="filled" fillcolor=yellow];
92 [label="Access variable R|<local>/x|"];
93 [label="Smart cast: R|<local>/x|"];
94 [label="Access variable R|kotlin/String.length|"];
95 [label="Exit block"];
}
96 [label="Exit when branch result"];
97 [label="Enter when branch result"];
subgraph cluster_22 {
color=blue
98 [label="Enter block"];
99 [label="Access variable R|<local>/x|"];
100 [label="Type operator: (R|<local>/x| is R|kotlin/String|)"];
101 [label="Function call: R|kotlin/require|(...)" style="filled" fillcolor=yellow];
102 [label="Access variable R|<local>/x|"];
103 [label="Smart cast: R|<local>/x|"];
104 [label="Access variable R|kotlin/String.length|"];
105 [label="Exit block"];
}
106 [label="Exit when branch result"];
107 [label="Exit when"];
}
108 [label="Access variable R|<local>/x|"];
109 [label="Smart cast: R|<local>/x|"];
110 [label="Access variable R|kotlin/String.length|"];
111 [label="Exit block"];
}
112 [label="Exit function test_6" style="filled" fillcolor=red];
}
79 -> {80};
80 -> {81};
81 -> {82};
82 -> {83};
83 -> {84};
84 -> {97 85};
85 -> {86};
86 -> {87};
87 -> {88};
88 -> {89};
89 -> {90};
90 -> {91};
91 -> {92};
92 -> {93};
93 -> {94};
94 -> {95};
95 -> {96};
96 -> {107};
97 -> {98};
98 -> {99};
99 -> {100};
100 -> {101};
101 -> {102};
102 -> {103};
103 -> {104};
104 -> {105};
105 -> {106};
106 -> {107};
107 -> {108};
108 -> {109};
109 -> {110};
110 -> {111};
111 -> {112};
}