[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,36 +5,41 @@ digraph bangbang_kt {
subgraph cluster_0 {
color=red
0 [label="Enter class A" style="filled" fillcolor=red];
1 [label="Exit class A" style="filled" fillcolor=red];
0 [label="Enter file bangbang.kt" style="filled" fillcolor=red];
1 [label="Exit file bangbang.kt" style="filled" fillcolor=red];
}
0 -> {1} [color=green];
subgraph cluster_1 {
color=red
2 [label="Enter function foo" style="filled" fillcolor=red];
3 [label="Exit function foo" style="filled" fillcolor=red];
2 [label="Enter class A" style="filled" fillcolor=red];
3 [label="Exit class A" style="filled" fillcolor=red];
}
2 -> {3};
2 -> {3} [color=green];
subgraph cluster_2 {
color=red
4 [label="Enter function test_0" style="filled" fillcolor=red];
subgraph cluster_3 {
color=blue
5 [label="Enter block"];
6 [label="Access variable R|<local>/a|"];
7 [label="Check not null: R|<local>/a|!!" style="filled" fillcolor=yellow];
8 [label="Function call: R|<local>/a|!!.R|/A.foo|()" style="filled" fillcolor=yellow];
9 [label="Access variable R|<local>/a|"];
10 [label="Smart cast: R|<local>/a|"];
11 [label="Function call: R|<local>/a|.R|/A.foo|()" style="filled" fillcolor=yellow];
12 [label="Exit block"];
}
13 [label="Exit function test_0" style="filled" fillcolor=red];
4 [label="Enter function foo" style="filled" fillcolor=red];
5 [label="Exit function foo" style="filled" fillcolor=red];
}
4 -> {5};
5 -> {6};
subgraph cluster_3 {
color=red
6 [label="Enter function test_0" style="filled" fillcolor=red];
subgraph cluster_4 {
color=blue
7 [label="Enter block"];
8 [label="Access variable R|<local>/a|"];
9 [label="Check not null: R|<local>/a|!!" style="filled" fillcolor=yellow];
10 [label="Function call: R|<local>/a|!!.R|/A.foo|()" style="filled" fillcolor=yellow];
11 [label="Access variable R|<local>/a|"];
12 [label="Smart cast: R|<local>/a|"];
13 [label="Function call: R|<local>/a|.R|/A.foo|()" style="filled" fillcolor=yellow];
14 [label="Exit block"];
}
15 [label="Exit function test_0" style="filled" fillcolor=red];
}
6 -> {7};
7 -> {8};
8 -> {9};
@@ -42,55 +47,55 @@ digraph bangbang_kt {
10 -> {11};
11 -> {12};
12 -> {13};
13 -> {14};
14 -> {15};
subgraph cluster_4 {
subgraph cluster_5 {
color=red
14 [label="Enter function test_1" style="filled" fillcolor=red];
subgraph cluster_5 {
16 [label="Enter function test_1" style="filled" fillcolor=red];
subgraph cluster_6 {
color=blue
15 [label="Enter block"];
subgraph cluster_6 {
17 [label="Enter block"];
subgraph cluster_7 {
color=blue
16 [label="Enter when"];
subgraph cluster_7 {
color=blue
17 [label="Enter when branch condition "];
18 [label="Access variable R|<local>/a|"];
19 [label="Check not null: R|<local>/a|!!" style="filled" fillcolor=yellow];
20 [label="Function call: R|<local>/a|!!.R|/A.foo|()" style="filled" fillcolor=yellow];
21 [label="Exit when branch condition"];
}
22 [label="Synthetic else branch"];
23 [label="Enter when branch result"];
18 [label="Enter when"];
subgraph cluster_8 {
color=blue
24 [label="Enter block"];
25 [label="Access variable R|<local>/a|"];
26 [label="Smart cast: R|<local>/a|"];
27 [label="Function call: R|<local>/a|.R|/A.foo|()" style="filled" fillcolor=yellow];
28 [label="Exit block"];
19 [label="Enter when branch condition "];
20 [label="Access variable R|<local>/a|"];
21 [label="Check not null: R|<local>/a|!!" style="filled" fillcolor=yellow];
22 [label="Function call: R|<local>/a|!!.R|/A.foo|()" style="filled" fillcolor=yellow];
23 [label="Exit when branch condition"];
}
29 [label="Exit when branch result"];
30 [label="Exit when"];
24 [label="Synthetic else branch"];
25 [label="Enter when branch result"];
subgraph cluster_9 {
color=blue
26 [label="Enter block"];
27 [label="Access variable R|<local>/a|"];
28 [label="Smart cast: R|<local>/a|"];
29 [label="Function call: R|<local>/a|.R|/A.foo|()" style="filled" fillcolor=yellow];
30 [label="Exit block"];
}
31 [label="Exit when branch result"];
32 [label="Exit when"];
}
31 [label="Access variable R|<local>/a|"];
32 [label="Smart cast: R|<local>/a|"];
33 [label="Function call: R|<local>/a|.R|/A.foo|()" style="filled" fillcolor=yellow];
34 [label="Exit block"];
33 [label="Access variable R|<local>/a|"];
34 [label="Smart cast: R|<local>/a|"];
35 [label="Function call: R|<local>/a|.R|/A.foo|()" style="filled" fillcolor=yellow];
36 [label="Exit block"];
}
35 [label="Exit function test_1" style="filled" fillcolor=red];
37 [label="Exit function test_1" style="filled" fillcolor=red];
}
14 -> {15};
15 -> {16};
16 -> {17};
17 -> {18};
18 -> {19};
19 -> {20};
20 -> {21};
21 -> {22 23};
22 -> {30};
23 -> {24};
24 -> {25};
21 -> {22};
22 -> {23};
23 -> {24 25};
24 -> {32};
25 -> {26};
26 -> {27};
27 -> {28};
@@ -101,68 +106,68 @@ digraph bangbang_kt {
32 -> {33};
33 -> {34};
34 -> {35};
subgraph cluster_9 {
color=red
36 [label="Enter function test_2" style="filled" fillcolor=red];
subgraph cluster_10 {
color=blue
37 [label="Enter block"];
subgraph cluster_11 {
color=blue
38 [label="Enter when"];
subgraph cluster_12 {
color=blue
39 [label="Enter when branch condition "];
subgraph cluster_13 {
color=blue
40 [label="Enter &&"];
41 [label="Access variable R|<local>/a|"];
42 [label="Check not null: R|<local>/a|!!" style="filled" fillcolor=yellow];
43 [label="Function call: R|<local>/a|!!.R|/A.foo|()" style="filled" fillcolor=yellow];
44 [label="Exit left part of &&"];
45 [label="Enter right part of &&"];
46 [label="Access variable R|<local>/b|"];
47 [label="Exit &&"];
}
48 [label="Exit when branch condition"];
}
49 [label="Synthetic else branch"];
50 [label="Enter when branch result"];
subgraph cluster_14 {
color=blue
51 [label="Enter block"];
52 [label="Access variable R|<local>/a|"];
53 [label="Smart cast: R|<local>/a|"];
54 [label="Function call: R|<local>/a|.R|/A.foo|()" style="filled" fillcolor=yellow];
55 [label="Exit block"];
}
56 [label="Exit when branch result"];
57 [label="Exit when"];
}
58 [label="Access variable R|<local>/a|"];
59 [label="Smart cast: R|<local>/a|"];
60 [label="Function call: R|<local>/a|.R|/A.foo|()" style="filled" fillcolor=yellow];
61 [label="Exit block"];
}
62 [label="Exit function test_2" style="filled" fillcolor=red];
}
35 -> {36};
36 -> {37};
37 -> {38};
subgraph cluster_10 {
color=red
38 [label="Enter function test_2" style="filled" fillcolor=red];
subgraph cluster_11 {
color=blue
39 [label="Enter block"];
subgraph cluster_12 {
color=blue
40 [label="Enter when"];
subgraph cluster_13 {
color=blue
41 [label="Enter when branch condition "];
subgraph cluster_14 {
color=blue
42 [label="Enter &&"];
43 [label="Access variable R|<local>/a|"];
44 [label="Check not null: R|<local>/a|!!" style="filled" fillcolor=yellow];
45 [label="Function call: R|<local>/a|!!.R|/A.foo|()" style="filled" fillcolor=yellow];
46 [label="Exit left part of &&"];
47 [label="Enter right part of &&"];
48 [label="Access variable R|<local>/b|"];
49 [label="Exit &&"];
}
50 [label="Exit when branch condition"];
}
51 [label="Synthetic else branch"];
52 [label="Enter when branch result"];
subgraph cluster_15 {
color=blue
53 [label="Enter block"];
54 [label="Access variable R|<local>/a|"];
55 [label="Smart cast: R|<local>/a|"];
56 [label="Function call: R|<local>/a|.R|/A.foo|()" style="filled" fillcolor=yellow];
57 [label="Exit block"];
}
58 [label="Exit when branch result"];
59 [label="Exit when"];
}
60 [label="Access variable R|<local>/a|"];
61 [label="Smart cast: R|<local>/a|"];
62 [label="Function call: R|<local>/a|.R|/A.foo|()" style="filled" fillcolor=yellow];
63 [label="Exit block"];
}
64 [label="Exit function test_2" style="filled" fillcolor=red];
}
38 -> {39};
39 -> {40};
40 -> {41};
41 -> {42};
42 -> {43};
43 -> {44};
44 -> {45 47};
44 -> {45};
45 -> {46};
46 -> {47};
46 -> {47 49};
47 -> {48};
48 -> {49 50};
49 -> {57};
50 -> {51};
51 -> {52};
48 -> {49};
49 -> {50};
50 -> {51 52};
51 -> {59};
52 -> {53};
53 -> {54};
54 -> {55};
@@ -173,67 +178,67 @@ digraph bangbang_kt {
59 -> {60};
60 -> {61};
61 -> {62};
subgraph cluster_15 {
color=red
63 [label="Enter function test_3" style="filled" fillcolor=red];
subgraph cluster_16 {
color=blue
64 [label="Enter block"];
subgraph cluster_17 {
color=blue
65 [label="Enter when"];
subgraph cluster_18 {
color=blue
66 [label="Enter when branch condition "];
subgraph cluster_19 {
color=blue
67 [label="Enter &&"];
68 [label="Access variable R|<local>/b|"];
69 [label="Exit left part of &&"];
70 [label="Enter right part of &&"];
71 [label="Access variable R|<local>/a|"];
72 [label="Check not null: R|<local>/a|!!" style="filled" fillcolor=yellow];
73 [label="Function call: R|<local>/a|!!.R|/A.foo|()" style="filled" fillcolor=yellow];
74 [label="Exit &&"];
}
75 [label="Exit when branch condition"];
}
76 [label="Synthetic else branch"];
77 [label="Enter when branch result"];
subgraph cluster_20 {
color=blue
78 [label="Enter block"];
79 [label="Access variable R|<local>/a|"];
80 [label="Smart cast: R|<local>/a|"];
81 [label="Function call: R|<local>/a|.R|/A.foo|()" style="filled" fillcolor=yellow];
82 [label="Exit block"];
}
83 [label="Exit when branch result"];
84 [label="Exit when"];
}
85 [label="Access variable R|<local>/a|"];
86 [label="Function call: R|<local>/a|.R|/A.foo<Inapplicable(UNSAFE_CALL): /A.foo>#|()" style="filled" fillcolor=yellow];
87 [label="Exit block"];
}
88 [label="Exit function test_3" style="filled" fillcolor=red];
}
62 -> {63};
63 -> {64};
64 -> {65};
subgraph cluster_16 {
color=red
65 [label="Enter function test_3" style="filled" fillcolor=red];
subgraph cluster_17 {
color=blue
66 [label="Enter block"];
subgraph cluster_18 {
color=blue
67 [label="Enter when"];
subgraph cluster_19 {
color=blue
68 [label="Enter when branch condition "];
subgraph cluster_20 {
color=blue
69 [label="Enter &&"];
70 [label="Access variable R|<local>/b|"];
71 [label="Exit left part of &&"];
72 [label="Enter right part of &&"];
73 [label="Access variable R|<local>/a|"];
74 [label="Check not null: R|<local>/a|!!" style="filled" fillcolor=yellow];
75 [label="Function call: R|<local>/a|!!.R|/A.foo|()" style="filled" fillcolor=yellow];
76 [label="Exit &&"];
}
77 [label="Exit when branch condition"];
}
78 [label="Synthetic else branch"];
79 [label="Enter when branch result"];
subgraph cluster_21 {
color=blue
80 [label="Enter block"];
81 [label="Access variable R|<local>/a|"];
82 [label="Smart cast: R|<local>/a|"];
83 [label="Function call: R|<local>/a|.R|/A.foo|()" style="filled" fillcolor=yellow];
84 [label="Exit block"];
}
85 [label="Exit when branch result"];
86 [label="Exit when"];
}
87 [label="Access variable R|<local>/a|"];
88 [label="Function call: R|<local>/a|.R|/A.foo<Inapplicable(UNSAFE_CALL): /A.foo>#|()" style="filled" fillcolor=yellow];
89 [label="Exit block"];
}
90 [label="Exit function test_3" style="filled" fillcolor=red];
}
65 -> {66};
66 -> {67};
67 -> {68};
68 -> {69};
69 -> {70 74};
69 -> {70};
70 -> {71};
71 -> {72};
71 -> {72 76};
72 -> {73};
73 -> {74};
74 -> {75};
75 -> {76 77};
76 -> {84};
77 -> {78};
78 -> {79};
75 -> {76};
76 -> {77};
77 -> {78 79};
78 -> {86};
79 -> {80};
80 -> {81};
81 -> {82};
@@ -243,68 +248,68 @@ digraph bangbang_kt {
85 -> {86};
86 -> {87};
87 -> {88};
subgraph cluster_21 {
color=red
89 [label="Enter function test_4" style="filled" fillcolor=red];
subgraph cluster_22 {
color=blue
90 [label="Enter block"];
subgraph cluster_23 {
color=blue
91 [label="Enter when"];
subgraph cluster_24 {
color=blue
92 [label="Enter when branch condition "];
subgraph cluster_25 {
color=blue
93 [label="Enter ||"];
94 [label="Access variable R|<local>/a|"];
95 [label="Check not null: R|<local>/a|!!" style="filled" fillcolor=yellow];
96 [label="Function call: R|<local>/a|!!.R|/A.foo|()" style="filled" fillcolor=yellow];
97 [label="Exit left part of ||"];
98 [label="Enter right part of ||"];
99 [label="Access variable R|<local>/b|"];
100 [label="Exit ||"];
}
101 [label="Exit when branch condition"];
}
102 [label="Synthetic else branch"];
103 [label="Enter when branch result"];
subgraph cluster_26 {
color=blue
104 [label="Enter block"];
105 [label="Access variable R|<local>/a|"];
106 [label="Smart cast: R|<local>/a|"];
107 [label="Function call: R|<local>/a|.R|/A.foo|()" style="filled" fillcolor=yellow];
108 [label="Exit block"];
}
109 [label="Exit when branch result"];
110 [label="Exit when"];
}
111 [label="Access variable R|<local>/a|"];
112 [label="Smart cast: R|<local>/a|"];
113 [label="Function call: R|<local>/a|.R|/A.foo|()" style="filled" fillcolor=yellow];
114 [label="Exit block"];
}
115 [label="Exit function test_4" style="filled" fillcolor=red];
}
88 -> {89};
89 -> {90};
90 -> {91};
subgraph cluster_22 {
color=red
91 [label="Enter function test_4" style="filled" fillcolor=red];
subgraph cluster_23 {
color=blue
92 [label="Enter block"];
subgraph cluster_24 {
color=blue
93 [label="Enter when"];
subgraph cluster_25 {
color=blue
94 [label="Enter when branch condition "];
subgraph cluster_26 {
color=blue
95 [label="Enter ||"];
96 [label="Access variable R|<local>/a|"];
97 [label="Check not null: R|<local>/a|!!" style="filled" fillcolor=yellow];
98 [label="Function call: R|<local>/a|!!.R|/A.foo|()" style="filled" fillcolor=yellow];
99 [label="Exit left part of ||"];
100 [label="Enter right part of ||"];
101 [label="Access variable R|<local>/b|"];
102 [label="Exit ||"];
}
103 [label="Exit when branch condition"];
}
104 [label="Synthetic else branch"];
105 [label="Enter when branch result"];
subgraph cluster_27 {
color=blue
106 [label="Enter block"];
107 [label="Access variable R|<local>/a|"];
108 [label="Smart cast: R|<local>/a|"];
109 [label="Function call: R|<local>/a|.R|/A.foo|()" style="filled" fillcolor=yellow];
110 [label="Exit block"];
}
111 [label="Exit when branch result"];
112 [label="Exit when"];
}
113 [label="Access variable R|<local>/a|"];
114 [label="Smart cast: R|<local>/a|"];
115 [label="Function call: R|<local>/a|.R|/A.foo|()" style="filled" fillcolor=yellow];
116 [label="Exit block"];
}
117 [label="Exit function test_4" style="filled" fillcolor=red];
}
91 -> {92};
92 -> {93};
93 -> {94};
94 -> {95};
95 -> {96};
96 -> {97};
97 -> {98 100};
97 -> {98};
98 -> {99};
99 -> {100};
99 -> {100 102};
100 -> {101};
101 -> {102 103};
102 -> {110};
103 -> {104};
104 -> {105};
101 -> {102};
102 -> {103};
103 -> {104 105};
104 -> {112};
105 -> {106};
106 -> {107};
107 -> {108};
@@ -315,66 +320,66 @@ digraph bangbang_kt {
112 -> {113};
113 -> {114};
114 -> {115};
subgraph cluster_27 {
color=red
116 [label="Enter function test_5" style="filled" fillcolor=red];
subgraph cluster_28 {
color=blue
117 [label="Enter block"];
subgraph cluster_29 {
color=blue
118 [label="Enter when"];
subgraph cluster_30 {
color=blue
119 [label="Enter when branch condition "];
subgraph cluster_31 {
color=blue
120 [label="Enter ||"];
121 [label="Access variable R|<local>/b|"];
122 [label="Exit left part of ||"];
123 [label="Enter right part of ||"];
124 [label="Access variable R|<local>/a|"];
125 [label="Check not null: R|<local>/a|!!" style="filled" fillcolor=yellow];
126 [label="Function call: R|<local>/a|!!.R|/A.foo|()" style="filled" fillcolor=yellow];
127 [label="Exit ||"];
}
128 [label="Exit when branch condition"];
}
129 [label="Synthetic else branch"];
130 [label="Enter when branch result"];
subgraph cluster_32 {
color=blue
131 [label="Enter block"];
132 [label="Access variable R|<local>/a|"];
133 [label="Function call: R|<local>/a|.R|/A.foo<Inapplicable(UNSAFE_CALL): /A.foo>#|()" style="filled" fillcolor=yellow];
134 [label="Exit block"];
}
135 [label="Exit when branch result"];
136 [label="Exit when"];
}
137 [label="Access variable R|<local>/a|"];
138 [label="Function call: R|<local>/a|.R|/A.foo<Inapplicable(UNSAFE_CALL): /A.foo>#|()" style="filled" fillcolor=yellow];
139 [label="Exit block"];
}
140 [label="Exit function test_5" style="filled" fillcolor=red];
}
115 -> {116};
116 -> {117};
117 -> {118};
subgraph cluster_28 {
color=red
118 [label="Enter function test_5" style="filled" fillcolor=red];
subgraph cluster_29 {
color=blue
119 [label="Enter block"];
subgraph cluster_30 {
color=blue
120 [label="Enter when"];
subgraph cluster_31 {
color=blue
121 [label="Enter when branch condition "];
subgraph cluster_32 {
color=blue
122 [label="Enter ||"];
123 [label="Access variable R|<local>/b|"];
124 [label="Exit left part of ||"];
125 [label="Enter right part of ||"];
126 [label="Access variable R|<local>/a|"];
127 [label="Check not null: R|<local>/a|!!" style="filled" fillcolor=yellow];
128 [label="Function call: R|<local>/a|!!.R|/A.foo|()" style="filled" fillcolor=yellow];
129 [label="Exit ||"];
}
130 [label="Exit when branch condition"];
}
131 [label="Synthetic else branch"];
132 [label="Enter when branch result"];
subgraph cluster_33 {
color=blue
133 [label="Enter block"];
134 [label="Access variable R|<local>/a|"];
135 [label="Function call: R|<local>/a|.R|/A.foo<Inapplicable(UNSAFE_CALL): /A.foo>#|()" style="filled" fillcolor=yellow];
136 [label="Exit block"];
}
137 [label="Exit when branch result"];
138 [label="Exit when"];
}
139 [label="Access variable R|<local>/a|"];
140 [label="Function call: R|<local>/a|.R|/A.foo<Inapplicable(UNSAFE_CALL): /A.foo>#|()" style="filled" fillcolor=yellow];
141 [label="Exit block"];
}
142 [label="Exit function test_5" style="filled" fillcolor=red];
}
118 -> {119};
119 -> {120};
120 -> {121};
121 -> {122};
122 -> {123 127};
122 -> {123};
123 -> {124};
124 -> {125};
124 -> {125 129};
125 -> {126};
126 -> {127};
127 -> {128};
128 -> {129 130};
129 -> {136};
130 -> {131};
131 -> {132};
128 -> {129};
129 -> {130};
130 -> {131 132};
131 -> {138};
132 -> {133};
133 -> {134};
134 -> {135};
@@ -383,45 +388,47 @@ digraph bangbang_kt {
137 -> {138};
138 -> {139};
139 -> {140};
subgraph cluster_33 {
color=red
141 [label="Enter function test_6" style="filled" fillcolor=red];
subgraph cluster_34 {
color=blue
142 [label="Enter block"];
143 [label="Access variable R|<local>/x|"];
144 [label="Check not null: R|<local>/x|!!" style="filled" fillcolor=yellow];
145 [label="Function call: R|<local>/x|!!.R|/A.foo|()" style="filled" fillcolor=yellow];
146 [label="Exit block"];
}
147 [label="Exit function test_6" style="filled" fillcolor=red];
}
140 -> {141};
141 -> {142};
142 -> {143};
subgraph cluster_34 {
color=red
143 [label="Enter function test_6" style="filled" fillcolor=red];
subgraph cluster_35 {
color=blue
144 [label="Enter block"];
145 [label="Access variable R|<local>/x|"];
146 [label="Check not null: R|<local>/x|!!" style="filled" fillcolor=yellow];
147 [label="Function call: R|<local>/x|!!.R|/A.foo|()" style="filled" fillcolor=yellow];
148 [label="Exit block"];
}
149 [label="Exit function test_6" style="filled" fillcolor=red];
}
143 -> {144};
144 -> {145};
145 -> {146};
146 -> {147};
subgraph cluster_35 {
color=red
148 [label="Enter function test_7" style="filled" fillcolor=red];
subgraph cluster_36 {
color=blue
149 [label="Enter block"];
150 [label="Access variable R|<local>/x|"];
151 [label="Check not null: R|<local>/x|!!" style="filled" fillcolor=yellow];
152 [label="Function call: R|<local>/x|!!.R|/A.foo|()" style="filled" fillcolor=yellow];
153 [label="Exit block"];
}
154 [label="Exit function test_7" style="filled" fillcolor=red];
}
147 -> {148};
148 -> {149};
149 -> {150};
subgraph cluster_36 {
color=red
150 [label="Enter function test_7" style="filled" fillcolor=red];
subgraph cluster_37 {
color=blue
151 [label="Enter block"];
152 [label="Access variable R|<local>/x|"];
153 [label="Check not null: R|<local>/x|!!" style="filled" fillcolor=yellow];
154 [label="Function call: R|<local>/x|!!.R|/A.foo|()" style="filled" fillcolor=yellow];
155 [label="Exit block"];
}
156 [label="Exit function test_7" style="filled" fillcolor=red];
}
150 -> {151};
151 -> {152};
152 -> {153};
153 -> {154};
154 -> {155};
155 -> {156};
}