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:
Vendored
+20
-20
@@ -56,10 +56,10 @@ digraph boundSmartcasts_kt {
|
||||
19 [label="Enter block"];
|
||||
20 [label="Access variable R|<local>/x|"];
|
||||
21 [label="Smart cast: R|<local>/x|"];
|
||||
22 [label="Function call: R|<local>/x|.R|/A.foo|()"];
|
||||
22 [label="Function call: R|<local>/x|.R|/A.foo|()" style="filled" fillcolor=yellow];
|
||||
23 [label="Access variable R|<local>/y|"];
|
||||
24 [label="Smart cast: R|<local>/y|"];
|
||||
25 [label="Function call: R|<local>/y|.R|/A.foo|()"];
|
||||
25 [label="Function call: R|<local>/y|.R|/A.foo|()" style="filled" fillcolor=yellow];
|
||||
26 [label="Exit block"];
|
||||
}
|
||||
27 [label="Exit when branch result"];
|
||||
@@ -117,10 +117,10 @@ digraph boundSmartcasts_kt {
|
||||
42 [label="Enter block"];
|
||||
43 [label="Access variable R|<local>/x|"];
|
||||
44 [label="Smart cast: R|<local>/x|"];
|
||||
45 [label="Function call: R|<local>/x|.R|/A.foo|()"];
|
||||
45 [label="Function call: R|<local>/x|.R|/A.foo|()" style="filled" fillcolor=yellow];
|
||||
46 [label="Access variable R|<local>/y|"];
|
||||
47 [label="Smart cast: R|<local>/y|"];
|
||||
48 [label="Function call: R|<local>/y|.R|/A.foo|()"];
|
||||
48 [label="Function call: R|<local>/y|.R|/A.foo|()" style="filled" fillcolor=yellow];
|
||||
49 [label="Exit block"];
|
||||
}
|
||||
50 [label="Exit when branch result"];
|
||||
@@ -178,7 +178,7 @@ digraph boundSmartcasts_kt {
|
||||
65 [label="Enter block"];
|
||||
66 [label="Access variable R|<local>/z|"];
|
||||
67 [label="Smart cast: R|<local>/z|"];
|
||||
68 [label="Function call: R|<local>/z|.R|/A.foo|()"];
|
||||
68 [label="Function call: R|<local>/z|.R|/A.foo|()" style="filled" fillcolor=yellow];
|
||||
69 [label="Exit block"];
|
||||
}
|
||||
70 [label="Exit when branch result"];
|
||||
@@ -203,10 +203,10 @@ digraph boundSmartcasts_kt {
|
||||
81 [label="Enter block"];
|
||||
82 [label="Access variable R|<local>/z|"];
|
||||
83 [label="Smart cast: R|<local>/z|"];
|
||||
84 [label="Function call: R|<local>/z|.<Unresolved name: foo>#()"];
|
||||
84 [label="Function call: R|<local>/z|.<Unresolved name: foo>#()" style="filled" fillcolor=yellow];
|
||||
85 [label="Access variable R|<local>/z|"];
|
||||
86 [label="Smart cast: R|<local>/z|"];
|
||||
87 [label="Function call: R|<local>/z|.R|/B.bar|()"];
|
||||
87 [label="Function call: R|<local>/z|.R|/B.bar|()" style="filled" fillcolor=yellow];
|
||||
88 [label="Exit block"];
|
||||
}
|
||||
89 [label="Exit when branch result"];
|
||||
@@ -267,11 +267,11 @@ digraph boundSmartcasts_kt {
|
||||
98 [label="Type operator: (R|<local>/x| as R|kotlin/Int|)"];
|
||||
99 [label="Access variable R|<local>/x|"];
|
||||
100 [label="Smart cast: R|<local>/x|"];
|
||||
101 [label="Function call: R|<local>/x|.R|kotlin/Int.inc|()"];
|
||||
101 [label="Function call: R|<local>/x|.R|kotlin/Int.inc|()" style="filled" fillcolor=yellow];
|
||||
102 [label="Access variable R|<local>/y|"];
|
||||
103 [label="Assignment: R|<local>/x|"];
|
||||
104 [label="Access variable R|<local>/x|"];
|
||||
105 [label="Function call: R|<local>/x|.<Unresolved name: inc>#()"];
|
||||
105 [label="Function call: R|<local>/x|.<Unresolved name: inc>#()" style="filled" fillcolor=yellow];
|
||||
subgraph cluster_24 {
|
||||
color=blue
|
||||
106 [label="Enter when"];
|
||||
@@ -289,10 +289,10 @@ digraph boundSmartcasts_kt {
|
||||
113 [label="Enter block"];
|
||||
114 [label="Access variable R|<local>/x|"];
|
||||
115 [label="Smart cast: R|<local>/x|"];
|
||||
116 [label="Function call: R|<local>/x|.R|/A.foo|()"];
|
||||
116 [label="Function call: R|<local>/x|.R|/A.foo|()" style="filled" fillcolor=yellow];
|
||||
117 [label="Access variable R|<local>/y|"];
|
||||
118 [label="Smart cast: R|<local>/y|"];
|
||||
119 [label="Function call: R|<local>/y|.R|/A.foo|()"];
|
||||
119 [label="Function call: R|<local>/y|.R|/A.foo|()" style="filled" fillcolor=yellow];
|
||||
120 [label="Exit block"];
|
||||
}
|
||||
121 [label="Exit when branch result"];
|
||||
@@ -337,7 +337,7 @@ digraph boundSmartcasts_kt {
|
||||
subgraph cluster_27 {
|
||||
color=red
|
||||
125 [label="Enter function <init>" style="filled" fillcolor=red];
|
||||
126 [label="Delegated constructor call: super<R|kotlin/Any|>()"];
|
||||
126 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=yellow];
|
||||
127 [label="Exit function <init>" style="filled" fillcolor=red];
|
||||
}
|
||||
125 -> {126};
|
||||
@@ -394,16 +394,16 @@ digraph boundSmartcasts_kt {
|
||||
147 [label="Exit ?:"];
|
||||
148 [label="Variable declaration: lval a: R|kotlin/Any|"];
|
||||
149 [label="Access variable R|<local>/a|"];
|
||||
150 [label="Function call: R|<local>/a|.R|/baz|()"];
|
||||
150 [label="Function call: R|<local>/a|.R|/baz|()" style="filled" fillcolor=yellow];
|
||||
151 [label="Access variable R|<local>/d|"];
|
||||
152 [label="Access variable R|/D.any|"];
|
||||
153 [label="Smart cast: R|<local>/d|.R|/D.any|"];
|
||||
154 [label="Function call: R|<local>/d|.R|/D.any|.R|/baz|()"];
|
||||
154 [label="Function call: R|<local>/d|.R|/D.any|.R|/baz|()" style="filled" fillcolor=yellow];
|
||||
155 [label="Access variable R|<local>/a|"];
|
||||
156 [label="Type operator: (R|<local>/a| as R|A|)"];
|
||||
157 [label="Access variable R|<local>/a|"];
|
||||
158 [label="Smart cast: R|<local>/a|"];
|
||||
159 [label="Function call: R|<local>/a|.R|/A.foo|()"];
|
||||
159 [label="Function call: R|<local>/a|.R|/A.foo|()" style="filled" fillcolor=yellow];
|
||||
160 [label="Exit block"];
|
||||
}
|
||||
161 [label="Exit function test_5" style="filled" fillcolor=red];
|
||||
@@ -446,15 +446,15 @@ digraph boundSmartcasts_kt {
|
||||
168 [label="Type operator: (R|<local>/a| as R|A|)"];
|
||||
169 [label="Access variable R|<local>/a|"];
|
||||
170 [label="Smart cast: R|<local>/a|"];
|
||||
171 [label="Function call: R|<local>/a|.R|/A.foo|()"];
|
||||
171 [label="Function call: R|<local>/a|.R|/A.foo|()" style="filled" fillcolor=yellow];
|
||||
172 [label="Access variable R|<local>/d1|"];
|
||||
173 [label="Access variable R|/D.any|"];
|
||||
174 [label="Smart cast: R|<local>/d1|.R|/D.any|"];
|
||||
175 [label="Function call: R|<local>/d1|.R|/D.any|.R|/A.foo|()"];
|
||||
175 [label="Function call: R|<local>/d1|.R|/D.any|.R|/A.foo|()" style="filled" fillcolor=yellow];
|
||||
176 [label="Access variable R|<local>/d1|"];
|
||||
177 [label="Access variable R|/D.any|"];
|
||||
178 [label="Smart cast: R|<local>/d1|.R|/D.any|"];
|
||||
179 [label="Function call: R|<local>/d1|.R|/D.any|.R|/baz|()"];
|
||||
179 [label="Function call: R|<local>/d1|.R|/D.any|.R|/baz|()" style="filled" fillcolor=yellow];
|
||||
180 [label="Exit block"];
|
||||
}
|
||||
181 [label="Exit function test_6" style="filled" fillcolor=red];
|
||||
@@ -499,12 +499,12 @@ digraph boundSmartcasts_kt {
|
||||
195 [label="Type operator: (R|<local>/a| as R|A|)"];
|
||||
196 [label="Access variable R|<local>/a|"];
|
||||
197 [label="Smart cast: R|<local>/a|"];
|
||||
198 [label="Function call: R|<local>/a|.R|/A.foo|()"];
|
||||
198 [label="Function call: R|<local>/a|.R|/A.foo|()" style="filled" fillcolor=yellow];
|
||||
199 [label="Access variable R|<local>/b|"];
|
||||
200 [label="Type operator: (R|<local>/b| as R|B|)"];
|
||||
201 [label="Access variable R|<local>/b|"];
|
||||
202 [label="Smart cast: R|<local>/b|"];
|
||||
203 [label="Function call: R|<local>/b|.R|/B.bar|()"];
|
||||
203 [label="Function call: R|<local>/b|.R|/B.bar|()" style="filled" fillcolor=yellow];
|
||||
204 [label="Exit block"];
|
||||
}
|
||||
205 [label="Exit function test_7" style="filled" fillcolor=red];
|
||||
|
||||
+7
-7
@@ -6,7 +6,7 @@ digraph boundSmartcastsInBranches_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};
|
||||
@@ -45,7 +45,7 @@ digraph boundSmartcastsInBranches_kt {
|
||||
color=blue
|
||||
13 [label="Enter block"];
|
||||
14 [label="Access variable R|<local>/list|"];
|
||||
15 [label="Function call: R|<local>/list|.R|SubstitutionOverride<kotlin/collections/List.iterator: R|kotlin/collections/Iterator<A>|>|()"];
|
||||
15 [label="Function call: R|<local>/list|.R|SubstitutionOverride<kotlin/collections/List.iterator: R|kotlin/collections/Iterator<A>|>|()" style="filled" fillcolor=yellow];
|
||||
16 [label="Variable declaration: lval <iterator>: R|kotlin/collections/Iterator<A>|"];
|
||||
subgraph cluster_6 {
|
||||
color=blue
|
||||
@@ -54,7 +54,7 @@ digraph boundSmartcastsInBranches_kt {
|
||||
color=blue
|
||||
18 [label="Enter loop condition"];
|
||||
19 [label="Access variable R|<local>/<iterator>|"];
|
||||
20 [label="Function call: R|<local>/<iterator>|.R|SubstitutionOverride<kotlin/collections/Iterator.hasNext: R|kotlin/Boolean|>|()"];
|
||||
20 [label="Function call: R|<local>/<iterator>|.R|SubstitutionOverride<kotlin/collections/Iterator.hasNext: R|kotlin/Boolean|>|()" style="filled" fillcolor=yellow];
|
||||
21 [label="Exit loop condition"];
|
||||
}
|
||||
subgraph cluster_8 {
|
||||
@@ -64,7 +64,7 @@ digraph boundSmartcastsInBranches_kt {
|
||||
color=blue
|
||||
23 [label="Enter block"];
|
||||
24 [label="Access variable R|<local>/<iterator>|"];
|
||||
25 [label="Function call: R|<local>/<iterator>|.R|SubstitutionOverride<kotlin/collections/Iterator.next: R|A|>|()"];
|
||||
25 [label="Function call: R|<local>/<iterator>|.R|SubstitutionOverride<kotlin/collections/Iterator.next: R|A|>|()" style="filled" fillcolor=yellow];
|
||||
26 [label="Variable declaration: lval a: R|A|"];
|
||||
subgraph cluster_10 {
|
||||
color=blue
|
||||
@@ -184,7 +184,7 @@ digraph boundSmartcastsInBranches_kt {
|
||||
subgraph cluster_19 {
|
||||
color=blue
|
||||
68 [label="Enter block"];
|
||||
69 [label="Function call: R|/A.A|()"];
|
||||
69 [label="Function call: R|/A.A|()" style="filled" fillcolor=yellow];
|
||||
70 [label="Assignment: R|<local>/x|"];
|
||||
71 [label="Exit block"];
|
||||
}
|
||||
@@ -261,7 +261,7 @@ digraph boundSmartcastsInBranches_kt {
|
||||
subgraph cluster_26 {
|
||||
color=blue
|
||||
97 [label="Enter block"];
|
||||
98 [label="Function call: R|/A.A|()"];
|
||||
98 [label="Function call: R|/A.A|()" style="filled" fillcolor=yellow];
|
||||
99 [label="Assignment: R|<local>/x|"];
|
||||
100 [label="Exit block"];
|
||||
}
|
||||
@@ -341,7 +341,7 @@ digraph boundSmartcastsInBranches_kt {
|
||||
subgraph cluster_33 {
|
||||
color=blue
|
||||
127 [label="Enter block"];
|
||||
128 [label="Function call: R|/A.A|()"];
|
||||
128 [label="Function call: R|/A.A|()" style="filled" fillcolor=yellow];
|
||||
129 [label="Assignment: R|<local>/x|"];
|
||||
130 [label="Exit block"];
|
||||
}
|
||||
|
||||
Vendored
+3
-3
@@ -6,7 +6,7 @@ digraph functionCallBound_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};
|
||||
@@ -22,7 +22,7 @@ digraph functionCallBound_kt {
|
||||
subgraph cluster_2 {
|
||||
color=red
|
||||
5 [label="Enter function <init>" style="filled" fillcolor=red];
|
||||
6 [label="Delegated constructor call: super<R|Base|>()"];
|
||||
6 [label="Delegated constructor call: super<R|Base|>()" style="filled" fillcolor=yellow];
|
||||
7 [label="Exit function <init>" style="filled" fillcolor=red];
|
||||
}
|
||||
5 -> {6};
|
||||
@@ -85,7 +85,7 @@ digraph functionCallBound_kt {
|
||||
25 [label="Access variable R|<local>/base|"];
|
||||
26 [label="Type operator: (R|<local>/base| as? R|Sub|)"];
|
||||
27 [label="Enter safe call"];
|
||||
28 [label="Function call: $subj$.R|/isOk|()"];
|
||||
28 [label="Function call: $subj$.R|/isOk|()" style="filled" fillcolor=yellow];
|
||||
29 [label="Exit safe call"];
|
||||
30 [label="Const: Boolean(true)"];
|
||||
31 [label="Equality operator =="];
|
||||
|
||||
Reference in New Issue
Block a user