[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
@@ -27,27 +27,27 @@ digraph inAnonymousObject_kt {
7 [label="Enter class <anonymous object>" style="filled" fillcolor=red];
subgraph cluster_5 {
color=blue
8 [label="Enter property" style="filled" fillcolor=red];
9 [label="Access variable R|<local>/a|"];
10 [label="Exit property" style="filled" fillcolor=red];
8 [label="Enter function <init>" style="filled" fillcolor=red];
9 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=yellow];
10 [label="Exit function <init>" style="filled" fillcolor=red];
}
subgraph cluster_6 {
color=blue
11 [label="Enter init block" style="filled" fillcolor=red];
subgraph cluster_7 {
color=blue
12 [label="Enter block"];
13 [label="Access variable R|<local>/b|"];
14 [label="Assignment: R|/<anonymous>.leaked|"];
15 [label="Exit block"];
}
16 [label="Exit init block" style="filled" fillcolor=red];
11 [label="Enter property" style="filled" fillcolor=red];
12 [label="Access variable R|<local>/a|"];
13 [label="Exit property" style="filled" fillcolor=red];
}
subgraph cluster_8 {
subgraph cluster_7 {
color=blue
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];
14 [label="Enter init block" style="filled" fillcolor=red];
subgraph cluster_8 {
color=blue
15 [label="Enter block"];
16 [label="Access variable R|<local>/b|"];
17 [label="Assignment: R|/<anonymous>.leaked|"];
18 [label="Exit block"];
}
19 [label="Exit init block" style="filled" fillcolor=red];
}
20 [label="Exit class <anonymous object>" style="filled" fillcolor=red];
}
@@ -94,20 +94,20 @@ digraph inAnonymousObject_kt {
6 -> {21} [style=dotted];
6 -> {7} [style=dashed];
7 -> {8};
7 -> {11 17 32} [color=red];
7 -> {11 14 32} [color=red];
7 -> {20} [style=dotted];
7 -> {8 11 17} [style=dashed];
7 -> {8 11 14} [style=dashed];
8 -> {9};
9 -> {10};
10 -> {11} [color=green];
10 -> {20} [color=red];
11 -> {12};
12 -> {13};
13 -> {14};
13 -> {14} [color=green];
13 -> {20} [color=red];
14 -> {15};
15 -> {16};
16 -> {17} [color=green];
16 -> {20} [color=red];
16 -> {17};
17 -> {18};
18 -> {19};
19 -> {20};