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.
221 lines
7.1 KiB
Plaintext
Vendored
221 lines
7.1 KiB
Plaintext
Vendored
digraph when_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="Enter when"];
|
|
subgraph cluster_3 {
|
|
color=blue
|
|
3 [label="Enter when branch condition "];
|
|
4 [label="Access variable R|<local>/x|"];
|
|
5 [label="Const: Int(1)"];
|
|
6 [label="Equality operator =="];
|
|
7 [label="Exit when branch condition"];
|
|
}
|
|
subgraph cluster_4 {
|
|
color=blue
|
|
8 [label="Enter when branch condition "];
|
|
9 [label="Access variable R|<local>/x|"];
|
|
10 [label="Const: Int(2)"];
|
|
11 [label="Function call: R|<local>/x|.R|kotlin/Int.rem|(...)" style="filled" fillcolor=yellow];
|
|
12 [label="Const: Int(0)"];
|
|
13 [label="Equality operator =="];
|
|
14 [label="Exit when branch condition"];
|
|
}
|
|
subgraph cluster_5 {
|
|
color=blue
|
|
15 [label="Enter when branch condition "];
|
|
16 [label="Const: Int(1)"];
|
|
17 [label="Const: Int(1)"];
|
|
18 [label="Function call: Int(1).R|kotlin/Int.minus|(...)" style="filled" fillcolor=yellow];
|
|
19 [label="Const: Int(0)"];
|
|
20 [label="Equality operator =="];
|
|
21 [label="Exit when branch condition"];
|
|
}
|
|
subgraph cluster_6 {
|
|
color=blue
|
|
22 [label="Enter when branch condition else"];
|
|
23 [label="Exit when branch condition"];
|
|
}
|
|
24 [label="Enter when branch result"];
|
|
subgraph cluster_7 {
|
|
color=blue
|
|
25 [label="Enter block"];
|
|
26 [label="Const: Int(5)"];
|
|
27 [label="Exit block"];
|
|
}
|
|
28 [label="Exit when branch result"];
|
|
29 [label="Enter when branch result"];
|
|
subgraph cluster_8 {
|
|
color=blue
|
|
30 [label="Enter block"];
|
|
31 [label="Jump: ^test_1 Unit"];
|
|
32 [label="Stub" style="filled" fillcolor=gray];
|
|
33 [label="Exit block" style="filled" fillcolor=gray];
|
|
}
|
|
34 [label="Exit when branch result" style="filled" fillcolor=gray];
|
|
35 [label="Enter when branch result"];
|
|
subgraph cluster_9 {
|
|
color=blue
|
|
36 [label="Enter block"];
|
|
37 [label="Const: Int(20)"];
|
|
38 [label="Exit block"];
|
|
}
|
|
39 [label="Exit when branch result"];
|
|
40 [label="Enter when branch result"];
|
|
subgraph cluster_10 {
|
|
color=blue
|
|
41 [label="Enter block"];
|
|
42 [label="Const: Int(10)"];
|
|
43 [label="Exit block"];
|
|
}
|
|
44 [label="Exit when branch result"];
|
|
45 [label="Exit when"];
|
|
}
|
|
46 [label="Variable declaration: lval y: R|kotlin/Int|"];
|
|
47 [label="Exit block"];
|
|
}
|
|
48 [label="Exit function test_1" style="filled" fillcolor=red];
|
|
}
|
|
0 -> {1};
|
|
1 -> {2};
|
|
2 -> {3};
|
|
3 -> {4};
|
|
4 -> {5};
|
|
5 -> {6};
|
|
6 -> {7};
|
|
7 -> {40 8};
|
|
8 -> {9};
|
|
9 -> {10};
|
|
10 -> {11};
|
|
11 -> {12};
|
|
12 -> {13};
|
|
13 -> {14};
|
|
14 -> {35 15};
|
|
15 -> {16};
|
|
16 -> {17};
|
|
17 -> {18};
|
|
18 -> {19};
|
|
19 -> {20};
|
|
20 -> {21};
|
|
21 -> {29 22};
|
|
22 -> {23};
|
|
23 -> {24};
|
|
24 -> {25};
|
|
25 -> {26};
|
|
26 -> {27};
|
|
27 -> {28};
|
|
28 -> {45};
|
|
29 -> {30};
|
|
30 -> {31};
|
|
31 -> {48};
|
|
31 -> {32} [style=dotted];
|
|
32 -> {33} [style=dotted];
|
|
33 -> {34} [style=dotted];
|
|
34 -> {45} [style=dotted];
|
|
35 -> {36};
|
|
36 -> {37};
|
|
37 -> {38};
|
|
38 -> {39};
|
|
39 -> {45};
|
|
40 -> {41};
|
|
41 -> {42};
|
|
42 -> {43};
|
|
43 -> {44};
|
|
44 -> {45};
|
|
45 -> {46};
|
|
46 -> {47};
|
|
47 -> {48};
|
|
|
|
subgraph cluster_11 {
|
|
color=red
|
|
49 [label="Enter class A" style="filled" fillcolor=red];
|
|
50 [label="Exit class A" style="filled" fillcolor=red];
|
|
}
|
|
49 -> {50} [color=green];
|
|
|
|
subgraph cluster_12 {
|
|
color=red
|
|
51 [label="Enter class B" style="filled" fillcolor=red];
|
|
52 [label="Exit class B" style="filled" fillcolor=red];
|
|
}
|
|
51 -> {52} [color=green];
|
|
|
|
subgraph cluster_13 {
|
|
color=red
|
|
53 [label="Enter function test_2" style="filled" fillcolor=red];
|
|
subgraph cluster_14 {
|
|
color=blue
|
|
54 [label="Enter block"];
|
|
subgraph cluster_15 {
|
|
color=blue
|
|
55 [label="Enter when"];
|
|
subgraph cluster_16 {
|
|
color=blue
|
|
56 [label="Enter when branch condition "];
|
|
subgraph cluster_17 {
|
|
color=blue
|
|
57 [label="Enter &&"];
|
|
58 [label="Access variable R|<local>/x|"];
|
|
59 [label="Type operator: (R|<local>/x| is R|A|)"];
|
|
60 [label="Exit left part of &&"];
|
|
61 [label="Enter right part of &&"];
|
|
62 [label="Access variable R|<local>/x|"];
|
|
63 [label="Smart cast: R|<local>/x|"];
|
|
64 [label="Type operator: (R|<local>/x| is R|B|)"];
|
|
65 [label="Exit &&"];
|
|
}
|
|
66 [label="Exit when branch condition"];
|
|
}
|
|
67 [label="Synthetic else branch"];
|
|
68 [label="Enter when branch result"];
|
|
subgraph cluster_18 {
|
|
color=blue
|
|
69 [label="Enter block"];
|
|
70 [label="Access variable R|<local>/x|"];
|
|
71 [label="Smart cast: R|<local>/x|"];
|
|
72 [label="Type operator: (R|<local>/x| is R|A|)"];
|
|
73 [label="Exit block"];
|
|
}
|
|
74 [label="Exit when branch result"];
|
|
75 [label="Exit when"];
|
|
}
|
|
76 [label="Exit block"];
|
|
}
|
|
77 [label="Exit function test_2" style="filled" fillcolor=red];
|
|
}
|
|
53 -> {54};
|
|
54 -> {55};
|
|
55 -> {56};
|
|
56 -> {57};
|
|
57 -> {58};
|
|
58 -> {59};
|
|
59 -> {60};
|
|
60 -> {65 61};
|
|
61 -> {62};
|
|
62 -> {63};
|
|
63 -> {64};
|
|
64 -> {65};
|
|
65 -> {66};
|
|
66 -> {68 67};
|
|
67 -> {75};
|
|
68 -> {69};
|
|
69 -> {70};
|
|
70 -> {71};
|
|
71 -> {72};
|
|
72 -> {73};
|
|
73 -> {74};
|
|
74 -> {75};
|
|
75 -> {76};
|
|
76 -> {77};
|
|
|
|
}
|