Files
kotlin-fork/compiler/fir/analysis-tests/testData/resolve/cfg/loops.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

553 lines
19 KiB
Plaintext
Vendored

digraph loops_kt {
graph [nodesep=3]
node [shape=box penwidth=2]
edge [penwidth=2]
subgraph cluster_0 {
color=red
0 [label="Enter function testWhile" style="filled" fillcolor=red];
subgraph cluster_1 {
color=blue
1 [label="Enter block"];
subgraph cluster_2 {
color=blue
2 [label="Enter while loop"];
subgraph cluster_3 {
color=blue
3 [label="Enter loop condition"];
4 [label="Access variable R|<local>/b|"];
5 [label="Exit loop condition"];
}
subgraph cluster_4 {
color=blue
6 [label="Enter loop block"];
subgraph cluster_5 {
color=blue
7 [label="Enter block"];
8 [label="Access variable R|<local>/x|"];
9 [label="Type operator: (R|<local>/x| is R|kotlin/String|)"];
10 [label="Variable declaration: lval y: R|kotlin/Boolean|"];
11 [label="Exit block"];
}
12 [label="Exit loop block"];
}
13 [label="Exit whileloop"];
}
14 [label="Access variable R|<local>/x|"];
15 [label="Type operator: (R|<local>/x| is R|kotlin/String|)"];
16 [label="Exit block"];
}
17 [label="Exit function testWhile" style="filled" fillcolor=red];
}
0 -> {1};
1 -> {2};
2 -> {3};
3 -> {4};
4 -> {5};
5 -> {13 6};
6 -> {7};
7 -> {8};
8 -> {9};
9 -> {10};
10 -> {11};
11 -> {12};
12 -> {3} [color=green style=dashed];
13 -> {14};
14 -> {15};
15 -> {16};
16 -> {17};
subgraph cluster_6 {
color=red
18 [label="Enter function testDoWhile" style="filled" fillcolor=red];
subgraph cluster_7 {
color=blue
19 [label="Enter block"];
subgraph cluster_8 {
color=blue
20 [label="Enter do-while loop"];
subgraph cluster_9 {
color=blue
21 [label="Enter loop block"];
subgraph cluster_10 {
color=blue
22 [label="Enter block"];
23 [label="Access variable R|<local>/x|"];
24 [label="Type operator: (R|<local>/x| is R|kotlin/String|)"];
25 [label="Variable declaration: lval y: R|kotlin/Boolean|"];
26 [label="Exit block"];
}
27 [label="Exit loop block"];
}
subgraph cluster_11 {
color=blue
28 [label="Enter loop condition"];
29 [label="Access variable R|<local>/b|"];
30 [label="Exit loop condition"];
}
31 [label="Exit do-whileloop"];
}
32 [label="Access variable R|<local>/x|"];
33 [label="Type operator: (R|<local>/x| is R|kotlin/String|)"];
34 [label="Exit block"];
}
35 [label="Exit function testDoWhile" style="filled" fillcolor=red];
}
18 -> {19};
19 -> {20};
20 -> {21};
21 -> {22};
22 -> {23};
23 -> {24};
24 -> {25};
25 -> {26};
26 -> {27};
27 -> {28};
28 -> {29};
29 -> {30};
30 -> {31};
30 -> {21} [color=green style=dashed];
31 -> {32};
32 -> {33};
33 -> {34};
34 -> {35};
subgraph cluster_12 {
color=red
36 [label="Enter function testFor" style="filled" fillcolor=red];
subgraph cluster_13 {
color=blue
37 [label="Enter block"];
subgraph cluster_14 {
color=blue
38 [label="Enter block"];
39 [label="Const: Int(0)"];
40 [label="Const: Int(5)"];
41 [label="Function call: Int(0).R|kotlin/Int.rangeTo|(...)" style="filled" fillcolor=yellow];
42 [label="Function call: Int(0).R|kotlin/Int.rangeTo|(...).R|kotlin/ranges/IntProgression.iterator|()" style="filled" fillcolor=yellow];
43 [label="Variable declaration: lval <iterator>: R|kotlin/collections/IntIterator|"];
subgraph cluster_15 {
color=blue
44 [label="Enter while loop"];
subgraph cluster_16 {
color=blue
45 [label="Enter loop condition"];
46 [label="Access variable R|<local>/<iterator>|"];
47 [label="Function call: R|<local>/<iterator>|.R|SubstitutionOverride<kotlin/collections/IntIterator.hasNext: R|kotlin/Boolean|>|()" style="filled" fillcolor=yellow];
48 [label="Exit loop condition"];
}
subgraph cluster_17 {
color=blue
49 [label="Enter loop block"];
subgraph cluster_18 {
color=blue
50 [label="Enter block"];
51 [label="Access variable R|<local>/<iterator>|"];
52 [label="Function call: R|<local>/<iterator>|.R|kotlin/collections/IntIterator.next|()" style="filled" fillcolor=yellow];
53 [label="Variable declaration: lval i: R|kotlin/Int|"];
54 [label="Access variable R|<local>/x|"];
55 [label="Type operator: (R|<local>/x| is R|kotlin/String|)"];
56 [label="Variable declaration: lval y: R|kotlin/Boolean|"];
57 [label="Exit block"];
}
58 [label="Exit loop block"];
}
59 [label="Exit whileloop"];
}
60 [label="Exit block"];
}
61 [label="Access variable R|<local>/x|"];
62 [label="Type operator: (R|<local>/x| is R|kotlin/String|)"];
63 [label="Exit block"];
}
64 [label="Exit function testFor" style="filled" fillcolor=red];
}
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 -> {59 49};
49 -> {50};
50 -> {51};
51 -> {52};
52 -> {53};
53 -> {54};
54 -> {55};
55 -> {56};
56 -> {57};
57 -> {58};
58 -> {45} [color=green style=dashed];
59 -> {60};
60 -> {61};
61 -> {62};
62 -> {63};
63 -> {64};
subgraph cluster_19 {
color=red
65 [label="Enter function testWhileTrue" style="filled" fillcolor=red];
subgraph cluster_20 {
color=blue
66 [label="Enter block"];
subgraph cluster_21 {
color=blue
67 [label="Enter while loop"];
subgraph cluster_22 {
color=blue
68 [label="Enter loop condition"];
69 [label="Const: Boolean(true)"];
70 [label="Exit loop condition"];
}
subgraph cluster_23 {
color=blue
71 [label="Enter loop block"];
subgraph cluster_24 {
color=blue
72 [label="Enter block"];
73 [label="Const: Int(1)"];
74 [label="Exit block"];
}
75 [label="Exit loop block"];
}
76 [label="Exit whileloop" style="filled" fillcolor=gray];
}
77 [label="Const: Int(1)" style="filled" fillcolor=gray];
78 [label="Exit block" style="filled" fillcolor=gray];
}
79 [label="Exit function testWhileTrue" style="filled" fillcolor=red style="filled" fillcolor=gray];
}
65 -> {66};
66 -> {67};
67 -> {68};
68 -> {69};
69 -> {70};
70 -> {71};
70 -> {76} [style=dotted];
71 -> {72};
72 -> {73};
73 -> {74};
74 -> {75};
75 -> {68} [color=green style=dashed];
76 -> {77} [style=dotted];
77 -> {78} [style=dotted];
78 -> {79} [style=dotted];
subgraph cluster_25 {
color=red
80 [label="Enter function testWhileTrueWithBreak" style="filled" fillcolor=red];
subgraph cluster_26 {
color=blue
81 [label="Enter block"];
subgraph cluster_27 {
color=blue
82 [label="Enter while loop"];
subgraph cluster_28 {
color=blue
83 [label="Enter loop condition"];
84 [label="Const: Boolean(true)"];
85 [label="Exit loop condition"];
}
subgraph cluster_29 {
color=blue
86 [label="Enter loop block"];
subgraph cluster_30 {
color=blue
87 [label="Enter block"];
subgraph cluster_31 {
color=blue
88 [label="Enter when"];
subgraph cluster_32 {
color=blue
89 [label="Enter when branch condition "];
90 [label="Access variable R|<local>/b|"];
91 [label="Exit when branch condition"];
}
92 [label="Synthetic else branch"];
93 [label="Enter when branch result"];
subgraph cluster_33 {
color=blue
94 [label="Enter block"];
95 [label="Jump: break@@@[Boolean(true)] "];
96 [label="Stub" style="filled" fillcolor=gray];
97 [label="Exit block" style="filled" fillcolor=gray];
}
98 [label="Exit when branch result" style="filled" fillcolor=gray];
99 [label="Exit when"];
}
100 [label="Exit block"];
}
101 [label="Exit loop block"];
}
102 [label="Exit whileloop"];
}
103 [label="Const: Int(1)"];
104 [label="Exit block"];
}
105 [label="Exit function testWhileTrueWithBreak" style="filled" fillcolor=red];
}
80 -> {81};
81 -> {82};
82 -> {83};
83 -> {84};
84 -> {85};
85 -> {86};
85 -> {102} [style=dotted];
86 -> {87};
87 -> {88};
88 -> {89};
89 -> {90};
90 -> {91};
91 -> {93 92};
92 -> {99};
93 -> {94};
94 -> {95};
95 -> {102};
95 -> {96} [style=dotted];
96 -> {97} [style=dotted];
97 -> {98} [style=dotted];
98 -> {99} [style=dotted];
99 -> {100};
100 -> {101};
101 -> {83} [color=green style=dashed];
102 -> {103};
103 -> {104};
104 -> {105};
subgraph cluster_34 {
color=red
106 [label="Enter function testWhileFalse" style="filled" fillcolor=red];
subgraph cluster_35 {
color=blue
107 [label="Enter block"];
subgraph cluster_36 {
color=blue
108 [label="Enter while loop"];
subgraph cluster_37 {
color=blue
109 [label="Enter loop condition"];
110 [label="Const: Boolean(false)"];
111 [label="Exit loop condition"];
}
subgraph cluster_38 {
color=blue
112 [label="Enter loop block" style="filled" fillcolor=gray];
subgraph cluster_39 {
color=blue
113 [label="Enter block" style="filled" fillcolor=gray];
114 [label="Const: Int(1)" style="filled" fillcolor=gray];
115 [label="Exit block" style="filled" fillcolor=gray];
}
116 [label="Exit loop block" style="filled" fillcolor=gray];
}
117 [label="Exit whileloop"];
}
118 [label="Const: Int(1)"];
119 [label="Exit block"];
}
120 [label="Exit function testWhileFalse" style="filled" fillcolor=red];
}
106 -> {107};
107 -> {108};
108 -> {109};
109 -> {110};
110 -> {111};
111 -> {117};
111 -> {112} [style=dotted];
112 -> {113} [style=dotted];
113 -> {114} [style=dotted];
114 -> {115} [style=dotted];
115 -> {116} [style=dotted];
116 -> {109} [color=green style=dotted];
117 -> {118};
118 -> {119};
119 -> {120};
subgraph cluster_40 {
color=red
121 [label="Enter function testDoWhileTrue" style="filled" fillcolor=red];
subgraph cluster_41 {
color=blue
122 [label="Enter block"];
subgraph cluster_42 {
color=blue
123 [label="Enter do-while loop"];
subgraph cluster_43 {
color=blue
124 [label="Enter loop block"];
subgraph cluster_44 {
color=blue
125 [label="Enter block"];
126 [label="Const: Int(1)"];
127 [label="Exit block"];
}
128 [label="Exit loop block"];
}
subgraph cluster_45 {
color=blue
129 [label="Enter loop condition"];
130 [label="Const: Boolean(true)"];
131 [label="Exit loop condition"];
}
132 [label="Exit do-whileloop" style="filled" fillcolor=gray];
}
133 [label="Const: Int(1)" style="filled" fillcolor=gray];
134 [label="Exit block" style="filled" fillcolor=gray];
}
135 [label="Exit function testDoWhileTrue" style="filled" fillcolor=red style="filled" fillcolor=gray];
}
121 -> {122};
122 -> {123};
123 -> {124};
124 -> {125};
125 -> {126};
126 -> {127};
127 -> {128};
128 -> {129};
129 -> {130};
130 -> {131};
131 -> {132} [style=dotted];
131 -> {124} [color=green style=dashed];
132 -> {133} [style=dotted];
133 -> {134} [style=dotted];
134 -> {135} [style=dotted];
subgraph cluster_46 {
color=red
136 [label="Enter function testDoWhileTrueWithBreak" style="filled" fillcolor=red];
subgraph cluster_47 {
color=blue
137 [label="Enter block"];
subgraph cluster_48 {
color=blue
138 [label="Enter do-while loop"];
subgraph cluster_49 {
color=blue
139 [label="Enter loop block"];
subgraph cluster_50 {
color=blue
140 [label="Enter block"];
subgraph cluster_51 {
color=blue
141 [label="Enter when"];
subgraph cluster_52 {
color=blue
142 [label="Enter when branch condition "];
143 [label="Access variable R|<local>/b|"];
144 [label="Exit when branch condition"];
}
145 [label="Synthetic else branch"];
146 [label="Enter when branch result"];
subgraph cluster_53 {
color=blue
147 [label="Enter block"];
148 [label="Jump: break@@@[Boolean(true)] "];
149 [label="Stub" style="filled" fillcolor=gray];
150 [label="Exit block" style="filled" fillcolor=gray];
}
151 [label="Exit when branch result" style="filled" fillcolor=gray];
152 [label="Exit when"];
}
153 [label="Exit block"];
}
154 [label="Exit loop block"];
}
subgraph cluster_54 {
color=blue
155 [label="Enter loop condition"];
156 [label="Const: Boolean(true)"];
157 [label="Exit loop condition"];
}
158 [label="Exit do-whileloop"];
}
159 [label="Const: Int(1)"];
160 [label="Exit block"];
}
161 [label="Exit function testDoWhileTrueWithBreak" style="filled" fillcolor=red];
}
136 -> {137};
137 -> {138};
138 -> {139};
139 -> {140};
140 -> {141};
141 -> {142};
142 -> {143};
143 -> {144};
144 -> {146 145};
145 -> {152};
146 -> {147};
147 -> {148};
148 -> {158};
148 -> {149} [style=dotted];
149 -> {150} [style=dotted];
150 -> {151} [style=dotted];
151 -> {152} [style=dotted];
152 -> {153};
153 -> {154};
154 -> {155};
155 -> {156};
156 -> {157};
157 -> {158} [style=dotted];
157 -> {139} [color=green style=dashed];
158 -> {159};
159 -> {160};
160 -> {161};
subgraph cluster_55 {
color=red
162 [label="Enter function testDoWhileFalse" style="filled" fillcolor=red];
subgraph cluster_56 {
color=blue
163 [label="Enter block"];
subgraph cluster_57 {
color=blue
164 [label="Enter do-while loop"];
subgraph cluster_58 {
color=blue
165 [label="Enter loop block"];
subgraph cluster_59 {
color=blue
166 [label="Enter block"];
167 [label="Const: Int(1)"];
168 [label="Exit block"];
}
169 [label="Exit loop block"];
}
subgraph cluster_60 {
color=blue
170 [label="Enter loop condition"];
171 [label="Const: Boolean(false)"];
172 [label="Exit loop condition"];
}
173 [label="Exit do-whileloop"];
}
174 [label="Const: Int(1)"];
175 [label="Exit block"];
}
176 [label="Exit function testDoWhileFalse" style="filled" fillcolor=red];
}
162 -> {163};
163 -> {164};
164 -> {165};
165 -> {166};
166 -> {167};
167 -> {168};
168 -> {169};
169 -> {170};
170 -> {171};
171 -> {172};
172 -> {173};
172 -> {165} [color=green style=dotted];
173 -> {174};
174 -> {175};
175 -> {176};
}