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