FIR CFG: join/unify data flow from postponed lambdas at each level

For example:

    foo(
        // `if` joins A & B
        if (condition)
            run { ... } // A
        else
            run { ... }, // B
        run { ... } // C
    ) // `foo` unifies `A & B` and `C`, so if it is not resolved itself,
      // further `if`s, `when`s, safe calls outside it, etc. continue
      // building the correct type predicate until the next completed
      // call.

^KT-44512 Fixed
This commit is contained in:
pyos
2022-06-13 14:17:34 +02:00
committed by teamcity
parent 755c54553a
commit 63b0708ed5
17 changed files with 720 additions and 623 deletions
File diff suppressed because it is too large Load Diff
@@ -28,7 +28,7 @@ FILE: flowFromInplaceLambda2.kt
^ R|/n|<R|kotlin/Nothing?|>()
}
)), R|/someCompletedCall|(Int(1)), R|kotlin/run|<R|kotlin/Int|>(<L> = run@fun <anonymous>(): R|kotlin/Int| <inline=Inline, kind=EXACTLY_ONCE> {
R|<local>/x|.R|kotlin/String.length|
R|<local>/x|.<Inapplicable(UNSAFE_CALL): kotlin/String.length>#
^ Int(123)
}
))
@@ -52,7 +52,7 @@ FILE: flowFromInplaceLambda2.kt
^ Int(123)
}
))
R|<local>/x|.<Inapplicable(UNSAFE_CALL): kotlin/String.length>#
R|<local>/x|.R|kotlin/String.length|
}
public final fun test4(x: R|kotlin/String?|): R|kotlin/Unit| {
lvar p: R|kotlin/String?| = R|<local>/x|
@@ -74,11 +74,11 @@ FILE: flowFromInplaceLambda2.kt
}
}
), Int(1), R|kotlin/run|<R|kotlin/Int|>(<L> = run@fun <anonymous>(): R|kotlin/Int| <inline=Inline, kind=EXACTLY_ONCE> {
R|<local>/p|.R|kotlin/String.length|
R|<local>/p|.<Inapplicable(UNSAFE_CALL): kotlin/String.length>#
^ Int(123)
}
))
R|<local>/p|.R|kotlin/String.length|
R|<local>/p|.<Inapplicable(UNSAFE_CALL): kotlin/String.length>#
}
}
@@ -92,7 +92,7 @@ FILE: flowFromInplaceLambda2.kt
^ String()
}
))
R|<local>/x|.R|kotlin/String.length|
R|<local>/x|.<Inapplicable(UNSAFE_CALL): kotlin/String.length>#
}
public final fun test6(x: R|kotlin/String?|): R|kotlin/Unit| {
R|/foo|<R|kotlin/Int|>(R|/id|<R|kotlin/Nothing?|>(when () {
@@ -21,7 +21,7 @@ fun test2(x: String?) {
foo(
id(run { x as String; n() }),
someCompletedCall(1),
run { x.length; 123 } // Bad (resolution order undefined)
run { x<!UNSAFE_CALL!>.<!>length; 123 } // Bad (resolution order undefined)
)
x.length // OK (x as String unconditional)
}
@@ -32,7 +32,7 @@ fun test3(x: String?) {
if (true) 1 else 2,
run { x<!UNSAFE_CALL!>.<!>length; 123 } // Bad (resolution order undefined)
)
x<!UNSAFE_CALL!>.<!>length // OK (x as String unconditional)
x.length // OK (x as String unconditional)
}
fun test4(x: String?) {
@@ -41,9 +41,9 @@ fun test4(x: String?) {
foo(
id(if (true) run { p = null; n() } else run { n() }),
1,
run { p.length; 123 } // Bad (p = null possible)
run { p<!UNSAFE_CALL!>.<!>length; 123 } // Bad (p = null possible)
)
p.length // Bad (p = null possible)
p<!UNSAFE_CALL!>.<!>length // Bad (p = null possible)
}
}
@@ -53,7 +53,7 @@ fun test5(x: String?, y: String?) {
1,
run { "" }
)
x.length // Bad (x as String conditional)
x<!UNSAFE_CALL!>.<!>length // Bad (x as String conditional)
}
fun test6(x: String?) {
@@ -63,14 +63,14 @@ digraph inplaceLambdaInControlFlowExpressions_kt {
24 [label="Postponed enter to lambda"];
subgraph cluster_9 {
color=blue
33 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
34 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
subgraph cluster_10 {
color=blue
34 [label="Enter block"];
35 [label="Function call: R|/materialize|<R|kotlin/String|>()"];
36 [label="Exit block"];
35 [label="Enter block"];
36 [label="Function call: R|/materialize|<R|kotlin/String|>()"];
37 [label="Exit block"];
}
37 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
38 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
}
25 [label="Postponed exit from lambda"];
26 [label="Function call: R|kotlin/run|<R|kotlin/String|>(...)"];
@@ -84,6 +84,7 @@ digraph inplaceLambdaInControlFlowExpressions_kt {
}
32 [label="Exit function test_1" style="filled" fillcolor=red];
}
33 [label="Merge postponed lambda exits"];
9 -> {10};
10 -> {11};
11 -> {12};
@@ -99,89 +100,89 @@ digraph inplaceLambdaInControlFlowExpressions_kt {
21 -> {29};
22 -> {23};
23 -> {24};
24 -> {33};
24 -> {34};
24 -> {25} [color=red];
24 -> {33} [style=dashed];
24 -> {34} [style=dashed];
25 -> {26};
26 -> {27};
27 -> {28};
28 -> {29};
29 -> {30};
29 -> {33 30};
30 -> {31};
31 -> {32};
33 -> {34};
34 -> {35};
35 -> {36};
36 -> {37};
37 -> {25} [color=green];
37 -> {38};
38 -> {33} [color=red];
38 -> {25} [color=green];
subgraph cluster_11 {
color=red
38 [label="Enter function test_2" style="filled" fillcolor=red];
39 [label="Enter function test_2" style="filled" fillcolor=red];
subgraph cluster_12 {
color=blue
39 [label="Enter block"];
40 [label="Enter block"];
subgraph cluster_13 {
color=blue
40 [label="Try expression enter"];
41 [label="Try expression enter"];
subgraph cluster_14 {
color=blue
41 [label="Try main block enter"];
42 [label="Try main block enter"];
subgraph cluster_15 {
color=blue
42 [label="Enter block"];
43 [label="Postponed enter to lambda"];
43 [label="Enter block"];
44 [label="Postponed enter to lambda"];
subgraph cluster_16 {
color=blue
58 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
59 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
subgraph cluster_17 {
color=blue
59 [label="Enter block"];
60 [label="Function call: R|/materialize|<R|kotlin/String|>()"];
61 [label="Exit block"];
60 [label="Enter block"];
61 [label="Function call: R|/materialize|<R|kotlin/String|>()"];
62 [label="Exit block"];
}
62 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
63 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
}
44 [label="Postponed exit from lambda"];
45 [label="Function call: R|kotlin/run|<R|kotlin/String|>(...)"];
46 [label="Exit block"];
45 [label="Postponed exit from lambda"];
46 [label="Function call: R|kotlin/run|<R|kotlin/String|>(...)"];
47 [label="Exit block"];
}
47 [label="Try main block exit"];
48 [label="Try main block exit"];
}
subgraph cluster_18 {
color=blue
48 [label="Catch enter"];
49 [label="Catch enter"];
subgraph cluster_19 {
color=blue
49 [label="Enter block"];
50 [label="Const: String()"];
51 [label="Exit block"];
50 [label="Enter block"];
51 [label="Const: String()"];
52 [label="Exit block"];
}
52 [label="Catch exit"];
53 [label="Catch exit"];
}
53 [label="Try expression exit"];
54 [label="Try expression exit"];
}
54 [label="Call arguments union" style="filled" fillcolor=yellow];
55 [label="Variable declaration: lval x: R|kotlin/String|"];
56 [label="Exit block"];
55 [label="Call arguments union" style="filled" fillcolor=yellow];
56 [label="Variable declaration: lval x: R|kotlin/String|"];
57 [label="Exit block"];
}
57 [label="Exit function test_2" style="filled" fillcolor=red];
58 [label="Exit function test_2" style="filled" fillcolor=red];
}
38 -> {39};
39 -> {40};
40 -> {41 48};
41 -> {42};
40 -> {41};
41 -> {42 49};
42 -> {43};
43 -> {58};
43 -> {44} [color=red];
43 -> {58} [style=dashed];
44 -> {45};
43 -> {44};
44 -> {59};
44 -> {45} [color=red];
44 -> {59} [style=dashed];
45 -> {46};
46 -> {47};
47 -> {53 48};
48 -> {49};
48 -> {57} [label=onUncaughtException];
47 -> {48};
48 -> {54 49};
49 -> {50};
49 -> {58} [label=onUncaughtException];
50 -> {51};
51 -> {52};
52 -> {53};
@@ -189,56 +190,57 @@ digraph inplaceLambdaInControlFlowExpressions_kt {
54 -> {55};
55 -> {56};
56 -> {57};
58 -> {59};
57 -> {58};
59 -> {60};
60 -> {61};
61 -> {62};
62 -> {54} [color=red];
62 -> {44} [color=green];
62 -> {63};
63 -> {55} [color=red];
63 -> {45} [color=green];
subgraph cluster_20 {
color=red
63 [label="Enter function test_3" style="filled" fillcolor=red];
64 [label="Enter function test_3" style="filled" fillcolor=red];
subgraph cluster_21 {
color=blue
64 [label="Enter block"];
65 [label="Postponed enter to lambda"];
65 [label="Enter block"];
66 [label="Postponed enter to lambda"];
subgraph cluster_22 {
color=blue
73 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
74 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
subgraph cluster_23 {
color=blue
74 [label="Enter block"];
75 [label="Function call: R|/materialize|<R|kotlin/String?|>()"];
76 [label="Exit block"];
75 [label="Enter block"];
76 [label="Function call: R|/materialize|<R|kotlin/String?|>()"];
77 [label="Exit block"];
}
77 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
78 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
}
66 [label="Postponed exit from lambda"];
67 [label="Function call: R|kotlin/run|<R|kotlin/String?|>(...)"];
68 [label="Check not null: R|kotlin/run|<R|kotlin/String?|>(...)!!"];
69 [label="Call arguments union" style="filled" fillcolor=yellow];
70 [label="Variable declaration: lval x: R|kotlin/String|"];
71 [label="Exit block"];
67 [label="Postponed exit from lambda"];
68 [label="Function call: R|kotlin/run|<R|kotlin/String?|>(...)"];
69 [label="Check not null: R|kotlin/run|<R|kotlin/String?|>(...)!!"];
70 [label="Call arguments union" style="filled" fillcolor=yellow];
71 [label="Variable declaration: lval x: R|kotlin/String|"];
72 [label="Exit block"];
}
72 [label="Exit function test_3" style="filled" fillcolor=red];
73 [label="Exit function test_3" style="filled" fillcolor=red];
}
63 -> {64};
64 -> {65};
65 -> {73};
65 -> {66} [color=red];
65 -> {73} [style=dashed];
66 -> {67};
65 -> {66};
66 -> {74};
66 -> {67} [color=red];
66 -> {74} [style=dashed];
67 -> {68};
68 -> {69};
69 -> {70};
70 -> {71};
71 -> {72};
73 -> {74};
72 -> {73};
74 -> {75};
75 -> {76};
76 -> {77};
77 -> {69} [color=red];
77 -> {66} [color=green];
77 -> {78};
78 -> {70} [color=red];
78 -> {67} [color=green];
}
@@ -69,16 +69,16 @@ digraph incorrectSmartcastToNothing_kt {
33 [label="Postponed enter to lambda"];
subgraph cluster_10 {
color=blue
43 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
45 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
subgraph cluster_11 {
color=blue
44 [label="Enter block"];
45 [label="Access variable R|<local>/it|"];
46 [label="Const: String(main.kts.compiled.cache)"];
47 [label="Function call: R|java/io/File.File|(...)"];
48 [label="Exit block"];
46 [label="Enter block"];
47 [label="Access variable R|<local>/it|"];
48 [label="Const: String(main.kts.compiled.cache)"];
49 [label="Function call: R|java/io/File.File|(...)"];
50 [label="Exit block"];
}
49 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
51 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
}
34 [label="Postponed exit from lambda"];
35 [label="Function call: $subj$.R|kotlin/let|<R|java/io/File|, R|java/io/File|>(...)"];
@@ -93,6 +93,8 @@ digraph incorrectSmartcastToNothing_kt {
}
42 [label="Exit function test" style="filled" fillcolor=red];
}
43 [label="Merge postponed lambda exits"];
44 [label="Merge postponed lambda exits"];
4 -> {5};
5 -> {6};
6 -> {7};
@@ -122,23 +124,25 @@ digraph incorrectSmartcastToNothing_kt {
30 -> {31};
31 -> {32 36};
32 -> {33};
33 -> {43};
33 -> {45};
33 -> {34} [color=red];
33 -> {43} [style=dashed];
33 -> {45} [style=dashed];
34 -> {35};
35 -> {36};
36 -> {37};
36 -> {43 37};
37 -> {38};
38 -> {39};
39 -> {40};
39 -> {44 40};
40 -> {41};
41 -> {42};
43 -> {44};
44 -> {45};
43 -> {44} [color=red];
45 -> {46};
46 -> {47};
47 -> {48};
48 -> {49};
49 -> {34} [color=green];
49 -> {50};
50 -> {51};
51 -> {43} [color=red];
51 -> {34} [color=green];
}
@@ -135,14 +135,14 @@ digraph lambdaInWhenBranch_kt {
48 [label="Postponed enter to lambda"];
subgraph cluster_18 {
color=blue
81 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
82 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
subgraph cluster_19 {
color=blue
82 [label="Enter block"];
83 [label="Access variable R|<local>/it|"];
84 [label="Exit block"];
83 [label="Enter block"];
84 [label="Access variable R|<local>/it|"];
85 [label="Exit block"];
}
85 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
86 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
}
49 [label="Postponed exit from lambda"];
50 [label="Function call: String().R|kotlin/let|<R|kotlin/String|, R|kotlin/String|>(...)"];
@@ -195,6 +195,7 @@ digraph lambdaInWhenBranch_kt {
}
80 [label="Exit function foo" style="filled" fillcolor=red];
}
81 [label="Merge postponed lambda exits"];
28 -> {29};
29 -> {30};
30 -> {31};
@@ -215,14 +216,14 @@ digraph lambdaInWhenBranch_kt {
45 -> {46};
46 -> {47};
47 -> {48};
48 -> {81};
48 -> {82};
48 -> {49} [color=red];
48 -> {81} [style=dashed];
48 -> {82} [style=dashed];
49 -> {50};
50 -> {51};
51 -> {52};
52 -> {53};
53 -> {54};
53 -> {81 54};
54 -> {55};
55 -> {56};
56 -> {57};
@@ -249,10 +250,11 @@ digraph lambdaInWhenBranch_kt {
77 -> {78};
78 -> {79};
79 -> {80};
81 -> {82};
82 -> {83};
83 -> {84};
84 -> {85};
85 -> {49} [color=green];
85 -> {86};
86 -> {81} [color=red];
86 -> {49} [color=green];
}