[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
@@ -423,15 +423,15 @@ digraph boundSmartcasts_kt {
149 [label="Enter class D" style="filled" fillcolor=red];
subgraph cluster_40 {
color=blue
150 [label="Enter property" style="filled" fillcolor=red];
151 [label="Access variable R|<local>/any|"];
152 [label="Exit property" style="filled" fillcolor=red];
150 [label="Enter function <init>" style="filled" fillcolor=red];
151 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=yellow];
152 [label="Exit function <init>" style="filled" fillcolor=red];
}
subgraph cluster_41 {
color=blue
153 [label="Enter function <init>" style="filled" fillcolor=red];
154 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=yellow];
155 [label="Exit function <init>" style="filled" fillcolor=red];
153 [label="Enter property" style="filled" fillcolor=red];
154 [label="Access variable R|<local>/any|"];
155 [label="Exit property" style="filled" fillcolor=red];
}
156 [label="Exit class D" style="filled" fillcolor=red];
}
@@ -15,15 +15,15 @@ digraph boundSmartcastsInBranches_kt {
2 [label="Enter class A" style="filled" fillcolor=red];
subgraph cluster_2 {
color=blue
3 [label="Enter property" style="filled" fillcolor=red];
4 [label="Const: String()"];
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 function <init>" style="filled" fillcolor=red];
7 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=yellow];
8 [label="Exit function <init>" style="filled" fillcolor=red];
6 [label="Enter property" style="filled" fillcolor=red];
7 [label="Const: String()"];
8 [label="Exit property" style="filled" fillcolor=red];
}
9 [label="Exit class A" style="filled" fillcolor=red];
}
@@ -33,15 +33,15 @@ digraph functionCallBound_kt {
7 [label="Enter class Sub" style="filled" fillcolor=red];
subgraph cluster_4 {
color=blue
8 [label="Enter property" style="filled" fillcolor=red];
9 [label="Access variable R|<local>/data|"];
10 [label="Exit property" style="filled" fillcolor=red];
8 [label="Enter function <init>" style="filled" fillcolor=red];
9 [label="Delegated constructor call: super<R|Base|>()" style="filled" fillcolor=yellow];
10 [label="Exit function <init>" style="filled" fillcolor=red];
}
subgraph cluster_5 {
color=blue
11 [label="Enter function <init>" style="filled" fillcolor=red];
12 [label="Delegated constructor call: super<R|Base|>()" style="filled" fillcolor=yellow];
13 [label="Exit function <init>" style="filled" fillcolor=red];
11 [label="Enter property" style="filled" fillcolor=red];
12 [label="Access variable R|<local>/data|"];
13 [label="Exit property" style="filled" fillcolor=red];
}
14 [label="Exit class Sub" style="filled" fillcolor=red];
}
@@ -33,15 +33,15 @@ digraph lambdaInWhenBranch_kt {
7 [label="Enter class SubClass1" style="filled" fillcolor=red];
subgraph cluster_4 {
color=blue
8 [label="Enter property" style="filled" fillcolor=red];
9 [label="Access variable R|<local>/t|"];
10 [label="Exit property" style="filled" fillcolor=red];
8 [label="Enter function <init>" style="filled" fillcolor=red];
9 [label="Delegated constructor call: super<R|Sealed|>()" style="filled" fillcolor=yellow];
10 [label="Exit function <init>" style="filled" fillcolor=red];
}
subgraph cluster_5 {
color=blue
11 [label="Enter function <init>" style="filled" fillcolor=red];
12 [label="Delegated constructor call: super<R|Sealed|>()" style="filled" fillcolor=yellow];
13 [label="Exit function <init>" style="filled" fillcolor=red];
11 [label="Enter property" style="filled" fillcolor=red];
12 [label="Access variable R|<local>/t|"];
13 [label="Exit property" style="filled" fillcolor=red];
}
14 [label="Exit class SubClass1" style="filled" fillcolor=red];
}
@@ -64,15 +64,15 @@ digraph nullability_kt {
16 [label="Enter class QImpl" style="filled" fillcolor=red];
subgraph cluster_9 {
color=blue
17 [label="Enter property" style="filled" fillcolor=red];
18 [label="Access variable R|<local>/data|"];
19 [label="Exit property" style="filled" fillcolor=red];
17 [label="Enter function <init>" style="filled" fillcolor=red];
18 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=yellow];
19 [label="Exit function <init>" style="filled" fillcolor=red];
}
subgraph cluster_10 {
color=blue
20 [label="Enter function <init>" style="filled" fillcolor=red];
21 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=yellow];
22 [label="Exit function <init>" style="filled" fillcolor=red];
20 [label="Enter property" style="filled" fillcolor=red];
21 [label="Access variable R|<local>/data|"];
22 [label="Exit property" style="filled" fillcolor=red];
}
23 [label="Exit class QImpl" style="filled" fillcolor=red];
}
@@ -112,15 +112,15 @@ digraph nullability_kt {
31 [label="Enter class QImplMutable" style="filled" fillcolor=red];
subgraph cluster_14 {
color=blue
32 [label="Enter property" style="filled" fillcolor=red];
33 [label="Access variable R|<local>/data|"];
34 [label="Exit property" style="filled" fillcolor=red];
32 [label="Enter function <init>" style="filled" fillcolor=red];
33 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=yellow];
34 [label="Exit function <init>" style="filled" fillcolor=red];
}
subgraph cluster_15 {
color=blue
35 [label="Enter function <init>" style="filled" fillcolor=red];
36 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=yellow];
37 [label="Exit function <init>" style="filled" fillcolor=red];
35 [label="Enter property" style="filled" fillcolor=red];
36 [label="Access variable R|<local>/data|"];
37 [label="Exit property" style="filled" fillcolor=red];
}
38 [label="Exit class QImplMutable" style="filled" fillcolor=red];
}
@@ -15,15 +15,15 @@ digraph assignSafeCall_kt {
2 [label="Enter class A" 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 function <init>" style="filled" fillcolor=red];
7 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=yellow];
8 [label="Exit function <init>" style="filled" fillcolor=red];
6 [label="Enter property" style="filled" fillcolor=red];
7 [label="Const: Int(1)"];
8 [label="Exit property" style="filled" fillcolor=red];
}
9 [label="Exit class A" style="filled" fillcolor=red];
}
@@ -65,43 +65,43 @@ digraph smartCastInInit_kt {
18 [label="Enter class Main" style="filled" fillcolor=red];
subgraph cluster_8 {
color=blue
19 [label="Enter init block" style="filled" fillcolor=red];
subgraph cluster_9 {
19 [label="Enter function <init>" style="filled" fillcolor=red];
20 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=yellow];
21 [label="Exit function <init>" style="filled" fillcolor=red];
}
subgraph cluster_9 {
color=blue
22 [label="Enter init block" style="filled" fillcolor=red];
subgraph cluster_10 {
color=blue
20 [label="Enter block"];
subgraph cluster_10 {
color=blue
21 [label="Function call arguments enter"];
22 [label="Function call arguments exit"];
}
23 [label="Function call: R|/s|()" style="filled" fillcolor=yellow];
24 [label="Assignment: R|/Main.x|"];
23 [label="Enter block"];
subgraph cluster_11 {
color=blue
25 [label="Function call arguments enter"];
26 [label="Access variable R|/Main.x|"];
27 [label="Smart cast: this@R|/Main|.R|/Main.x|"];
28 [label="Function call arguments exit"];
24 [label="Function call arguments enter"];
25 [label="Function call arguments exit"];
}
29 [label="Function call: this@R|/Main|.R|/Main.x|.R|/S.foo|()" style="filled" fillcolor=yellow];
30 [label="Exit block"];
26 [label="Function call: R|/s|()" style="filled" fillcolor=yellow];
27 [label="Assignment: R|/Main.x|"];
subgraph cluster_12 {
color=blue
28 [label="Function call arguments enter"];
29 [label="Access variable R|/Main.x|"];
30 [label="Smart cast: this@R|/Main|.R|/Main.x|"];
31 [label="Function call arguments exit"];
}
32 [label="Function call: this@R|/Main|.R|/Main.x|.R|/S.foo|()" style="filled" fillcolor=yellow];
33 [label="Exit block"];
}
31 [label="Exit init block" style="filled" fillcolor=red];
}
subgraph cluster_12 {
color=blue
32 [label="Enter function <init>" style="filled" fillcolor=red];
33 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=yellow];
34 [label="Exit function <init>" style="filled" fillcolor=red];
34 [label="Exit init block" style="filled" fillcolor=red];
}
35 [label="Exit class Main" style="filled" fillcolor=red];
}
18 -> {19} [color=green];
18 -> {35} [style=dotted];
18 -> {19 32} [style=dashed];
18 -> {19 22} [style=dashed];
19 -> {20};
20 -> {21};
21 -> {22};
21 -> {22} [color=green];
22 -> {23};
23 -> {24};
24 -> {25};
@@ -111,7 +111,7 @@ digraph smartCastInInit_kt {
28 -> {29};
29 -> {30};
30 -> {31};
31 -> {32} [color=green];
31 -> {32};
32 -> {33};
33 -> {34};
34 -> {35} [color=green];
@@ -15,21 +15,21 @@ digraph smartcastInByClause_kt {
2 [label="Enter class A" style="filled" fillcolor=red];
subgraph cluster_2 {
color=blue
3 [label="Enter property" style="filled" fillcolor=red];
4 [label="Access variable R|<local>/path|"];
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|<local>/index|"];
7 [label="Access variable R|<local>/path|"];
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|<local>/index|"];
11 [label="Exit property" style="filled" fillcolor=red];
}
12 [label="Exit class A" style="filled" fillcolor=red];
}
@@ -58,15 +58,15 @@ digraph smartcastInByClause_kt {
15 [label="Enter class Derived" style="filled" fillcolor=red];
subgraph cluster_7 {
color=blue
16 [label="Enter property" style="filled" fillcolor=red];
17 [label="Access variable R|<local>/index|"];
18 [label="Exit property" style="filled" fillcolor=red];
16 [label="Enter function <init>" style="filled" fillcolor=red];
17 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=yellow];
18 [label="Exit function <init>" style="filled" fillcolor=red];
}
subgraph cluster_8 {
color=blue
19 [label="Enter function <init>" style="filled" fillcolor=red];
20 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=yellow];
21 [label="Exit function <init>" style="filled" fillcolor=red];
19 [label="Enter property" style="filled" fillcolor=red];
20 [label="Access variable R|<local>/index|"];
21 [label="Exit property" style="filled" fillcolor=red];
}
22 [label="Exit class Derived" style="filled" fillcolor=red];
}
@@ -113,31 +113,31 @@ digraph smartcastInByClause_kt {
44 [label="Enter class <anonymous object>" style="filled" fillcolor=red];
subgraph cluster_13 {
color=blue
45 [label="Enter field" style="filled" fillcolor=red];
subgraph cluster_14 {
color=blue
46 [label="Function call arguments enter"];
47 [label="Access variable R|<local>/a|"];
48 [label="Smart cast: R|<local>/a|"];
49 [label="Access variable R|/A.index|"];
50 [label="Function call arguments exit"];
}
51 [label="Function call: R|/Derived.Derived|(...)" style="filled" fillcolor=yellow];
52 [label="Exit field" style="filled" fillcolor=red];
45 [label="Enter function <init>" style="filled" fillcolor=red];
46 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=yellow];
47 [label="Exit function <init>" style="filled" fillcolor=red];
}
subgraph cluster_15 {
subgraph cluster_14 {
color=blue
53 [label="Enter property" style="filled" fillcolor=red];
54 [label="Access variable R|<local>/a|"];
55 [label="Smart cast: R|<local>/a|"];
56 [label="Access variable R|/A.index|"];
57 [label="Exit property" style="filled" fillcolor=red];
48 [label="Enter field" style="filled" fillcolor=red];
subgraph cluster_15 {
color=blue
49 [label="Function call arguments enter"];
50 [label="Access variable R|<local>/a|"];
51 [label="Smart cast: R|<local>/a|"];
52 [label="Access variable R|/A.index|"];
53 [label="Function call arguments exit"];
}
54 [label="Function call: R|/Derived.Derived|(...)" style="filled" fillcolor=yellow];
55 [label="Exit field" style="filled" fillcolor=red];
}
subgraph cluster_16 {
color=blue
58 [label="Enter function <init>" style="filled" fillcolor=red];
59 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=yellow];
60 [label="Exit function <init>" style="filled" fillcolor=red];
56 [label="Enter property" style="filled" fillcolor=red];
57 [label="Access variable R|<local>/a|"];
58 [label="Smart cast: R|<local>/a|"];
59 [label="Access variable R|/A.index|"];
60 [label="Exit property" style="filled" fillcolor=red];
}
61 [label="Exit class <anonymous object>" style="filled" fillcolor=red];
}
@@ -207,24 +207,24 @@ digraph smartcastInByClause_kt {
43 -> {62} [style=dotted];
43 -> {44} [style=dashed];
44 -> {45};
44 -> {53 58 67} [color=red];
44 -> {48 56 67} [color=red];
44 -> {61} [style=dotted];
44 -> {45 53 58} [style=dashed];
44 -> {45 48 56} [style=dashed];
45 -> {46};
46 -> {47};
47 -> {48};
47 -> {48} [color=green];
47 -> {61} [color=red];
48 -> {49};
49 -> {50};
50 -> {51};
51 -> {52};
52 -> {53} [color=green];
52 -> {61} [color=red];
52 -> {53};
53 -> {54};
54 -> {55};
55 -> {56};
55 -> {56} [color=green];
55 -> {61} [color=red];
56 -> {57};
57 -> {58} [color=green];
57 -> {61} [color=red];
57 -> {58};
58 -> {59};
59 -> {60};
60 -> {61};
@@ -133,21 +133,21 @@ digraph smartcastToNothing_kt {
43 [label="Enter class A" style="filled" fillcolor=red];
subgraph cluster_13 {
color=blue
44 [label="Enter property" style="filled" fillcolor=red];
45 [label="Const: Int(1)"];
46 [label="Exit property" style="filled" fillcolor=red];
44 [label="Enter function <init>" style="filled" fillcolor=red];
45 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=yellow];
46 [label="Exit function <init>" style="filled" fillcolor=red];
}
subgraph cluster_14 {
color=blue
47 [label="Enter property" style="filled" fillcolor=red];
48 [label="Const: Boolean(true)"];
48 [label="Const: Int(1)"];
49 [label="Exit property" style="filled" fillcolor=red];
}
subgraph cluster_15 {
color=blue
50 [label="Enter function <init>" style="filled" fillcolor=red];
51 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=yellow];
52 [label="Exit function <init>" style="filled" fillcolor=red];
50 [label="Enter property" style="filled" fillcolor=red];
51 [label="Const: Boolean(true)"];
52 [label="Exit property" style="filled" fillcolor=red];
}
53 [label="Exit class A" style="filled" fillcolor=red];
}
@@ -15,15 +15,15 @@ digraph overridenOpenVal_kt {
2 [label="Enter class A" style="filled" fillcolor=red];
subgraph cluster_2 {
color=blue
3 [label="Enter property" style="filled" fillcolor=red];
4 [label="Access variable R|<local>/x|"];
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 function <init>" style="filled" fillcolor=red];
7 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=yellow];
8 [label="Exit function <init>" style="filled" fillcolor=red];
6 [label="Enter property" style="filled" fillcolor=red];
7 [label="Access variable R|<local>/x|"];
8 [label="Exit property" style="filled" fillcolor=red];
}
9 [label="Exit class A" style="filled" fillcolor=red];
}