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

519 lines
19 KiB
Plaintext
Vendored

digraph localClassesWithImplicit_kt {
graph [nodesep=3]
node [shape=box penwidth=2]
edge [penwidth=2]
subgraph cluster_0 {
color=red
0 [label="Enter function myRun" style="filled" fillcolor=red];
subgraph cluster_1 {
color=blue
1 [label="Enter block"];
2 [label="Function call: R|<local>/block|.R|SubstitutionOverride<kotlin/Function0.invoke: R|T|>|()" style="filled" fillcolor=yellow];
3 [label="Jump: ^myRun R|<local>/block|.R|SubstitutionOverride<kotlin/Function0.invoke: R|T|>|()"];
4 [label="Stub" style="filled" fillcolor=gray];
5 [label="Exit block" style="filled" fillcolor=gray];
}
6 [label="Exit function myRun" style="filled" fillcolor=red];
}
0 -> {1};
1 -> {2};
2 -> {3};
3 -> {6};
3 -> {4} [style=dotted];
4 -> {5} [style=dotted];
5 -> {6} [style=dotted];
subgraph cluster_2 {
color=red
7 [label="Enter function test" style="filled" fillcolor=red];
subgraph cluster_3 {
color=blue
8 [label="Enter block"];
subgraph cluster_4 {
color=blue
9 [label="Enter when"];
subgraph cluster_5 {
color=blue
10 [label="Enter when branch condition "];
11 [label="Access variable R|<local>/a|"];
12 [label="Type operator: (R|<local>/a| !is R|kotlin/String|)"];
13 [label="Exit when branch condition"];
}
14 [label="Synthetic else branch"];
15 [label="Enter when branch result"];
subgraph cluster_6 {
color=blue
16 [label="Enter block"];
17 [label="Jump: ^test Unit"];
18 [label="Stub" style="filled" fillcolor=gray];
19 [label="Exit block" style="filled" fillcolor=gray];
}
20 [label="Exit when branch result" style="filled" fillcolor=gray];
21 [label="Exit when"];
}
22 [label="Exit local class test"];
23 [label="Enter anonymous object"];
subgraph cluster_7 {
color=blue
31 [label="Enter class <anonymous object>" style="filled" fillcolor=red];
32 [label="Exit class <anonymous object>" style="filled" fillcolor=red];
}
24 [label="Exit anonymous object"];
25 [label="Exit anonymous object expression"];
26 [label="Variable declaration: lval x: R|<anonymous>|"];
27 [label="Exit block"];
}
subgraph cluster_8 {
color=blue
29 [label="Enter class A" style="filled" fillcolor=red];
30 [label="Exit class A" style="filled" fillcolor=red];
}
28 [label="Exit function test" style="filled" fillcolor=red];
}
7 -> {8};
8 -> {9};
9 -> {10};
10 -> {11};
11 -> {12};
12 -> {13};
13 -> {15 14};
14 -> {21};
15 -> {16};
16 -> {17};
17 -> {28};
17 -> {18} [style=dotted];
18 -> {19} [style=dotted];
19 -> {20} [style=dotted];
20 -> {21} [style=dotted];
21 -> {22};
21 -> {33 36 73 92} [color=red];
22 -> {23};
22 -> {99 102 139 158} [color=red];
22 -> {33 36 73 92 29} [color=green];
22 -> {33 36 73 92 29} [style=dashed];
23 -> {24} [color=red];
23 -> {31} [color=green];
23 -> {31} [style=dashed];
24 -> {25};
24 -> {99 102 139 158} [color=green];
24 -> {99 102 139 158} [style=dashed];
25 -> {26};
26 -> {27};
27 -> {28};
29 -> {30} [color=green];
31 -> {32} [color=green];
32 -> {24} [color=green];
subgraph cluster_9 {
color=red
33 [label="Enter function <init>" style="filled" fillcolor=red];
34 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=yellow];
35 [label="Exit function <init>" style="filled" fillcolor=red];
}
33 -> {34};
34 -> {35};
subgraph cluster_10 {
color=red
36 [label="Enter function foo" style="filled" fillcolor=red];
subgraph cluster_11 {
color=blue
37 [label="Enter block"];
38 [label="Postponed enter to lambda"];
subgraph cluster_12 {
color=blue
45 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
subgraph cluster_13 {
color=blue
46 [label="Enter block"];
47 [label="Access variable R|<local>/a|"];
48 [label="Smart cast: R|<local>/a|"];
49 [label="Access variable R|kotlin/String.length|"];
subgraph cluster_14 {
color=blue
50 [label="Enter when"];
subgraph cluster_15 {
color=blue
51 [label="Enter when branch condition "];
52 [label="Access variable R|<local>/b|"];
53 [label="Type operator: (R|<local>/b| is R|kotlin/String|)"];
54 [label="Exit when branch condition"];
}
subgraph cluster_16 {
color=blue
55 [label="Enter when branch condition else"];
56 [label="Exit when branch condition"];
}
57 [label="Enter when branch result"];
subgraph cluster_17 {
color=blue
58 [label="Enter block"];
59 [label="Const: Int(1)"];
60 [label="Exit block"];
}
61 [label="Exit when branch result"];
62 [label="Enter when branch result"];
subgraph cluster_18 {
color=blue
63 [label="Enter block"];
64 [label="Access variable R|<local>/b|"];
65 [label="Smart cast: R|<local>/b|"];
66 [label="Access variable R|kotlin/String.length|"];
67 [label="Function call: this@R|/A|.R|<local>/bar|()" style="filled" fillcolor=yellow];
68 [label="Exit block"];
}
69 [label="Exit when branch result"];
70 [label="Exit when"];
}
71 [label="Exit block"];
}
72 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
}
39 [label="Postponed exit from lambda"];
40 [label="Function call: R|/myRun|<R|kotlin/Int|>(...)" style="filled" fillcolor=yellow];
41 [label="Jump: ^foo R|/myRun|<R|kotlin/Int|>(<L> = myRun@fun <anonymous>(): R|kotlin/Int| <inline=Inline, kind=UNKNOWN> {
R|<local>/a|.R|kotlin/String.length|
^ when () {
(R|<local>/b| is R|kotlin/String|) -> {
R|<local>/b|.R|kotlin/String.length|
this@R|/A|.R|<local>/bar|()
}
else -> {
Int(1)
}
}
}
)"];
42 [label="Stub" style="filled" fillcolor=gray];
43 [label="Exit block" style="filled" fillcolor=gray];
}
44 [label="Exit function foo" style="filled" fillcolor=red];
}
36 -> {37};
37 -> {38};
38 -> {39 45};
38 -> {45} [style=dashed];
39 -> {40};
39 -> {38} [color=green style=dashed];
40 -> {41};
41 -> {44};
41 -> {42} [style=dotted];
42 -> {43} [style=dotted];
43 -> {44} [style=dotted];
45 -> {46};
46 -> {47};
47 -> {48};
48 -> {49};
49 -> {50};
50 -> {51};
51 -> {52};
52 -> {53};
53 -> {54};
54 -> {62 55};
55 -> {56};
56 -> {57};
57 -> {58};
58 -> {59};
59 -> {60};
60 -> {61};
61 -> {70};
62 -> {63};
63 -> {64};
64 -> {65};
65 -> {66};
66 -> {67};
67 -> {68};
68 -> {69};
69 -> {70};
70 -> {71};
71 -> {72};
72 -> {39};
subgraph cluster_19 {
color=red
73 [label="Enter function bar" style="filled" fillcolor=red];
subgraph cluster_20 {
color=blue
74 [label="Enter block"];
75 [label="Postponed enter to lambda"];
subgraph cluster_21 {
color=blue
82 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
subgraph cluster_22 {
color=blue
83 [label="Enter block"];
84 [label="Access variable R|<local>/b|"];
85 [label="Access variable <Unresolved name: length>#"];
86 [label="Access variable R|<local>/a|"];
87 [label="Smart cast: R|<local>/a|"];
88 [label="Access variable R|kotlin/String.length|"];
89 [label="Function call: this@R|/A|.R|<local>/baz|()" style="filled" fillcolor=yellow];
90 [label="Exit block"];
}
91 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
}
76 [label="Postponed exit from lambda"];
77 [label="Function call: R|/myRun|<R|kotlin/Int|>(...)" style="filled" fillcolor=yellow];
78 [label="Jump: ^bar R|/myRun|<R|kotlin/Int|>(<L> = myRun@fun <anonymous>(): R|kotlin/Int| <inline=Inline, kind=UNKNOWN> {
R|<local>/b|.<Unresolved name: length>#
R|<local>/a|.R|kotlin/String.length|
^ this@R|/A|.R|<local>/baz|()
}
)"];
79 [label="Stub" style="filled" fillcolor=gray];
80 [label="Exit block" style="filled" fillcolor=gray];
}
81 [label="Exit function bar" style="filled" fillcolor=red];
}
73 -> {74};
74 -> {75};
75 -> {76 82};
75 -> {82} [style=dashed];
76 -> {77};
76 -> {75} [color=green style=dashed];
77 -> {78};
78 -> {81};
78 -> {79} [style=dotted];
79 -> {80} [style=dotted];
80 -> {81} [style=dotted];
82 -> {83};
83 -> {84};
84 -> {85};
85 -> {86};
86 -> {87};
87 -> {88};
88 -> {89};
89 -> {90};
90 -> {91};
91 -> {76};
subgraph cluster_23 {
color=red
92 [label="Enter function baz" style="filled" fillcolor=red];
subgraph cluster_24 {
color=blue
93 [label="Enter block"];
94 [label="Const: Int(1)"];
95 [label="Jump: ^baz Int(1)"];
96 [label="Stub" style="filled" fillcolor=gray];
97 [label="Exit block" style="filled" fillcolor=gray];
}
98 [label="Exit function baz" style="filled" fillcolor=red];
}
92 -> {93};
93 -> {94};
94 -> {95};
95 -> {98};
95 -> {96} [style=dotted];
96 -> {97} [style=dotted];
97 -> {98} [style=dotted];
subgraph cluster_25 {
color=red
99 [label="Enter function <init>" style="filled" fillcolor=red];
100 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=yellow];
101 [label="Exit function <init>" style="filled" fillcolor=red];
}
99 -> {100};
100 -> {101};
subgraph cluster_26 {
color=red
102 [label="Enter function foo" style="filled" fillcolor=red];
subgraph cluster_27 {
color=blue
103 [label="Enter block"];
104 [label="Postponed enter to lambda"];
subgraph cluster_28 {
color=blue
111 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
subgraph cluster_29 {
color=blue
112 [label="Enter block"];
113 [label="Access variable R|<local>/a|"];
114 [label="Smart cast: R|<local>/a|"];
115 [label="Access variable R|kotlin/String.length|"];
subgraph cluster_30 {
color=blue
116 [label="Enter when"];
subgraph cluster_31 {
color=blue
117 [label="Enter when branch condition "];
118 [label="Access variable R|<local>/b|"];
119 [label="Type operator: (R|<local>/b| is R|kotlin/String|)"];
120 [label="Exit when branch condition"];
}
subgraph cluster_32 {
color=blue
121 [label="Enter when branch condition else"];
122 [label="Exit when branch condition"];
}
123 [label="Enter when branch result"];
subgraph cluster_33 {
color=blue
124 [label="Enter block"];
125 [label="Const: Int(1)"];
126 [label="Exit block"];
}
127 [label="Exit when branch result"];
128 [label="Enter when branch result"];
subgraph cluster_34 {
color=blue
129 [label="Enter block"];
130 [label="Access variable R|<local>/b|"];
131 [label="Smart cast: R|<local>/b|"];
132 [label="Access variable R|kotlin/String.length|"];
133 [label="Function call: this@R|/<anonymous>|.R|/<anonymous>.bar|()" style="filled" fillcolor=yellow];
134 [label="Exit block"];
}
135 [label="Exit when branch result"];
136 [label="Exit when"];
}
137 [label="Exit block"];
}
138 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
}
105 [label="Postponed exit from lambda"];
106 [label="Function call: R|/myRun|<R|kotlin/Int|>(...)" style="filled" fillcolor=yellow];
107 [label="Jump: ^foo R|/myRun|<R|kotlin/Int|>(<L> = myRun@fun <anonymous>(): R|kotlin/Int| <inline=Inline, kind=UNKNOWN> {
R|<local>/a|.R|kotlin/String.length|
^ when () {
(R|<local>/b| is R|kotlin/String|) -> {
R|<local>/b|.R|kotlin/String.length|
this@R|/<anonymous>|.R|/<anonymous>.bar|()
}
else -> {
Int(1)
}
}
}
)"];
108 [label="Stub" style="filled" fillcolor=gray];
109 [label="Exit block" style="filled" fillcolor=gray];
}
110 [label="Exit function foo" style="filled" fillcolor=red];
}
102 -> {103};
103 -> {104};
104 -> {105 111};
104 -> {111} [style=dashed];
105 -> {106};
105 -> {104} [color=green style=dashed];
106 -> {107};
107 -> {110};
107 -> {108} [style=dotted];
108 -> {109} [style=dotted];
109 -> {110} [style=dotted];
111 -> {112};
112 -> {113};
113 -> {114};
114 -> {115};
115 -> {116};
116 -> {117};
117 -> {118};
118 -> {119};
119 -> {120};
120 -> {128 121};
121 -> {122};
122 -> {123};
123 -> {124};
124 -> {125};
125 -> {126};
126 -> {127};
127 -> {136};
128 -> {129};
129 -> {130};
130 -> {131};
131 -> {132};
132 -> {133};
133 -> {134};
134 -> {135};
135 -> {136};
136 -> {137};
137 -> {138};
138 -> {105};
subgraph cluster_35 {
color=red
139 [label="Enter function bar" style="filled" fillcolor=red];
subgraph cluster_36 {
color=blue
140 [label="Enter block"];
141 [label="Postponed enter to lambda"];
subgraph cluster_37 {
color=blue
148 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
subgraph cluster_38 {
color=blue
149 [label="Enter block"];
150 [label="Access variable R|<local>/a|"];
151 [label="Smart cast: R|<local>/a|"];
152 [label="Access variable R|kotlin/String.length|"];
153 [label="Access variable R|<local>/b|"];
154 [label="Access variable <Unresolved name: length>#"];
155 [label="Function call: this@R|/<anonymous>|.R|/<anonymous>.baz|()" style="filled" fillcolor=yellow];
156 [label="Exit block"];
}
157 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
}
142 [label="Postponed exit from lambda"];
143 [label="Function call: R|/myRun|<R|kotlin/Int|>(...)" style="filled" fillcolor=yellow];
144 [label="Jump: ^bar R|/myRun|<R|kotlin/Int|>(<L> = myRun@fun <anonymous>(): R|kotlin/Int| <inline=Inline, kind=UNKNOWN> {
R|<local>/a|.R|kotlin/String.length|
R|<local>/b|.<Unresolved name: length>#
^ this@R|/<anonymous>|.R|/<anonymous>.baz|()
}
)"];
145 [label="Stub" style="filled" fillcolor=gray];
146 [label="Exit block" style="filled" fillcolor=gray];
}
147 [label="Exit function bar" style="filled" fillcolor=red];
}
139 -> {140};
140 -> {141};
141 -> {142 148};
141 -> {148} [style=dashed];
142 -> {143};
142 -> {141} [color=green style=dashed];
143 -> {144};
144 -> {147};
144 -> {145} [style=dotted];
145 -> {146} [style=dotted];
146 -> {147} [style=dotted];
148 -> {149};
149 -> {150};
150 -> {151};
151 -> {152};
152 -> {153};
153 -> {154};
154 -> {155};
155 -> {156};
156 -> {157};
157 -> {142};
subgraph cluster_39 {
color=red
158 [label="Enter function baz" style="filled" fillcolor=red];
subgraph cluster_40 {
color=blue
159 [label="Enter block"];
160 [label="Const: Int(1)"];
161 [label="Jump: ^baz Int(1)"];
162 [label="Stub" style="filled" fillcolor=gray];
163 [label="Exit block" style="filled" fillcolor=gray];
}
164 [label="Exit function baz" style="filled" fillcolor=red];
}
158 -> {159};
159 -> {160};
160 -> {161};
161 -> {164};
161 -> {162} [style=dotted];
162 -> {163} [style=dotted];
163 -> {164} [style=dotted];
}