FIR DFA: split flow for postponed lambdas from a single node
This removes the need for hacks around the order in which function call arguments are visited, fixes called-in-place lambda arguments for augmented assignment operators, and makes CFG dumps a bit prettier.
This commit is contained in:
+431
-463
File diff suppressed because it is too large
Load Diff
+34
-36
@@ -5,26 +5,26 @@ digraph lambdaAsReturnOfLambda_kt {
|
||||
|
||||
subgraph cluster_0 {
|
||||
color=red
|
||||
14 [label="Enter property" style="filled" fillcolor=red];
|
||||
15 [label="Postponed enter to lambda"];
|
||||
13 [label="Enter property" style="filled" fillcolor=red];
|
||||
14 [label="Postponed enter to lambda"];
|
||||
subgraph cluster_1 {
|
||||
color=blue
|
||||
0 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
|
||||
subgraph cluster_2 {
|
||||
color=blue
|
||||
1 [label="Enter block"];
|
||||
2 [label="Postponed enter to lambda"];
|
||||
2 [label="Exit anonymous function expression"];
|
||||
subgraph cluster_3 {
|
||||
color=blue
|
||||
8 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
|
||||
7 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
|
||||
subgraph cluster_4 {
|
||||
color=blue
|
||||
9 [label="Enter block"];
|
||||
10 [label="Access variable R|<local>/foo|"];
|
||||
11 [label="Function call: R|/bar|(...)" style="filled" fillcolor=yellow];
|
||||
12 [label="Exit block"];
|
||||
8 [label="Enter block"];
|
||||
9 [label="Access variable R|<local>/foo|"];
|
||||
10 [label="Function call: R|/bar|(...)" style="filled" fillcolor=yellow];
|
||||
11 [label="Exit block"];
|
||||
}
|
||||
13 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
|
||||
12 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
|
||||
}
|
||||
3 [label="Jump: ^@run lambda@fun <anonymous>(foo: R|kotlin/String|): R|kotlin/Unit| <inline=Unknown> {
|
||||
R|/bar|(R|<local>/foo|)
|
||||
@@ -35,64 +35,62 @@ digraph lambdaAsReturnOfLambda_kt {
|
||||
}
|
||||
6 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
|
||||
}
|
||||
7 [label="Postponed exit from lambda"];
|
||||
16 [label="Postponed exit from lambda"];
|
||||
17 [label="Function call: R|/run|<R|(kotlin/String) -> kotlin/Unit|>(...)" style="filled" fillcolor=yellow];
|
||||
18 [label="Exit property" style="filled" fillcolor=red];
|
||||
15 [label="Postponed exit from lambda"];
|
||||
16 [label="Function call: R|/run|<R|(kotlin/String) -> kotlin/Unit|>(...)" style="filled" fillcolor=yellow];
|
||||
17 [label="Exit property" style="filled" fillcolor=red];
|
||||
}
|
||||
14 -> {15};
|
||||
15 -> {16 0 17};
|
||||
15 -> {0} [style=dashed];
|
||||
13 -> {14};
|
||||
14 -> {15 0 16};
|
||||
14 -> {0} [style=dashed];
|
||||
15 -> {16};
|
||||
16 -> {17};
|
||||
17 -> {18};
|
||||
0 -> {1};
|
||||
1 -> {2};
|
||||
2 -> {7 3 8};
|
||||
2 -> {8} [style=dashed];
|
||||
2 -> {3 7};
|
||||
2 -> {7} [style=dashed];
|
||||
3 -> {6};
|
||||
3 -> {4} [style=dotted];
|
||||
4 -> {5} [style=dotted];
|
||||
5 -> {6} [style=dotted];
|
||||
7 -> {17};
|
||||
7 -> {8};
|
||||
8 -> {9};
|
||||
9 -> {10};
|
||||
10 -> {11};
|
||||
11 -> {12};
|
||||
12 -> {13};
|
||||
|
||||
subgraph cluster_5 {
|
||||
color=red
|
||||
19 [label="Enter function bar" style="filled" fillcolor=red];
|
||||
18 [label="Enter function bar" style="filled" fillcolor=red];
|
||||
subgraph cluster_6 {
|
||||
color=blue
|
||||
20 [label="Enter block"];
|
||||
21 [label="Exit block"];
|
||||
19 [label="Enter block"];
|
||||
20 [label="Exit block"];
|
||||
}
|
||||
22 [label="Exit function bar" style="filled" fillcolor=red];
|
||||
21 [label="Exit function bar" style="filled" fillcolor=red];
|
||||
}
|
||||
18 -> {19};
|
||||
19 -> {20};
|
||||
20 -> {21};
|
||||
21 -> {22};
|
||||
|
||||
subgraph cluster_7 {
|
||||
color=red
|
||||
23 [label="Enter function run" style="filled" fillcolor=red];
|
||||
22 [label="Enter function run" style="filled" fillcolor=red];
|
||||
subgraph cluster_8 {
|
||||
color=blue
|
||||
24 [label="Enter block"];
|
||||
25 [label="Function call: R|<local>/block|.R|SubstitutionOverride<kotlin/Function0.invoke: R|R|>|()" style="filled" fillcolor=yellow];
|
||||
26 [label="Jump: ^run R|<local>/block|.R|SubstitutionOverride<kotlin/Function0.invoke: R|R|>|()"];
|
||||
27 [label="Stub" style="filled" fillcolor=gray];
|
||||
28 [label="Exit block" style="filled" fillcolor=gray];
|
||||
23 [label="Enter block"];
|
||||
24 [label="Function call: R|<local>/block|.R|SubstitutionOverride<kotlin/Function0.invoke: R|R|>|()" style="filled" fillcolor=yellow];
|
||||
25 [label="Jump: ^run R|<local>/block|.R|SubstitutionOverride<kotlin/Function0.invoke: R|R|>|()"];
|
||||
26 [label="Stub" style="filled" fillcolor=gray];
|
||||
27 [label="Exit block" style="filled" fillcolor=gray];
|
||||
}
|
||||
29 [label="Exit function run" style="filled" fillcolor=red];
|
||||
28 [label="Exit function run" style="filled" fillcolor=red];
|
||||
}
|
||||
22 -> {23};
|
||||
23 -> {24};
|
||||
24 -> {25};
|
||||
25 -> {26};
|
||||
26 -> {29};
|
||||
25 -> {28};
|
||||
25 -> {26} [style=dotted];
|
||||
26 -> {27} [style=dotted];
|
||||
27 -> {28} [style=dotted];
|
||||
28 -> {29} [style=dotted];
|
||||
|
||||
}
|
||||
|
||||
+83
-85
@@ -113,30 +113,29 @@ digraph lambdas_kt {
|
||||
subgraph cluster_13 {
|
||||
color=blue
|
||||
39 [label="Enter block"];
|
||||
40 [label="Local function declaration test_2"];
|
||||
41 [label="Exit anonymous function expression"];
|
||||
42 [label="Variable declaration: lval lambda: R|() -> kotlin/Int|"];
|
||||
43 [label="Exit block"];
|
||||
40 [label="Exit anonymous function expression"];
|
||||
41 [label="Variable declaration: lval lambda: R|() -> kotlin/Int|"];
|
||||
42 [label="Exit block"];
|
||||
}
|
||||
44 [label="Exit when branch result"];
|
||||
45 [label="Exit when"];
|
||||
43 [label="Exit when branch result"];
|
||||
44 [label="Exit when"];
|
||||
}
|
||||
46 [label="Exit block"];
|
||||
45 [label="Exit block"];
|
||||
}
|
||||
47 [label="Exit function test_2" style="filled" fillcolor=red];
|
||||
46 [label="Exit function test_2" style="filled" fillcolor=red];
|
||||
}
|
||||
subgraph cluster_14 {
|
||||
color=blue
|
||||
48 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
|
||||
47 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
|
||||
subgraph cluster_15 {
|
||||
color=blue
|
||||
49 [label="Enter block"];
|
||||
50 [label="Access variable R|<local>/x|"];
|
||||
51 [label="Smart cast: R|<local>/x|"];
|
||||
52 [label="Function call: R|<local>/x|.R|kotlin/Int.inc|()" style="filled" fillcolor=yellow];
|
||||
53 [label="Exit block"];
|
||||
48 [label="Enter block"];
|
||||
49 [label="Access variable R|<local>/x|"];
|
||||
50 [label="Smart cast: R|<local>/x|"];
|
||||
51 [label="Function call: R|<local>/x|.R|kotlin/Int.inc|()" style="filled" fillcolor=yellow];
|
||||
52 [label="Exit block"];
|
||||
}
|
||||
54 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
|
||||
53 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
|
||||
}
|
||||
30 -> {31};
|
||||
31 -> {32};
|
||||
@@ -145,147 +144,146 @@ digraph lambdas_kt {
|
||||
34 -> {35};
|
||||
35 -> {36};
|
||||
36 -> {38 37};
|
||||
37 -> {45};
|
||||
37 -> {44};
|
||||
38 -> {39};
|
||||
39 -> {40};
|
||||
40 -> {48 41};
|
||||
40 -> {48} [style=dashed];
|
||||
40 -> {47 41};
|
||||
40 -> {47} [style=dashed];
|
||||
41 -> {42};
|
||||
42 -> {43};
|
||||
43 -> {44};
|
||||
44 -> {45};
|
||||
45 -> {46};
|
||||
46 -> {47};
|
||||
47 -> {48};
|
||||
48 -> {49};
|
||||
49 -> {50};
|
||||
50 -> {51};
|
||||
51 -> {52};
|
||||
52 -> {53};
|
||||
53 -> {54};
|
||||
|
||||
subgraph cluster_16 {
|
||||
color=red
|
||||
55 [label="Enter function getInt" style="filled" fillcolor=red];
|
||||
54 [label="Enter function getInt" style="filled" fillcolor=red];
|
||||
subgraph cluster_17 {
|
||||
color=blue
|
||||
56 [label="Enter block"];
|
||||
57 [label="Function call: R|<local>/block|.R|SubstitutionOverride<kotlin/Function0.invoke: R|kotlin/Unit|>|()" style="filled" fillcolor=yellow];
|
||||
58 [label="Const: Int(1)"];
|
||||
59 [label="Jump: ^getInt Int(1)"];
|
||||
60 [label="Stub" style="filled" fillcolor=gray];
|
||||
61 [label="Exit block" style="filled" fillcolor=gray];
|
||||
55 [label="Enter block"];
|
||||
56 [label="Function call: R|<local>/block|.R|SubstitutionOverride<kotlin/Function0.invoke: R|kotlin/Unit|>|()" style="filled" fillcolor=yellow];
|
||||
57 [label="Const: Int(1)"];
|
||||
58 [label="Jump: ^getInt Int(1)"];
|
||||
59 [label="Stub" style="filled" fillcolor=gray];
|
||||
60 [label="Exit block" style="filled" fillcolor=gray];
|
||||
}
|
||||
62 [label="Exit function getInt" style="filled" fillcolor=red];
|
||||
61 [label="Exit function getInt" style="filled" fillcolor=red];
|
||||
}
|
||||
54 -> {55};
|
||||
55 -> {56};
|
||||
56 -> {57};
|
||||
57 -> {58};
|
||||
58 -> {59};
|
||||
59 -> {62};
|
||||
58 -> {61};
|
||||
58 -> {59} [style=dotted];
|
||||
59 -> {60} [style=dotted];
|
||||
60 -> {61} [style=dotted];
|
||||
61 -> {62} [style=dotted];
|
||||
|
||||
subgraph cluster_18 {
|
||||
color=red
|
||||
63 [label="Enter function test_3" style="filled" fillcolor=red];
|
||||
62 [label="Enter function test_3" style="filled" fillcolor=red];
|
||||
subgraph cluster_19 {
|
||||
color=blue
|
||||
64 [label="Enter block"];
|
||||
65 [label="Postponed enter to lambda"];
|
||||
63 [label="Enter block"];
|
||||
64 [label="Postponed enter to lambda"];
|
||||
subgraph cluster_20 {
|
||||
color=blue
|
||||
72 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
|
||||
71 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
|
||||
subgraph cluster_21 {
|
||||
color=blue
|
||||
73 [label="Enter block"];
|
||||
74 [label="Const: Int(1)"];
|
||||
75 [label="Jump: ^test_3 Int(1)"];
|
||||
76 [label="Stub" style="filled" fillcolor=gray];
|
||||
77 [label="Exit block" style="filled" fillcolor=gray];
|
||||
72 [label="Enter block"];
|
||||
73 [label="Const: Int(1)"];
|
||||
74 [label="Jump: ^test_3 Int(1)"];
|
||||
75 [label="Stub" style="filled" fillcolor=gray];
|
||||
76 [label="Exit block" style="filled" fillcolor=gray];
|
||||
}
|
||||
78 [label="Exit function anonymousFunction" style="filled" fillcolor=red style="filled" fillcolor=gray];
|
||||
77 [label="Exit function anonymousFunction" style="filled" fillcolor=red style="filled" fillcolor=gray];
|
||||
}
|
||||
66 [label="Postponed exit from lambda"];
|
||||
67 [label="Function call: R|/getInt|(...)" style="filled" fillcolor=yellow];
|
||||
68 [label="Jump: ^test_3 R|/getInt|(<L> = getInt@fun <anonymous>(): R|kotlin/Unit| <inline=Inline, kind=UNKNOWN> {
|
||||
65 [label="Postponed exit from lambda"];
|
||||
66 [label="Function call: R|/getInt|(...)" style="filled" fillcolor=yellow];
|
||||
67 [label="Jump: ^test_3 R|/getInt|(<L> = getInt@fun <anonymous>(): R|kotlin/Unit| <inline=Inline, kind=UNKNOWN> {
|
||||
^test_3 Int(1)
|
||||
}
|
||||
)"];
|
||||
69 [label="Stub" style="filled" fillcolor=gray];
|
||||
70 [label="Exit block" style="filled" fillcolor=gray];
|
||||
68 [label="Stub" style="filled" fillcolor=gray];
|
||||
69 [label="Exit block" style="filled" fillcolor=gray];
|
||||
}
|
||||
71 [label="Exit function test_3" style="filled" fillcolor=red];
|
||||
70 [label="Exit function test_3" style="filled" fillcolor=red];
|
||||
}
|
||||
62 -> {63};
|
||||
63 -> {64};
|
||||
64 -> {65};
|
||||
65 -> {66 72 67};
|
||||
65 -> {72} [style=dashed];
|
||||
64 -> {65 71 66};
|
||||
64 -> {71} [style=dashed];
|
||||
65 -> {66};
|
||||
65 -> {64} [color=green style=dashed];
|
||||
66 -> {67};
|
||||
66 -> {65} [color=green style=dashed];
|
||||
67 -> {68};
|
||||
68 -> {71};
|
||||
67 -> {70};
|
||||
67 -> {68} [style=dotted];
|
||||
68 -> {69} [style=dotted];
|
||||
69 -> {70} [style=dotted];
|
||||
70 -> {71} [style=dotted];
|
||||
71 -> {72};
|
||||
72 -> {73};
|
||||
73 -> {74};
|
||||
74 -> {75};
|
||||
75 -> {71};
|
||||
74 -> {70};
|
||||
74 -> {75} [style=dotted];
|
||||
75 -> {76} [style=dotted];
|
||||
76 -> {77} [style=dotted];
|
||||
77 -> {78} [style=dotted];
|
||||
78 -> {66} [style=dotted];
|
||||
77 -> {65} [style=dotted];
|
||||
|
||||
subgraph cluster_22 {
|
||||
color=red
|
||||
79 [label="Enter function test_4" style="filled" fillcolor=red];
|
||||
78 [label="Enter function test_4" style="filled" fillcolor=red];
|
||||
subgraph cluster_23 {
|
||||
color=blue
|
||||
80 [label="Enter block"];
|
||||
81 [label="Postponed enter to lambda"];
|
||||
79 [label="Enter block"];
|
||||
80 [label="Postponed enter to lambda"];
|
||||
subgraph cluster_24 {
|
||||
color=blue
|
||||
88 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
|
||||
87 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
|
||||
subgraph cluster_25 {
|
||||
color=blue
|
||||
89 [label="Enter block"];
|
||||
90 [label="Const: Int(1)"];
|
||||
91 [label="Jump: ^test_4 Int(1)"];
|
||||
92 [label="Stub" style="filled" fillcolor=gray];
|
||||
93 [label="Exit block" style="filled" fillcolor=gray];
|
||||
88 [label="Enter block"];
|
||||
89 [label="Const: Int(1)"];
|
||||
90 [label="Jump: ^test_4 Int(1)"];
|
||||
91 [label="Stub" style="filled" fillcolor=gray];
|
||||
92 [label="Exit block" style="filled" fillcolor=gray];
|
||||
}
|
||||
94 [label="Exit function anonymousFunction" style="filled" fillcolor=red style="filled" fillcolor=gray];
|
||||
93 [label="Exit function anonymousFunction" style="filled" fillcolor=red style="filled" fillcolor=gray];
|
||||
}
|
||||
82 [label="Postponed exit from lambda"];
|
||||
83 [label="Function call: R|/getInt|(...)" style="filled" fillcolor=yellow];
|
||||
84 [label="Jump: ^test_4 R|/getInt|(block = getInt@fun <anonymous>(): R|kotlin/Unit| <inline=Inline, kind=UNKNOWN> {
|
||||
81 [label="Postponed exit from lambda"];
|
||||
82 [label="Function call: R|/getInt|(...)" style="filled" fillcolor=yellow];
|
||||
83 [label="Jump: ^test_4 R|/getInt|(block = getInt@fun <anonymous>(): R|kotlin/Unit| <inline=Inline, kind=UNKNOWN> {
|
||||
^test_4 Int(1)
|
||||
}
|
||||
)"];
|
||||
85 [label="Stub" style="filled" fillcolor=gray];
|
||||
86 [label="Exit block" style="filled" fillcolor=gray];
|
||||
84 [label="Stub" style="filled" fillcolor=gray];
|
||||
85 [label="Exit block" style="filled" fillcolor=gray];
|
||||
}
|
||||
87 [label="Exit function test_4" style="filled" fillcolor=red];
|
||||
86 [label="Exit function test_4" style="filled" fillcolor=red];
|
||||
}
|
||||
78 -> {79};
|
||||
79 -> {80};
|
||||
80 -> {81};
|
||||
81 -> {82 88 83};
|
||||
81 -> {88} [style=dashed];
|
||||
80 -> {81 87 82};
|
||||
80 -> {87} [style=dashed];
|
||||
81 -> {82};
|
||||
81 -> {80} [color=green style=dashed];
|
||||
82 -> {83};
|
||||
82 -> {81} [color=green style=dashed];
|
||||
83 -> {84};
|
||||
84 -> {87};
|
||||
83 -> {86};
|
||||
83 -> {84} [style=dotted];
|
||||
84 -> {85} [style=dotted];
|
||||
85 -> {86} [style=dotted];
|
||||
86 -> {87} [style=dotted];
|
||||
87 -> {88};
|
||||
88 -> {89};
|
||||
89 -> {90};
|
||||
90 -> {91};
|
||||
91 -> {87};
|
||||
90 -> {86};
|
||||
90 -> {91} [style=dotted];
|
||||
91 -> {92} [style=dotted];
|
||||
92 -> {93} [style=dotted];
|
||||
93 -> {94} [style=dotted];
|
||||
94 -> {82} [style=dotted];
|
||||
93 -> {81} [style=dotted];
|
||||
|
||||
}
|
||||
|
||||
+27
-30
@@ -30,23 +30,22 @@ digraph postponedLambdaInConstructor_kt {
|
||||
subgraph cluster_4 {
|
||||
color=blue
|
||||
13 [label="Enter block"];
|
||||
14 [label="Postponed enter to lambda"];
|
||||
14 [label="Exit anonymous function expression"];
|
||||
subgraph cluster_5 {
|
||||
color=blue
|
||||
18 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
|
||||
17 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
|
||||
subgraph cluster_6 {
|
||||
color=blue
|
||||
19 [label="Enter block"];
|
||||
20 [label="Access variable R|<local>/it|"];
|
||||
21 [label="Exit block"];
|
||||
18 [label="Enter block"];
|
||||
19 [label="Access variable R|<local>/it|"];
|
||||
20 [label="Exit block"];
|
||||
}
|
||||
22 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
|
||||
21 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
|
||||
}
|
||||
15 [label="Exit block"];
|
||||
}
|
||||
16 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
|
||||
}
|
||||
17 [label="Postponed exit from lambda"];
|
||||
8 [label="Postponed exit from lambda"];
|
||||
9 [label="Function call: R|<local>/s|.R|kotlin/let|<R|kotlin/String|, R|() -> kotlin/String|>(...)" style="filled" fillcolor=yellow];
|
||||
10 [label="Delegated constructor call: super<R|A|>(...)" style="filled" fillcolor=yellow];
|
||||
@@ -63,52 +62,50 @@ digraph postponedLambdaInConstructor_kt {
|
||||
10 -> {11};
|
||||
12 -> {13};
|
||||
13 -> {14};
|
||||
14 -> {17 15 18};
|
||||
14 -> {18} [style=dashed];
|
||||
14 -> {15 17};
|
||||
14 -> {17} [style=dashed];
|
||||
15 -> {16};
|
||||
16 -> {8};
|
||||
17 -> {10} [color=red];
|
||||
17 -> {9} [color=green];
|
||||
17 -> {18};
|
||||
18 -> {19};
|
||||
19 -> {20};
|
||||
20 -> {21};
|
||||
21 -> {22};
|
||||
|
||||
subgraph cluster_7 {
|
||||
color=red
|
||||
23 [label="Enter property" style="filled" fillcolor=red];
|
||||
24 [label="Access variable R|<local>/s|"];
|
||||
25 [label="Exit property" style="filled" fillcolor=red];
|
||||
22 [label="Enter property" style="filled" fillcolor=red];
|
||||
23 [label="Access variable R|<local>/s|"];
|
||||
24 [label="Exit property" style="filled" fillcolor=red];
|
||||
}
|
||||
22 -> {23};
|
||||
23 -> {24};
|
||||
24 -> {25};
|
||||
25 -> {33} [color=green];
|
||||
24 -> {32} [color=green];
|
||||
|
||||
subgraph cluster_8 {
|
||||
color=red
|
||||
26 [label="Enter function foo" style="filled" fillcolor=red];
|
||||
25 [label="Enter function foo" style="filled" fillcolor=red];
|
||||
subgraph cluster_9 {
|
||||
color=blue
|
||||
27 [label="Enter block"];
|
||||
28 [label="Function call: this@R|/B|.R|/B.foo|()" style="filled" fillcolor=yellow];
|
||||
29 [label="Exit block"];
|
||||
26 [label="Enter block"];
|
||||
27 [label="Function call: this@R|/B|.R|/B.foo|()" style="filled" fillcolor=yellow];
|
||||
28 [label="Exit block"];
|
||||
}
|
||||
30 [label="Exit function foo" style="filled" fillcolor=red];
|
||||
29 [label="Exit function foo" style="filled" fillcolor=red];
|
||||
}
|
||||
25 -> {26};
|
||||
26 -> {27};
|
||||
27 -> {28};
|
||||
28 -> {29};
|
||||
29 -> {30};
|
||||
|
||||
subgraph cluster_10 {
|
||||
color=red
|
||||
31 [label="Enter class B" style="filled" fillcolor=red];
|
||||
32 [label="Part of class initialization"];
|
||||
33 [label="Exit class B" style="filled" fillcolor=red];
|
||||
30 [label="Enter class B" style="filled" fillcolor=red];
|
||||
31 [label="Part of class initialization"];
|
||||
32 [label="Exit class B" style="filled" fillcolor=red];
|
||||
}
|
||||
31 -> {32} [color=green];
|
||||
32 -> {33} [style=dotted];
|
||||
32 -> {23} [color=green];
|
||||
32 -> {23} [style=dashed];
|
||||
30 -> {31} [color=green];
|
||||
31 -> {32} [style=dotted];
|
||||
31 -> {22} [color=green];
|
||||
31 -> {22} [style=dashed];
|
||||
|
||||
}
|
||||
|
||||
Vendored
+85
-91
@@ -95,7 +95,8 @@ digraph callsInPlace_kt {
|
||||
subgraph cluster_9 {
|
||||
color=blue
|
||||
30 [label="Enter block"];
|
||||
31 [label="Postponed enter to lambda"];
|
||||
31 [label="Const: Int(10)"];
|
||||
32 [label="Postponed enter to lambda"];
|
||||
subgraph cluster_10 {
|
||||
color=blue
|
||||
37 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
|
||||
@@ -107,8 +108,7 @@ digraph callsInPlace_kt {
|
||||
}
|
||||
41 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
|
||||
}
|
||||
33 [label="Const: Int(10)"];
|
||||
32 [label="Postponed exit from lambda"];
|
||||
33 [label="Postponed exit from lambda"];
|
||||
34 [label="Function call: R|kotlin/repeat|(...)" style="filled" fillcolor=yellow];
|
||||
35 [label="Exit block"];
|
||||
}
|
||||
@@ -116,18 +116,18 @@ digraph callsInPlace_kt {
|
||||
}
|
||||
29 -> {30};
|
||||
30 -> {31};
|
||||
31 -> {32 33 37};
|
||||
31 -> {37} [style=dashed];
|
||||
32 -> {34};
|
||||
32 -> {31} [color=green style=dashed];
|
||||
31 -> {32};
|
||||
32 -> {33 37 34};
|
||||
32 -> {37} [style=dashed];
|
||||
33 -> {34};
|
||||
33 -> {32} [color=green style=dashed];
|
||||
34 -> {35};
|
||||
35 -> {36};
|
||||
37 -> {38};
|
||||
38 -> {39};
|
||||
39 -> {40};
|
||||
40 -> {41};
|
||||
41 -> {32};
|
||||
41 -> {33};
|
||||
|
||||
subgraph cluster_12 {
|
||||
color=red
|
||||
@@ -252,167 +252,161 @@ digraph callsInPlace_kt {
|
||||
84 [label="Postponed enter to lambda"];
|
||||
subgraph cluster_24 {
|
||||
color=blue
|
||||
96 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
|
||||
95 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
|
||||
subgraph cluster_25 {
|
||||
color=blue
|
||||
97 [label="Enter block"];
|
||||
98 [label="Const: String(test_6_2)"];
|
||||
99 [label="Exit block"];
|
||||
96 [label="Enter block"];
|
||||
97 [label="Const: String(test_6_2)"];
|
||||
98 [label="Exit block"];
|
||||
}
|
||||
100 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
|
||||
99 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
|
||||
}
|
||||
86 [label="Postponed enter to lambda"];
|
||||
subgraph cluster_26 {
|
||||
color=blue
|
||||
91 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
|
||||
90 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
|
||||
subgraph cluster_27 {
|
||||
color=blue
|
||||
92 [label="Enter block"];
|
||||
93 [label="Const: String(test_6_1)"];
|
||||
94 [label="Exit block"];
|
||||
91 [label="Enter block"];
|
||||
92 [label="Const: String(test_6_1)"];
|
||||
93 [label="Exit block"];
|
||||
}
|
||||
95 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
|
||||
94 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
|
||||
}
|
||||
87 [label="Postponed exit from lambda"];
|
||||
85 [label="Postponed exit from lambda"];
|
||||
88 [label="Function call: R|/myRun|(...)" style="filled" fillcolor=yellow];
|
||||
89 [label="Exit block"];
|
||||
86 [label="Postponed exit from lambda"];
|
||||
87 [label="Function call: R|/myRun|(...)" style="filled" fillcolor=yellow];
|
||||
88 [label="Exit block"];
|
||||
}
|
||||
90 [label="Exit function test_6" style="filled" fillcolor=red];
|
||||
89 [label="Exit function test_6" style="filled" fillcolor=red];
|
||||
}
|
||||
82 -> {83};
|
||||
83 -> {84};
|
||||
84 -> {85 86 96};
|
||||
84 -> {96} [style=dashed];
|
||||
85 -> {88};
|
||||
84 -> {86 85 90 95 87};
|
||||
84 -> {90 95} [style=dashed];
|
||||
85 -> {87};
|
||||
85 -> {84} [color=green style=dashed];
|
||||
86 -> {87 91 88};
|
||||
86 -> {91} [style=dashed];
|
||||
86 -> {87};
|
||||
86 -> {84} [color=green style=dashed];
|
||||
87 -> {88};
|
||||
87 -> {86} [color=green style=dashed];
|
||||
88 -> {89};
|
||||
89 -> {90};
|
||||
90 -> {91};
|
||||
91 -> {92};
|
||||
92 -> {93};
|
||||
93 -> {94};
|
||||
94 -> {95};
|
||||
95 -> {87};
|
||||
94 -> {86};
|
||||
95 -> {96};
|
||||
96 -> {97};
|
||||
97 -> {98};
|
||||
98 -> {99};
|
||||
99 -> {100};
|
||||
100 -> {85};
|
||||
99 -> {85};
|
||||
|
||||
subgraph cluster_28 {
|
||||
color=red
|
||||
101 [label="Enter function test_7" style="filled" fillcolor=red];
|
||||
100 [label="Enter function test_7" style="filled" fillcolor=red];
|
||||
subgraph cluster_29 {
|
||||
color=blue
|
||||
102 [label="Enter block"];
|
||||
103 [label="Postponed enter to lambda"];
|
||||
101 [label="Enter block"];
|
||||
102 [label="Postponed enter to lambda"];
|
||||
subgraph cluster_30 {
|
||||
color=blue
|
||||
110 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
|
||||
113 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
|
||||
subgraph cluster_31 {
|
||||
color=blue
|
||||
111 [label="Enter block"];
|
||||
112 [label="Const: String(test_7_2)"];
|
||||
113 [label="Exit block"];
|
||||
114 [label="Enter block"];
|
||||
115 [label="Const: String(test_7_1)"];
|
||||
116 [label="Exit block"];
|
||||
}
|
||||
114 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
|
||||
117 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
|
||||
}
|
||||
105 [label="Postponed enter to lambda"];
|
||||
subgraph cluster_32 {
|
||||
color=blue
|
||||
115 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
|
||||
108 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
|
||||
subgraph cluster_33 {
|
||||
color=blue
|
||||
116 [label="Enter block"];
|
||||
117 [label="Const: String(test_7_1)"];
|
||||
118 [label="Exit block"];
|
||||
109 [label="Enter block"];
|
||||
110 [label="Const: String(test_7_2)"];
|
||||
111 [label="Exit block"];
|
||||
}
|
||||
119 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
|
||||
112 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
|
||||
}
|
||||
106 [label="Postponed exit from lambda"];
|
||||
103 [label="Postponed exit from lambda"];
|
||||
104 [label="Postponed exit from lambda"];
|
||||
107 [label="Function call: R|/myRun|(...)" style="filled" fillcolor=yellow];
|
||||
108 [label="Exit block"];
|
||||
105 [label="Function call: R|/myRun|(...)" style="filled" fillcolor=yellow];
|
||||
106 [label="Exit block"];
|
||||
}
|
||||
109 [label="Exit function test_7" style="filled" fillcolor=red];
|
||||
107 [label="Exit function test_7" style="filled" fillcolor=red];
|
||||
}
|
||||
100 -> {101};
|
||||
101 -> {102};
|
||||
102 -> {103};
|
||||
103 -> {104 105 110};
|
||||
103 -> {110} [style=dashed];
|
||||
104 -> {107};
|
||||
104 -> {103} [color=green style=dashed];
|
||||
105 -> {106 115 107};
|
||||
105 -> {115} [style=dashed];
|
||||
102 -> {104 103 108 113 105};
|
||||
102 -> {108 113} [style=dashed];
|
||||
103 -> {105};
|
||||
103 -> {102} [color=green style=dashed];
|
||||
104 -> {105};
|
||||
104 -> {102} [color=green style=dashed];
|
||||
105 -> {106};
|
||||
106 -> {107};
|
||||
106 -> {105} [color=green style=dashed];
|
||||
107 -> {108};
|
||||
108 -> {109};
|
||||
109 -> {110};
|
||||
110 -> {111};
|
||||
111 -> {112};
|
||||
112 -> {113};
|
||||
112 -> {104};
|
||||
113 -> {114};
|
||||
114 -> {104};
|
||||
114 -> {115};
|
||||
115 -> {116};
|
||||
116 -> {117};
|
||||
117 -> {118};
|
||||
118 -> {119};
|
||||
119 -> {106};
|
||||
117 -> {103};
|
||||
|
||||
subgraph cluster_34 {
|
||||
color=red
|
||||
120 [label="Enter function myDummyRun" style="filled" fillcolor=red];
|
||||
118 [label="Enter function myDummyRun" style="filled" fillcolor=red];
|
||||
subgraph cluster_35 {
|
||||
color=blue
|
||||
121 [label="Enter block"];
|
||||
122 [label="Function call: R|<local>/block|.R|SubstitutionOverride<kotlin/Function0.invoke: R|kotlin/Unit|>|()" style="filled" fillcolor=yellow];
|
||||
123 [label="Exit block"];
|
||||
119 [label="Enter block"];
|
||||
120 [label="Function call: R|<local>/block|.R|SubstitutionOverride<kotlin/Function0.invoke: R|kotlin/Unit|>|()" style="filled" fillcolor=yellow];
|
||||
121 [label="Exit block"];
|
||||
}
|
||||
124 [label="Exit function myDummyRun" style="filled" fillcolor=red];
|
||||
122 [label="Exit function myDummyRun" style="filled" fillcolor=red];
|
||||
}
|
||||
118 -> {119};
|
||||
119 -> {120};
|
||||
120 -> {121};
|
||||
121 -> {122};
|
||||
122 -> {123};
|
||||
123 -> {124};
|
||||
|
||||
subgraph cluster_36 {
|
||||
color=red
|
||||
125 [label="Enter function test_8" style="filled" fillcolor=red];
|
||||
123 [label="Enter function test_8" style="filled" fillcolor=red];
|
||||
subgraph cluster_37 {
|
||||
color=blue
|
||||
126 [label="Enter block"];
|
||||
127 [label="Postponed enter to lambda"];
|
||||
124 [label="Enter block"];
|
||||
125 [label="Postponed enter to lambda"];
|
||||
subgraph cluster_38 {
|
||||
color=blue
|
||||
132 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
|
||||
130 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
|
||||
subgraph cluster_39 {
|
||||
color=blue
|
||||
133 [label="Enter block"];
|
||||
134 [label="Const: String(test_8)"];
|
||||
135 [label="Exit block"];
|
||||
131 [label="Enter block"];
|
||||
132 [label="Const: String(test_8)"];
|
||||
133 [label="Exit block"];
|
||||
}
|
||||
136 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
|
||||
134 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
|
||||
}
|
||||
128 [label="Postponed exit from lambda"];
|
||||
129 [label="Function call: R|/myDummyRun|(...)" style="filled" fillcolor=yellow];
|
||||
130 [label="Exit block"];
|
||||
126 [label="Postponed exit from lambda"];
|
||||
127 [label="Function call: R|/myDummyRun|(...)" style="filled" fillcolor=yellow];
|
||||
128 [label="Exit block"];
|
||||
}
|
||||
131 [label="Exit function test_8" style="filled" fillcolor=red];
|
||||
129 [label="Exit function test_8" style="filled" fillcolor=red];
|
||||
}
|
||||
125 -> {126};
|
||||
123 -> {124};
|
||||
124 -> {125};
|
||||
125 -> {126 130 127};
|
||||
125 -> {130} [style=dashed];
|
||||
126 -> {127};
|
||||
127 -> {128 132 129};
|
||||
127 -> {132} [style=dashed];
|
||||
127 -> {128};
|
||||
128 -> {129};
|
||||
129 -> {130};
|
||||
130 -> {131};
|
||||
131 -> {132};
|
||||
132 -> {133};
|
||||
133 -> {134};
|
||||
134 -> {135};
|
||||
135 -> {136};
|
||||
|
||||
}
|
||||
|
||||
+6
-2
@@ -39,11 +39,15 @@ class LocalPropertyAndCapturedWriteCollector private constructor() : ControlFlow
|
||||
symbols[node.fir.symbol] = lambdaOrLocalFunctionStack.lastOrNull() == null
|
||||
}
|
||||
|
||||
override fun visitPostponedLambdaEnterNode(node: PostponedLambdaEnterNode) {
|
||||
override fun visitSplitPostponedLambdasNode(node: SplitPostponedLambdasNode) {
|
||||
lambdaOrLocalFunctionStack.addAll(node.lambdas)
|
||||
}
|
||||
|
||||
override fun visitAnonymousFunctionExpressionNode(node: AnonymousFunctionExpressionNode) {
|
||||
lambdaOrLocalFunctionStack.add(node.fir.anonymousFunction)
|
||||
}
|
||||
|
||||
override fun visitLocalFunctionDeclarationNode(node: LocalFunctionDeclarationNode, data: Nothing?) {
|
||||
override fun visitLocalFunctionDeclarationNode(node: LocalFunctionDeclarationNode) {
|
||||
lambdaOrLocalFunctionStack.add(node.fir)
|
||||
}
|
||||
|
||||
|
||||
+1
@@ -49,6 +49,7 @@ object UnreachableCodeChecker : FirControlFlowChecker() {
|
||||
val skipType = this is ExitNodeMarker ||
|
||||
this is EnterNodeMarker ||
|
||||
this is StubNode ||
|
||||
this is SplitPostponedLambdasNode ||
|
||||
this is BinaryOrExitLeftOperandNode ||
|
||||
this is BinaryOrEnterRightOperandNode ||
|
||||
this is BinaryAndExitLeftOperandNode ||
|
||||
|
||||
@@ -68,21 +68,7 @@ class FirCallResolver(
|
||||
val conflictResolver: ConeCallConflictResolver =
|
||||
session.callConflictResolverFactory.create(TypeSpecificityComparator.NONE, session.inferenceComponents, components)
|
||||
|
||||
@PrivateForInline
|
||||
var needTransformArguments: Boolean = true
|
||||
|
||||
@OptIn(PrivateForInline::class)
|
||||
fun resolveCallAndSelectCandidate(functionCall: FirFunctionCall): FirFunctionCall {
|
||||
@Suppress("NAME_SHADOWING")
|
||||
val functionCall = if (needTransformArguments) {
|
||||
functionCall.transformExplicitReceiver().also {
|
||||
components.dataFlowAnalyzer.enterQualifiedAccessExpression()
|
||||
functionCall.replaceArgumentList(functionCall.argumentList.transform(transformer, ResolutionMode.ContextDependent))
|
||||
}
|
||||
} else {
|
||||
functionCall
|
||||
}
|
||||
|
||||
val name = functionCall.calleeReference.name
|
||||
val result = collectCandidates(functionCall, name, origin = functionCall.origin)
|
||||
|
||||
@@ -132,29 +118,6 @@ class FirCallResolver(
|
||||
return resultFunctionCall
|
||||
}
|
||||
|
||||
private inline fun <reified Q : FirQualifiedAccess> Q.transformExplicitReceiver(): Q {
|
||||
val explicitReceiver =
|
||||
explicitReceiver as? FirQualifiedAccessExpression
|
||||
?: return transformExplicitReceiver(transformer, ResolutionMode.ReceiverResolution) as Q
|
||||
|
||||
(explicitReceiver.calleeReference as? FirSuperReference)?.let {
|
||||
transformer.transformSuperReceiver(it, explicitReceiver, this)
|
||||
return this
|
||||
}
|
||||
|
||||
if (explicitReceiver is FirPropertyAccessExpression) {
|
||||
this.replaceExplicitReceiver(
|
||||
transformer.transformQualifiedAccessExpression(
|
||||
explicitReceiver, ResolutionMode.ReceiverResolution,
|
||||
isUsedAsReceiver = true
|
||||
) as FirExpression
|
||||
)
|
||||
return this
|
||||
}
|
||||
|
||||
return transformExplicitReceiver(transformer, ResolutionMode.ReceiverResolution) as Q
|
||||
}
|
||||
|
||||
private data class ResolutionResult(
|
||||
val info: CallInfo, val applicability: CandidateApplicability, val candidates: Collection<Candidate>,
|
||||
)
|
||||
@@ -249,7 +212,7 @@ class FirCallResolver(
|
||||
val callee = qualifiedAccess.calleeReference as? FirSimpleNamedReference ?: return qualifiedAccess
|
||||
|
||||
@Suppress("NAME_SHADOWING")
|
||||
val qualifiedAccess = qualifiedAccess.transformExplicitReceiver<FirQualifiedAccess>()
|
||||
val qualifiedAccess = transformer.transformExplicitReceiver(qualifiedAccess)
|
||||
val nonFatalDiagnosticFromExpression = (qualifiedAccess as? FirPropertyAccessExpression)?.nonFatalDiagnostics
|
||||
|
||||
val basicResult by lazy(LazyThreadSafetyMode.NONE) {
|
||||
@@ -605,17 +568,6 @@ class FirCallResolver(
|
||||
return ResolutionResult(callInfo, applicability, listOf(candidate))
|
||||
}
|
||||
|
||||
@OptIn(PrivateForInline::class)
|
||||
inline fun <T> withNoArgumentsTransform(block: () -> T): T {
|
||||
val oldValue = needTransformArguments
|
||||
needTransformArguments = false
|
||||
return try {
|
||||
block()
|
||||
} finally {
|
||||
needTransformArguments = oldValue
|
||||
}
|
||||
}
|
||||
|
||||
private fun selectDelegatingConstructorCall(
|
||||
call: FirDelegatedConstructorCall, name: Name, result: CandidateCollector, callInfo: CallInfo
|
||||
): FirDelegatedConstructorCall {
|
||||
|
||||
+10
-41
@@ -152,7 +152,7 @@ abstract class FirDataFlowAnalyzer(
|
||||
if (function is FirDefaultPropertyAccessor) return
|
||||
|
||||
val (localFunctionNode, functionEnterNode) = if (function is FirAnonymousFunction) {
|
||||
graphBuilder.enterAnonymousFunction(function)
|
||||
null to graphBuilder.enterAnonymousFunction(function)
|
||||
} else {
|
||||
graphBuilder.enterFunction(function)
|
||||
}
|
||||
@@ -201,12 +201,8 @@ abstract class FirDataFlowAnalyzer(
|
||||
|
||||
// ----------------------------------- Anonymous function -----------------------------------
|
||||
|
||||
fun visitPostponedAnonymousFunction(anonymousFunctionExpression: FirAnonymousFunctionExpression) {
|
||||
graphBuilder.visitPostponedAnonymousFunction(anonymousFunctionExpression).mergeIncomingFlow()
|
||||
}
|
||||
|
||||
fun exitAnonymousFunctionExpression(anonymousFunctionExpression: FirAnonymousFunctionExpression) {
|
||||
graphBuilder.exitAnonymousFunctionExpression(anonymousFunctionExpression).mergeIncomingFlow()
|
||||
fun enterAnonymousFunctionExpression(anonymousFunctionExpression: FirAnonymousFunctionExpression) {
|
||||
graphBuilder.enterAnonymousFunctionExpression(anonymousFunctionExpression)?.mergeIncomingFlow()
|
||||
}
|
||||
|
||||
// ----------------------------------- Classes -----------------------------------
|
||||
@@ -739,9 +735,6 @@ abstract class FirDataFlowAnalyzer(
|
||||
|
||||
// ----------------------------------- Resolvable call -----------------------------------
|
||||
|
||||
// Intentionally left empty for potential future needs (call sites are preserved)
|
||||
fun enterQualifiedAccessExpression() {}
|
||||
|
||||
fun exitQualifiedAccessExpression(qualifiedAccessExpression: FirQualifiedAccessExpression) {
|
||||
graphBuilder.exitQualifiedAccessExpression(qualifiedAccessExpression).mergeIncomingFlow { flow ->
|
||||
processConditionalContract(flow, qualifiedAccessExpression)
|
||||
@@ -780,50 +773,26 @@ abstract class FirDataFlowAnalyzer(
|
||||
graphBuilder.exitResolvedQualifierNode(resolvedQualifier).mergeIncomingFlow()
|
||||
}
|
||||
|
||||
private var resolvingAugmentedAssignmentOptions: Boolean = false
|
||||
|
||||
// The expected sequence of calls for augmented assignment:
|
||||
// 1. enterAugmentedAssignmentCall()
|
||||
// 2. resolve arguments
|
||||
// 3. enterSelectAugmentedAssignmentCall()
|
||||
// 4. resolve all options for calls in context-independent mode
|
||||
// 5. exitSelectAugmentedAssignmentCall()
|
||||
// 6. complete the chosen version
|
||||
// 7. exitFunctionCall(top-level call in the chosen option)
|
||||
fun enterAugmentedAssignmentCall() {
|
||||
fun enterCallArguments(call: FirStatement, arguments: List<FirExpression>) {
|
||||
val lambdas = arguments.mapNotNull { it.unwrapAnonymousFunctionExpression() }
|
||||
context.variableAssignmentAnalyzer.enterFunctionCall(lambdas)
|
||||
graphBuilder.enterCall()
|
||||
context.variableAssignmentAnalyzer.enterFunctionCall(emptyList())
|
||||
graphBuilder.enterCallArguments(call, lambdas)
|
||||
}
|
||||
|
||||
fun enterSelectAugmentedAssignmentCall() {
|
||||
assert(!resolvingAugmentedAssignmentOptions) { "resolving augmented assignment while resolving augmented assignment?" }
|
||||
resolvingAugmentedAssignmentOptions = true
|
||||
}
|
||||
|
||||
fun exitSelectAugmentedAssignmentCall() {
|
||||
assert(resolvingAugmentedAssignmentOptions) { "no enterSelectAugmentedAssignmentCall before exitSelectAugmentedAssignmentCall" }
|
||||
resolvingAugmentedAssignmentOptions = false
|
||||
}
|
||||
|
||||
fun enterFunctionCall(functionCall: FirFunctionCall) {
|
||||
if (resolvingAugmentedAssignmentOptions) return // shouldn't be any lambda arguments anyway, they're visited before that
|
||||
context.variableAssignmentAnalyzer.enterFunctionCall(functionCall.arguments.mapNotNull { it.unwrapAnonymousFunctionExpression() })
|
||||
graphBuilder.enterCall()
|
||||
fun exitCallArguments() {
|
||||
graphBuilder.exitCallArguments()?.mergeIncomingFlow()
|
||||
}
|
||||
|
||||
fun exitFunctionCall(functionCall: FirFunctionCall, callCompleted: Boolean) {
|
||||
if (resolvingAugmentedAssignmentOptions) return
|
||||
context.variableAssignmentAnalyzer.exitFunctionCall(callCompleted)
|
||||
graphBuilder.exitFunctionCall(functionCall, callCompleted).mergeIncomingFlow {
|
||||
processConditionalContract(it, functionCall)
|
||||
}
|
||||
}
|
||||
|
||||
fun enterDelegatedConstructorCall() {
|
||||
graphBuilder.enterCall()
|
||||
}
|
||||
|
||||
fun exitDelegatedConstructorCall(call: FirDelegatedConstructorCall, callCompleted: Boolean) {
|
||||
context.variableAssignmentAnalyzer.exitFunctionCall(callCompleted)
|
||||
graphBuilder.exitDelegatedConstructorCall(call, callCompleted).mergeIncomingFlow()
|
||||
}
|
||||
|
||||
|
||||
+57
-38
@@ -61,14 +61,15 @@ class ControlFlowGraphBuilder {
|
||||
//return jumps via finally blocks, target -> jumps
|
||||
private val nonDirectJumps: ListMultimap<CFGNode<*>, CFGNode<*>> = listMultimapOf()
|
||||
|
||||
private val argumentListSplitNodes: Stack<SplitPostponedLambdasNode?> = stackOf()
|
||||
private val postponedAnonymousFunctionNodes =
|
||||
mutableMapOf<FirFunctionSymbol<*>, Pair<PostponedLambdaEnterNode, PostponedLambdaExitNode>>()
|
||||
mutableMapOf<FirFunctionSymbol<*>, Pair<CFGNodeWithSubgraphs<*>, PostponedLambdaExitNode?>>()
|
||||
private val postponedLambdaExits: Stack<MutableList<Pair<CFGNode<*>, EdgeKind>>> = stackOf()
|
||||
|
||||
private val loopConditionEnterNodes: NodeStorage<FirElement, LoopConditionEnterNode> = NodeStorage()
|
||||
private val loopExitNodes: NodeStorage<FirLoop, LoopExitNode> = NodeStorage()
|
||||
|
||||
private val whenExitNodes: NodeStorage<FirWhenExpression, WhenExitNode> = NodeStorage()
|
||||
private val whenExitNodes: Stack<WhenExitNode> = stackOf()
|
||||
|
||||
private val binaryLogicExpressionExitNodes: Stack<AbstractBinaryExitNode<FirBinaryLogicExpression>> = stackOf()
|
||||
|
||||
@@ -236,23 +237,28 @@ class ControlFlowGraphBuilder {
|
||||
// for them may not have been computed yet. Instead, these edges are redirected
|
||||
// into the outer call. The outermost call *has* to be completed, so at some point
|
||||
// all data will be unified in a single call node.
|
||||
fun visitPostponedAnonymousFunction(anonymousFunctionExpression: FirAnonymousFunctionExpression): PostponedLambdaEnterNode {
|
||||
// TODO: should only have 1 enter node for all lambdas in a single call.
|
||||
val enterNode = createPostponedLambdaEnterNode(anonymousFunctionExpression)
|
||||
val exitNode = createPostponedLambdaExitNode(anonymousFunctionExpression)
|
||||
fun enterAnonymousFunctionExpression(anonymousFunctionExpression: FirAnonymousFunctionExpression): AnonymousFunctionExpressionNode? {
|
||||
val symbol = anonymousFunctionExpression.anonymousFunction.symbol
|
||||
postponedAnonymousFunctionNodes[symbol] = enterNode to exitNode
|
||||
addNewSimpleNode(enterNode)
|
||||
val enterNode = postponedAnonymousFunctionNodes[symbol]?.first
|
||||
?: return createAnonymousFunctionExpressionNode(anonymousFunctionExpression).also {
|
||||
addNewSimpleNode(it)
|
||||
// Not in an argument list, won't be called in-place, don't need an exit node.
|
||||
postponedAnonymousFunctionNodes[symbol] = it to null
|
||||
}
|
||||
val exitNode = createPostponedLambdaExitNode(anonymousFunctionExpression)
|
||||
// Ideally we'd only add this edge in `exitAnonymousFunction`, but unfortunately it's possible
|
||||
// that the function won't be visited for so long, we'll exit `currentGraph` before that.
|
||||
// When exiting a graph, all nodes in it are topologically sorted, so unless we add some edge
|
||||
// here, `exitNode` will be dropped from the node list. Oops. TODO: fix `orderNodes` someday.
|
||||
addEdge(enterNode, exitNode)
|
||||
postponedAnonymousFunctionNodes[symbol] = enterNode to exitNode
|
||||
postponedLambdaExits.top().add(exitNode to EdgeKind.Forward)
|
||||
return enterNode
|
||||
return null
|
||||
}
|
||||
|
||||
fun enterAnonymousFunction(anonymousFunction: FirAnonymousFunction): Pair<LocalFunctionDeclarationNode?, FunctionEnterNode> {
|
||||
fun enterAnonymousFunction(anonymousFunction: FirAnonymousFunction): FunctionEnterNode {
|
||||
val symbol = anonymousFunction.symbol
|
||||
val flowSourceNode = postponedAnonymousFunctionNodes[symbol]?.first
|
||||
?: createLocalFunctionDeclarationNode(anonymousFunction).also { addNewSimpleNode(it) }
|
||||
|
||||
val flowSourceNode = postponedAnonymousFunctionNodes.getValue(symbol).first
|
||||
pushGraph(ControlFlowGraph(anonymousFunction, "<anonymous>", ControlFlowGraph.Kind.AnonymousFunction), Mode.Function)
|
||||
val enterNode = createFunctionEnterNode(anonymousFunction)
|
||||
val exitNode = createFunctionExitNode(anonymousFunction)
|
||||
@@ -260,10 +266,9 @@ class ControlFlowGraphBuilder {
|
||||
if (!anonymousFunction.invocationKind.isInPlace) {
|
||||
exitTargetsForTry.push(exitNode)
|
||||
}
|
||||
|
||||
addEdge(flowSourceNode, enterNode)
|
||||
lastNodes.push(enterNode)
|
||||
return (flowSourceNode as? LocalFunctionDeclarationNode) to enterNode
|
||||
return enterNode
|
||||
}
|
||||
|
||||
fun exitAnonymousFunction(anonymousFunction: FirAnonymousFunction): Triple<FunctionExitNode, PostponedLambdaExitNode?, ControlFlowGraph> {
|
||||
@@ -276,41 +281,41 @@ class ControlFlowGraphBuilder {
|
||||
popAndAddEdge(exitNode)
|
||||
exitNode.updateDeadStatus()
|
||||
|
||||
val graph = popGraph().also { graph ->
|
||||
assert(graph.declaration == anonymousFunction)
|
||||
assert(graph.exitNode == exitNode)
|
||||
}
|
||||
val graph = popGraph()
|
||||
assert(graph.declaration == anonymousFunction)
|
||||
assert(graph.exitNode == exitNode)
|
||||
|
||||
val (postponedEnterNode, postponedExitNode) = postponedAnonymousFunctionNodes.remove(symbol)
|
||||
?: return Triple(exitNode, null, graph).also { currentGraph.addSubGraph(graph) }
|
||||
val (splitNode, postponedExitNode) = postponedAnonymousFunctionNodes.remove(symbol)!!
|
||||
splitNode.addSubGraph(graph)
|
||||
// May not be the current graph: `select(run { run { generic() } }, 1)`
|
||||
splitNode.owner.addSubGraph(graph)
|
||||
|
||||
val invocationKind = anonymousFunction.invocationKind
|
||||
if (postponedExitNode == null) {
|
||||
// Postponed exit node was needed so we could create lambda->call edges without having the subgraph ready. If it
|
||||
// doesn't exist, then we probably can't do that anymore, and the lambda won't be called-in-place in the CFG.
|
||||
// TODO: verify & enable this assertion?
|
||||
//assert(invocationKind?.canBeVisited() != true) { "no exit node for calledInPlace($invocationKind) lambda" }
|
||||
return Triple(exitNode, null, graph)
|
||||
}
|
||||
|
||||
// Lambdas not called in-place behave as if called never, but with extra invalidation of all smart casts
|
||||
// for all variables that they reassign. That second part is handled by `FirDataFlowAnalyzer`.
|
||||
val isDefinitelyVisited = invocationKind?.isDefinitelyVisited() == true
|
||||
if (isDefinitelyVisited || splitNode.isDead) {
|
||||
// The edge that was added as a hack to enforce ordering of nodes needs to be marked as dead if this lambda is never
|
||||
// skipped. Or if the entry node is dead, because at the time we added the hack-edge we didn't know that.
|
||||
CFGNode.addJustKindEdge(splitNode, postponedExitNode, EdgeKind.DeadForward, propagateDeadness = !isDefinitelyVisited)
|
||||
}
|
||||
if (invocationKind?.canBeVisited() == true) {
|
||||
addEdge(exitNode, postponedExitNode, propagateDeadness = invocationKind.isDefinitelyVisited())
|
||||
if (invocationKind.isDefinitelyVisited()) {
|
||||
// We had to create this edge so that if the lambda is postponed for so long that we exit the subgraph
|
||||
// before visiting it, `orderNodes` can still find an ordering. Now we can kill it.
|
||||
CFGNode.addJustKindEdge(postponedEnterNode, postponedExitNode, EdgeKind.DeadForward, propagateDeadness = false)
|
||||
}
|
||||
addEdge(exitNode, postponedExitNode, propagateDeadness = isDefinitelyVisited)
|
||||
if (invocationKind.canBeRevisited()) {
|
||||
addBackEdge(postponedExitNode, postponedEnterNode)
|
||||
addBackEdge(postponedExitNode, splitNode, label = LoopBackPath)
|
||||
}
|
||||
}
|
||||
|
||||
postponedEnterNode.addSubGraph(graph)
|
||||
// May not be the current graph: `nearestCompletedCall(run { run { generic() } }, 1)`
|
||||
postponedEnterNode.owner.addSubGraph(graph)
|
||||
return Triple(exitNode, postponedExitNode, graph)
|
||||
}
|
||||
|
||||
fun exitAnonymousFunctionExpression(anonymousFunctionExpression: FirAnonymousFunctionExpression): AnonymousFunctionExpressionExitNode {
|
||||
return createAnonymousFunctionExpressionExitNode(anonymousFunctionExpression).also {
|
||||
addNewSimpleNode(it)
|
||||
}
|
||||
}
|
||||
|
||||
private fun splitDataFlowForPostponedLambdas() {
|
||||
postponedLambdaExits.push(mutableListOf())
|
||||
}
|
||||
@@ -1084,6 +1089,20 @@ class ControlFlowGraphBuilder {
|
||||
splitDataFlowForPostponedLambdas()
|
||||
}
|
||||
|
||||
fun enterCallArguments(fir: FirStatement, anonymousFunctions: List<FirAnonymousFunction>) {
|
||||
if (anonymousFunctions.isEmpty()) {
|
||||
argumentListSplitNodes.push(null)
|
||||
} else {
|
||||
val splitNode = createSplitPostponedLambdasNode(fir, anonymousFunctions)
|
||||
anonymousFunctions.associateTo(postponedAnonymousFunctionNodes) { it.symbol to (splitNode to null) }
|
||||
argumentListSplitNodes.push(splitNode)
|
||||
}
|
||||
}
|
||||
|
||||
fun exitCallArguments(): SplitPostponedLambdasNode? {
|
||||
return argumentListSplitNodes.pop()?.also { addNewSimpleNode(it) }
|
||||
}
|
||||
|
||||
fun exitFunctionCall(functionCall: FirFunctionCall, callCompleted: Boolean): FunctionCallNode {
|
||||
levelCounter--
|
||||
val returnsNothing = functionCall.resultType.isNothing
|
||||
|
||||
+7
-7
@@ -223,11 +223,14 @@ fun ControlFlowGraphBuilder.createEnterSafeCallNode(fir: FirSafeCallExpression):
|
||||
fun ControlFlowGraphBuilder.createPostponedLambdaExitNode(fir: FirAnonymousFunctionExpression): PostponedLambdaExitNode =
|
||||
PostponedLambdaExitNode(currentGraph, fir, levelCounter, createId())
|
||||
|
||||
fun ControlFlowGraphBuilder.createPostponedLambdaEnterNode(fir: FirAnonymousFunctionExpression): PostponedLambdaEnterNode =
|
||||
PostponedLambdaEnterNode(currentGraph, fir, levelCounter, createId())
|
||||
fun ControlFlowGraphBuilder.createSplitPostponedLambdasNode(fir: FirStatement, lambdas: List<FirAnonymousFunction>): SplitPostponedLambdasNode =
|
||||
SplitPostponedLambdasNode(currentGraph, fir, lambdas, levelCounter, createId())
|
||||
|
||||
fun ControlFlowGraphBuilder.createAnonymousFunctionExpressionExitNode(fir: FirAnonymousFunctionExpression): AnonymousFunctionExpressionExitNode =
|
||||
AnonymousFunctionExpressionExitNode(currentGraph, fir, levelCounter, createId())
|
||||
fun ControlFlowGraphBuilder.createMergePostponedLambdaExitsNode(fir: FirElement): MergePostponedLambdaExitsNode =
|
||||
MergePostponedLambdaExitsNode(currentGraph, fir, levelCounter, createId())
|
||||
|
||||
fun ControlFlowGraphBuilder.createAnonymousFunctionExpressionNode(fir: FirAnonymousFunctionExpression): AnonymousFunctionExpressionNode =
|
||||
AnonymousFunctionExpressionNode(currentGraph, fir, levelCounter, createId())
|
||||
|
||||
fun ControlFlowGraphBuilder.createAnonymousObjectEnterNode(fir: FirAnonymousObject): AnonymousObjectEnterNode =
|
||||
AnonymousObjectEnterNode(currentGraph, fir, levelCounter, createId())
|
||||
@@ -244,9 +247,6 @@ fun ControlFlowGraphBuilder.createScriptEnterNode(fir: FirScript): ScriptEnterNo
|
||||
fun ControlFlowGraphBuilder.createScriptExitNode(fir: FirScript): ScriptExitNode =
|
||||
ScriptExitNode(currentGraph, fir, levelCounter, createId())
|
||||
|
||||
fun ControlFlowGraphBuilder.createMergePostponedLambdaExitsNode(fir: FirElement): MergePostponedLambdaExitsNode =
|
||||
MergePostponedLambdaExitsNode(currentGraph, fir, levelCounter, createId())
|
||||
|
||||
fun ControlFlowGraphBuilder.createClassEnterNode(fir: FirClass): ClassEnterNode =
|
||||
ClassEnterNode(currentGraph, fir, levelCounter, createId())
|
||||
|
||||
|
||||
+49
-55
@@ -164,8 +164,6 @@ open class FirExpressionsResolveTransformer(transformer: FirAbstractBodyResolveT
|
||||
}
|
||||
when (result) {
|
||||
is FirQualifiedAccessExpression -> {
|
||||
// TODO: Is it really needed?
|
||||
dataFlowAnalyzer.enterQualifiedAccessExpression()
|
||||
dataFlowAnalyzer.exitQualifiedAccessExpression(result)
|
||||
result = components.transformQualifiedAccessUsingSmartcastInfo(result)
|
||||
if (result is FirSmartCastExpression) {
|
||||
@@ -179,6 +177,27 @@ open class FirExpressionsResolveTransformer(transformer: FirAbstractBodyResolveT
|
||||
return result
|
||||
}
|
||||
|
||||
fun <Q : FirQualifiedAccess> transformExplicitReceiver(qualifiedAccessExpression: Q): Q {
|
||||
val explicitReceiver = qualifiedAccessExpression.explicitReceiver as? FirQualifiedAccessExpression
|
||||
if (explicitReceiver is FirQualifiedAccessExpression) {
|
||||
val superReference = explicitReceiver.calleeReference as? FirSuperReference
|
||||
if (superReference != null) {
|
||||
transformSuperReceiver(superReference, explicitReceiver, qualifiedAccessExpression)
|
||||
return qualifiedAccessExpression
|
||||
}
|
||||
}
|
||||
if (explicitReceiver is FirPropertyAccessExpression) {
|
||||
qualifiedAccessExpression.replaceExplicitReceiver(
|
||||
transformQualifiedAccessExpression(
|
||||
explicitReceiver, ResolutionMode.ReceiverResolution, isUsedAsReceiver = true
|
||||
) as FirExpression
|
||||
)
|
||||
return qualifiedAccessExpression
|
||||
}
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return qualifiedAccessExpression.transformExplicitReceiver(transformer, ResolutionMode.ReceiverResolution) as Q
|
||||
}
|
||||
|
||||
override fun transformPropertyAccessExpression(
|
||||
propertyAccessExpression: FirPropertyAccessExpression,
|
||||
data: ResolutionMode
|
||||
@@ -379,11 +398,19 @@ open class FirExpressionsResolveTransformer(transformer: FirAbstractBodyResolveT
|
||||
functionCall.transformAnnotations(transformer, data)
|
||||
functionCall.replaceLambdaArgumentInvocationKinds(session)
|
||||
functionCall.transformTypeArguments(transformer, ResolutionMode.ContextIndependent)
|
||||
dataFlowAnalyzer.enterFunctionCall(functionCall)
|
||||
val (completeInference, callCompleted) =
|
||||
try {
|
||||
val initialExplicitReceiver = functionCall.explicitReceiver
|
||||
val resultExpression = callResolver.resolveCallAndSelectCandidate(functionCall)
|
||||
val withTransformedArguments = if (!resolvingAugmentedAssignment) {
|
||||
dataFlowAnalyzer.enterCallArguments(functionCall, functionCall.arguments)
|
||||
transformExplicitReceiver(functionCall).also {
|
||||
it.replaceArgumentList(it.argumentList.transform(this, ResolutionMode.ContextDependent))
|
||||
dataFlowAnalyzer.exitCallArguments()
|
||||
}
|
||||
} else {
|
||||
functionCall
|
||||
}
|
||||
val resultExpression = callResolver.resolveCallAndSelectCandidate(withTransformedArguments)
|
||||
val resultExplicitReceiver = resultExpression.explicitReceiver?.unwrapSmartcastExpression()
|
||||
if (initialExplicitReceiver !== resultExplicitReceiver && resultExplicitReceiver is FirQualifiedAccess) {
|
||||
// name.invoke() case
|
||||
@@ -395,7 +422,9 @@ open class FirExpressionsResolveTransformer(transformer: FirAbstractBodyResolveT
|
||||
throw RuntimeException("While resolving call ${functionCall.render()}", e)
|
||||
}
|
||||
val result = completeInference.transformToIntegerOperatorCallOrApproximateItIfNeeded(data)
|
||||
dataFlowAnalyzer.exitFunctionCall(result, callCompleted)
|
||||
if (!resolvingAugmentedAssignment) {
|
||||
dataFlowAnalyzer.exitFunctionCall(result, callCompleted)
|
||||
}
|
||||
|
||||
addReceiversFromExtensions(result)
|
||||
|
||||
@@ -533,12 +562,12 @@ open class FirExpressionsResolveTransformer(transformer: FirAbstractBodyResolveT
|
||||
require(operation != FirOperation.ASSIGN)
|
||||
|
||||
assignmentOperatorStatement.transformAnnotations(transformer, ResolutionMode.ContextIndependent)
|
||||
dataFlowAnalyzer.enterAugmentedAssignmentCall()
|
||||
dataFlowAnalyzer.enterCallArguments(assignmentOperatorStatement, listOf(assignmentOperatorStatement.rightArgument))
|
||||
val leftArgument = assignmentOperatorStatement.leftArgument.transformSingle(transformer, ResolutionMode.ContextIndependent)
|
||||
val rightArgument = assignmentOperatorStatement.rightArgument.transformSingle(transformer, ResolutionMode.ContextDependent)
|
||||
dataFlowAnalyzer.exitCallArguments()
|
||||
|
||||
val generator = GeneratorOfPlusAssignCalls(assignmentOperatorStatement, operation, leftArgument, rightArgument)
|
||||
dataFlowAnalyzer.enterSelectAugmentedAssignmentCall()
|
||||
|
||||
// x.plusAssign(y)
|
||||
val assignOperatorCall = generator.createAssignOperatorCall()
|
||||
@@ -556,8 +585,6 @@ open class FirExpressionsResolveTransformer(transformer: FirAbstractBodyResolveT
|
||||
val operatorCallReference = resolvedOperatorCall.calleeReference as? FirNamedReferenceWithCandidate
|
||||
val operatorIsSuccessful = operatorCallReference?.isError == false
|
||||
|
||||
dataFlowAnalyzer.exitSelectAugmentedAssignmentCall()
|
||||
|
||||
fun operatorReturnTypeMatches(candidate: Candidate): Boolean {
|
||||
// After KT-45503, non-assign flavor of operator is checked more strictly: the return type must be assignable to the variable.
|
||||
val operatorCallReturnType = resolvedOperatorCall.typeRef.coneType
|
||||
@@ -671,11 +698,17 @@ open class FirExpressionsResolveTransformer(transformer: FirAbstractBodyResolveT
|
||||
return equalityOperatorCall
|
||||
}
|
||||
|
||||
private var resolvingAugmentedAssignment: Boolean = false
|
||||
|
||||
private inline fun <T> resolveCandidateForAssignmentOperatorCall(block: () -> T): T {
|
||||
return callResolver.withNoArgumentsTransform {
|
||||
assert(!resolvingAugmentedAssignment)
|
||||
resolvingAugmentedAssignment = true
|
||||
return try {
|
||||
context.withInferenceSession(InferenceSessionForAssignmentOperatorCall) {
|
||||
block()
|
||||
}
|
||||
} finally {
|
||||
resolvingAugmentedAssignment = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1121,12 +1154,12 @@ open class FirExpressionsResolveTransformer(transformer: FirAbstractBodyResolveT
|
||||
})
|
||||
}
|
||||
|
||||
dataFlowAnalyzer.enterDelegatedConstructorCall()
|
||||
|
||||
dataFlowAnalyzer.enterCallArguments(delegatedConstructorCall, delegatedConstructorCall.arguments)
|
||||
val lastDispatchReceiver = implicitReceiverStack.lastDispatchReceiver()
|
||||
context.forDelegatedConstructorCall(containingConstructor, containingClass as? FirRegularClass, components) {
|
||||
delegatedConstructorCall.transformChildren(transformer, ResolutionMode.ContextDependent)
|
||||
}
|
||||
dataFlowAnalyzer.exitCallArguments()
|
||||
|
||||
val reference = delegatedConstructorCall.calleeReference
|
||||
val constructorType: ConeClassLikeType? = when (reference) {
|
||||
@@ -1225,15 +1258,14 @@ open class FirExpressionsResolveTransformer(transformer: FirAbstractBodyResolveT
|
||||
|
||||
augmentedArraySetCall.transformAnnotations(transformer, data)
|
||||
|
||||
dataFlowAnalyzer.enterCallArguments(augmentedArraySetCall, listOf(augmentedArraySetCall.rhs))
|
||||
// transformedLhsCall: a.get(index)
|
||||
dataFlowAnalyzer.enterAugmentedAssignmentCall()
|
||||
val transformedLhsCall = augmentedArraySetCall.lhsGetCall.transformSingle(transformer, ResolutionMode.ContextIndependent)
|
||||
val transformedRhs = augmentedArraySetCall.rhs.transformSingle(transformer, ResolutionMode.ContextDependent)
|
||||
dataFlowAnalyzer.exitCallArguments()
|
||||
|
||||
val generator = GeneratorOfPlusAssignCalls(augmentedArraySetCall, operation, transformedLhsCall, transformedRhs)
|
||||
|
||||
dataFlowAnalyzer.enterSelectAugmentedAssignmentCall()
|
||||
|
||||
// a.get(b).plusAssign(c)
|
||||
val assignOperatorCall = generator.createAssignOperatorCall()
|
||||
val resolvedAssignCall = resolveCandidateForAssignmentOperatorCall {
|
||||
@@ -1250,15 +1282,12 @@ open class FirExpressionsResolveTransformer(transformer: FirAbstractBodyResolveT
|
||||
|
||||
// prefer a "simpler" variant for dynamics
|
||||
if (transformedLhsCall.calleeReference.resolvedSymbol?.origin == FirDeclarationOrigin.DynamicScope) {
|
||||
dataFlowAnalyzer.exitSelectAugmentedAssignmentCall()
|
||||
return chooseAssign()
|
||||
}
|
||||
|
||||
// <array>.set(<index_i>, <array>.get(<index_i>).plus(c))
|
||||
val info = tryResolveAugmentedArraySetCallAsSetGetBlock(augmentedArraySetCall, transformedLhsCall, transformedRhs)
|
||||
|
||||
dataFlowAnalyzer.exitSelectAugmentedAssignmentCall()
|
||||
|
||||
val resolvedOperatorCall = info.operatorCall
|
||||
val operatorCallReference = resolvedOperatorCall.calleeReference as? FirNamedReferenceWithCandidate
|
||||
val operatorIsSuccessful = operatorCallReference?.isError == false
|
||||
@@ -1482,47 +1511,12 @@ open class FirExpressionsResolveTransformer(transformer: FirAbstractBodyResolveT
|
||||
return anonymousObjectExpression
|
||||
}
|
||||
|
||||
private val nonLambdaArgumentTransformer = object : FirTransformer<ResolutionMode>() {
|
||||
override fun <E : FirElement> transformElement(element: E, data: ResolutionMode): E =
|
||||
element.transform(this@FirExpressionsResolveTransformer, data)
|
||||
|
||||
override fun transformAnonymousFunctionExpression(
|
||||
anonymousFunctionExpression: FirAnonymousFunctionExpression,
|
||||
data: ResolutionMode
|
||||
): FirStatement = anonymousFunctionExpression
|
||||
}
|
||||
|
||||
private val lambdaArgumentTransformer = object : FirTransformer<ResolutionMode>() {
|
||||
override fun <E : FirElement> transformElement(element: E, data: ResolutionMode): E =
|
||||
element
|
||||
|
||||
override fun transformAnonymousFunctionExpression(
|
||||
anonymousFunctionExpression: FirAnonymousFunctionExpression,
|
||||
data: ResolutionMode
|
||||
): FirStatement = this@FirExpressionsResolveTransformer.transformAnonymousFunctionExpression(anonymousFunctionExpression, data)
|
||||
}
|
||||
|
||||
override fun transformArgumentList(argumentList: FirArgumentList, data: ResolutionMode): FirArgumentList {
|
||||
// Transform all normal arguments first and then lambda to make CFG correct. See KT-46825
|
||||
return argumentList
|
||||
.transformArguments(nonLambdaArgumentTransformer, data)
|
||||
.transformArguments(lambdaArgumentTransformer, data)
|
||||
}
|
||||
|
||||
override fun transformAnonymousFunctionExpression(
|
||||
anonymousFunctionExpression: FirAnonymousFunctionExpression,
|
||||
data: ResolutionMode
|
||||
): FirStatement {
|
||||
anonymousFunctionExpression.transformAnonymousFunction(transformer, data)
|
||||
when (data) {
|
||||
is ResolutionMode.ContextDependent, is ResolutionMode.ContextDependentDelegate -> {
|
||||
dataFlowAnalyzer.visitPostponedAnonymousFunction(anonymousFunctionExpression)
|
||||
}
|
||||
else -> {
|
||||
dataFlowAnalyzer.exitAnonymousFunctionExpression(anonymousFunctionExpression)
|
||||
}
|
||||
}
|
||||
return anonymousFunctionExpression
|
||||
dataFlowAnalyzer.enterAnonymousFunctionExpression(anonymousFunctionExpression)
|
||||
return anonymousFunctionExpression.transformAnonymousFunction(transformer, data)
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -243,9 +243,10 @@ class ExitDefaultArgumentsNode(owner: ControlFlowGraph, override val fir: FirVal
|
||||
|
||||
// ----------------------------------- Anonymous function -----------------------------------
|
||||
|
||||
class PostponedLambdaEnterNode(owner: ControlFlowGraph, override val fir: FirAnonymousFunctionExpression, level: Int, id: Int) : CFGNodeWithSubgraphs<FirAnonymousFunctionExpression>(owner, level, id) {
|
||||
class SplitPostponedLambdasNode(owner: ControlFlowGraph, override val fir: FirStatement, val lambdas: List<FirAnonymousFunction>, level: Int, id: Int)
|
||||
: CFGNodeWithSubgraphs<FirStatement>(owner, level, id) {
|
||||
override fun <R, D> accept(visitor: ControlFlowGraphVisitor<R, D>, data: D): R {
|
||||
return visitor.visitPostponedLambdaEnterNode(this, data)
|
||||
return visitor.visitSplitPostponedLambdasNode(this, data)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -261,9 +262,9 @@ class MergePostponedLambdaExitsNode(owner: ControlFlowGraph, override val fir: F
|
||||
}
|
||||
}
|
||||
|
||||
class AnonymousFunctionExpressionExitNode(owner: ControlFlowGraph, override val fir: FirAnonymousFunctionExpression, level: Int, id: Int) : CFGNode<FirAnonymousFunctionExpression>(owner, level, id) {
|
||||
class AnonymousFunctionExpressionNode(owner: ControlFlowGraph, override val fir: FirAnonymousFunctionExpression, level: Int, id: Int) : CFGNodeWithSubgraphs<FirAnonymousFunctionExpression>(owner, level, id) {
|
||||
override fun <R, D> accept(visitor: ControlFlowGraphVisitor<R, D>, data: D): R {
|
||||
return visitor.visitAnonymousFunctionExpressionExitNode(this, data)
|
||||
return visitor.visitAnonymousFunctionExpressionNode(this, data)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-4
@@ -98,12 +98,10 @@ fun CFGNode<*>.render(): String =
|
||||
|
||||
is WhenSubjectExpressionExitNode -> "Exit ${'$'}subj"
|
||||
|
||||
is PostponedLambdaEnterNode -> "Postponed enter to lambda"
|
||||
is SplitPostponedLambdasNode -> "Postponed enter to lambda"
|
||||
is PostponedLambdaExitNode -> "Postponed exit from lambda"
|
||||
|
||||
is AnonymousFunctionExpressionExitNode -> "Exit anonymous function expression"
|
||||
|
||||
is MergePostponedLambdaExitsNode -> "Merge postponed lambda exits"
|
||||
is AnonymousFunctionExpressionNode -> "Exit anonymous function expression"
|
||||
|
||||
is ClassEnterNode -> "Enter class ${owner.name}"
|
||||
is ClassExitNode -> "Exit class ${owner.name}"
|
||||
|
||||
+2
-2
@@ -36,7 +36,7 @@ abstract class ControlFlowGraphVisitor<out R, in D> {
|
||||
|
||||
// ----------------------------------- Anonymous function -----------------------------------
|
||||
|
||||
open fun visitPostponedLambdaEnterNode(node: PostponedLambdaEnterNode, data: D): R {
|
||||
open fun visitSplitPostponedLambdasNode(node: SplitPostponedLambdasNode, data: D): R {
|
||||
return visitNode(node, data)
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ abstract class ControlFlowGraphVisitor<out R, in D> {
|
||||
return visitNode(node, data)
|
||||
}
|
||||
|
||||
open fun visitAnonymousFunctionExpressionExitNode(node: AnonymousFunctionExpressionExitNode, data: D): R {
|
||||
open fun visitAnonymousFunctionExpressionNode(node: AnonymousFunctionExpressionNode, data: D): R {
|
||||
return visitNode(node, data)
|
||||
}
|
||||
|
||||
|
||||
+19
-3
@@ -20,9 +20,13 @@ abstract class ControlFlowGraphVisitorVoid : ControlFlowGraphVisitor<Unit, Nothi
|
||||
visitNode(node)
|
||||
}
|
||||
|
||||
open fun visitLocalFunctionDeclarationNode(node: LocalFunctionDeclarationNode) {
|
||||
visitNode(node)
|
||||
}
|
||||
|
||||
// ----------------------------------- Anonymous function -----------------------------------
|
||||
|
||||
open fun visitPostponedLambdaEnterNode(node: PostponedLambdaEnterNode) {
|
||||
open fun visitSplitPostponedLambdasNode(node: SplitPostponedLambdasNode) {
|
||||
visitNode(node)
|
||||
}
|
||||
|
||||
@@ -34,6 +38,10 @@ abstract class ControlFlowGraphVisitorVoid : ControlFlowGraphVisitor<Unit, Nothi
|
||||
visitNode(node)
|
||||
}
|
||||
|
||||
open fun visitAnonymousFunctionExpressionNode(node: AnonymousFunctionExpressionNode) {
|
||||
visitNode(node)
|
||||
}
|
||||
|
||||
// ----------------------------------- Anonymous object -----------------------------------
|
||||
|
||||
open fun visitAnonymousObjectExitNode(node: AnonymousObjectExitNode) {
|
||||
@@ -313,10 +321,14 @@ abstract class ControlFlowGraphVisitorVoid : ControlFlowGraphVisitor<Unit, Nothi
|
||||
visitFunctionExitNode(node)
|
||||
}
|
||||
|
||||
final override fun visitLocalFunctionDeclarationNode(node: LocalFunctionDeclarationNode, data: Nothing?) {
|
||||
visitLocalFunctionDeclarationNode(node)
|
||||
}
|
||||
|
||||
// ----------------------------------- Anonymous function -----------------------------------
|
||||
|
||||
final override fun visitPostponedLambdaEnterNode(node: PostponedLambdaEnterNode, data: Nothing?) {
|
||||
visitPostponedLambdaEnterNode(node)
|
||||
final override fun visitSplitPostponedLambdasNode(node: SplitPostponedLambdasNode, data: Nothing?) {
|
||||
visitSplitPostponedLambdasNode(node)
|
||||
}
|
||||
|
||||
final override fun visitPostponedLambdaExitNode(node: PostponedLambdaExitNode, data: Nothing?) {
|
||||
@@ -327,6 +339,10 @@ abstract class ControlFlowGraphVisitorVoid : ControlFlowGraphVisitor<Unit, Nothi
|
||||
visitMergePostponedLambdaExitsNode(node)
|
||||
}
|
||||
|
||||
final override fun visitAnonymousFunctionExpressionNode(node: AnonymousFunctionExpressionNode, data: Nothing?) {
|
||||
visitAnonymousFunctionExpressionNode(node)
|
||||
}
|
||||
|
||||
// ----------------------------------- Anonymous object -----------------------------------
|
||||
|
||||
final override fun visitAnonymousObjectExitNode(node: AnonymousObjectExitNode, data: Nothing?) {
|
||||
|
||||
Reference in New Issue
Block a user