IR:
- Redo smart casts handling (yet again). Front-end typing information can't be used for expressions in IR, since it provides inferred type for PSI expressions for the last corresponding resoled call. - Assignments handling, initial implementation.
This commit is contained in:
committed by
Dmitry Petrov
parent
c4bbcadb34
commit
ecf6ab9e25
+12
@@ -0,0 +1,12 @@
|
||||
// <<< assignments.txt
|
||||
class Ref(var x: Int)
|
||||
|
||||
fun test1() {
|
||||
var x = 0
|
||||
x = 1
|
||||
x = x + 1
|
||||
}
|
||||
|
||||
fun test2(r: Ref) {
|
||||
r.x = 0
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
IrFile /assignments.kt
|
||||
DUMMY Ref
|
||||
IrFunction public fun test1(): kotlin.Unit
|
||||
IrExpressionBody
|
||||
BLOCK type=<no-type> hasResult=false isDesugared=false
|
||||
VAR var x: kotlin.Int
|
||||
LITERAL Int type=kotlin.Int value='0'
|
||||
SET_VAR x type=<no-type>
|
||||
LITERAL Int type=kotlin.Int value='1'
|
||||
SET_VAR x type=<no-type>
|
||||
DUMMY PLUS type=kotlin.Int
|
||||
IrFunction public fun test2(/*0*/ r: Ref): kotlin.Unit
|
||||
IrExpressionBody
|
||||
BLOCK type=<no-type> hasResult=false isDesugared=false
|
||||
SET_PROPERTY .xtype=<no-type>
|
||||
$this: GET_VAR r type=Ref
|
||||
$value: LITERAL Int type=kotlin.Int value='0'
|
||||
@@ -1,7 +1,7 @@
|
||||
IrFile /callWithReorderedArguments.kt
|
||||
IrFunction public fun foo(/*0*/ a: kotlin.Int, /*1*/ b: kotlin.Int): kotlin.Unit
|
||||
IrExpressionBody
|
||||
BLOCK type=kotlin.Unit hasResult=false isDesugared=false
|
||||
BLOCK type=<no-type> hasResult=false isDesugared=false
|
||||
IrFunction public fun noReorder1(): kotlin.Int
|
||||
IrExpressionBody
|
||||
BLOCK type=<no-type> hasResult=false isDesugared=true
|
||||
@@ -24,7 +24,7 @@ IrFile /callWithReorderedArguments.kt
|
||||
LITERAL Int type=kotlin.Int value='2'
|
||||
IrFunction public fun test(): kotlin.Unit
|
||||
IrExpressionBody
|
||||
BLOCK type=kotlin.Unit hasResult=false isDesugared=false
|
||||
BLOCK type=<no-type> hasResult=false isDesugared=false
|
||||
CALL .foo type=kotlin.Unit operator=
|
||||
a: CALL .noReorder1 type=kotlin.Int operator=
|
||||
b: CALL .noReorder2 type=kotlin.Int operator=
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
IrFunction public fun B.test(): kotlin.Unit
|
||||
IrExpressionBody
|
||||
BLOCK type=kotlin.Unit hasResult=false isDesugared=false
|
||||
BLOCK type=<no-type> hasResult=false isDesugared=false
|
||||
VAR val tmp0: A
|
||||
GET_VAR A type=A
|
||||
VAR val x: kotlin.Int
|
||||
|
||||
+2
-1
@@ -10,4 +10,5 @@ IrFile /dotQualified.kt
|
||||
BLOCK type=<no-type> hasResult=false isDesugared=true
|
||||
RETURN type=<no-type>
|
||||
GET_PROPERTY ?.length type=kotlin.Int?
|
||||
$this: GET_VAR s type=kotlin.String?
|
||||
$this: TYPE_OP operator=SMART_AS typeOperand=kotlin.String
|
||||
GET_VAR s type=kotlin.String?
|
||||
|
||||
+2
-2
@@ -23,10 +23,10 @@ IrFile /references.kt
|
||||
GET_VAR x type=kotlin.String
|
||||
IrFunction public fun test3(): kotlin.String
|
||||
IrExpressionBody
|
||||
BLOCK type=kotlin.Nothing hasResult=false isDesugared=false
|
||||
BLOCK type=<no-type> hasResult=false isDesugared=false
|
||||
VAR val x: kotlin.String = "OK"
|
||||
LITERAL String type=kotlin.String value='OK'
|
||||
RETURN type=kotlin.Nothing
|
||||
RETURN type=<no-type>
|
||||
GET_VAR x type=kotlin.String
|
||||
IrFunction public fun test4(): kotlin.String
|
||||
IrExpressionBody
|
||||
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
// <<< smartCasts.txt
|
||||
fun expectsString(s: String) {}
|
||||
fun expectsInt(i: Int) {}
|
||||
|
||||
fun overloaded(s: String) = s
|
||||
fun overloaded(x: Any) = x
|
||||
|
||||
fun test1(x: Any) {
|
||||
if (x !is String) return
|
||||
println(x.length)
|
||||
expectsString(x)
|
||||
expectsInt(x.length)
|
||||
expectsString(overloaded(x))
|
||||
}
|
||||
|
||||
fun test2(x: Any): String {
|
||||
if (x !is String) return ""
|
||||
return overloaded(x)
|
||||
}
|
||||
|
||||
fun test3(x: Any): String {
|
||||
if (x !is String) return ""
|
||||
return x
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
IrFile /smartCasts.kt
|
||||
IrFunction public fun expectsString(/*0*/ s: kotlin.String): kotlin.Unit
|
||||
IrExpressionBody
|
||||
BLOCK type=<no-type> hasResult=false isDesugared=false
|
||||
IrFunction public fun expectsInt(/*0*/ i: kotlin.Int): kotlin.Unit
|
||||
IrExpressionBody
|
||||
BLOCK type=<no-type> hasResult=false isDesugared=false
|
||||
IrFunction public fun overloaded(/*0*/ s: kotlin.String): kotlin.String
|
||||
IrExpressionBody
|
||||
BLOCK type=<no-type> hasResult=false isDesugared=true
|
||||
RETURN type=<no-type>
|
||||
GET_VAR s type=kotlin.String
|
||||
IrFunction public fun overloaded(/*0*/ x: kotlin.Any): kotlin.Any
|
||||
IrExpressionBody
|
||||
BLOCK type=<no-type> hasResult=false isDesugared=true
|
||||
RETURN type=<no-type>
|
||||
GET_VAR x type=kotlin.Any
|
||||
IrFunction public fun test1(/*0*/ x: kotlin.Any): kotlin.Unit
|
||||
IrExpressionBody
|
||||
BLOCK type=<no-type> hasResult=false isDesugared=false
|
||||
DUMMY KtIfExpression type=kotlin.Unit
|
||||
CALL .println type=kotlin.Unit operator=
|
||||
message: GET_PROPERTY .length type=kotlin.Int
|
||||
$this: TYPE_OP operator=SMART_AS typeOperand=kotlin.String
|
||||
GET_VAR x type=kotlin.Any
|
||||
CALL .expectsString type=kotlin.Unit operator=
|
||||
s: TYPE_OP operator=SMART_AS typeOperand=kotlin.String
|
||||
GET_VAR x type=kotlin.Any
|
||||
CALL .expectsInt type=kotlin.Unit operator=
|
||||
i: GET_PROPERTY .length type=kotlin.Int
|
||||
$this: TYPE_OP operator=SMART_AS typeOperand=kotlin.String
|
||||
GET_VAR x type=kotlin.Any
|
||||
CALL .expectsString type=kotlin.Unit operator=
|
||||
s: CALL .overloaded type=kotlin.String operator=
|
||||
s: TYPE_OP operator=SMART_AS typeOperand=kotlin.String
|
||||
GET_VAR x type=kotlin.Any
|
||||
IrFunction public fun test2(/*0*/ x: kotlin.Any): kotlin.String
|
||||
IrExpressionBody
|
||||
BLOCK type=<no-type> hasResult=false isDesugared=false
|
||||
DUMMY KtIfExpression type=kotlin.Unit
|
||||
RETURN type=<no-type>
|
||||
CALL .overloaded type=kotlin.String operator=
|
||||
s: TYPE_OP operator=SMART_AS typeOperand=kotlin.String
|
||||
GET_VAR x type=kotlin.Any
|
||||
IrFunction public fun test3(/*0*/ x: kotlin.Any): kotlin.String
|
||||
IrExpressionBody
|
||||
BLOCK type=<no-type> hasResult=false isDesugared=false
|
||||
DUMMY KtIfExpression type=kotlin.Unit
|
||||
RETURN type=<no-type>
|
||||
TYPE_OP operator=SMART_AS typeOperand=kotlin.String
|
||||
GET_VAR x type=kotlin.Any
|
||||
@@ -0,0 +1,11 @@
|
||||
// <<< smartCastsWithDestructuring.txt
|
||||
interface I1
|
||||
interface I2
|
||||
|
||||
operator fun I1.component1() = 1
|
||||
operator fun I2.component2() = ""
|
||||
|
||||
fun test(x: I1) {
|
||||
if (x !is I2) return
|
||||
val (c1, c2) = x
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
IrFile /smartCastsWithDestructuring.kt
|
||||
DUMMY I1
|
||||
DUMMY I2
|
||||
IrFunction public operator fun I1.component1(): kotlin.Int
|
||||
IrExpressionBody
|
||||
BLOCK type=<no-type> hasResult=false isDesugared=true
|
||||
RETURN type=<no-type>
|
||||
LITERAL Int type=kotlin.Int value='1'
|
||||
IrFunction public operator fun I2.component2(): kotlin.String
|
||||
IrExpressionBody
|
||||
BLOCK type=<no-type> hasResult=false isDesugared=true
|
||||
RETURN type=<no-type>
|
||||
? IrStringConcatenationExpressionImpl type=kotlin.String
|
||||
IrFunction public fun test(/*0*/ x: I1): kotlin.Unit
|
||||
IrExpressionBody
|
||||
BLOCK type=<no-type> hasResult=false isDesugared=false
|
||||
DUMMY KtIfExpression type=kotlin.Unit
|
||||
VAR val tmp0: I1
|
||||
GET_VAR x type=I1
|
||||
VAR val c1: kotlin.Int
|
||||
CALL .component1 type=kotlin.Int operator=COMPONENT_N(index=1)
|
||||
$receiver: GET_VAR tmp0 type=I1
|
||||
VAR val c2: kotlin.String
|
||||
CALL .component2 type=kotlin.String operator=COMPONENT_N(index=2)
|
||||
$receiver: TYPE_OP operator=SMART_AS typeOperand=I2
|
||||
GET_VAR tmp0 type=I1
|
||||
+3
-3
@@ -1,8 +1,8 @@
|
||||
IrFile /smoke.kt
|
||||
IrFunction public fun testFun(): kotlin.String
|
||||
IrExpressionBody
|
||||
BLOCK type=kotlin.Nothing hasResult=false isDesugared=false
|
||||
RETURN type=kotlin.Nothing
|
||||
BLOCK type=<no-type> hasResult=false isDesugared=false
|
||||
RETURN type=<no-type>
|
||||
LITERAL String type=kotlin.String value='OK'
|
||||
IrProperty public val testSimpleVal: kotlin.Int = 1 getter=null setter=null
|
||||
IrExpressionBody
|
||||
@@ -24,4 +24,4 @@ IrFile /smoke.kt
|
||||
LITERAL Int type=kotlin.Int value='42'
|
||||
IrPropertySetter public fun <set-testVarWithAccessors>(/*0*/ v: kotlin.Int): kotlin.Unit property=testVarWithAccessors
|
||||
IrExpressionBody
|
||||
BLOCK type=kotlin.Unit hasResult=false isDesugared=false
|
||||
BLOCK type=<no-type> hasResult=false isDesugared=false
|
||||
|
||||
Reference in New Issue
Block a user