[FIR] Make sure the primary constructor is first in class CFG

The primary constructor of a class needs to be the first subgraph of the
class control-flow graph. Based on the Kotlin specification, class
initialization order goes first primary constructor, in-place
declarations (properties and init blocks), and then secondary
constructors. If the class doesn't have a primary constructor, then it
is just skipped in the order.

Unfortunately, the class control-flow graph had in-place declarations
first and then all constructors. Instead, we should treat the primary
constructor as the first in-place declaration, and then continue with
the existing processing as secondary constructors. This will guarantee
that super constructor calls have the correct property initialization
information.

^KT-65093 Fixed
This commit is contained in:
Brian Norman
2024-01-18 20:17:17 -06:00
committed by Space Team
parent c628172235
commit 17a1871b83
28 changed files with 732 additions and 900 deletions
@@ -15,33 +15,33 @@ digraph initBlock_kt {
2 [label="Enter class Foo" style="filled" fillcolor=red];
subgraph cluster_2 {
color=blue
3 [label="Enter init block" style="filled" fillcolor=red];
subgraph cluster_3 {
color=blue
4 [label="Enter block"];
5 [label="Const: Int(1)"];
6 [label="Variable declaration: lval x: R|kotlin/Int|"];
7 [label="Exit block"];
}
8 [label="Exit init block" style="filled" fillcolor=red];
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];
}
subgraph cluster_4 {
subgraph cluster_3 {
color=blue
9 [label="Enter function <init>" style="filled" fillcolor=red];
10 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=yellow];
11 [label="Exit function <init>" style="filled" fillcolor=red];
6 [label="Enter init block" style="filled" fillcolor=red];
subgraph cluster_4 {
color=blue
7 [label="Enter block"];
8 [label="Const: Int(1)"];
9 [label="Variable declaration: lval x: R|kotlin/Int|"];
10 [label="Exit block"];
}
11 [label="Exit init block" style="filled" fillcolor=red];
}
12 [label="Exit class Foo" style="filled" fillcolor=red];
}
2 -> {3} [color=green];
2 -> {12} [style=dotted];
2 -> {3 9} [style=dashed];
2 -> {3 6} [style=dashed];
3 -> {4};
4 -> {5};
5 -> {6};
5 -> {6} [color=green];
6 -> {7};
7 -> {8};
8 -> {9} [color=green];
8 -> {9};
9 -> {10};
10 -> {11};
11 -> {12} [color=green];
@@ -51,47 +51,47 @@ digraph initBlock_kt {
13 [label="Enter class Bar" style="filled" fillcolor=red];
subgraph cluster_6 {
color=blue
14 [label="Enter init block" style="filled" fillcolor=red];
subgraph cluster_7 {
color=blue
15 [label="Enter block"];
16 [label="Const: Int(1)"];
17 [label="Variable declaration: lval x: R|kotlin/Int|"];
subgraph cluster_8 {
color=blue
18 [label="Function call arguments enter"];
19 [label="Function call arguments exit"];
}
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="Const: Int(2)" style="filled" fillcolor=gray];
24 [label="Variable declaration: lval y: R|kotlin/Int|" style="filled" fillcolor=gray];
25 [label="Exit block" style="filled" fillcolor=gray];
}
26 [label="Exit init block" style="filled" fillcolor=gray];
14 [label="Enter function <init>" style="filled" fillcolor=red];
15 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=yellow];
16 [label="Exit function <init>" style="filled" fillcolor=red];
}
subgraph cluster_9 {
subgraph cluster_7 {
color=blue
27 [label="Enter function <init>" style="filled" fillcolor=gray];
28 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=gray];
29 [label="Exit function <init>" style="filled" fillcolor=gray];
17 [label="Enter init block" style="filled" fillcolor=red];
subgraph cluster_8 {
color=blue
18 [label="Enter block"];
19 [label="Const: Int(1)"];
20 [label="Variable declaration: lval x: R|kotlin/Int|"];
subgraph cluster_9 {
color=blue
21 [label="Function call arguments enter"];
22 [label="Function call arguments exit"];
}
23 [label="Function call: R|java/lang/Exception.Exception|()" style="filled" fillcolor=yellow];
24 [label="Throw: throw R|java/lang/Exception.Exception|()"];
25 [label="Stub" style="filled" fillcolor=gray];
26 [label="Const: Int(2)" style="filled" fillcolor=gray];
27 [label="Variable declaration: lval y: R|kotlin/Int|" style="filled" fillcolor=gray];
28 [label="Exit block" style="filled" fillcolor=gray];
}
29 [label="Exit init block" style="filled" fillcolor=gray];
}
30 [label="Exit class Bar" style="filled" fillcolor=gray];
}
13 -> {14} [color=green];
13 -> {30} [style=dotted];
13 -> {14 27} [style=dashed];
13 -> {14 17} [style=dashed];
14 -> {15};
15 -> {16};
16 -> {17};
16 -> {17} [color=green];
17 -> {18};
18 -> {19};
19 -> {20};
20 -> {21};
21 -> {22} [style=dotted];
22 -> {23} [style=dotted];
23 -> {24} [style=dotted];
21 -> {22};
22 -> {23};
23 -> {24};
24 -> {25} [style=dotted];
25 -> {26} [style=dotted];
26 -> {27} [style=dotted];
@@ -29,81 +29,81 @@ digraph initBlockAndInPlaceLambda_kt {
6 [label="Enter class C" style="filled" fillcolor=red];
subgraph cluster_4 {
color=blue
7 [label="Enter init block" style="filled" fillcolor=red];
subgraph cluster_5 {
color=blue
8 [label="Enter block"];
9 [label="Access variable R|<local>/a|"];
10 [label="Access variable R|/A.b|"];
11 [label="Enter safe call"];
subgraph cluster_6 {
color=blue
12 [label="Function call arguments enter"];
13 [label="Postponed enter to lambda"];
subgraph cluster_7 {
color=blue
14 [label="Enter function <anonymous>" style="filled" fillcolor=red];
subgraph cluster_8 {
color=blue
15 [label="Enter block"];
subgraph cluster_9 {
color=blue
16 [label="Function call arguments enter"];
17 [label="Access variable R|<local>/a|"];
18 [label="Access variable R|<local>/it|"];
19 [label="Function call arguments exit"];
}
20 [label="Function call: R|/C.C|(...)" style="filled" fillcolor=yellow];
21 [label="Exit block"];
}
22 [label="Exit function <anonymous>" style="filled" fillcolor=red];
}
23 [label="Function call arguments exit"];
}
24 [label="Postponed exit from lambda"];
25 [label="Function call: $subj$.R|kotlin/let|<R|B|, R|C|>(...)" style="filled" fillcolor=yellow];
26 [label="Exit safe call"];
27 [label="Variable declaration: lval c: R|C?|"];
28 [label="Exit block"];
}
29 [label="Exit init block" style="filled" fillcolor=red];
7 [label="Enter function <init>" style="filled" fillcolor=red];
8 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=yellow];
9 [label="Exit function <init>" style="filled" fillcolor=red];
}
subgraph cluster_10 {
subgraph cluster_5 {
color=blue
30 [label="Enter function <init>" style="filled" fillcolor=red];
31 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=yellow];
32 [label="Exit function <init>" style="filled" fillcolor=red];
10 [label="Enter init block" style="filled" fillcolor=red];
subgraph cluster_6 {
color=blue
11 [label="Enter block"];
12 [label="Access variable R|<local>/a|"];
13 [label="Access variable R|/A.b|"];
14 [label="Enter safe call"];
subgraph cluster_7 {
color=blue
15 [label="Function call arguments enter"];
16 [label="Postponed enter to lambda"];
subgraph cluster_8 {
color=blue
17 [label="Enter function <anonymous>" style="filled" fillcolor=red];
subgraph cluster_9 {
color=blue
18 [label="Enter block"];
subgraph cluster_10 {
color=blue
19 [label="Function call arguments enter"];
20 [label="Access variable R|<local>/a|"];
21 [label="Access variable R|<local>/it|"];
22 [label="Function call arguments exit"];
}
23 [label="Function call: R|/C.C|(...)" style="filled" fillcolor=yellow];
24 [label="Exit block"];
}
25 [label="Exit function <anonymous>" style="filled" fillcolor=red];
}
26 [label="Function call arguments exit"];
}
27 [label="Postponed exit from lambda"];
28 [label="Function call: $subj$.R|kotlin/let|<R|B|, R|C|>(...)" style="filled" fillcolor=yellow];
29 [label="Exit safe call"];
30 [label="Variable declaration: lval c: R|C?|"];
31 [label="Exit block"];
}
32 [label="Exit init block" style="filled" fillcolor=red];
}
33 [label="Exit class C" style="filled" fillcolor=red];
}
6 -> {7} [color=green];
6 -> {33} [style=dotted];
6 -> {7 30} [style=dashed];
6 -> {7 10} [style=dashed];
7 -> {8};
8 -> {9};
9 -> {10};
10 -> {11 26};
9 -> {10} [color=green];
10 -> {11};
11 -> {12};
12 -> {13};
13 -> {14 23};
13 -> {24} [style=dotted];
13 -> {14} [style=dashed];
13 -> {14 29};
14 -> {15};
15 -> {16};
16 -> {17};
16 -> {17 26};
16 -> {27} [style=dotted];
16 -> {17} [style=dashed];
17 -> {18};
18 -> {19};
19 -> {20};
20 -> {21};
21 -> {22};
22 -> {24};
23 -> {25};
24 -> {25} [label="Postponed"];
25 -> {26};
26 -> {27};
27 -> {28};
22 -> {23};
23 -> {24};
24 -> {25};
25 -> {27};
26 -> {28};
27 -> {28} [label="Postponed"];
28 -> {29};
29 -> {30} [color=green];
29 -> {30};
30 -> {31};
31 -> {32};
32 -> {33} [color=green];
@@ -15,21 +15,21 @@ digraph nestedClass_kt {
2 [label="Enter class OuterClass" style="filled" fillcolor=red];
subgraph cluster_2 {
color=blue
3 [label="Enter property" style="filled" fillcolor=red];
4 [label="Const: Int(1)"];
5 [label="Exit property" style="filled" fillcolor=red];
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];
}
subgraph cluster_3 {
color=blue
6 [label="Enter property" style="filled" fillcolor=red];
7 [label="Access variable R|/OuterClass.outerProperty|"];
7 [label="Const: Int(1)"];
8 [label="Exit property" style="filled" fillcolor=red];
}
subgraph cluster_4 {
color=blue
9 [label="Enter function <init>" style="filled" fillcolor=red];
10 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=yellow];
11 [label="Exit function <init>" style="filled" fillcolor=red];
9 [label="Enter property" style="filled" fillcolor=red];
10 [label="Access variable R|/OuterClass.outerProperty|"];
11 [label="Exit property" style="filled" fillcolor=red];
}
12 [label="Exit class OuterClass" style="filled" fillcolor=red];
}
@@ -65,21 +65,21 @@ digraph nestedClass_kt {
17 [label="Enter class NestedClass" style="filled" fillcolor=red];
subgraph cluster_8 {
color=blue
18 [label="Enter property" style="filled" fillcolor=red];
19 [label="Const: Int(1)"];
20 [label="Exit property" style="filled" fillcolor=red];
18 [label="Enter function <init>" style="filled" fillcolor=red];
19 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=yellow];
20 [label="Exit function <init>" style="filled" fillcolor=red];
}
subgraph cluster_9 {
color=blue
21 [label="Enter property" style="filled" fillcolor=red];
22 [label="Access variable R|/OuterClass.NestedClass.nestedProperty|"];
22 [label="Const: Int(1)"];
23 [label="Exit property" style="filled" fillcolor=red];
}
subgraph cluster_10 {
color=blue
24 [label="Enter function <init>" style="filled" fillcolor=red];
25 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=yellow];
26 [label="Exit function <init>" style="filled" fillcolor=red];
24 [label="Enter property" style="filled" fillcolor=red];
25 [label="Access variable R|/OuterClass.NestedClass.nestedProperty|"];
26 [label="Exit property" style="filled" fillcolor=red];
}
27 [label="Exit class NestedClass" style="filled" fillcolor=red];
}
@@ -33,74 +33,74 @@ digraph postponedLambdaInConstructor_kt {
7 [label="Enter class B" style="filled" fillcolor=red];
subgraph cluster_4 {
color=blue
8 [label="Enter property" style="filled" fillcolor=red];
9 [label="Access variable R|<local>/s|"];
10 [label="Exit property" style="filled" fillcolor=red];
}
subgraph cluster_5 {
color=blue
11 [label="Enter function <init>" style="filled" fillcolor=red];
subgraph cluster_6 {
8 [label="Enter function <init>" style="filled" fillcolor=red];
subgraph cluster_5 {
color=blue
12 [label="Function call arguments enter"];
13 [label="Access variable R|<local>/s|"];
14 [label="Postponed enter to lambda"];
subgraph cluster_7 {
9 [label="Function call arguments enter"];
10 [label="Access variable R|<local>/s|"];
11 [label="Postponed enter to lambda"];
subgraph cluster_6 {
color=blue
15 [label="Enter function <anonymous>" style="filled" fillcolor=red];
subgraph cluster_8 {
12 [label="Enter function <anonymous>" style="filled" fillcolor=red];
subgraph cluster_7 {
color=blue
16 [label="Enter block"];
17 [label="Exit anonymous function expression"];
subgraph cluster_9 {
13 [label="Enter block"];
14 [label="Exit anonymous function expression"];
subgraph cluster_8 {
color=blue
18 [label="Enter function <anonymous>" style="filled" fillcolor=red];
subgraph cluster_10 {
15 [label="Enter function <anonymous>" style="filled" fillcolor=red];
subgraph cluster_9 {
color=blue
19 [label="Enter block"];
20 [label="Access variable R|<local>/it|"];
21 [label="Exit block"];
16 [label="Enter block"];
17 [label="Access variable R|<local>/it|"];
18 [label="Exit block"];
}
22 [label="Exit function <anonymous>" style="filled" fillcolor=red];
19 [label="Exit function <anonymous>" style="filled" fillcolor=red];
}
23 [label="Exit block"];
20 [label="Exit block"];
}
24 [label="Exit function <anonymous>" style="filled" fillcolor=red];
21 [label="Exit function <anonymous>" style="filled" fillcolor=red];
}
25 [label="Function call arguments exit"];
22 [label="Function call arguments exit"];
}
26 [label="Postponed exit from lambda"];
27 [label="Function call: R|<local>/s|.R|kotlin/let|<R|kotlin/String|, R|() -> kotlin/String|>(...)" style="filled" fillcolor=yellow];
28 [label="Delegated constructor call: super<R|A|>(...)" style="filled" fillcolor=yellow];
29 [label="Exit function <init>" style="filled" fillcolor=red];
23 [label="Postponed exit from lambda"];
24 [label="Function call: R|<local>/s|.R|kotlin/let|<R|kotlin/String|, R|() -> kotlin/String|>(...)" style="filled" fillcolor=yellow];
25 [label="Delegated constructor call: super<R|A|>(...)" style="filled" fillcolor=yellow];
26 [label="Exit function <init>" style="filled" fillcolor=red];
}
subgraph cluster_10 {
color=blue
27 [label="Enter property" style="filled" fillcolor=red];
28 [label="Access variable R|<local>/s|"];
29 [label="Exit property" style="filled" fillcolor=red];
}
30 [label="Exit class B" style="filled" fillcolor=red];
}
7 -> {8} [color=green];
7 -> {30} [style=dotted];
7 -> {8 11} [style=dashed];
7 -> {8 27} [style=dashed];
8 -> {9};
9 -> {10};
10 -> {11} [color=green];
11 -> {12};
10 -> {11};
11 -> {12 22};
11 -> {23} [style=dotted];
11 -> {12} [style=dashed];
12 -> {13};
13 -> {14};
14 -> {15 25};
14 -> {26} [style=dotted];
14 -> {15 20};
14 -> {15} [style=dashed];
15 -> {16};
16 -> {17};
17 -> {18 23};
17 -> {18} [style=dashed];
17 -> {18};
18 -> {19};
19 -> {20};
20 -> {21};
21 -> {22};
23 -> {24};
24 -> {26};
25 -> {27};
21 -> {23};
22 -> {24};
23 -> {24} [color=green];
23 -> {25} [color=red label="Postponed"];
24 -> {25};
25 -> {26};
26 -> {27} [color=green];
26 -> {28} [color=red label="Postponed"];
27 -> {28};
28 -> {29};
29 -> {30} [color=green];
@@ -50,28 +50,28 @@ digraph propertiesAndInitBlocks_kt {
21 [label="Enter class InitializerLocalClass" style="filled" fillcolor=red];
subgraph cluster_9 {
color=blue
22 [label="Enter init block" style="filled" fillcolor=red];
subgraph cluster_10 {
color=blue
23 [label="Enter block"];
subgraph cluster_11 {
color=blue
24 [label="Function call arguments enter"];
25 [label="Function call arguments exit"];
}
26 [label="Function call: R|java/lang/Exception.Exception|()" style="filled" fillcolor=yellow];
27 [label="Throw: throw R|java/lang/Exception.Exception|()"];
28 [label="Stub" style="filled" fillcolor=gray];
29 [label="Const: Int(1)" style="filled" fillcolor=gray];
30 [label="Exit block" style="filled" fillcolor=gray];
}
31 [label="Exit init block" style="filled" fillcolor=gray];
22 [label="Enter function <init>" style="filled" fillcolor=red];
23 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=yellow];
24 [label="Exit function <init>" style="filled" fillcolor=red];
}
subgraph cluster_12 {
subgraph cluster_10 {
color=blue
32 [label="Enter function <init>" style="filled" fillcolor=gray];
33 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=gray];
34 [label="Exit function <init>" style="filled" fillcolor=gray];
25 [label="Enter init block" style="filled" fillcolor=red];
subgraph cluster_11 {
color=blue
26 [label="Enter block"];
subgraph cluster_12 {
color=blue
27 [label="Function call arguments enter"];
28 [label="Function call arguments exit"];
}
29 [label="Function call: R|java/lang/Exception.Exception|()" style="filled" fillcolor=yellow];
30 [label="Throw: throw R|java/lang/Exception.Exception|()"];
31 [label="Stub" style="filled" fillcolor=gray];
32 [label="Const: Int(1)" style="filled" fillcolor=gray];
33 [label="Exit block" style="filled" fillcolor=gray];
}
34 [label="Exit init block" style="filled" fillcolor=gray];
}
35 [label="Exit class InitializerLocalClass" style="filled" fillcolor=gray];
}
@@ -181,17 +181,17 @@ digraph propertiesAndInitBlocks_kt {
19 -> {20} [style=dotted];
20 -> {52} [style=dotted];
21 -> {22};
21 -> {32} [color=red];
21 -> {25} [color=red];
21 -> {35} [style=dotted];
21 -> {22 32} [style=dashed];
21 -> {22 25} [style=dashed];
22 -> {23};
23 -> {24};
24 -> {25};
24 -> {25} [color=green];
25 -> {26};
26 -> {27};
27 -> {28} [style=dotted];
28 -> {29} [style=dotted];
29 -> {30} [style=dotted];
27 -> {28};
28 -> {29};
29 -> {30};
30 -> {31} [style=dotted];
31 -> {32} [style=dotted];
32 -> {33} [style=dotted];
@@ -317,27 +317,27 @@ digraph propertiesAndInitBlocks_kt {
101 [label="Enter class GetterLocalClass" style="filled" fillcolor=red];
subgraph cluster_35 {
color=blue
102 [label="Enter init block" style="filled" fillcolor=red];
subgraph cluster_36 {
color=blue
103 [label="Enter block"];
subgraph cluster_37 {
color=blue
104 [label="Function call arguments enter"];
105 [label="Function call arguments exit"];
}
106 [label="Function call: R|java/lang/Exception.Exception|()" style="filled" fillcolor=yellow];
107 [label="Throw: throw R|java/lang/Exception.Exception|()"];
108 [label="Stub" style="filled" fillcolor=gray];
109 [label="Exit block" style="filled" fillcolor=gray];
}
110 [label="Exit init block" style="filled" fillcolor=gray];
102 [label="Enter function <init>" style="filled" fillcolor=red];
103 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=yellow];
104 [label="Exit function <init>" style="filled" fillcolor=red];
}
subgraph cluster_38 {
subgraph cluster_36 {
color=blue
111 [label="Enter function <init>" style="filled" fillcolor=gray];
112 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=gray];
113 [label="Exit function <init>" style="filled" fillcolor=gray];
105 [label="Enter init block" style="filled" fillcolor=red];
subgraph cluster_37 {
color=blue
106 [label="Enter block"];
subgraph cluster_38 {
color=blue
107 [label="Function call arguments enter"];
108 [label="Function call arguments exit"];
}
109 [label="Function call: R|java/lang/Exception.Exception|()" style="filled" fillcolor=yellow];
110 [label="Throw: throw R|java/lang/Exception.Exception|()"];
111 [label="Stub" style="filled" fillcolor=gray];
112 [label="Exit block" style="filled" fillcolor=gray];
}
113 [label="Exit init block" style="filled" fillcolor=gray];
}
114 [label="Exit class GetterLocalClass" style="filled" fillcolor=gray];
}
@@ -347,17 +347,17 @@ digraph propertiesAndInitBlocks_kt {
98 -> {101} [style=dashed];
99 -> {100};
101 -> {102};
101 -> {111} [color=red];
101 -> {105} [color=red];
101 -> {114} [style=dotted];
101 -> {102 111} [style=dashed];
101 -> {102 105} [style=dashed];
102 -> {103};
103 -> {104};
104 -> {105};
104 -> {105} [color=green];
105 -> {106};
106 -> {107};
107 -> {108} [style=dotted];
108 -> {109} [style=dotted];
109 -> {110} [style=dotted];
107 -> {108};
108 -> {109};
109 -> {110};
110 -> {111} [style=dotted];
111 -> {112} [style=dotted];
112 -> {113} [style=dotted];