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:
@@ -50,7 +50,7 @@ digraph casts_kt {
|
||||
18 [label="Enter block"];
|
||||
19 [label="Access variable R|<local>/x|"];
|
||||
20 [label="Smart cast: R|<local>/x|"];
|
||||
21 [label="Function call: R|<local>/x|.R|kotlin/Boolean.not|()"];
|
||||
21 [label="Function call: R|<local>/x|.R|kotlin/Boolean.not|()" style="filled" fillcolor=yellow];
|
||||
22 [label="Exit block"];
|
||||
}
|
||||
23 [label="Exit when branch result"];
|
||||
@@ -58,7 +58,7 @@ digraph casts_kt {
|
||||
}
|
||||
25 [label="Access variable R|<local>/x|"];
|
||||
26 [label="Smart cast: R|<local>/x|"];
|
||||
27 [label="Function call: R|<local>/x|.R|kotlin/Boolean.not|()"];
|
||||
27 [label="Function call: R|<local>/x|.R|kotlin/Boolean.not|()" style="filled" fillcolor=yellow];
|
||||
28 [label="Exit block"];
|
||||
}
|
||||
29 [label="Exit function test_2" style="filled" fillcolor=red];
|
||||
@@ -115,14 +115,14 @@ digraph casts_kt {
|
||||
44 [label="Enter block"];
|
||||
45 [label="Access variable R|<local>/x|"];
|
||||
46 [label="Smart cast: R|<local>/x|"];
|
||||
47 [label="Function call: R|<local>/x|.R|kotlin/Boolean.not|()"];
|
||||
47 [label="Function call: R|<local>/x|.R|kotlin/Boolean.not|()" style="filled" fillcolor=yellow];
|
||||
48 [label="Exit block"];
|
||||
}
|
||||
49 [label="Exit when branch result"];
|
||||
50 [label="Exit when"];
|
||||
}
|
||||
51 [label="Access variable R|<local>/x|"];
|
||||
52 [label="Function call: R|<local>/x|.<Unresolved name: not>#()"];
|
||||
52 [label="Function call: R|<local>/x|.<Unresolved name: not>#()" style="filled" fillcolor=yellow];
|
||||
subgraph cluster_13 {
|
||||
color=blue
|
||||
53 [label="Enter when"];
|
||||
@@ -150,14 +150,14 @@ digraph casts_kt {
|
||||
67 [label="Enter block"];
|
||||
68 [label="Access variable R|<local>/x|"];
|
||||
69 [label="Smart cast: R|<local>/x|"];
|
||||
70 [label="Function call: R|<local>/x|.R|kotlin/Boolean.not|()"];
|
||||
70 [label="Function call: R|<local>/x|.R|kotlin/Boolean.not|()" style="filled" fillcolor=yellow];
|
||||
71 [label="Exit block"];
|
||||
}
|
||||
72 [label="Exit when branch result"];
|
||||
73 [label="Exit when"];
|
||||
}
|
||||
74 [label="Access variable R|<local>/x|"];
|
||||
75 [label="Function call: R|<local>/x|.<Unresolved name: not>#()"];
|
||||
75 [label="Function call: R|<local>/x|.<Unresolved name: not>#()" style="filled" fillcolor=yellow];
|
||||
subgraph cluster_17 {
|
||||
color=blue
|
||||
76 [label="Enter when"];
|
||||
@@ -182,14 +182,14 @@ digraph casts_kt {
|
||||
color=blue
|
||||
88 [label="Enter block"];
|
||||
89 [label="Access variable R|<local>/x|"];
|
||||
90 [label="Function call: R|<local>/x|.<Unresolved name: not>#()"];
|
||||
90 [label="Function call: R|<local>/x|.<Unresolved name: not>#()" style="filled" fillcolor=yellow];
|
||||
91 [label="Exit block"];
|
||||
}
|
||||
92 [label="Exit when branch result"];
|
||||
93 [label="Exit when"];
|
||||
}
|
||||
94 [label="Access variable R|<local>/x|"];
|
||||
95 [label="Function call: R|<local>/x|.<Unresolved name: not>#()"];
|
||||
95 [label="Function call: R|<local>/x|.<Unresolved name: not>#()" style="filled" fillcolor=yellow];
|
||||
96 [label="Exit block"];
|
||||
}
|
||||
97 [label="Exit function test_3" style="filled" fillcolor=red];
|
||||
@@ -290,7 +290,7 @@ digraph casts_kt {
|
||||
color=blue
|
||||
110 [label="Enter block"];
|
||||
111 [label="Access variable R|<local>/b|"];
|
||||
112 [label="Function call: R|<local>/b|.<Unresolved name: not>#()"];
|
||||
112 [label="Function call: R|<local>/b|.<Unresolved name: not>#()" style="filled" fillcolor=yellow];
|
||||
113 [label="Exit block"];
|
||||
}
|
||||
114 [label="Exit when branch result"];
|
||||
@@ -300,14 +300,14 @@ digraph casts_kt {
|
||||
116 [label="Enter block"];
|
||||
117 [label="Access variable R|<local>/b|"];
|
||||
118 [label="Smart cast: R|<local>/b|"];
|
||||
119 [label="Function call: R|<local>/b|.R|kotlin/Boolean.not|()"];
|
||||
119 [label="Function call: R|<local>/b|.R|kotlin/Boolean.not|()" style="filled" fillcolor=yellow];
|
||||
120 [label="Exit block"];
|
||||
}
|
||||
121 [label="Exit when branch result"];
|
||||
122 [label="Exit when"];
|
||||
}
|
||||
123 [label="Access variable R|<local>/b|"];
|
||||
124 [label="Function call: R|<local>/b|.<Unresolved name: not>#()"];
|
||||
124 [label="Function call: R|<local>/b|.<Unresolved name: not>#()" style="filled" fillcolor=yellow];
|
||||
subgraph cluster_28 {
|
||||
color=blue
|
||||
125 [label="Enter when"];
|
||||
@@ -331,7 +331,7 @@ digraph casts_kt {
|
||||
135 [label="Enter block"];
|
||||
136 [label="Access variable R|<local>/b|"];
|
||||
137 [label="Smart cast: R|<local>/b|"];
|
||||
138 [label="Function call: R|<local>/b|.R|kotlin/Boolean.not|()"];
|
||||
138 [label="Function call: R|<local>/b|.R|kotlin/Boolean.not|()" style="filled" fillcolor=yellow];
|
||||
139 [label="Exit block"];
|
||||
}
|
||||
140 [label="Exit when branch result"];
|
||||
@@ -340,14 +340,14 @@ digraph casts_kt {
|
||||
color=blue
|
||||
142 [label="Enter block"];
|
||||
143 [label="Access variable R|<local>/b|"];
|
||||
144 [label="Function call: R|<local>/b|.<Unresolved name: not>#()"];
|
||||
144 [label="Function call: R|<local>/b|.<Unresolved name: not>#()" style="filled" fillcolor=yellow];
|
||||
145 [label="Exit block"];
|
||||
}
|
||||
146 [label="Exit when branch result"];
|
||||
147 [label="Exit when"];
|
||||
}
|
||||
148 [label="Access variable R|<local>/b|"];
|
||||
149 [label="Function call: R|<local>/b|.<Unresolved name: not>#()"];
|
||||
149 [label="Function call: R|<local>/b|.<Unresolved name: not>#()" style="filled" fillcolor=yellow];
|
||||
150 [label="Exit block"];
|
||||
}
|
||||
151 [label="Exit function test_4" style="filled" fillcolor=red];
|
||||
|
||||
Reference in New Issue
Block a user