[IR] Split const folding into necessary one and for optimizations only

In this commit we have a lot of change in test data. This was caused
by the way where we evaluate constants. We split constant evaluation
into two distinct parts: only necessary evaluations for `fir2ir`
(like const val and annotations) and optimizations for lowering.
Now we don't do all constant evaluation on `fir2ir`, but IR
dump is executed after this phase, so test data changed.

#KT-58923
This commit is contained in:
Ivan Kylchik
2023-05-28 18:43:30 +02:00
committed by Space Team
parent 8067df3c94
commit dd264cff50
96 changed files with 648 additions and 327 deletions
@@ -91,7 +91,8 @@ FILE fqName:<root> fileName:/arrayAccessCompositeOperators.kt
BLOCK_BODY
RETURN type=kotlin.Nothing from='public open fun toString (): kotlin.String declared in <root>.MyContainer'
STRING_CONCATENATION type=kotlin.String
CONST String type=kotlin.String value="MyContainer(i="
CONST String type=kotlin.String value="MyContainer("
CONST String type=kotlin.String value="i="
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:i type:kotlin.Int visibility:private' type=kotlin.Int origin=null
receiver: GET_VAR '<this>: <root>.MyContainer declared in <root>.MyContainer.toString' type=<root>.MyContainer origin=null
CONST String type=kotlin.String value=")"
@@ -37,7 +37,7 @@ data class MyContainer {
}
override fun toString(): String {
return "MyContainer(i=" + <this>.#i + ")"
return "MyContainer(" + "i=" + <this>.#i + ")"
}
}
@@ -91,7 +91,8 @@ FILE fqName:<root> fileName:/arrayAccessOperators.kt
BLOCK_BODY
RETURN type=kotlin.Nothing from='public open fun toString (): kotlin.String declared in <root>.MyContainer'
STRING_CONCATENATION type=kotlin.String
CONST String type=kotlin.String value="MyContainer(s="
CONST String type=kotlin.String value="MyContainer("
CONST String type=kotlin.String value="s="
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:s type:kotlin.String visibility:private' type=kotlin.String origin=null
receiver: GET_VAR '<this>: <root>.MyContainer declared in <root>.MyContainer.toString' type=<root>.MyContainer origin=null
CONST String type=kotlin.String value=")"
@@ -37,7 +37,7 @@ data class MyContainer {
}
override fun toString(): String {
return "MyContainer(s=" + <this>.#s + ")"
return "MyContainer(" + "s=" + <this>.#s + ")"
}
}
@@ -91,7 +91,8 @@ FILE fqName:<root> fileName:/compoundAssignmentOperators.kt
BLOCK_BODY
RETURN type=kotlin.Nothing from='public open fun toString (): kotlin.String declared in <root>.Result'
STRING_CONCATENATION type=kotlin.String
CONST String type=kotlin.String value="Result(i="
CONST String type=kotlin.String value="Result("
CONST String type=kotlin.String value="i="
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:i type:kotlin.Int visibility:private' type=kotlin.Int origin=null
receiver: GET_VAR '<this>: <root>.Result declared in <root>.Result.toString' type=<root>.Result origin=null
CONST String type=kotlin.String value=")"
@@ -37,7 +37,7 @@ data class Result {
}
override fun toString(): String {
return "Result(i=" + <this>.#i + ")"
return "Result(" + "i=" + <this>.#i + ")"
}
}
@@ -148,10 +148,12 @@ FILE fqName:<root> fileName:/compareTo.kt
BLOCK_BODY
RETURN type=kotlin.Nothing from='public open fun toString (): kotlin.String declared in <root>.Pair'
STRING_CONCATENATION type=kotlin.String
CONST String type=kotlin.String value="Pair(first="
CONST String type=kotlin.String value="Pair("
CONST String type=kotlin.String value="first="
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:first type:A of <root>.Pair visibility:private [final]' type=A of <root>.Pair origin=null
receiver: GET_VAR '<this>: <root>.Pair<A of <root>.Pair, B of <root>.Pair> declared in <root>.Pair.toString' type=<root>.Pair<A of <root>.Pair, B of <root>.Pair> origin=null
CONST String type=kotlin.String value=", second="
CONST String type=kotlin.String value=", "
CONST String type=kotlin.String value="second="
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:second type:B of <root>.Pair visibility:private [final]' type=B of <root>.Pair origin=null
receiver: GET_VAR '<this>: <root>.Pair<A of <root>.Pair, B of <root>.Pair> declared in <root>.Pair.toString' type=<root>.Pair<A of <root>.Pair, B of <root>.Pair> origin=null
CONST String type=kotlin.String value=")"
@@ -55,7 +55,7 @@ data class Pair<A : Any?, B : Any?> {
}
override fun toString(): String {
return "Pair(first=" + <this>.#first + ", second=" + <this>.#second + ")"
return "Pair(" + "first=" + <this>.#first + ", " + "second=" + <this>.#second + ")"
}
}
@@ -93,7 +93,8 @@ FILE fqName:<root> fileName:/iteratorOperator.kt
BLOCK_BODY
RETURN type=kotlin.Nothing from='public open fun toString (): kotlin.String declared in <root>.Counter'
STRING_CONCATENATION type=kotlin.String
CONST String type=kotlin.String value="Counter(i="
CONST String type=kotlin.String value="Counter("
CONST String type=kotlin.String value="i="
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:i type:kotlin.Int visibility:private' type=kotlin.Int origin=null
receiver: GET_VAR '<this>: <root>.Counter declared in <root>.Counter.toString' type=<root>.Counter origin=null
CONST String type=kotlin.String value=")"
@@ -183,7 +184,8 @@ FILE fqName:<root> fileName:/iteratorOperator.kt
BLOCK_BODY
RETURN type=kotlin.Nothing from='public open fun toString (): kotlin.String declared in <root>.CounterConfig'
STRING_CONCATENATION type=kotlin.String
CONST String type=kotlin.String value="CounterConfig(max="
CONST String type=kotlin.String value="CounterConfig("
CONST String type=kotlin.String value="max="
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:max type:kotlin.Int visibility:private [final]' type=kotlin.Int origin=null
receiver: GET_VAR '<this>: <root>.CounterConfig declared in <root>.CounterConfig.toString' type=<root>.CounterConfig origin=null
CONST String type=kotlin.String value=")"
@@ -37,7 +37,7 @@ data class Counter {
}
override fun toString(): String {
return "Counter(i=" + <this>.#i + ")"
return "Counter(" + "i=" + <this>.#i + ")"
}
}
@@ -80,7 +80,7 @@ data class CounterConfig {
}
override fun toString(): String {
return "CounterConfig(max=" + <this>.#max + ")"
return "CounterConfig(" + "max=" + <this>.#max + ")"
}
}
@@ -83,7 +83,8 @@ FILE fqName:<root> fileName:/unaryOperators.kt
BLOCK_BODY
RETURN type=kotlin.Nothing from='public open fun toString (): kotlin.String declared in <root>.Result'
STRING_CONCATENATION type=kotlin.String
CONST String type=kotlin.String value="Result(i="
CONST String type=kotlin.String value="Result("
CONST String type=kotlin.String value="i="
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:i type:kotlin.Int visibility:private [final]' type=kotlin.Int origin=null
receiver: GET_VAR '<this>: <root>.Result declared in <root>.Result.toString' type=<root>.Result origin=null
CONST String type=kotlin.String value=")"
@@ -36,7 +36,7 @@ data class Result {
}
override fun toString(): String {
return "Result(i=" + <this>.#i + ")"
return "Result(" + "i=" + <this>.#i + ")"
}
}
@@ -60,7 +60,8 @@ FILE fqName:<root> fileName:/inlineCollectionOfInlineClass.kt
BLOCK_BODY
RETURN type=kotlin.Nothing from='public open fun toString (): kotlin.String declared in <root>.IT'
STRING_CONCATENATION type=kotlin.String
CONST String type=kotlin.String value="IT(x="
CONST String type=kotlin.String value="IT("
CONST String type=kotlin.String value="x="
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:x type:kotlin.Int visibility:private [final]' type=kotlin.Int origin=null
receiver: GET_VAR '<this>: <root>.IT declared in <root>.IT.toString' type=<root>.IT origin=null
CONST String type=kotlin.String value=")"
@@ -241,7 +242,8 @@ FILE fqName:<root> fileName:/inlineCollectionOfInlineClass.kt
BLOCK_BODY
RETURN type=kotlin.Nothing from='public open fun toString (): kotlin.String declared in <root>.InlineMutableSet'
STRING_CONCATENATION type=kotlin.String
CONST String type=kotlin.String value="InlineMutableSet(ms="
CONST String type=kotlin.String value="InlineMutableSet("
CONST String type=kotlin.String value="ms="
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:ms type:kotlin.collections.MutableSet<<root>.IT> visibility:private [final]' type=kotlin.collections.MutableSet<<root>.IT> origin=null
receiver: GET_VAR '<this>: <root>.InlineMutableSet declared in <root>.InlineMutableSet.toString' type=<root>.InlineMutableSet origin=null
CONST String type=kotlin.String value=")"
@@ -25,7 +25,7 @@ value class IT {
}
override fun toString(): String {
return "IT(x=" + <this>.#x + ")"
return "IT(" + "x=" + <this>.#x + ")"
}
}
@@ -102,7 +102,7 @@ value class InlineMutableSet : MutableSet<IT> {
}
override fun toString(): String {
return "InlineMutableSet(ms=" + <this>.#ms + ")"
return "InlineMutableSet(" + "ms=" + <this>.#ms + ")"
}
}
@@ -85,7 +85,8 @@ FILE fqName:<root> fileName:/dataClassWithJvmRecord.kt
BLOCK_BODY
RETURN type=kotlin.Nothing from='public open fun toString (): kotlin.String declared in <root>.MyRec'
STRING_CONCATENATION type=kotlin.String
CONST String type=kotlin.String value="MyRec(name="
CONST String type=kotlin.String value="MyRec("
CONST String type=kotlin.String value="name="
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:name type:kotlin.String visibility:private [final]' type=kotlin.String origin=null
receiver: GET_VAR '<this>: <root>.MyRec declared in <root>.MyRec.toString' type=<root>.MyRec origin=null
CONST String type=kotlin.String value=")"
@@ -37,7 +37,7 @@ data class MyRec : Record {
}
override fun toString(): String {
return "MyRec(name=" + <this>.#name + ")"
return "MyRec(" + "name=" + <this>.#name + ")"
}
}
@@ -0,0 +1,42 @@
FILE fqName:interop fileName:/Definitions.kt
CLASS OBJECT name:Definitions modality:FINAL visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:interop.Definitions
CONSTRUCTOR visibility:private <> () returnType:interop.Definitions [primary]
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS OBJECT name:Definitions modality:FINAL visibility:public superTypes:[kotlin.Any]'
PROPERTY name:KT_CONSTANT visibility:public modality:FINAL [const,val]
FIELD PROPERTY_BACKING_FIELD name:KT_CONSTANT type:kotlin.String visibility:public [final]
EXPRESSION_BODY
CONST String type=kotlin.String value="constant"
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-KT_CONSTANT> visibility:public modality:FINAL <> ($this:interop.Definitions) returnType:kotlin.String
correspondingProperty: PROPERTY name:KT_CONSTANT visibility:public modality:FINAL [const,val]
$this: VALUE_PARAMETER name:<this> type:interop.Definitions
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-KT_CONSTANT> (): kotlin.String declared in interop.Definitions'
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:KT_CONSTANT type:kotlin.String visibility:public [final]' type=kotlin.String origin=null
receiver: GET_VAR '<this>: interop.Definitions declared in interop.Definitions.<get-KT_CONSTANT>' type=interop.Definitions origin=null
PROPERTY name:ktValue visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:ktValue type:kotlin.String visibility:private [final]
EXPRESSION_BODY
GET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:CONSTANT type:kotlin.String visibility:public [final,static]' type=kotlin.String origin=GET_PROPERTY
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-ktValue> visibility:public modality:FINAL <> ($this:interop.Definitions) returnType:kotlin.String
correspondingProperty: PROPERTY name:ktValue visibility:public modality:FINAL [val]
$this: VALUE_PARAMETER name:<this> type:interop.Definitions
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-ktValue> (): kotlin.String declared in interop.Definitions'
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:ktValue type:kotlin.String visibility:private [final]' type=kotlin.String origin=null
receiver: GET_VAR '<this>: interop.Definitions declared in interop.Definitions.<get-ktValue>' type=interop.Definitions origin=null
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
overridden:
public open fun hashCode (): kotlin.Int declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
overridden:
public open fun toString (): kotlin.String declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
@@ -0,0 +1,19 @@
package interop
object Definitions {
private constructor() /* primary */ {
super/*Any*/()
/* <init>() */
}
const val KT_CONSTANT: String
field = "constant"
get
val ktValue: String
field = #CONSTANT
get
}
-1
View File
@@ -1,4 +1,3 @@
// FIR_IDENTICAL
// TARGET_BACKEND: JVM
// FILE: Definitions.kt
// IR_FILE: kt29833.txt
@@ -16,3 +16,4 @@ object Definitions {
get
}
@@ -117,7 +117,8 @@ FILE fqName:<root> fileName:/kt52677.kt
BLOCK_BODY
RETURN type=kotlin.Nothing from='public open fun toString (): kotlin.String declared in <root>.LoginSuccessPacket'
STRING_CONCATENATION type=kotlin.String
CONST String type=kotlin.String value="LoginSuccessPacket(id="
CONST String type=kotlin.String value="LoginSuccessPacket("
CONST String type=kotlin.String value="id="
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:id type:@[MySerializable(c = ...)] <root>.Uuid1 visibility:private [final]' type=@[MySerializable(c = CLASS_REFERENCE 'CLASS OBJECT name:UuidSerializer modality:FINAL visibility:public superTypes:[<root>.MySerializer<@[MySerializable(c = ...)] <root>.Uuid1>]' type=kotlin.reflect.KClass<<root>.UuidSerializer>)] <root>.Uuid1 origin=null
receiver: GET_VAR '<this>: <root>.LoginSuccessPacket declared in <root>.LoginSuccessPacket.toString' type=<root>.LoginSuccessPacket origin=null
CONST String type=kotlin.String value=")"
@@ -51,7 +51,7 @@ data class LoginSuccessPacket {
}
override fun toString(): String {
return "LoginSuccessPacket(id=" + <this>.#id + ")"
return "LoginSuccessPacket(" + "id=" + <this>.#id + ")"
}
}
@@ -139,10 +139,12 @@ FILE fqName:<root> fileName:/dataClassMembers.kt
BLOCK_BODY
RETURN type=kotlin.Nothing from='public open fun toString (): kotlin.String declared in <root>.Test'
STRING_CONCATENATION type=kotlin.String
CONST String type=kotlin.String value="Test(x="
CONST String type=kotlin.String value="Test("
CONST String type=kotlin.String value="x="
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:x type:T of <root>.Test visibility:private [final]' type=T of <root>.Test origin=null
receiver: GET_VAR '<this>: <root>.Test<T of <root>.Test> declared in <root>.Test.toString' type=<root>.Test<T of <root>.Test> origin=null
CONST String type=kotlin.String value=", y="
CONST String type=kotlin.String value=", "
CONST String type=kotlin.String value="y="
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:y type:kotlin.String visibility:private [final]' type=kotlin.String origin=null
receiver: GET_VAR '<this>: <root>.Test<T of <root>.Test> declared in <root>.Test.toString' type=<root>.Test<T of <root>.Test> origin=null
CONST String type=kotlin.String value=")"
@@ -52,7 +52,7 @@ data class Test<T : Any?> {
}
override fun toString(): String {
return "Test(x=" + <this>.#x + ", y=" + <this>.#y + ")"
return "Test(" + "x=" + <this>.#x + ", " + "y=" + <this>.#y + ")"
}
}