Psi2Ir: Fold constants when generating IR

This is necessary to avoid stack overflow errors on large constant
expressions.
This commit is contained in:
Steven Schäfer
2021-04-20 21:23:19 +02:00
committed by Dmitry Petrov
parent e87d816994
commit 8c9ad81c76
15 changed files with 69 additions and 31 deletions
@@ -0,0 +1,4 @@
val test: Int
field = Companion.<get-MIN_VALUE>()
get
@@ -0,0 +1,11 @@
FILE fqName:<root> fileName:/constFromBuiltins.kt
PROPERTY name:test visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:test type:kotlin.Int visibility:private [final,static]
EXPRESSION_BODY
CALL 'public final fun <get-MIN_VALUE> (): kotlin.Int declared in kotlin.Int.Companion' type=kotlin.Int origin=GET_PROPERTY
$this: GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Companion modality:FINAL visibility:public [companion] superTypes:[kotlin.Any]' type=kotlin.Int.Companion
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-test> visibility:public modality:FINAL <> () returnType:kotlin.Int
correspondingProperty: PROPERTY name:test visibility:public modality:FINAL [val]
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-test> (): kotlin.Int declared in <root>'
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:test type:kotlin.Int visibility:private [final,static]' type=kotlin.Int origin=null
@@ -1,4 +1,3 @@
// FIR_IDENTICAL
// DUMP_EXTERNAL_CLASS: kotlin.Int
val test = Int.MIN_VALUE
+1 -1
View File
@@ -1,4 +1,4 @@
val test: Int
field = Companion.<get-MIN_VALUE>()
field = -2147483648
get
+1 -2
View File
@@ -2,8 +2,7 @@ FILE fqName:<root> fileName:/constFromBuiltins.kt
PROPERTY name:test visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:test type:kotlin.Int visibility:private [final,static]
EXPRESSION_BODY
CALL 'public final fun <get-MIN_VALUE> (): kotlin.Int declared in kotlin.Int.Companion' type=kotlin.Int origin=GET_PROPERTY
$this: GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Companion modality:FINAL visibility:public [companion] superTypes:[kotlin.Any]' type=kotlin.Int.Companion
CONST Int type=kotlin.Int value=-2147483648
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-test> visibility:public modality:FINAL <> () returnType:kotlin.Int
correspondingProperty: PROPERTY name:test visibility:public modality:FINAL [val]
BLOCK_BODY
+4
View File
@@ -0,0 +1,4 @@
val test: Int
field = 2.plus(other = 2)
get
+12
View File
@@ -0,0 +1,12 @@
FILE fqName:<root> fileName:/simple.kt
PROPERTY name:test visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:test type:kotlin.Int visibility:private [final,static]
EXPRESSION_BODY
CALL 'public final fun plus (other: kotlin.Int): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=PLUS
$this: CONST Int type=kotlin.Int value=2
other: CONST Int type=kotlin.Int value=2
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-test> visibility:public modality:FINAL <> () returnType:kotlin.Int
correspondingProperty: PROPERTY name:test visibility:public modality:FINAL [val]
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-test> (): kotlin.Int declared in <root>'
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:test type:kotlin.Int visibility:private [final,static]' type=kotlin.Int origin=null
-1
View File
@@ -1,4 +1,3 @@
// FIR_IDENTICAL
// !DUMP_DEPENDENCIES
val test = 2 + 2
+1 -1
View File
@@ -1,4 +1,4 @@
val test: Int
field = 2.plus(other = 2)
field = 4
get
+1 -3
View File
@@ -2,9 +2,7 @@ FILE fqName:<root> fileName:/simple.kt
PROPERTY name:test visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:test type:kotlin.Int visibility:private [final,static]
EXPRESSION_BODY
CALL 'public final fun plus (other: kotlin.Int): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=PLUS
$this: CONST Int type=kotlin.Int value=2
other: CONST Int type=kotlin.Int value=2
CONST Int type=kotlin.Int value=4
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-test> visibility:public modality:FINAL <> () returnType:kotlin.Int
correspondingProperty: PROPERTY name:test visibility:public modality:FINAL [val]
BLOCK_BODY