FIR CFA: properly visit subgraphs in checkers

Interpretation: a graph A is a subgraph of B if information available at
nodes of A depends on the paths taken in B. For example, local classes
are subgraphs of a graph in which they are declared, and members of
those classes are subgraphs of the local class itself - because these
members can reference captured values.

Consequences:

 * if graph G is a subgraph of node N, then G is a subgraph of N's
   owner;
 * `ControlFlowAnalysisDiagnosticComponent` will only visit root graphs;
 * `graph.traverse` will ignore subgraph boundaries, as if all subgraphs
   are inlined into one huge root graph;
 * if a control flow checker needs information from a declaration to
   which a graph is attached, it must look at subgraphs explicitly.

For example, consider the `callsInPlace` checker. When a function
has a `callsInPlace` contract and a local declaration, the checker must
visit that local declaration to ensure it does not capture the allegedly
called-in-place argument - hence `graph.traverse` will look at the
nodes. However, the local declaration can also be a function with its
own `callsInPlace` contracts, so the checker should also run for it in
isolation. If that sounds quadratic, that's because unfortunately it is.
This commit is contained in:
pyos
2022-12-09 12:32:46 +01:00
committed by Dmitriy Novozhilov
parent 5180e1f4a4
commit aadea0e26f
35 changed files with 1191 additions and 1325 deletions
@@ -28,35 +28,45 @@ digraph initBlockAndInPlaceLambda_kt {
subgraph cluster_3 {
color=red
7 [label="Enter init block" style="filled" fillcolor=red];
26 [label="Enter class C" style="filled" fillcolor=red];
27 [label="Part of class initialization"];
subgraph cluster_4 {
color=blue
8 [label="Enter block"];
9 [label="Access variable R|<local>/a|"];
10 [label="Access variable R|/A.b|"];
11 [label="Enter safe call"];
12 [label="Postponed enter to lambda"];
7 [label="Enter init block" style="filled" fillcolor=red];
subgraph cluster_5 {
color=blue
19 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
8 [label="Enter block"];
9 [label="Access variable R|<local>/a|"];
10 [label="Access variable R|/A.b|"];
11 [label="Enter safe call"];
12 [label="Postponed enter to lambda"];
subgraph cluster_6 {
color=blue
20 [label="Enter block"];
21 [label="Access variable R|<local>/a|"];
22 [label="Access variable R|<local>/it|"];
23 [label="Function call: R|/C.C|(...)" style="filled" fillcolor=yellow];
24 [label="Exit block"];
19 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
subgraph cluster_7 {
color=blue
20 [label="Enter block"];
21 [label="Access variable R|<local>/a|"];
22 [label="Access variable R|<local>/it|"];
23 [label="Function call: R|/C.C|(...)" style="filled" fillcolor=yellow];
24 [label="Exit block"];
}
25 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
}
25 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
13 [label="Postponed exit from lambda"];
14 [label="Function call: $subj$.R|kotlin/let|<R|B|, R|C|>(...)" style="filled" fillcolor=yellow];
15 [label="Exit safe call"];
16 [label="Variable declaration: lval c: R|C?|"];
17 [label="Exit block"];
}
13 [label="Postponed exit from lambda"];
14 [label="Function call: $subj$.R|kotlin/let|<R|B|, R|C|>(...)" style="filled" fillcolor=yellow];
15 [label="Exit safe call"];
16 [label="Variable declaration: lval c: R|C?|"];
17 [label="Exit block"];
18 [label="Exit init block" style="filled" fillcolor=red];
}
18 [label="Exit init block" style="filled" fillcolor=red];
28 [label="Exit class C" style="filled" fillcolor=red];
}
26 -> {27} [color=green];
27 -> {7} [color=green];
27 -> {28} [style=dotted];
27 -> {7} [style=dashed];
7 -> {8};
8 -> {9};
9 -> {10};
@@ -79,15 +89,4 @@ digraph initBlockAndInPlaceLambda_kt {
24 -> {25};
25 -> {13};
subgraph cluster_7 {
color=red
26 [label="Enter class C" style="filled" fillcolor=red];
27 [label="Part of class initialization"];
28 [label="Exit class C" style="filled" fillcolor=red];
}
26 -> {27} [color=green];
27 -> {7} [color=green];
27 -> {28} [style=dotted];
27 -> {7} [style=dashed];
}