[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,331 +5,336 @@ digraph flowFromInplaceLambda3_kt {
subgraph cluster_0 {
color=red
0 [label="Enter function unknown" style="filled" fillcolor=red];
subgraph cluster_1 {
color=blue
1 [label="Enter block"];
subgraph cluster_2 {
color=blue
2 [label="Enter block"];
3 [label="Exit block"];
}
4 [label="Function call: R|<local>/x|.R|SubstitutionOverride<kotlin/Function0.invoke: R|kotlin/Unit|>|()" style="filled" fillcolor=yellow];
5 [label="Exit block"];
}
6 [label="Exit function unknown" style="filled" fillcolor=red];
0 [label="Enter file flowFromInplaceLambda3.kt" style="filled" fillcolor=red];
1 [label="Exit file flowFromInplaceLambda3.kt" style="filled" fillcolor=red];
}
0 -> {1} [color=green];
subgraph cluster_1 {
color=red
2 [label="Enter function unknown" style="filled" fillcolor=red];
subgraph cluster_2 {
color=blue
3 [label="Enter block"];
subgraph cluster_3 {
color=blue
4 [label="Enter block"];
5 [label="Exit block"];
}
6 [label="Function call: R|<local>/x|.R|SubstitutionOverride<kotlin/Function0.invoke: R|kotlin/Unit|>|()" style="filled" fillcolor=yellow];
7 [label="Exit block"];
}
8 [label="Exit function unknown" style="filled" fillcolor=red];
}
0 -> {1};
1 -> {2};
2 -> {3};
3 -> {4};
4 -> {5};
5 -> {6};
subgraph cluster_3 {
color=red
7 [label="Enter function atLeastOnce" style="filled" fillcolor=red];
subgraph cluster_4 {
color=blue
8 [label="Enter block"];
subgraph cluster_5 {
color=blue
9 [label="Enter block"];
10 [label="Exit block"];
}
11 [label="Function call: R|<local>/x|.R|SubstitutionOverride<kotlin/Function0.invoke: R|kotlin/Unit|>|()" style="filled" fillcolor=yellow];
12 [label="Exit block"];
}
13 [label="Exit function atLeastOnce" style="filled" fillcolor=red];
}
6 -> {7};
7 -> {8};
8 -> {9};
subgraph cluster_4 {
color=red
9 [label="Enter function atLeastOnce" style="filled" fillcolor=red];
subgraph cluster_5 {
color=blue
10 [label="Enter block"];
subgraph cluster_6 {
color=blue
11 [label="Enter block"];
12 [label="Exit block"];
}
13 [label="Function call: R|<local>/x|.R|SubstitutionOverride<kotlin/Function0.invoke: R|kotlin/Unit|>|()" style="filled" fillcolor=yellow];
14 [label="Exit block"];
}
15 [label="Exit function atLeastOnce" style="filled" fillcolor=red];
}
9 -> {10};
10 -> {11};
11 -> {12};
12 -> {13};
subgraph cluster_6 {
color=red
14 [label="Enter function exactlyOnce" style="filled" fillcolor=red];
subgraph cluster_7 {
color=blue
15 [label="Enter block"];
subgraph cluster_8 {
color=blue
16 [label="Enter block"];
17 [label="Exit block"];
}
18 [label="Function call: R|<local>/x|.R|SubstitutionOverride<kotlin/Function0.invoke: R|kotlin/Unit|>|()" style="filled" fillcolor=yellow];
19 [label="Exit block"];
}
20 [label="Exit function exactlyOnce" style="filled" fillcolor=red];
}
13 -> {14};
14 -> {15};
15 -> {16};
subgraph cluster_7 {
color=red
16 [label="Enter function exactlyOnce" style="filled" fillcolor=red];
subgraph cluster_8 {
color=blue
17 [label="Enter block"];
subgraph cluster_9 {
color=blue
18 [label="Enter block"];
19 [label="Exit block"];
}
20 [label="Function call: R|<local>/x|.R|SubstitutionOverride<kotlin/Function0.invoke: R|kotlin/Unit|>|()" style="filled" fillcolor=yellow];
21 [label="Exit block"];
}
22 [label="Exit function exactlyOnce" style="filled" fillcolor=red];
}
16 -> {17};
17 -> {18};
18 -> {19};
19 -> {20};
subgraph cluster_9 {
color=red
21 [label="Enter function atMostOnce" style="filled" fillcolor=red];
subgraph cluster_10 {
color=blue
22 [label="Enter block"];
subgraph cluster_11 {
color=blue
23 [label="Enter block"];
24 [label="Exit block"];
}
25 [label="Exit block"];
}
26 [label="Exit function atMostOnce" style="filled" fillcolor=red];
}
20 -> {21};
21 -> {22};
22 -> {23};
subgraph cluster_10 {
color=red
23 [label="Enter function atMostOnce" style="filled" fillcolor=red];
subgraph cluster_11 {
color=blue
24 [label="Enter block"];
subgraph cluster_12 {
color=blue
25 [label="Enter block"];
26 [label="Exit block"];
}
27 [label="Exit block"];
}
28 [label="Exit function atMostOnce" style="filled" fillcolor=red];
}
23 -> {24};
24 -> {25};
25 -> {26};
subgraph cluster_12 {
color=red
27 [label="Enter function test1" style="filled" fillcolor=red];
subgraph cluster_13 {
color=blue
28 [label="Enter block"];
29 [label="Variable declaration: lvar x: R|kotlin/Any?|"];
30 [label="Const: String()"];
31 [label="Assignment: R|<local>/x|"];
32 [label="Access variable R|<local>/x|"];
33 [label="Smart cast: R|<local>/x|"];
34 [label="Access variable R|kotlin/String.length|"];
35 [label="Postponed enter to lambda"];
subgraph cluster_14 {
color=blue
36 [label="Enter function <anonymous>" style="filled" fillcolor=red];
subgraph cluster_15 {
color=blue
37 [label="Enter block"];
38 [label="Const: Int(1)"];
39 [label="Assignment: R|<local>/x|"];
40 [label="Exit block"];
}
41 [label="Exit function <anonymous>" style="filled" fillcolor=red];
}
42 [label="Postponed exit from lambda"];
43 [label="Function call: R|/unknown|(...)" style="filled" fillcolor=yellow];
44 [label="Access variable R|<local>/x|"];
45 [label="Smart cast: R|<local>/x|"];
46 [label="Access variable <Unresolved name: length>#"];
47 [label="Access variable R|<local>/x|"];
48 [label="Smart cast: R|<local>/x|"];
49 [label="Function call: R|<local>/x|.<Unresolved name: inc>#()" style="filled" fillcolor=yellow];
50 [label="Exit block"];
}
51 [label="Exit function test1" style="filled" fillcolor=red];
}
26 -> {27};
27 -> {28};
28 -> {29};
subgraph cluster_13 {
color=red
29 [label="Enter function test1" style="filled" fillcolor=red];
subgraph cluster_14 {
color=blue
30 [label="Enter block"];
31 [label="Variable declaration: lvar x: R|kotlin/Any?|"];
32 [label="Const: String()"];
33 [label="Assignment: R|<local>/x|"];
34 [label="Access variable R|<local>/x|"];
35 [label="Smart cast: R|<local>/x|"];
36 [label="Access variable R|kotlin/String.length|"];
37 [label="Postponed enter to lambda"];
subgraph cluster_15 {
color=blue
38 [label="Enter function <anonymous>" style="filled" fillcolor=red];
subgraph cluster_16 {
color=blue
39 [label="Enter block"];
40 [label="Const: Int(1)"];
41 [label="Assignment: R|<local>/x|"];
42 [label="Exit block"];
}
43 [label="Exit function <anonymous>" style="filled" fillcolor=red];
}
44 [label="Postponed exit from lambda"];
45 [label="Function call: R|/unknown|(...)" style="filled" fillcolor=yellow];
46 [label="Access variable R|<local>/x|"];
47 [label="Smart cast: R|<local>/x|"];
48 [label="Access variable <Unresolved name: length>#"];
49 [label="Access variable R|<local>/x|"];
50 [label="Smart cast: R|<local>/x|"];
51 [label="Function call: R|<local>/x|.<Unresolved name: inc>#()" style="filled" fillcolor=yellow];
52 [label="Exit block"];
}
53 [label="Exit function test1" style="filled" fillcolor=red];
}
29 -> {30};
30 -> {31};
31 -> {32};
32 -> {33};
33 -> {34};
34 -> {35};
35 -> {36 42 43};
35 -> {36} [style=dashed];
35 -> {36};
36 -> {37};
37 -> {38};
37 -> {38 44 45};
37 -> {38} [style=dashed];
38 -> {39};
39 -> {40};
40 -> {41};
41 -> {42};
42 -> {43};
42 -> {35} [color=green style=dashed];
43 -> {44};
44 -> {45};
44 -> {37} [color=green style=dashed];
45 -> {46};
46 -> {47};
47 -> {48};
48 -> {49};
49 -> {50};
50 -> {51};
subgraph cluster_16 {
color=red
52 [label="Enter function test1m" style="filled" fillcolor=red];
subgraph cluster_17 {
color=blue
53 [label="Enter block"];
54 [label="Variable declaration: lvar x: R|kotlin/Any?|"];
55 [label="Const: String()"];
56 [label="Assignment: R|<local>/x|"];
57 [label="Access variable R|<local>/x|"];
58 [label="Smart cast: R|<local>/x|"];
59 [label="Access variable R|kotlin/String.length|"];
60 [label="Postponed enter to lambda"];
subgraph cluster_18 {
color=blue
61 [label="Enter function <anonymous>" style="filled" fillcolor=red];
subgraph cluster_19 {
color=blue
62 [label="Enter block"];
63 [label="Const: String()"];
64 [label="Assignment: R|<local>/x|"];
65 [label="Exit block"];
}
66 [label="Exit function <anonymous>" style="filled" fillcolor=red];
}
67 [label="Postponed exit from lambda"];
68 [label="Function call: R|/unknown|(...)" 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"];
}
73 [label="Exit function test1m" style="filled" fillcolor=red];
}
51 -> {52};
52 -> {53};
53 -> {54};
subgraph cluster_17 {
color=red
54 [label="Enter function test1m" style="filled" fillcolor=red];
subgraph cluster_18 {
color=blue
55 [label="Enter block"];
56 [label="Variable declaration: lvar x: R|kotlin/Any?|"];
57 [label="Const: String()"];
58 [label="Assignment: R|<local>/x|"];
59 [label="Access variable R|<local>/x|"];
60 [label="Smart cast: R|<local>/x|"];
61 [label="Access variable R|kotlin/String.length|"];
62 [label="Postponed enter to lambda"];
subgraph cluster_19 {
color=blue
63 [label="Enter function <anonymous>" style="filled" fillcolor=red];
subgraph cluster_20 {
color=blue
64 [label="Enter block"];
65 [label="Const: String()"];
66 [label="Assignment: R|<local>/x|"];
67 [label="Exit block"];
}
68 [label="Exit function <anonymous>" style="filled" fillcolor=red];
}
69 [label="Postponed exit from lambda"];
70 [label="Function call: R|/unknown|(...)" 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 function test1m" style="filled" fillcolor=red];
}
54 -> {55};
55 -> {56};
56 -> {57};
57 -> {58};
58 -> {59};
59 -> {60};
60 -> {61 67 68};
60 -> {61} [style=dashed];
60 -> {61};
61 -> {62};
62 -> {63};
62 -> {63 69 70};
62 -> {63} [style=dashed];
63 -> {64};
64 -> {65};
65 -> {66};
66 -> {67};
67 -> {68};
67 -> {60} [color=green style=dashed];
68 -> {69};
69 -> {70};
69 -> {62} [color=green style=dashed];
70 -> {71};
71 -> {72};
72 -> {73};
subgraph cluster_20 {
color=red
74 [label="Enter function test2" style="filled" fillcolor=red];
subgraph cluster_21 {
color=blue
75 [label="Enter block"];
76 [label="Variable declaration: lvar x: R|kotlin/Any?|"];
77 [label="Const: String()"];
78 [label="Assignment: R|<local>/x|"];
79 [label="Access variable R|<local>/x|"];
80 [label="Smart cast: R|<local>/x|"];
81 [label="Access variable R|kotlin/String.length|"];
82 [label="Postponed enter to lambda"];
subgraph cluster_22 {
color=blue
83 [label="Enter function <anonymous>" style="filled" fillcolor=red];
subgraph cluster_23 {
color=blue
84 [label="Enter block"];
85 [label="Const: Int(1)"];
86 [label="Assignment: R|<local>/x|"];
87 [label="Exit block"];
}
88 [label="Exit function <anonymous>" style="filled" fillcolor=red];
}
89 [label="Postponed exit from lambda"];
90 [label="Function call: R|/atLeastOnce|(...)" style="filled" fillcolor=yellow];
91 [label="Access variable R|<local>/x|"];
92 [label="Smart cast: R|<local>/x|"];
93 [label="Access variable <Unresolved name: length>#"];
94 [label="Access variable R|<local>/x|"];
95 [label="Smart cast: R|<local>/x|"];
96 [label="Function call: R|<local>/x|.R|kotlin/Int.inc|()" style="filled" fillcolor=yellow];
97 [label="Exit block"];
}
98 [label="Exit function test2" style="filled" fillcolor=red];
}
73 -> {74};
74 -> {75};
75 -> {76};
subgraph cluster_21 {
color=red
76 [label="Enter function test2" style="filled" fillcolor=red];
subgraph cluster_22 {
color=blue
77 [label="Enter block"];
78 [label="Variable declaration: lvar x: R|kotlin/Any?|"];
79 [label="Const: String()"];
80 [label="Assignment: R|<local>/x|"];
81 [label="Access variable R|<local>/x|"];
82 [label="Smart cast: R|<local>/x|"];
83 [label="Access variable R|kotlin/String.length|"];
84 [label="Postponed enter to lambda"];
subgraph cluster_23 {
color=blue
85 [label="Enter function <anonymous>" style="filled" fillcolor=red];
subgraph cluster_24 {
color=blue
86 [label="Enter block"];
87 [label="Const: Int(1)"];
88 [label="Assignment: R|<local>/x|"];
89 [label="Exit block"];
}
90 [label="Exit function <anonymous>" style="filled" fillcolor=red];
}
91 [label="Postponed exit from lambda"];
92 [label="Function call: R|/atLeastOnce|(...)" style="filled" fillcolor=yellow];
93 [label="Access variable R|<local>/x|"];
94 [label="Smart cast: R|<local>/x|"];
95 [label="Access variable <Unresolved name: length>#"];
96 [label="Access variable R|<local>/x|"];
97 [label="Smart cast: R|<local>/x|"];
98 [label="Function call: R|<local>/x|.R|kotlin/Int.inc|()" style="filled" fillcolor=yellow];
99 [label="Exit block"];
}
100 [label="Exit function test2" style="filled" fillcolor=red];
}
76 -> {77};
77 -> {78};
78 -> {79};
79 -> {80};
80 -> {81};
81 -> {82};
82 -> {83 90};
82 -> {89} [style=dotted];
82 -> {83} [style=dashed];
82 -> {83};
83 -> {84};
84 -> {85};
84 -> {85 92};
84 -> {91} [style=dotted];
84 -> {85} [style=dashed];
85 -> {86};
86 -> {87};
87 -> {88};
88 -> {89};
89 -> {90};
89 -> {82} [color=green style=dashed];
90 -> {91};
91 -> {92};
91 -> {84} [color=green style=dashed];
92 -> {93};
93 -> {94};
94 -> {95};
95 -> {96};
96 -> {97};
97 -> {98};
subgraph cluster_24 {
color=red
99 [label="Enter function test3" style="filled" fillcolor=red];
subgraph cluster_25 {
color=blue
100 [label="Enter block"];
101 [label="Variable declaration: lvar x: R|kotlin/Any?|"];
102 [label="Const: String()"];
103 [label="Assignment: R|<local>/x|"];
104 [label="Access variable R|<local>/x|"];
105 [label="Smart cast: R|<local>/x|"];
106 [label="Access variable R|kotlin/String.length|"];
107 [label="Postponed enter to lambda"];
subgraph cluster_26 {
color=blue
108 [label="Enter function <anonymous>" style="filled" fillcolor=red];
subgraph cluster_27 {
color=blue
109 [label="Enter block"];
110 [label="Const: Int(1)"];
111 [label="Assignment: R|<local>/x|"];
112 [label="Exit block"];
}
113 [label="Exit function <anonymous>" style="filled" fillcolor=red];
}
114 [label="Postponed exit from lambda"];
115 [label="Function call: R|/exactlyOnce|(...)" style="filled" fillcolor=yellow];
116 [label="Access variable R|<local>/x|"];
117 [label="Smart cast: R|<local>/x|"];
118 [label="Access variable <Unresolved name: length>#"];
119 [label="Access variable R|<local>/x|"];
120 [label="Smart cast: R|<local>/x|"];
121 [label="Function call: R|<local>/x|.R|kotlin/Int.inc|()" style="filled" fillcolor=yellow];
122 [label="Exit block"];
}
123 [label="Exit function test3" style="filled" fillcolor=red];
}
98 -> {99};
99 -> {100};
100 -> {101};
subgraph cluster_25 {
color=red
101 [label="Enter function test3" style="filled" fillcolor=red];
subgraph cluster_26 {
color=blue
102 [label="Enter block"];
103 [label="Variable declaration: lvar x: R|kotlin/Any?|"];
104 [label="Const: String()"];
105 [label="Assignment: R|<local>/x|"];
106 [label="Access variable R|<local>/x|"];
107 [label="Smart cast: R|<local>/x|"];
108 [label="Access variable R|kotlin/String.length|"];
109 [label="Postponed enter to lambda"];
subgraph cluster_27 {
color=blue
110 [label="Enter function <anonymous>" style="filled" fillcolor=red];
subgraph cluster_28 {
color=blue
111 [label="Enter block"];
112 [label="Const: Int(1)"];
113 [label="Assignment: R|<local>/x|"];
114 [label="Exit block"];
}
115 [label="Exit function <anonymous>" style="filled" fillcolor=red];
}
116 [label="Postponed exit from lambda"];
117 [label="Function call: R|/exactlyOnce|(...)" style="filled" fillcolor=yellow];
118 [label="Access variable R|<local>/x|"];
119 [label="Smart cast: R|<local>/x|"];
120 [label="Access variable <Unresolved name: length>#"];
121 [label="Access variable R|<local>/x|"];
122 [label="Smart cast: R|<local>/x|"];
123 [label="Function call: R|<local>/x|.R|kotlin/Int.inc|()" style="filled" fillcolor=yellow];
124 [label="Exit block"];
}
125 [label="Exit function test3" style="filled" fillcolor=red];
}
101 -> {102};
102 -> {103};
103 -> {104};
104 -> {105};
105 -> {106};
106 -> {107};
107 -> {108 115};
107 -> {114} [style=dotted];
107 -> {108} [style=dashed];
107 -> {108};
108 -> {109};
109 -> {110};
109 -> {110 117};
109 -> {116} [style=dotted];
109 -> {110} [style=dashed];
110 -> {111};
111 -> {112};
112 -> {113};
@@ -343,56 +348,56 @@ digraph flowFromInplaceLambda3_kt {
120 -> {121};
121 -> {122};
122 -> {123};
subgraph cluster_28 {
color=red
124 [label="Enter function test4" style="filled" fillcolor=red];
subgraph cluster_29 {
color=blue
125 [label="Enter block"];
126 [label="Variable declaration: lvar x: R|kotlin/Any?|"];
127 [label="Const: String()"];
128 [label="Assignment: R|<local>/x|"];
129 [label="Access variable R|<local>/x|"];
130 [label="Smart cast: R|<local>/x|"];
131 [label="Access variable R|kotlin/String.length|"];
132 [label="Postponed enter to lambda"];
subgraph cluster_30 {
color=blue
133 [label="Enter function <anonymous>" style="filled" fillcolor=red];
subgraph cluster_31 {
color=blue
134 [label="Enter block"];
135 [label="Const: Int(1)"];
136 [label="Assignment: R|<local>/x|"];
137 [label="Exit block"];
}
138 [label="Exit function <anonymous>" style="filled" fillcolor=red];
}
139 [label="Postponed exit from lambda"];
140 [label="Function call: R|/atMostOnce|(...)" style="filled" fillcolor=yellow];
141 [label="Access variable R|<local>/x|"];
142 [label="Smart cast: R|<local>/x|"];
143 [label="Access variable <Unresolved name: length>#"];
144 [label="Access variable R|<local>/x|"];
145 [label="Smart cast: R|<local>/x|"];
146 [label="Function call: R|<local>/x|.<Unresolved name: inc>#()" style="filled" fillcolor=yellow];
147 [label="Exit block"];
}
148 [label="Exit function test4" style="filled" fillcolor=red];
}
123 -> {124};
124 -> {125};
125 -> {126};
subgraph cluster_29 {
color=red
126 [label="Enter function test4" style="filled" fillcolor=red];
subgraph cluster_30 {
color=blue
127 [label="Enter block"];
128 [label="Variable declaration: lvar x: R|kotlin/Any?|"];
129 [label="Const: String()"];
130 [label="Assignment: R|<local>/x|"];
131 [label="Access variable R|<local>/x|"];
132 [label="Smart cast: R|<local>/x|"];
133 [label="Access variable R|kotlin/String.length|"];
134 [label="Postponed enter to lambda"];
subgraph cluster_31 {
color=blue
135 [label="Enter function <anonymous>" style="filled" fillcolor=red];
subgraph cluster_32 {
color=blue
136 [label="Enter block"];
137 [label="Const: Int(1)"];
138 [label="Assignment: R|<local>/x|"];
139 [label="Exit block"];
}
140 [label="Exit function <anonymous>" style="filled" fillcolor=red];
}
141 [label="Postponed exit from lambda"];
142 [label="Function call: R|/atMostOnce|(...)" style="filled" fillcolor=yellow];
143 [label="Access variable R|<local>/x|"];
144 [label="Smart cast: R|<local>/x|"];
145 [label="Access variable <Unresolved name: length>#"];
146 [label="Access variable R|<local>/x|"];
147 [label="Smart cast: R|<local>/x|"];
148 [label="Function call: R|<local>/x|.<Unresolved name: inc>#()" style="filled" fillcolor=yellow];
149 [label="Exit block"];
}
150 [label="Exit function test4" style="filled" fillcolor=red];
}
126 -> {127};
127 -> {128};
128 -> {129};
129 -> {130};
130 -> {131};
131 -> {132};
132 -> {133 139 140};
132 -> {133} [style=dashed];
132 -> {133};
133 -> {134};
134 -> {135};
134 -> {135 141 142};
134 -> {135} [style=dashed];
135 -> {136};
136 -> {137};
137 -> {138};
@@ -406,5 +411,7 @@ digraph flowFromInplaceLambda3_kt {
145 -> {146};
146 -> {147};
147 -> {148};
148 -> {149};
149 -> {150};
}