[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,22 +5,27 @@ digraph conditionalEffects_kt {
subgraph cluster_0 {
color=red
0 [label="Enter function test_1" style="filled" fillcolor=red];
subgraph cluster_1 {
color=blue
1 [label="Enter block"];
2 [label="Access variable R|<local>/x|"];
3 [label="Type operator: (R|<local>/x| is R|kotlin/Int|)"];
4 [label="Function call: R|kotlin/require|(...)" style="filled" fillcolor=yellow];
5 [label="Access variable R|<local>/x|"];
6 [label="Smart cast: R|<local>/x|"];
7 [label="Function call: R|<local>/x|.R|kotlin/Int.inc|()" style="filled" fillcolor=yellow];
8 [label="Exit block"];
}
9 [label="Exit function test_1" style="filled" fillcolor=red];
0 [label="Enter file conditionalEffects.kt" style="filled" fillcolor=red];
1 [label="Exit file conditionalEffects.kt" style="filled" fillcolor=red];
}
0 -> {1} [color=green];
subgraph cluster_1 {
color=red
2 [label="Enter function test_1" style="filled" fillcolor=red];
subgraph cluster_2 {
color=blue
3 [label="Enter block"];
4 [label="Access variable R|<local>/x|"];
5 [label="Type operator: (R|<local>/x| is R|kotlin/Int|)"];
6 [label="Function call: R|kotlin/require|(...)" style="filled" fillcolor=yellow];
7 [label="Access variable R|<local>/x|"];
8 [label="Smart cast: R|<local>/x|"];
9 [label="Function call: R|<local>/x|.R|kotlin/Int.inc|()" style="filled" fillcolor=yellow];
10 [label="Exit block"];
}
11 [label="Exit function test_1" style="filled" fillcolor=red];
}
0 -> {1};
1 -> {2};
2 -> {3};
3 -> {4};
4 -> {5};
@@ -28,50 +33,50 @@ digraph conditionalEffects_kt {
6 -> {7};
7 -> {8};
8 -> {9};
subgraph cluster_2 {
color=red
10 [label="Enter function test_2" style="filled" fillcolor=red];
subgraph cluster_3 {
color=blue
11 [label="Enter block"];
12 [label="Access variable R|<local>/x|"];
13 [label="Function call: R|kotlin/requireNotNull|<R|kotlin/String|>(...)" style="filled" fillcolor=yellow];
14 [label="Access variable R|<local>/x|"];
15 [label="Smart cast: R|<local>/x|"];
16 [label="Access variable R|kotlin/String.length|"];
17 [label="Exit block"];
}
18 [label="Exit function test_2" style="filled" fillcolor=red];
}
9 -> {10};
10 -> {11};
11 -> {12};
subgraph cluster_3 {
color=red
12 [label="Enter function test_2" style="filled" fillcolor=red];
subgraph cluster_4 {
color=blue
13 [label="Enter block"];
14 [label="Access variable R|<local>/x|"];
15 [label="Function call: R|kotlin/requireNotNull|<R|kotlin/String|>(...)" style="filled" fillcolor=yellow];
16 [label="Access variable R|<local>/x|"];
17 [label="Smart cast: R|<local>/x|"];
18 [label="Access variable R|kotlin/String.length|"];
19 [label="Exit block"];
}
20 [label="Exit function test_2" style="filled" fillcolor=red];
}
12 -> {13};
13 -> {14};
14 -> {15};
15 -> {16};
16 -> {17};
17 -> {18};
subgraph cluster_4 {
color=red
19 [label="Enter function test_3" style="filled" fillcolor=red];
subgraph cluster_5 {
color=blue
20 [label="Enter block"];
21 [label="Access variable R|<local>/x|"];
22 [label="Const: Null(null)"];
23 [label="Equality operator !="];
24 [label="Function call: R|kotlin/require|(...)" style="filled" fillcolor=yellow];
25 [label="Access variable R|<local>/x|"];
26 [label="Smart cast: R|<local>/x|"];
27 [label="Access variable R|kotlin/String.length|"];
28 [label="Exit block"];
}
29 [label="Exit function test_3" style="filled" fillcolor=red];
}
18 -> {19};
19 -> {20};
20 -> {21};
subgraph cluster_5 {
color=red
21 [label="Enter function test_3" style="filled" fillcolor=red];
subgraph cluster_6 {
color=blue
22 [label="Enter block"];
23 [label="Access variable R|<local>/x|"];
24 [label="Const: Null(null)"];
25 [label="Equality operator !="];
26 [label="Function call: R|kotlin/require|(...)" style="filled" fillcolor=yellow];
27 [label="Access variable R|<local>/x|"];
28 [label="Smart cast: R|<local>/x|"];
29 [label="Access variable R|kotlin/String.length|"];
30 [label="Exit block"];
}
31 [label="Exit function test_3" style="filled" fillcolor=red];
}
21 -> {22};
22 -> {23};
23 -> {24};
@@ -80,44 +85,44 @@ digraph conditionalEffects_kt {
26 -> {27};
27 -> {28};
28 -> {29};
subgraph cluster_6 {
color=red
30 [label="Enter function test_4" style="filled" fillcolor=red];
subgraph cluster_7 {
color=blue
31 [label="Enter block"];
subgraph cluster_8 {
color=blue
32 [label="Enter &&"];
33 [label="Access variable R|<local>/x|"];
34 [label="Type operator: (R|<local>/x| is R|kotlin/String|)"];
35 [label="Exit left part of &&"];
36 [label="Enter right part of &&"];
37 [label="Access variable R|<local>/y|"];
38 [label="Const: Null(null)"];
39 [label="Equality operator !="];
40 [label="Exit &&"];
}
41 [label="Function call: R|kotlin/require|(...)" style="filled" fillcolor=yellow];
42 [label="Access variable R|<local>/x|"];
43 [label="Smart cast: R|<local>/x|"];
44 [label="Access variable R|kotlin/String.length|"];
45 [label="Access variable R|<local>/y|"];
46 [label="Smart cast: R|<local>/y|"];
47 [label="Access variable R|kotlin/String.length|"];
48 [label="Exit block"];
}
49 [label="Exit function test_4" style="filled" fillcolor=red];
}
29 -> {30};
30 -> {31};
31 -> {32};
subgraph cluster_7 {
color=red
32 [label="Enter function test_4" style="filled" fillcolor=red];
subgraph cluster_8 {
color=blue
33 [label="Enter block"];
subgraph cluster_9 {
color=blue
34 [label="Enter &&"];
35 [label="Access variable R|<local>/x|"];
36 [label="Type operator: (R|<local>/x| is R|kotlin/String|)"];
37 [label="Exit left part of &&"];
38 [label="Enter right part of &&"];
39 [label="Access variable R|<local>/y|"];
40 [label="Const: Null(null)"];
41 [label="Equality operator !="];
42 [label="Exit &&"];
}
43 [label="Function call: R|kotlin/require|(...)" style="filled" fillcolor=yellow];
44 [label="Access variable R|<local>/x|"];
45 [label="Smart cast: R|<local>/x|"];
46 [label="Access variable R|kotlin/String.length|"];
47 [label="Access variable R|<local>/y|"];
48 [label="Smart cast: R|<local>/y|"];
49 [label="Access variable R|kotlin/String.length|"];
50 [label="Exit block"];
}
51 [label="Exit function test_4" style="filled" fillcolor=red];
}
32 -> {33};
33 -> {34};
34 -> {35};
35 -> {36 40};
35 -> {36};
36 -> {37};
37 -> {38};
37 -> {38 42};
38 -> {39};
39 -> {40};
40 -> {41};
@@ -129,73 +134,73 @@ digraph conditionalEffects_kt {
46 -> {47};
47 -> {48};
48 -> {49};
49 -> {50};
50 -> {51};
subgraph cluster_9 {
subgraph cluster_10 {
color=red
50 [label="Enter function test_5" style="filled" fillcolor=red];
subgraph cluster_10 {
52 [label="Enter function test_5" style="filled" fillcolor=red];
subgraph cluster_11 {
color=blue
51 [label="Enter block"];
subgraph cluster_11 {
53 [label="Enter block"];
subgraph cluster_12 {
color=blue
52 [label="Enter when"];
subgraph cluster_12 {
color=blue
53 [label="Enter when branch condition "];
54 [label="Access variable R|<local>/b|"];
55 [label="Exit when branch condition"];
}
54 [label="Enter when"];
subgraph cluster_13 {
color=blue
56 [label="Enter when branch condition else"];
55 [label="Enter when branch condition "];
56 [label="Access variable R|<local>/b|"];
57 [label="Exit when branch condition"];
}
58 [label="Enter when branch result"];
subgraph cluster_14 {
color=blue
59 [label="Enter block"];
60 [label="Access variable R|<local>/x|"];
61 [label="Access variable <Unresolved name: length>#"];
62 [label="Exit block"];
58 [label="Enter when branch condition else"];
59 [label="Exit when branch condition"];
}
63 [label="Exit when branch result"];
64 [label="Enter when branch result"];
60 [label="Enter when branch result"];
subgraph cluster_15 {
color=blue
65 [label="Enter block"];
66 [label="Access variable R|<local>/x|"];
67 [label="Type operator: (R|<local>/x| is R|kotlin/String|)"];
68 [label="Function call: R|kotlin/require|(...)" style="filled" fillcolor=yellow];
69 [label="Access variable R|<local>/x|"];
70 [label="Smart cast: R|<local>/x|"];
71 [label="Access variable R|kotlin/String.length|"];
72 [label="Exit block"];
61 [label="Enter block"];
62 [label="Access variable R|<local>/x|"];
63 [label="Access variable <Unresolved name: length>#"];
64 [label="Exit block"];
}
73 [label="Exit when branch result"];
74 [label="Exit when"];
65 [label="Exit when branch result"];
66 [label="Enter when branch result"];
subgraph cluster_16 {
color=blue
67 [label="Enter block"];
68 [label="Access variable R|<local>/x|"];
69 [label="Type operator: (R|<local>/x| is R|kotlin/String|)"];
70 [label="Function call: R|kotlin/require|(...)" style="filled" fillcolor=yellow];
71 [label="Access variable R|<local>/x|"];
72 [label="Smart cast: R|<local>/x|"];
73 [label="Access variable R|kotlin/String.length|"];
74 [label="Exit block"];
}
75 [label="Exit when branch result"];
76 [label="Exit when"];
}
75 [label="Access variable R|<local>/x|"];
76 [label="Access variable <Unresolved name: length>#"];
77 [label="Exit block"];
77 [label="Access variable R|<local>/x|"];
78 [label="Access variable <Unresolved name: length>#"];
79 [label="Exit block"];
}
78 [label="Exit function test_5" style="filled" fillcolor=red];
80 [label="Exit function test_5" style="filled" fillcolor=red];
}
50 -> {51};
51 -> {52};
52 -> {53};
53 -> {54};
54 -> {55};
55 -> {56 64};
55 -> {56};
56 -> {57};
57 -> {58};
57 -> {58 66};
58 -> {59};
59 -> {60};
60 -> {61};
61 -> {62};
62 -> {63};
63 -> {74};
63 -> {64};
64 -> {65};
65 -> {66};
65 -> {76};
66 -> {67};
67 -> {68};
68 -> {69};
@@ -208,70 +213,70 @@ digraph conditionalEffects_kt {
75 -> {76};
76 -> {77};
77 -> {78};
78 -> {79};
79 -> {80};
subgraph cluster_16 {
subgraph cluster_17 {
color=red
79 [label="Enter function test_6" style="filled" fillcolor=red];
subgraph cluster_17 {
81 [label="Enter function test_6" style="filled" fillcolor=red];
subgraph cluster_18 {
color=blue
80 [label="Enter block"];
subgraph cluster_18 {
82 [label="Enter block"];
subgraph cluster_19 {
color=blue
81 [label="Enter when"];
subgraph cluster_19 {
color=blue
82 [label="Enter when branch condition "];
83 [label="Access variable R|<local>/b|"];
84 [label="Exit when branch condition"];
}
83 [label="Enter when"];
subgraph cluster_20 {
color=blue
85 [label="Enter when branch condition else"];
84 [label="Enter when branch condition "];
85 [label="Access variable R|<local>/b|"];
86 [label="Exit when branch condition"];
}
87 [label="Enter when branch result"];
subgraph cluster_21 {
color=blue
88 [label="Enter block"];
89 [label="Access variable R|<local>/x|"];
90 [label="Type operator: (R|<local>/x| is R|kotlin/String|)"];
91 [label="Function call: R|kotlin/require|(...)" style="filled" fillcolor=yellow];
92 [label="Access variable R|<local>/x|"];
93 [label="Smart cast: R|<local>/x|"];
94 [label="Access variable R|kotlin/String.length|"];
95 [label="Exit block"];
87 [label="Enter when branch condition else"];
88 [label="Exit when branch condition"];
}
96 [label="Exit when branch result"];
97 [label="Enter when branch result"];
89 [label="Enter when branch result"];
subgraph cluster_22 {
color=blue
98 [label="Enter block"];
99 [label="Access variable R|<local>/x|"];
100 [label="Type operator: (R|<local>/x| is R|kotlin/String|)"];
101 [label="Function call: R|kotlin/require|(...)" style="filled" fillcolor=yellow];
102 [label="Access variable R|<local>/x|"];
103 [label="Smart cast: R|<local>/x|"];
104 [label="Access variable R|kotlin/String.length|"];
105 [label="Exit block"];
90 [label="Enter block"];
91 [label="Access variable R|<local>/x|"];
92 [label="Type operator: (R|<local>/x| is R|kotlin/String|)"];
93 [label="Function call: R|kotlin/require|(...)" style="filled" fillcolor=yellow];
94 [label="Access variable R|<local>/x|"];
95 [label="Smart cast: R|<local>/x|"];
96 [label="Access variable R|kotlin/String.length|"];
97 [label="Exit block"];
}
106 [label="Exit when branch result"];
107 [label="Exit when"];
98 [label="Exit when branch result"];
99 [label="Enter when branch result"];
subgraph cluster_23 {
color=blue
100 [label="Enter block"];
101 [label="Access variable R|<local>/x|"];
102 [label="Type operator: (R|<local>/x| is R|kotlin/String|)"];
103 [label="Function call: R|kotlin/require|(...)" style="filled" fillcolor=yellow];
104 [label="Access variable R|<local>/x|"];
105 [label="Smart cast: R|<local>/x|"];
106 [label="Access variable R|kotlin/String.length|"];
107 [label="Exit block"];
}
108 [label="Exit when branch result"];
109 [label="Exit when"];
}
108 [label="Access variable R|<local>/x|"];
109 [label="Smart cast: R|<local>/x|"];
110 [label="Access variable R|kotlin/String.length|"];
111 [label="Exit block"];
110 [label="Access variable R|<local>/x|"];
111 [label="Smart cast: R|<local>/x|"];
112 [label="Access variable R|kotlin/String.length|"];
113 [label="Exit block"];
}
112 [label="Exit function test_6" style="filled" fillcolor=red];
114 [label="Exit function test_6" style="filled" fillcolor=red];
}
79 -> {80};
80 -> {81};
81 -> {82};
82 -> {83};
83 -> {84};
84 -> {85 97};
84 -> {85};
85 -> {86};
86 -> {87};
86 -> {87 99};
87 -> {88};
88 -> {89};
89 -> {90};
@@ -281,9 +286,9 @@ digraph conditionalEffects_kt {
93 -> {94};
94 -> {95};
95 -> {96};
96 -> {107};
96 -> {97};
97 -> {98};
98 -> {99};
98 -> {109};
99 -> {100};
100 -> {101};
101 -> {102};
@@ -297,5 +302,7 @@ digraph conditionalEffects_kt {
109 -> {110};
110 -> {111};
111 -> {112};
112 -> {113};
113 -> {114};
}