[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
@@ -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];