FIR DFA: take all statements from ?. if result is non-null.

I.e. a?.f(b as T) != null => b is T.

This also allows to remove the copyAllInformationFrom hack by moving the
edge directly in the control flow graph.
This commit is contained in:
pyos
2022-11-19 19:13:27 +01:00
committed by teamcity
parent 3392e066df
commit 16b8811697
14 changed files with 278 additions and 245 deletions
@@ -40,51 +40,116 @@ digraph safeCalls_kt {
10 [label="Access variable R|<local>/x|"];
11 [label="Enter safe call"];
12 [label="Function call: $subj$.R|/A.foo|()"];
13 [label="Exit safe call"];
14 [label="Enter safe call"];
15 [label="Function call: $subj$.R|/A.bar|()"];
13 [label="Enter safe call"];
14 [label="Const: String()"];
15 [label="Function call: $subj$.R|/A.bar|(...)"];
16 [label="Exit safe call"];
17 [label="Exit block"];
17 [label="Exit safe call"];
18 [label="Exit block"];
}
18 [label="Exit function test_1" style="filled" fillcolor=red];
19 [label="Exit function test_1" style="filled" fillcolor=red];
}
8 -> {9};
9 -> {10};
10 -> {11 13};
10 -> {11 16};
11 -> {12};
12 -> {13};
13 -> {14 16};
12 -> {16 13};
13 -> {14};
14 -> {15};
15 -> {16};
15 -> {17};
16 -> {17};
17 -> {18};
18 -> {19};
subgraph cluster_6 {
color=red
19 [label="Enter function test_2" style="filled" fillcolor=red];
20 [label="Enter function test_2" style="filled" fillcolor=red];
subgraph cluster_7 {
color=blue
20 [label="Enter block"];
21 [label="Access variable R|<local>/x|"];
22 [label="Enter safe call"];
23 [label="Access variable R|/B.foo|"];
24 [label="Exit safe call"];
21 [label="Enter block"];
22 [label="Access variable R|<local>/x|"];
23 [label="Enter safe call"];
24 [label="Access variable R|/B.foo|"];
25 [label="Enter safe call"];
26 [label="Access variable R|/B.bar|"];
27 [label="Exit safe call"];
28 [label="Exit block"];
28 [label="Exit safe call"];
29 [label="Exit block"];
}
29 [label="Exit function test_2" style="filled" fillcolor=red];
30 [label="Exit function test_2" style="filled" fillcolor=red];
}
19 -> {20};
20 -> {21};
21 -> {22 24};
22 -> {23};
21 -> {22};
22 -> {23 27};
23 -> {24};
24 -> {25 27};
24 -> {27 25};
25 -> {26};
26 -> {27};
26 -> {28};
27 -> {28};
28 -> {29};
29 -> {30};
subgraph cluster_8 {
color=red
31 [label="Enter function test_3" style="filled" fillcolor=red];
subgraph cluster_9 {
color=blue
32 [label="Enter block"];
subgraph cluster_10 {
color=blue
33 [label="Enter when"];
subgraph cluster_11 {
color=blue
34 [label="Enter when branch condition "];
35 [label="Access variable R|<local>/x|"];
36 [label="Enter safe call"];
37 [label="Access variable R|<local>/y|"];
38 [label="Type operator: (R|<local>/y| as R|kotlin/String|)"];
39 [label="Function call: $subj$.R|/A.bar|(...)"];
40 [label="Exit safe call"];
41 [label="Const: Null(null)"];
42 [label="Equality operator !="];
43 [label="Exit when branch condition"];
}
44 [label="Synthetic else branch"];
45 [label="Enter when branch result"];
subgraph cluster_12 {
color=blue
46 [label="Enter block"];
47 [label="Access variable R|<local>/y|"];
48 [label="Smart cast: R|<local>/y|"];
49 [label="Access variable R|kotlin/String.length|"];
50 [label="Exit block"];
}
51 [label="Exit when branch result"];
52 [label="Exit when"];
}
53 [label="Exit block"];
}
54 [label="Exit function test_3" style="filled" fillcolor=red];
}
31 -> {32};
32 -> {33};
33 -> {34};
34 -> {35};
35 -> {36 40};
36 -> {37};
37 -> {38};
38 -> {39};
39 -> {40};
40 -> {41};
41 -> {42};
42 -> {43};
43 -> {45 44};
44 -> {52};
45 -> {46};
46 -> {47};
47 -> {48};
48 -> {49};
49 -> {50};
50 -> {51};
51 -> {52};
52 -> {53};
53 -> {54};
}
@@ -2,7 +2,7 @@ FILE: safeCalls.kt
public abstract interface A : R|kotlin/Any| {
public abstract fun foo(): R|A|
public abstract fun bar(): R|A|
public abstract fun bar(x: R|kotlin/String|): R|A|
}
public abstract interface B : R|kotlin/Any| {
@@ -14,8 +14,16 @@ FILE: safeCalls.kt
}
public final fun test_1(x: R|A?|): R|kotlin/Unit| {
R|<local>/x|?.{ $subj$.R|/A.foo|() }?.{ $subj$.R|/A.bar|() }
R|<local>/x|?.{ $subj$.R|/A.foo|() }?.{ $subj$.R|/A.bar|(String()) }
}
public final fun test_2(x: R|B?|): R|kotlin/Unit| {
R|<local>/x|?.{ $subj$.R|/B.foo| }?.{ $subj$.R|/B.bar| }
}
public final fun test_3(x: R|A?|, y: R|kotlin/String?|): R|kotlin/Unit| {
when () {
!=(R|<local>/x|?.{ $subj$.R|/A.bar|((R|<local>/y| as R|kotlin/String|)) }, Null(null)) -> {
R|<local>/y|.R|kotlin/String.length|
}
}
}
@@ -1,7 +1,7 @@
// !DUMP_CFG
interface A {
fun foo(): A
fun bar(): A
fun bar(x: String): A
}
interface B {
@@ -10,9 +10,15 @@ interface B {
}
fun test_1(x: A?) {
x?.foo()?.bar()
x?.foo()?.bar("")
}
fun test_2(x: B?) {
x?.foo?.bar
}
fun test_3(x: A?, y: String?) {
if (x?.bar(y as String) != null) {
y.length
}
}