FIR CFG: add union nodes
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.
This commit is contained in:
+11
-11
@@ -6,7 +6,7 @@ digraph assignSafeCall_kt {
|
||||
subgraph cluster_0 {
|
||||
color=red
|
||||
0 [label="Enter function <init>" style="filled" fillcolor=red];
|
||||
1 [label="Delegated constructor call: super<R|kotlin/Any|>()"];
|
||||
1 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=yellow];
|
||||
2 [label="Exit function <init>" style="filled" fillcolor=red];
|
||||
}
|
||||
0 -> {1};
|
||||
@@ -97,7 +97,7 @@ digraph assignSafeCall_kt {
|
||||
35 [label="Enter block"];
|
||||
36 [label="Access variable R|<local>/a|"];
|
||||
37 [label="Smart cast: R|<local>/a|"];
|
||||
38 [label="Function call: R|<local>/a|.R|/A.bar|()"];
|
||||
38 [label="Function call: R|<local>/a|.R|/A.bar|()" style="filled" fillcolor=yellow];
|
||||
39 [label="Exit block"];
|
||||
}
|
||||
40 [label="Exit when branch result"];
|
||||
@@ -139,7 +139,7 @@ digraph assignSafeCall_kt {
|
||||
45 [label="Enter block"];
|
||||
46 [label="Access variable R|<local>/a|"];
|
||||
47 [label="Enter safe call"];
|
||||
48 [label="Function call: $subj$.R|/A.foo|()"];
|
||||
48 [label="Function call: $subj$.R|/A.foo|()" style="filled" fillcolor=yellow];
|
||||
49 [label="Exit safe call"];
|
||||
50 [label="Variable declaration: lval x: R|kotlin/Int?|"];
|
||||
subgraph cluster_14 {
|
||||
@@ -160,7 +160,7 @@ digraph assignSafeCall_kt {
|
||||
59 [label="Enter block"];
|
||||
60 [label="Access variable R|<local>/a|"];
|
||||
61 [label="Smart cast: R|<local>/a|"];
|
||||
62 [label="Function call: R|<local>/a|.R|/A.bar|()"];
|
||||
62 [label="Function call: R|<local>/a|.R|/A.bar|()" style="filled" fillcolor=yellow];
|
||||
63 [label="Exit block"];
|
||||
}
|
||||
64 [label="Exit when branch result"];
|
||||
@@ -210,10 +210,10 @@ digraph assignSafeCall_kt {
|
||||
77 [label="Exit ?:"];
|
||||
78 [label="Variable declaration: lval a: R|A|"];
|
||||
79 [label="Access variable R|<local>/a|"];
|
||||
80 [label="Function call: R|<local>/a|.R|/A.foo|()"];
|
||||
80 [label="Function call: R|<local>/a|.R|/A.foo|()" style="filled" fillcolor=yellow];
|
||||
81 [label="Access variable R|<local>/x|"];
|
||||
82 [label="Smart cast: R|<local>/x|"];
|
||||
83 [label="Function call: R|<local>/x|.R|/A.foo|()"];
|
||||
83 [label="Function call: R|<local>/x|.R|/A.foo|()" style="filled" fillcolor=yellow];
|
||||
84 [label="Exit block"];
|
||||
}
|
||||
85 [label="Exit function test_3" style="filled" fillcolor=red];
|
||||
@@ -287,7 +287,7 @@ digraph assignSafeCall_kt {
|
||||
107 [label="Enter block"];
|
||||
108 [label="Access variable R|<local>/a|"];
|
||||
109 [label="Smart cast: R|<local>/a|"];
|
||||
110 [label="Function call: R|<local>/a|.R|/B.bar|()"];
|
||||
110 [label="Function call: R|<local>/a|.R|/B.bar|()" style="filled" fillcolor=yellow];
|
||||
111 [label="Exit block"];
|
||||
}
|
||||
112 [label="Exit when branch result"];
|
||||
@@ -329,7 +329,7 @@ digraph assignSafeCall_kt {
|
||||
117 [label="Enter block"];
|
||||
118 [label="Access variable R|<local>/a|"];
|
||||
119 [label="Enter safe call"];
|
||||
120 [label="Function call: $subj$.R|/B.foo|()"];
|
||||
120 [label="Function call: $subj$.R|/B.foo|()" style="filled" fillcolor=yellow];
|
||||
121 [label="Exit safe call"];
|
||||
122 [label="Variable declaration: lval x: R|kotlin/Int?|"];
|
||||
subgraph cluster_29 {
|
||||
@@ -350,7 +350,7 @@ digraph assignSafeCall_kt {
|
||||
131 [label="Enter block"];
|
||||
132 [label="Access variable R|<local>/a|"];
|
||||
133 [label="Smart cast: R|<local>/a|"];
|
||||
134 [label="Function call: R|<local>/a|.R|/B.bar|()"];
|
||||
134 [label="Function call: R|<local>/a|.R|/B.bar|()" style="filled" fillcolor=yellow];
|
||||
135 [label="Exit block"];
|
||||
}
|
||||
136 [label="Exit when branch result"];
|
||||
@@ -400,10 +400,10 @@ digraph assignSafeCall_kt {
|
||||
149 [label="Exit ?:"];
|
||||
150 [label="Variable declaration: lval a: R|B|"];
|
||||
151 [label="Access variable R|<local>/a|"];
|
||||
152 [label="Function call: R|<local>/a|.R|/B.foo|()"];
|
||||
152 [label="Function call: R|<local>/a|.R|/B.foo|()" style="filled" fillcolor=yellow];
|
||||
153 [label="Access variable R|<local>/x|"];
|
||||
154 [label="Smart cast: R|<local>/x|"];
|
||||
155 [label="Function call: R|<local>/x|.R|/B.foo|()"];
|
||||
155 [label="Function call: R|<local>/x|.R|/B.foo|()" style="filled" fillcolor=yellow];
|
||||
156 [label="Exit block"];
|
||||
}
|
||||
157 [label="Exit function test_3" style="filled" fillcolor=red];
|
||||
|
||||
Vendored
+4
-4
@@ -38,7 +38,7 @@ digraph safeCallAndEqualityToBool_kt {
|
||||
10 [label="Enter when branch condition "];
|
||||
11 [label="Access variable R|<local>/s|"];
|
||||
12 [label="Enter safe call"];
|
||||
13 [label="Function call: $subj$.R|/check|()"];
|
||||
13 [label="Function call: $subj$.R|/check|()" style="filled" fillcolor=yellow];
|
||||
14 [label="Exit safe call"];
|
||||
15 [label="Const: Boolean(true)"];
|
||||
16 [label="Equality operator =="];
|
||||
@@ -117,7 +117,7 @@ digraph safeCallAndEqualityToBool_kt {
|
||||
39 [label="Enter when branch condition "];
|
||||
40 [label="Access variable R|<local>/s|"];
|
||||
41 [label="Enter safe call"];
|
||||
42 [label="Function call: $subj$.R|/check|()"];
|
||||
42 [label="Function call: $subj$.R|/check|()" style="filled" fillcolor=yellow];
|
||||
43 [label="Exit safe call"];
|
||||
44 [label="Const: Boolean(false)"];
|
||||
45 [label="Equality operator =="];
|
||||
@@ -196,7 +196,7 @@ digraph safeCallAndEqualityToBool_kt {
|
||||
68 [label="Enter when branch condition "];
|
||||
69 [label="Access variable R|<local>/s|"];
|
||||
70 [label="Enter safe call"];
|
||||
71 [label="Function call: $subj$.R|/check|()"];
|
||||
71 [label="Function call: $subj$.R|/check|()" style="filled" fillcolor=yellow];
|
||||
72 [label="Exit safe call"];
|
||||
73 [label="Const: Boolean(true)"];
|
||||
74 [label="Equality operator !="];
|
||||
@@ -275,7 +275,7 @@ digraph safeCallAndEqualityToBool_kt {
|
||||
97 [label="Enter when branch condition "];
|
||||
98 [label="Access variable R|<local>/s|"];
|
||||
99 [label="Enter safe call"];
|
||||
100 [label="Function call: $subj$.R|/check|()"];
|
||||
100 [label="Function call: $subj$.R|/check|()" style="filled" fillcolor=yellow];
|
||||
101 [label="Exit safe call"];
|
||||
102 [label="Const: Boolean(false)"];
|
||||
103 [label="Equality operator !="];
|
||||
|
||||
+44
-46
@@ -51,7 +51,7 @@ digraph safeCalls_kt {
|
||||
17 [label="Access variable R|kotlin/String.length|"];
|
||||
18 [label="Const: Int(1)"];
|
||||
19 [label="Equality operator =="];
|
||||
20 [label="Function call: $subj$.R|/foo|(...)"];
|
||||
20 [label="Function call: $subj$.R|/foo|(...)" style="filled" fillcolor=yellow];
|
||||
21 [label="Exit safe call"];
|
||||
22 [label="Access variable R|<local>/x|"];
|
||||
23 [label="Access variable <Inapplicable(UNSAFE_CALL): kotlin/String.length>#"];
|
||||
@@ -113,7 +113,7 @@ digraph safeCalls_kt {
|
||||
38 [label="Enter safe call"];
|
||||
39 [label="Access variable R|<local>/x|"];
|
||||
40 [label="Smart cast: R|<local>/x|"];
|
||||
41 [label="Function call: $subj$.R|/A.bar|(...)"];
|
||||
41 [label="Function call: $subj$.R|/A.bar|(...)" style="filled" fillcolor=yellow];
|
||||
42 [label="Exit safe call"];
|
||||
43 [label="Exit block"];
|
||||
}
|
||||
@@ -141,12 +141,12 @@ digraph safeCalls_kt {
|
||||
49 [label="Enter safe call"];
|
||||
50 [label="Access variable R|<local>/x|"];
|
||||
51 [label="Smart cast: R|<local>/x|"];
|
||||
52 [label="Function call: $subj$.R|/A.bar|(...)"];
|
||||
52 [label="Function call: $subj$.R|/A.bar|(...)" style="filled" fillcolor=yellow];
|
||||
53 [label="Enter safe call"];
|
||||
54 [label="Access variable R|<local>/x|"];
|
||||
55 [label="Smart cast: R|<local>/x|"];
|
||||
56 [label="Function call: R|<local>/x|.R|/A.bool|()"];
|
||||
57 [label="Function call: $subj$.R|/foo|(...)"];
|
||||
56 [label="Function call: R|<local>/x|.R|/A.bool|()" style="filled" fillcolor=yellow];
|
||||
57 [label="Function call: $subj$.R|/foo|(...)" style="filled" fillcolor=yellow];
|
||||
58 [label="Enter safe call"];
|
||||
59 [label="Postponed enter to lambda"];
|
||||
subgraph cluster_14 {
|
||||
@@ -157,18 +157,18 @@ digraph safeCalls_kt {
|
||||
70 [label="Enter block"];
|
||||
71 [label="Access variable R|<local>/x|"];
|
||||
72 [label="Smart cast: R|<local>/x|"];
|
||||
73 [label="Function call: R|<local>/x|.R|/A.bool|()"];
|
||||
73 [label="Function call: R|<local>/x|.R|/A.bool|()" style="filled" fillcolor=yellow];
|
||||
74 [label="Exit block"];
|
||||
}
|
||||
75 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
|
||||
}
|
||||
60 [label="Postponed exit from lambda"];
|
||||
61 [label="Function call: $subj$.R|/let|(...)"];
|
||||
61 [label="Function call: $subj$.R|/let|(...)" style="filled" fillcolor=yellow];
|
||||
62 [label="Exit safe call"];
|
||||
63 [label="Exit safe call"];
|
||||
64 [label="Exit safe call"];
|
||||
65 [label="Access variable R|<local>/x|"];
|
||||
66 [label="Function call: R|<local>/x|.<Unresolved name: bool>#()"];
|
||||
66 [label="Function call: R|<local>/x|.<Unresolved name: bool>#()" style="filled" fillcolor=yellow];
|
||||
67 [label="Exit block"];
|
||||
}
|
||||
68 [label="Exit function test_3" style="filled" fillcolor=red];
|
||||
@@ -212,13 +212,13 @@ digraph safeCalls_kt {
|
||||
77 [label="Enter block"];
|
||||
78 [label="Access variable R|<local>/x|"];
|
||||
79 [label="Enter safe call"];
|
||||
80 [label="Function call: $subj$.R|/A.id|()"];
|
||||
80 [label="Function call: $subj$.R|/A.id|()" style="filled" fillcolor=yellow];
|
||||
81 [label="Enter safe call"];
|
||||
82 [label="Function call: $subj$.R|/A.bool|()"];
|
||||
82 [label="Function call: $subj$.R|/A.bool|()" style="filled" fillcolor=yellow];
|
||||
83 [label="Exit safe call"];
|
||||
84 [label="Exit safe call"];
|
||||
85 [label="Access variable R|<local>/x|"];
|
||||
86 [label="Function call: R|<local>/x|.<Inapplicable(UNSAFE_CALL): /A.id>#()"];
|
||||
86 [label="Function call: R|<local>/x|.<Inapplicable(UNSAFE_CALL): /A.id>#()" style="filled" fillcolor=yellow];
|
||||
87 [label="Exit block"];
|
||||
}
|
||||
88 [label="Exit function test_4" style="filled" fillcolor=red];
|
||||
@@ -261,61 +261,59 @@ digraph safeCalls_kt {
|
||||
97 [label="Postponed enter to lambda"];
|
||||
subgraph cluster_22 {
|
||||
color=blue
|
||||
113 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
|
||||
112 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
|
||||
subgraph cluster_23 {
|
||||
color=blue
|
||||
114 [label="Enter block"];
|
||||
115 [label="Jump: ^test_5 Unit"];
|
||||
116 [label="Stub" style="filled" fillcolor=gray];
|
||||
117 [label="Exit block" style="filled" fillcolor=gray];
|
||||
113 [label="Enter block"];
|
||||
114 [label="Jump: ^test_5 Unit"];
|
||||
115 [label="Stub" style="filled" fillcolor=gray];
|
||||
116 [label="Exit block" style="filled" fillcolor=gray];
|
||||
}
|
||||
118 [label="Exit function anonymousFunction" style="filled" fillcolor=red style="filled" fillcolor=gray];
|
||||
117 [label="Exit function anonymousFunction" style="filled" fillcolor=red style="filled" fillcolor=gray];
|
||||
}
|
||||
98 [label="Call arguments union" style="filled" fillcolor=gray];
|
||||
99 [label="Postponed exit from lambda" style="filled" fillcolor=gray];
|
||||
100 [label="Function call: $subj$.R|kotlin/let|<R|A|, R|kotlin/Nothing|>(...)" style="filled" fillcolor=gray];
|
||||
101 [label="Stub" style="filled" fillcolor=gray];
|
||||
102 [label="Enter safe call" style="filled" fillcolor=gray];
|
||||
103 [label="Access variable R|<local>/x|" style="filled" fillcolor=gray];
|
||||
104 [label="Smart cast: R|<local>/x|" style="filled" fillcolor=gray];
|
||||
105 [label="Function call: R|<local>/x|.R|/A.bool|()" style="filled" fillcolor=gray];
|
||||
106 [label="Function call: $subj$.R|/boo|(...)" style="filled" fillcolor=gray];
|
||||
98 [label="Postponed exit from lambda" style="filled" fillcolor=gray];
|
||||
99 [label="Function call: $subj$.R|kotlin/let|<R|A|, R|kotlin/Nothing|>(...)" style="filled" fillcolor=gray];
|
||||
100 [label="Stub" style="filled" fillcolor=gray];
|
||||
101 [label="Enter safe call" style="filled" fillcolor=gray];
|
||||
102 [label="Access variable R|<local>/x|" style="filled" fillcolor=gray];
|
||||
103 [label="Smart cast: R|<local>/x|" style="filled" fillcolor=gray];
|
||||
104 [label="Function call: R|<local>/x|.R|/A.bool|()" style="filled" fillcolor=gray];
|
||||
105 [label="Function call: $subj$.R|/boo|(...)" style="filled" fillcolor=gray];
|
||||
106 [label="Exit safe call"];
|
||||
107 [label="Exit safe call"];
|
||||
108 [label="Exit safe call"];
|
||||
109 [label="Access variable R|<local>/x|"];
|
||||
110 [label="Function call: R|<local>/x|.<Inapplicable(UNSAFE_CALL): /A.id>#()"];
|
||||
111 [label="Exit block"];
|
||||
108 [label="Access variable R|<local>/x|"];
|
||||
109 [label="Function call: R|<local>/x|.<Inapplicable(UNSAFE_CALL): /A.id>#()" style="filled" fillcolor=yellow];
|
||||
110 [label="Exit block"];
|
||||
}
|
||||
112 [label="Exit function test_5" style="filled" fillcolor=red];
|
||||
111 [label="Exit function test_5" style="filled" fillcolor=red];
|
||||
}
|
||||
93 -> {94};
|
||||
94 -> {95};
|
||||
95 -> {96 107};
|
||||
95 -> {96 106};
|
||||
96 -> {97};
|
||||
97 -> {113};
|
||||
97 -> {99} [color=red];
|
||||
97 -> {113} [style=dashed];
|
||||
98 -> {100} [style=dotted];
|
||||
97 -> {112};
|
||||
97 -> {98} [color=red];
|
||||
97 -> {112} [style=dashed];
|
||||
98 -> {99} [style=dotted];
|
||||
99 -> {100} [style=dotted];
|
||||
100 -> {101} [style=dotted];
|
||||
100 -> {112} [style=dotted] [label=onUncaughtException];
|
||||
101 -> {107 102} [style=dotted];
|
||||
99 -> {111} [style=dotted] [label=onUncaughtException];
|
||||
100 -> {106 101} [style=dotted];
|
||||
101 -> {102} [style=dotted];
|
||||
102 -> {103} [style=dotted];
|
||||
103 -> {104} [style=dotted];
|
||||
104 -> {105} [style=dotted];
|
||||
105 -> {106} [style=dotted];
|
||||
106 -> {108} [style=dotted];
|
||||
105 -> {107} [style=dotted];
|
||||
106 -> {107};
|
||||
107 -> {108};
|
||||
108 -> {109};
|
||||
109 -> {110};
|
||||
110 -> {111};
|
||||
111 -> {112};
|
||||
112 -> {113};
|
||||
113 -> {114};
|
||||
114 -> {115};
|
||||
115 -> {112};
|
||||
114 -> {111};
|
||||
114 -> {115} [style=dotted];
|
||||
115 -> {116} [style=dotted];
|
||||
116 -> {117} [style=dotted];
|
||||
117 -> {118} [style=dotted];
|
||||
118 -> {99 98} [style=dotted];
|
||||
117 -> {98 99} [style=dotted];
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user