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.
178 lines
5.9 KiB
Plaintext
Vendored
178 lines
5.9 KiB
Plaintext
Vendored
digraph initializationInTry_kt {
|
|
graph [nodesep=3]
|
|
node [shape=box penwidth=2]
|
|
edge [penwidth=2]
|
|
|
|
subgraph cluster_0 {
|
|
color=red
|
|
0 [label="Enter function getNullableString" style="filled" fillcolor=red];
|
|
subgraph cluster_1 {
|
|
color=blue
|
|
1 [label="Enter block"];
|
|
2 [label="Const: Null(null)"];
|
|
3 [label="Jump: ^getNullableString Null(null)"];
|
|
4 [label="Stub" style="filled" fillcolor=gray];
|
|
5 [label="Exit block" style="filled" fillcolor=gray];
|
|
}
|
|
6 [label="Exit function getNullableString" 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 takeNullableString" style="filled" fillcolor=red];
|
|
subgraph cluster_3 {
|
|
color=blue
|
|
8 [label="Enter block"];
|
|
9 [label="Exit block"];
|
|
}
|
|
10 [label="Exit function takeNullableString" style="filled" fillcolor=red];
|
|
}
|
|
7 -> {8};
|
|
8 -> {9};
|
|
9 -> {10};
|
|
|
|
subgraph cluster_4 {
|
|
color=red
|
|
11 [label="Enter function test_1" style="filled" fillcolor=red];
|
|
subgraph cluster_5 {
|
|
color=blue
|
|
12 [label="Enter block"];
|
|
13 [label="Variable declaration: lval x: R|kotlin/String?|"];
|
|
subgraph cluster_6 {
|
|
color=blue
|
|
14 [label="Try expression enter"];
|
|
subgraph cluster_7 {
|
|
color=blue
|
|
15 [label="Try main block enter"];
|
|
subgraph cluster_8 {
|
|
color=blue
|
|
16 [label="Enter block"];
|
|
17 [label="Function call: R|/getNullableString|()" style="filled" fillcolor=yellow];
|
|
18 [label="Check not null: R|/getNullableString|()!!" style="filled" fillcolor=yellow];
|
|
19 [label="Variable declaration: lval y: R|kotlin/String|"];
|
|
20 [label="Function call: R|/getNullableString|()" style="filled" fillcolor=yellow];
|
|
21 [label="Assignment: R|<local>/x|"];
|
|
22 [label="Exit block"];
|
|
}
|
|
23 [label="Try main block exit"];
|
|
}
|
|
subgraph cluster_9 {
|
|
color=blue
|
|
24 [label="Enter finally"];
|
|
subgraph cluster_10 {
|
|
color=blue
|
|
25 [label="Enter block"];
|
|
26 [label="Access qualifier kotlin/Unit"];
|
|
27 [label="Exit block"];
|
|
}
|
|
28 [label="Exit finally"];
|
|
}
|
|
29 [label="Try expression exit"];
|
|
}
|
|
30 [label="Access variable R|<local>/x|"];
|
|
31 [label="Function call: R|/takeNullableString|(...)" style="filled" fillcolor=yellow];
|
|
32 [label="Exit block"];
|
|
}
|
|
33 [label="Exit function test_1" style="filled" fillcolor=red];
|
|
}
|
|
11 -> {12};
|
|
12 -> {13};
|
|
13 -> {14};
|
|
14 -> {15};
|
|
14 -> {24} [label=onUncaughtException];
|
|
15 -> {16};
|
|
16 -> {17};
|
|
17 -> {18};
|
|
18 -> {19};
|
|
19 -> {20};
|
|
20 -> {21};
|
|
21 -> {22};
|
|
22 -> {23};
|
|
23 -> {24};
|
|
24 -> {25};
|
|
25 -> {26};
|
|
26 -> {27};
|
|
27 -> {28};
|
|
28 -> {29};
|
|
28 -> {33} [label=onUncaughtException];
|
|
29 -> {30};
|
|
30 -> {31};
|
|
31 -> {32};
|
|
32 -> {33};
|
|
|
|
subgraph cluster_11 {
|
|
color=red
|
|
34 [label="Enter function test_2" style="filled" fillcolor=red];
|
|
subgraph cluster_12 {
|
|
color=blue
|
|
35 [label="Enter block"];
|
|
36 [label="Variable declaration: lval x: R|kotlin/String?|"];
|
|
subgraph cluster_13 {
|
|
color=blue
|
|
37 [label="Try expression enter"];
|
|
subgraph cluster_14 {
|
|
color=blue
|
|
38 [label="Try main block enter"];
|
|
subgraph cluster_15 {
|
|
color=blue
|
|
39 [label="Enter block"];
|
|
40 [label="Function call: R|/getNullableString|()" style="filled" fillcolor=yellow];
|
|
41 [label="Variable declaration: lval y: R|kotlin/String?|"];
|
|
42 [label="Function call: R|/getNullableString|()" style="filled" fillcolor=yellow];
|
|
43 [label="Assignment: R|<local>/x|"];
|
|
44 [label="Exit block"];
|
|
}
|
|
45 [label="Try main block exit"];
|
|
}
|
|
subgraph cluster_16 {
|
|
color=blue
|
|
46 [label="Enter finally"];
|
|
subgraph cluster_17 {
|
|
color=blue
|
|
47 [label="Enter block"];
|
|
48 [label="Access qualifier kotlin/Unit"];
|
|
49 [label="Exit block"];
|
|
}
|
|
50 [label="Exit finally"];
|
|
}
|
|
51 [label="Try expression exit"];
|
|
}
|
|
52 [label="Access variable R|<local>/x|"];
|
|
53 [label="Function call: R|/takeNullableString|(...)" style="filled" fillcolor=yellow];
|
|
54 [label="Exit block"];
|
|
}
|
|
55 [label="Exit function test_2" style="filled" fillcolor=red];
|
|
}
|
|
34 -> {35};
|
|
35 -> {36};
|
|
36 -> {37};
|
|
37 -> {38};
|
|
37 -> {46} [label=onUncaughtException];
|
|
38 -> {39};
|
|
39 -> {40};
|
|
40 -> {41};
|
|
41 -> {42};
|
|
42 -> {43};
|
|
43 -> {44};
|
|
44 -> {45};
|
|
45 -> {46};
|
|
46 -> {47};
|
|
47 -> {48};
|
|
48 -> {49};
|
|
49 -> {50};
|
|
50 -> {51};
|
|
50 -> {55} [label=onUncaughtException];
|
|
51 -> {52};
|
|
52 -> {53};
|
|
53 -> {54};
|
|
54 -> {55};
|
|
|
|
}
|