FIR checker: substitute type parameters in dispatch receiver type

Consider the following code:

```
fun test(a: List<String>) {
  a.first()
}
```

The dispatch receiver type of `first` in this case is `List<T>` before
this change. After this change, it's `List<String>`.

In addition, this change also replace the dispatch receiver type with
the more specific type if available. For example, consider the following

```
class MyList: ArrayList<String>()

fun test(a: MyList) {
  a.get(0)
}
```
The dispatch receiver type of `get` is `MyList`, instead of
`ArrayList<String>`. That is, a fake override is created in this case.
This commit is contained in:
Tianyu Geng
2021-08-06 14:56:37 -07:00
committed by teamcityserver
parent c047adbaec
commit 765cad8448
61 changed files with 342 additions and 145 deletions
@@ -54,7 +54,7 @@ digraph boundSmartcastsInBranches_kt {
color=blue
18 [label="Enter loop condition"];
19 [label="Access variable R|<local>/<iterator>|"];
20 [label="Function call: R|<local>/<iterator>|.R|kotlin/collections/Iterator.hasNext|()"];
20 [label="Function call: R|<local>/<iterator>|.R|SubstitutionOverride<kotlin/collections/Iterator.hasNext: R|kotlin/Boolean|>|()"];
21 [label="Exit loop condition"];
}
subgraph cluster_8 {
@@ -84,7 +84,7 @@ digraph boundSmartcastsInBranches_kt {
35 [label="Enter block"];
36 [label="Access variable R|<local>/a|"];
37 [label="Assignment: R|<local>/goodA|"];
38 [label="Jump: continue@@@[R|<local>/<iterator>|.R|kotlin/collections/Iterator.hasNext|()] "];
38 [label="Jump: continue@@@[R|<local>/<iterator>|.R|SubstitutionOverride<kotlin/collections/Iterator.hasNext: R|kotlin/Boolean|>|()] "];
39 [label="Stub" style="filled" fillcolor=gray];
40 [label="Exit block" style="filled" fillcolor=gray];
}
@@ -12,12 +12,12 @@ FILE: boundSmartcastsInBranches.kt
lvar goodA: R|A?| = Null(null)
{
lval <iterator>: R|kotlin/collections/Iterator<A>| = R|<local>/list|.R|SubstitutionOverride<kotlin/collections/List.iterator: R|kotlin/collections/Iterator<A>|>|()
while(R|<local>/<iterator>|.R|kotlin/collections/Iterator.hasNext|()) {
while(R|<local>/<iterator>|.R|SubstitutionOverride<kotlin/collections/Iterator.hasNext: R|kotlin/Boolean|>|()) {
lval a: R|A| = R|<local>/<iterator>|.R|SubstitutionOverride<kotlin/collections/Iterator.next: R|A|>|()
when () {
==(R|<local>/goodA|, Null(null)) -> {
R|<local>/goodA| = R|<local>/a|
continue@@@[R|<local>/<iterator>|.R|kotlin/collections/Iterator.hasNext|()]
continue@@@[R|<local>/<iterator>|.R|SubstitutionOverride<kotlin/collections/Iterator.hasNext: R|kotlin/Boolean|>|()]
}
}
@@ -51,7 +51,7 @@ digraph implicitReceiverAsWhenSubject_kt {
color=blue
23 [label="Enter block"];
24 [label="Access variable this@R|/test_1|"];
25 [label="Access variable R|kotlin/collections/List.size|"];
25 [label="Access variable R|SubstitutionOverride<kotlin/collections/List.size: R|kotlin/Int|>|"];
26 [label="Exit block"];
}
27 [label="Exit when branch result"];
@@ -59,7 +59,7 @@ digraph implicitReceiverAsWhenSubject_kt {
}
29 [label="Jump: ^test_1 when (this@R|/test_1|) {
($subj$ is R|kotlin/collections/List<*>|) -> {
this@R|/test_1|.R|kotlin/collections/List.size|
this@R|/test_1|.R|SubstitutionOverride<kotlin/collections/List.size: R|kotlin/Int|>|
}
($subj$ is R|kotlin/String|) -> {
this@R|/test_1|.R|kotlin/String.length|
@@ -159,9 +159,9 @@ digraph implicitReceiverAsWhenSubject_kt {
color=blue
59 [label="Enter block"];
60 [label="Access variable R|<local>/x|"];
61 [label="Access variable R|kotlin/collections/List.size|"];
61 [label="Access variable R|SubstitutionOverride<kotlin/collections/List.size: R|kotlin/Int|>|"];
62 [label="Access variable this@R|/test_2|"];
63 [label="Access variable R|kotlin/collections/List.size|"];
63 [label="Access variable R|SubstitutionOverride<kotlin/collections/List.size: R|kotlin/Int|>|"];
64 [label="Exit block"];
}
65 [label="Exit when branch result"];
@@ -169,8 +169,8 @@ digraph implicitReceiverAsWhenSubject_kt {
}
67 [label="Jump: ^test_2 when (lval x: R|kotlin/Any| = this@R|/test_2|) {
($subj$ is R|kotlin/collections/List<*>|) -> {
R|<local>/x|.R|kotlin/collections/List.size|
this@R|/test_2|.R|kotlin/collections/List.size|
R|<local>/x|.R|SubstitutionOverride<kotlin/collections/List.size: R|kotlin/Int|>|
this@R|/test_2|.R|SubstitutionOverride<kotlin/collections/List.size: R|kotlin/Int|>|
}
($subj$ is R|kotlin/String|) -> {
R|<local>/x|.R|kotlin/String.length|
@@ -2,7 +2,7 @@ FILE: implicitReceiverAsWhenSubject.kt
public final fun R|kotlin/Any|.test_1(): R|kotlin/Int| {
^test_1 when (this@R|/test_1|) {
($subj$ is R|kotlin/collections/List<*>|) -> {
this@R|/test_1|.R|kotlin/collections/List.size|
this@R|/test_1|.R|SubstitutionOverride<kotlin/collections/List.size: R|kotlin/Int|>|
}
($subj$ is R|kotlin/String|) -> {
this@R|/test_1|.R|kotlin/String.length|
@@ -16,8 +16,8 @@ FILE: implicitReceiverAsWhenSubject.kt
public final fun R|kotlin/Any|.test_2(): R|kotlin/Int| {
^test_2 when (lval x: R|kotlin/Any| = this@R|/test_2|) {
($subj$ is R|kotlin/collections/List<*>|) -> {
R|<local>/x|.R|kotlin/collections/List.size|
this@R|/test_2|.R|kotlin/collections/List.size|
R|<local>/x|.R|SubstitutionOverride<kotlin/collections/List.size: R|kotlin/Int|>|
this@R|/test_2|.R|SubstitutionOverride<kotlin/collections/List.size: R|kotlin/Int|>|
}
($subj$ is R|kotlin/String|) -> {
R|<local>/x|.R|kotlin/String.length|
@@ -547,7 +547,7 @@ digraph implicitReceivers_kt {
subgraph cluster_52 {
color=blue
202 [label="Enter block"];
203 [label="Access variable R|kotlin/collections/List.size|"];
203 [label="Access variable R|SubstitutionOverride<kotlin/collections/List.size: R|kotlin/Int|>|"];
204 [label="Exit block"];
}
205 [label="Exit when branch result"];
@@ -555,7 +555,7 @@ digraph implicitReceivers_kt {
}
207 [label="Jump: ^test_5 when () {
(this@R|/test_5| is R|kotlin/collections/List<*>|) -> {
this@R|/test_5|.R|kotlin/collections/List.size|
this@R|/test_5|.R|SubstitutionOverride<kotlin/collections/List.size: R|kotlin/Int|>|
}
(this@R|/test_5| is R|kotlin/String|) -> {
this@R|/test_5|.R|kotlin/String.length|
@@ -612,7 +612,7 @@ digraph implicitReceivers_kt {
212 [label="Enter block"];
213 [label="Access variable this@R|/test_6|"];
214 [label="Type operator: (this@R|/test_6| as R|kotlin/collections/List<*>|)"];
215 [label="Access variable R|kotlin/collections/List.size|"];
215 [label="Access variable R|SubstitutionOverride<kotlin/collections/List.size: R|kotlin/Int|>|"];
216 [label="Access variable this@R|/test_6|"];
217 [label="Type operator: (this@R|/test_6| as R|kotlin/String|)"];
218 [label="Access variable R|kotlin/String.length|"];
@@ -100,7 +100,7 @@ FILE: implicitReceivers.kt
public final fun R|kotlin/Any|.test_5(): R|kotlin/Int| {
^test_5 when () {
(this@R|/test_5| is R|kotlin/collections/List<*>|) -> {
this@R|/test_5|.R|kotlin/collections/List.size|
this@R|/test_5|.R|SubstitutionOverride<kotlin/collections/List.size: R|kotlin/Int|>|
}
(this@R|/test_5| is R|kotlin/String|) -> {
this@R|/test_5|.R|kotlin/String.length|
@@ -113,7 +113,7 @@ FILE: implicitReceivers.kt
}
public final fun R|kotlin/Any|.test_6(): R|kotlin/Unit| {
(this@R|/test_6| as R|kotlin/collections/List<*>|)
this@R|/test_6|.R|kotlin/collections/List.size|
this@R|/test_6|.R|SubstitutionOverride<kotlin/collections/List.size: R|kotlin/Int|>|
(this@R|/test_6| as R|kotlin/String|)
this@R|/test_6|.R|kotlin/String.length|
}
@@ -181,7 +181,7 @@ digraph smartcastToNothing_kt {
color=blue
61 [label="Enter loop condition"];
62 [label="Access variable R|<local>/<iterator>|"];
63 [label="Function call: R|<local>/<iterator>|.R|kotlin/collections/Iterator.hasNext|()"];
63 [label="Function call: R|<local>/<iterator>|.R|SubstitutionOverride<kotlin/collections/Iterator.hasNext: R|kotlin/Boolean|>|()"];
64 [label="Exit loop condition"];
}
subgraph cluster_19 {
@@ -213,7 +213,7 @@ digraph smartcastToNothing_kt {
subgraph cluster_23 {
color=blue
82 [label="Enter block" style="filled" fillcolor=gray];
83 [label="Jump: break@@@[R|<local>/<iterator>|.R|kotlin/collections/Iterator.hasNext|()] " style="filled" fillcolor=gray];
83 [label="Jump: break@@@[R|<local>/<iterator>|.R|SubstitutionOverride<kotlin/collections/Iterator.hasNext: R|kotlin/Boolean|>|()] " style="filled" fillcolor=gray];
84 [label="Stub" style="filled" fillcolor=gray];
85 [label="Exit block" style="filled" fillcolor=gray];
}
@@ -32,12 +32,12 @@ FILE: smartcastToNothing.kt
lvar s: R|A?| = Null(null)
{
lval <iterator>: R|kotlin/collections/Iterator<kotlin/Nothing>| = R|<local>/results|.R|SubstitutionOverride<kotlin/collections/List.iterator: R|kotlin/collections/Iterator<kotlin/Nothing>|>|()
while(R|<local>/<iterator>|.R|kotlin/collections/Iterator.hasNext|()) {
while(R|<local>/<iterator>|.R|SubstitutionOverride<kotlin/collections/Iterator.hasNext: R|kotlin/Boolean|>|()) {
lval result: R|kotlin/Nothing| = R|<local>/<iterator>|.R|SubstitutionOverride<kotlin/collections/Iterator.next: R|kotlin/Nothing|>|()
R|<local>/s| = R|<local>/result|
when () {
R|<local>/result|.<Unresolved name: b># -> {
break@@@[R|<local>/<iterator>|.R|kotlin/collections/Iterator.hasNext|()]
break@@@[R|<local>/<iterator>|.R|SubstitutionOverride<kotlin/collections/Iterator.hasNext: R|kotlin/Boolean|>|()]
}
}