[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:
+69
-62
@@ -5,103 +5,108 @@ digraph delayedAssignment_kt {
|
||||
|
||||
subgraph cluster_0 {
|
||||
color=red
|
||||
0 [label="Enter class A" style="filled" fillcolor=red];
|
||||
subgraph cluster_1 {
|
||||
color=blue
|
||||
1 [label="Enter function <init>" style="filled" fillcolor=red];
|
||||
2 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=yellow];
|
||||
3 [label="Exit function <init>" style="filled" fillcolor=red];
|
||||
}
|
||||
4 [label="Exit class A" style="filled" fillcolor=red];
|
||||
0 [label="Enter file delayedAssignment.kt" style="filled" fillcolor=red];
|
||||
1 [label="Exit file delayedAssignment.kt" style="filled" fillcolor=red];
|
||||
}
|
||||
0 -> {1} [color=green];
|
||||
0 -> {4} [style=dotted];
|
||||
0 -> {1} [style=dashed];
|
||||
1 -> {2};
|
||||
2 -> {3};
|
||||
3 -> {4} [color=green];
|
||||
|
||||
subgraph cluster_2 {
|
||||
subgraph cluster_1 {
|
||||
color=red
|
||||
5 [label="Enter function foo" style="filled" fillcolor=red];
|
||||
subgraph cluster_3 {
|
||||
2 [label="Enter class A" style="filled" fillcolor=red];
|
||||
subgraph cluster_2 {
|
||||
color=blue
|
||||
6 [label="Enter block"];
|
||||
7 [label="Exit block"];
|
||||
3 [label="Enter function <init>" style="filled" fillcolor=red];
|
||||
4 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=yellow];
|
||||
5 [label="Exit function <init>" style="filled" fillcolor=red];
|
||||
}
|
||||
8 [label="Exit function foo" style="filled" fillcolor=red];
|
||||
6 [label="Exit class A" style="filled" fillcolor=red];
|
||||
}
|
||||
5 -> {6};
|
||||
6 -> {7};
|
||||
7 -> {8};
|
||||
2 -> {3} [color=green];
|
||||
2 -> {6} [style=dotted];
|
||||
2 -> {3} [style=dashed];
|
||||
3 -> {4};
|
||||
4 -> {5};
|
||||
5 -> {6} [color=green];
|
||||
|
||||
subgraph cluster_4 {
|
||||
subgraph cluster_3 {
|
||||
color=red
|
||||
9 [label="Enter function test" style="filled" fillcolor=red];
|
||||
subgraph cluster_5 {
|
||||
7 [label="Enter function foo" style="filled" fillcolor=red];
|
||||
subgraph cluster_4 {
|
||||
color=blue
|
||||
10 [label="Enter block"];
|
||||
11 [label="Variable declaration: lval a: R|A?|"];
|
||||
subgraph cluster_6 {
|
||||
8 [label="Enter block"];
|
||||
9 [label="Exit block"];
|
||||
}
|
||||
10 [label="Exit function foo" style="filled" fillcolor=red];
|
||||
}
|
||||
7 -> {8};
|
||||
8 -> {9};
|
||||
9 -> {10};
|
||||
|
||||
subgraph cluster_5 {
|
||||
color=red
|
||||
11 [label="Enter function test" style="filled" fillcolor=red];
|
||||
subgraph cluster_6 {
|
||||
color=blue
|
||||
12 [label="Enter block"];
|
||||
13 [label="Variable declaration: lval a: R|A?|"];
|
||||
subgraph cluster_7 {
|
||||
color=blue
|
||||
12 [label="Enter when"];
|
||||
subgraph cluster_7 {
|
||||
color=blue
|
||||
13 [label="Enter when branch condition "];
|
||||
14 [label="Access variable R|<local>/b|"];
|
||||
15 [label="Exit when branch condition"];
|
||||
}
|
||||
14 [label="Enter when"];
|
||||
subgraph cluster_8 {
|
||||
color=blue
|
||||
16 [label="Enter when branch condition else"];
|
||||
15 [label="Enter when branch condition "];
|
||||
16 [label="Access variable R|<local>/b|"];
|
||||
17 [label="Exit when branch condition"];
|
||||
}
|
||||
18 [label="Enter when branch result"];
|
||||
subgraph cluster_9 {
|
||||
color=blue
|
||||
19 [label="Enter block"];
|
||||
20 [label="Const: Null(null)"];
|
||||
21 [label="Assignment: R|<local>/a|"];
|
||||
22 [label="Exit block"];
|
||||
18 [label="Enter when branch condition else"];
|
||||
19 [label="Exit when branch condition"];
|
||||
}
|
||||
23 [label="Exit when branch result"];
|
||||
24 [label="Enter when branch result"];
|
||||
20 [label="Enter when branch result"];
|
||||
subgraph cluster_10 {
|
||||
color=blue
|
||||
25 [label="Enter block"];
|
||||
26 [label="Function call: R|/A.A|()" style="filled" fillcolor=yellow];
|
||||
27 [label="Assignment: R|<local>/a|"];
|
||||
28 [label="Access variable R|<local>/a|"];
|
||||
29 [label="Smart cast: R|<local>/a|"];
|
||||
30 [label="Function call: R|<local>/a|.R|/A.foo|()" style="filled" fillcolor=yellow];
|
||||
31 [label="Exit block"];
|
||||
21 [label="Enter block"];
|
||||
22 [label="Const: Null(null)"];
|
||||
23 [label="Assignment: R|<local>/a|"];
|
||||
24 [label="Exit block"];
|
||||
}
|
||||
32 [label="Exit when branch result"];
|
||||
33 [label="Exit when"];
|
||||
25 [label="Exit when branch result"];
|
||||
26 [label="Enter when branch result"];
|
||||
subgraph cluster_11 {
|
||||
color=blue
|
||||
27 [label="Enter block"];
|
||||
28 [label="Function call: R|/A.A|()" style="filled" fillcolor=yellow];
|
||||
29 [label="Assignment: R|<local>/a|"];
|
||||
30 [label="Access variable R|<local>/a|"];
|
||||
31 [label="Smart cast: R|<local>/a|"];
|
||||
32 [label="Function call: R|<local>/a|.R|/A.foo|()" style="filled" fillcolor=yellow];
|
||||
33 [label="Exit block"];
|
||||
}
|
||||
34 [label="Exit when branch result"];
|
||||
35 [label="Exit when"];
|
||||
}
|
||||
34 [label="Access variable R|<local>/a|"];
|
||||
35 [label="Function call: R|<local>/a|.R|/A.foo<Inapplicable(UNSAFE_CALL): /A.foo>#|()" style="filled" fillcolor=yellow];
|
||||
36 [label="Exit block"];
|
||||
36 [label="Access variable R|<local>/a|"];
|
||||
37 [label="Function call: R|<local>/a|.R|/A.foo<Inapplicable(UNSAFE_CALL): /A.foo>#|()" style="filled" fillcolor=yellow];
|
||||
38 [label="Exit block"];
|
||||
}
|
||||
37 [label="Exit function test" style="filled" fillcolor=red];
|
||||
39 [label="Exit function test" style="filled" fillcolor=red];
|
||||
}
|
||||
9 -> {10};
|
||||
10 -> {11};
|
||||
11 -> {12};
|
||||
12 -> {13};
|
||||
13 -> {14};
|
||||
14 -> {15};
|
||||
15 -> {16 24};
|
||||
15 -> {16};
|
||||
16 -> {17};
|
||||
17 -> {18};
|
||||
17 -> {18 26};
|
||||
18 -> {19};
|
||||
19 -> {20};
|
||||
20 -> {21};
|
||||
21 -> {22};
|
||||
22 -> {23};
|
||||
23 -> {33};
|
||||
23 -> {24};
|
||||
24 -> {25};
|
||||
25 -> {26};
|
||||
25 -> {35};
|
||||
26 -> {27};
|
||||
27 -> {28};
|
||||
28 -> {29};
|
||||
@@ -113,5 +118,7 @@ digraph delayedAssignment_kt {
|
||||
34 -> {35};
|
||||
35 -> {36};
|
||||
36 -> {37};
|
||||
37 -> {38};
|
||||
38 -> {39};
|
||||
|
||||
}
|
||||
|
||||
Vendored
+82
-75
@@ -5,23 +5,28 @@ digraph smartcastAfterReassignment_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="Const: Int(1)"];
|
||||
3 [label="Variable declaration: lvar x: R|kotlin/Any|"];
|
||||
4 [label="Const: String()"];
|
||||
5 [label="Assignment: R|<local>/x|"];
|
||||
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 [label="Enter file smartcastAfterReassignment.kt" style="filled" fillcolor=red];
|
||||
1 [label="Exit file smartcastAfterReassignment.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="Const: Int(1)"];
|
||||
5 [label="Variable declaration: lvar x: R|kotlin/Any|"];
|
||||
6 [label="Const: String()"];
|
||||
7 [label="Assignment: R|<local>/x|"];
|
||||
8 [label="Access variable R|<local>/x|"];
|
||||
9 [label="Smart cast: R|<local>/x|"];
|
||||
10 [label="Access variable R|kotlin/String.length|"];
|
||||
11 [label="Exit block"];
|
||||
}
|
||||
12 [label="Exit function test_1" style="filled" fillcolor=red];
|
||||
}
|
||||
0 -> {1};
|
||||
1 -> {2};
|
||||
2 -> {3};
|
||||
3 -> {4};
|
||||
4 -> {5};
|
||||
@@ -30,47 +35,47 @@ digraph smartcastAfterReassignment_kt {
|
||||
7 -> {8};
|
||||
8 -> {9};
|
||||
9 -> {10};
|
||||
10 -> {11};
|
||||
11 -> {12};
|
||||
|
||||
subgraph cluster_2 {
|
||||
subgraph cluster_3 {
|
||||
color=red
|
||||
11 [label="Enter function test_2" style="filled" fillcolor=red];
|
||||
subgraph cluster_3 {
|
||||
13 [label="Enter function test_2" style="filled" fillcolor=red];
|
||||
subgraph cluster_4 {
|
||||
color=blue
|
||||
12 [label="Enter block"];
|
||||
13 [label="Const: Null(null)"];
|
||||
14 [label="Variable declaration: lvar x: R|kotlin/String?|"];
|
||||
subgraph cluster_4 {
|
||||
14 [label="Enter block"];
|
||||
15 [label="Const: Null(null)"];
|
||||
16 [label="Variable declaration: lvar x: R|kotlin/String?|"];
|
||||
subgraph cluster_5 {
|
||||
color=blue
|
||||
15 [label="Enter when"];
|
||||
subgraph cluster_5 {
|
||||
color=blue
|
||||
16 [label="Enter when branch condition "];
|
||||
17 [label="Access variable R|<local>/x|"];
|
||||
18 [label="Const: Null(null)"];
|
||||
19 [label="Equality operator =="];
|
||||
20 [label="Exit when branch condition"];
|
||||
}
|
||||
21 [label="Synthetic else branch"];
|
||||
22 [label="Enter when branch result"];
|
||||
17 [label="Enter when"];
|
||||
subgraph cluster_6 {
|
||||
color=blue
|
||||
23 [label="Enter block"];
|
||||
24 [label="Const: String()"];
|
||||
25 [label="Assignment: R|<local>/x|"];
|
||||
26 [label="Exit block"];
|
||||
18 [label="Enter when branch condition "];
|
||||
19 [label="Access variable R|<local>/x|"];
|
||||
20 [label="Const: Null(null)"];
|
||||
21 [label="Equality operator =="];
|
||||
22 [label="Exit when branch condition"];
|
||||
}
|
||||
27 [label="Exit when branch result"];
|
||||
28 [label="Exit when"];
|
||||
23 [label="Synthetic else branch"];
|
||||
24 [label="Enter when branch result"];
|
||||
subgraph cluster_7 {
|
||||
color=blue
|
||||
25 [label="Enter block"];
|
||||
26 [label="Const: String()"];
|
||||
27 [label="Assignment: R|<local>/x|"];
|
||||
28 [label="Exit block"];
|
||||
}
|
||||
29 [label="Exit when branch result"];
|
||||
30 [label="Exit when"];
|
||||
}
|
||||
29 [label="Access variable R|<local>/x|"];
|
||||
30 [label="Smart cast: R|<local>/x|"];
|
||||
31 [label="Access variable R|kotlin/String.length|"];
|
||||
32 [label="Exit block"];
|
||||
31 [label="Access variable R|<local>/x|"];
|
||||
32 [label="Smart cast: R|<local>/x|"];
|
||||
33 [label="Access variable R|kotlin/String.length|"];
|
||||
34 [label="Exit block"];
|
||||
}
|
||||
33 [label="Exit function test_2" style="filled" fillcolor=red];
|
||||
35 [label="Exit function test_2" style="filled" fillcolor=red];
|
||||
}
|
||||
11 -> {12};
|
||||
12 -> {13};
|
||||
13 -> {14};
|
||||
14 -> {15};
|
||||
15 -> {16};
|
||||
@@ -78,10 +83,10 @@ digraph smartcastAfterReassignment_kt {
|
||||
17 -> {18};
|
||||
18 -> {19};
|
||||
19 -> {20};
|
||||
20 -> {21 22};
|
||||
21 -> {28};
|
||||
22 -> {23};
|
||||
23 -> {24};
|
||||
20 -> {21};
|
||||
21 -> {22};
|
||||
22 -> {23 24};
|
||||
23 -> {30};
|
||||
24 -> {25};
|
||||
25 -> {26};
|
||||
26 -> {27};
|
||||
@@ -91,31 +96,31 @@ digraph smartcastAfterReassignment_kt {
|
||||
30 -> {31};
|
||||
31 -> {32};
|
||||
32 -> {33};
|
||||
|
||||
subgraph cluster_7 {
|
||||
color=red
|
||||
34 [label="Enter function test_3" style="filled" fillcolor=red];
|
||||
subgraph cluster_8 {
|
||||
color=blue
|
||||
35 [label="Enter block"];
|
||||
36 [label="Const: Null(null)"];
|
||||
37 [label="Variable declaration: lvar x: R|kotlin/String?|"];
|
||||
38 [label="Const: String()"];
|
||||
39 [label="Assignment: R|<local>/x|"];
|
||||
40 [label="Access variable R|<local>/x|"];
|
||||
41 [label="Smart cast: R|<local>/x|"];
|
||||
42 [label="Access variable R|kotlin/String.length|"];
|
||||
43 [label="Const: Null(null)"];
|
||||
44 [label="Assignment: R|<local>/x|"];
|
||||
45 [label="Access variable R|<local>/x|"];
|
||||
46 [label="Smart cast: R|<local>/x|"];
|
||||
47 [label="Access variable R|kotlin/String.length<Inapplicable(UNSAFE_CALL): kotlin/String.length>#|"];
|
||||
48 [label="Exit block"];
|
||||
}
|
||||
49 [label="Exit function test_3" style="filled" fillcolor=red];
|
||||
}
|
||||
33 -> {34};
|
||||
34 -> {35};
|
||||
35 -> {36};
|
||||
|
||||
subgraph cluster_8 {
|
||||
color=red
|
||||
36 [label="Enter function test_3" style="filled" fillcolor=red];
|
||||
subgraph cluster_9 {
|
||||
color=blue
|
||||
37 [label="Enter block"];
|
||||
38 [label="Const: Null(null)"];
|
||||
39 [label="Variable declaration: lvar x: R|kotlin/String?|"];
|
||||
40 [label="Const: String()"];
|
||||
41 [label="Assignment: R|<local>/x|"];
|
||||
42 [label="Access variable R|<local>/x|"];
|
||||
43 [label="Smart cast: R|<local>/x|"];
|
||||
44 [label="Access variable R|kotlin/String.length|"];
|
||||
45 [label="Const: Null(null)"];
|
||||
46 [label="Assignment: R|<local>/x|"];
|
||||
47 [label="Access variable R|<local>/x|"];
|
||||
48 [label="Smart cast: R|<local>/x|"];
|
||||
49 [label="Access variable R|kotlin/String.length<Inapplicable(UNSAFE_CALL): kotlin/String.length>#|"];
|
||||
50 [label="Exit block"];
|
||||
}
|
||||
51 [label="Exit function test_3" style="filled" fillcolor=red];
|
||||
}
|
||||
36 -> {37};
|
||||
37 -> {38};
|
||||
38 -> {39};
|
||||
@@ -129,5 +134,7 @@ digraph smartcastAfterReassignment_kt {
|
||||
46 -> {47};
|
||||
47 -> {48};
|
||||
48 -> {49};
|
||||
49 -> {50};
|
||||
50 -> {51};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user