[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,40 +5,45 @@ digraph callsInPlace_kt {
subgraph cluster_0 {
color=red
0 [label="Enter function test" style="filled" fillcolor=red];
subgraph cluster_1 {
color=blue
1 [label="Enter block"];
2 [label="Variable declaration: lval x: R|kotlin/Int|"];
3 [label="Postponed enter to lambda"];
subgraph cluster_2 {
color=blue
4 [label="Enter function <anonymous>" style="filled" fillcolor=red];
subgraph cluster_3 {
color=blue
5 [label="Enter block"];
6 [label="Const: Int(1)"];
7 [label="Assignment: R|<local>/x|"];
8 [label="Exit block"];
}
9 [label="Exit function <anonymous>" style="filled" fillcolor=red];
}
10 [label="Postponed exit from lambda"];
11 [label="Function call: R|kotlin/run|<R|kotlin/Unit|>(...)" style="filled" fillcolor=yellow];
12 [label="Access variable R|<local>/x|"];
13 [label="Function call: R|<local>/x|.R|kotlin/Int.inc|()" style="filled" fillcolor=yellow];
14 [label="Exit block"];
}
15 [label="Exit function test" style="filled" fillcolor=red];
0 [label="Enter file callsInPlace.kt" style="filled" fillcolor=red];
1 [label="Exit file callsInPlace.kt" style="filled" fillcolor=red];
}
0 -> {1} [color=green];
subgraph cluster_1 {
color=red
2 [label="Enter function test" style="filled" fillcolor=red];
subgraph cluster_2 {
color=blue
3 [label="Enter block"];
4 [label="Variable declaration: lval x: R|kotlin/Int|"];
5 [label="Postponed enter to lambda"];
subgraph cluster_3 {
color=blue
6 [label="Enter function <anonymous>" style="filled" fillcolor=red];
subgraph cluster_4 {
color=blue
7 [label="Enter block"];
8 [label="Const: Int(1)"];
9 [label="Assignment: R|<local>/x|"];
10 [label="Exit block"];
}
11 [label="Exit function <anonymous>" style="filled" fillcolor=red];
}
12 [label="Postponed exit from lambda"];
13 [label="Function call: R|kotlin/run|<R|kotlin/Unit|>(...)" style="filled" fillcolor=yellow];
14 [label="Access variable R|<local>/x|"];
15 [label="Function call: R|<local>/x|.R|kotlin/Int.inc|()" style="filled" fillcolor=yellow];
16 [label="Exit block"];
}
17 [label="Exit function test" style="filled" fillcolor=red];
}
0 -> {1};
1 -> {2};
2 -> {3};
3 -> {4 11};
3 -> {10} [style=dotted];
3 -> {4} [style=dashed];
3 -> {4};
4 -> {5};
5 -> {6};
5 -> {6 13};
5 -> {12} [style=dotted];
5 -> {6} [style=dashed];
6 -> {7};
7 -> {8};
8 -> {9};
@@ -48,124 +53,124 @@ digraph callsInPlace_kt {
12 -> {13};
13 -> {14};
14 -> {15};
subgraph cluster_4 {
color=red
16 [label="Enter function test_2" style="filled" fillcolor=red];
subgraph cluster_5 {
color=blue
17 [label="Enter block"];
18 [label="Const: Int(10)"];
19 [label="Postponed enter to lambda"];
subgraph cluster_6 {
color=blue
20 [label="Enter function <anonymous>" style="filled" fillcolor=red];
subgraph cluster_7 {
color=blue
21 [label="Enter block"];
22 [label="Const: String(test_2)"];
23 [label="Exit block"];
}
24 [label="Exit function <anonymous>" style="filled" fillcolor=red];
}
25 [label="Postponed exit from lambda"];
26 [label="Function call: R|kotlin/repeat|(...)" style="filled" fillcolor=yellow];
27 [label="Exit block"];
}
28 [label="Exit function test_2" style="filled" fillcolor=red];
}
15 -> {16};
16 -> {17};
17 -> {18};
subgraph cluster_5 {
color=red
18 [label="Enter function test_2" style="filled" fillcolor=red];
subgraph cluster_6 {
color=blue
19 [label="Enter block"];
20 [label="Const: Int(10)"];
21 [label="Postponed enter to lambda"];
subgraph cluster_7 {
color=blue
22 [label="Enter function <anonymous>" style="filled" fillcolor=red];
subgraph cluster_8 {
color=blue
23 [label="Enter block"];
24 [label="Const: String(test_2)"];
25 [label="Exit block"];
}
26 [label="Exit function <anonymous>" style="filled" fillcolor=red];
}
27 [label="Postponed exit from lambda"];
28 [label="Function call: R|kotlin/repeat|(...)" style="filled" fillcolor=yellow];
29 [label="Exit block"];
}
30 [label="Exit function test_2" style="filled" fillcolor=red];
}
18 -> {19};
19 -> {20 25 26};
19 -> {20} [style=dashed];
19 -> {20};
20 -> {21};
21 -> {22};
21 -> {22 27 28};
21 -> {22} [style=dashed];
22 -> {23};
23 -> {24};
24 -> {25};
25 -> {26};
25 -> {19} [color=green style=dashed];
26 -> {27};
27 -> {28};
subgraph cluster_8 {
color=red
29 [label="Enter function test_3" style="filled" fillcolor=red];
subgraph cluster_9 {
color=blue
30 [label="Enter block"];
31 [label="Const: Int(10)"];
32 [label="Postponed enter to lambda"];
subgraph cluster_10 {
color=blue
33 [label="Enter function <anonymous>" style="filled" fillcolor=red];
subgraph cluster_11 {
color=blue
34 [label="Enter block"];
35 [label="Const: String(test_3)"];
36 [label="Exit block"];
}
37 [label="Exit function <anonymous>" style="filled" fillcolor=red];
}
38 [label="Postponed exit from lambda"];
39 [label="Function call: R|kotlin/repeat|(...)" style="filled" fillcolor=yellow];
40 [label="Exit block"];
}
41 [label="Exit function test_3" style="filled" fillcolor=red];
}
27 -> {21} [color=green style=dashed];
28 -> {29};
29 -> {30};
30 -> {31};
subgraph cluster_9 {
color=red
31 [label="Enter function test_3" style="filled" fillcolor=red];
subgraph cluster_10 {
color=blue
32 [label="Enter block"];
33 [label="Const: Int(10)"];
34 [label="Postponed enter to lambda"];
subgraph cluster_11 {
color=blue
35 [label="Enter function <anonymous>" style="filled" fillcolor=red];
subgraph cluster_12 {
color=blue
36 [label="Enter block"];
37 [label="Const: String(test_3)"];
38 [label="Exit block"];
}
39 [label="Exit function <anonymous>" style="filled" fillcolor=red];
}
40 [label="Postponed exit from lambda"];
41 [label="Function call: R|kotlin/repeat|(...)" style="filled" fillcolor=yellow];
42 [label="Exit block"];
}
43 [label="Exit function test_3" style="filled" fillcolor=red];
}
31 -> {32};
32 -> {33 38 39};
32 -> {33} [style=dashed];
32 -> {33};
33 -> {34};
34 -> {35};
34 -> {35 40 41};
34 -> {35} [style=dashed];
35 -> {36};
36 -> {37};
37 -> {38};
38 -> {39};
38 -> {32} [color=green style=dashed];
39 -> {40};
40 -> {41};
subgraph cluster_12 {
color=red
42 [label="Enter function test_4" style="filled" fillcolor=red];
subgraph cluster_13 {
color=blue
43 [label="Enter block"];
44 [label="Const: Int(1)"];
45 [label="Postponed enter to lambda"];
subgraph cluster_14 {
color=blue
46 [label="Enter function <anonymous>" style="filled" fillcolor=red];
subgraph cluster_15 {
color=blue
47 [label="Enter block"];
48 [label="Const: String(test_4)"];
49 [label="Access variable R|<local>/it|"];
50 [label="Const: Int(0)"];
51 [label="Function call: R|<local>/it|.R|kotlin/Int.compareTo|(...)" style="filled" fillcolor=yellow];
52 [label="Comparison >"];
53 [label="Exit block"];
}
54 [label="Exit function <anonymous>" style="filled" fillcolor=red];
}
55 [label="Postponed exit from lambda"];
56 [label="Function call: Int(1).R|kotlin/takeUnless|<R|kotlin/Int|>(...)" style="filled" fillcolor=yellow];
57 [label="Exit block"];
}
58 [label="Exit function test_4" style="filled" fillcolor=red];
}
40 -> {34} [color=green style=dashed];
41 -> {42};
42 -> {43};
43 -> {44};
subgraph cluster_13 {
color=red
44 [label="Enter function test_4" style="filled" fillcolor=red];
subgraph cluster_14 {
color=blue
45 [label="Enter block"];
46 [label="Const: Int(1)"];
47 [label="Postponed enter to lambda"];
subgraph cluster_15 {
color=blue
48 [label="Enter function <anonymous>" style="filled" fillcolor=red];
subgraph cluster_16 {
color=blue
49 [label="Enter block"];
50 [label="Const: String(test_4)"];
51 [label="Access variable R|<local>/it|"];
52 [label="Const: Int(0)"];
53 [label="Function call: R|<local>/it|.R|kotlin/Int.compareTo|(...)" style="filled" fillcolor=yellow];
54 [label="Comparison >"];
55 [label="Exit block"];
}
56 [label="Exit function <anonymous>" style="filled" fillcolor=red];
}
57 [label="Postponed exit from lambda"];
58 [label="Function call: Int(1).R|kotlin/takeUnless|<R|kotlin/Int|>(...)" style="filled" fillcolor=yellow];
59 [label="Exit block"];
}
60 [label="Exit function test_4" style="filled" fillcolor=red];
}
44 -> {45};
45 -> {46 56};
45 -> {55} [style=dotted];
45 -> {46} [style=dashed];
45 -> {46};
46 -> {47};
47 -> {48};
47 -> {48 58};
47 -> {57} [style=dotted];
47 -> {48} [style=dashed];
48 -> {49};
49 -> {50};
50 -> {51};
@@ -176,44 +181,44 @@ digraph callsInPlace_kt {
55 -> {56};
56 -> {57};
57 -> {58};
subgraph cluster_16 {
color=red
59 [label="Enter function test_5" style="filled" fillcolor=red];
subgraph cluster_17 {
color=blue
60 [label="Enter block"];
61 [label="Const: Int(1)"];
62 [label="Postponed enter to lambda"];
subgraph cluster_18 {
color=blue
63 [label="Enter function <anonymous>" style="filled" fillcolor=red];
subgraph cluster_19 {
color=blue
64 [label="Enter block"];
65 [label="Const: String(test_5)"];
66 [label="Access variable R|<local>/it|"];
67 [label="Const: Int(0)"];
68 [label="Function call: R|<local>/it|.R|kotlin/Int.compareTo|(...)" style="filled" fillcolor=yellow];
69 [label="Comparison >"];
70 [label="Exit block"];
}
71 [label="Exit function <anonymous>" style="filled" fillcolor=red];
}
72 [label="Postponed exit from lambda"];
73 [label="Function call: Int(1).R|kotlin/takeUnless|<R|kotlin/Int|>(...)" style="filled" fillcolor=yellow];
74 [label="Exit block"];
}
75 [label="Exit function test_5" style="filled" fillcolor=red];
}
58 -> {59};
59 -> {60};
60 -> {61};
subgraph cluster_17 {
color=red
61 [label="Enter function test_5" style="filled" fillcolor=red];
subgraph cluster_18 {
color=blue
62 [label="Enter block"];
63 [label="Const: Int(1)"];
64 [label="Postponed enter to lambda"];
subgraph cluster_19 {
color=blue
65 [label="Enter function <anonymous>" style="filled" fillcolor=red];
subgraph cluster_20 {
color=blue
66 [label="Enter block"];
67 [label="Const: String(test_5)"];
68 [label="Access variable R|<local>/it|"];
69 [label="Const: Int(0)"];
70 [label="Function call: R|<local>/it|.R|kotlin/Int.compareTo|(...)" style="filled" fillcolor=yellow];
71 [label="Comparison >"];
72 [label="Exit block"];
}
73 [label="Exit function <anonymous>" style="filled" fillcolor=red];
}
74 [label="Postponed exit from lambda"];
75 [label="Function call: Int(1).R|kotlin/takeUnless|<R|kotlin/Int|>(...)" style="filled" fillcolor=yellow];
76 [label="Exit block"];
}
77 [label="Exit function test_5" style="filled" fillcolor=red];
}
61 -> {62};
62 -> {63 73};
62 -> {72} [style=dotted];
62 -> {63} [style=dashed];
62 -> {63};
63 -> {64};
64 -> {65};
64 -> {65 75};
64 -> {74} [style=dotted];
64 -> {65} [style=dashed];
65 -> {66};
66 -> {67};
67 -> {68};
@@ -224,189 +229,191 @@ digraph callsInPlace_kt {
72 -> {73};
73 -> {74};
74 -> {75};
subgraph cluster_20 {
color=red
76 [label="Enter function myRun" style="filled" fillcolor=red];
subgraph cluster_21 {
color=blue
77 [label="Enter block"];
78 [label="Function call: R|<local>/block1|.R|SubstitutionOverride<kotlin/Function0.invoke: R|kotlin/Unit|>|()" style="filled" fillcolor=yellow];
79 [label="Function call: R|<local>/block2|.R|SubstitutionOverride<kotlin/Function0.invoke: R|kotlin/Unit|>|()" style="filled" fillcolor=yellow];
80 [label="Exit block"];
}
81 [label="Exit function myRun" style="filled" fillcolor=red];
}
75 -> {76};
76 -> {77};
77 -> {78};
subgraph cluster_21 {
color=red
78 [label="Enter function myRun" style="filled" fillcolor=red];
subgraph cluster_22 {
color=blue
79 [label="Enter block"];
80 [label="Function call: R|<local>/block1|.R|SubstitutionOverride<kotlin/Function0.invoke: R|kotlin/Unit|>|()" style="filled" fillcolor=yellow];
81 [label="Function call: R|<local>/block2|.R|SubstitutionOverride<kotlin/Function0.invoke: R|kotlin/Unit|>|()" style="filled" fillcolor=yellow];
82 [label="Exit block"];
}
83 [label="Exit function myRun" style="filled" fillcolor=red];
}
78 -> {79};
79 -> {80};
80 -> {81};
subgraph cluster_22 {
color=red
82 [label="Enter function test_6" style="filled" fillcolor=red];
subgraph cluster_23 {
color=blue
83 [label="Enter block"];
84 [label="Postponed enter to lambda"];
subgraph cluster_24 {
color=blue
85 [label="Enter function <anonymous>" style="filled" fillcolor=red];
subgraph cluster_25 {
color=blue
86 [label="Enter block"];
87 [label="Const: String(test_6_2)"];
88 [label="Exit block"];
}
89 [label="Exit function <anonymous>" style="filled" fillcolor=red];
}
subgraph cluster_26 {
color=blue
90 [label="Enter function <anonymous>" style="filled" fillcolor=red];
subgraph cluster_27 {
color=blue
91 [label="Enter block"];
92 [label="Const: String(test_6_1)"];
93 [label="Exit block"];
}
94 [label="Exit function <anonymous>" style="filled" fillcolor=red];
}
95 [label="Postponed exit from lambda"];
96 [label="Postponed exit from lambda"];
97 [label="Function call: R|/myRun|(...)" style="filled" fillcolor=yellow];
98 [label="Exit block"];
}
99 [label="Exit function test_6" style="filled" fillcolor=red];
}
81 -> {82};
82 -> {83};
83 -> {84};
84 -> {85 90 95 96 97};
84 -> {85 90} [style=dashed];
subgraph cluster_23 {
color=red
84 [label="Enter function test_6" style="filled" fillcolor=red];
subgraph cluster_24 {
color=blue
85 [label="Enter block"];
86 [label="Postponed enter to lambda"];
subgraph cluster_25 {
color=blue
87 [label="Enter function <anonymous>" style="filled" fillcolor=red];
subgraph cluster_26 {
color=blue
88 [label="Enter block"];
89 [label="Const: String(test_6_2)"];
90 [label="Exit block"];
}
91 [label="Exit function <anonymous>" style="filled" fillcolor=red];
}
subgraph cluster_27 {
color=blue
92 [label="Enter function <anonymous>" style="filled" fillcolor=red];
subgraph cluster_28 {
color=blue
93 [label="Enter block"];
94 [label="Const: String(test_6_1)"];
95 [label="Exit block"];
}
96 [label="Exit function <anonymous>" style="filled" fillcolor=red];
}
97 [label="Postponed exit from lambda"];
98 [label="Postponed exit from lambda"];
99 [label="Function call: R|/myRun|(...)" style="filled" fillcolor=yellow];
100 [label="Exit block"];
}
101 [label="Exit function test_6" style="filled" fillcolor=red];
}
84 -> {85};
85 -> {86};
86 -> {87};
86 -> {87 92 97 98 99};
86 -> {87 92} [style=dashed];
87 -> {88};
88 -> {89};
89 -> {95};
89 -> {90};
90 -> {91};
91 -> {92};
91 -> {97};
92 -> {93};
93 -> {94};
94 -> {96};
95 -> {97};
95 -> {84} [color=green style=dashed];
96 -> {97};
96 -> {84} [color=green style=dashed];
97 -> {98};
94 -> {95};
95 -> {96};
96 -> {98};
97 -> {99};
97 -> {86} [color=green style=dashed];
98 -> {99};
subgraph cluster_28 {
color=red
100 [label="Enter function test_7" style="filled" fillcolor=red];
subgraph cluster_29 {
color=blue
101 [label="Enter block"];
102 [label="Postponed enter to lambda"];
subgraph cluster_30 {
color=blue
103 [label="Enter function <anonymous>" style="filled" fillcolor=red];
subgraph cluster_31 {
color=blue
104 [label="Enter block"];
105 [label="Const: String(test_7_1)"];
106 [label="Exit block"];
}
107 [label="Exit function <anonymous>" style="filled" fillcolor=red];
}
subgraph cluster_32 {
color=blue
108 [label="Enter function <anonymous>" style="filled" fillcolor=red];
subgraph cluster_33 {
color=blue
109 [label="Enter block"];
110 [label="Const: String(test_7_2)"];
111 [label="Exit block"];
}
112 [label="Exit function <anonymous>" style="filled" fillcolor=red];
}
113 [label="Postponed exit from lambda"];
114 [label="Postponed exit from lambda"];
115 [label="Function call: R|/myRun|(...)" style="filled" fillcolor=yellow];
116 [label="Exit block"];
}
117 [label="Exit function test_7" style="filled" fillcolor=red];
}
98 -> {86} [color=green style=dashed];
99 -> {100};
100 -> {101};
101 -> {102};
102 -> {103 108 113 114 115};
102 -> {103 108} [style=dashed];
subgraph cluster_29 {
color=red
102 [label="Enter function test_7" style="filled" fillcolor=red];
subgraph cluster_30 {
color=blue
103 [label="Enter block"];
104 [label="Postponed enter to lambda"];
subgraph cluster_31 {
color=blue
105 [label="Enter function <anonymous>" style="filled" fillcolor=red];
subgraph cluster_32 {
color=blue
106 [label="Enter block"];
107 [label="Const: String(test_7_1)"];
108 [label="Exit block"];
}
109 [label="Exit function <anonymous>" style="filled" fillcolor=red];
}
subgraph cluster_33 {
color=blue
110 [label="Enter function <anonymous>" style="filled" fillcolor=red];
subgraph cluster_34 {
color=blue
111 [label="Enter block"];
112 [label="Const: String(test_7_2)"];
113 [label="Exit block"];
}
114 [label="Exit function <anonymous>" style="filled" fillcolor=red];
}
115 [label="Postponed exit from lambda"];
116 [label="Postponed exit from lambda"];
117 [label="Function call: R|/myRun|(...)" style="filled" fillcolor=yellow];
118 [label="Exit block"];
}
119 [label="Exit function test_7" style="filled" fillcolor=red];
}
102 -> {103};
103 -> {104};
104 -> {105};
104 -> {105 110 115 116 117};
104 -> {105 110} [style=dashed];
105 -> {106};
106 -> {107};
107 -> {113};
107 -> {108};
108 -> {109};
109 -> {110};
109 -> {115};
110 -> {111};
111 -> {112};
112 -> {114};
113 -> {115};
113 -> {102} [color=green style=dashed];
114 -> {115};
114 -> {102} [color=green style=dashed];
115 -> {116};
112 -> {113};
113 -> {114};
114 -> {116};
115 -> {117};
115 -> {104} [color=green style=dashed];
116 -> {117};
subgraph cluster_34 {
color=red
118 [label="Enter function myDummyRun" style="filled" fillcolor=red];
subgraph cluster_35 {
color=blue
119 [label="Enter block"];
120 [label="Function call: R|<local>/block|.R|SubstitutionOverride<kotlin/Function0.invoke: R|kotlin/Unit|>|()" style="filled" fillcolor=yellow];
121 [label="Exit block"];
}
122 [label="Exit function myDummyRun" style="filled" fillcolor=red];
}
116 -> {104} [color=green style=dashed];
117 -> {118};
118 -> {119};
119 -> {120};
subgraph cluster_35 {
color=red
120 [label="Enter function myDummyRun" style="filled" fillcolor=red];
subgraph cluster_36 {
color=blue
121 [label="Enter block"];
122 [label="Function call: R|<local>/block|.R|SubstitutionOverride<kotlin/Function0.invoke: R|kotlin/Unit|>|()" style="filled" fillcolor=yellow];
123 [label="Exit block"];
}
124 [label="Exit function myDummyRun" style="filled" fillcolor=red];
}
120 -> {121};
121 -> {122};
subgraph cluster_36 {
color=red
123 [label="Enter function test_8" style="filled" fillcolor=red];
subgraph cluster_37 {
color=blue
124 [label="Enter block"];
125 [label="Postponed enter to lambda"];
subgraph cluster_38 {
color=blue
126 [label="Enter function <anonymous>" style="filled" fillcolor=red];
subgraph cluster_39 {
color=blue
127 [label="Enter block"];
128 [label="Const: String(test_8)"];
129 [label="Exit block"];
}
130 [label="Exit function <anonymous>" style="filled" fillcolor=red];
}
131 [label="Postponed exit from lambda"];
132 [label="Function call: R|/myDummyRun|(...)" style="filled" fillcolor=yellow];
133 [label="Exit block"];
}
134 [label="Exit function test_8" style="filled" fillcolor=red];
}
122 -> {123};
123 -> {124};
124 -> {125};
125 -> {126 131 132};
125 -> {126} [style=dashed];
subgraph cluster_37 {
color=red
125 [label="Enter function test_8" style="filled" fillcolor=red];
subgraph cluster_38 {
color=blue
126 [label="Enter block"];
127 [label="Postponed enter to lambda"];
subgraph cluster_39 {
color=blue
128 [label="Enter function <anonymous>" style="filled" fillcolor=red];
subgraph cluster_40 {
color=blue
129 [label="Enter block"];
130 [label="Const: String(test_8)"];
131 [label="Exit block"];
}
132 [label="Exit function <anonymous>" style="filled" fillcolor=red];
}
133 [label="Postponed exit from lambda"];
134 [label="Function call: R|/myDummyRun|(...)" style="filled" fillcolor=yellow];
135 [label="Exit block"];
}
136 [label="Exit function test_8" style="filled" fillcolor=red];
}
125 -> {126};
126 -> {127};
127 -> {128};
127 -> {128 133 134};
127 -> {128} [style=dashed];
128 -> {129};
129 -> {130};
130 -> {131};
131 -> {132};
132 -> {133};
133 -> {134};
134 -> {135};
135 -> {136};
}