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
@@ -124,30 +124,22 @@ digraph smartcastToNothing_kt {
40 -> {41};
subgraph cluster_11 {
color=red
42 [label="Enter property" style="filled" fillcolor=red];
43 [label="Const: Int(1)"];
44 [label="Exit property" style="filled" fillcolor=red];
}
42 -> {43};
43 -> {44};
44 -> {50} [color=green];
subgraph cluster_12 {
color=red
45 [label="Enter property" style="filled" fillcolor=red];
46 [label="Const: Boolean(true)"];
47 [label="Exit property" style="filled" fillcolor=red];
}
45 -> {46};
46 -> {47};
47 -> {51} [color=green];
subgraph cluster_13 {
color=red
48 [label="Enter class A" style="filled" fillcolor=red];
49 [label="Part of class initialization"];
subgraph cluster_12 {
color=blue
42 [label="Enter property" style="filled" fillcolor=red];
43 [label="Const: Int(1)"];
44 [label="Exit property" style="filled" fillcolor=red];
}
50 [label="Part of class initialization"];
subgraph cluster_13 {
color=blue
45 [label="Enter property" style="filled" fillcolor=red];
46 [label="Const: Boolean(true)"];
47 [label="Exit property" style="filled" fillcolor=red];
}
51 [label="Exit class A" style="filled" fillcolor=red];
}
48 -> {49} [color=green];
@@ -157,6 +149,12 @@ digraph smartcastToNothing_kt {
50 -> {45} [color=green];
50 -> {51} [style=dotted];
50 -> {45} [style=dashed];
42 -> {43};
43 -> {44};
44 -> {50} [color=green];
45 -> {46};
46 -> {47};
47 -> {51} [color=green];
subgraph cluster_14 {
color=red