a9be27e330
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.
200 lines
6.5 KiB
Plaintext
Vendored
200 lines
6.5 KiB
Plaintext
Vendored
digraph elvis_kt {
|
|
graph [nodesep=3]
|
|
node [shape=box penwidth=2]
|
|
edge [penwidth=2]
|
|
|
|
subgraph cluster_0 {
|
|
color=red
|
|
0 [label="Enter function foo" style="filled" fillcolor=red];
|
|
1 [label="Exit function foo" style="filled" fillcolor=red];
|
|
}
|
|
0 -> {1};
|
|
|
|
subgraph cluster_1 {
|
|
color=red
|
|
2 [label="Enter class A" style="filled" fillcolor=red];
|
|
3 [label="Exit class A" style="filled" fillcolor=red];
|
|
}
|
|
2 -> {3} [color=green];
|
|
|
|
subgraph cluster_2 {
|
|
color=red
|
|
4 [label="Enter function test_1" style="filled" fillcolor=red];
|
|
subgraph cluster_3 {
|
|
color=blue
|
|
5 [label="Enter block"];
|
|
subgraph cluster_4 {
|
|
color=blue
|
|
6 [label="Enter when"];
|
|
subgraph cluster_5 {
|
|
color=blue
|
|
7 [label="Enter when branch condition "];
|
|
8 [label="Access variable R|<local>/x|"];
|
|
9 [label="Enter safe call"];
|
|
10 [label="Access variable R|/A.b|"];
|
|
11 [label="Exit safe call"];
|
|
12 [label="Exit lhs of ?:"];
|
|
13 [label="Enter rhs of ?:"];
|
|
14 [label="Jump: ^test_1 Unit"];
|
|
15 [label="Stub" style="filled" fillcolor=gray];
|
|
16 [label="Lhs of ?: is not null"];
|
|
17 [label="Exit ?:"];
|
|
18 [label="Exit when branch condition"];
|
|
}
|
|
19 [label="Synthetic else branch"];
|
|
20 [label="Enter when branch result"];
|
|
subgraph cluster_6 {
|
|
color=blue
|
|
21 [label="Enter block"];
|
|
22 [label="Access variable R|<local>/x|"];
|
|
23 [label="Smart cast: R|<local>/x|"];
|
|
24 [label="Function call: R|<local>/x|.R|/A.foo|()" style="filled" fillcolor=yellow];
|
|
25 [label="Exit block"];
|
|
}
|
|
26 [label="Exit when branch result"];
|
|
27 [label="Exit when"];
|
|
}
|
|
28 [label="Exit block"];
|
|
}
|
|
29 [label="Exit function test_1" style="filled" fillcolor=red];
|
|
}
|
|
4 -> {5};
|
|
5 -> {6};
|
|
6 -> {7};
|
|
7 -> {8};
|
|
8 -> {9 13};
|
|
9 -> {10};
|
|
10 -> {11};
|
|
11 -> {12};
|
|
12 -> {16 13};
|
|
13 -> {14};
|
|
14 -> {29};
|
|
14 -> {15} [style=dotted];
|
|
15 -> {17} [style=dotted];
|
|
16 -> {17};
|
|
17 -> {18};
|
|
18 -> {20 19};
|
|
19 -> {27};
|
|
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 test2" 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 "];
|
|
34 [label="Access variable R|<local>/b|"];
|
|
35 [label="Type operator: (R|<local>/b| !is R|kotlin/String|)"];
|
|
36 [label="Exit when branch condition"];
|
|
}
|
|
37 [label="Synthetic else branch"];
|
|
38 [label="Enter when branch result"];
|
|
subgraph cluster_11 {
|
|
color=blue
|
|
39 [label="Enter block"];
|
|
40 [label="Const: String()"];
|
|
41 [label="Jump: ^test2 String()"];
|
|
42 [label="Stub" style="filled" fillcolor=gray];
|
|
43 [label="Exit block" style="filled" fillcolor=gray];
|
|
}
|
|
44 [label="Exit when branch result" style="filled" fillcolor=gray];
|
|
45 [label="Exit when"];
|
|
}
|
|
subgraph cluster_12 {
|
|
color=blue
|
|
46 [label="Enter when"];
|
|
subgraph cluster_13 {
|
|
color=blue
|
|
47 [label="Enter when branch condition "];
|
|
48 [label="Access variable R|<local>/a|"];
|
|
49 [label="Type operator: (R|<local>/a| !is R|kotlin/String?|)"];
|
|
50 [label="Exit when branch condition"];
|
|
}
|
|
51 [label="Synthetic else branch"];
|
|
52 [label="Enter when branch result"];
|
|
subgraph cluster_14 {
|
|
color=blue
|
|
53 [label="Enter block"];
|
|
54 [label="Const: String()"];
|
|
55 [label="Jump: ^test2 String()"];
|
|
56 [label="Stub" style="filled" fillcolor=gray];
|
|
57 [label="Exit block" style="filled" fillcolor=gray];
|
|
}
|
|
58 [label="Exit when branch result" style="filled" fillcolor=gray];
|
|
59 [label="Exit when"];
|
|
}
|
|
60 [label="Access variable R|<local>/a|"];
|
|
61 [label="Smart cast: R|<local>/a|"];
|
|
62 [label="Exit lhs of ?:"];
|
|
63 [label="Enter rhs of ?:"];
|
|
64 [label="Access variable R|<local>/b|"];
|
|
65 [label="Smart cast: R|<local>/b|"];
|
|
66 [label="Lhs of ?: is not null"];
|
|
67 [label="Exit ?:"];
|
|
68 [label="Jump: ^test2 R|<local>/a| ?: R|<local>/b|"];
|
|
69 [label="Stub" style="filled" fillcolor=gray];
|
|
70 [label="Exit block" style="filled" fillcolor=gray];
|
|
}
|
|
71 [label="Exit function test2" style="filled" fillcolor=red];
|
|
}
|
|
30 -> {31};
|
|
31 -> {32};
|
|
32 -> {33};
|
|
33 -> {34};
|
|
34 -> {35};
|
|
35 -> {36};
|
|
36 -> {38 37};
|
|
37 -> {45};
|
|
38 -> {39};
|
|
39 -> {40};
|
|
40 -> {41};
|
|
41 -> {71};
|
|
41 -> {42} [style=dotted];
|
|
42 -> {43} [style=dotted];
|
|
43 -> {44} [style=dotted];
|
|
44 -> {45} [style=dotted];
|
|
45 -> {46};
|
|
46 -> {47};
|
|
47 -> {48};
|
|
48 -> {49};
|
|
49 -> {50};
|
|
50 -> {52 51};
|
|
51 -> {59};
|
|
52 -> {53};
|
|
53 -> {54};
|
|
54 -> {55};
|
|
55 -> {71};
|
|
55 -> {56} [style=dotted];
|
|
56 -> {57} [style=dotted];
|
|
57 -> {58} [style=dotted];
|
|
58 -> {59} [style=dotted];
|
|
59 -> {60};
|
|
60 -> {61};
|
|
61 -> {62};
|
|
62 -> {66 63};
|
|
63 -> {64};
|
|
64 -> {65};
|
|
65 -> {67};
|
|
66 -> {67};
|
|
67 -> {68};
|
|
68 -> {71};
|
|
68 -> {69} [style=dotted];
|
|
69 -> {70} [style=dotted];
|
|
70 -> {71} [style=dotted];
|
|
|
|
}
|