[IR] Unite inline class and multi-field value class representation

#KT-1179
This commit is contained in:
Evgeniy.Zhelenskiy
2022-03-10 00:02:35 +03:00
committed by teamcity
parent 282ab398c6
commit 28bf83ceac
69 changed files with 2464 additions and 3598 deletions
@@ -38,9 +38,13 @@ abstract class IrClass :
abstract var thisReceiver: IrValueParameter?
abstract var inlineClassRepresentation: InlineClassRepresentation<IrSimpleType>?
abstract var valueClassRepresentation: ValueClassRepresentation<IrSimpleType>?
abstract var multiFieldValueClassRepresentation: MultiFieldValueClassRepresentation<IrSimpleType>?
val inlineClassRepresentation: InlineClassRepresentation<IrSimpleType>?
get() = valueClassRepresentation as? InlineClassRepresentation<IrSimpleType>
val multiFieldValueClassRepresentation: MultiFieldValueClassRepresentation<IrSimpleType>?
get() = valueClassRepresentation as? MultiFieldValueClassRepresentation<IrSimpleType>
abstract var sealedSubclasses: List<IrClassSymbol>
@@ -5,10 +5,11 @@
package org.jetbrains.kotlin.ir.declarations
import org.jetbrains.kotlin.descriptors.InlineClassRepresentation
import org.jetbrains.kotlin.descriptors.MultiFieldValueClassRepresentation
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
import org.jetbrains.kotlin.ir.util.primaryConstructor
import java.io.File
fun <D : IrAttributeContainer> D.copyAttributes(other: IrAttributeContainer?): D = apply {
@@ -18,10 +19,10 @@ fun <D : IrAttributeContainer> D.copyAttributes(other: IrAttributeContainer?): D
}
val IrClass.isSingleFieldValueClass: Boolean
get() = this.isValue && (this.inlineClassRepresentation != null || this.primaryConstructor?.valueParameters?.size == 1)
get() = valueClassRepresentation is InlineClassRepresentation
val IrClass.isMultiFieldValueClass: Boolean
get() = this.isValue && !isSingleFieldValueClass
get() = valueClassRepresentation is MultiFieldValueClassRepresentation
fun IrClass.addMember(member: IrDeclaration) {
declarations.add(member)
@@ -17,7 +17,6 @@ import org.jetbrains.kotlin.metadata.ProtoBuf
import org.jetbrains.kotlin.metadata.deserialization.NameResolver
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedClassDescriptor
import org.jetbrains.kotlin.types.SimpleType
class IrLazyClass(
override val startOffset: Int,
@@ -101,15 +100,10 @@ class IrLazyClass(
}
}
override var inlineClassRepresentation: InlineClassRepresentation<IrSimpleType>? by lazyVar(stubGenerator.lock) {
descriptor.inlineClassRepresentation?.mapUnderlyingType(::simplyTypeToIrOrThrow)
}
private fun simplyTypeToIrOrThrow(it: SimpleType) =
it.toIrType() as? IrSimpleType ?: error("Inline class underlying type is not a simple type: ${render()}")
override var multiFieldValueClassRepresentation: MultiFieldValueClassRepresentation<IrSimpleType>? by lazyVar(stubGenerator.lock) {
descriptor.multiFieldValueClassRepresentation?.mapUnderlyingType(::simplyTypeToIrOrThrow)
override var valueClassRepresentation: ValueClassRepresentation<IrSimpleType>? by lazyVar(stubGenerator.lock) {
descriptor.valueClassRepresentation?.mapUnderlyingType {
it.toIrType() as? IrSimpleType ?: error("Value class underlying type is not a simple type: ${render()}")
}
}
override var attributeOwnerId: IrAttributeContainer = this
@@ -30,7 +30,6 @@ import org.jetbrains.kotlin.serialization.deserialization.descriptors.Deserializ
import org.jetbrains.kotlin.storage.LockBasedStorageManager
import org.jetbrains.kotlin.storage.StorageManager
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.typeUtil.makeNullable
/* Descriptors that serve purely as a view into IR structures.
Created each time at the borderline between IR-based and descriptor-based code (such as inliner).
@@ -626,11 +625,8 @@ open class IrBasedClassDescriptor(owner: IrClass) : ClassDescriptor, IrBasedDecl
TODO("not implemented")
}
override fun getInlineClassRepresentation(): InlineClassRepresentation<SimpleType>? =
owner.inlineClassRepresentation?.mapUnderlyingType { it.toIrBasedKotlinType() as SimpleType }
override fun getMultiFieldValueClassRepresentation(): MultiFieldValueClassRepresentation<SimpleType>? =
owner.multiFieldValueClassRepresentation?.mapUnderlyingType { it.toIrBasedKotlinType() as SimpleType }
override fun getValueClassRepresentation(): ValueClassRepresentation<SimpleType>? =
owner.valueClassRepresentation?.mapUnderlyingType { it.toIrBasedKotlinType() as SimpleType }
override fun getOriginal() = this
@@ -756,13 +752,9 @@ open class IrBasedEnumEntryDescriptor(owner: IrEnumEntry) : ClassDescriptor, IrB
override fun getDeclaredTypeParameters(): List<TypeParameterDescriptor> = emptyList()
override fun getSealedSubclasses(): Collection<ClassDescriptor> {
TODO("not implemented")
}
override fun getSealedSubclasses(): Collection<ClassDescriptor> = TODO("not implemented")
override fun getInlineClassRepresentation(): InlineClassRepresentation<SimpleType>? = TODO("not implemented")
override fun getMultiFieldValueClassRepresentation(): MultiFieldValueClassRepresentation<SimpleType>? = TODO("not implemented")
override fun getValueClassRepresentation(): ValueClassRepresentation<SimpleType>? = TODO("not implemented")
override fun getOriginal() = this
@@ -462,6 +462,12 @@ interface IrTypeSystemContext : TypeSystemContext, TypeSystemCommonSuperTypesCon
override fun TypeConstructorMarker.isInlineClass(): Boolean =
(this as? IrClassSymbol)?.owner?.isSingleFieldValueClass == true
override fun TypeConstructorMarker.isMultiFieldValueClass(): Boolean =
(this as? IrClassSymbol)?.owner?.isMultiFieldValueClass == true
override fun TypeConstructorMarker.valueClassRepresentationTypeMarkersList(): List<Pair<Name, SimpleTypeMarker>>? =
(this as? IrClassSymbol)?.owner?.valueClassRepresentation?.underlyingPropertyNamesToTypes
override fun TypeConstructorMarker.isInnerClass(): Boolean =
(this as? IrClassSymbol)?.owner?.isInner == true
@@ -30,7 +30,7 @@ import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
import org.jetbrains.kotlin.ir.symbols.impl.IrValueParameterSymbolImpl
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.descriptorUtil.isEffectivelyExternal
import org.jetbrains.kotlin.resolve.isInlineOrValueClass
import org.jetbrains.kotlin.resolve.isValueClass
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedContainerSource
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
@@ -269,7 +269,7 @@ abstract class DeclarationStubGenerator(
isInner = descriptor.isInner,
isData = descriptor.isData,
isExternal = descriptor.isEffectivelyExternal(),
isValue = descriptor.isInlineOrValueClass(),
isValue = descriptor.isValueClass(),
isExpect = descriptor.isExpect,
isFun = descriptor.isFun,
stubGenerator = this,
@@ -159,7 +159,7 @@ open class DeepCopyIrTreeWithSymbols(
symbolRemapper.getReferencedClass(it)
}
thisReceiver = declaration.thisReceiver?.transform()
inlineClassRepresentation = declaration.inlineClassRepresentation?.mapUnderlyingType { it.remapType() as IrSimpleType }
valueClassRepresentation = declaration.valueClassRepresentation?.mapUnderlyingType { it.remapType() as IrSimpleType }
declaration.transformDeclarationsTo(this)
}.copyAttributes(declaration)
@@ -12,7 +12,7 @@ import org.jetbrains.kotlin.ir.declarations.IrFactory
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.descriptorUtil.isEffectivelyExternal
import org.jetbrains.kotlin.resolve.isInlineOrValueClass
import org.jetbrains.kotlin.resolve.isValueClass
import org.jetbrains.kotlin.types.KotlinType
val ParameterDescriptor.indexOrMinusOne: Int
@@ -39,5 +39,5 @@ fun IrFactory.createIrClassFromDescriptor(
): IrClass = createClass(
startOffset, endOffset, origin, symbol, name, descriptor.kind, visibility, modality,
descriptor.isCompanionObject, descriptor.isInner, descriptor.isData, descriptor.isEffectivelyExternal(),
descriptor.isInlineOrValueClass(), descriptor.isExpect, descriptor.isFun, descriptor.source
descriptor.isValueClass(), descriptor.isExpect, descriptor.isFun, descriptor.source
)