[IR] Make IrFunction.returnType lateinit
to replace custom logic that would throw in case of IrUninitialized. This is to remove custom logic from those classes, so that source generator will be able to generate them in a straight-forward way. Otherwise, it would need to be thought about those special cases, which is better to be avoided. There are two consequences: - The error message will be more generic, and won't contain reference to the element. - It becomes possible to reassign returnType property with IrUninitializedType and read it afterward. ^KT-65773 In Progress
This commit is contained in:
committed by
Space Team
parent
92c56d0535
commit
a005f2e75d
+2
-8
@@ -26,7 +26,6 @@ class IrConstructorImpl @IrImplementationDetail constructor(
|
|||||||
override val symbol: IrConstructorSymbol,
|
override val symbol: IrConstructorSymbol,
|
||||||
override var name: Name,
|
override var name: Name,
|
||||||
override var visibility: DescriptorVisibility,
|
override var visibility: DescriptorVisibility,
|
||||||
returnType: IrType,
|
|
||||||
override var isInline: Boolean,
|
override var isInline: Boolean,
|
||||||
override var isExternal: Boolean,
|
override var isExternal: Boolean,
|
||||||
override var isPrimary: Boolean,
|
override var isPrimary: Boolean,
|
||||||
@@ -41,13 +40,6 @@ class IrConstructorImpl @IrImplementationDetail constructor(
|
|||||||
override lateinit var parent: IrDeclarationParent
|
override lateinit var parent: IrDeclarationParent
|
||||||
override var annotations: List<IrConstructorCall> = emptyList()
|
override var annotations: List<IrConstructorCall> = emptyList()
|
||||||
|
|
||||||
override var returnType: IrType = returnType
|
|
||||||
get() = if (field === IrUninitializedType) {
|
|
||||||
throw ReturnTypeIsNotInitializedException(this)
|
|
||||||
} else {
|
|
||||||
field
|
|
||||||
}
|
|
||||||
|
|
||||||
override var typeParameters: List<IrTypeParameter> = emptyList()
|
override var typeParameters: List<IrTypeParameter> = emptyList()
|
||||||
|
|
||||||
override var dispatchReceiverParameter: IrValueParameter? = null
|
override var dispatchReceiverParameter: IrValueParameter? = null
|
||||||
@@ -55,6 +47,8 @@ class IrConstructorImpl @IrImplementationDetail constructor(
|
|||||||
override var contextReceiverParametersCount: Int = 0
|
override var contextReceiverParametersCount: Int = 0
|
||||||
override var valueParameters: List<IrValueParameter> = emptyList()
|
override var valueParameters: List<IrValueParameter> = emptyList()
|
||||||
|
|
||||||
|
override lateinit var returnType: IrType
|
||||||
|
|
||||||
override var body: IrBody? = null
|
override var body: IrBody? = null
|
||||||
|
|
||||||
override var metadata: MetadataSource? = null
|
override var metadata: MetadataSource? = null
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.ir.expressions.impl.IrBlockBodyImpl
|
|||||||
import org.jetbrains.kotlin.ir.expressions.impl.IrExpressionBodyImpl
|
import org.jetbrains.kotlin.ir.expressions.impl.IrExpressionBodyImpl
|
||||||
import org.jetbrains.kotlin.ir.symbols.*
|
import org.jetbrains.kotlin.ir.symbols.*
|
||||||
import org.jetbrains.kotlin.ir.types.IrType
|
import org.jetbrains.kotlin.ir.types.IrType
|
||||||
|
import org.jetbrains.kotlin.ir.types.impl.IrUninitializedType
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedContainerSource
|
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedContainerSource
|
||||||
import org.jetbrains.kotlin.types.Variance
|
import org.jetbrains.kotlin.types.Variance
|
||||||
@@ -83,9 +84,13 @@ abstract class AbstractIrFactoryImpl : IrFactory {
|
|||||||
containerSource: DeserializedContainerSource?,
|
containerSource: DeserializedContainerSource?,
|
||||||
): IrConstructor =
|
): IrConstructor =
|
||||||
IrConstructorImpl(
|
IrConstructorImpl(
|
||||||
startOffset, endOffset, origin, symbol, name, visibility, returnType, isInline, isExternal, isPrimary, isExpect,
|
startOffset, endOffset, origin, symbol, name, visibility, isInline, isExternal, isPrimary, isExpect,
|
||||||
containerSource, factory = this
|
containerSource, factory = this
|
||||||
)
|
).apply {
|
||||||
|
if (returnType != IrUninitializedType) {
|
||||||
|
this.returnType = returnType
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun createEnumEntry(
|
override fun createEnumEntry(
|
||||||
startOffset: Int,
|
startOffset: Int,
|
||||||
@@ -137,10 +142,14 @@ abstract class AbstractIrFactoryImpl : IrFactory {
|
|||||||
isFakeOverride: Boolean,
|
isFakeOverride: Boolean,
|
||||||
): IrSimpleFunction =
|
): IrSimpleFunction =
|
||||||
IrFunctionImpl(
|
IrFunctionImpl(
|
||||||
startOffset, endOffset, origin, symbol, name, visibility, modality, returnType,
|
startOffset, endOffset, origin, symbol, name, visibility, modality,
|
||||||
isInline, isExternal, isTailrec, isSuspend, isOperator, isInfix, isExpect, isFakeOverride,
|
isInline, isExternal, isTailrec, isSuspend, isOperator, isInfix, isExpect, isFakeOverride,
|
||||||
containerSource, factory = this
|
containerSource, factory = this
|
||||||
)
|
).apply {
|
||||||
|
if (returnType != IrUninitializedType) {
|
||||||
|
this.returnType = returnType
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun createFunctionWithLateBinding(
|
override fun createFunctionWithLateBinding(
|
||||||
startOffset: Int,
|
startOffset: Int,
|
||||||
@@ -166,7 +175,6 @@ abstract class AbstractIrFactoryImpl : IrFactory {
|
|||||||
name = name,
|
name = name,
|
||||||
visibility = visibility,
|
visibility = visibility,
|
||||||
modality = modality,
|
modality = modality,
|
||||||
returnType = returnType,
|
|
||||||
isInline = isInline,
|
isInline = isInline,
|
||||||
isExternal = isExternal,
|
isExternal = isExternal,
|
||||||
isTailrec = isTailrec,
|
isTailrec = isTailrec,
|
||||||
@@ -176,7 +184,11 @@ abstract class AbstractIrFactoryImpl : IrFactory {
|
|||||||
isExpect = isExpect,
|
isExpect = isExpect,
|
||||||
isFakeOverride = isFakeOverride,
|
isFakeOverride = isFakeOverride,
|
||||||
factory = this
|
factory = this
|
||||||
)
|
).apply {
|
||||||
|
if (returnType != IrUninitializedType) {
|
||||||
|
this.returnType = returnType
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun createLocalDelegatedProperty(
|
override fun createLocalDelegatedProperty(
|
||||||
startOffset: Int,
|
startOffset: Int,
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ class IrFunctionImpl @IrImplementationDetail constructor(
|
|||||||
override var name: Name,
|
override var name: Name,
|
||||||
override var visibility: DescriptorVisibility,
|
override var visibility: DescriptorVisibility,
|
||||||
override var modality: Modality,
|
override var modality: Modality,
|
||||||
returnType: IrType,
|
|
||||||
override var isInline: Boolean,
|
override var isInline: Boolean,
|
||||||
override var isExternal: Boolean,
|
override var isExternal: Boolean,
|
||||||
override var isTailrec: Boolean,
|
override var isTailrec: Boolean,
|
||||||
@@ -55,13 +54,6 @@ class IrFunctionImpl @IrImplementationDetail constructor(
|
|||||||
override lateinit var parent: IrDeclarationParent
|
override lateinit var parent: IrDeclarationParent
|
||||||
override var annotations: List<IrConstructorCall> = emptyList()
|
override var annotations: List<IrConstructorCall> = emptyList()
|
||||||
|
|
||||||
override var returnType: IrType = returnType
|
|
||||||
get() = if (field === IrUninitializedType) {
|
|
||||||
throw ReturnTypeIsNotInitializedException(this)
|
|
||||||
} else {
|
|
||||||
field
|
|
||||||
}
|
|
||||||
|
|
||||||
override var typeParameters: List<IrTypeParameter> = emptyList()
|
override var typeParameters: List<IrTypeParameter> = emptyList()
|
||||||
|
|
||||||
override var dispatchReceiverParameter: IrValueParameter? = null
|
override var dispatchReceiverParameter: IrValueParameter? = null
|
||||||
@@ -70,6 +62,8 @@ class IrFunctionImpl @IrImplementationDetail constructor(
|
|||||||
|
|
||||||
override var contextReceiverParametersCount: Int = 0
|
override var contextReceiverParametersCount: Int = 0
|
||||||
|
|
||||||
|
override lateinit var returnType: IrType
|
||||||
|
|
||||||
override var body: IrBody? = null
|
override var body: IrBody? = null
|
||||||
|
|
||||||
override var metadata: MetadataSource? = null
|
override var metadata: MetadataSource? = null
|
||||||
|
|||||||
+2
-8
@@ -28,7 +28,6 @@ class IrFunctionWithLateBindingImpl @IrImplementationDetail constructor(
|
|||||||
override var name: Name,
|
override var name: Name,
|
||||||
override var visibility: DescriptorVisibility,
|
override var visibility: DescriptorVisibility,
|
||||||
override var modality: Modality,
|
override var modality: Modality,
|
||||||
returnType: IrType,
|
|
||||||
override var isInline: Boolean,
|
override var isInline: Boolean,
|
||||||
override var isExternal: Boolean,
|
override var isExternal: Boolean,
|
||||||
override var isTailrec: Boolean,
|
override var isTailrec: Boolean,
|
||||||
@@ -66,13 +65,6 @@ class IrFunctionWithLateBindingImpl @IrImplementationDetail constructor(
|
|||||||
|
|
||||||
override var annotations: List<IrConstructorCall> = emptyList()
|
override var annotations: List<IrConstructorCall> = emptyList()
|
||||||
|
|
||||||
override var returnType: IrType = returnType
|
|
||||||
get() = if (field === IrUninitializedType) {
|
|
||||||
throw ReturnTypeIsNotInitializedException(this)
|
|
||||||
} else {
|
|
||||||
field
|
|
||||||
}
|
|
||||||
|
|
||||||
override var typeParameters: List<IrTypeParameter> = emptyList()
|
override var typeParameters: List<IrTypeParameter> = emptyList()
|
||||||
|
|
||||||
override var dispatchReceiverParameter: IrValueParameter? = null
|
override var dispatchReceiverParameter: IrValueParameter? = null
|
||||||
@@ -81,6 +73,8 @@ class IrFunctionWithLateBindingImpl @IrImplementationDetail constructor(
|
|||||||
|
|
||||||
override var contextReceiverParametersCount: Int = 0
|
override var contextReceiverParametersCount: Int = 0
|
||||||
|
|
||||||
|
override lateinit var returnType: IrType
|
||||||
|
|
||||||
override var body: IrBody? = null
|
override var body: IrBody? = null
|
||||||
|
|
||||||
override var metadata: MetadataSource? = null
|
override var metadata: MetadataSource? = null
|
||||||
|
|||||||
Reference in New Issue
Block a user