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

344 lines
11 KiB
Plaintext
Vendored

digraph safeCallAndEqualityToBool_kt {
graph [nodesep=3]
node [shape=box penwidth=2]
edge [penwidth=2]
subgraph cluster_0 {
color=red
0 [label="Enter function check" style="filled" fillcolor=red];
subgraph cluster_1 {
color=blue
1 [label="Enter block"];
2 [label="Const: Boolean(true)"];
3 [label="Jump: ^check Boolean(true)"];
4 [label="Stub" style="filled" fillcolor=gray];
5 [label="Exit block" style="filled" fillcolor=gray];
}
6 [label="Exit function check" 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_1" 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>/s|"];
12 [label="Enter safe call"];
13 [label="Function call: $subj$.R|/check|()" style="filled" fillcolor=yellow];
14 [label="Exit safe call"];
15 [label="Const: Boolean(true)"];
16 [label="Equality operator =="];
17 [label="Exit when branch condition"];
}
subgraph cluster_6 {
color=blue
18 [label="Enter when branch condition else"];
19 [label="Exit when branch condition"];
}
20 [label="Enter when branch result"];
subgraph cluster_7 {
color=blue
21 [label="Enter block"];
22 [label="Access variable R|<local>/s|"];
23 [label="Access variable <Inapplicable(UNSAFE_CALL): kotlin/String.length>#"];
24 [label="Exit block"];
}
25 [label="Exit when branch result"];
26 [label="Enter when branch result"];
subgraph cluster_8 {
color=blue
27 [label="Enter block"];
28 [label="Access variable R|<local>/s|"];
29 [label="Smart cast: R|<local>/s|"];
30 [label="Access variable R|kotlin/String.length|"];
31 [label="Exit block"];
}
32 [label="Exit when branch result"];
33 [label="Exit when"];
}
34 [label="Exit block"];
}
35 [label="Exit function test_1" style="filled" fillcolor=red];
}
7 -> {8};
8 -> {9};
9 -> {10};
10 -> {11};
11 -> {12 14};
12 -> {13};
13 -> {14};
14 -> {15};
15 -> {16};
16 -> {17};
17 -> {26 18};
18 -> {19};
19 -> {20};
20 -> {21};
21 -> {22};
22 -> {23};
23 -> {24};
24 -> {25};
25 -> {33};
26 -> {27};
27 -> {28};
28 -> {29};
29 -> {30};
30 -> {31};
31 -> {32};
32 -> {33};
33 -> {34};
34 -> {35};
subgraph cluster_9 {
color=red
36 [label="Enter function test_2" style="filled" fillcolor=red];
subgraph cluster_10 {
color=blue
37 [label="Enter block"];
subgraph cluster_11 {
color=blue
38 [label="Enter when"];
subgraph cluster_12 {
color=blue
39 [label="Enter when branch condition "];
40 [label="Access variable R|<local>/s|"];
41 [label="Enter safe call"];
42 [label="Function call: $subj$.R|/check|()" style="filled" fillcolor=yellow];
43 [label="Exit safe call"];
44 [label="Const: Boolean(false)"];
45 [label="Equality operator =="];
46 [label="Exit when branch condition"];
}
subgraph cluster_13 {
color=blue
47 [label="Enter when branch condition else"];
48 [label="Exit when branch condition"];
}
49 [label="Enter when branch result"];
subgraph cluster_14 {
color=blue
50 [label="Enter block"];
51 [label="Access variable R|<local>/s|"];
52 [label="Access variable <Inapplicable(UNSAFE_CALL): kotlin/String.length>#"];
53 [label="Exit block"];
}
54 [label="Exit when branch result"];
55 [label="Enter when branch result"];
subgraph cluster_15 {
color=blue
56 [label="Enter block"];
57 [label="Access variable R|<local>/s|"];
58 [label="Smart cast: R|<local>/s|"];
59 [label="Access variable R|kotlin/String.length|"];
60 [label="Exit block"];
}
61 [label="Exit when branch result"];
62 [label="Exit when"];
}
63 [label="Exit block"];
}
64 [label="Exit function test_2" style="filled" fillcolor=red];
}
36 -> {37};
37 -> {38};
38 -> {39};
39 -> {40};
40 -> {41 43};
41 -> {42};
42 -> {43};
43 -> {44};
44 -> {45};
45 -> {46};
46 -> {55 47};
47 -> {48};
48 -> {49};
49 -> {50};
50 -> {51};
51 -> {52};
52 -> {53};
53 -> {54};
54 -> {62};
55 -> {56};
56 -> {57};
57 -> {58};
58 -> {59};
59 -> {60};
60 -> {61};
61 -> {62};
62 -> {63};
63 -> {64};
subgraph cluster_16 {
color=red
65 [label="Enter function test_3" style="filled" fillcolor=red];
subgraph cluster_17 {
color=blue
66 [label="Enter block"];
subgraph cluster_18 {
color=blue
67 [label="Enter when"];
subgraph cluster_19 {
color=blue
68 [label="Enter when branch condition "];
69 [label="Access variable R|<local>/s|"];
70 [label="Enter safe call"];
71 [label="Function call: $subj$.R|/check|()" style="filled" fillcolor=yellow];
72 [label="Exit safe call"];
73 [label="Const: Boolean(true)"];
74 [label="Equality operator !="];
75 [label="Exit when branch condition"];
}
subgraph cluster_20 {
color=blue
76 [label="Enter when branch condition else"];
77 [label="Exit when branch condition"];
}
78 [label="Enter when branch result"];
subgraph cluster_21 {
color=blue
79 [label="Enter block"];
80 [label="Access variable R|<local>/s|"];
81 [label="Smart cast: R|<local>/s|"];
82 [label="Access variable R|kotlin/String.length|"];
83 [label="Exit block"];
}
84 [label="Exit when branch result"];
85 [label="Enter when branch result"];
subgraph cluster_22 {
color=blue
86 [label="Enter block"];
87 [label="Access variable R|<local>/s|"];
88 [label="Access variable <Inapplicable(UNSAFE_CALL): kotlin/String.length>#"];
89 [label="Exit block"];
}
90 [label="Exit when branch result"];
91 [label="Exit when"];
}
92 [label="Exit block"];
}
93 [label="Exit function test_3" style="filled" fillcolor=red];
}
65 -> {66};
66 -> {67};
67 -> {68};
68 -> {69};
69 -> {70 72};
70 -> {71};
71 -> {72};
72 -> {73};
73 -> {74};
74 -> {75};
75 -> {85 76};
76 -> {77};
77 -> {78};
78 -> {79};
79 -> {80};
80 -> {81};
81 -> {82};
82 -> {83};
83 -> {84};
84 -> {91};
85 -> {86};
86 -> {87};
87 -> {88};
88 -> {89};
89 -> {90};
90 -> {91};
91 -> {92};
92 -> {93};
subgraph cluster_23 {
color=red
94 [label="Enter function test_4" style="filled" fillcolor=red];
subgraph cluster_24 {
color=blue
95 [label="Enter block"];
subgraph cluster_25 {
color=blue
96 [label="Enter when"];
subgraph cluster_26 {
color=blue
97 [label="Enter when branch condition "];
98 [label="Access variable R|<local>/s|"];
99 [label="Enter safe call"];
100 [label="Function call: $subj$.R|/check|()" style="filled" fillcolor=yellow];
101 [label="Exit safe call"];
102 [label="Const: Boolean(false)"];
103 [label="Equality operator !="];
104 [label="Exit when branch condition"];
}
subgraph cluster_27 {
color=blue
105 [label="Enter when branch condition else"];
106 [label="Exit when branch condition"];
}
107 [label="Enter when branch result"];
subgraph cluster_28 {
color=blue
108 [label="Enter block"];
109 [label="Access variable R|<local>/s|"];
110 [label="Smart cast: R|<local>/s|"];
111 [label="Access variable R|kotlin/String.length|"];
112 [label="Exit block"];
}
113 [label="Exit when branch result"];
114 [label="Enter when branch result"];
subgraph cluster_29 {
color=blue
115 [label="Enter block"];
116 [label="Access variable R|<local>/s|"];
117 [label="Access variable <Inapplicable(UNSAFE_CALL): kotlin/String.length>#"];
118 [label="Exit block"];
}
119 [label="Exit when branch result"];
120 [label="Exit when"];
}
121 [label="Exit block"];
}
122 [label="Exit function test_4" style="filled" fillcolor=red];
}
94 -> {95};
95 -> {96};
96 -> {97};
97 -> {98};
98 -> {99 101};
99 -> {100};
100 -> {101};
101 -> {102};
102 -> {103};
103 -> {104};
104 -> {114 105};
105 -> {106};
106 -> {107};
107 -> {108};
108 -> {109};
109 -> {110};
110 -> {111};
111 -> {112};
112 -> {113};
113 -> {120};
114 -> {115};
115 -> {116};
116 -> {117};
117 -> {118};
118 -> {119};
119 -> {120};
120 -> {121};
121 -> {122};
}