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:
+4
-4
@@ -6,7 +6,7 @@ digraph delayedAssignment_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};
|
||||
@@ -67,18 +67,18 @@ digraph delayedAssignment_kt {
|
||||
subgraph cluster_10 {
|
||||
color=blue
|
||||
25 [label="Enter block"];
|
||||
26 [label="Function call: R|/A.A|()"];
|
||||
26 [label="Function call: R|/A.A|()" style="filled" fillcolor=yellow];
|
||||
27 [label="Assignment: R|<local>/a|"];
|
||||
28 [label="Access variable R|<local>/a|"];
|
||||
29 [label="Smart cast: R|<local>/a|"];
|
||||
30 [label="Function call: R|<local>/a|.R|/A.foo|()"];
|
||||
30 [label="Function call: R|<local>/a|.R|/A.foo|()" style="filled" fillcolor=yellow];
|
||||
31 [label="Exit block"];
|
||||
}
|
||||
32 [label="Exit when branch result"];
|
||||
33 [label="Exit when"];
|
||||
}
|
||||
34 [label="Access variable R|<local>/a|"];
|
||||
35 [label="Function call: R|<local>/a|.<Inapplicable(UNSAFE_CALL): /A.foo>#()"];
|
||||
35 [label="Function call: R|<local>/a|.<Inapplicable(UNSAFE_CALL): /A.foo>#()" style="filled" fillcolor=yellow];
|
||||
36 [label="Exit block"];
|
||||
}
|
||||
37 [label="Exit function test" style="filled" fillcolor=red];
|
||||
|
||||
Reference in New Issue
Block a user