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.
262 lines
8.6 KiB
Plaintext
Vendored
262 lines
8.6 KiB
Plaintext
Vendored
digraph lambdaInWhenBranch_kt {
|
|
graph [nodesep=3]
|
|
node [shape=box penwidth=2]
|
|
edge [penwidth=2]
|
|
|
|
subgraph cluster_0 {
|
|
color=red
|
|
0 [label="Enter function <init>" style="filled" fillcolor=red];
|
|
1 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=yellow];
|
|
2 [label="Exit function <init>" style="filled" fillcolor=red];
|
|
}
|
|
0 -> {1};
|
|
1 -> {2};
|
|
|
|
subgraph cluster_1 {
|
|
color=red
|
|
3 [label="Enter class Sealed" style="filled" fillcolor=red];
|
|
4 [label="Exit class Sealed" style="filled" fillcolor=red];
|
|
}
|
|
3 -> {4} [color=green];
|
|
|
|
subgraph cluster_2 {
|
|
color=red
|
|
5 [label="Enter function <init>" style="filled" fillcolor=red];
|
|
6 [label="Delegated constructor call: super<R|Sealed|>()" style="filled" fillcolor=yellow];
|
|
7 [label="Exit function <init>" style="filled" fillcolor=red];
|
|
}
|
|
5 -> {6};
|
|
6 -> {7};
|
|
|
|
subgraph cluster_3 {
|
|
color=red
|
|
8 [label="Enter property" style="filled" fillcolor=red];
|
|
9 [label="Access variable R|<local>/t|"];
|
|
10 [label="Exit property" style="filled" fillcolor=red];
|
|
}
|
|
8 -> {9};
|
|
9 -> {10};
|
|
10 -> {20} [color=green];
|
|
|
|
subgraph cluster_4 {
|
|
color=red
|
|
11 [label="Enter function component1" style="filled" fillcolor=red];
|
|
12 [label="Exit function component1" style="filled" fillcolor=red];
|
|
}
|
|
11 -> {12};
|
|
|
|
subgraph cluster_5 {
|
|
color=red
|
|
13 [label="Enter function copy" style="filled" fillcolor=red];
|
|
subgraph cluster_6 {
|
|
color=blue
|
|
15 [label="Enter default value of t" style="filled" fillcolor=red];
|
|
16 [label="Access variable R|/SubClass1.t|"];
|
|
17 [label="Exit default value of t" style="filled" fillcolor=red];
|
|
}
|
|
14 [label="Exit function copy" style="filled" fillcolor=red];
|
|
}
|
|
13 -> {15 14};
|
|
15 -> {16};
|
|
15 -> {15} [style=dashed];
|
|
16 -> {17};
|
|
|
|
subgraph cluster_7 {
|
|
color=red
|
|
18 [label="Enter class SubClass1" style="filled" fillcolor=red];
|
|
19 [label="Part of class initialization"];
|
|
20 [label="Exit class SubClass1" style="filled" fillcolor=red];
|
|
}
|
|
18 -> {19} [color=green];
|
|
19 -> {20} [style=dotted];
|
|
19 -> {8} [color=green];
|
|
19 -> {8} [style=dashed];
|
|
|
|
subgraph cluster_8 {
|
|
color=red
|
|
21 [label="Enter function <init>" style="filled" fillcolor=red];
|
|
22 [label="Delegated constructor call: super<R|Sealed|>()" style="filled" fillcolor=yellow];
|
|
23 [label="Exit function <init>" style="filled" fillcolor=red];
|
|
}
|
|
21 -> {22};
|
|
22 -> {23};
|
|
|
|
subgraph cluster_9 {
|
|
color=red
|
|
24 [label="Enter function copy" style="filled" fillcolor=red];
|
|
25 [label="Exit function copy" style="filled" fillcolor=red];
|
|
}
|
|
24 -> {25};
|
|
|
|
subgraph cluster_10 {
|
|
color=red
|
|
26 [label="Enter class SubClass2" style="filled" fillcolor=red];
|
|
27 [label="Exit class SubClass2" style="filled" fillcolor=red];
|
|
}
|
|
26 -> {27} [color=green];
|
|
|
|
subgraph cluster_11 {
|
|
color=red
|
|
28 [label="Enter function foo" style="filled" fillcolor=red];
|
|
subgraph cluster_12 {
|
|
color=blue
|
|
29 [label="Enter block"];
|
|
subgraph cluster_13 {
|
|
color=blue
|
|
30 [label="Enter when"];
|
|
31 [label="Access variable R|<local>/p|"];
|
|
subgraph cluster_14 {
|
|
color=blue
|
|
32 [label="Enter when branch condition "];
|
|
33 [label="Exit $subj"];
|
|
34 [label="Type operator: ($subj$ is R|SubClass1|)"];
|
|
35 [label="Exit when branch condition"];
|
|
}
|
|
subgraph cluster_15 {
|
|
color=blue
|
|
36 [label="Enter when branch condition "];
|
|
37 [label="Exit $subj"];
|
|
38 [label="Type operator: ($subj$ is R|SubClass2|)"];
|
|
39 [label="Exit when branch condition"];
|
|
}
|
|
40 [label="Enter when branch result"];
|
|
subgraph cluster_16 {
|
|
color=blue
|
|
41 [label="Enter block"];
|
|
42 [label="Const: String()"];
|
|
43 [label="Exit block"];
|
|
}
|
|
44 [label="Exit when branch result"];
|
|
45 [label="Enter when branch result"];
|
|
subgraph cluster_17 {
|
|
color=blue
|
|
46 [label="Enter block"];
|
|
47 [label="Const: String()"];
|
|
48 [label="Postponed enter to lambda"];
|
|
subgraph cluster_18 {
|
|
color=blue
|
|
82 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
|
|
subgraph cluster_19 {
|
|
color=blue
|
|
83 [label="Enter block"];
|
|
84 [label="Access variable R|<local>/it|"];
|
|
85 [label="Exit block"];
|
|
}
|
|
86 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
|
|
}
|
|
49 [label="Postponed exit from lambda"];
|
|
50 [label="Function call: String().R|kotlin/let|<R|kotlin/String|, R|kotlin/String|>(...)" style="filled" fillcolor=yellow];
|
|
51 [label="Exit block"];
|
|
}
|
|
52 [label="Exit when branch result"];
|
|
53 [label="Exit when"];
|
|
}
|
|
54 [label="Access variable R|<local>/p|"];
|
|
55 [label="Access variable <Unresolved name: t>#"];
|
|
subgraph cluster_20 {
|
|
color=blue
|
|
56 [label="Enter when"];
|
|
57 [label="Access variable R|<local>/p|"];
|
|
subgraph cluster_21 {
|
|
color=blue
|
|
58 [label="Enter when branch condition "];
|
|
59 [label="Exit $subj"];
|
|
60 [label="Type operator: ($subj$ is R|SubClass1|)"];
|
|
61 [label="Exit when branch condition"];
|
|
}
|
|
subgraph cluster_22 {
|
|
color=blue
|
|
62 [label="Enter when branch condition "];
|
|
63 [label="Exit $subj"];
|
|
64 [label="Type operator: ($subj$ is R|SubClass2|)"];
|
|
65 [label="Exit when branch condition"];
|
|
}
|
|
66 [label="Enter when branch result"];
|
|
subgraph cluster_23 {
|
|
color=blue
|
|
67 [label="Enter block"];
|
|
68 [label="Const: String(2)"];
|
|
69 [label="Exit block"];
|
|
}
|
|
70 [label="Exit when branch result"];
|
|
71 [label="Enter when branch result"];
|
|
subgraph cluster_24 {
|
|
color=blue
|
|
72 [label="Enter block"];
|
|
73 [label="Access variable R|<local>/p|"];
|
|
74 [label="Smart cast: R|<local>/p|"];
|
|
75 [label="Access variable R|/SubClass1.t|"];
|
|
76 [label="Exit block"];
|
|
}
|
|
77 [label="Exit when branch result"];
|
|
78 [label="Exit when"];
|
|
}
|
|
79 [label="Access variable R|kotlin/String.length|"];
|
|
80 [label="Exit block"];
|
|
}
|
|
81 [label="Exit function foo" style="filled" fillcolor=red];
|
|
}
|
|
28 -> {29};
|
|
29 -> {30};
|
|
30 -> {31};
|
|
31 -> {32};
|
|
32 -> {33};
|
|
33 -> {34};
|
|
34 -> {35};
|
|
35 -> {45 36};
|
|
36 -> {37};
|
|
37 -> {38};
|
|
38 -> {39};
|
|
39 -> {40};
|
|
40 -> {41};
|
|
41 -> {42};
|
|
42 -> {43};
|
|
43 -> {44};
|
|
44 -> {53};
|
|
45 -> {46};
|
|
46 -> {47};
|
|
47 -> {48};
|
|
48 -> {82};
|
|
48 -> {49} [color=red];
|
|
48 -> {82} [style=dashed];
|
|
49 -> {50};
|
|
50 -> {51};
|
|
51 -> {52};
|
|
52 -> {53};
|
|
53 -> {54};
|
|
54 -> {55};
|
|
55 -> {56};
|
|
56 -> {57};
|
|
57 -> {58};
|
|
58 -> {59};
|
|
59 -> {60};
|
|
60 -> {61};
|
|
61 -> {71 62};
|
|
62 -> {63};
|
|
63 -> {64};
|
|
64 -> {65};
|
|
65 -> {66};
|
|
66 -> {67};
|
|
67 -> {68};
|
|
68 -> {69};
|
|
69 -> {70};
|
|
70 -> {78};
|
|
71 -> {72};
|
|
72 -> {73};
|
|
73 -> {74};
|
|
74 -> {75};
|
|
75 -> {76};
|
|
76 -> {77};
|
|
77 -> {78};
|
|
78 -> {79};
|
|
79 -> {80};
|
|
80 -> {81};
|
|
82 -> {83};
|
|
83 -> {84};
|
|
84 -> {85};
|
|
85 -> {86};
|
|
86 -> {53} [color=red];
|
|
86 -> {49} [color=green];
|
|
|
|
}
|