[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
+276 -269
View File
@@ -5,156 +5,161 @@ digraph jumps_kt {
subgraph cluster_0 {
color=red
0 [label="Enter function test_1" style="filled" fillcolor=red];
subgraph cluster_1 {
0 [label="Enter file jumps.kt" style="filled" fillcolor=red];
1 [label="Exit file jumps.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
1 [label="Enter block"];
subgraph cluster_2 {
3 [label="Enter block"];
subgraph cluster_3 {
color=blue
2 [label="Enter when"];
subgraph cluster_3 {
color=blue
3 [label="Enter when branch condition "];
4 [label="Access variable R|<local>/x|"];
5 [label="Const: Null(null)"];
6 [label="Equality operator =="];
7 [label="Exit when branch condition"];
}
4 [label="Enter when"];
subgraph cluster_4 {
color=blue
8 [label="Enter when branch condition else"];
5 [label="Enter when branch condition "];
6 [label="Access variable R|<local>/x|"];
7 [label="Const: Null(null)"];
8 [label="Equality operator =="];
9 [label="Exit when branch condition"];
}
10 [label="Enter when branch result"];
subgraph cluster_5 {
color=blue
11 [label="Enter block"];
12 [label="Access variable R|<local>/x|"];
13 [label="Smart cast: R|<local>/x|"];
14 [label="Exit block"];
10 [label="Enter when branch condition else"];
11 [label="Exit when branch condition"];
}
15 [label="Exit when branch result"];
16 [label="Enter when branch result"];
12 [label="Enter when branch result"];
subgraph cluster_6 {
color=blue
17 [label="Enter block"];
18 [label="Function call: R|java/lang/Exception.Exception|()" style="filled" fillcolor=yellow];
19 [label="Throw: throw R|java/lang/Exception.Exception|()"];
20 [label="Stub" style="filled" fillcolor=gray];
21 [label="Exit block" style="filled" fillcolor=gray];
13 [label="Enter block"];
14 [label="Access variable R|<local>/x|"];
15 [label="Smart cast: R|<local>/x|"];
16 [label="Exit block"];
}
22 [label="Exit when branch result" style="filled" fillcolor=gray];
23 [label="Exit when"];
17 [label="Exit when branch result"];
18 [label="Enter when branch result"];
subgraph cluster_7 {
color=blue
19 [label="Enter block"];
20 [label="Function call: R|java/lang/Exception.Exception|()" style="filled" fillcolor=yellow];
21 [label="Throw: throw R|java/lang/Exception.Exception|()"];
22 [label="Stub" style="filled" fillcolor=gray];
23 [label="Exit block" style="filled" fillcolor=gray];
}
24 [label="Exit when branch result" style="filled" fillcolor=gray];
25 [label="Exit when"];
}
24 [label="Variable declaration: lval y: R|kotlin/Int|"];
25 [label="Access variable R|<local>/y|"];
26 [label="Function call: R|<local>/y|.R|kotlin/Int.inc|()" style="filled" fillcolor=yellow];
27 [label="Access variable R|<local>/x|"];
28 [label="Smart cast: R|<local>/x|"];
29 [label="Function call: R|<local>/x|.R|kotlin/Int.inc|()" style="filled" fillcolor=yellow];
30 [label="Exit block"];
26 [label="Variable declaration: lval y: R|kotlin/Int|"];
27 [label="Access variable R|<local>/y|"];
28 [label="Function call: R|<local>/y|.R|kotlin/Int.inc|()" style="filled" fillcolor=yellow];
29 [label="Access variable R|<local>/x|"];
30 [label="Smart cast: R|<local>/x|"];
31 [label="Function call: R|<local>/x|.R|kotlin/Int.inc|()" style="filled" fillcolor=yellow];
32 [label="Exit block"];
}
31 [label="Exit function test_1" style="filled" fillcolor=red];
33 [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 16};
7 -> {8};
8 -> {9};
9 -> {10};
9 -> {10 18};
10 -> {11};
11 -> {12};
12 -> {13};
13 -> {14};
14 -> {15};
15 -> {23};
15 -> {16};
16 -> {17};
17 -> {18};
17 -> {25};
18 -> {19};
19 -> {20} [style=dotted];
20 -> {21} [style=dotted];
19 -> {20};
20 -> {21};
21 -> {22} [style=dotted];
22 -> {23} [style=dotted];
23 -> {24};
24 -> {25};
23 -> {24} [style=dotted];
24 -> {25} [style=dotted];
25 -> {26};
26 -> {27};
27 -> {28};
28 -> {29};
29 -> {30};
30 -> {31};
31 -> {32};
32 -> {33};
subgraph cluster_7 {
subgraph cluster_8 {
color=red
32 [label="Enter function test_2" style="filled" fillcolor=red];
subgraph cluster_8 {
34 [label="Enter function test_2" style="filled" fillcolor=red];
subgraph cluster_9 {
color=blue
33 [label="Enter block"];
subgraph cluster_9 {
35 [label="Enter block"];
subgraph cluster_10 {
color=blue
34 [label="Enter when"];
subgraph cluster_10 {
color=blue
35 [label="Enter when branch condition "];
36 [label="Access variable R|<local>/x|"];
37 [label="Const: Null(null)"];
38 [label="Equality operator =="];
39 [label="Exit when branch condition"];
}
36 [label="Enter when"];
subgraph cluster_11 {
color=blue
40 [label="Enter when branch condition else"];
37 [label="Enter when branch condition "];
38 [label="Access variable R|<local>/x|"];
39 [label="Const: Null(null)"];
40 [label="Equality operator =="];
41 [label="Exit when branch condition"];
}
42 [label="Enter when branch result"];
subgraph cluster_12 {
color=blue
43 [label="Enter block"];
44 [label="Access variable R|<local>/x|"];
45 [label="Smart cast: R|<local>/x|"];
46 [label="Exit block"];
42 [label="Enter when branch condition else"];
43 [label="Exit when branch condition"];
}
47 [label="Exit when branch result"];
48 [label="Enter when branch result"];
44 [label="Enter when branch result"];
subgraph cluster_13 {
color=blue
49 [label="Enter block"];
50 [label="Access variable R|<local>/x|"];
51 [label="Smart cast: R|<local>/x|"];
52 [label="Exit block"];
45 [label="Enter block"];
46 [label="Access variable R|<local>/x|"];
47 [label="Smart cast: R|<local>/x|"];
48 [label="Exit block"];
}
53 [label="Exit when branch result"];
54 [label="Exit when"];
49 [label="Exit when branch result"];
50 [label="Enter when branch result"];
subgraph cluster_14 {
color=blue
51 [label="Enter block"];
52 [label="Access variable R|<local>/x|"];
53 [label="Smart cast: R|<local>/x|"];
54 [label="Exit block"];
}
55 [label="Exit when branch result"];
56 [label="Exit when"];
}
55 [label="Variable declaration: lval y: R|kotlin/Int?|"];
56 [label="Access variable R|<local>/y|"];
57 [label="Function call: R|<local>/y|.R|kotlin/Int.inc<Inapplicable(UNSAFE_CALL): kotlin/Int.inc>#|()" style="filled" fillcolor=yellow];
58 [label="Exit block"];
57 [label="Variable declaration: lval y: R|kotlin/Int?|"];
58 [label="Access variable R|<local>/y|"];
59 [label="Function call: R|<local>/y|.R|kotlin/Int.inc<Inapplicable(UNSAFE_CALL): kotlin/Int.inc>#|()" style="filled" fillcolor=yellow];
60 [label="Exit block"];
}
59 [label="Exit function test_2" style="filled" fillcolor=red];
61 [label="Exit function test_2" style="filled" fillcolor=red];
}
32 -> {33};
33 -> {34};
34 -> {35};
35 -> {36};
36 -> {37};
37 -> {38};
38 -> {39};
39 -> {40 48};
39 -> {40};
40 -> {41};
41 -> {42};
41 -> {42 50};
42 -> {43};
43 -> {44};
44 -> {45};
45 -> {46};
46 -> {47};
47 -> {54};
47 -> {48};
48 -> {49};
49 -> {50};
49 -> {56};
50 -> {51};
51 -> {52};
52 -> {53};
@@ -164,260 +169,262 @@ digraph jumps_kt {
56 -> {57};
57 -> {58};
58 -> {59};
59 -> {60};
60 -> {61};
subgraph cluster_14 {
subgraph cluster_15 {
color=red
60 [label="Enter function test_3" style="filled" fillcolor=red];
subgraph cluster_15 {
62 [label="Enter function test_3" style="filled" fillcolor=red];
subgraph cluster_16 {
color=blue
61 [label="Enter block"];
subgraph cluster_16 {
63 [label="Enter block"];
subgraph cluster_17 {
color=blue
62 [label="Enter while loop"];
subgraph cluster_17 {
color=blue
63 [label="Enter loop condition"];
64 [label="Const: Boolean(true)"];
65 [label="Exit loop condition"];
}
64 [label="Enter while loop"];
subgraph cluster_18 {
color=blue
66 [label="Enter loop block"];
subgraph cluster_19 {
color=blue
67 [label="Enter block"];
68 [label="Access variable R|<local>/x|"];
69 [label="Type operator: (R|<local>/x| as R|kotlin/Int|)"];
70 [label="Jump: break@@@[Boolean(true)] "];
71 [label="Stub" style="filled" fillcolor=gray];
72 [label="Exit block" style="filled" fillcolor=gray];
}
73 [label="Exit loop block" style="filled" fillcolor=gray];
65 [label="Enter loop condition"];
66 [label="Const: Boolean(true)"];
67 [label="Exit loop condition"];
}
74 [label="Exit while loop"];
subgraph cluster_19 {
color=blue
68 [label="Enter loop block"];
subgraph cluster_20 {
color=blue
69 [label="Enter block"];
70 [label="Access variable R|<local>/x|"];
71 [label="Type operator: (R|<local>/x| as R|kotlin/Int|)"];
72 [label="Jump: break@@@[Boolean(true)] "];
73 [label="Stub" style="filled" fillcolor=gray];
74 [label="Exit block" style="filled" fillcolor=gray];
}
75 [label="Exit loop block" style="filled" fillcolor=gray];
}
76 [label="Exit while loop"];
}
75 [label="Access variable R|<local>/x|"];
76 [label="Smart cast: R|<local>/x|"];
77 [label="Function call: R|<local>/x|.R|kotlin/Int.inc|()" style="filled" fillcolor=yellow];
78 [label="Exit block"];
77 [label="Access variable R|<local>/x|"];
78 [label="Smart cast: R|<local>/x|"];
79 [label="Function call: R|<local>/x|.R|kotlin/Int.inc|()" style="filled" fillcolor=yellow];
80 [label="Exit block"];
}
79 [label="Exit function test_3" style="filled" fillcolor=red];
81 [label="Exit function test_3" style="filled" fillcolor=red];
}
60 -> {61};
61 -> {62};
62 -> {63};
63 -> {64};
64 -> {65};
65 -> {66};
65 -> {74} [style=dotted];
66 -> {67};
67 -> {68};
67 -> {76} [style=dotted];
68 -> {69};
69 -> {70};
70 -> {74};
70 -> {71} [style=dotted];
71 -> {72} [style=dotted];
70 -> {71};
71 -> {72};
72 -> {76};
72 -> {73} [style=dotted];
73 -> {63} [color=green style=dotted];
74 -> {75};
75 -> {76};
73 -> {74} [style=dotted];
74 -> {75} [style=dotted];
75 -> {65} [color=green style=dotted];
76 -> {77};
77 -> {78};
78 -> {79};
subgraph cluster_20 {
color=red
80 [label="Enter function test_4" style="filled" fillcolor=red];
subgraph cluster_21 {
color=blue
81 [label="Enter block"];
subgraph cluster_22 {
color=blue
82 [label="Enter do-while loop"];
subgraph cluster_23 {
color=blue
83 [label="Enter loop block"];
subgraph cluster_24 {
color=blue
84 [label="Enter block"];
85 [label="Access variable R|<local>/x|"];
86 [label="Type operator: (R|<local>/x| as R|kotlin/Int|)"];
87 [label="Jump: break@@@[Boolean(true)] "];
88 [label="Stub" style="filled" fillcolor=gray];
89 [label="Exit block" style="filled" fillcolor=gray];
}
90 [label="Exit loop block" style="filled" fillcolor=gray];
}
subgraph cluster_25 {
color=blue
91 [label="Enter loop condition" style="filled" fillcolor=gray];
92 [label="Const: Boolean(true)" style="filled" fillcolor=gray];
93 [label="Exit loop condition" style="filled" fillcolor=gray];
}
94 [label="Exit do-while loop"];
}
95 [label="Access variable R|<local>/x|"];
96 [label="Smart cast: R|<local>/x|"];
97 [label="Function call: R|<local>/x|.R|kotlin/Int.inc|()" style="filled" fillcolor=yellow];
98 [label="Exit block"];
}
99 [label="Exit function test_4" style="filled" fillcolor=red];
}
79 -> {80};
80 -> {81};
81 -> {82};
subgraph cluster_21 {
color=red
82 [label="Enter function test_4" style="filled" fillcolor=red];
subgraph cluster_22 {
color=blue
83 [label="Enter block"];
subgraph cluster_23 {
color=blue
84 [label="Enter do-while loop"];
subgraph cluster_24 {
color=blue
85 [label="Enter loop block"];
subgraph cluster_25 {
color=blue
86 [label="Enter block"];
87 [label="Access variable R|<local>/x|"];
88 [label="Type operator: (R|<local>/x| as R|kotlin/Int|)"];
89 [label="Jump: break@@@[Boolean(true)] "];
90 [label="Stub" style="filled" fillcolor=gray];
91 [label="Exit block" style="filled" fillcolor=gray];
}
92 [label="Exit loop block" style="filled" fillcolor=gray];
}
subgraph cluster_26 {
color=blue
93 [label="Enter loop condition" style="filled" fillcolor=gray];
94 [label="Const: Boolean(true)" style="filled" fillcolor=gray];
95 [label="Exit loop condition" style="filled" fillcolor=gray];
}
96 [label="Exit do-while loop"];
}
97 [label="Access variable R|<local>/x|"];
98 [label="Smart cast: R|<local>/x|"];
99 [label="Function call: R|<local>/x|.R|kotlin/Int.inc|()" style="filled" fillcolor=yellow];
100 [label="Exit block"];
}
101 [label="Exit function test_4" style="filled" fillcolor=red];
}
82 -> {83};
83 -> {84};
84 -> {85};
85 -> {86};
86 -> {87};
87 -> {94};
87 -> {88} [style=dotted];
88 -> {89} [style=dotted];
87 -> {88};
88 -> {89};
89 -> {96};
89 -> {90} [style=dotted];
90 -> {91} [style=dotted];
91 -> {92} [style=dotted];
92 -> {93} [style=dotted];
93 -> {83} [color=green style=dotted];
93 -> {94} [style=dotted];
94 -> {95};
95 -> {96};
94 -> {95} [style=dotted];
95 -> {85} [color=green style=dotted];
95 -> {96} [style=dotted];
96 -> {97};
97 -> {98};
98 -> {99};
99 -> {100};
100 -> {101};
subgraph cluster_26 {
subgraph cluster_27 {
color=red
100 [label="Enter function test_5" style="filled" fillcolor=red];
subgraph cluster_27 {
102 [label="Enter function test_5" style="filled" fillcolor=red];
subgraph cluster_28 {
color=blue
101 [label="Enter block"];
subgraph cluster_28 {
103 [label="Enter block"];
subgraph cluster_29 {
color=blue
102 [label="Enter while loop"];
subgraph cluster_29 {
color=blue
103 [label="Enter loop condition"];
104 [label="Access variable R|<local>/b|"];
105 [label="Exit loop condition"];
}
104 [label="Enter while loop"];
subgraph cluster_30 {
color=blue
106 [label="Enter loop block"];
subgraph cluster_31 {
105 [label="Enter loop condition"];
106 [label="Access variable R|<local>/b|"];
107 [label="Exit loop condition"];
}
subgraph cluster_31 {
color=blue
108 [label="Enter loop block"];
subgraph cluster_32 {
color=blue
107 [label="Enter block"];
subgraph cluster_32 {
109 [label="Enter block"];
subgraph cluster_33 {
color=blue
108 [label="Enter when"];
subgraph cluster_33 {
color=blue
109 [label="Enter when branch condition "];
110 [label="Access variable R|<local>/b|"];
111 [label="Exit when branch condition"];
}
112 [label="Synthetic else branch"];
113 [label="Enter when branch result"];
110 [label="Enter when"];
subgraph cluster_34 {
color=blue
114 [label="Enter block"];
115 [label="Jump: continue@@@[R|<local>/b|] "];
116 [label="Stub" style="filled" fillcolor=gray];
117 [label="Exit block" style="filled" fillcolor=gray];
111 [label="Enter when branch condition "];
112 [label="Access variable R|<local>/b|"];
113 [label="Exit when branch condition"];
}
118 [label="Exit when branch result" style="filled" fillcolor=gray];
119 [label="Exit when"];
114 [label="Synthetic else branch"];
115 [label="Enter when branch result"];
subgraph cluster_35 {
color=blue
116 [label="Enter block"];
117 [label="Jump: continue@@@[R|<local>/b|] "];
118 [label="Stub" style="filled" fillcolor=gray];
119 [label="Exit block" style="filled" fillcolor=gray];
}
120 [label="Exit when branch result" style="filled" fillcolor=gray];
121 [label="Exit when"];
}
120 [label="Exit block"];
122 [label="Exit block"];
}
121 [label="Exit loop block"];
123 [label="Exit loop block"];
}
122 [label="Exit while loop"];
124 [label="Exit while loop"];
}
123 [label="Exit block"];
125 [label="Exit block"];
}
124 [label="Exit function test_5" style="filled" fillcolor=red];
126 [label="Exit function test_5" style="filled" fillcolor=red];
}
100 -> {101};
101 -> {102};
102 -> {103};
103 -> {104};
104 -> {105};
105 -> {106 122};
105 -> {106};
106 -> {107};
107 -> {108};
107 -> {108 124};
108 -> {109};
109 -> {110};
110 -> {111};
111 -> {112 113};
112 -> {119};
113 -> {114};
114 -> {115};
115 -> {103} [color=green style=dashed];
115 -> {116} [style=dotted];
116 -> {117} [style=dotted];
111 -> {112};
112 -> {113};
113 -> {114 115};
114 -> {121};
115 -> {116};
116 -> {117};
117 -> {105} [color=green style=dashed];
117 -> {118} [style=dotted];
118 -> {119} [style=dotted];
119 -> {120};
120 -> {121};
121 -> {103} [color=green style=dashed];
119 -> {120} [style=dotted];
120 -> {121} [style=dotted];
121 -> {122};
122 -> {123};
123 -> {124};
subgraph cluster_35 {
color=red
125 [label="Enter function run" style="filled" fillcolor=red];
subgraph cluster_36 {
color=blue
126 [label="Enter block"];
127 [label="Function call: R|<local>/block|.R|SubstitutionOverride<kotlin/Function0.invoke: R|kotlin/Unit|>|()" style="filled" fillcolor=yellow];
128 [label="Exit block"];
}
129 [label="Exit function run" style="filled" fillcolor=red];
}
123 -> {105} [color=green style=dashed];
124 -> {125};
125 -> {126};
126 -> {127};
subgraph cluster_36 {
color=red
127 [label="Enter function run" style="filled" fillcolor=red];
subgraph cluster_37 {
color=blue
128 [label="Enter block"];
129 [label="Function call: R|<local>/block|.R|SubstitutionOverride<kotlin/Function0.invoke: R|kotlin/Unit|>|()" style="filled" fillcolor=yellow];
130 [label="Exit block"];
}
131 [label="Exit function run" style="filled" fillcolor=red];
}
127 -> {128};
128 -> {129};
subgraph cluster_37 {
color=red
130 [label="Enter function test_6" style="filled" fillcolor=red];
subgraph cluster_38 {
color=blue
131 [label="Enter block"];
132 [label="Postponed enter to lambda"];
subgraph cluster_39 {
color=blue
133 [label="Enter function <anonymous>" style="filled" fillcolor=red];
subgraph cluster_40 {
color=blue
134 [label="Enter block"];
135 [label="Jump: ^@run Unit"];
136 [label="Stub" style="filled" fillcolor=gray];
137 [label="Exit block" style="filled" fillcolor=gray];
}
138 [label="Exit function <anonymous>" style="filled" fillcolor=red];
}
139 [label="Postponed exit from lambda"];
140 [label="Function call: R|/run|(...)" style="filled" fillcolor=yellow];
141 [label="Exit block"];
}
142 [label="Exit function test_6" style="filled" fillcolor=red];
}
129 -> {130};
130 -> {131};
131 -> {132};
132 -> {133 139 140};
132 -> {133} [style=dashed];
subgraph cluster_38 {
color=red
132 [label="Enter function test_6" style="filled" fillcolor=red];
subgraph cluster_39 {
color=blue
133 [label="Enter block"];
134 [label="Postponed enter to lambda"];
subgraph cluster_40 {
color=blue
135 [label="Enter function <anonymous>" style="filled" fillcolor=red];
subgraph cluster_41 {
color=blue
136 [label="Enter block"];
137 [label="Jump: ^@run Unit"];
138 [label="Stub" style="filled" fillcolor=gray];
139 [label="Exit block" style="filled" fillcolor=gray];
}
140 [label="Exit function <anonymous>" style="filled" fillcolor=red];
}
141 [label="Postponed exit from lambda"];
142 [label="Function call: R|/run|(...)" style="filled" fillcolor=yellow];
143 [label="Exit block"];
}
144 [label="Exit function test_6" style="filled" fillcolor=red];
}
132 -> {133};
133 -> {134};
134 -> {135};
135 -> {138};
135 -> {136} [style=dotted];
136 -> {137} [style=dotted];
134 -> {135 141 142};
134 -> {135} [style=dashed];
135 -> {136};
136 -> {137};
137 -> {140};
137 -> {138} [style=dotted];
138 -> {139};
139 -> {140};
139 -> {132} [color=green style=dashed];
138 -> {139} [style=dotted];
139 -> {140} [style=dotted];
140 -> {141};
141 -> {142};
141 -> {134} [color=green style=dashed];
142 -> {143};
143 -> {144};
}