[FIR] Properly support @JvmRecord

^KT-53867 Fixed
This commit is contained in:
Dmitriy Novozhilov
2022-09-19 14:52:39 +03:00
parent c0ad67c4f9
commit 6623456d2a
23 changed files with 490 additions and 29 deletions
@@ -0,0 +1,98 @@
FILE fqName:<root> fileName:/dataClassWithJvmRecord.kt
CLASS CLASS name:MyRec modality:FINAL visibility:public [data] superTypes:[java.lang.Record]
annotations:
JvmRecord
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.MyRec
CONSTRUCTOR visibility:public <> (name:kotlin.String) returnType:<root>.MyRec [primary]
VALUE_PARAMETER name:name index:0 type:kotlin.String
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'protected/*protected and package*/ constructor <init> () declared in java.lang.Record'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:MyRec modality:FINAL visibility:public [data] superTypes:[java.lang.Record]'
PROPERTY name:name visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:name type:kotlin.String visibility:private [final]
EXPRESSION_BODY
GET_VAR 'name: kotlin.String declared in <root>.MyRec.<init>' type=kotlin.String origin=INITIALIZE_PROPERTY_FROM_PARAMETER
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-name> visibility:public modality:FINAL <> ($this:<root>.MyRec) returnType:kotlin.String
correspondingProperty: PROPERTY name:name visibility:public modality:FINAL [val]
$this: VALUE_PARAMETER name:<this> type:<root>.MyRec
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-name> (): kotlin.String declared in <root>.MyRec'
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.<get-name>' type=<root>.MyRec origin=null
FUN name:component1 visibility:public modality:FINAL <> ($this:<root>.MyRec) returnType:kotlin.String [operator]
$this: VALUE_PARAMETER name:<this> type:<root>.MyRec
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun component1 (): kotlin.String [operator] declared in <root>.MyRec'
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.component1' type=<root>.MyRec origin=null
FUN name:copy visibility:public modality:FINAL <> ($this:<root>.MyRec, name:kotlin.String) returnType:<root>.MyRec
$this: VALUE_PARAMETER name:<this> type:<root>.MyRec
VALUE_PARAMETER name:name index:0 type:kotlin.String
EXPRESSION_BODY
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.copy' type=<root>.MyRec origin=null
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun copy (name: kotlin.String): <root>.MyRec declared in <root>.MyRec'
CONSTRUCTOR_CALL 'public constructor <init> (name: kotlin.String) [primary] declared in <root>.MyRec' type=<root>.MyRec origin=null
name: GET_VAR 'name: kotlin.String declared in <root>.MyRec.copy' type=kotlin.String origin=null
FUN GENERATED_DATA_CLASS_MEMBER name:equals visibility:public modality:OPEN <> ($this:<root>.MyRec, other:kotlin.Any?) returnType:kotlin.Boolean
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any
$this: VALUE_PARAMETER GENERATED_DATA_CLASS_MEMBER name:<this> type:<root>.MyRec
VALUE_PARAMETER GENERATED_DATA_CLASS_MEMBER name:other index:0 type:kotlin.Any?
BLOCK_BODY
WHEN type=kotlin.Unit origin=null
BRANCH
if: CALL 'public final fun EQEQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQEQ
arg0: GET_VAR '<this>: <root>.MyRec declared in <root>.MyRec.equals' type=<root>.MyRec origin=null
arg1: GET_VAR 'other: kotlin.Any? declared in <root>.MyRec.equals' type=kotlin.Any? origin=null
then: RETURN type=kotlin.Nothing from='public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in <root>.MyRec'
CONST Boolean type=kotlin.Boolean value=true
WHEN type=kotlin.Unit origin=null
BRANCH
if: TYPE_OP type=kotlin.Boolean origin=NOT_INSTANCEOF typeOperand=<root>.MyRec
GET_VAR 'other: kotlin.Any? declared in <root>.MyRec.equals' type=kotlin.Any? origin=null
then: RETURN type=kotlin.Nothing from='public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in <root>.MyRec'
CONST Boolean type=kotlin.Boolean value=false
VAR IR_TEMPORARY_VARIABLE name:tmp_0 type:<root>.MyRec [val]
TYPE_OP type=<root>.MyRec origin=CAST typeOperand=<root>.MyRec
GET_VAR 'other: kotlin.Any? declared in <root>.MyRec.equals' type=kotlin.Any? origin=null
WHEN type=kotlin.Unit origin=null
BRANCH
if: CALL 'public final fun not (): kotlin.Boolean [operator] declared in kotlin.Boolean' type=kotlin.Boolean origin=EXCLEQ
$this: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EXCLEQ
arg0: 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.equals' type=<root>.MyRec origin=null
arg1: GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:name type:kotlin.String visibility:private [final]' type=kotlin.String origin=null
receiver: GET_VAR 'val tmp_0: <root>.MyRec [val] declared in <root>.MyRec.equals' type=<root>.MyRec origin=null
then: RETURN type=kotlin.Nothing from='public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in <root>.MyRec'
CONST Boolean type=kotlin.Boolean value=false
RETURN type=kotlin.Nothing from='public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in <root>.MyRec'
CONST Boolean type=kotlin.Boolean value=true
FUN GENERATED_DATA_CLASS_MEMBER name:hashCode visibility:public modality:OPEN <> ($this:<root>.MyRec) returnType:kotlin.Int
overridden:
public open fun hashCode (): kotlin.Int declared in kotlin.Any
$this: VALUE_PARAMETER GENERATED_DATA_CLASS_MEMBER name:<this> type:<root>.MyRec
BLOCK_BODY
RETURN type=kotlin.Nothing from='public open fun hashCode (): kotlin.Int declared in <root>.MyRec'
CALL 'public open fun hashCode (): kotlin.Int [fake_override] declared in kotlin.String' type=kotlin.Int origin=null
$this: 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.hashCode' type=<root>.MyRec origin=null
FUN GENERATED_DATA_CLASS_MEMBER name:toString visibility:public modality:OPEN <> ($this:<root>.MyRec) returnType:kotlin.String
overridden:
public open fun toString (): kotlin.String declared in kotlin.Any
$this: VALUE_PARAMETER GENERATED_DATA_CLASS_MEMBER name:<this> type:<root>.MyRec
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("
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=")"
FUN name:test visibility:public modality:FINAL <> (rec:<root>.MyRec) returnType:kotlin.Unit
VALUE_PARAMETER name:rec index:0 type:<root>.MyRec
BLOCK_BODY
TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit
CALL 'public final fun <get-name> (): kotlin.String declared in <root>.MyRec' type=kotlin.String origin=GET_PROPERTY
$this: GET_VAR 'rec: <root>.MyRec declared in <root>.test' type=<root>.MyRec origin=null
@@ -0,0 +1,47 @@
@JvmRecord
data class MyRec : Record {
constructor(name: String) /* primary */ {
super/*Record*/()
/* <init>() */
}
val name: String
field = name
get
operator fun component1(): String {
return <this>.#name
}
fun copy(name: String = <this>.#name): MyRec {
return MyRec(name = name)
}
override fun equals(other: Any?): Boolean {
when {
EQEQEQ(arg0 = <this>, arg1 = other) -> return true
}
when {
other !is MyRec -> return false
}
val tmp0_other_with_cast: MyRec = other as MyRec
when {
EQEQ(arg0 = <this>.#name, arg1 = tmp0_other_with_cast.#name).not() -> return false
}
return true
}
override fun hashCode(): Int {
return <this>.#name.hashCode()
}
override fun toString(): String {
return "MyRec(" + "name=" + <this>.#name + ")"
}
}
fun test(rec: MyRec) {
rec.<get-name>() /*~> Unit */
}
@@ -0,0 +1,98 @@
FILE fqName:<root> fileName:/dataClassWithJvmRecord.kt
CLASS CLASS name:MyRec modality:FINAL visibility:public [data] superTypes:[java.lang.Record]
annotations:
JvmRecord
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.MyRec
CONSTRUCTOR visibility:public <> (name:kotlin.String) returnType:<root>.MyRec [primary]
VALUE_PARAMETER name:name index:0 type:kotlin.String
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'protected/*protected and package*/ constructor <init> () declared in java.lang.Record'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:MyRec modality:FINAL visibility:public [data] superTypes:[java.lang.Record]'
PROPERTY name:name visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:name type:kotlin.String visibility:private [final]
EXPRESSION_BODY
GET_VAR 'name: kotlin.String declared in <root>.MyRec.<init>' type=kotlin.String origin=INITIALIZE_PROPERTY_FROM_PARAMETER
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-name> visibility:public modality:FINAL <> ($this:<root>.MyRec) returnType:kotlin.String
correspondingProperty: PROPERTY name:name visibility:public modality:FINAL [val]
$this: VALUE_PARAMETER name:<this> type:<root>.MyRec
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-name> (): kotlin.String declared in <root>.MyRec'
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.<get-name>' type=<root>.MyRec origin=null
FUN GENERATED_DATA_CLASS_MEMBER name:component1 visibility:public modality:FINAL <> ($this:<root>.MyRec) returnType:kotlin.String [operator]
$this: VALUE_PARAMETER name:<this> type:<root>.MyRec
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun component1 (): kotlin.String [operator] declared in <root>.MyRec'
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.component1' type=<root>.MyRec origin=null
FUN GENERATED_DATA_CLASS_MEMBER name:copy visibility:public modality:FINAL <> ($this:<root>.MyRec, name:kotlin.String) returnType:<root>.MyRec
$this: VALUE_PARAMETER name:<this> type:<root>.MyRec
VALUE_PARAMETER name:name index:0 type:kotlin.String
EXPRESSION_BODY
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.copy' type=<root>.MyRec origin=null
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun copy (name: kotlin.String): <root>.MyRec declared in <root>.MyRec'
CONSTRUCTOR_CALL 'public constructor <init> (name: kotlin.String) [primary] declared in <root>.MyRec' type=<root>.MyRec origin=null
name: GET_VAR 'name: kotlin.String declared in <root>.MyRec.copy' type=kotlin.String origin=null
FUN GENERATED_DATA_CLASS_MEMBER name:toString visibility:public modality:OPEN <> ($this:<root>.MyRec) returnType:kotlin.String
overridden:
public abstract fun toString (): @[EnhancedNullability] kotlin.String declared in java.lang.Record
$this: VALUE_PARAMETER name:<this> type:<root>.MyRec
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("
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=")"
FUN GENERATED_DATA_CLASS_MEMBER name:hashCode visibility:public modality:OPEN <> ($this:<root>.MyRec) returnType:kotlin.Int
overridden:
public abstract fun hashCode (): kotlin.Int declared in java.lang.Record
$this: VALUE_PARAMETER name:<this> type:<root>.MyRec
BLOCK_BODY
RETURN type=kotlin.Nothing from='public open fun hashCode (): kotlin.Int declared in <root>.MyRec'
CALL 'public open fun hashCode (): kotlin.Int [fake_override] declared in kotlin.String' type=kotlin.Int origin=null
$this: 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.hashCode' type=<root>.MyRec origin=null
FUN GENERATED_DATA_CLASS_MEMBER name:equals visibility:public modality:OPEN <> ($this:<root>.MyRec, other:kotlin.Any?) returnType:kotlin.Boolean [operator]
overridden:
public abstract fun equals (other: @[EnhancedNullability] kotlin.Any?): kotlin.Boolean [operator] declared in java.lang.Record
$this: VALUE_PARAMETER name:<this> type:<root>.MyRec
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
BLOCK_BODY
WHEN type=kotlin.Unit origin=null
BRANCH
if: CALL 'public final fun EQEQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQEQ
arg0: GET_VAR '<this>: <root>.MyRec declared in <root>.MyRec.equals' type=<root>.MyRec origin=null
arg1: GET_VAR 'other: kotlin.Any? declared in <root>.MyRec.equals' type=kotlin.Any? origin=null
then: RETURN type=kotlin.Nothing from='public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in <root>.MyRec'
CONST Boolean type=kotlin.Boolean value=true
WHEN type=kotlin.Unit origin=null
BRANCH
if: TYPE_OP type=kotlin.Boolean origin=NOT_INSTANCEOF typeOperand=<root>.MyRec
GET_VAR 'other: kotlin.Any? declared in <root>.MyRec.equals' type=kotlin.Any? origin=null
then: RETURN type=kotlin.Nothing from='public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in <root>.MyRec'
CONST Boolean type=kotlin.Boolean value=false
VAR IR_TEMPORARY_VARIABLE name:tmp_0 type:<root>.MyRec [val]
TYPE_OP type=<root>.MyRec origin=CAST typeOperand=<root>.MyRec
GET_VAR 'other: kotlin.Any? declared in <root>.MyRec.equals' type=kotlin.Any? origin=null
WHEN type=kotlin.Unit origin=null
BRANCH
if: CALL 'public final fun not (): kotlin.Boolean [operator] declared in kotlin.Boolean' type=kotlin.Boolean origin=EXCLEQ
$this: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EXCLEQ
arg0: 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.equals' type=<root>.MyRec origin=null
arg1: GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:name type:kotlin.String visibility:private [final]' type=kotlin.String origin=null
receiver: GET_VAR 'val tmp_0: <root>.MyRec [val] declared in <root>.MyRec.equals' type=<root>.MyRec origin=null
then: RETURN type=kotlin.Nothing from='public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in <root>.MyRec'
CONST Boolean type=kotlin.Boolean value=false
RETURN type=kotlin.Nothing from='public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in <root>.MyRec'
CONST Boolean type=kotlin.Boolean value=true
FUN name:test visibility:public modality:FINAL <> (rec:<root>.MyRec) returnType:kotlin.Unit
VALUE_PARAMETER name:rec index:0 type:<root>.MyRec
BLOCK_BODY
TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit
CALL 'public final fun <get-name> (): kotlin.String declared in <root>.MyRec' type=kotlin.String origin=GET_PROPERTY
$this: GET_VAR 'rec: <root>.MyRec declared in <root>.test' type=<root>.MyRec origin=null
@@ -0,0 +1,11 @@
// TARGET_BACKEND: JVM_IR
// JDK_KIND: FULL_JDK_17
// WITH_STDLIB
// JVM_TARGET: 17
@JvmRecord
data class MyRec(val name: String)
fun test(rec: MyRec) {
rec.name
}
@@ -0,0 +1,47 @@
@JvmRecord
data class MyRec : Record {
constructor(name: String) /* primary */ {
super/*Record*/()
/* <init>() */
}
val name: String
field = name
get
operator fun component1(): String {
return <this>.#name
}
fun copy(name: String = <this>.#name): MyRec {
return MyRec(name = name)
}
override fun toString(): String {
return "MyRec(" + "name=" + <this>.#name + ")"
}
override fun hashCode(): Int {
return <this>.#name.hashCode()
}
override operator fun equals(other: Any?): Boolean {
when {
EQEQEQ(arg0 = <this>, arg1 = other) -> return true
}
when {
other !is MyRec -> return false
}
val tmp0_other_with_cast: MyRec = other as MyRec
when {
EQEQ(arg0 = <this>.#name, arg1 = tmp0_other_with_cast.#name).not() -> return false
}
return true
}
}
fun test(rec: MyRec) {
rec.<get-name>() /*~> Unit */
}