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

338 lines
13 KiB
Plaintext
Vendored

digraph tryCatch_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"];
subgraph cluster_2 {
color=blue
2 [label="Try expression enter"];
subgraph cluster_3 {
color=blue
3 [label="Try main block enter"];
subgraph cluster_4 {
color=blue
4 [label="Enter block"];
5 [label="Const: Int(1)"];
6 [label="Variable declaration: lval x: R|kotlin/Int|"];
7 [label="Exit block"];
}
8 [label="Try main block exit"];
}
subgraph cluster_5 {
color=blue
9 [label="Catch enter"];
10 [label="Variable declaration: e: R|kotlin/Exception|"];
subgraph cluster_6 {
color=blue
11 [label="Enter block"];
12 [label="Const: Int(3)"];
13 [label="Variable declaration: lval z: R|kotlin/Int|"];
14 [label="Exit block"];
}
15 [label="Catch exit"];
}
subgraph cluster_7 {
color=blue
16 [label="Catch enter"];
17 [label="Variable declaration: e: R|kotlin/RuntimeException|"];
subgraph cluster_8 {
color=blue
18 [label="Enter block"];
19 [label="Const: Int(2)"];
20 [label="Variable declaration: lval y: R|kotlin/Int|"];
21 [label="Exit block"];
}
22 [label="Catch exit"];
}
23 [label="Try expression exit"];
}
24 [label="Exit block"];
}
25 [label="Exit function test_1" style="filled" fillcolor=red];
}
0 -> {1};
1 -> {2};
2 -> {3 16 9};
3 -> {4};
4 -> {5};
5 -> {6};
6 -> {7};
7 -> {8};
8 -> {23 16 9};
9 -> {10};
9 -> {25} [label=onUncaughtException];
10 -> {11};
11 -> {12};
12 -> {13};
13 -> {14};
14 -> {15};
15 -> {23};
16 -> {17};
16 -> {25} [label=onUncaughtException];
17 -> {18};
18 -> {19};
19 -> {20};
20 -> {21};
21 -> {22};
22 -> {23};
23 -> {24};
24 -> {25};
subgraph cluster_9 {
color=red
26 [label="Enter function test_2" style="filled" fillcolor=red];
subgraph cluster_10 {
color=blue
27 [label="Enter block"];
subgraph cluster_11 {
color=blue
28 [label="Try expression enter"];
subgraph cluster_12 {
color=blue
29 [label="Try main block enter"];
subgraph cluster_13 {
color=blue
30 [label="Enter block"];
31 [label="Const: Int(1)"];
32 [label="Exit block"];
}
33 [label="Try main block exit"];
}
subgraph cluster_14 {
color=blue
34 [label="Catch enter"];
35 [label="Variable declaration: e: R|kotlin/Exception|"];
subgraph cluster_15 {
color=blue
36 [label="Enter block"];
37 [label="Const: Int(2)"];
38 [label="Exit block"];
}
39 [label="Catch exit"];
}
40 [label="Try expression exit"];
}
41 [label="Variable declaration: lval x: R|kotlin/Int|"];
42 [label="Exit block"];
}
43 [label="Exit function test_2" style="filled" fillcolor=red];
}
26 -> {27};
27 -> {28};
28 -> {29 34};
29 -> {30};
30 -> {31};
31 -> {32};
32 -> {33};
33 -> {40 34};
34 -> {35};
34 -> {43} [label=onUncaughtException];
35 -> {36};
36 -> {37};
37 -> {38};
38 -> {39};
39 -> {40};
40 -> {41};
41 -> {42};
42 -> {43};
subgraph cluster_16 {
color=red
44 [label="Enter function test_3" style="filled" fillcolor=red];
subgraph cluster_17 {
color=blue
45 [label="Enter block"];
subgraph cluster_18 {
color=blue
46 [label="Enter while loop"];
subgraph cluster_19 {
color=blue
47 [label="Enter loop condition"];
48 [label="Const: Boolean(true)"];
49 [label="Exit loop condition"];
}
subgraph cluster_20 {
color=blue
50 [label="Enter loop block"];
subgraph cluster_21 {
color=blue
51 [label="Enter block"];
subgraph cluster_22 {
color=blue
52 [label="Try expression enter"];
subgraph cluster_23 {
color=blue
53 [label="Try main block enter"];
subgraph cluster_24 {
color=blue
54 [label="Enter block"];
subgraph cluster_25 {
color=blue
55 [label="Enter when"];
subgraph cluster_26 {
color=blue
56 [label="Enter when branch condition "];
57 [label="Access variable R|<local>/b|"];
58 [label="Exit when branch condition"];
}
59 [label="Synthetic else branch"];
60 [label="Enter when branch result"];
subgraph cluster_27 {
color=blue
61 [label="Enter block"];
62 [label="Jump: ^test_3 Unit"];
63 [label="Stub" style="filled" fillcolor=gray];
64 [label="Exit block" style="filled" fillcolor=gray];
}
65 [label="Exit when branch result" style="filled" fillcolor=gray];
66 [label="Exit when"];
}
67 [label="Const: Int(1)"];
68 [label="Variable declaration: lval x: R|kotlin/Int|"];
subgraph cluster_28 {
color=blue
69 [label="Enter when"];
subgraph cluster_29 {
color=blue
70 [label="Enter when branch condition "];
71 [label="Access variable R|<local>/b|"];
72 [label="Function call: R|<local>/b|.R|kotlin/Boolean.not|()" style="filled" fillcolor=yellow];
73 [label="Exit when branch condition"];
}
74 [label="Synthetic else branch"];
75 [label="Enter when branch result"];
subgraph cluster_30 {
color=blue
76 [label="Enter block"];
77 [label="Jump: break@@@[Boolean(true)] "];
78 [label="Stub" style="filled" fillcolor=gray];
79 [label="Exit block" style="filled" fillcolor=gray];
}
80 [label="Exit when branch result" style="filled" fillcolor=gray];
81 [label="Exit when"];
}
82 [label="Exit block"];
}
83 [label="Try main block exit"];
}
subgraph cluster_31 {
color=blue
84 [label="Catch enter"];
85 [label="Variable declaration: e: R|kotlin/RuntimeException|"];
subgraph cluster_32 {
color=blue
86 [label="Enter block"];
87 [label="Jump: break@@@[Boolean(true)] "];
88 [label="Stub" style="filled" fillcolor=gray];
89 [label="Exit block" style="filled" fillcolor=gray];
}
90 [label="Catch exit" style="filled" fillcolor=gray];
}
subgraph cluster_33 {
color=blue
95 [label="Catch enter"];
96 [label="Variable declaration: e: R|kotlin/Exception|"];
subgraph cluster_34 {
color=blue
97 [label="Enter block"];
98 [label="Jump: continue@@@[Boolean(true)] "];
99 [label="Stub" style="filled" fillcolor=gray];
100 [label="Exit block" style="filled" fillcolor=gray];
}
101 [label="Catch exit" style="filled" fillcolor=gray];
}
102 [label="Try expression exit"];
}
103 [label="Const: Int(2)"];
104 [label="Variable declaration: lval y: R|kotlin/Int|"];
105 [label="Exit block"];
}
106 [label="Exit loop block"];
}
91 [label="Exit whileloop"];
}
92 [label="Const: Int(3)"];
93 [label="Variable declaration: lval z: R|kotlin/Int|"];
94 [label="Exit block"];
}
107 [label="Exit function test_3" style="filled" fillcolor=red];
}
44 -> {45};
45 -> {46};
46 -> {47};
47 -> {48};
48 -> {49};
49 -> {50};
49 -> {91} [style=dotted];
50 -> {51};
51 -> {52};
52 -> {53 95 84};
53 -> {54};
54 -> {55};
55 -> {56};
56 -> {57};
57 -> {58};
58 -> {60 59};
59 -> {66};
60 -> {61};
61 -> {62};
62 -> {107};
62 -> {63} [style=dotted];
63 -> {64} [style=dotted];
64 -> {65} [style=dotted];
65 -> {66} [style=dotted];
66 -> {67};
67 -> {68};
68 -> {69};
69 -> {70};
70 -> {71};
71 -> {72};
72 -> {73};
73 -> {75 74};
74 -> {81};
75 -> {76};
76 -> {77};
77 -> {91};
77 -> {78} [style=dotted];
78 -> {79} [style=dotted];
79 -> {80} [style=dotted];
80 -> {81} [style=dotted];
81 -> {82};
82 -> {83};
83 -> {102 95 84};
84 -> {85};
84 -> {107} [label=onUncaughtException];
85 -> {86};
86 -> {87};
87 -> {91};
87 -> {88} [style=dotted];
88 -> {89} [style=dotted];
89 -> {90} [style=dotted];
90 -> {102} [style=dotted];
91 -> {92};
92 -> {93};
93 -> {94};
94 -> {107};
95 -> {96};
95 -> {107} [label=onUncaughtException];
96 -> {97};
97 -> {98};
98 -> {99} [style=dotted];
98 -> {47} [color=green style=dashed];
99 -> {100} [style=dotted];
100 -> {101} [style=dotted];
101 -> {102} [style=dotted];
102 -> {103};
103 -> {104};
104 -> {105};
105 -> {106};
106 -> {47} [color=green style=dashed];
}