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

410 lines
14 KiB
Plaintext
Vendored

digraph casts_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| as R|kotlin/String|)"];
4 [label="Access variable R|<local>/x|"];
5 [label="Smart cast: R|<local>/x|"];
6 [label="Access variable R|kotlin/String.length|"];
7 [label="Exit block"];
}
8 [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};
subgraph cluster_2 {
color=red
9 [label="Enter function test_2" style="filled" fillcolor=red];
subgraph cluster_3 {
color=blue
10 [label="Enter block"];
subgraph cluster_4 {
color=blue
11 [label="Enter when"];
subgraph cluster_5 {
color=blue
12 [label="Enter when branch condition "];
13 [label="Access variable R|<local>/x|"];
14 [label="Type operator: (R|<local>/x| as R|kotlin/Boolean|)"];
15 [label="Exit when branch condition"];
}
16 [label="Synthetic else branch"];
17 [label="Enter when branch result"];
subgraph cluster_6 {
color=blue
18 [label="Enter block"];
19 [label="Access variable R|<local>/x|"];
20 [label="Smart cast: R|<local>/x|"];
21 [label="Function call: R|<local>/x|.R|kotlin/Boolean.not|()" style="filled" fillcolor=yellow];
22 [label="Exit block"];
}
23 [label="Exit when branch result"];
24 [label="Exit when"];
}
25 [label="Access variable R|<local>/x|"];
26 [label="Smart cast: R|<local>/x|"];
27 [label="Function call: R|<local>/x|.R|kotlin/Boolean.not|()" style="filled" fillcolor=yellow];
28 [label="Exit block"];
}
29 [label="Exit function test_2" style="filled" fillcolor=red];
}
9 -> {10};
10 -> {11};
11 -> {12};
12 -> {13};
13 -> {14};
14 -> {15};
15 -> {17 16};
16 -> {24};
17 -> {18};
18 -> {19};
19 -> {20};
20 -> {21};
21 -> {22};
22 -> {23};
23 -> {24};
24 -> {25};
25 -> {26};
26 -> {27};
27 -> {28};
28 -> {29};
subgraph cluster_7 {
color=red
30 [label="Enter function test_3" style="filled" fillcolor=red];
subgraph cluster_8 {
color=blue
31 [label="Enter block"];
subgraph cluster_9 {
color=blue
32 [label="Enter when"];
subgraph cluster_10 {
color=blue
33 [label="Enter when branch condition "];
subgraph cluster_11 {
color=blue
34 [label="Enter &&"];
35 [label="Access variable R|<local>/b|"];
36 [label="Exit left part of &&"];
37 [label="Enter right part of &&"];
38 [label="Access variable R|<local>/x|"];
39 [label="Type operator: (R|<local>/x| as R|kotlin/Boolean|)"];
40 [label="Exit &&"];
}
41 [label="Exit when branch condition"];
}
42 [label="Synthetic else branch"];
43 [label="Enter when branch result"];
subgraph cluster_12 {
color=blue
44 [label="Enter block"];
45 [label="Access variable R|<local>/x|"];
46 [label="Smart cast: R|<local>/x|"];
47 [label="Function call: R|<local>/x|.R|kotlin/Boolean.not|()" style="filled" fillcolor=yellow];
48 [label="Exit block"];
}
49 [label="Exit when branch result"];
50 [label="Exit when"];
}
51 [label="Access variable R|<local>/x|"];
52 [label="Function call: R|<local>/x|.<Unresolved name: not>#()" style="filled" fillcolor=yellow];
subgraph cluster_13 {
color=blue
53 [label="Enter when"];
subgraph cluster_14 {
color=blue
54 [label="Enter when branch condition "];
subgraph cluster_15 {
color=blue
55 [label="Enter &&"];
56 [label="Access variable R|<local>/b|"];
57 [label="Exit left part of &&"];
58 [label="Enter right part of &&"];
59 [label="Access variable R|<local>/x|"];
60 [label="Type operator: (R|<local>/x| as R|kotlin/Boolean|)"];
61 [label="Const: Boolean(true)"];
62 [label="Equality operator =="];
63 [label="Exit &&"];
}
64 [label="Exit when branch condition"];
}
65 [label="Synthetic else branch"];
66 [label="Enter when branch result"];
subgraph cluster_16 {
color=blue
67 [label="Enter block"];
68 [label="Access variable R|<local>/x|"];
69 [label="Smart cast: R|<local>/x|"];
70 [label="Function call: R|<local>/x|.R|kotlin/Boolean.not|()" style="filled" fillcolor=yellow];
71 [label="Exit block"];
}
72 [label="Exit when branch result"];
73 [label="Exit when"];
}
74 [label="Access variable R|<local>/x|"];
75 [label="Function call: R|<local>/x|.<Unresolved name: not>#()" style="filled" fillcolor=yellow];
subgraph cluster_17 {
color=blue
76 [label="Enter when"];
subgraph cluster_18 {
color=blue
77 [label="Enter when branch condition "];
subgraph cluster_19 {
color=blue
78 [label="Enter ||"];
79 [label="Access variable R|<local>/b|"];
80 [label="Exit left part of ||"];
81 [label="Enter right part of ||"];
82 [label="Access variable R|<local>/x|"];
83 [label="Type operator: (R|<local>/x| as R|kotlin/Boolean|)"];
84 [label="Exit ||"];
}
85 [label="Exit when branch condition"];
}
86 [label="Synthetic else branch"];
87 [label="Enter when branch result"];
subgraph cluster_20 {
color=blue
88 [label="Enter block"];
89 [label="Access variable R|<local>/x|"];
90 [label="Function call: R|<local>/x|.<Unresolved name: not>#()" style="filled" fillcolor=yellow];
91 [label="Exit block"];
}
92 [label="Exit when branch result"];
93 [label="Exit when"];
}
94 [label="Access variable R|<local>/x|"];
95 [label="Function call: R|<local>/x|.<Unresolved name: not>#()" style="filled" fillcolor=yellow];
96 [label="Exit block"];
}
97 [label="Exit function test_3" style="filled" fillcolor=red];
}
30 -> {31};
31 -> {32};
32 -> {33};
33 -> {34};
34 -> {35};
35 -> {36};
36 -> {40 37};
37 -> {38};
38 -> {39};
39 -> {40};
40 -> {41};
41 -> {43 42};
42 -> {50};
43 -> {44};
44 -> {45};
45 -> {46};
46 -> {47};
47 -> {48};
48 -> {49};
49 -> {50};
50 -> {51};
51 -> {52};
52 -> {53};
53 -> {54};
54 -> {55};
55 -> {56};
56 -> {57};
57 -> {63 58};
58 -> {59};
59 -> {60};
60 -> {61};
61 -> {62};
62 -> {63};
63 -> {64};
64 -> {66 65};
65 -> {73};
66 -> {67};
67 -> {68};
68 -> {69};
69 -> {70};
70 -> {71};
71 -> {72};
72 -> {73};
73 -> {74};
74 -> {75};
75 -> {76};
76 -> {77};
77 -> {78};
78 -> {79};
79 -> {80};
80 -> {84 81};
81 -> {82};
82 -> {83};
83 -> {84};
84 -> {85};
85 -> {87 86};
86 -> {93};
87 -> {88};
88 -> {89};
89 -> {90};
90 -> {91};
91 -> {92};
92 -> {93};
93 -> {94};
94 -> {95};
95 -> {96};
96 -> {97};
subgraph cluster_21 {
color=red
98 [label="Enter function test_4" style="filled" fillcolor=red];
subgraph cluster_22 {
color=blue
99 [label="Enter block"];
subgraph cluster_23 {
color=blue
100 [label="Enter when"];
subgraph cluster_24 {
color=blue
101 [label="Enter when branch condition "];
102 [label="Access variable R|<local>/b|"];
103 [label="Type operator: (R|<local>/b| as? R|kotlin/Boolean|)"];
104 [label="Const: Null(null)"];
105 [label="Equality operator !="];
106 [label="Exit when branch condition"];
}
subgraph cluster_25 {
color=blue
107 [label="Enter when branch condition else"];
108 [label="Exit when branch condition"];
}
109 [label="Enter when branch result"];
subgraph cluster_26 {
color=blue
110 [label="Enter block"];
111 [label="Access variable R|<local>/b|"];
112 [label="Function call: R|<local>/b|.<Unresolved name: not>#()" style="filled" fillcolor=yellow];
113 [label="Exit block"];
}
114 [label="Exit when branch result"];
115 [label="Enter when branch result"];
subgraph cluster_27 {
color=blue
116 [label="Enter block"];
117 [label="Access variable R|<local>/b|"];
118 [label="Smart cast: R|<local>/b|"];
119 [label="Function call: R|<local>/b|.R|kotlin/Boolean.not|()" style="filled" fillcolor=yellow];
120 [label="Exit block"];
}
121 [label="Exit when branch result"];
122 [label="Exit when"];
}
123 [label="Access variable R|<local>/b|"];
124 [label="Function call: R|<local>/b|.<Unresolved name: not>#()" style="filled" fillcolor=yellow];
subgraph cluster_28 {
color=blue
125 [label="Enter when"];
subgraph cluster_29 {
color=blue
126 [label="Enter when branch condition "];
127 [label="Access variable R|<local>/b|"];
128 [label="Type operator: (R|<local>/b| as? R|kotlin/Boolean|)"];
129 [label="Const: Null(null)"];
130 [label="Equality operator =="];
131 [label="Exit when branch condition"];
}
subgraph cluster_30 {
color=blue
132 [label="Enter when branch condition else"];
133 [label="Exit when branch condition"];
}
134 [label="Enter when branch result"];
subgraph cluster_31 {
color=blue
135 [label="Enter block"];
136 [label="Access variable R|<local>/b|"];
137 [label="Smart cast: R|<local>/b|"];
138 [label="Function call: R|<local>/b|.R|kotlin/Boolean.not|()" style="filled" fillcolor=yellow];
139 [label="Exit block"];
}
140 [label="Exit when branch result"];
141 [label="Enter when branch result"];
subgraph cluster_32 {
color=blue
142 [label="Enter block"];
143 [label="Access variable R|<local>/b|"];
144 [label="Function call: R|<local>/b|.<Unresolved name: not>#()" style="filled" fillcolor=yellow];
145 [label="Exit block"];
}
146 [label="Exit when branch result"];
147 [label="Exit when"];
}
148 [label="Access variable R|<local>/b|"];
149 [label="Function call: R|<local>/b|.<Unresolved name: not>#()" style="filled" fillcolor=yellow];
150 [label="Exit block"];
}
151 [label="Exit function test_4" style="filled" fillcolor=red];
}
98 -> {99};
99 -> {100};
100 -> {101};
101 -> {102};
102 -> {103};
103 -> {104};
104 -> {105};
105 -> {106};
106 -> {115 107};
107 -> {108};
108 -> {109};
109 -> {110};
110 -> {111};
111 -> {112};
112 -> {113};
113 -> {114};
114 -> {122};
115 -> {116};
116 -> {117};
117 -> {118};
118 -> {119};
119 -> {120};
120 -> {121};
121 -> {122};
122 -> {123};
123 -> {124};
124 -> {125};
125 -> {126};
126 -> {127};
127 -> {128};
128 -> {129};
129 -> {130};
130 -> {131};
131 -> {141 132};
132 -> {133};
133 -> {134};
134 -> {135};
135 -> {136};
136 -> {137};
137 -> {138};
138 -> {139};
139 -> {140};
140 -> {147};
141 -> {142};
142 -> {143};
143 -> {144};
144 -> {145};
145 -> {146};
146 -> {147};
147 -> {148};
148 -> {149};
149 -> {150};
150 -> {151};
}