[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
@@ -89,153 +89,153 @@ digraph delegateWithAnonymousObject_kt {
25 [label="Enter class IssuesListUserProfile" style="filled" fillcolor=red];
subgraph cluster_10 {
color=blue
26 [label="Enter property" style="filled" fillcolor=red];
subgraph cluster_11 {
color=blue
27 [label="Function call arguments enter"];
28 [label="Postponed enter to lambda"];
subgraph cluster_12 {
color=blue
29 [label="Enter function <anonymous>" style="filled" fillcolor=red];
subgraph cluster_13 {
color=blue
30 [label="Enter block"];
31 [label="Enter anonymous object"];
subgraph cluster_14 {
color=blue
32 [label="Enter class <anonymous object>" style="filled" fillcolor=red];
subgraph cluster_15 {
color=blue
33 [label="Enter function <init>" style="filled" fillcolor=red];
34 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=yellow];
35 [label="Exit function <init>" style="filled" fillcolor=red];
}
36 [label="Exit class <anonymous object>" style="filled" fillcolor=red];
}
37 [label="Exit anonymous object expression"];
38 [label="Exit block"];
}
39 [label="Exit function <anonymous>" style="filled" fillcolor=red];
}
subgraph cluster_16 {
color=blue
40 [label="Enter function setValue" style="filled" fillcolor=red];
subgraph cluster_17 {
color=blue
41 [label="Enter block"];
subgraph cluster_18 {
color=blue
42 [label="Function call arguments enter"];
subgraph cluster_19 {
color=blue
43 [label="Function call arguments enter"];
44 [label="Function call arguments exit"];
}
45 [label="Function call: R|/IssueListView.IssueListView|()" style="filled" fillcolor=yellow];
46 [label="Access variable R|<local>/value|"];
47 [label="Function call arguments exit"];
}
48 [label="Function call: R|/IssueListView.IssueListView|().R|/IssueListView.updateFrom|(...)" style="filled" fillcolor=yellow];
49 [label="Jump: ^setValue R|/IssueListView.IssueListView|().R|/IssueListView.updateFrom|(R|<local>/value|)"];
50 [label="Stub" style="filled" fillcolor=gray];
51 [label="Exit block" style="filled" fillcolor=gray];
}
52 [label="Exit function setValue" style="filled" fillcolor=red];
}
subgraph cluster_20 {
color=blue
53 [label="Enter function getValue" style="filled" fillcolor=red];
subgraph cluster_21 {
color=blue
54 [label="Enter block"];
subgraph cluster_22 {
color=blue
55 [label="Function call arguments enter"];
56 [label="Function call arguments exit"];
}
57 [label="Function call: R|/IssueListView.IssueListView|()" style="filled" fillcolor=yellow];
58 [label="Jump: ^getValue R|/IssueListView.IssueListView|()"];
59 [label="Stub" style="filled" fillcolor=gray];
60 [label="Exit block" style="filled" fillcolor=gray];
}
61 [label="Exit function getValue" style="filled" fillcolor=red];
}
62 [label="Function call arguments exit"];
}
63 [label="Postponed exit from lambda"];
64 [label="Function call: this@R|/IssuesListUserProfile|.R|/delegate|<R|IssuesListUserProfile|, R|IssuesListUserProfile|, R|IssueListView|>(...)" style="filled" fillcolor=yellow];
subgraph cluster_23 {
color=blue
65 [label="Function call arguments enter"];
66 [label="Function call arguments exit"];
}
67 [label="Function call: this@R|/IssuesListUserProfile|.R|/delegate|<R|IssuesListUserProfile|, R|IssuesListUserProfile|, R|IssueListView|>(...).R?C|special/error|(...)" style="filled" fillcolor=yellow];
68 [label="Exit property delegate" style="filled" fillcolor=yellow];
69 [label="Exit property" style="filled" fillcolor=red];
26 [label="Enter function <init>" style="filled" fillcolor=red];
27 [label="Delegated constructor call: super<R|DelegateProvider<IssuesListUserProfile>|>()" style="filled" fillcolor=yellow];
28 [label="Exit function <init>" style="filled" fillcolor=red];
}
subgraph cluster_24 {
subgraph cluster_11 {
color=blue
70 [label="Enter function <init>" style="filled" fillcolor=red];
71 [label="Delegated constructor call: super<R|DelegateProvider<IssuesListUserProfile>|>()" style="filled" fillcolor=yellow];
72 [label="Exit function <init>" style="filled" fillcolor=red];
29 [label="Enter property" style="filled" fillcolor=red];
subgraph cluster_12 {
color=blue
30 [label="Function call arguments enter"];
31 [label="Postponed enter to lambda"];
subgraph cluster_13 {
color=blue
32 [label="Enter function <anonymous>" style="filled" fillcolor=red];
subgraph cluster_14 {
color=blue
33 [label="Enter block"];
34 [label="Enter anonymous object"];
subgraph cluster_15 {
color=blue
35 [label="Enter class <anonymous object>" style="filled" fillcolor=red];
subgraph cluster_16 {
color=blue
36 [label="Enter function <init>" style="filled" fillcolor=red];
37 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=yellow];
38 [label="Exit function <init>" style="filled" fillcolor=red];
}
39 [label="Exit class <anonymous object>" style="filled" fillcolor=red];
}
40 [label="Exit anonymous object expression"];
41 [label="Exit block"];
}
42 [label="Exit function <anonymous>" style="filled" fillcolor=red];
}
subgraph cluster_17 {
color=blue
43 [label="Enter function setValue" style="filled" fillcolor=red];
subgraph cluster_18 {
color=blue
44 [label="Enter block"];
subgraph cluster_19 {
color=blue
45 [label="Function call arguments enter"];
subgraph cluster_20 {
color=blue
46 [label="Function call arguments enter"];
47 [label="Function call arguments exit"];
}
48 [label="Function call: R|/IssueListView.IssueListView|()" style="filled" fillcolor=yellow];
49 [label="Access variable R|<local>/value|"];
50 [label="Function call arguments exit"];
}
51 [label="Function call: R|/IssueListView.IssueListView|().R|/IssueListView.updateFrom|(...)" style="filled" fillcolor=yellow];
52 [label="Jump: ^setValue R|/IssueListView.IssueListView|().R|/IssueListView.updateFrom|(R|<local>/value|)"];
53 [label="Stub" style="filled" fillcolor=gray];
54 [label="Exit block" style="filled" fillcolor=gray];
}
55 [label="Exit function setValue" style="filled" fillcolor=red];
}
subgraph cluster_21 {
color=blue
56 [label="Enter function getValue" style="filled" fillcolor=red];
subgraph cluster_22 {
color=blue
57 [label="Enter block"];
subgraph cluster_23 {
color=blue
58 [label="Function call arguments enter"];
59 [label="Function call arguments exit"];
}
60 [label="Function call: R|/IssueListView.IssueListView|()" style="filled" fillcolor=yellow];
61 [label="Jump: ^getValue R|/IssueListView.IssueListView|()"];
62 [label="Stub" style="filled" fillcolor=gray];
63 [label="Exit block" style="filled" fillcolor=gray];
}
64 [label="Exit function getValue" style="filled" fillcolor=red];
}
65 [label="Function call arguments exit"];
}
66 [label="Postponed exit from lambda"];
67 [label="Function call: this@R|/IssuesListUserProfile|.R|/delegate|<R|IssuesListUserProfile|, R|IssuesListUserProfile|, R|IssueListView|>(...)" style="filled" fillcolor=yellow];
subgraph cluster_24 {
color=blue
68 [label="Function call arguments enter"];
69 [label="Function call arguments exit"];
}
70 [label="Function call: this@R|/IssuesListUserProfile|.R|/delegate|<R|IssuesListUserProfile|, R|IssuesListUserProfile|, R|IssueListView|>(...).R?C|special/error|(...)" style="filled" fillcolor=yellow];
71 [label="Exit property delegate" style="filled" fillcolor=yellow];
72 [label="Exit property" style="filled" fillcolor=red];
}
73 [label="Exit class IssuesListUserProfile" style="filled" fillcolor=red];
}
25 -> {26} [color=green];
25 -> {73} [style=dotted];
25 -> {26 70} [style=dashed];
25 -> {26 29} [style=dashed];
26 -> {27};
27 -> {28};
28 -> {29 62 63};
28 -> {29} [style=dashed];
28 -> {29} [color=green];
29 -> {30};
30 -> {31};
31 -> {32};
31 -> {37} [style=dotted];
31 -> {32 65 66};
31 -> {32} [style=dashed];
32 -> {33};
32 -> {40 53} [color=red];
32 -> {36} [style=dotted];
32 -> {33} [style=dashed];
33 -> {34};
34 -> {35};
34 -> {40} [style=dotted];
34 -> {35} [style=dashed];
35 -> {36};
35 -> {43 56} [color=red];
35 -> {39} [style=dotted];
35 -> {36} [style=dashed];
36 -> {37};
36 -> {40 53} [color=green];
36 -> {40 53} [style=dashed];
37 -> {38};
38 -> {39};
39 -> {40};
39 -> {43 56} [color=green];
39 -> {43 56} [style=dashed];
40 -> {41};
41 -> {42};
42 -> {43};
43 -> {44};
44 -> {45};
45 -> {46};
46 -> {47};
47 -> {48};
48 -> {49};
49 -> {52};
49 -> {50} [style=dotted];
50 -> {51} [style=dotted];
51 -> {52} [style=dotted];
53 -> {54};
54 -> {55};
55 -> {56};
49 -> {50};
50 -> {51};
51 -> {52};
52 -> {55};
52 -> {53} [style=dotted];
53 -> {54} [style=dotted];
54 -> {55} [style=dotted];
56 -> {57};
57 -> {58};
58 -> {61};
58 -> {59} [style=dotted];
59 -> {60} [style=dotted];
60 -> {61} [style=dotted];
62 -> {64};
63 -> {64} [color=green];
63 -> {68} [color=red label="Postponed"];
64 -> {65};
65 -> {66};
66 -> {67};
58 -> {59};
59 -> {60};
60 -> {61};
61 -> {64};
61 -> {62} [style=dotted];
62 -> {63} [style=dotted];
63 -> {64} [style=dotted];
65 -> {67};
66 -> {67} [color=green];
66 -> {71} [color=red label="Postponed"];
67 -> {68};
68 -> {69};
69 -> {70} [color=green];
69 -> {70};
70 -> {71};
71 -> {72};
72 -> {73} [color=green];