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
@@ -19,7 +19,25 @@ digraph inAnonymousObject_kt {
color=blue
13 [label="Enter class <anonymous object>" style="filled" fillcolor=red];
14 [label="Part of class initialization"];
subgraph cluster_4 {
color=blue
17 [label="Enter property" style="filled" fillcolor=red];
18 [label="Access variable R|<local>/a|"];
19 [label="Exit property" style="filled" fillcolor=red];
}
15 [label="Part of class initialization"];
subgraph cluster_5 {
color=blue
20 [label="Enter init block" style="filled" fillcolor=red];
subgraph cluster_6 {
color=blue
21 [label="Enter block"];
22 [label="Access variable R|<local>/b|"];
23 [label="Assignment: R|/<anonymous>.leaked|"];
24 [label="Exit block"];
}
25 [label="Exit init block" style="filled" fillcolor=red];
}
16 [label="Exit class <anonymous object>" style="filled" fillcolor=red];
}
5 [label="Exit anonymous object"];
@@ -32,17 +50,34 @@ digraph inAnonymousObject_kt {
}
12 [label="Exit function foo" style="filled" fillcolor=red];
}
subgraph cluster_7 {
color=blue
29 [label="Enter function run" style="filled" fillcolor=red];
subgraph cluster_8 {
color=blue
30 [label="Enter block"];
31 [label="Function call: R|<local>/c|.R|SubstitutionOverride<kotlin/Function0.invoke: R|kotlin/Unit|>|()" style="filled" fillcolor=yellow];
32 [label="Exit block"];
}
33 [label="Exit function run" style="filled" fillcolor=red];
}
subgraph cluster_9 {
color=blue
26 [label="Enter function <init>" style="filled" fillcolor=red];
27 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=yellow];
28 [label="Exit function <init>" style="filled" fillcolor=red];
}
0 -> {1};
1 -> {2};
2 -> {3};
3 -> {4};
3 -> {37 40 43 49} [color=red];
3 -> {17 20 26 29} [color=red];
4 -> {13} [color=green];
4 -> {5} [color=red];
4 -> {13} [style=dashed];
5 -> {6};
5 -> {37 49} [color=green];
5 -> {37 49} [style=dashed];
5 -> {26 29} [color=green];
5 -> {26 29} [style=dashed];
6 -> {7};
7 -> {8};
8 -> {9};
@@ -50,66 +85,27 @@ digraph inAnonymousObject_kt {
10 -> {11};
11 -> {12};
13 -> {14} [color=green];
14 -> {40} [color=green];
14 -> {17} [color=green];
14 -> {15} [style=dotted];
14 -> {40} [style=dashed];
15 -> {43} [color=green];
14 -> {17} [style=dashed];
15 -> {20} [color=green];
15 -> {16} [style=dotted];
15 -> {43} [style=dashed];
15 -> {20} [style=dashed];
16 -> {5} [color=green];
subgraph cluster_4 {
color=red
37 [label="Enter function <init>" style="filled" fillcolor=red];
38 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=yellow];
39 [label="Exit function <init>" style="filled" fillcolor=red];
}
37 -> {38};
38 -> {39};
subgraph cluster_5 {
color=red
40 [label="Enter property" style="filled" fillcolor=red];
41 [label="Access variable R|<local>/a|"];
42 [label="Exit property" style="filled" fillcolor=red];
}
40 -> {41};
41 -> {42};
42 -> {15} [color=green];
subgraph cluster_6 {
color=red
43 [label="Enter init block" style="filled" fillcolor=red];
subgraph cluster_7 {
color=blue
44 [label="Enter block"];
45 [label="Access variable R|<local>/b|"];
46 [label="Assignment: R|/<anonymous>.leaked|"];
47 [label="Exit block"];
}
48 [label="Exit init block" style="filled" fillcolor=red];
}
43 -> {44};
44 -> {45};
45 -> {46};
46 -> {47};
47 -> {48};
48 -> {16} [color=green];
subgraph cluster_8 {
color=red
49 [label="Enter function run" style="filled" fillcolor=red];
subgraph cluster_9 {
color=blue
50 [label="Enter block"];
51 [label="Function call: R|<local>/c|.R|SubstitutionOverride<kotlin/Function0.invoke: R|kotlin/Unit|>|()" style="filled" fillcolor=yellow];
52 [label="Exit block"];
}
53 [label="Exit function run" style="filled" fillcolor=red];
}
49 -> {50};
50 -> {51};
51 -> {52};
52 -> {53};
17 -> {18};
18 -> {19};
19 -> {15} [color=green];
20 -> {21};
21 -> {22};
22 -> {23};
23 -> {24};
24 -> {25};
25 -> {16} [color=green];
26 -> {27};
27 -> {28};
29 -> {30};
30 -> {31};
31 -> {32};
32 -> {33};
}
@@ -26,90 +26,86 @@ digraph inLocalClass_kt {
color=blue
10 [label="Enter class LocalClass" style="filled" fillcolor=red];
11 [label="Part of class initialization"];
subgraph cluster_4 {
color=blue
29 [label="Enter function run" style="filled" fillcolor=red];
subgraph cluster_5 {
color=blue
30 [label="Enter block"];
31 [label="Function call: R|<local>/d|.R|SubstitutionOverride<kotlin/Function0.invoke: R|kotlin/Unit|>|()" style="filled" fillcolor=yellow];
32 [label="Exit block"];
}
33 [label="Exit function run" style="filled" fillcolor=red];
}
subgraph cluster_6 {
color=blue
23 [label="Enter function <init>" style="filled" fillcolor=red];
24 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=yellow];
subgraph cluster_7 {
color=blue
25 [label="Enter block"];
26 [label="Function call: R|<local>/b|.R|SubstitutionOverride<kotlin/Function0.invoke: R|kotlin/Unit|>|()" style="filled" fillcolor=yellow];
27 [label="Exit block"];
}
28 [label="Exit function <init>" style="filled" fillcolor=red];
}
subgraph cluster_8 {
color=blue
14 [label="Enter property" style="filled" fillcolor=red];
15 [label="Access variable R|<local>/a|"];
16 [label="Exit property" style="filled" fillcolor=red];
}
12 [label="Part of class initialization"];
subgraph cluster_9 {
color=blue
17 [label="Enter init block" style="filled" fillcolor=red];
subgraph cluster_10 {
color=blue
18 [label="Enter block"];
19 [label="Access variable R|<local>/c|"];
20 [label="Assignment: R|<local>/leaked|"];
21 [label="Exit block"];
}
22 [label="Exit init block" style="filled" fillcolor=red];
}
13 [label="Exit class LocalClass" style="filled" fillcolor=red];
}
0 -> {1};
1 -> {2};
2 -> {3};
3 -> {4};
3 -> {38 41 47 53} [color=red];
3 -> {14 17 23 29} [color=red];
4 -> {5};
4 -> {10 41 53} [color=green];
4 -> {10 41 53} [style=dashed];
4 -> {10 23 29} [color=green];
4 -> {10 23 29} [style=dashed];
5 -> {6};
6 -> {7};
7 -> {8};
8 -> {9};
10 -> {11} [color=green];
11 -> {38} [color=green];
11 -> {14} [color=green];
11 -> {12} [style=dotted];
11 -> {38} [style=dashed];
12 -> {47} [color=green];
11 -> {14} [style=dashed];
12 -> {17} [color=green];
12 -> {13} [style=dotted];
12 -> {47} [style=dashed];
subgraph cluster_4 {
color=red
38 [label="Enter property" style="filled" fillcolor=red];
39 [label="Access variable R|<local>/a|"];
40 [label="Exit property" style="filled" fillcolor=red];
}
38 -> {39};
39 -> {40};
40 -> {12} [color=green];
subgraph cluster_5 {
color=red
41 [label="Enter function <init>" style="filled" fillcolor=red];
42 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=yellow];
subgraph cluster_6 {
color=blue
43 [label="Enter block"];
44 [label="Function call: R|<local>/b|.R|SubstitutionOverride<kotlin/Function0.invoke: R|kotlin/Unit|>|()" style="filled" fillcolor=yellow];
45 [label="Exit block"];
}
46 [label="Exit function <init>" style="filled" fillcolor=red];
}
41 -> {42};
42 -> {43};
43 -> {44};
44 -> {45};
45 -> {46};
subgraph cluster_7 {
color=red
47 [label="Enter init block" style="filled" fillcolor=red];
subgraph cluster_8 {
color=blue
48 [label="Enter block"];
49 [label="Access variable R|<local>/c|"];
50 [label="Assignment: R|<local>/leaked|"];
51 [label="Exit block"];
}
52 [label="Exit init block" style="filled" fillcolor=red];
}
47 -> {48};
48 -> {49};
49 -> {50};
50 -> {51};
51 -> {52};
52 -> {13} [color=green];
subgraph cluster_9 {
color=red
53 [label="Enter function run" style="filled" fillcolor=red];
subgraph cluster_10 {
color=blue
54 [label="Enter block"];
55 [label="Function call: R|<local>/d|.R|SubstitutionOverride<kotlin/Function0.invoke: R|kotlin/Unit|>|()" style="filled" fillcolor=yellow];
56 [label="Exit block"];
}
57 [label="Exit function run" style="filled" fillcolor=red];
}
53 -> {54};
54 -> {55};
55 -> {56};
56 -> {57};
12 -> {17} [style=dashed];
14 -> {15};
15 -> {16};
16 -> {12} [color=green];
17 -> {18};
18 -> {19};
19 -> {20};
20 -> {21};
21 -> {22};
22 -> {13} [color=green];
23 -> {24};
24 -> {25};
25 -> {26};
26 -> {27};
27 -> {28};
29 -> {30};
30 -> {31};
31 -> {32};
32 -> {33};
}
@@ -83,64 +83,9 @@ digraph delegateWithAnonymousObject_kt {
24 -> {25};
subgraph cluster_9 {
color=red
35 [label="Enter function <init>" style="filled" fillcolor=red];
36 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=yellow];
37 [label="Exit function <init>" style="filled" fillcolor=red];
}
35 -> {36};
36 -> {37};
subgraph cluster_10 {
color=red
38 [label="Enter function getValue" style="filled" fillcolor=red];
subgraph cluster_11 {
color=blue
39 [label="Enter block"];
40 [label="Function call: R|/IssueListView.IssueListView|()" style="filled" fillcolor=yellow];
41 [label="Jump: ^getValue R|/IssueListView.IssueListView|()"];
42 [label="Stub" style="filled" fillcolor=gray];
43 [label="Exit block" style="filled" fillcolor=gray];
}
44 [label="Exit function getValue" style="filled" fillcolor=red];
}
38 -> {39};
39 -> {40};
40 -> {41};
41 -> {44};
41 -> {42} [style=dotted];
42 -> {43} [style=dotted];
43 -> {44} [style=dotted];
subgraph cluster_12 {
color=red
45 [label="Enter function setValue" style="filled" fillcolor=red];
subgraph cluster_13 {
color=blue
46 [label="Enter block"];
47 [label="Function call: R|/IssueListView.IssueListView|()" style="filled" fillcolor=yellow];
48 [label="Access variable R|<local>/value|"];
49 [label="Function call: R|/IssueListView.IssueListView|().R|/IssueListView.updateFrom|(...)" style="filled" fillcolor=yellow];
50 [label="Jump: ^setValue R|/IssueListView.IssueListView|().R|/IssueListView.updateFrom|(R|<local>/value|)"];
51 [label="Stub" style="filled" fillcolor=gray];
52 [label="Exit block" style="filled" fillcolor=gray];
}
53 [label="Exit function setValue" style="filled" fillcolor=red];
}
45 -> {46};
46 -> {47};
47 -> {48};
48 -> {49};
49 -> {50};
50 -> {53};
50 -> {51} [style=dotted];
51 -> {52} [style=dotted];
52 -> {53} [style=dotted];
subgraph cluster_14 {
color=red
54 [label="Enter function getter" style="filled" fillcolor=red];
subgraph cluster_15 {
subgraph cluster_10 {
color=blue
55 [label="Enter block"];
56 [label="Access variable D|/IssuesListUserProfile.issueListView|"];
@@ -162,10 +107,10 @@ digraph delegateWithAnonymousObject_kt {
60 -> {61} [style=dotted];
61 -> {62} [style=dotted];
subgraph cluster_16 {
subgraph cluster_11 {
color=red
63 [label="Enter function setter" style="filled" fillcolor=red];
subgraph cluster_17 {
subgraph cluster_12 {
color=blue
64 [label="Enter block"];
65 [label="Access variable D|/IssuesListUserProfile.issueListView|"];
@@ -184,35 +129,79 @@ digraph delegateWithAnonymousObject_kt {
68 -> {69};
69 -> {70};
subgraph cluster_18 {
subgraph cluster_13 {
color=red
71 [label="Enter property" style="filled" fillcolor=red];
72 [label="Postponed enter to lambda"];
subgraph cluster_19 {
79 [label="Enter class IssuesListUserProfile" style="filled" fillcolor=red];
80 [label="Part of class initialization"];
subgraph cluster_14 {
color=blue
26 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
71 [label="Enter property" style="filled" fillcolor=red];
72 [label="Postponed enter to lambda"];
subgraph cluster_15 {
color=blue
26 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
subgraph cluster_16 {
color=blue
27 [label="Enter block"];
28 [label="Enter anonymous object"];
subgraph cluster_17 {
color=blue
33 [label="Enter class <anonymous object>" style="filled" fillcolor=red];
34 [label="Exit class <anonymous object>" style="filled" fillcolor=red];
}
29 [label="Exit anonymous object"];
30 [label="Exit anonymous object expression"];
31 [label="Exit block"];
}
32 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
}
subgraph cluster_18 {
color=blue
45 [label="Enter function setValue" style="filled" fillcolor=red];
subgraph cluster_19 {
color=blue
46 [label="Enter block"];
47 [label="Function call: R|/IssueListView.IssueListView|()" style="filled" fillcolor=yellow];
48 [label="Access variable R|<local>/value|"];
49 [label="Function call: R|/IssueListView.IssueListView|().R|/IssueListView.updateFrom|(...)" style="filled" fillcolor=yellow];
50 [label="Jump: ^setValue R|/IssueListView.IssueListView|().R|/IssueListView.updateFrom|(R|<local>/value|)"];
51 [label="Stub" style="filled" fillcolor=gray];
52 [label="Exit block" style="filled" fillcolor=gray];
}
53 [label="Exit function setValue" style="filled" fillcolor=red];
}
subgraph cluster_20 {
color=blue
27 [label="Enter block"];
28 [label="Enter anonymous object"];
38 [label="Enter function getValue" style="filled" fillcolor=red];
subgraph cluster_21 {
color=blue
33 [label="Enter class <anonymous object>" style="filled" fillcolor=red];
34 [label="Exit class <anonymous object>" style="filled" fillcolor=red];
39 [label="Enter block"];
40 [label="Function call: R|/IssueListView.IssueListView|()" style="filled" fillcolor=yellow];
41 [label="Jump: ^getValue R|/IssueListView.IssueListView|()"];
42 [label="Stub" style="filled" fillcolor=gray];
43 [label="Exit block" style="filled" fillcolor=gray];
}
29 [label="Exit anonymous object"];
30 [label="Exit anonymous object expression"];
31 [label="Exit block"];
44 [label="Exit function getValue" style="filled" fillcolor=red];
}
32 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
subgraph cluster_22 {
color=blue
35 [label="Enter function <init>" style="filled" fillcolor=red];
36 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=yellow];
37 [label="Exit function <init>" style="filled" fillcolor=red];
}
73 [label="Postponed exit from lambda"];
74 [label="Function call: this@R|/IssuesListUserProfile|.R|/delegate|<R|IssuesListUserProfile|, R|IssuesListUserProfile|, R|IssueListView|>(...)" style="filled" fillcolor=yellow];
75 [label="Access variable this@R|/IssuesListUserProfile|"];
76 [label="Function call: this@R|/IssuesListUserProfile|.R|/delegate|<R|IssuesListUserProfile|, R|IssuesListUserProfile|, R|IssueListView|>(...).<Unresolved name: provideDelegate>#(...)" style="filled" fillcolor=yellow];
77 [label="Exit property delegate" style="filled" fillcolor=yellow];
78 [label="Exit property" style="filled" fillcolor=red];
}
73 [label="Postponed exit from lambda"];
74 [label="Function call: this@R|/IssuesListUserProfile|.R|/delegate|<R|IssuesListUserProfile|, R|IssuesListUserProfile|, R|IssueListView|>(...)" style="filled" fillcolor=yellow];
75 [label="Access variable this@R|/IssuesListUserProfile|"];
76 [label="Function call: this@R|/IssuesListUserProfile|.R|/delegate|<R|IssuesListUserProfile|, R|IssuesListUserProfile|, R|IssueListView|>(...).<Unresolved name: provideDelegate>#(...)" style="filled" fillcolor=yellow];
77 [label="Exit property delegate" style="filled" fillcolor=yellow];
78 [label="Exit property" style="filled" fillcolor=red];
81 [label="Exit class IssuesListUserProfile" style="filled" fillcolor=red];
}
79 -> {80} [color=green];
80 -> {71} [color=green];
80 -> {81} [style=dotted];
80 -> {71} [style=dashed];
71 -> {72};
72 -> {26 73 74};
72 -> {26} [style=dashed];
@@ -236,16 +225,23 @@ digraph delegateWithAnonymousObject_kt {
31 -> {32};
33 -> {34} [color=green];
34 -> {29} [color=green];
subgraph cluster_22 {
color=red
79 [label="Enter class IssuesListUserProfile" style="filled" fillcolor=red];
80 [label="Part of class initialization"];
81 [label="Exit class IssuesListUserProfile" style="filled" fillcolor=red];
}
79 -> {80} [color=green];
80 -> {71} [color=green];
80 -> {81} [style=dotted];
80 -> {71} [style=dashed];
35 -> {36};
36 -> {37};
38 -> {39};
39 -> {40};
40 -> {41};
41 -> {44};
41 -> {42} [style=dotted];
42 -> {43} [style=dotted];
43 -> {44} [style=dotted];
45 -> {46};
46 -> {47};
47 -> {48};
48 -> {49};
49 -> {50};
50 -> {53};
50 -> {51} [style=dotted];
51 -> {52} [style=dotted];
52 -> {53} [style=dotted];
}
@@ -59,25 +59,24 @@ digraph plusAssignWithLambdaInRhs_kt {
18 -> {19};
subgraph cluster_5 {
color=red
20 [label="Enter property" style="filled" fillcolor=red];
21 [label="Access variable R|<local>/executor|"];
22 [label="Exit property" style="filled" fillcolor=red];
}
20 -> {21};
21 -> {22};
22 -> {25} [color=green];
subgraph cluster_6 {
color=red
23 [label="Enter class A" style="filled" fillcolor=red];
24 [label="Part of class initialization"];
subgraph cluster_6 {
color=blue
20 [label="Enter property" style="filled" fillcolor=red];
21 [label="Access variable R|<local>/executor|"];
22 [label="Exit property" style="filled" fillcolor=red];
}
25 [label="Exit class A" style="filled" fillcolor=red];
}
23 -> {24} [color=green];
24 -> {20} [color=green];
24 -> {25} [style=dotted];
24 -> {20} [style=dashed];
20 -> {21};
21 -> {22};
22 -> {25} [color=green];
subgraph cluster_7 {
color=red