[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
+101 -94
View File
@@ -5,145 +5,150 @@ digraph safeCalls_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 safeCalls.kt" style="filled" fillcolor=red];
1 [label="Exit file safeCalls.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 bar" style="filled" fillcolor=red];
5 [label="Exit function bar" style="filled" fillcolor=red];
4 [label="Enter function foo" style="filled" fillcolor=red];
5 [label="Exit function foo" style="filled" fillcolor=red];
}
4 -> {5};
subgraph cluster_3 {
color=red
6 [label="Enter class B" style="filled" fillcolor=red];
7 [label="Exit class B" style="filled" fillcolor=red];
6 [label="Enter function bar" style="filled" fillcolor=red];
7 [label="Exit function bar" style="filled" fillcolor=red];
}
6 -> {7} [color=green];
6 -> {7};
subgraph cluster_4 {
color=red
8 [label="Enter function test_1" style="filled" fillcolor=red];
subgraph cluster_5 {
8 [label="Enter class B" style="filled" fillcolor=red];
9 [label="Exit class B" style="filled" fillcolor=red];
}
8 -> {9} [color=green];
subgraph cluster_5 {
color=red
10 [label="Enter function test_1" style="filled" fillcolor=red];
subgraph cluster_6 {
color=blue
9 [label="Enter block"];
10 [label="Access variable R|<local>/x|"];
11 [label="Enter safe call"];
12 [label="Function call: $subj$.R|/A.foo|()" style="filled" fillcolor=yellow];
11 [label="Enter block"];
12 [label="Access variable R|<local>/x|"];
13 [label="Enter safe call"];
14 [label="Const: String()"];
15 [label="Function call: $subj$.R|/A.bar|(...)" style="filled" fillcolor=yellow];
16 [label="Exit safe call"];
17 [label="Exit safe call"];
18 [label="Exit block"];
14 [label="Function call: $subj$.R|/A.foo|()" style="filled" fillcolor=yellow];
15 [label="Enter safe call"];
16 [label="Const: String()"];
17 [label="Function call: $subj$.R|/A.bar|(...)" style="filled" fillcolor=yellow];
18 [label="Exit safe call"];
19 [label="Exit safe call"];
20 [label="Exit block"];
}
19 [label="Exit function test_1" style="filled" fillcolor=red];
21 [label="Exit function test_1" style="filled" fillcolor=red];
}
8 -> {9};
9 -> {10};
10 -> {11 16};
10 -> {11};
11 -> {12};
12 -> {13 16};
12 -> {13 18};
13 -> {14};
14 -> {15};
15 -> {17};
14 -> {15 18};
15 -> {16};
16 -> {17};
17 -> {18};
17 -> {19};
18 -> {19};
subgraph cluster_6 {
color=red
20 [label="Enter function test_2" style="filled" fillcolor=red];
subgraph cluster_7 {
color=blue
21 [label="Enter block"];
22 [label="Access variable R|<local>/x|"];
23 [label="Enter safe call"];
24 [label="Access variable R|/B.foo|"];
25 [label="Enter safe call"];
26 [label="Access variable R|/B.bar|"];
27 [label="Exit safe call"];
28 [label="Exit safe call"];
29 [label="Exit block"];
}
30 [label="Exit function test_2" style="filled" fillcolor=red];
}
19 -> {20};
20 -> {21};
21 -> {22};
22 -> {23 27};
23 -> {24};
24 -> {25 27};
25 -> {26};
26 -> {28};
27 -> {28};
28 -> {29};
29 -> {30};
subgraph cluster_8 {
subgraph cluster_7 {
color=red
31 [label="Enter function test_3" style="filled" fillcolor=red];
subgraph cluster_9 {
22 [label="Enter function test_2" style="filled" fillcolor=red];
subgraph cluster_8 {
color=blue
32 [label="Enter block"];
subgraph cluster_10 {
23 [label="Enter block"];
24 [label="Access variable R|<local>/x|"];
25 [label="Enter safe call"];
26 [label="Access variable R|/B.foo|"];
27 [label="Enter safe call"];
28 [label="Access variable R|/B.bar|"];
29 [label="Exit safe call"];
30 [label="Exit safe call"];
31 [label="Exit block"];
}
32 [label="Exit function test_2" style="filled" fillcolor=red];
}
22 -> {23};
23 -> {24};
24 -> {25 29};
25 -> {26};
26 -> {27 29};
27 -> {28};
28 -> {30};
29 -> {30};
30 -> {31};
31 -> {32};
subgraph cluster_9 {
color=red
33 [label="Enter function test_3" style="filled" fillcolor=red];
subgraph cluster_10 {
color=blue
34 [label="Enter block"];
subgraph cluster_11 {
color=blue
33 [label="Enter when"];
subgraph cluster_11 {
color=blue
34 [label="Enter when branch condition "];
35 [label="Access variable R|<local>/x|"];
36 [label="Enter safe call"];
37 [label="Access variable R|<local>/y|"];
38 [label="Type operator: (R|<local>/y| as R|kotlin/String|)"];
39 [label="Function call: $subj$.R|/A.bar|(...)" style="filled" fillcolor=yellow];
40 [label="Exit safe call"];
41 [label="Const: Null(null)"];
42 [label="Equality operator !="];
43 [label="Exit when branch condition"];
}
44 [label="Synthetic else branch"];
45 [label="Enter when branch result"];
35 [label="Enter when"];
subgraph cluster_12 {
color=blue
46 [label="Enter block"];
47 [label="Access variable R|<local>/y|"];
48 [label="Smart cast: R|<local>/y|"];
49 [label="Access variable R|kotlin/String.length|"];
50 [label="Exit block"];
36 [label="Enter when branch condition "];
37 [label="Access variable R|<local>/x|"];
38 [label="Enter safe call"];
39 [label="Access variable R|<local>/y|"];
40 [label="Type operator: (R|<local>/y| as R|kotlin/String|)"];
41 [label="Function call: $subj$.R|/A.bar|(...)" style="filled" fillcolor=yellow];
42 [label="Exit safe call"];
43 [label="Const: Null(null)"];
44 [label="Equality operator !="];
45 [label="Exit when branch condition"];
}
51 [label="Exit when branch result"];
52 [label="Exit when"];
46 [label="Synthetic else branch"];
47 [label="Enter when branch result"];
subgraph cluster_13 {
color=blue
48 [label="Enter block"];
49 [label="Access variable R|<local>/y|"];
50 [label="Smart cast: R|<local>/y|"];
51 [label="Access variable R|kotlin/String.length|"];
52 [label="Exit block"];
}
53 [label="Exit when branch result"];
54 [label="Exit when"];
}
53 [label="Exit block"];
55 [label="Exit block"];
}
54 [label="Exit function test_3" style="filled" fillcolor=red];
56 [label="Exit function test_3" style="filled" fillcolor=red];
}
31 -> {32};
32 -> {33};
33 -> {34};
34 -> {35};
35 -> {36 40};
35 -> {36};
36 -> {37};
37 -> {38};
37 -> {38 42};
38 -> {39};
39 -> {40};
40 -> {41};
41 -> {42};
42 -> {43};
43 -> {44 45};
44 -> {52};
45 -> {46};
46 -> {47};
43 -> {44};
44 -> {45};
45 -> {46 47};
46 -> {54};
47 -> {48};
48 -> {49};
49 -> {50};
@@ -151,5 +156,7 @@ digraph safeCalls_kt {
51 -> {52};
52 -> {53};
53 -> {54};
54 -> {55};
55 -> {56};
}