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.
203 lines
6.5 KiB
Plaintext
Vendored
203 lines
6.5 KiB
Plaintext
Vendored
digraph whenSubjectExpression_kt {
|
|
graph [nodesep=3]
|
|
node [shape=box penwidth=2]
|
|
edge [penwidth=2]
|
|
|
|
subgraph cluster_0 {
|
|
color=red
|
|
0 [label="Enter function whenWithSubjectExpression" style="filled" fillcolor=red];
|
|
subgraph cluster_1 {
|
|
color=blue
|
|
1 [label="Enter block"];
|
|
subgraph cluster_2 {
|
|
color=blue
|
|
2 [label="Enter when"];
|
|
3 [label="Access variable R|<local>/x|"];
|
|
subgraph cluster_3 {
|
|
color=blue
|
|
4 [label="Enter when branch condition "];
|
|
5 [label="Exit $subj"];
|
|
6 [label="Type operator: ($subj$ !is R|kotlin/Double|)"];
|
|
7 [label="Exit when branch condition"];
|
|
}
|
|
subgraph cluster_4 {
|
|
color=blue
|
|
8 [label="Enter when branch condition "];
|
|
9 [label="Exit $subj"];
|
|
10 [label="Const: Double(0.0)"];
|
|
11 [label="Equality operator =="];
|
|
12 [label="Exit when branch condition"];
|
|
}
|
|
subgraph cluster_5 {
|
|
color=blue
|
|
13 [label="Enter when branch condition else"];
|
|
14 [label="Exit when branch condition"];
|
|
}
|
|
15 [label="Enter when branch result"];
|
|
subgraph cluster_6 {
|
|
color=blue
|
|
16 [label="Enter block"];
|
|
17 [label="Access variable R|<local>/x|"];
|
|
18 [label="Smart cast: R|<local>/x|"];
|
|
19 [label="Function call: R|<local>/x|.R|kotlin/Double.toInt|()" style="filled" fillcolor=yellow];
|
|
20 [label="Exit block"];
|
|
}
|
|
21 [label="Exit when branch result"];
|
|
22 [label="Enter when branch result"];
|
|
subgraph cluster_7 {
|
|
color=blue
|
|
23 [label="Enter block"];
|
|
24 [label="Const: Int(0)"];
|
|
25 [label="Exit block"];
|
|
}
|
|
26 [label="Exit when branch result"];
|
|
27 [label="Enter when branch result"];
|
|
subgraph cluster_8 {
|
|
color=blue
|
|
28 [label="Enter block"];
|
|
29 [label="Const: Int(-1)"];
|
|
30 [label="Exit block"];
|
|
}
|
|
31 [label="Exit when branch result"];
|
|
32 [label="Exit when"];
|
|
}
|
|
33 [label="Exit block"];
|
|
}
|
|
34 [label="Exit function whenWithSubjectExpression" style="filled" fillcolor=red];
|
|
}
|
|
0 -> {1};
|
|
1 -> {2};
|
|
2 -> {3};
|
|
3 -> {4};
|
|
4 -> {5};
|
|
5 -> {6};
|
|
6 -> {7};
|
|
7 -> {27 8};
|
|
8 -> {9};
|
|
9 -> {10};
|
|
10 -> {11};
|
|
11 -> {12};
|
|
12 -> {22 13};
|
|
13 -> {14};
|
|
14 -> {15};
|
|
15 -> {16};
|
|
16 -> {17};
|
|
17 -> {18};
|
|
18 -> {19};
|
|
19 -> {20};
|
|
20 -> {21};
|
|
21 -> {32};
|
|
22 -> {23};
|
|
23 -> {24};
|
|
24 -> {25};
|
|
25 -> {26};
|
|
26 -> {32};
|
|
27 -> {28};
|
|
28 -> {29};
|
|
29 -> {30};
|
|
30 -> {31};
|
|
31 -> {32};
|
|
32 -> {33};
|
|
33 -> {34};
|
|
|
|
subgraph cluster_9 {
|
|
color=red
|
|
35 [label="Enter function whenWithSubjectVariable" style="filled" fillcolor=red];
|
|
subgraph cluster_10 {
|
|
color=blue
|
|
36 [label="Enter block"];
|
|
subgraph cluster_11 {
|
|
color=blue
|
|
37 [label="Enter when"];
|
|
38 [label="Access variable R|<local>/x|"];
|
|
39 [label="Variable declaration: lval y: R|kotlin/Any|"];
|
|
subgraph cluster_12 {
|
|
color=blue
|
|
40 [label="Enter when branch condition "];
|
|
41 [label="Exit $subj"];
|
|
42 [label="Type operator: ($subj$ !is R|kotlin/Double|)"];
|
|
43 [label="Exit when branch condition"];
|
|
}
|
|
subgraph cluster_13 {
|
|
color=blue
|
|
44 [label="Enter when branch condition "];
|
|
45 [label="Exit $subj"];
|
|
46 [label="Const: Double(0.0)"];
|
|
47 [label="Equality operator =="];
|
|
48 [label="Exit when branch condition"];
|
|
}
|
|
subgraph cluster_14 {
|
|
color=blue
|
|
49 [label="Enter when branch condition else"];
|
|
50 [label="Exit when branch condition"];
|
|
}
|
|
51 [label="Enter when branch result"];
|
|
subgraph cluster_15 {
|
|
color=blue
|
|
52 [label="Enter block"];
|
|
53 [label="Access variable R|<local>/y|"];
|
|
54 [label="Smart cast: R|<local>/y|"];
|
|
55 [label="Function call: R|<local>/y|.R|kotlin/Double.toInt|()" style="filled" fillcolor=yellow];
|
|
56 [label="Exit block"];
|
|
}
|
|
57 [label="Exit when branch result"];
|
|
58 [label="Enter when branch result"];
|
|
subgraph cluster_16 {
|
|
color=blue
|
|
59 [label="Enter block"];
|
|
60 [label="Const: Int(0)"];
|
|
61 [label="Exit block"];
|
|
}
|
|
62 [label="Exit when branch result"];
|
|
63 [label="Enter when branch result"];
|
|
subgraph cluster_17 {
|
|
color=blue
|
|
64 [label="Enter block"];
|
|
65 [label="Const: Int(-1)"];
|
|
66 [label="Exit block"];
|
|
}
|
|
67 [label="Exit when branch result"];
|
|
68 [label="Exit when"];
|
|
}
|
|
69 [label="Exit block"];
|
|
}
|
|
70 [label="Exit function whenWithSubjectVariable" style="filled" fillcolor=red];
|
|
}
|
|
35 -> {36};
|
|
36 -> {37};
|
|
37 -> {38};
|
|
38 -> {39};
|
|
39 -> {40};
|
|
40 -> {41};
|
|
41 -> {42};
|
|
42 -> {43};
|
|
43 -> {63 44};
|
|
44 -> {45};
|
|
45 -> {46};
|
|
46 -> {47};
|
|
47 -> {48};
|
|
48 -> {58 49};
|
|
49 -> {50};
|
|
50 -> {51};
|
|
51 -> {52};
|
|
52 -> {53};
|
|
53 -> {54};
|
|
54 -> {55};
|
|
55 -> {56};
|
|
56 -> {57};
|
|
57 -> {68};
|
|
58 -> {59};
|
|
59 -> {60};
|
|
60 -> {61};
|
|
61 -> {62};
|
|
62 -> {68};
|
|
63 -> {64};
|
|
64 -> {65};
|
|
65 -> {66};
|
|
66 -> {67};
|
|
67 -> {68};
|
|
68 -> {69};
|
|
69 -> {70};
|
|
|
|
}
|