Disable data class copy function body in raw FIR

After this commit we require 'copy' body generation in FIR2IR converter
This commit is contained in:
Simon Ogorodnik
2019-05-20 19:56:36 +03:00
committed by Mikhail Glukhikh
parent a849cc7da4
commit d3f00280e9
13 changed files with 31 additions and 100 deletions
@@ -14,10 +14,7 @@ import org.jetbrains.kotlin.fir.declarations.FirProperty
import org.jetbrains.kotlin.fir.declarations.impl.FirClassImpl
import org.jetbrains.kotlin.fir.declarations.impl.FirMemberFunctionImpl
import org.jetbrains.kotlin.fir.declarations.impl.FirValueParameterImpl
import org.jetbrains.kotlin.fir.expressions.impl.FirFunctionCallImpl
import org.jetbrains.kotlin.fir.expressions.impl.FirQualifiedAccessExpressionImpl
import org.jetbrains.kotlin.fir.expressions.impl.FirReturnExpressionImpl
import org.jetbrains.kotlin.fir.expressions.impl.FirSingleExpressionBlock
import org.jetbrains.kotlin.fir.expressions.impl.*
import org.jetbrains.kotlin.fir.references.FirResolvedCallableReferenceImpl
import org.jetbrains.kotlin.fir.symbols.CallableId
import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
@@ -89,7 +86,7 @@ internal fun KtClassOrObject.generateCopyFunction(
isInfix = false, isInline = false,
isTailRec = false, isExternal = false,
isSuspend = false, receiverTypeRef = null,
returnTypeRef = FirImplicitTypeRefImpl(session, this)
returnTypeRef = firPrimaryConstructor.returnTypeRef//FirImplicitTypeRefImpl(session, this)
).apply {
val copyFunction = this
val zippedParameters =
@@ -105,29 +102,31 @@ internal fun KtClassOrObject.generateCopyFunction(
isCrossinline = false, isNoinline = false, isVararg = false
)
}
body = FirSingleExpressionBlock(
session,
FirReturnExpressionImpl(
session, this@generateCopyFunction,
FirFunctionCallImpl(session, this@generateCopyFunction).apply {
calleeReference = FirResolvedCallableReferenceImpl(
session, this@generateCopyFunction, firClass.name,
firPrimaryConstructor.symbol
)
}.apply {
for ((ktParameter, firParameter) in primaryConstructorParameters.zip(valueParameters)) {
this.arguments += FirQualifiedAccessExpressionImpl(session, ktParameter).apply {
calleeReference = FirResolvedCallableReferenceImpl(
session, ktParameter, firParameter.name, firParameter.symbol
)
}
}
}
).apply {
target = FirFunctionTarget(null)
target.bind(copyFunction)
}
)
body = FirEmptyExpressionBlock(session)
// body = FirSingleExpressionBlock(
// session,
// FirReturnExpressionImpl(
// session, this@generateCopyFunction,
// FirFunctionCallImpl(session, this@generateCopyFunction).apply {
// calleeReference = FirResolvedCallableReferenceImpl(
// session, this@generateCopyFunction, firClass.name,
// firPrimaryConstructor.symbol
// )
// }.apply {
// for ((ktParameter, firParameter) in primaryConstructorParameters.zip(valueParameters)) {
// this.arguments += FirQualifiedAccessExpressionImpl(session, ktParameter).apply {
// calleeReference = FirResolvedCallableReferenceImpl(
// session, ktParameter, firParameter.name, firParameter.symbol
// )
// }
// }
// }
// ).apply {
// target = FirFunctionTarget(null)
// target.bind(copyFunction)
// }
// )
}
)
}
@@ -29,8 +29,7 @@ FILE: annotated.kt
super<kotlin/Any>()
}
public final fun copy(): <implicit> {
^copy R|/Two.Two|()
public final fun copy(): R|Two| {
}
}
@@ -25,8 +25,7 @@ FILE: destructuring.kt
^component3 R|/Some.third|
}
public final fun copy(first: Int = R|/Some.first|, second: Double = R|/Some.second|, third: String = R|/Some.third|): <implicit> {
^copy R|/Some.Some|(R|<local>/first|, R|<local>/second|, R|<local>/third|)
public final fun copy(first: Int = R|/Some.first|, second: Double = R|/Some.second|, third: String = R|/Some.third|): R|Some| {
}
}
@@ -43,8 +43,7 @@ FILE: for.kt
^component2 R|/Some.y|
}
public final fun copy(x: Int = R|/Some.x|, y: Int = R|/Some.y|): <implicit> {
^copy R|/Some.Some|(R|<local>/x|, R|<local>/y|)
public final fun copy(x: Int = R|/Some.x|, y: Int = R|/Some.y|): R|Some| {
}
}
@@ -18,8 +18,7 @@ FILE: lambda.kt
^component2 R|/Tuple.y|
}
public final fun copy(x: Int = R|/Tuple.x|, y: Int = R|/Tuple.y|): <implicit> {
^copy R|/Tuple.Tuple|(R|<local>/x|, R|<local>/y|)
public final fun copy(x: Int = R|/Tuple.x|, y: Int = R|/Tuple.y|): R|Tuple| {
}
}
-1
View File
@@ -19,7 +19,6 @@ FILE: copy.kt
}
public final fun copy(x: R|kotlin/Int| = R|/Some.x|, y: R|kotlin/String| = R|/Some.y|): R|Some| {
^copy R|/Some.Some|(R|<local>/x|, R|<local>/y|)
}
}
@@ -19,7 +19,6 @@ FILE: components.kt
}
public final fun copy(x: R|kotlin/Int| = R|/D.x|, y: R|kotlin/String| = R|/D.y|): R|D| {
^copy R|/D.D|(R|<local>/x|, R|<local>/y|)
}
}
@@ -188,17 +188,6 @@ FILE fqName:<root> fileName:/dataClassWithArrayMembers.kt
EXPRESSION_BODY
CALL 'public final fun <get-doubleArray> (): kotlin.DoubleArray declared in <root>.Test1' type=kotlin.DoubleArray origin=null
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun copy (stringArray: kotlin.Array<kotlin.String>, charArray: kotlin.CharArray, booleanArray: kotlin.BooleanArray, byteArray: kotlin.ByteArray, shortArray: kotlin.ShortArray, intArray: kotlin.IntArray, longArray: kotlin.LongArray, floatArray: kotlin.FloatArray, doubleArray: kotlin.DoubleArray): <root>.Test1 declared in <root>.Test1'
CONSTRUCTOR_CALL 'public constructor <init> (stringArray: kotlin.Array<kotlin.String>, charArray: kotlin.CharArray, booleanArray: kotlin.BooleanArray, byteArray: kotlin.ByteArray, shortArray: kotlin.ShortArray, intArray: kotlin.IntArray, longArray: kotlin.LongArray, floatArray: kotlin.FloatArray, doubleArray: kotlin.DoubleArray) [primary] declared in <root>.Test1' type=<root>.Test1 origin=null
stringArray: GET_VAR 'stringArray: kotlin.Array<kotlin.String> declared in <root>.Test1.copy' type=IrErrorType origin=null
charArray: GET_VAR 'charArray: kotlin.CharArray declared in <root>.Test1.copy' type=IrErrorType origin=null
booleanArray: GET_VAR 'booleanArray: kotlin.BooleanArray declared in <root>.Test1.copy' type=IrErrorType origin=null
byteArray: GET_VAR 'byteArray: kotlin.ByteArray declared in <root>.Test1.copy' type=IrErrorType origin=null
shortArray: GET_VAR 'shortArray: kotlin.ShortArray declared in <root>.Test1.copy' type=IrErrorType origin=null
intArray: GET_VAR 'intArray: kotlin.IntArray declared in <root>.Test1.copy' type=IrErrorType origin=null
longArray: GET_VAR 'longArray: kotlin.LongArray declared in <root>.Test1.copy' type=IrErrorType origin=null
floatArray: GET_VAR 'floatArray: kotlin.FloatArray declared in <root>.Test1.copy' type=IrErrorType origin=null
doubleArray: GET_VAR 'doubleArray: kotlin.DoubleArray declared in <root>.Test1.copy' type=IrErrorType origin=null
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any
@@ -242,10 +231,6 @@ FILE fqName:<root> fileName:/dataClassWithArrayMembers.kt
EXPRESSION_BODY
CALL 'public final fun <get-genericArray> (): kotlin.Array<T of <root>.Test2> declared in <root>.Test2' type=kotlin.Array<T of <root>.Test2> origin=null
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun copy (genericArray: kotlin.Array<T of <root>.Test2>): <root>.Test2<T of <uninitialized parent>> declared in <root>.Test2'
CONSTRUCTOR_CALL 'public constructor <init> (genericArray: kotlin.Array<T of <uninitialized parent>>) [primary] declared in <root>.Test2' type=<root>.Test2<T of <uninitialized parent>> origin=null
<class: T>: <none>
genericArray: GET_VAR 'genericArray: kotlin.Array<T of <root>.Test2> declared in <root>.Test2.copy' type=IrErrorType origin=null
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any
@@ -288,9 +273,6 @@ FILE fqName:<root> fileName:/dataClassWithArrayMembers.kt
EXPRESSION_BODY
CALL 'public final fun <get-anyArrayN> (): kotlin.Array<kotlin.Any>? declared in <root>.Test3' type=kotlin.Array<kotlin.Any>? origin=null
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun copy (anyArrayN: kotlin.Array<kotlin.Any>?): <root>.Test3 declared in <root>.Test3'
CONSTRUCTOR_CALL 'public constructor <init> (anyArrayN: kotlin.Array<kotlin.Any>?) [primary] declared in <root>.Test3' type=<root>.Test3 origin=null
anyArrayN: GET_VAR 'anyArrayN: kotlin.Array<kotlin.Any>? declared in <root>.Test3.copy' type=IrErrorType origin=null
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any
-14
View File
@@ -68,11 +68,6 @@ FILE fqName:<root> fileName:/dataClasses.kt
EXPRESSION_BODY
CALL 'public final fun <get-z> (): kotlin.Any declared in <root>.Test1' type=kotlin.Any origin=null
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun copy (x: kotlin.Int, y: kotlin.String, z: kotlin.Any): <root>.Test1 declared in <root>.Test1'
CONSTRUCTOR_CALL 'public constructor <init> (x: kotlin.Int, y: kotlin.String, z: kotlin.Any) [primary] declared in <root>.Test1' type=<root>.Test1 origin=null
x: GET_VAR 'x: kotlin.Int declared in <root>.Test1.copy' type=IrErrorType origin=null
y: GET_VAR 'y: kotlin.String declared in <root>.Test1.copy' type=IrErrorType origin=null
z: GET_VAR 'z: kotlin.Any declared in <root>.Test1.copy' type=IrErrorType origin=null
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any
@@ -115,9 +110,6 @@ FILE fqName:<root> fileName:/dataClasses.kt
EXPRESSION_BODY
CALL 'public final fun <get-x> (): kotlin.Any? declared in <root>.Test2' type=kotlin.Any? origin=null
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun copy (x: kotlin.Any?): <root>.Test2 declared in <root>.Test2'
CONSTRUCTOR_CALL 'public constructor <init> (x: kotlin.Any?) [primary] declared in <root>.Test2' type=<root>.Test2 origin=null
x: GET_VAR 'x: kotlin.Any? declared in <root>.Test2.copy' type=IrErrorType origin=null
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any
@@ -220,12 +212,6 @@ FILE fqName:<root> fileName:/dataClasses.kt
EXPRESSION_BODY
CALL 'public final fun <get-df> (): kotlin.Float? declared in <root>.Test3' type=kotlin.Float? origin=null
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun copy (d: kotlin.Double, dn: kotlin.Double?, f: kotlin.Float, df: kotlin.Float?): <root>.Test3 declared in <root>.Test3'
CONSTRUCTOR_CALL 'public constructor <init> (d: kotlin.Double, dn: kotlin.Double?, f: kotlin.Float, df: kotlin.Float?) [primary] declared in <root>.Test3' type=<root>.Test3 origin=null
d: GET_VAR 'd: kotlin.Double declared in <root>.Test3.copy' type=IrErrorType origin=null
dn: GET_VAR 'dn: kotlin.Double? declared in <root>.Test3.copy' type=IrErrorType origin=null
f: GET_VAR 'f: kotlin.Float declared in <root>.Test3.copy' type=IrErrorType origin=null
df: GET_VAR 'df: kotlin.Float? declared in <root>.Test3.copy' type=IrErrorType origin=null
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any
@@ -29,10 +29,6 @@ FILE fqName:<root> fileName:/dataClassesGeneric.kt
EXPRESSION_BODY
CALL 'public final fun <get-x> (): T of <root>.Test1 declared in <root>.Test1' type=T of <root>.Test1 origin=null
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun copy (x: T of <root>.Test1): <root>.Test1<T of <uninitialized parent>> declared in <root>.Test1'
CONSTRUCTOR_CALL 'public constructor <init> (x: T of <uninitialized parent>) [primary] declared in <root>.Test1' type=<root>.Test1<T of <uninitialized parent>> origin=null
<class: T>: <none>
x: GET_VAR 'x: T of <root>.Test1 declared in <root>.Test1.copy' type=IrErrorType origin=null
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any
@@ -76,10 +72,6 @@ FILE fqName:<root> fileName:/dataClassesGeneric.kt
EXPRESSION_BODY
CALL 'public final fun <get-x> (): T of <root>.Test2 declared in <root>.Test2' type=T of <root>.Test2 origin=null
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun copy (x: T of <root>.Test2): <root>.Test2<T of <uninitialized parent>> declared in <root>.Test2'
CONSTRUCTOR_CALL 'public constructor <init> (x: T of <uninitialized parent>) [primary] declared in <root>.Test2' type=<root>.Test2<T of <uninitialized parent>> origin=null
<class: T>: <none>
x: GET_VAR 'x: T of <root>.Test2 declared in <root>.Test2.copy' type=IrErrorType origin=null
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any
@@ -123,10 +115,6 @@ FILE fqName:<root> fileName:/dataClassesGeneric.kt
EXPRESSION_BODY
CALL 'public final fun <get-x> (): kotlin.collections.List<T of <root>.Test3> declared in <root>.Test3' type=kotlin.collections.List<T of <root>.Test3> origin=null
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun copy (x: kotlin.collections.List<T of <root>.Test3>): <root>.Test3<T of <uninitialized parent>> declared in <root>.Test3'
CONSTRUCTOR_CALL 'public constructor <init> (x: kotlin.collections.List<T of <uninitialized parent>>) [primary] declared in <root>.Test3' type=<root>.Test3<T of <uninitialized parent>> origin=null
<class: T>: <none>
x: GET_VAR 'x: kotlin.collections.List<T of <root>.Test3> declared in <root>.Test3.copy' type=IrErrorType origin=null
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any
@@ -169,9 +157,6 @@ FILE fqName:<root> fileName:/dataClassesGeneric.kt
EXPRESSION_BODY
CALL 'public final fun <get-x> (): kotlin.collections.List<kotlin.String> declared in <root>.Test4' type=kotlin.collections.List<kotlin.String> origin=null
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun copy (x: kotlin.collections.List<kotlin.String>): <root>.Test4 declared in <root>.Test4'
CONSTRUCTOR_CALL 'public constructor <init> (x: kotlin.collections.List<kotlin.String>) [primary] declared in <root>.Test4' type=<root>.Test4 origin=null
x: GET_VAR 'x: kotlin.collections.List<kotlin.String> declared in <root>.Test4.copy' type=IrErrorType origin=null
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any
@@ -34,9 +34,6 @@ FILE fqName:<root> fileName:/lambdaInDataClassDefaultParameter.kt
EXPRESSION_BODY
CALL 'public final fun <get-runA> (): kotlin.Function2<<root>.A, kotlin.String, kotlin.Unit> declared in <root>.A' type=kotlin.Function2<<root>.A, kotlin.String, kotlin.Unit> origin=null
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun copy (runA: kotlin.Function2<<root>.A, kotlin.String, kotlin.Unit>): <root>.A declared in <root>.A'
CONSTRUCTOR_CALL 'public constructor <init> (runA: kotlin.Function2<<root>.A, kotlin.String, kotlin.Unit>) [primary] declared in <root>.A' type=<root>.A origin=null
runA: GET_VAR 'runA: kotlin.Function2<<root>.A, kotlin.String, kotlin.Unit> declared in <root>.A.copy' type=IrErrorType origin=null
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any
@@ -88,9 +85,6 @@ FILE fqName:<root> fileName:/lambdaInDataClassDefaultParameter.kt
EXPRESSION_BODY
CALL 'public final fun <get-x> (): kotlin.Any declared in <root>.B' type=kotlin.Any origin=null
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun copy (x: kotlin.Any): <root>.B declared in <root>.B'
CONSTRUCTOR_CALL 'public constructor <init> (x: kotlin.Any) [primary] declared in <root>.B' type=<root>.B origin=null
x: GET_VAR 'x: kotlin.Any declared in <root>.B.copy' type=IrErrorType origin=null
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any
@@ -51,11 +51,6 @@ FILE fqName:<root> fileName:/dataClassMembers.kt
EXPRESSION_BODY
CALL 'public final fun <get-y> (): kotlin.String declared in <root>.Test' type=kotlin.String origin=null
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun copy (x: T of <root>.Test, y: kotlin.String): <root>.Test<T of <uninitialized parent>> declared in <root>.Test'
CONSTRUCTOR_CALL 'public constructor <init> (x: T of <uninitialized parent>, y: kotlin.String) [primary] declared in <root>.Test' type=<root>.Test<T of <uninitialized parent>> origin=null
<class: T>: <none>
x: GET_VAR 'x: T of <root>.Test declared in <root>.Test.copy' type=IrErrorType origin=null
y: GET_VAR 'y: kotlin.String declared in <root>.Test.copy' type=IrErrorType origin=null
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any
@@ -48,10 +48,6 @@ FILE fqName:<root> fileName:/destructuringInLambda.kt
EXPRESSION_BODY
CALL 'public final fun <get-y> (): kotlin.Int declared in <root>.A' type=kotlin.Int origin=null
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun copy (x: kotlin.Int, y: kotlin.Int): <root>.A declared in <root>.A'
CONSTRUCTOR_CALL 'public constructor <init> (x: kotlin.Int, y: kotlin.Int) [primary] declared in <root>.A' type=<root>.A origin=null
x: GET_VAR 'x: kotlin.Int declared in <root>.A.copy' type=IrErrorType origin=null
y: GET_VAR 'y: kotlin.Int declared in <root>.A.copy' type=IrErrorType origin=null
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any