[FIR] Create CFG for files to track top-level property initialization

In order to properly analyze top-level property initialization, a
control-flow graph must be created for FirFiles. This change adds the
foundation for the file CFG and updates body resolve to create the CFG.
Checking the CFG for proper initialization is separated into a following
change to ease code review.

KT-56683
This commit is contained in:
Brian Norman
2023-07-25 10:23:22 -05:00
committed by Space Team
parent 0b7eb32064
commit b55fda0c55
127 changed files with 19565 additions and 18746 deletions
@@ -5,102 +5,109 @@ digraph inAnonymousObject_kt {
subgraph cluster_0 {
color=red
0 [label="Enter function foo" style="filled" fillcolor=red];
subgraph cluster_1 {
0 [label="Enter file inAnonymousObject.kt" style="filled" fillcolor=red];
1 [label="Exit file inAnonymousObject.kt" style="filled" fillcolor=red];
}
0 -> {1} [color=green];
subgraph cluster_1 {
color=red
2 [label="Enter function foo" style="filled" fillcolor=red];
subgraph cluster_2 {
color=blue
1 [label="Enter block"];
subgraph cluster_2 {
color=blue
2 [label="Enter block"];
3 [label="Exit block"];
}
4 [label="Enter anonymous object"];
3 [label="Enter block"];
subgraph cluster_3 {
color=blue
5 [label="Enter class <anonymous object>" style="filled" fillcolor=red];
subgraph cluster_4 {
color=blue
6 [label="Enter property" style="filled" fillcolor=red];
7 [label="Access variable R|<local>/a|"];
8 [label="Exit property" style="filled" fillcolor=red];
}
4 [label="Enter block"];
5 [label="Exit block"];
}
6 [label="Enter anonymous object"];
subgraph cluster_4 {
color=blue
7 [label="Enter class <anonymous object>" style="filled" fillcolor=red];
subgraph cluster_5 {
color=blue
9 [label="Enter init block" style="filled" fillcolor=red];
subgraph cluster_6 {
color=blue
10 [label="Enter block"];
11 [label="Access variable R|<local>/b|"];
12 [label="Assignment: R|/<anonymous>.leaked|"];
13 [label="Exit block"];
}
14 [label="Exit init block" style="filled" fillcolor=red];
8 [label="Enter property" style="filled" fillcolor=red];
9 [label="Access variable R|<local>/a|"];
10 [label="Exit property" style="filled" fillcolor=red];
}
subgraph cluster_7 {
subgraph cluster_6 {
color=blue
15 [label="Enter function <init>" style="filled" fillcolor=red];
16 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=yellow];
17 [label="Exit function <init>" style="filled" fillcolor=red];
11 [label="Enter init block" style="filled" fillcolor=red];
subgraph cluster_7 {
color=blue
12 [label="Enter block"];
13 [label="Access variable R|<local>/b|"];
14 [label="Assignment: R|/<anonymous>.leaked|"];
15 [label="Exit block"];
}
16 [label="Exit init block" style="filled" fillcolor=red];
}
18 [label="Exit class <anonymous object>" style="filled" fillcolor=red];
subgraph cluster_8 {
color=blue
17 [label="Enter function <init>" style="filled" fillcolor=red];
18 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=yellow];
19 [label="Exit function <init>" style="filled" fillcolor=red];
}
20 [label="Exit class <anonymous object>" style="filled" fillcolor=red];
}
19 [label="Exit anonymous object expression"];
20 [label="Variable declaration: lval obj: R|<anonymous>|"];
21 [label="Access variable R|<local>/obj|"];
22 [label="Function call: R|<local>/obj|.R|/<anonymous>.run|()" style="filled" fillcolor=yellow];
23 [label="Function call: R|<local>/d|.R|SubstitutionOverride<kotlin/Function0.invoke: R|kotlin/Unit|>|()" style="filled" fillcolor=yellow];
24 [label="Exit block"];
21 [label="Exit anonymous object expression"];
22 [label="Variable declaration: lval obj: R|<anonymous>|"];
23 [label="Access variable R|<local>/obj|"];
24 [label="Function call: R|<local>/obj|.R|/<anonymous>.run|()" style="filled" fillcolor=yellow];
25 [label="Function call: R|<local>/d|.R|SubstitutionOverride<kotlin/Function0.invoke: R|kotlin/Unit|>|()" style="filled" fillcolor=yellow];
26 [label="Exit block"];
}
25 [label="Exit function foo" style="filled" fillcolor=red];
27 [label="Exit function foo" style="filled" fillcolor=red];
}
subgraph cluster_8 {
subgraph cluster_9 {
color=blue
26 [label="Enter function run" style="filled" fillcolor=red];
subgraph cluster_9 {
28 [label="Enter function run" style="filled" fillcolor=red];
subgraph cluster_10 {
color=blue
27 [label="Enter block"];
28 [label="Function call: R|<local>/c|.R|SubstitutionOverride<kotlin/Function0.invoke: R|kotlin/Unit|>|()" style="filled" fillcolor=yellow];
29 [label="Exit block"];
29 [label="Enter block"];
30 [label="Function call: R|<local>/c|.R|SubstitutionOverride<kotlin/Function0.invoke: R|kotlin/Unit|>|()" style="filled" fillcolor=yellow];
31 [label="Exit block"];
}
30 [label="Exit function run" style="filled" fillcolor=red];
32 [label="Exit function run" style="filled" fillcolor=red];
}
0 -> {1};
1 -> {2};
2 -> {3};
3 -> {4};
4 -> {5};
4 -> {19} [style=dotted];
4 -> {5} [style=dashed];
5 -> {6};
5 -> {9 15 26} [color=red];
5 -> {18} [style=dotted];
5 -> {6 9 15} [style=dashed];
6 -> {7};
6 -> {21} [style=dotted];
6 -> {7} [style=dashed];
7 -> {8};
8 -> {9} [color=green];
8 -> {18} [color=red];
7 -> {11 17 28} [color=red];
7 -> {20} [style=dotted];
7 -> {8 11 17} [style=dashed];
8 -> {9};
9 -> {10};
10 -> {11};
10 -> {11} [color=green];
10 -> {20} [color=red];
11 -> {12};
12 -> {13};
13 -> {14};
14 -> {15} [color=green];
14 -> {18} [color=red];
14 -> {15};
15 -> {16};
16 -> {17};
16 -> {17} [color=green];
16 -> {20} [color=red];
17 -> {18};
18 -> {19};
18 -> {26} [color=green];
18 -> {26} [style=dashed];
19 -> {20};
20 -> {21};
20 -> {28} [color=green];
20 -> {28} [style=dashed];
21 -> {22};
22 -> {23};
23 -> {24};
24 -> {25};
25 -> {26};
26 -> {27};
27 -> {28};
28 -> {29};
29 -> {30};
30 -> {31};
31 -> {32};
}
@@ -5,103 +5,110 @@ digraph inLocalClass_kt {
subgraph cluster_0 {
color=red
0 [label="Enter function foo" style="filled" fillcolor=red];
subgraph cluster_1 {
color=blue
1 [label="Enter block"];
subgraph cluster_2 {
color=blue
2 [label="Enter block"];
3 [label="Exit block"];
}
4 [label="Local class declaration"];
5 [label="Function call: R|<local>/LocalClass.LocalClass|()" style="filled" fillcolor=yellow];
6 [label="Function call: R|<local>/LocalClass.LocalClass|().R|<local>/run|()" style="filled" fillcolor=yellow];
7 [label="Function call: R|<local>/e|.R|SubstitutionOverride<kotlin/Function0.invoke: R|kotlin/Unit|>|()" style="filled" fillcolor=yellow];
8 [label="Exit block"];
}
9 [label="Exit function foo" style="filled" fillcolor=red];
0 [label="Enter file inLocalClass.kt" style="filled" fillcolor=red];
1 [label="Exit file inLocalClass.kt" style="filled" fillcolor=red];
}
subgraph cluster_3 {
color=blue
10 [label="Enter class LocalClass" style="filled" fillcolor=red];
subgraph cluster_4 {
0 -> {1} [color=green];
subgraph cluster_1 {
color=red
2 [label="Enter function foo" style="filled" fillcolor=red];
subgraph cluster_2 {
color=blue
11 [label="Enter property" style="filled" fillcolor=red];
12 [label="Access variable R|<local>/a|"];
13 [label="Exit property" style="filled" fillcolor=red];
3 [label="Enter block"];
subgraph cluster_3 {
color=blue
4 [label="Enter block"];
5 [label="Exit block"];
}
6 [label="Local class declaration"];
7 [label="Function call: R|<local>/LocalClass.LocalClass|()" style="filled" fillcolor=yellow];
8 [label="Function call: R|<local>/LocalClass.LocalClass|().R|<local>/run|()" style="filled" fillcolor=yellow];
9 [label="Function call: R|<local>/e|.R|SubstitutionOverride<kotlin/Function0.invoke: R|kotlin/Unit|>|()" style="filled" fillcolor=yellow];
10 [label="Exit block"];
}
11 [label="Exit function foo" style="filled" fillcolor=red];
}
subgraph cluster_4 {
color=blue
12 [label="Enter class LocalClass" style="filled" fillcolor=red];
subgraph cluster_5 {
color=blue
14 [label="Enter init block" style="filled" fillcolor=red];
subgraph cluster_6 {
color=blue
15 [label="Enter block"];
16 [label="Access variable R|<local>/c|"];
17 [label="Assignment: R|<local>/leaked|"];
18 [label="Exit block"];
}
19 [label="Exit init block" style="filled" fillcolor=red];
13 [label="Enter property" style="filled" fillcolor=red];
14 [label="Access variable R|<local>/a|"];
15 [label="Exit property" style="filled" fillcolor=red];
}
subgraph cluster_7 {
subgraph cluster_6 {
color=blue
20 [label="Enter function <init>" style="filled" fillcolor=red];
21 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=yellow];
subgraph cluster_8 {
16 [label="Enter init block" style="filled" fillcolor=red];
subgraph cluster_7 {
color=blue
22 [label="Enter block"];
23 [label="Function call: R|<local>/b|.R|SubstitutionOverride<kotlin/Function0.invoke: R|kotlin/Unit|>|()" style="filled" fillcolor=yellow];
24 [label="Exit block"];
17 [label="Enter block"];
18 [label="Access variable R|<local>/c|"];
19 [label="Assignment: R|<local>/leaked|"];
20 [label="Exit block"];
}
25 [label="Exit function <init>" style="filled" fillcolor=red];
21 [label="Exit init block" style="filled" fillcolor=red];
}
26 [label="Exit class LocalClass" style="filled" fillcolor=red];
subgraph cluster_8 {
color=blue
22 [label="Enter function <init>" style="filled" fillcolor=red];
23 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=yellow];
subgraph cluster_9 {
color=blue
24 [label="Enter block"];
25 [label="Function call: R|<local>/b|.R|SubstitutionOverride<kotlin/Function0.invoke: R|kotlin/Unit|>|()" style="filled" fillcolor=yellow];
26 [label="Exit block"];
}
27 [label="Exit function <init>" style="filled" fillcolor=red];
}
28 [label="Exit class LocalClass" style="filled" fillcolor=red];
}
subgraph cluster_9 {
subgraph cluster_10 {
color=blue
27 [label="Enter function run" style="filled" fillcolor=red];
subgraph cluster_10 {
29 [label="Enter function run" style="filled" fillcolor=red];
subgraph cluster_11 {
color=blue
28 [label="Enter block"];
29 [label="Function call: R|<local>/d|.R|SubstitutionOverride<kotlin/Function0.invoke: R|kotlin/Unit|>|()" style="filled" fillcolor=yellow];
30 [label="Exit block"];
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"];
}
31 [label="Exit function run" style="filled" fillcolor=red];
33 [label="Exit function run" style="filled" fillcolor=red];
}
0 -> {1};
1 -> {2};
2 -> {3};
3 -> {4};
4 -> {5 10};
4 -> {10} [style=dashed];
4 -> {5};
5 -> {6};
6 -> {7};
6 -> {7 12};
6 -> {12} [style=dashed];
7 -> {8};
8 -> {9};
9 -> {10};
10 -> {11};
10 -> {14 20 27} [color=red];
10 -> {26} [style=dotted];
10 -> {11 14 20} [style=dashed];
11 -> {12};
12 -> {13};
13 -> {14} [color=green];
12 -> {16 22 29} [color=red];
12 -> {28} [style=dotted];
12 -> {13 16 22} [style=dashed];
13 -> {14};
14 -> {15};
15 -> {16};
15 -> {16} [color=green];
16 -> {17};
17 -> {18};
18 -> {19};
19 -> {20} [color=green];
19 -> {20};
20 -> {21};
21 -> {22};
21 -> {22} [color=green];
22 -> {23};
23 -> {24};
24 -> {25};
25 -> {26} [color=green];
26 -> {27} [color=green];
26 -> {27} [style=dashed];
27 -> {28};
28 -> {29};
25 -> {26};
26 -> {27};
27 -> {28} [color=green];
28 -> {29} [color=green];
28 -> {29} [style=dashed];
29 -> {30};
30 -> {31};
31 -> {32};
32 -> {33};
}
@@ -5,49 +5,56 @@ digraph inLocalFunction_kt {
subgraph cluster_0 {
color=red
0 [label="Enter function foo" style="filled" fillcolor=red];
subgraph cluster_1 {
0 [label="Enter file inLocalFunction.kt" style="filled" fillcolor=red];
1 [label="Exit file inLocalFunction.kt" style="filled" fillcolor=red];
}
0 -> {1} [color=green];
subgraph cluster_1 {
color=red
2 [label="Enter function foo" style="filled" fillcolor=red];
subgraph cluster_2 {
color=blue
1 [label="Enter block"];
subgraph cluster_2 {
3 [label="Enter block"];
subgraph cluster_3 {
color=blue
2 [label="Enter block"];
3 [label="Exit block"];
4 [label="Enter block"];
5 [label="Exit block"];
}
4 [label="Local function declaration"];
5 [label="Function call: R|<local>/localFun|()" style="filled" fillcolor=yellow];
6 [label="Function call: R|<local>/b|.R|SubstitutionOverride<kotlin/Function0.invoke: R|kotlin/Unit|>|()" style="filled" fillcolor=yellow];
7 [label="Exit block"];
6 [label="Local function declaration"];
7 [label="Function call: R|<local>/localFun|()" style="filled" fillcolor=yellow];
8 [label="Function call: R|<local>/b|.R|SubstitutionOverride<kotlin/Function0.invoke: R|kotlin/Unit|>|()" style="filled" fillcolor=yellow];
9 [label="Exit block"];
}
8 [label="Exit function foo" style="filled" fillcolor=red];
10 [label="Exit function foo" style="filled" fillcolor=red];
}
subgraph cluster_3 {
subgraph cluster_4 {
color=blue
9 [label="Enter function localFun" style="filled" fillcolor=red];
subgraph cluster_4 {
11 [label="Enter function localFun" style="filled" fillcolor=red];
subgraph cluster_5 {
color=blue
10 [label="Enter block"];
11 [label="Access variable R|<local>/a|"];
12 [label="Function call: R|<local>/a|.R|SubstitutionOverride<kotlin/Function0.invoke: R|kotlin/Unit|>|()" style="filled" fillcolor=yellow];
13 [label="Function call: R|<local>/a|.R|SubstitutionOverride<kotlin/Function0.invoke: R|kotlin/Unit|>|()" style="filled" fillcolor=yellow];
14 [label="Exit block"];
12 [label="Enter block"];
13 [label="Access variable R|<local>/a|"];
14 [label="Function call: R|<local>/a|.R|SubstitutionOverride<kotlin/Function0.invoke: R|kotlin/Unit|>|()" style="filled" fillcolor=yellow];
15 [label="Function call: R|<local>/a|.R|SubstitutionOverride<kotlin/Function0.invoke: R|kotlin/Unit|>|()" style="filled" fillcolor=yellow];
16 [label="Exit block"];
}
15 [label="Exit function localFun" style="filled" fillcolor=red];
17 [label="Exit function localFun" style="filled" fillcolor=red];
}
0 -> {1};
1 -> {2};
2 -> {3};
3 -> {4};
4 -> {5 9};
4 -> {9} [style=dashed];
4 -> {5};
5 -> {6};
6 -> {7};
6 -> {7 11};
6 -> {11} [style=dashed];
7 -> {8};
8 -> {9};
9 -> {10};
10 -> {11};
11 -> {12};
12 -> {13};
13 -> {14};
14 -> {15};
15 -> {16};
16 -> {17};
}
@@ -5,91 +5,96 @@ digraph toLocalVariables_kt {
subgraph cluster_0 {
color=red
0 [label="Enter function bar" style="filled" fillcolor=red];
subgraph cluster_1 {
color=blue
1 [label="Enter block"];
2 [label="Exit block"];
}
3 [label="Exit function bar" style="filled" fillcolor=red];
0 [label="Enter file toLocalVariables.kt" style="filled" fillcolor=red];
1 [label="Exit file toLocalVariables.kt" style="filled" fillcolor=red];
}
0 -> {1};
1 -> {2};
2 -> {3};
0 -> {1} [color=green];
subgraph cluster_2 {
subgraph cluster_1 {
color=red
4 [label="Enter function foo" style="filled" fillcolor=red];
subgraph cluster_3 {
2 [label="Enter function bar" style="filled" fillcolor=red];
subgraph cluster_2 {
color=blue
5 [label="Enter block"];
subgraph cluster_4 {
color=blue
6 [label="Enter block"];
7 [label="Exit block"];
}
3 [label="Enter block"];
4 [label="Exit block"];
}
5 [label="Exit function bar" style="filled" fillcolor=red];
}
2 -> {3};
3 -> {4};
4 -> {5};
subgraph cluster_3 {
color=red
6 [label="Enter function foo" style="filled" fillcolor=red];
subgraph cluster_4 {
color=blue
7 [label="Enter block"];
subgraph cluster_5 {
color=blue
8 [label="Enter when"];
subgraph cluster_6 {
color=blue
9 [label="Enter when branch condition "];
10 [label="Const: Boolean(true)"];
11 [label="Exit when branch condition"];
}
8 [label="Enter block"];
9 [label="Exit block"];
}
subgraph cluster_6 {
color=blue
10 [label="Enter when"];
subgraph cluster_7 {
color=blue
12 [label="Enter when branch condition else"];
11 [label="Enter when branch condition "];
12 [label="Const: Boolean(true)"];
13 [label="Exit when branch condition"];
}
14 [label="Enter when branch result"];
subgraph cluster_8 {
color=blue
15 [label="Enter block"];
16 [label="Access variable R|<local>/y|"];
17 [label="Variable declaration: lval yCopy: R|() -> kotlin/Unit|"];
18 [label="Function call: R|<local>/yCopy|.R|SubstitutionOverride<kotlin/Function0.invoke: R|kotlin/Unit|>|()" style="filled" fillcolor=yellow];
19 [label="Exit block"];
14 [label="Enter when branch condition else"];
15 [label="Exit when branch condition"];
}
20 [label="Exit when branch result"];
21 [label="Enter when branch result"];
16 [label="Enter when branch result"];
subgraph cluster_9 {
color=blue
22 [label="Enter block"];
23 [label="Access variable R|<local>/x|"];
24 [label="Function call: R|/bar|(...)" style="filled" fillcolor=yellow];
25 [label="Exit block"];
17 [label="Enter block"];
18 [label="Access variable R|<local>/y|"];
19 [label="Variable declaration: lval yCopy: R|() -> kotlin/Unit|"];
20 [label="Function call: R|<local>/yCopy|.R|SubstitutionOverride<kotlin/Function0.invoke: R|kotlin/Unit|>|()" style="filled" fillcolor=yellow];
21 [label="Exit block"];
}
26 [label="Exit when branch result"];
27 [label="Exit when"];
22 [label="Exit when branch result"];
23 [label="Enter when branch result"];
subgraph cluster_10 {
color=blue
24 [label="Enter block"];
25 [label="Access variable R|<local>/x|"];
26 [label="Function call: R|/bar|(...)" style="filled" fillcolor=yellow];
27 [label="Exit block"];
}
28 [label="Exit when branch result"];
29 [label="Exit when"];
}
28 [label="Variable declaration: lval zCopy: R|() -> kotlin/Unit|"];
29 [label="Access variable R|<local>/z|"];
30 [label="Assignment: R|<local>/zCopy|"];
31 [label="Function call: R|<local>/zCopy|.R|SubstitutionOverride<kotlin/Function0.invoke: R|kotlin/Unit|>|()" style="filled" fillcolor=yellow];
32 [label="Exit block"];
30 [label="Variable declaration: lval zCopy: R|() -> kotlin/Unit|"];
31 [label="Access variable R|<local>/z|"];
32 [label="Assignment: R|<local>/zCopy|"];
33 [label="Function call: R|<local>/zCopy|.R|SubstitutionOverride<kotlin/Function0.invoke: R|kotlin/Unit|>|()" style="filled" fillcolor=yellow];
34 [label="Exit block"];
}
33 [label="Exit function foo" style="filled" fillcolor=red];
35 [label="Exit function foo" style="filled" fillcolor=red];
}
4 -> {5};
5 -> {6};
6 -> {7};
7 -> {8};
8 -> {9};
9 -> {10};
10 -> {11};
11 -> {12 21};
11 -> {12};
12 -> {13};
13 -> {14};
13 -> {14 23};
14 -> {15};
15 -> {16};
16 -> {17};
17 -> {18};
18 -> {19};
19 -> {20};
20 -> {27};
20 -> {21};
21 -> {22};
22 -> {23};
22 -> {29};
23 -> {24};
24 -> {25};
25 -> {26};
@@ -100,5 +105,7 @@ digraph toLocalVariables_kt {
30 -> {31};
31 -> {32};
32 -> {33};
33 -> {34};
34 -> {35};
}