[PSI2IR] Propagate smart cast information for variable loads.

This gives us more precise type information and can enable backend
optimizations. This was motivated by when expressions not compiled
to table switches in the JVM_IR backend.

Fixed KT-36845.
This commit is contained in:
Mads Ager
2020-12-17 12:51:53 +01:00
committed by Dmitry Petrov
parent 98a9e142e8
commit 6fc0de39c2
24 changed files with 59 additions and 69 deletions
@@ -89,7 +89,7 @@ fun test5(a: Any) {
a as Function1<Int, Unit> /*~> Unit */
{ // BLOCK
val tmp0_array: A = A
val tmp2_sam: IFoo = a /*as Function1<@ParameterName(name = "i") Int, Unit> */ /*-> IFoo */
val tmp2_sam: IFoo = a /*as Function1<Int, Unit> */ /*-> IFoo */
tmp0_array.set(i = tmp2_sam, newValue = tmp0_array.get(i = tmp2_sam).plus(other = 1))
}
}
@@ -199,7 +199,7 @@ FILE fqName:<root> fileName:/caoWithAdaptationForSam.kt
GET_OBJECT 'CLASS OBJECT name:A modality:FINAL visibility:public superTypes:[kotlin.Any]' type=<root>.A
VAR IR_TEMPORARY_VARIABLE name:tmp_9 type:<root>.IFoo [val]
TYPE_OP type=<root>.IFoo origin=SAM_CONVERSION typeOperand=<root>.IFoo
TYPE_OP type=kotlin.Function1<@[ParameterName(name = 'i')] kotlin.Int, kotlin.Unit> origin=IMPLICIT_CAST typeOperand=kotlin.Function1<@[ParameterName(name = 'i')] kotlin.Int, kotlin.Unit>
TYPE_OP type=kotlin.Function1<kotlin.Int, kotlin.Unit> origin=IMPLICIT_CAST typeOperand=kotlin.Function1<kotlin.Int, kotlin.Unit>
GET_VAR 'a: kotlin.Any declared in <root>.test5' type=kotlin.Any origin=null
CALL 'public final fun set (i: <root>.IFoo, newValue: kotlin.Int): kotlin.Unit [operator] declared in <root>' type=kotlin.Unit origin=PLUSEQ
$receiver: GET_VAR 'val tmp_8: <root>.A [val] declared in <root>.test5' type=<root>.A origin=null