[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
@@ -201,10 +201,11 @@ open class ProtoCompareGenerated(
if (!checkEquals(oldTypeTable.getType(old.inlineClassUnderlyingTypeId), newTypeTable.getType(new.inlineClassUnderlyingTypeId))) return false
}
if (old.hasMultiFieldValueClassRepresentation() != new.hasMultiFieldValueClassRepresentation()) return false
if (old.hasMultiFieldValueClassRepresentation()) {
if (!checkEquals(old.multiFieldValueClassRepresentation, new.multiFieldValueClassRepresentation)) return false
}
if (!checkEqualsClassMultiFieldValueClassUnderlyingName(old, new)) return false
if (!checkEqualsClassMultiFieldValueClassUnderlyingType(old, new)) return false
if (!checkEqualsClassMultiFieldValueClassUnderlyingTypeId(old, new)) return false
if (!checkEqualsClassVersionRequirement(old, new)) return false
@@ -295,7 +296,9 @@ open class ProtoCompareGenerated(
INLINE_CLASS_UNDERLYING_PROPERTY_NAME,
INLINE_CLASS_UNDERLYING_TYPE,
INLINE_CLASS_UNDERLYING_TYPE_ID,
MULTI_FIELD_VALUE_CLASS_REPRESENTATION,
MULTI_FIELD_VALUE_CLASS_UNDERLYING_NAME_LIST,
MULTI_FIELD_VALUE_CLASS_UNDERLYING_TYPE_LIST,
MULTI_FIELD_VALUE_CLASS_UNDERLYING_TYPE_ID_LIST,
VERSION_REQUIREMENT_LIST,
VERSION_REQUIREMENT_TABLE,
JVM_EXT_CLASS_MODULE_NAME,
@@ -363,10 +366,11 @@ open class ProtoCompareGenerated(
if (!checkEquals(oldTypeTable.getType(old.inlineClassUnderlyingTypeId), newTypeTable.getType(new.inlineClassUnderlyingTypeId))) result.add(ProtoBufClassKind.INLINE_CLASS_UNDERLYING_TYPE_ID)
}
if (old.hasMultiFieldValueClassRepresentation() != new.hasMultiFieldValueClassRepresentation()) result.add(ProtoBufClassKind.MULTI_FIELD_VALUE_CLASS_REPRESENTATION)
if (old.hasMultiFieldValueClassRepresentation()) {
if (!checkEquals(old.multiFieldValueClassRepresentation, new.multiFieldValueClassRepresentation)) result.add(ProtoBufClassKind.MULTI_FIELD_VALUE_CLASS_REPRESENTATION)
}
if (!checkEqualsClassMultiFieldValueClassUnderlyingName(old, new)) result.add(ProtoBufClassKind.MULTI_FIELD_VALUE_CLASS_UNDERLYING_NAME_LIST)
if (!checkEqualsClassMultiFieldValueClassUnderlyingType(old, new)) result.add(ProtoBufClassKind.MULTI_FIELD_VALUE_CLASS_UNDERLYING_TYPE_LIST)
if (!checkEqualsClassMultiFieldValueClassUnderlyingTypeId(old, new)) result.add(ProtoBufClassKind.MULTI_FIELD_VALUE_CLASS_UNDERLYING_TYPE_ID_LIST)
if (!checkEqualsClassVersionRequirement(old, new)) result.add(ProtoBufClassKind.VERSION_REQUIREMENT_LIST)
@@ -1026,12 +1030,6 @@ open class ProtoCompareGenerated(
return true
}
open fun checkEquals(old: ProtoBuf.Class.MultiFieldValueClassRepresentation, new: ProtoBuf.Class.MultiFieldValueClassRepresentation): Boolean {
if (!checkEqualsClassMultiFieldValueClassRepresentationProperty(old, new)) return false
return true
}
open fun checkEquals(old: ProtoBuf.Annotation, new: ProtoBuf.Annotation): Boolean {
if (!checkClassIdEquals(old.id, new.id)) return false
@@ -1256,22 +1254,6 @@ open class ProtoCompareGenerated(
return true
}
open fun checkEquals(old: ProtoBuf.Class.MultiFieldValueClassRepresentation.MultiFieldValueClassProperty, new: ProtoBuf.Class.MultiFieldValueClassRepresentation.MultiFieldValueClassProperty): Boolean {
if (old.name != new.name) return false
if (old.hasType() != new.hasType()) return false
if (old.hasType()) {
if (!checkEquals(old.type, new.type)) return false
}
if (old.hasTypeId() != new.hasTypeId()) return false
if (old.hasTypeId()) {
if (old.typeId != new.typeId) return false
}
return true
}
open fun checkEquals(old: ProtoBuf.Annotation.Argument, new: ProtoBuf.Annotation.Argument): Boolean {
if (!checkStringEquals(old.nameId, new.nameId)) return false
@@ -1498,6 +1480,36 @@ open class ProtoCompareGenerated(
return true
}
open fun checkEqualsClassMultiFieldValueClassUnderlyingName(old: ProtoBuf.Class, new: ProtoBuf.Class): Boolean {
if (old.multiFieldValueClassUnderlyingNameCount != new.multiFieldValueClassUnderlyingNameCount) return false
for(i in 0..old.multiFieldValueClassUnderlyingNameCount - 1) {
if (!checkStringEquals(old.getMultiFieldValueClassUnderlyingName(i), new.getMultiFieldValueClassUnderlyingName(i))) return false
}
return true
}
open fun checkEqualsClassMultiFieldValueClassUnderlyingType(old: ProtoBuf.Class, new: ProtoBuf.Class): Boolean {
if (old.multiFieldValueClassUnderlyingTypeCount != new.multiFieldValueClassUnderlyingTypeCount) return false
for(i in 0..old.multiFieldValueClassUnderlyingTypeCount - 1) {
if (!checkEquals(old.getMultiFieldValueClassUnderlyingType(i), new.getMultiFieldValueClassUnderlyingType(i))) return false
}
return true
}
open fun checkEqualsClassMultiFieldValueClassUnderlyingTypeId(old: ProtoBuf.Class, new: ProtoBuf.Class): Boolean {
if (old.multiFieldValueClassUnderlyingTypeIdCount != new.multiFieldValueClassUnderlyingTypeIdCount) return false
for(i in 0..old.multiFieldValueClassUnderlyingTypeIdCount - 1) {
if (!checkEquals(oldTypeTable.getType(old.getMultiFieldValueClassUnderlyingTypeId(i)), newTypeTable.getType(new.getMultiFieldValueClassUnderlyingTypeId(i)))) return false
}
return true
}
open fun checkEqualsClassVersionRequirement(old: ProtoBuf.Class, new: ProtoBuf.Class): Boolean {
if (old.versionRequirementCount != new.versionRequirementCount) return false
@@ -1688,16 +1700,6 @@ open class ProtoCompareGenerated(
return true
}
open fun checkEqualsClassMultiFieldValueClassRepresentationProperty(old: ProtoBuf.Class.MultiFieldValueClassRepresentation, new: ProtoBuf.Class.MultiFieldValueClassRepresentation): Boolean {
if (old.propertyCount != new.propertyCount) return false
for(i in 0..old.propertyCount - 1) {
if (!checkEquals(old.getProperty(i), new.getProperty(i))) return false
}
return true
}
open fun checkEqualsAnnotationArgument(old: ProtoBuf.Annotation, new: ProtoBuf.Annotation): Boolean {
if (old.argumentCount != new.argumentCount) return false
@@ -1907,8 +1909,16 @@ fun ProtoBuf.Class.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes: (Int) ->
hashCode = 31 * hashCode + typeById(inlineClassUnderlyingTypeId).hashCode(stringIndexes, fqNameIndexes, typeById)
}
if (hasMultiFieldValueClassRepresentation()) {
hashCode = 31 * hashCode + multiFieldValueClassRepresentation.hashCode(stringIndexes, fqNameIndexes, typeById)
for(i in 0..multiFieldValueClassUnderlyingNameCount - 1) {
hashCode = 31 * hashCode + stringIndexes(getMultiFieldValueClassUnderlyingName(i))
}
for(i in 0..multiFieldValueClassUnderlyingTypeCount - 1) {
hashCode = 31 * hashCode + getMultiFieldValueClassUnderlyingType(i).hashCode(stringIndexes, fqNameIndexes, typeById)
}
for(i in 0..multiFieldValueClassUnderlyingTypeIdCount - 1) {
hashCode = 31 * hashCode + typeById(getMultiFieldValueClassUnderlyingTypeId(i)).hashCode(stringIndexes, fqNameIndexes, typeById)
}
for(i in 0..versionRequirementCount - 1) {
@@ -2412,16 +2422,6 @@ fun ProtoBuf.EnumEntry.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes: (Int
return hashCode
}
fun ProtoBuf.Class.MultiFieldValueClassRepresentation.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes: (Int) -> Int, typeById: (Int) -> ProtoBuf.Type): Int {
var hashCode = 1
for(i in 0..propertyCount - 1) {
hashCode = 31 * hashCode + getProperty(i).hashCode(stringIndexes, fqNameIndexes, typeById)
}
return hashCode
}
fun ProtoBuf.Annotation.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes: (Int) -> Int, typeById: (Int) -> ProtoBuf.Type): Int {
var hashCode = 1
@@ -2622,22 +2622,6 @@ fun ProtoBuf.Type.Argument.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes:
return hashCode
}
fun ProtoBuf.Class.MultiFieldValueClassRepresentation.MultiFieldValueClassProperty.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes: (Int) -> Int, typeById: (Int) -> ProtoBuf.Type): Int {
var hashCode = 1
hashCode = 31 * hashCode + name
if (hasType()) {
hashCode = 31 * hashCode + type.hashCode(stringIndexes, fqNameIndexes, typeById)
}
if (hasTypeId()) {
hashCode = 31 * hashCode + typeId
}
return hashCode
}
fun ProtoBuf.Annotation.Argument.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes: (Int) -> Int, typeById: (Int) -> ProtoBuf.Type): Int {
var hashCode = 1
@@ -292,7 +292,9 @@ class DifferenceCalculatorForClass(
ProtoBufClassKind.INLINE_CLASS_UNDERLYING_PROPERTY_NAME,
ProtoBufClassKind.INLINE_CLASS_UNDERLYING_TYPE,
ProtoBufClassKind.INLINE_CLASS_UNDERLYING_TYPE_ID,
ProtoBufClassKind.MULTI_FIELD_VALUE_CLASS_REPRESENTATION -> {
ProtoBufClassKind.MULTI_FIELD_VALUE_CLASS_UNDERLYING_NAME_LIST,
ProtoBufClassKind.MULTI_FIELD_VALUE_CLASS_UNDERLYING_TYPE_LIST,
ProtoBufClassKind.MULTI_FIELD_VALUE_CLASS_UNDERLYING_TYPE_ID_LIST -> {
isClassAffected = true
}
ProtoBufClassKind.CONTEXT_RECEIVER_TYPE_LIST,
File diff suppressed because it is too large Load Diff
@@ -59,6 +59,7 @@ import static org.jetbrains.kotlin.codegen.DescriptorAsmUtil.*;
import static org.jetbrains.kotlin.codegen.JvmCodegenUtil.isConst;
import static org.jetbrains.kotlin.codegen.binding.CodegenBinding.CLOSURE;
import static org.jetbrains.kotlin.codegen.serialization.JvmSerializationBindings.METHOD_FOR_FUNCTION;
import static org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt.getInlineClassRepresentation;
import static org.jetbrains.kotlin.resolve.jvm.AsmTypes.*;
import static org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin.NO_ORIGIN;
import static org.jetbrains.org.objectweb.asm.Opcodes.*;
@@ -382,8 +383,7 @@ public class ClosureCodegen extends MemberCodegen<KtElement> {
}
if (InlineClassesCodegenUtilKt.isInlineClassWithUnderlyingTypeAnyOrAnyN(parameterType) && functionReferenceCall == null) {
ClassDescriptor descriptor = TypeUtils.getClassDescriptor(parameterType);
InlineClassRepresentation<SimpleType> representation =
descriptor != null ? descriptor.getInlineClassRepresentation() : null;
InlineClassRepresentation<SimpleType> representation = getInlineClassRepresentation(descriptor);
assert representation != null : "Not an inline class type: " + parameterType;
parameterType = representation.getUnderlyingType();
}
@@ -117,6 +117,7 @@ import static org.jetbrains.kotlin.resolve.BindingContext.*;
import static org.jetbrains.kotlin.resolve.BindingContextUtils.getDelegationConstructorCall;
import static org.jetbrains.kotlin.resolve.BindingContextUtils.isBoxedLocalCapturedInClosure;
import static org.jetbrains.kotlin.resolve.DescriptorUtils.*;
import static org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt.getInlineClassRepresentation;
import static org.jetbrains.kotlin.resolve.jvm.AsmTypes.*;
import static org.jetbrains.kotlin.types.RangeUtilKt.isPrimitiveNumberClassDescriptor;
import static org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils.isFunctionExpression;
@@ -1998,8 +1999,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
!CoroutineCodegenUtilKt.isInvokeSuspendOfLambda(context.getFunctionDescriptor())
) {
ClassDescriptor inlineClass = (ClassDescriptor) inlineClassType.getConstructor().getDeclarationDescriptor();
InlineClassRepresentation<SimpleType> representation =
inlineClass != null ? inlineClass.getInlineClassRepresentation() : null;
InlineClassRepresentation<SimpleType> representation = getInlineClassRepresentation(inlineClass);
assert representation != null : "Not an inline class: " + inlineClassType;
KotlinType underlyingType = representation.getUnderlyingType();
return StackValue.underlyingValueOfInlineClass(typeMapper.mapType(underlyingType), underlyingType, localOrCaptured);
@@ -79,6 +79,7 @@ import static org.jetbrains.kotlin.descriptors.CallableMemberDescriptor.Kind.DEL
import static org.jetbrains.kotlin.descriptors.ModalityUtilsKt.isOverridable;
import static org.jetbrains.kotlin.resolve.DescriptorToSourceUtils.getSourceFromDescriptor;
import static org.jetbrains.kotlin.resolve.DescriptorUtils.*;
import static org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt.getInlineClassRepresentation;
import static org.jetbrains.kotlin.resolve.inline.InlineOnlyKt.isInlineOnlyPrivateInBytecode;
import static org.jetbrains.kotlin.resolve.jvm.AsmTypes.OBJECT_TYPE;
import static org.jetbrains.kotlin.resolve.jvm.InlineClassManglingRulesKt.shouldHideConstructorDueToInlineClassTypeValueParameters;
@@ -378,7 +379,7 @@ public class FunctionCodegen {
Type fieldOwnerType = typeMapper.mapClass(inlineClass);
Method erasedMethodImpl = typeMapper.mapAsmMethod(functionDescriptor.getOriginal(), OwnerKind.ERASED_INLINE_CLASS);
InlineClassRepresentation<SimpleType> representation = inlineClass.getInlineClassRepresentation();
InlineClassRepresentation<SimpleType> representation = getInlineClassRepresentation(inlineClass);
assert representation != null : "Not an inline class: " + inlineClass;
generateDelegateToStaticErasedVersion(
@@ -82,6 +82,7 @@ import static org.jetbrains.kotlin.resolve.BindingContext.INDEXED_LVALUE_SET;
import static org.jetbrains.kotlin.resolve.BindingContextUtils.getNotNull;
import static org.jetbrains.kotlin.resolve.DescriptorToSourceUtils.descriptorToDeclaration;
import static org.jetbrains.kotlin.resolve.DescriptorUtils.*;
import static org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt.getInlineClassRepresentation;
import static org.jetbrains.kotlin.resolve.jvm.AsmTypes.OBJECT_TYPE;
import static org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin.NO_ORIGIN;
import static org.jetbrains.kotlin.types.Variance.INVARIANT;
@@ -276,7 +277,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
@Override
protected void generateUnboxMethodForInlineClass() {
if (!(myClass instanceof KtClass)) return;
InlineClassRepresentation<SimpleType> inlineClassRepresentation = descriptor.getInlineClassRepresentation();
InlineClassRepresentation<SimpleType> inlineClassRepresentation = getInlineClassRepresentation(descriptor);
if (inlineClassRepresentation == null) return;
Type ownerType = typeMapper.mapClass(descriptor);
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.load.kotlin.JvmPackagePartSource
import org.jetbrains.kotlin.load.kotlin.VirtualFileFinder
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.resolve.descriptorUtil.classId
import org.jetbrains.kotlin.resolve.descriptorUtil.inlineClassRepresentation
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedClassDescriptor
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedSimpleFunctionDescriptor
import org.jetbrains.kotlin.types.KotlinType
@@ -643,21 +643,10 @@ fun Fir2IrComponents.createTemporaryVariableForSafeCallConstruction(
): Pair<IrVariable, IrValueSymbol> =
createTemporaryVariable(receiverExpression, conversionScope, "safe_receiver")
// TODO: implement inlineClassRepresentation in FirRegularClass instead.
fun Fir2IrComponents.computeInlineClassRepresentation(klass: FirRegularClass): InlineClassRepresentation<IrSimpleType>? {
if (!(klass.isInline && klass.primaryConstructorIfAny(session)?.valueParameterSymbols?.size == 1)) return null
val parameter = klass.getInlineClassUnderlyingParameter(session) ?: error("Inline class has no underlying parameter: ${klass.render()}")
val underlyingType = parameter.returnTypeRef.toIrType(typeConverter)
return InlineClassRepresentation(
parameter.name,
underlyingType as? IrSimpleType ?: error("Inline class underlying type is not a simple type: ${klass.render()}")
)
}
// TODO: implement multiFieldValueClassRepresentation in FirRegularClass instead.
fun Fir2IrComponents.computeMultiFieldValueClassRepresentation(klass: FirRegularClass): MultiFieldValueClassRepresentation<IrSimpleType>? {
val parameters = klass.getMultiFieldValueClassUnderlyingParameters(session) ?: return null
return MultiFieldValueClassRepresentation(parameters.map {
// TODO: implement valueClassRepresentation in FirRegularClass instead. zhelenskiy
fun Fir2IrComponents.computeValueClassRepresentation(klass: FirRegularClass): ValueClassRepresentation<IrSimpleType>? {
val parameters = klass.getValueClassUnderlyingParameters(session) ?: return null
return createValueClassRepresentation(IrTypeSystemContextImpl(irBuiltIns), parameters.map {
val type = it.returnTypeRef.toIrType(typeConverter).safeAs<IrSimpleType>()
?: error("Value class underlying type is not a simple type: ${klass.render()}")
it.name to type
@@ -133,9 +133,9 @@ class Fir2IrClassifierStorage(
superTypes = klass.superTypeRefs.map { superTypeRef -> superTypeRef.toIrType() }
}
private fun IrClass.declareInlineClassRepresentation(klass: FirRegularClass) {
private fun IrClass.declareValueClassRepresentation(klass: FirRegularClass) {
if (this !is Fir2IrLazyClass) {
inlineClassRepresentation = computeInlineClassRepresentation(klass)
valueClassRepresentation = computeValueClassRepresentation(klass)
}
}
@@ -216,7 +216,7 @@ class Fir2IrClassifierStorage(
irClass.declareTypeParameters(regularClass)
irClass.setThisReceiver(regularClass.typeParameters)
irClass.declareSupertypes(regularClass)
irClass.declareInlineClassRepresentation(regularClass)
irClass.declareValueClassRepresentation(regularClass)
return irClass
}
@@ -134,13 +134,8 @@ class Fir2IrLazyClass(
receiver
}
override var inlineClassRepresentation: InlineClassRepresentation<IrSimpleType>?
get() = computeInlineClassRepresentation(fir)
set(_) {
error("Mutating Fir2Ir lazy elements is not possible")
}
override var multiFieldValueClassRepresentation: MultiFieldValueClassRepresentation<IrSimpleType>?
get() = computeMultiFieldValueClassRepresentation(fir)
override var valueClassRepresentation: ValueClassRepresentation<IrSimpleType>?
get() = computeValueClassRepresentation(fir)
set(_) {
error("Mutating Fir2Ir lazy elements is not possible")
}
@@ -1,43 +0,0 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.fir.declarations
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.declarations.utils.isInline
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
import org.jetbrains.kotlin.fir.resolve.substitution.createTypeSubstitutorByTypeConstructor
import org.jetbrains.kotlin.fir.resolve.toSymbol
import org.jetbrains.kotlin.fir.symbols.ensureResolved
import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
import org.jetbrains.kotlin.fir.types.ConeKotlinType
import org.jetbrains.kotlin.fir.types.ConeLookupTagBasedType
import org.jetbrains.kotlin.fir.types.ConeTypeContext
import org.jetbrains.kotlin.fir.types.coneType
import org.jetbrains.kotlin.types.model.typeConstructor
internal fun ConeKotlinType.substitutedUnderlyingTypeForInlineClass(session: FirSession, context: ConeTypeContext): ConeKotlinType? {
val unsubstitutedType = unsubstitutedUnderlyingTypeForInlineClass(session) ?: return null
val substitutor = createTypeSubstitutorByTypeConstructor(
mapOf(this.typeConstructor(context) to this), context, approximateIntegerLiterals = true
)
return substitutor.substituteOrNull(unsubstitutedType)
}
internal fun ConeKotlinType.unsubstitutedUnderlyingTypeForInlineClass(session: FirSession): ConeKotlinType? {
val symbol = (this.fullyExpandedType(session) as? ConeLookupTagBasedType)
?.lookupTag
?.toSymbol(session) as? FirRegularClassSymbol
?: return null
symbol.ensureResolved(FirResolvePhase.STATUS)
return symbol.fir.getInlineClassUnderlyingParameter(session)?.returnTypeRef?.coneType
}
// TODO: implement inlineClassRepresentation in FirRegularClass instead.
fun FirRegularClass.getInlineClassUnderlyingParameter(session: FirSession): FirValueParameter? =
if (isInline) primaryConstructorIfAny(session)?.fir?.valueParameters?.singleOrNull() else null
fun FirRegularClass.getMultiFieldValueClassUnderlyingParameters(session: FirSession): List<FirValueParameter>? =
if (isInline) primaryConstructorIfAny(session)?.fir?.valueParameters?.takeIf { it.size > 1 } else null
@@ -9,6 +9,8 @@ import org.jetbrains.kotlin.builtins.PrimitiveType
import org.jetbrains.kotlin.builtins.StandardNames
import org.jetbrains.kotlin.descriptors.ClassKind
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.descriptors.ValueClassKind
import org.jetbrains.kotlin.descriptors.valueClassLoweringKind
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.declarations.utils.*
@@ -22,10 +24,7 @@ import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag
import org.jetbrains.kotlin.fir.symbols.ConeTypeParameterLookupTag
import org.jetbrains.kotlin.fir.symbols.ensureResolved
import org.jetbrains.kotlin.fir.symbols.impl.*
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.FqNameUnsafe
import org.jetbrains.kotlin.name.SpecialNames
import org.jetbrains.kotlin.name.StandardClassIds
import org.jetbrains.kotlin.name.*
import org.jetbrains.kotlin.types.TypeCheckerState
import org.jetbrains.kotlin.types.TypeCheckerState.SupertypesPolicy.DoCustomTransform
import org.jetbrains.kotlin.types.TypeCheckerState.SupertypesPolicy.LowerIfFlexible
@@ -552,7 +551,17 @@ interface ConeTypeContext : TypeSystemContext, TypeSystemOptimizationContext, Ty
}
override fun TypeConstructorMarker.isInlineClass(): Boolean {
return toFirRegularClass()?.isInline == true
val fields = getValueClassProperties() ?: return false
return this@ConeTypeContext.valueClassLoweringKind(fields) == ValueClassKind.Inline
}
override fun TypeConstructorMarker.isMultiFieldValueClass(): Boolean {
val fields = getValueClassProperties() ?: return false
return this@ConeTypeContext.valueClassLoweringKind(fields) == ValueClassKind.MultiField
}
override fun TypeConstructorMarker.getValueClassProperties(): List<Pair<Name, SimpleTypeMarker>>? {
return toFirRegularClass()?.valueClassRepresentation?.underlyingPropertyNamesToTypes
}
override fun TypeConstructorMarker.isInnerClass(): Boolean {
@@ -94,8 +94,7 @@ class SyntheticClassOrObjectDescriptor(
override fun getStaticScope() = MemberScope.Empty
override fun getUnsubstitutedMemberScope(kotlinTypeRefiner: KotlinTypeRefiner) = unsubstitutedMemberScope
override fun getSealedSubclasses() = emptyList<ClassDescriptor>()
override fun getInlineClassRepresentation(): InlineClassRepresentation<SimpleType>? = null
override fun getMultiFieldValueClassRepresentation(): MultiFieldValueClassRepresentation<SimpleType>? = null
override fun getValueClassRepresentation(): ValueClassRepresentation<SimpleType>? = null
init {
assert(modality != Modality.SEALED) { "Implement getSealedSubclasses() for this class: ${this::class.java}" }
@@ -271,7 +271,7 @@ class DeclarationsChecker(
if (declaration is KtPrimaryConstructor &&
!DescriptorUtils.isAnnotationClass(constructorDescriptor.constructedClass) &&
!constructorDescriptor.constructedClass.isInlineOrValueClass()
!constructorDescriptor.constructedClass.isValueClass()
) {
for (parameter in declaration.valueParameters) {
if (parameter.hasValOrVar()) {
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
import org.jetbrains.kotlin.resolve.descriptorUtil.inlineClassRepresentation
import org.jetbrains.kotlin.types.KotlinType
object InlineClassDescriptorResolver {
@@ -77,7 +77,7 @@ object InlineClassDeclarationChecker : DeclarationChecker {
return
}
if (context.languageVersionSettings.supportsFeature(LanguageFeature.ValueClasses) && descriptor.isValueClass()) {
if (context.languageVersionSettings.supportsFeature(LanguageFeature.ValueClasses)) {
if (primaryConstructor.valueParameters.isEmpty()) {
(primaryConstructor.valueParameterList ?: declaration).let {
trace.report(Errors.VALUE_CLASS_EMPTY_CONSTRUCTOR.on(it))
@@ -176,7 +176,7 @@ class PropertiesWithBackingFieldsInsideInlineClass : DeclarationChecker {
if (declaration !is KtProperty) return
if (descriptor !is PropertyDescriptor) return
if (!descriptor.containingDeclaration.isInlineOrValueClass()) return
if (!descriptor.containingDeclaration.isValueClass()) return
if (context.trace.get(BindingContext.BACKING_FIELD_REQUIRED, descriptor) == true) {
context.trace.report(Errors.PROPERTY_WITH_BACKING_FIELD_INSIDE_VALUE_CLASS.on(declaration))
@@ -194,7 +194,7 @@ class InnerClassInsideInlineClass : DeclarationChecker {
if (descriptor !is ClassDescriptor) return
if (!descriptor.isInner) return
if (!descriptor.containingDeclaration.isInlineOrValueClass()) return
if (!descriptor.containingDeclaration.isValueClass()) return
context.trace.report(Errors.INNER_CLASS_INSIDE_VALUE_CLASS.on(declaration.modifierList!!.getModifier(KtTokens.INNER_KEYWORD)!!))
}
@@ -208,7 +208,7 @@ class ReservedMembersAndConstructsForInlineClass : DeclarationChecker {
override fun check(declaration: KtDeclaration, descriptor: DeclarationDescriptor, context: DeclarationCheckerContext) {
val containingDeclaration = descriptor.containingDeclaration ?: return
if (!containingDeclaration.isInlineOrValueClass()) return
if (!containingDeclaration.isValueClass()) return
if (descriptor !is FunctionDescriptor) return
@@ -23,8 +23,6 @@ import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.diagnostics.reportDiagnosticOnce
import org.jetbrains.kotlin.incremental.components.InlineConstTracker
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.resolve.descriptorUtil.isCompanionObject
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.parsing.*
@@ -32,15 +30,18 @@ import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
import org.jetbrains.kotlin.resolve.*
import org.jetbrains.kotlin.resolve.BindingContext.COLLECTION_LITERAL_CALL
import org.jetbrains.kotlin.resolve.calls.util.getEffectiveExpectedType
import org.jetbrains.kotlin.resolve.calls.util.getResolvedCall
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
import org.jetbrains.kotlin.resolve.calls.model.ResolvedValueArgument
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
import org.jetbrains.kotlin.resolve.calls.util.getEffectiveExpectedType
import org.jetbrains.kotlin.resolve.calls.util.getResolvedCall
import org.jetbrains.kotlin.resolve.checkers.ExperimentalUsageChecker
import org.jetbrains.kotlin.resolve.constants.*
import org.jetbrains.kotlin.resolve.constants.evaluate.CompileTimeType.*
import org.jetbrains.kotlin.resolve.descriptorUtil.classId
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
import org.jetbrains.kotlin.resolve.descriptorUtil.inlineClassRepresentation
import org.jetbrains.kotlin.resolve.descriptorUtil.isCompanionObject
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.SimpleType
import org.jetbrains.kotlin.types.TypeUtils
@@ -52,7 +53,6 @@ import org.jetbrains.kotlin.types.typeUtil.isBoolean
import org.jetbrains.kotlin.types.typeUtil.isSubtypeOf
import org.jetbrains.kotlin.util.OperatorNameConventions
import java.math.BigInteger
import java.util.*
class ConstantExpressionEvaluator(
internal val module: ModuleDescriptor,
@@ -19,7 +19,6 @@ import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
import org.jetbrains.kotlin.descriptors.impl.ClassDescriptorBase;
import org.jetbrains.kotlin.descriptors.impl.FunctionDescriptorImpl;
import org.jetbrains.kotlin.descriptors.impl.ReceiverParameterDescriptorImpl;
import org.jetbrains.kotlin.diagnostics.DiagnosticFactory0;
import org.jetbrains.kotlin.incremental.components.NoLookupLocation;
import org.jetbrains.kotlin.lexer.KtTokens;
@@ -41,7 +40,6 @@ import org.jetbrains.kotlin.resolve.lazy.declarations.ClassMemberDeclarationProv
import org.jetbrains.kotlin.resolve.scopes.LexicalScope;
import org.jetbrains.kotlin.resolve.scopes.MemberScope;
import org.jetbrains.kotlin.resolve.scopes.StaticScopeForKotlinEnum;
import org.jetbrains.kotlin.resolve.scopes.receivers.ContextClassReceiver;
import org.jetbrains.kotlin.resolve.source.KotlinSourceElementKt;
import org.jetbrains.kotlin.storage.MemoizedFunctionToNotNull;
import org.jetbrains.kotlin.storage.NotNullLazyValue;
@@ -631,43 +629,49 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
@Nullable
@Override
public InlineClassRepresentation<SimpleType> getInlineClassRepresentation() {
if (!InlineClassesUtilsKt.isInlineClass(this)) return null;
ClassConstructorDescriptor constructor = getUnsubstitutedPrimaryConstructor();
if (constructor != null) {
ValueParameterDescriptor parameter = firstOrNull(constructor.getValueParameters());
if (parameter != null) {
return new InlineClassRepresentation<>(parameter.getName(), (SimpleType) parameter.getType());
}
public ValueClassRepresentation<SimpleType> getValueClassRepresentation() {
if (!this.isValue && !this.isInline) {
return null;
}
ClassConstructorDescriptor constructor = getUnsubstitutedPrimaryConstructor();
// Don't crash on invalid code.
return new InlineClassRepresentation<>(
InlineClassRepresentation<SimpleType> invalidValueClassRepresentation = new InlineClassRepresentation<>(
SpecialNames.SAFE_IDENTIFIER_FOR_NO_NAME, c.getModuleDescriptor().getBuiltIns().getAnyType()
);
}
@Nullable
@Override
public MultiFieldValueClassRepresentation<SimpleType> getMultiFieldValueClassRepresentation() {
if (!InlineClassesUtilsKt.isValueClass(this) || InlineClassesUtilsKt.isInlineClass(this)) {
return null;
}
ClassConstructorDescriptor constructor = getUnsubstitutedPrimaryConstructor();
// Don't crash on invalid code. It is IC, not MFVC.
if (constructor == null) {
return null;
return invalidValueClassRepresentation;
}
List<ValueParameterDescriptor> parameters = constructor.getValueParameters();
if (parameters.size() <= 1) {
return null;
SimpleClassicTypeSystemContext context = SimpleClassicTypeSystemContext.INSTANCE;
if (isRecursiveInlineClass(constructor, new HashSet<>())) {
return new InlineClassRepresentation<>(parameters.get(0).getName(), (SimpleType) parameters.get(0).getType());
}
List<Pair<Name, SimpleType>> properties = parameters.stream()
if (parameters.size() == 0) {
return invalidValueClassRepresentation;
}
List<Pair<Name, SimpleType>> fields = parameters.stream()
.map(parameter -> new Pair<>(parameter.getName(), (SimpleType) parameter.getType()))
.collect(Collectors.toList());
return new MultiFieldValueClassRepresentation<>(properties);
return ValueClassRepresentationKt.createValueClassRepresentation(context, fields);
}
private static boolean isRecursiveInlineClass(@Nullable ClassConstructorDescriptor constructor, @NotNull Set<ClassDescriptor> visited) {
if (constructor == null || constructor.getValueParameters().size() != 1 ||
!(constructor.getConstructedClass().isValue() || constructor.getConstructedClass().isInline())) {
return false;
}
if (!visited.add(constructor.getConstructedClass())) {
return true;
}
SimpleType type = (SimpleType) constructor.getValueParameters().get(0).getType();
ClassifierDescriptor descriptor = type.getConstructor().getDeclarationDescriptor();
if (descriptor instanceof ClassDescriptor) {
ClassConstructorDescriptor newConstructor = ((ClassDescriptor) descriptor).getUnsubstitutedPrimaryConstructor();
return isRecursiveInlineClass(newConstructor, visited);
}
return false;
}
@Override
@@ -296,7 +296,7 @@ open class LazyClassMemberScope(
}
result.addAll(generateDelegatingDescriptors(name, EXTRACT_FUNCTIONS, result))
generateDataClassMethods(result, name, location, fromSupertypes)
generateFunctionsFromAnyForInlineClass(result, name, fromSupertypes)
generateFunctionsFromAnyForValueClass(result, name, fromSupertypes)
c.syntheticResolveExtension.generateSyntheticMethods(thisDescriptor, name, trace.bindingContext, fromSupertypes, result)
c.additionalClassPartsProvider.generateAdditionalMethods(thisDescriptor, result, name, location, fromSupertypes)
@@ -304,12 +304,12 @@ open class LazyClassMemberScope(
generateFakeOverrides(name, fromSupertypes, result, SimpleFunctionDescriptor::class.java)
}
private fun generateFunctionsFromAnyForInlineClass(
private fun generateFunctionsFromAnyForValueClass(
result: MutableCollection<SimpleFunctionDescriptor>,
name: Name,
fromSupertypes: List<SimpleFunctionDescriptor>
) {
if (!thisDescriptor.isInlineOrValueClass()) return
if (!thisDescriptor.isValueClass()) return
FunctionsFromAny.addFunctionFromAnyIfNeeded(thisDescriptor, result, name, fromSupertypes)
}
@@ -5,6 +5,7 @@
package org.jetbrains.kotlin.ir.backend.js.lower.calls
import org.jetbrains.kotlin.descriptors.InlineClassRepresentation
import org.jetbrains.kotlin.ir.backend.js.JsIrBackendContext
import org.jetbrains.kotlin.ir.backend.js.ir.JsIrBuilder
import org.jetbrains.kotlin.ir.backend.js.utils.isEqualsInheritedFromAny
@@ -17,6 +18,7 @@ import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
import org.jetbrains.kotlin.ir.types.*
import org.jetbrains.kotlin.ir.util.*
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
class EqualityAndComparisonCallsTransformer(context: JsIrBackendContext) : CallsTransformer {
@@ -11,7 +11,7 @@ import org.jetbrains.kotlin.backend.jvm.isMultiFieldValueClassFieldGetter
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.expressions.*
private class JvmInlineMultiFieldValueClassLowering(context: JvmBackendContext) : JvmValueClassAbstractLowering(context) {
private class JvmMultiFieldValueClassLowering(context: JvmBackendContext) : JvmValueClassAbstractLowering(context) {
override val replacements: MemoizedValueClassAbstractReplacements
get() = context.multiFieldValueClassReplacements
@@ -121,14 +121,6 @@ internal abstract class JvmValueClassAbstractLowering(val context: JvmBackendCon
protected abstract fun addJvmInlineAnnotation(valueClass: IrClass)
// abstract override fun visitFunctionReference(expression: IrFunctionReference): IrExpression
// abstract override fun visitFunctionAccess(expression: IrFunctionAccessExpression): IrExpression
// abstract override fun visitCall(expression: IrCall): IrExpression
// abstract override fun visitGetField(expression: IrGetField): IrExpression
final override fun visitReturn(expression: IrReturn): IrExpression {
expression.returnTargetSymbol.owner.safeAs<IrFunction>()?.let { target ->
val suffix = target.hashSuffix()
@@ -129,8 +129,7 @@ class JvmBackendContext(
val inlineClassReplacements = MemoizedInlineClassReplacements(state.functionsWithInlineClassReturnTypesMangled, irFactory, this)
val multiFieldValueClassReplacements =
MemoizedMultiFieldValueClassReplacements(state.functionsWithInlineClassReturnTypesMangled, irFactory, this)
val multiFieldValueClassReplacements = MemoizedMultiFieldValueClassReplacements(irFactory, this)
val continuationClassesVarsCountByType: MutableMap<IrAttributeContainer, Map<Type, Int>> = hashMapOf()
@@ -273,7 +273,7 @@ class JvmSymbols(
private val resultClassStub: IrClassSymbol =
createClass(StandardNames.RESULT_FQ_NAME, classIsValue = true) { klass ->
klass.addTypeParameter("T", irBuiltIns.anyNType, Variance.OUT_VARIANCE)
klass.inlineClassRepresentation = InlineClassRepresentation(Name.identifier("value"), irBuiltIns.anyNType as IrSimpleType)
klass.valueClassRepresentation = InlineClassRepresentation(Name.identifier("value"), irBuiltIns.anyNType as IrSimpleType)
}
val resultOfAnyType: IrType = resultClassStub.typeWith(irBuiltIns.anyNType)
@@ -40,7 +40,7 @@ class MemoizedInlineClassReplacements(
private val storageManager = LockBasedStorageManager("inline-class-replacements")
private val propertyMap = ConcurrentHashMap<IrPropertySymbol, IrProperty>()
val originalFunctionForStaticReplacement: MutableMap<IrFunction, IrFunction> = ConcurrentHashMap()
override val originalFunctionForStaticReplacement: MutableMap<IrFunction, IrFunction> = ConcurrentHashMap()
internal val originalFunctionForMethodReplacement: MutableMap<IrFunction, IrFunction> = ConcurrentHashMap()
/**
@@ -5,298 +5,28 @@
package org.jetbrains.kotlin.backend.jvm
import org.jetbrains.kotlin.backend.common.ir.copyTo
import org.jetbrains.kotlin.backend.common.ir.copyTypeParameters
import org.jetbrains.kotlin.backend.jvm.ir.*
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.ir.builders.declarations.buildFun
import org.jetbrains.kotlin.ir.builders.declarations.buildProperty
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
import org.jetbrains.kotlin.ir.types.isInt
import org.jetbrains.kotlin.ir.util.*
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.ir.declarations.IrFactory
import org.jetbrains.kotlin.ir.declarations.IrFunction
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
import org.jetbrains.kotlin.storage.LockBasedStorageManager
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
import java.util.concurrent.ConcurrentHashMap
/**
* Keeps track of replacement functions and multi-field value class box/unbox functions.
*/
class MemoizedMultiFieldValueClassReplacements(
private val mangleReturnTypes: Boolean, // todo always false
irFactory: IrFactory,
context: JvmBackendContext
) : MemoizedValueClassAbstractReplacements(irFactory, context) { // There is only sample logic yet
) : MemoizedValueClassAbstractReplacements(irFactory, context) {
private val storageManager = LockBasedStorageManager("multi-field-value-class-replacements")
private val propertyMap = ConcurrentHashMap<IrPropertySymbol, IrProperty>()
val originalFunctionForStaticReplacement: MutableMap<IrFunction, IrFunction> = ConcurrentHashMap()
override val originalFunctionForStaticReplacement: MutableMap<IrFunction, IrFunction> = ConcurrentHashMap()
internal val originalFunctionForMethodReplacement: MutableMap<IrFunction, IrFunction> = ConcurrentHashMap()
/**
* Get a replacement for a function or a constructor.
*/
override val getReplacementFunction: (IrFunction) -> IrSimpleFunction? = storageManager.createMemoizedFunctionWithNullableValues {
when {
// Don't mangle anonymous or synthetic functions, except for generated SAM wrapper methods
(it.isLocal && it is IrSimpleFunction && it.overriddenSymbols.isEmpty()) ||
(it.origin == IrDeclarationOrigin.DELEGATED_PROPERTY_ACCESSOR && it.visibility == DescriptorVisibilities.LOCAL) ||
it.isStaticInlineClassReplacement ||
it.origin.isSynthetic && it.origin != IrDeclarationOrigin.SYNTHETIC_GENERATED_SAM_IMPLEMENTATION ->
null
it.isMultiFieldValueClassFieldGetter ->
if (it.hasMangledReturnType)
createMethodReplacement(it)
else
null
// Mangle all functions in the body of an inline class
it.parent.safeAs<IrClass>()?.isMultiFieldValueClass == true ->
when {
it.isRemoveAtSpecialBuiltinStub() ->
null
it.isInlineClassMemberFakeOverriddenFromJvmDefaultInterfaceMethod() ||
it.origin == IrDeclarationOrigin.IR_BUILTINS_STUB ->
createMethodReplacement(it)
else ->
createStaticReplacement(it)
}
// Otherwise, mangle functions with mangled parameters, ignoring constructors
it is IrSimpleFunction && !it.isFromJava() && (it.hasMangledParameters || mangleReturnTypes && it.hasMangledReturnType) ->
createMethodReplacement(it)
else ->
null
}
}
private fun IrFunction.isRemoveAtSpecialBuiltinStub() =
origin == IrDeclarationOrigin.IR_BUILTINS_STUB &&
name.asString() == "remove" &&
valueParameters.size == 1 &&
valueParameters[0].type.isInt()
private fun IrFunction.isInlineClassMemberFakeOverriddenFromJvmDefaultInterfaceMethod(): Boolean {
if (this !is IrSimpleFunction) return false
if (!this.isFakeOverride) return false
val parentClass = parentClassOrNull ?: return false
if (!parentClass.isMultiFieldValueClass) return false
val overridden = resolveFakeOverride() ?: return false
if (!overridden.parentAsClass.isJvmInterface) return false
if (overridden.modality == Modality.ABSTRACT) return false
// We have a non-abstract interface member.
// It is a JVM default interface method if one of the following conditions are true:
// - it is a Java method,
// - it is a Kotlin function compiled to JVM default interface method.
return overridden.isFromJava() || overridden.isCompiledToJvmDefault(context.state.jvmDefaultMode)
}
// /**
// * Get the box function for an inline class. Concretely, this is a synthetic
// * static function named "box-impl" which takes an unboxed value and returns
// * a boxed value.
// */
// val getBoxFunction: (IrClass) -> IrSimpleFunction =
// storageManager.createMemoizedFunction { irClass ->
// require(irClass.isSingleFieldValueClass)
// irFactory.buildFun {
// name = Name.identifier(KotlinTypeMapper.BOX_JVM_METHOD_NAME)
// origin = JvmLoweredDeclarationOrigin.SYNTHETIC_INLINE_CLASS_MEMBER
// returnType = irClass.defaultType
// }.apply {
// parent = irClass
// copyTypeParametersFrom(irClass)
// addValueParameter {
// name = InlineClassDescriptorResolver.BOXING_VALUE_PARAMETER_NAME
// type = irClass.inlineClassRepresentation!!.underlyingType
// }
// }
// }
//
// /**
// * Get the unbox function for an inline class. Concretely, this is a synthetic
// * member function named "unbox-impl" which returns an unboxed result.
// */
// val getUnboxFunction: (IrClass) -> IrSimpleFunction =
// storageManager.createMemoizedFunction { irClass ->
// require(irClass.isSingleFieldValueClass)
// irFactory.buildFun {
// name = Name.identifier(KotlinTypeMapper.UNBOX_JVM_METHOD_NAME)
// origin = JvmLoweredDeclarationOrigin.SYNTHETIC_INLINE_CLASS_MEMBER
// returnType = irClass.inlineClassRepresentation!!.underlyingType
// }.apply {
// parent = irClass
// createDispatchReceiverParameter()
// }
// }
//
// private val specializedEqualsCache = storageManager.createCacheWithNotNullValues<IrClass, IrSimpleFunction>()
// fun getSpecializedEqualsMethod(irClass: IrClass, irBuiltIns: IrBuiltIns): IrSimpleFunction {
// require(irClass.isSingleFieldValueClass)
// return specializedEqualsCache.computeIfAbsent(irClass) {
// irFactory.buildFun {
// name = InlineClassDescriptorResolver.SPECIALIZED_EQUALS_NAME
// // TODO: Revisit this once we allow user defined equals methods in inline classes.
// origin = JvmLoweredDeclarationOrigin.INLINE_CLASS_GENERATED_IMPL_METHOD
// returnType = irBuiltIns.booleanType
// }.apply {
// parent = irClass
// // We ignore type arguments here, since there is no good way to go from type arguments to types in the IR anyway.
// val typeArgument =
// IrSimpleTypeImpl(null, irClass.symbol, false, List(irClass.typeParameters.size) { IrStarProjectionImpl }, listOf())
// addValueParameter {
// name = InlineClassDescriptorResolver.SPECIALIZED_EQUALS_FIRST_PARAMETER_NAME
// type = typeArgument
// }
// addValueParameter {
// name = InlineClassDescriptorResolver.SPECIALIZED_EQUALS_SECOND_PARAMETER_NAME
// type = typeArgument
// }
// }
// }
// }
private fun createMethodReplacement(function: IrFunction): IrSimpleFunction =
buildReplacement(function, function.origin) {
originalFunctionForMethodReplacement[this] = function
dispatchReceiverParameter = function.dispatchReceiverParameter?.copyTo(this, index = -1)
extensionReceiverParameter = function.extensionReceiverParameter?.copyTo(
// The function's name will be mangled, so preserve the old receiver name.
this, index = -1, name = Name.identifier(function.extensionReceiverName(context.state))
)
contextReceiverParametersCount = function.contextReceiverParametersCount
valueParameters = function.valueParameters.mapIndexed { index, parameter ->
parameter.copyTo(this, index = index, defaultValue = null).also {
// Assuming that constructors and non-override functions are always replaced with the unboxed
// equivalent, deep-copying the value here is unnecessary. See `JvmInlineClassLowering`.
it.defaultValue = parameter.defaultValue?.patchDeclarationParents(this)
}
}
}
private fun createStaticReplacement(function: IrFunction): IrSimpleFunction =
buildReplacement(function, JvmLoweredDeclarationOrigin.STATIC_INLINE_CLASS_REPLACEMENT, noFakeOverride = true) {
originalFunctionForStaticReplacement[this] = function
val newValueParameters = mutableListOf<IrValueParameter>()
if (function.dispatchReceiverParameter != null) {
// FAKE_OVERRIDEs have broken dispatch receivers
newValueParameters += function.parentAsClass.thisReceiver!!.copyTo(
this, index = newValueParameters.size, name = Name.identifier("arg${newValueParameters.size}"),
type = function.parentAsClass.defaultType, origin = IrDeclarationOrigin.MOVED_DISPATCH_RECEIVER
)
}
if (function.contextReceiverParametersCount != 0) {
function.valueParameters.take(function.contextReceiverParametersCount).forEachIndexed { i, contextReceiver ->
newValueParameters += contextReceiver.copyTo(
this, index = newValueParameters.size, name = Name.identifier("contextReceiver$i"),
origin = IrDeclarationOrigin.MOVED_CONTEXT_RECEIVER
)
}
}
function.extensionReceiverParameter?.let {
newValueParameters += it.copyTo(
this, index = newValueParameters.size, name = Name.identifier(function.extensionReceiverName(context.state)),
origin = IrDeclarationOrigin.MOVED_EXTENSION_RECEIVER
)
}
for (parameter in function.valueParameters.drop(function.contextReceiverParametersCount)) {
newValueParameters += parameter.copyTo(this, index = newValueParameters.size, defaultValue = null).also {
// See comment next to a similar line above.
it.defaultValue = parameter.defaultValue?.patchDeclarationParents(this)
}
}
valueParameters = newValueParameters
}
private fun buildReplacement(
function: IrFunction,
replacementOrigin: IrDeclarationOrigin,
noFakeOverride: Boolean = false,
body: IrFunction.() -> Unit
): IrSimpleFunction {
val useOldManglingScheme = context.state.useOldManglingSchemeForFunctionsWithInlineClassesInSignatures
val replacement = buildReplacementInner(function, replacementOrigin, noFakeOverride, useOldManglingScheme, body)
// When using the new mangling scheme we might run into dependencies using the old scheme
// for which we will fall back to the old mangling scheme as well.
if (
!useOldManglingScheme &&
replacement.name.asString().contains("-") &&
function.parentClassId?.let { classFileContainsMethod(it, replacement, context) } == false
) {
return buildReplacementInner(function, replacementOrigin, noFakeOverride, true, body)
}
return replacement
}
private fun buildReplacementInner(
function: IrFunction,
replacementOrigin: IrDeclarationOrigin,
noFakeOverride: Boolean,
useOldManglingScheme: Boolean,
body: IrFunction.() -> Unit,
): IrSimpleFunction = irFactory.buildFun {
updateFrom(function)
if (function is IrConstructor) {
// The [updateFrom] call will set the modality to FINAL for constructors, while the JVM backend would use OPEN here.
modality = Modality.OPEN
}
origin = when {
function.origin == IrDeclarationOrigin.GENERATED_SINGLE_FIELD_VALUE_CLASS_MEMBER ->
JvmLoweredDeclarationOrigin.INLINE_CLASS_GENERATED_IMPL_METHOD
function is IrConstructor && function.constructedClass.isSingleFieldValueClass ->
JvmLoweredDeclarationOrigin.STATIC_INLINE_CLASS_CONSTRUCTOR
else ->
replacementOrigin
}
if (noFakeOverride) {
isFakeOverride = false
}
name = InlineClassAbi.mangledNameFor(function, mangleReturnTypes, useOldManglingScheme)
returnType = function.returnType
}.apply {
parent = function.parent
annotations = function.annotations
copyTypeParameters(function.allTypeParameters)
if (function.metadata != null) {
metadata = function.metadata
function.metadata = null
}
copyAttributes(function as? IrAttributeContainer)
if (function is IrSimpleFunction) {
val propertySymbol = function.correspondingPropertySymbol
if (propertySymbol != null) {
val property = propertyMap.getOrPut(propertySymbol) {
irFactory.buildProperty {
name = propertySymbol.owner.name
updateFrom(propertySymbol.owner)
}.apply {
parent = propertySymbol.owner.parent
copyAttributes(propertySymbol.owner)
annotations = propertySymbol.owner.annotations
backingField = propertySymbol.owner.backingField
}
}
correspondingPropertySymbol = property.symbol
when (function) {
propertySymbol.owner.getter -> property.getter = this
propertySymbol.owner.setter -> property.setter = this
else -> error("Orphaned property getter/setter: ${function.render()}")
}
}
overriddenSymbols = function.overriddenSymbols.map {
getReplacementFunction(it.owner)?.symbol ?: it
}
}
body()
TODO()
}
}
@@ -14,4 +14,7 @@ abstract class MemoizedValueClassAbstractReplacements(protected val irFactory: I
* Get a replacement for a function or a constructor.
*/
abstract val getReplacementFunction: (IrFunction) -> IrSimpleFunction?
abstract val originalFunctionForStaticReplacement: MutableMap<IrFunction, IrFunction>
}
@@ -106,12 +106,11 @@ class ClassGenerator(
generateFakeOverrideMemberDeclarations(irClass, ktClassOrObject)
irClass.valueClassRepresentation = classDescriptor.valueClassRepresentation?.mapUnderlyingType { type ->
type.toIrType() as? IrSimpleType ?: error("Value class underlying type is not a simple type: $classDescriptor")
}
if (irClass.isSingleFieldValueClass && ktClassOrObject is KtClassOrObject) {
val representation = classDescriptor.inlineClassRepresentation
?: error("Unknown representation for inline class: $classDescriptor")
irClass.inlineClassRepresentation = representation.mapUnderlyingType { type ->
type.toIrType() as? IrSimpleType ?: error("Inline class underlying type is not a simple type: $classDescriptor")
}
generateAdditionalMembersForSingleFieldValueClasses(irClass, ktClassOrObject)
}
@@ -164,7 +163,11 @@ class ClassGenerator(
context.extensions.getParentClassStaticScope(classDescriptor)?.run {
for (parentStaticMember in getContributedDescriptors()) {
if (parentStaticMember is FunctionDescriptor &&
DescriptorVisibilityUtils.isVisibleIgnoringReceiver(parentStaticMember, classDescriptor, context.languageVersionSettings)
DescriptorVisibilityUtils.isVisibleIgnoringReceiver(
parentStaticMember,
classDescriptor,
context.languageVersionSettings
)
) {
val fakeOverride = createFakeOverrideDescriptorForParentStaticMember(classDescriptor, parentStaticMember)
declarationGenerator.generateFakeOverrideDeclaration(fakeOverride, ktClassOrObject)?.let {
@@ -523,8 +526,10 @@ class ClassGenerator(
if (!enumEntryDescriptor.isExpect) {
irEnumEntry.initializerExpression =
context.irFactory.createExpressionBody(createBodyGenerator(irEnumEntry.symbol)
.generateEnumEntryInitializer(ktEnumEntry, enumEntryDescriptor))
context.irFactory.createExpressionBody(
createBodyGenerator(irEnumEntry.symbol)
.generateEnumEntryInitializer(ktEnumEntry, enumEntryDescriptor)
)
}
if (ktEnumEntry.hasMemberDeclarations()) {
@@ -97,7 +97,7 @@ class StandaloneDeclarationGenerator(private val context: GeneratorContext) {
descriptor.thisAsReceiverParameter.type.toIrType()
).also { it.parent = irClass }
irClass.inlineClassRepresentation = descriptor.inlineClassRepresentation?.mapUnderlyingType { it.toIrType() as IrSimpleType }
irClass.valueClassRepresentation = descriptor.valueClassRepresentation?.mapUnderlyingType { it.toIrType() as IrSimpleType }
}
return irClass
@@ -63,9 +63,7 @@ open class IrClassImpl(
override var superTypes: List<IrType> = emptyList()
override var inlineClassRepresentation: InlineClassRepresentation<IrSimpleType>? = null
override var multiFieldValueClassRepresentation: MultiFieldValueClassRepresentation<IrSimpleType>? = null
override var valueClassRepresentation: ValueClassRepresentation<IrSimpleType>? = null
override var metadata: MetadataSource? = null
@@ -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
)
@@ -533,6 +533,7 @@ message IrClass {
repeated IrDeclaration declaration = 5;
repeated int32 super_type = 6 [packed=true];
optional IrInlineClassRepresentation inline_class_representation = 7;
optional IrMultiFieldValueClassRepresentation multi_field_value_class_representation = 9;
repeated int64 sealed_subclass = 8 [packed=true];
}
@@ -621,3 +622,8 @@ message IrInlineClassRepresentation {
required int32 underlying_property_name = 1;
required int32 underlying_property_type = 2;
}
message IrMultiFieldValueClassRepresentation {
repeated int32 underlying_property_name = 1 [packed=true];
repeated int32 underlying_property_type = 2 [packed=true];
}
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.backend.common.serialization.proto.IrType.KindCase.*
import org.jetbrains.kotlin.descriptors.ClassKind
import org.jetbrains.kotlin.descriptors.InlineClassRepresentation
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.descriptors.MultiFieldValueClassRepresentation
import org.jetbrains.kotlin.ir.IrBuiltIns
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.declarations.*
@@ -23,7 +24,6 @@ import org.jetbrains.kotlin.ir.expressions.*
import org.jetbrains.kotlin.ir.expressions.impl.IrCompositeImpl
import org.jetbrains.kotlin.ir.symbols.*
import org.jetbrains.kotlin.ir.symbols.impl.IrPublicSymbolBase
import org.jetbrains.kotlin.ir.symbols.impl.IrTypeParameterPublicSymbolImpl
import org.jetbrains.kotlin.ir.symbols.impl.IrTypeParameterSymbolImpl
import org.jetbrains.kotlin.ir.types.*
import org.jetbrains.kotlin.ir.types.impl.*
@@ -48,6 +48,7 @@ import org.jetbrains.kotlin.backend.common.serialization.proto.IrFunction as Pro
import org.jetbrains.kotlin.backend.common.serialization.proto.IrFunctionBase as ProtoFunctionBase
import org.jetbrains.kotlin.backend.common.serialization.proto.IrInlineClassRepresentation as ProtoIrInlineClassRepresentation
import org.jetbrains.kotlin.backend.common.serialization.proto.IrLocalDelegatedProperty as ProtoLocalDelegatedProperty
import org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation as ProtoIrMultiFieldValueClassRepresentation
import org.jetbrains.kotlin.backend.common.serialization.proto.IrProperty as ProtoProperty
import org.jetbrains.kotlin.backend.common.serialization.proto.IrSimpleType as ProtoSimpleType
import org.jetbrains.kotlin.backend.common.serialization.proto.IrStatement as ProtoStatement
@@ -347,14 +348,16 @@ class IrDeclarationDeserializer(
thisReceiver = deserializeIrValueParameter(proto.thisReceiver, -1)
inlineClassRepresentation = when {
!(flags.isValue && primaryConstructor?.valueParameters?.size == 1) -> null
valueClassRepresentation = when {
!flags.isValue -> null
proto.hasMultiFieldValueClassRepresentation() && proto.hasInlineClassRepresentation() ->
error("Class cannot be both inline and multi-field value: $name")
proto.hasInlineClassRepresentation() -> deserializeInlineClassRepresentation(proto.inlineClassRepresentation)
proto.hasMultiFieldValueClassRepresentation() ->
deserializeMultiFieldValueClassRepresentation(proto.multiFieldValueClassRepresentation)
else -> computeMissingInlineClassRepresentationForCompatibility(this)
}
// todo something when value classes
sealedSubclasses = proto.sealedSubclassList.map { deserializeIrSymbol(it) as IrClassSymbol }
fakeOverrideBuilder.enqueueClass(this, signature, compatibilityMode)
@@ -367,6 +370,12 @@ class IrDeclarationDeserializer(
deserializeIrType(proto.underlyingPropertyType) as IrSimpleType,
)
private fun deserializeMultiFieldValueClassRepresentation(proto: ProtoIrMultiFieldValueClassRepresentation): MultiFieldValueClassRepresentation<IrSimpleType> {
val names = proto.underlyingPropertyNameList.map { deserializeName(it) }
val types = proto.underlyingPropertyTypeList.map { deserializeIrType(it) as IrSimpleType }
return MultiFieldValueClassRepresentation(names zip types)
}
private fun computeMissingInlineClassRepresentationForCompatibility(irClass: IrClass): InlineClassRepresentation<IrSimpleType> {
// For inline classes compiled with 1.5.20 or earlier, try to reconstruct inline class representation from the single parameter of
// the primary constructor. Something similar is happening in `DeserializedClassDescriptor.computeInlineClassRepresentation`.
@@ -6,10 +6,7 @@
package org.jetbrains.kotlin.backend.common.serialization
import org.jetbrains.kotlin.backend.common.serialization.encodings.*
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
import org.jetbrains.kotlin.descriptors.InlineClassRepresentation
import org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.IrFileEntry
import org.jetbrains.kotlin.ir.declarations.*
@@ -83,6 +80,7 @@ import org.jetbrains.kotlin.backend.common.serialization.proto.IrInlineClassRepr
import org.jetbrains.kotlin.backend.common.serialization.proto.IrInstanceInitializerCall as ProtoInstanceInitializerCall
import org.jetbrains.kotlin.backend.common.serialization.proto.IrLocalDelegatedProperty as ProtoLocalDelegatedProperty
import org.jetbrains.kotlin.backend.common.serialization.proto.IrLocalDelegatedPropertyReference as ProtoLocalDelegatedPropertyReference
import org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation as ProtoIrMultiFieldValueClassRepresentation
import org.jetbrains.kotlin.backend.common.serialization.proto.IrOperation as ProtoOperation
import org.jetbrains.kotlin.backend.common.serialization.proto.IrProperty as ProtoProperty
import org.jetbrains.kotlin.backend.common.serialization.proto.IrPropertyReference as ProtoPropertyReference
@@ -1031,7 +1029,8 @@ open class IrFileSerializer(
is IrGetEnumValue -> operationProto.getEnumValue = serializeGetEnumValue(expression)
is IrGetObjectValue -> operationProto.getObject = serializeGetObject(expression)
is IrInstanceInitializerCall -> operationProto.instanceInitializerCall = serializeInstanceInitializerCall(expression)
is IrLocalDelegatedPropertyReference -> operationProto.localDelegatedPropertyReference = serializeIrLocalDelegatedPropertyReference(expression)
is IrLocalDelegatedPropertyReference -> operationProto.localDelegatedPropertyReference =
serializeIrLocalDelegatedPropertyReference(expression)
is IrPropertyReference -> operationProto.propertyReference = serializePropertyReference(expression)
is IrReturn -> serializeReturn(operationProto, expression)
is IrSetField -> operationProto.setField = serializeSetField(expression)
@@ -1234,9 +1233,12 @@ open class IrFileSerializer(
.setBase(serializeIrDeclarationBase(clazz, ClassFlags.encode(clazz)))
.setName(serializeName(clazz.name))
val representation = clazz.inlineClassRepresentation
if (representation != null) {
proto.inlineClassRepresentation = serializeInlineClassRepresentation(representation)
when (val representation = clazz.valueClassRepresentation) {
is MultiFieldValueClassRepresentation ->
proto.multiFieldValueClassRepresentation = serializeMultiFieldValueClassRepresentation(representation)
is InlineClassRepresentation -> proto.inlineClassRepresentation = serializeInlineClassRepresentation(representation)
null -> Unit
}
clazz.declarations.forEach {
@@ -1267,6 +1269,12 @@ open class IrFileSerializer(
underlyingPropertyType = serializeIrType(representation.underlyingType)
}.build()
private fun serializeMultiFieldValueClassRepresentation(representation: MultiFieldValueClassRepresentation<IrSimpleType>): ProtoIrMultiFieldValueClassRepresentation =
ProtoIrMultiFieldValueClassRepresentation.newBuilder().apply {
addAllUnderlyingPropertyName(representation.underlyingPropertyNamesToTypes.map { (name, _) -> serializeName(name) })
addAllUnderlyingPropertyType(representation.underlyingPropertyNamesToTypes.map { (_, irType) -> serializeIrType(irType) })
}.build()
private fun serializeIrTypeAlias(typeAlias: IrTypeAlias): ProtoTypeAlias {
val proto = ProtoTypeAlias.newBuilder()
@@ -135,9 +135,9 @@ public final class IrClass extends
break;
}
case 64: {
if (!((mutable_bitField0_ & 0x00000080) == 0x00000080)) {
if (!((mutable_bitField0_ & 0x00000100) == 0x00000100)) {
sealedSubclass_ = new java.util.ArrayList<java.lang.Long>();
mutable_bitField0_ |= 0x00000080;
mutable_bitField0_ |= 0x00000100;
}
sealedSubclass_.add(input.readInt64());
break;
@@ -145,9 +145,9 @@ public final class IrClass extends
case 66: {
int length = input.readRawVarint32();
int limit = input.pushLimit(length);
if (!((mutable_bitField0_ & 0x00000080) == 0x00000080) && input.getBytesUntilLimit() > 0) {
if (!((mutable_bitField0_ & 0x00000100) == 0x00000100) && input.getBytesUntilLimit() > 0) {
sealedSubclass_ = new java.util.ArrayList<java.lang.Long>();
mutable_bitField0_ |= 0x00000080;
mutable_bitField0_ |= 0x00000100;
}
while (input.getBytesUntilLimit() > 0) {
sealedSubclass_.add(input.readInt64());
@@ -155,6 +155,19 @@ public final class IrClass extends
input.popLimit(limit);
break;
}
case 74: {
org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation.Builder subBuilder = null;
if (((bitField0_ & 0x00000010) == 0x00000010)) {
subBuilder = multiFieldValueClassRepresentation_.toBuilder();
}
multiFieldValueClassRepresentation_ = input.readMessage(org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation.PARSER, extensionRegistry);
if (subBuilder != null) {
subBuilder.mergeFrom(multiFieldValueClassRepresentation_);
multiFieldValueClassRepresentation_ = subBuilder.buildPartial();
}
bitField0_ |= 0x00000010;
break;
}
}
}
} catch (org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException e) {
@@ -172,7 +185,7 @@ public final class IrClass extends
if (((mutable_bitField0_ & 0x00000020) == 0x00000020)) {
superType_ = java.util.Collections.unmodifiableList(superType_);
}
if (((mutable_bitField0_ & 0x00000080) == 0x00000080)) {
if (((mutable_bitField0_ & 0x00000100) == 0x00000100)) {
sealedSubclass_ = java.util.Collections.unmodifiableList(sealedSubclass_);
}
try {
@@ -354,6 +367,21 @@ public final class IrClass extends
return inlineClassRepresentation_;
}
public static final int MULTI_FIELD_VALUE_CLASS_REPRESENTATION_FIELD_NUMBER = 9;
private org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation multiFieldValueClassRepresentation_;
/**
* <code>optional .org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation multi_field_value_class_representation = 9;</code>
*/
public boolean hasMultiFieldValueClassRepresentation() {
return ((bitField0_ & 0x00000010) == 0x00000010);
}
/**
* <code>optional .org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation multi_field_value_class_representation = 9;</code>
*/
public org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation getMultiFieldValueClassRepresentation() {
return multiFieldValueClassRepresentation_;
}
public static final int SEALED_SUBCLASS_FIELD_NUMBER = 8;
private java.util.List<java.lang.Long> sealedSubclass_;
/**
@@ -385,6 +413,7 @@ public final class IrClass extends
declaration_ = java.util.Collections.emptyList();
superType_ = java.util.Collections.emptyList();
inlineClassRepresentation_ = org.jetbrains.kotlin.backend.common.serialization.proto.IrInlineClassRepresentation.getDefaultInstance();
multiFieldValueClassRepresentation_ = org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation.getDefaultInstance();
sealedSubclass_ = java.util.Collections.emptyList();
}
private byte memoizedIsInitialized = -1;
@@ -468,6 +497,9 @@ public final class IrClass extends
for (int i = 0; i < sealedSubclass_.size(); i++) {
output.writeInt64NoTag(sealedSubclass_.get(i));
}
if (((bitField0_ & 0x00000010) == 0x00000010)) {
output.writeMessage(9, multiFieldValueClassRepresentation_);
}
output.writeRawBytes(unknownFields);
}
@@ -529,6 +561,10 @@ public final class IrClass extends
}
sealedSubclassMemoizedSerializedSize = dataSize;
}
if (((bitField0_ & 0x00000010) == 0x00000010)) {
size += org.jetbrains.kotlin.protobuf.CodedOutputStream
.computeMessageSize(9, multiFieldValueClassRepresentation_);
}
size += unknownFields.size();
memoizedSerializedSize = size;
return size;
@@ -637,8 +673,10 @@ public final class IrClass extends
bitField0_ = (bitField0_ & ~0x00000020);
inlineClassRepresentation_ = org.jetbrains.kotlin.backend.common.serialization.proto.IrInlineClassRepresentation.getDefaultInstance();
bitField0_ = (bitField0_ & ~0x00000040);
sealedSubclass_ = java.util.Collections.emptyList();
multiFieldValueClassRepresentation_ = org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation.getDefaultInstance();
bitField0_ = (bitField0_ & ~0x00000080);
sealedSubclass_ = java.util.Collections.emptyList();
bitField0_ = (bitField0_ & ~0x00000100);
return this;
}
@@ -693,9 +731,13 @@ public final class IrClass extends
to_bitField0_ |= 0x00000008;
}
result.inlineClassRepresentation_ = inlineClassRepresentation_;
if (((bitField0_ & 0x00000080) == 0x00000080)) {
if (((from_bitField0_ & 0x00000080) == 0x00000080)) {
to_bitField0_ |= 0x00000010;
}
result.multiFieldValueClassRepresentation_ = multiFieldValueClassRepresentation_;
if (((bitField0_ & 0x00000100) == 0x00000100)) {
sealedSubclass_ = java.util.Collections.unmodifiableList(sealedSubclass_);
bitField0_ = (bitField0_ & ~0x00000080);
bitField0_ = (bitField0_ & ~0x00000100);
}
result.sealedSubclass_ = sealedSubclass_;
result.bitField0_ = to_bitField0_;
@@ -746,10 +788,13 @@ public final class IrClass extends
if (other.hasInlineClassRepresentation()) {
mergeInlineClassRepresentation(other.getInlineClassRepresentation());
}
if (other.hasMultiFieldValueClassRepresentation()) {
mergeMultiFieldValueClassRepresentation(other.getMultiFieldValueClassRepresentation());
}
if (!other.sealedSubclass_.isEmpty()) {
if (sealedSubclass_.isEmpty()) {
sealedSubclass_ = other.sealedSubclass_;
bitField0_ = (bitField0_ & ~0x00000080);
bitField0_ = (bitField0_ & ~0x00000100);
} else {
ensureSealedSubclassIsMutable();
sealedSubclass_.addAll(other.sealedSubclass_);
@@ -1348,11 +1393,71 @@ public final class IrClass extends
return this;
}
private org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation multiFieldValueClassRepresentation_ = org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation.getDefaultInstance();
/**
* <code>optional .org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation multi_field_value_class_representation = 9;</code>
*/
public boolean hasMultiFieldValueClassRepresentation() {
return ((bitField0_ & 0x00000080) == 0x00000080);
}
/**
* <code>optional .org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation multi_field_value_class_representation = 9;</code>
*/
public org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation getMultiFieldValueClassRepresentation() {
return multiFieldValueClassRepresentation_;
}
/**
* <code>optional .org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation multi_field_value_class_representation = 9;</code>
*/
public Builder setMultiFieldValueClassRepresentation(org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation value) {
if (value == null) {
throw new NullPointerException();
}
multiFieldValueClassRepresentation_ = value;
bitField0_ |= 0x00000080;
return this;
}
/**
* <code>optional .org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation multi_field_value_class_representation = 9;</code>
*/
public Builder setMultiFieldValueClassRepresentation(
org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation.Builder builderForValue) {
multiFieldValueClassRepresentation_ = builderForValue.build();
bitField0_ |= 0x00000080;
return this;
}
/**
* <code>optional .org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation multi_field_value_class_representation = 9;</code>
*/
public Builder mergeMultiFieldValueClassRepresentation(org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation value) {
if (((bitField0_ & 0x00000080) == 0x00000080) &&
multiFieldValueClassRepresentation_ != org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation.getDefaultInstance()) {
multiFieldValueClassRepresentation_ =
org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation.newBuilder(multiFieldValueClassRepresentation_).mergeFrom(value).buildPartial();
} else {
multiFieldValueClassRepresentation_ = value;
}
bitField0_ |= 0x00000080;
return this;
}
/**
* <code>optional .org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation multi_field_value_class_representation = 9;</code>
*/
public Builder clearMultiFieldValueClassRepresentation() {
multiFieldValueClassRepresentation_ = org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation.getDefaultInstance();
bitField0_ = (bitField0_ & ~0x00000080);
return this;
}
private java.util.List<java.lang.Long> sealedSubclass_ = java.util.Collections.emptyList();
private void ensureSealedSubclassIsMutable() {
if (!((bitField0_ & 0x00000080) == 0x00000080)) {
if (!((bitField0_ & 0x00000100) == 0x00000100)) {
sealedSubclass_ = new java.util.ArrayList<java.lang.Long>(sealedSubclass_);
bitField0_ |= 0x00000080;
bitField0_ |= 0x00000100;
}
}
/**
@@ -1409,7 +1514,7 @@ public final class IrClass extends
*/
public Builder clearSealedSubclass() {
sealedSubclass_ = java.util.Collections.emptyList();
bitField0_ = (bitField0_ & ~0x00000080);
bitField0_ = (bitField0_ & ~0x00000100);
return this;
}
@@ -84,6 +84,15 @@ public interface IrClassOrBuilder extends
*/
org.jetbrains.kotlin.backend.common.serialization.proto.IrInlineClassRepresentation getInlineClassRepresentation();
/**
* <code>optional .org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation multi_field_value_class_representation = 9;</code>
*/
boolean hasMultiFieldValueClassRepresentation();
/**
* <code>optional .org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation multi_field_value_class_representation = 9;</code>
*/
org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation getMultiFieldValueClassRepresentation();
/**
* <code>repeated int64 sealed_subclass = 8 [packed = true];</code>
*/
@@ -0,0 +1,575 @@
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: compiler/ir/serialization.common/src/KotlinIr.proto
package org.jetbrains.kotlin.backend.common.serialization.proto;
/**
* Protobuf type {@code org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation}
*/
public final class IrMultiFieldValueClassRepresentation extends
org.jetbrains.kotlin.protobuf.GeneratedMessageLite implements
// @@protoc_insertion_point(message_implements:org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation)
IrMultiFieldValueClassRepresentationOrBuilder {
// Use IrMultiFieldValueClassRepresentation.newBuilder() to construct.
private IrMultiFieldValueClassRepresentation(org.jetbrains.kotlin.protobuf.GeneratedMessageLite.Builder builder) {
super(builder);
this.unknownFields = builder.getUnknownFields();
}
private IrMultiFieldValueClassRepresentation(boolean noInit) { this.unknownFields = org.jetbrains.kotlin.protobuf.ByteString.EMPTY;}
private static final IrMultiFieldValueClassRepresentation defaultInstance;
public static IrMultiFieldValueClassRepresentation getDefaultInstance() {
return defaultInstance;
}
public IrMultiFieldValueClassRepresentation getDefaultInstanceForType() {
return defaultInstance;
}
private final org.jetbrains.kotlin.protobuf.ByteString unknownFields;
private IrMultiFieldValueClassRepresentation(
org.jetbrains.kotlin.protobuf.CodedInputStream input,
org.jetbrains.kotlin.protobuf.ExtensionRegistryLite extensionRegistry)
throws org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException {
initFields();
int mutable_bitField0_ = 0;
org.jetbrains.kotlin.protobuf.ByteString.Output unknownFieldsOutput =
org.jetbrains.kotlin.protobuf.ByteString.newOutput();
org.jetbrains.kotlin.protobuf.CodedOutputStream unknownFieldsCodedOutput =
org.jetbrains.kotlin.protobuf.CodedOutputStream.newInstance(
unknownFieldsOutput, 1);
try {
boolean done = false;
while (!done) {
int tag = input.readTag();
switch (tag) {
case 0:
done = true;
break;
default: {
if (!parseUnknownField(input, unknownFieldsCodedOutput,
extensionRegistry, tag)) {
done = true;
}
break;
}
case 8: {
if (!((mutable_bitField0_ & 0x00000001) == 0x00000001)) {
underlyingPropertyName_ = new java.util.ArrayList<java.lang.Integer>();
mutable_bitField0_ |= 0x00000001;
}
underlyingPropertyName_.add(input.readInt32());
break;
}
case 10: {
int length = input.readRawVarint32();
int limit = input.pushLimit(length);
if (!((mutable_bitField0_ & 0x00000001) == 0x00000001) && input.getBytesUntilLimit() > 0) {
underlyingPropertyName_ = new java.util.ArrayList<java.lang.Integer>();
mutable_bitField0_ |= 0x00000001;
}
while (input.getBytesUntilLimit() > 0) {
underlyingPropertyName_.add(input.readInt32());
}
input.popLimit(limit);
break;
}
case 16: {
if (!((mutable_bitField0_ & 0x00000002) == 0x00000002)) {
underlyingPropertyType_ = new java.util.ArrayList<java.lang.Integer>();
mutable_bitField0_ |= 0x00000002;
}
underlyingPropertyType_.add(input.readInt32());
break;
}
case 18: {
int length = input.readRawVarint32();
int limit = input.pushLimit(length);
if (!((mutable_bitField0_ & 0x00000002) == 0x00000002) && input.getBytesUntilLimit() > 0) {
underlyingPropertyType_ = new java.util.ArrayList<java.lang.Integer>();
mutable_bitField0_ |= 0x00000002;
}
while (input.getBytesUntilLimit() > 0) {
underlyingPropertyType_.add(input.readInt32());
}
input.popLimit(limit);
break;
}
}
}
} catch (org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException e) {
throw e.setUnfinishedMessage(this);
} catch (java.io.IOException e) {
throw new org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException(
e.getMessage()).setUnfinishedMessage(this);
} finally {
if (((mutable_bitField0_ & 0x00000001) == 0x00000001)) {
underlyingPropertyName_ = java.util.Collections.unmodifiableList(underlyingPropertyName_);
}
if (((mutable_bitField0_ & 0x00000002) == 0x00000002)) {
underlyingPropertyType_ = java.util.Collections.unmodifiableList(underlyingPropertyType_);
}
try {
unknownFieldsCodedOutput.flush();
} catch (java.io.IOException e) {
// Should not happen
} finally {
unknownFields = unknownFieldsOutput.toByteString();
}
makeExtensionsImmutable();
}
}
public static org.jetbrains.kotlin.protobuf.Parser<IrMultiFieldValueClassRepresentation> PARSER =
new org.jetbrains.kotlin.protobuf.AbstractParser<IrMultiFieldValueClassRepresentation>() {
public IrMultiFieldValueClassRepresentation parsePartialFrom(
org.jetbrains.kotlin.protobuf.CodedInputStream input,
org.jetbrains.kotlin.protobuf.ExtensionRegistryLite extensionRegistry)
throws org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException {
return new IrMultiFieldValueClassRepresentation(input, extensionRegistry);
}
};
@java.lang.Override
public org.jetbrains.kotlin.protobuf.Parser<IrMultiFieldValueClassRepresentation> getParserForType() {
return PARSER;
}
public static final int UNDERLYING_PROPERTY_NAME_FIELD_NUMBER = 1;
private java.util.List<java.lang.Integer> underlyingPropertyName_;
/**
* <code>repeated int32 underlying_property_name = 1 [packed = true];</code>
*/
public java.util.List<java.lang.Integer>
getUnderlyingPropertyNameList() {
return underlyingPropertyName_;
}
/**
* <code>repeated int32 underlying_property_name = 1 [packed = true];</code>
*/
public int getUnderlyingPropertyNameCount() {
return underlyingPropertyName_.size();
}
/**
* <code>repeated int32 underlying_property_name = 1 [packed = true];</code>
*/
public int getUnderlyingPropertyName(int index) {
return underlyingPropertyName_.get(index);
}
private int underlyingPropertyNameMemoizedSerializedSize = -1;
public static final int UNDERLYING_PROPERTY_TYPE_FIELD_NUMBER = 2;
private java.util.List<java.lang.Integer> underlyingPropertyType_;
/**
* <code>repeated int32 underlying_property_type = 2 [packed = true];</code>
*/
public java.util.List<java.lang.Integer>
getUnderlyingPropertyTypeList() {
return underlyingPropertyType_;
}
/**
* <code>repeated int32 underlying_property_type = 2 [packed = true];</code>
*/
public int getUnderlyingPropertyTypeCount() {
return underlyingPropertyType_.size();
}
/**
* <code>repeated int32 underlying_property_type = 2 [packed = true];</code>
*/
public int getUnderlyingPropertyType(int index) {
return underlyingPropertyType_.get(index);
}
private int underlyingPropertyTypeMemoizedSerializedSize = -1;
private void initFields() {
underlyingPropertyName_ = java.util.Collections.emptyList();
underlyingPropertyType_ = java.util.Collections.emptyList();
}
private byte memoizedIsInitialized = -1;
public final boolean isInitialized() {
byte isInitialized = memoizedIsInitialized;
if (isInitialized == 1) return true;
if (isInitialized == 0) return false;
memoizedIsInitialized = 1;
return true;
}
public void writeTo(org.jetbrains.kotlin.protobuf.CodedOutputStream output)
throws java.io.IOException {
getSerializedSize();
if (getUnderlyingPropertyNameList().size() > 0) {
output.writeRawVarint32(10);
output.writeRawVarint32(underlyingPropertyNameMemoizedSerializedSize);
}
for (int i = 0; i < underlyingPropertyName_.size(); i++) {
output.writeInt32NoTag(underlyingPropertyName_.get(i));
}
if (getUnderlyingPropertyTypeList().size() > 0) {
output.writeRawVarint32(18);
output.writeRawVarint32(underlyingPropertyTypeMemoizedSerializedSize);
}
for (int i = 0; i < underlyingPropertyType_.size(); i++) {
output.writeInt32NoTag(underlyingPropertyType_.get(i));
}
output.writeRawBytes(unknownFields);
}
private int memoizedSerializedSize = -1;
public int getSerializedSize() {
int size = memoizedSerializedSize;
if (size != -1) return size;
size = 0;
{
int dataSize = 0;
for (int i = 0; i < underlyingPropertyName_.size(); i++) {
dataSize += org.jetbrains.kotlin.protobuf.CodedOutputStream
.computeInt32SizeNoTag(underlyingPropertyName_.get(i));
}
size += dataSize;
if (!getUnderlyingPropertyNameList().isEmpty()) {
size += 1;
size += org.jetbrains.kotlin.protobuf.CodedOutputStream
.computeInt32SizeNoTag(dataSize);
}
underlyingPropertyNameMemoizedSerializedSize = dataSize;
}
{
int dataSize = 0;
for (int i = 0; i < underlyingPropertyType_.size(); i++) {
dataSize += org.jetbrains.kotlin.protobuf.CodedOutputStream
.computeInt32SizeNoTag(underlyingPropertyType_.get(i));
}
size += dataSize;
if (!getUnderlyingPropertyTypeList().isEmpty()) {
size += 1;
size += org.jetbrains.kotlin.protobuf.CodedOutputStream
.computeInt32SizeNoTag(dataSize);
}
underlyingPropertyTypeMemoizedSerializedSize = dataSize;
}
size += unknownFields.size();
memoizedSerializedSize = size;
return size;
}
private static final long serialVersionUID = 0L;
@java.lang.Override
protected java.lang.Object writeReplace()
throws java.io.ObjectStreamException {
return super.writeReplace();
}
public static org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation parseFrom(
org.jetbrains.kotlin.protobuf.ByteString data)
throws org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation parseFrom(
org.jetbrains.kotlin.protobuf.ByteString data,
org.jetbrains.kotlin.protobuf.ExtensionRegistryLite extensionRegistry)
throws org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation parseFrom(byte[] data)
throws org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation parseFrom(
byte[] data,
org.jetbrains.kotlin.protobuf.ExtensionRegistryLite extensionRegistry)
throws org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation parseFrom(java.io.InputStream input)
throws java.io.IOException {
return PARSER.parseFrom(input);
}
public static org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation parseFrom(
java.io.InputStream input,
org.jetbrains.kotlin.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return PARSER.parseFrom(input, extensionRegistry);
}
public static org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation parseDelimitedFrom(java.io.InputStream input)
throws java.io.IOException {
return PARSER.parseDelimitedFrom(input);
}
public static org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation parseDelimitedFrom(
java.io.InputStream input,
org.jetbrains.kotlin.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return PARSER.parseDelimitedFrom(input, extensionRegistry);
}
public static org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation parseFrom(
org.jetbrains.kotlin.protobuf.CodedInputStream input)
throws java.io.IOException {
return PARSER.parseFrom(input);
}
public static org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation parseFrom(
org.jetbrains.kotlin.protobuf.CodedInputStream input,
org.jetbrains.kotlin.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return PARSER.parseFrom(input, extensionRegistry);
}
public static Builder newBuilder() { return Builder.create(); }
public Builder newBuilderForType() { return newBuilder(); }
public static Builder newBuilder(org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation prototype) {
return newBuilder().mergeFrom(prototype);
}
public Builder toBuilder() { return newBuilder(this); }
/**
* Protobuf type {@code org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation}
*/
public static final class Builder extends
org.jetbrains.kotlin.protobuf.GeneratedMessageLite.Builder<
org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation, Builder>
implements
// @@protoc_insertion_point(builder_implements:org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation)
org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentationOrBuilder {
// Construct using org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation.newBuilder()
private Builder() {
maybeForceBuilderInitialization();
}
private void maybeForceBuilderInitialization() {
}
private static Builder create() {
return new Builder();
}
public Builder clear() {
super.clear();
underlyingPropertyName_ = java.util.Collections.emptyList();
bitField0_ = (bitField0_ & ~0x00000001);
underlyingPropertyType_ = java.util.Collections.emptyList();
bitField0_ = (bitField0_ & ~0x00000002);
return this;
}
public Builder clone() {
return create().mergeFrom(buildPartial());
}
public org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation getDefaultInstanceForType() {
return org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation.getDefaultInstance();
}
public org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation build() {
org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation result = buildPartial();
if (!result.isInitialized()) {
throw newUninitializedMessageException(result);
}
return result;
}
public org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation buildPartial() {
org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation result = new org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation(this);
int from_bitField0_ = bitField0_;
if (((bitField0_ & 0x00000001) == 0x00000001)) {
underlyingPropertyName_ = java.util.Collections.unmodifiableList(underlyingPropertyName_);
bitField0_ = (bitField0_ & ~0x00000001);
}
result.underlyingPropertyName_ = underlyingPropertyName_;
if (((bitField0_ & 0x00000002) == 0x00000002)) {
underlyingPropertyType_ = java.util.Collections.unmodifiableList(underlyingPropertyType_);
bitField0_ = (bitField0_ & ~0x00000002);
}
result.underlyingPropertyType_ = underlyingPropertyType_;
return result;
}
public Builder mergeFrom(org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation other) {
if (other == org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation.getDefaultInstance()) return this;
if (!other.underlyingPropertyName_.isEmpty()) {
if (underlyingPropertyName_.isEmpty()) {
underlyingPropertyName_ = other.underlyingPropertyName_;
bitField0_ = (bitField0_ & ~0x00000001);
} else {
ensureUnderlyingPropertyNameIsMutable();
underlyingPropertyName_.addAll(other.underlyingPropertyName_);
}
}
if (!other.underlyingPropertyType_.isEmpty()) {
if (underlyingPropertyType_.isEmpty()) {
underlyingPropertyType_ = other.underlyingPropertyType_;
bitField0_ = (bitField0_ & ~0x00000002);
} else {
ensureUnderlyingPropertyTypeIsMutable();
underlyingPropertyType_.addAll(other.underlyingPropertyType_);
}
}
setUnknownFields(
getUnknownFields().concat(other.unknownFields));
return this;
}
public final boolean isInitialized() {
return true;
}
public Builder mergeFrom(
org.jetbrains.kotlin.protobuf.CodedInputStream input,
org.jetbrains.kotlin.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation parsedMessage = null;
try {
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
} catch (org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException e) {
parsedMessage = (org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation) e.getUnfinishedMessage();
throw e;
} finally {
if (parsedMessage != null) {
mergeFrom(parsedMessage);
}
}
return this;
}
private int bitField0_;
private java.util.List<java.lang.Integer> underlyingPropertyName_ = java.util.Collections.emptyList();
private void ensureUnderlyingPropertyNameIsMutable() {
if (!((bitField0_ & 0x00000001) == 0x00000001)) {
underlyingPropertyName_ = new java.util.ArrayList<java.lang.Integer>(underlyingPropertyName_);
bitField0_ |= 0x00000001;
}
}
/**
* <code>repeated int32 underlying_property_name = 1 [packed = true];</code>
*/
public java.util.List<java.lang.Integer>
getUnderlyingPropertyNameList() {
return java.util.Collections.unmodifiableList(underlyingPropertyName_);
}
/**
* <code>repeated int32 underlying_property_name = 1 [packed = true];</code>
*/
public int getUnderlyingPropertyNameCount() {
return underlyingPropertyName_.size();
}
/**
* <code>repeated int32 underlying_property_name = 1 [packed = true];</code>
*/
public int getUnderlyingPropertyName(int index) {
return underlyingPropertyName_.get(index);
}
/**
* <code>repeated int32 underlying_property_name = 1 [packed = true];</code>
*/
public Builder setUnderlyingPropertyName(
int index, int value) {
ensureUnderlyingPropertyNameIsMutable();
underlyingPropertyName_.set(index, value);
return this;
}
/**
* <code>repeated int32 underlying_property_name = 1 [packed = true];</code>
*/
public Builder addUnderlyingPropertyName(int value) {
ensureUnderlyingPropertyNameIsMutable();
underlyingPropertyName_.add(value);
return this;
}
/**
* <code>repeated int32 underlying_property_name = 1 [packed = true];</code>
*/
public Builder addAllUnderlyingPropertyName(
java.lang.Iterable<? extends java.lang.Integer> values) {
ensureUnderlyingPropertyNameIsMutable();
org.jetbrains.kotlin.protobuf.AbstractMessageLite.Builder.addAll(
values, underlyingPropertyName_);
return this;
}
/**
* <code>repeated int32 underlying_property_name = 1 [packed = true];</code>
*/
public Builder clearUnderlyingPropertyName() {
underlyingPropertyName_ = java.util.Collections.emptyList();
bitField0_ = (bitField0_ & ~0x00000001);
return this;
}
private java.util.List<java.lang.Integer> underlyingPropertyType_ = java.util.Collections.emptyList();
private void ensureUnderlyingPropertyTypeIsMutable() {
if (!((bitField0_ & 0x00000002) == 0x00000002)) {
underlyingPropertyType_ = new java.util.ArrayList<java.lang.Integer>(underlyingPropertyType_);
bitField0_ |= 0x00000002;
}
}
/**
* <code>repeated int32 underlying_property_type = 2 [packed = true];</code>
*/
public java.util.List<java.lang.Integer>
getUnderlyingPropertyTypeList() {
return java.util.Collections.unmodifiableList(underlyingPropertyType_);
}
/**
* <code>repeated int32 underlying_property_type = 2 [packed = true];</code>
*/
public int getUnderlyingPropertyTypeCount() {
return underlyingPropertyType_.size();
}
/**
* <code>repeated int32 underlying_property_type = 2 [packed = true];</code>
*/
public int getUnderlyingPropertyType(int index) {
return underlyingPropertyType_.get(index);
}
/**
* <code>repeated int32 underlying_property_type = 2 [packed = true];</code>
*/
public Builder setUnderlyingPropertyType(
int index, int value) {
ensureUnderlyingPropertyTypeIsMutable();
underlyingPropertyType_.set(index, value);
return this;
}
/**
* <code>repeated int32 underlying_property_type = 2 [packed = true];</code>
*/
public Builder addUnderlyingPropertyType(int value) {
ensureUnderlyingPropertyTypeIsMutable();
underlyingPropertyType_.add(value);
return this;
}
/**
* <code>repeated int32 underlying_property_type = 2 [packed = true];</code>
*/
public Builder addAllUnderlyingPropertyType(
java.lang.Iterable<? extends java.lang.Integer> values) {
ensureUnderlyingPropertyTypeIsMutable();
org.jetbrains.kotlin.protobuf.AbstractMessageLite.Builder.addAll(
values, underlyingPropertyType_);
return this;
}
/**
* <code>repeated int32 underlying_property_type = 2 [packed = true];</code>
*/
public Builder clearUnderlyingPropertyType() {
underlyingPropertyType_ = java.util.Collections.emptyList();
bitField0_ = (bitField0_ & ~0x00000002);
return this;
}
// @@protoc_insertion_point(builder_scope:org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation)
}
static {
defaultInstance = new IrMultiFieldValueClassRepresentation(true);
defaultInstance.initFields();
}
// @@protoc_insertion_point(class_scope:org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation)
}
@@ -0,0 +1,35 @@
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: compiler/ir/serialization.common/src/KotlinIr.proto
package org.jetbrains.kotlin.backend.common.serialization.proto;
public interface IrMultiFieldValueClassRepresentationOrBuilder extends
// @@protoc_insertion_point(interface_extends:org.jetbrains.kotlin.backend.common.serialization.proto.IrMultiFieldValueClassRepresentation)
org.jetbrains.kotlin.protobuf.MessageLiteOrBuilder {
/**
* <code>repeated int32 underlying_property_name = 1 [packed = true];</code>
*/
java.util.List<java.lang.Integer> getUnderlyingPropertyNameList();
/**
* <code>repeated int32 underlying_property_name = 1 [packed = true];</code>
*/
int getUnderlyingPropertyNameCount();
/**
* <code>repeated int32 underlying_property_name = 1 [packed = true];</code>
*/
int getUnderlyingPropertyName(int index);
/**
* <code>repeated int32 underlying_property_type = 2 [packed = true];</code>
*/
java.util.List<java.lang.Integer> getUnderlyingPropertyTypeList();
/**
* <code>repeated int32 underlying_property_type = 2 [packed = true];</code>
*/
int getUnderlyingPropertyTypeCount();
/**
* <code>repeated int32 underlying_property_type = 2 [packed = true];</code>
*/
int getUnderlyingPropertyType(int index);
}
@@ -31,6 +31,8 @@ import org.jetbrains.kotlin.resolve.constants.EnumValue
import org.jetbrains.kotlin.resolve.constants.IntValue
import org.jetbrains.kotlin.resolve.constants.NullValue
import org.jetbrains.kotlin.resolve.constants.StringValue
import org.jetbrains.kotlin.resolve.descriptorUtil.inlineClassRepresentation
import org.jetbrains.kotlin.resolve.descriptorUtil.multiFieldValueClassRepresentation
import org.jetbrains.kotlin.resolve.descriptorUtil.nonSourceAnnotations
import org.jetbrains.kotlin.serialization.deserialization.ProtoEnumFlags
import org.jetbrains.kotlin.serialization.deserialization.descriptorVisibility
@@ -92,7 +94,7 @@ class DescriptorSerializer private constructor(
ProtoEnumFlags.modality(classDescriptor.modality),
ProtoEnumFlags.classKind(classDescriptor.kind, classDescriptor.isCompanionObject),
classDescriptor.isInner, classDescriptor.isData, classDescriptor.isExternal, classDescriptor.isExpect,
classDescriptor.isInlineOrValueClass(), classDescriptor.isFun
classDescriptor.isValueClass(), classDescriptor.isFun
)
if (flags != builder.flags) {
builder.flags = flags
@@ -171,22 +173,31 @@ class DescriptorSerializer private constructor(
builder.companionObjectName = getSimpleNameIndex(companionObjectDescriptor.name)
}
val representation = classDescriptor.inlineClassRepresentation
if (representation != null) {
builder.inlineClassUnderlyingPropertyName = getSimpleNameIndex(representation.underlyingPropertyName)
classDescriptor.inlineClassRepresentation?.let { inlineClassRepresentation ->
builder.inlineClassUnderlyingPropertyName = getSimpleNameIndex(inlineClassRepresentation.underlyingPropertyName)
val property = callableMembers.single {
it is PropertyDescriptor && it.extensionReceiverParameter == null && it.name == representation.underlyingPropertyName
it is PropertyDescriptor && it.extensionReceiverParameter == null && it.name == inlineClassRepresentation.underlyingPropertyName
}
if (!property.visibility.isPublicAPI) {
if (useTypeTable()) {
builder.inlineClassUnderlyingTypeId = typeId(representation.underlyingType)
builder.inlineClassUnderlyingTypeId = typeId(inlineClassRepresentation.underlyingType)
} else {
builder.setInlineClassUnderlyingType(type(representation.underlyingType))
builder.setInlineClassUnderlyingType(type(inlineClassRepresentation.underlyingType))
}
}
}
classDescriptor.multiFieldValueClassRepresentation?.let { multiFieldValueClassRepresentation ->
val namesToTypes = multiFieldValueClassRepresentation.underlyingPropertyNamesToTypes
builder.addAllMultiFieldValueClassUnderlyingName(namesToTypes.map { (name, _) -> getSimpleNameIndex(name) })
if (useTypeTable()) {
builder.addAllMultiFieldValueClassUnderlyingTypeId(namesToTypes.map { (_, kotlinType) -> typeId(kotlinType) })
} else {
builder.addAllMultiFieldValueClassUnderlyingType(namesToTypes.map { (_, kotlinType) -> type(kotlinType).build() })
}
}
if (versionRequirementTable == null) error("Version requirements must be serialized for classes: $classDescriptor")
builder.addAllVersionRequirement(versionRequirementTable.serializeVersionRequirements(classDescriptor))
@@ -513,7 +524,8 @@ class DescriptorSerializer private constructor(
val builder = ProtoBuf.TypeAlias.newBuilder()
val local = createChildSerializer(descriptor)
val flags = Flags.getTypeAliasFlags(hasAnnotations(descriptor), ProtoEnumFlags.descriptorVisibility(normalizeVisibility(descriptor)))
val flags =
Flags.getTypeAliasFlags(hasAnnotations(descriptor), ProtoEnumFlags.descriptorVisibility(normalizeVisibility(descriptor)))
if (flags != builder.flags) {
builder.flags = flags
}
@@ -18,4 +18,4 @@ value class GreaterMFVC(val x: SimpleMFVC, val y: IC, val z: SimpleMFVC)
fun gmfvc(ic: IC, x: GreaterMFVC, ic1: UInt) = smfvc(ic, x.x, 0U) + ic(x.y) + smfvc(IC(0U), x.z, ic1)
fun box() = "todo"
fun box() = "OK" // todo real test
@@ -44,3 +44,4 @@ public inline object InlineObject {
public open override /*1*/ /*synthesized*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*synthesized*/ fun toString(): kotlin.String
}
@@ -57,3 +57,4 @@ package kotlin {
}
}
}
@@ -8,10 +8,15 @@ package org.jetbrains.kotlin.descriptors
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.types.model.SimpleTypeMarker
class InlineClassRepresentation<Type : SimpleTypeMarker>(
class InlineClassRepresentation<Type : SimpleTypeMarker> constructor(
val underlyingPropertyName: Name,
val underlyingType: Type,
) {
inline fun <Other : SimpleTypeMarker> mapUnderlyingType(transform: (Type) -> Other): InlineClassRepresentation<Other> =
InlineClassRepresentation(underlyingPropertyName, transform(underlyingType))
}
) : ValueClassRepresentation<Type>() {
override val underlyingPropertyNamesToTypes: List<Pair<Name, Type>>
get() = listOf(underlyingPropertyName to underlyingType)
override fun containsPropertyWithName(name: Name): Boolean = underlyingPropertyName == name
override fun propertyTypeByName(name: Name): Type? = underlyingType.takeIf { containsPropertyWithName(name) }
}
@@ -9,19 +9,13 @@ import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.types.model.SimpleTypeMarker
class MultiFieldValueClassRepresentation<Type : SimpleTypeMarker>(
val underlyingPropertyNamesToTypes: List<Pair<Name, Type>>
) {
init {
require(underlyingPropertyNamesToTypes.size > 1) { "MultiFieldValueClassRepresentation has at least 2 properties" }
}
override val underlyingPropertyNamesToTypes: List<Pair<Name, Type>>
) : ValueClassRepresentation<Type>() {
private val map = underlyingPropertyNamesToTypes.toMap().also {
require(it.size == underlyingPropertyNamesToTypes.size) { "Some properties have the same names" }
}
fun containsPropertyWithName(name: Name): Boolean = name in map
fun propertyTypeByName(name: Name): Type? = map[name]
inline fun <Other : SimpleTypeMarker> mapUnderlyingType(transform: (Type) -> Other): MultiFieldValueClassRepresentation<Other> =
MultiFieldValueClassRepresentation(underlyingPropertyNamesToTypes.map { (key, value) -> key to transform(value) })
override fun containsPropertyWithName(name: Name): Boolean = name in map
override fun propertyTypeByName(name: Name): Type? = map[name]
}
@@ -0,0 +1,49 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.descriptors
import org.jetbrains.kotlin.descriptors.ValueClassKind.Inline
import org.jetbrains.kotlin.descriptors.ValueClassKind.MultiField
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.types.TypeSystemCommonBackendContext
import org.jetbrains.kotlin.types.model.SimpleTypeMarker
sealed class ValueClassRepresentation<Type : SimpleTypeMarker> {
abstract val underlyingPropertyNamesToTypes: List<Pair<Name, Type>>
abstract fun containsPropertyWithName(name: Name): Boolean
abstract fun getPropertyTypeByName(name: Name): Type?
fun <Other : SimpleTypeMarker> mapUnderlyingType(transform: (Type) -> Other): ValueClassRepresentation<Other> = when (this) {
is InlineClassRepresentation -> InlineClassRepresentation(underlyingPropertyName, transform(underlyingType))
is MultiFieldValueClassRepresentation ->
MultiFieldValueClassRepresentation(underlyingPropertyNamesToTypes.map { (name, type) -> name to transform(type) })
}
}
enum class ValueClassKind { Inline, MultiField }
fun <Type : SimpleTypeMarker> TypeSystemCommonBackendContext.valueClassLoweringKind(
fields: List<Pair<Name, Type>>,
): ValueClassKind = when {
fields.size > 1 -> MultiField
fields.isEmpty() -> error("Value classes cannot have 0 fields")
else -> {
val type = fields.single().second
with(this) {
when {
type.isNullableType() -> Inline
!type.typeConstructor().isMultiFieldValueClass() -> Inline
else -> MultiField
}
}
}
}
fun <Type : SimpleTypeMarker> createValueClassRepresentation(context: TypeSystemCommonBackendContext, fields: List<Pair<Name, Type>>) =
when (context.valueClassLoweringKind(fields)) {
Inline -> InlineClassRepresentation(fields[0].first, fields[0].second)
MultiField -> MultiFieldValueClassRepresentation(fields)
}
@@ -31,6 +31,8 @@ interface TypeSystemCommonBackendContext : TypeSystemContext {
fun KotlinTypeMarker.getAnnotationFirstArgumentValue(fqName: FqName): Any?
fun TypeConstructorMarker.isInlineClass(): Boolean
fun TypeConstructorMarker.isMultiFieldValueClass(): Boolean
fun TypeConstructorMarker.valueClassRepresentationTypeMarkersList(): List<Pair<Name, SimpleTypeMarker>>?
fun TypeConstructorMarker.isInnerClass(): Boolean
fun TypeParameterMarker.getRepresentativeUpperBound(): KotlinTypeMarker
fun KotlinTypeMarker.getUnsubstitutedUnderlyingType(): KotlinTypeMarker?
@@ -196,9 +196,7 @@ class LazyJavaClassDescriptor(
emptyList()
}
override fun getInlineClassRepresentation(): InlineClassRepresentation<SimpleType>? = null
override fun getMultiFieldValueClassRepresentation(): MultiFieldValueClassRepresentation<SimpleType>? = null
override fun getValueClassRepresentation(): ValueClassRepresentation<SimpleType>? = null
override fun toString() = "Lazy Java class ${this.fqNameUnsafe}"
@@ -87,8 +87,7 @@ class FunctionClassDescriptor(
override val annotations: Annotations get() = Annotations.EMPTY
override fun getSource(): SourceElement = SourceElement.NO_SOURCE
override fun getSealedSubclasses() = emptyList<ClassDescriptor>()
override fun getInlineClassRepresentation(): InlineClassRepresentation<SimpleType>? = null
override fun getMultiFieldValueClassRepresentation(): MultiFieldValueClassRepresentation<SimpleType>? = null
override fun getValueClassRepresentation(): ValueClassRepresentation<SimpleType>? = null
override fun getDeclaredTypeParameters() = parameters
@@ -102,10 +102,7 @@ public interface ClassDescriptor extends ClassifierDescriptorWithTypeParameters,
Collection<ClassDescriptor> getSealedSubclasses();
@Nullable
InlineClassRepresentation<SimpleType> getInlineClassRepresentation();
@Nullable
MultiFieldValueClassRepresentation<SimpleType> getMultiFieldValueClassRepresentation();
ValueClassRepresentation<SimpleType> getValueClassRepresentation();
@NotNull
@Override
@@ -84,8 +84,7 @@ class NotFoundClasses(private val storageManager: StorageManager, private val mo
override fun getUnsubstitutedPrimaryConstructor(): ClassConstructorDescriptor? = null
override fun getCompanionObjectDescriptor(): ClassDescriptor? = null
override fun getSealedSubclasses(): Collection<ClassDescriptor> = emptyList()
override fun getInlineClassRepresentation(): InlineClassRepresentation<SimpleType>? = null
override fun getMultiFieldValueClassRepresentation(): MultiFieldValueClassRepresentation<SimpleType>? = null
override fun getValueClassRepresentation(): ValueClassRepresentation<SimpleType>? = null
override fun toString() = "class $name (not found)"
}
@@ -178,13 +178,7 @@ public class ClassDescriptorImpl extends ClassDescriptorBase {
@Nullable
@Override
public InlineClassRepresentation<SimpleType> getInlineClassRepresentation() {
return null;
}
@Nullable
@Override
public MultiFieldValueClassRepresentation<SimpleType> getMultiFieldValueClassRepresentation() {
public ValueClassRepresentation<SimpleType> getValueClassRepresentation() {
return null;
}
}
@@ -195,13 +195,7 @@ public class EnumEntrySyntheticClassDescriptor extends ClassDescriptorBase {
@Nullable
@Override
public InlineClassRepresentation<SimpleType> getInlineClassRepresentation() {
return null;
}
@Nullable
@Override
public MultiFieldValueClassRepresentation<SimpleType> getMultiFieldValueClassRepresentation() {
public ValueClassRepresentation<SimpleType> getValueClassRepresentation() {
return null;
}
@@ -324,30 +324,17 @@ public class LazySubstitutingClassDescriptor extends ModuleAwareClassDescriptor
@Nullable
@Override
public InlineClassRepresentation<SimpleType> getInlineClassRepresentation() {
InlineClassRepresentation<SimpleType> representation = original.getInlineClassRepresentation();
//noinspection ConstantConditions
return representation == null ? null : new InlineClassRepresentation<SimpleType>(
representation.getUnderlyingPropertyName(),
substituteSimpleType(representation.getUnderlyingType())
);
}
@Nullable
@Override
public MultiFieldValueClassRepresentation<SimpleType> getMultiFieldValueClassRepresentation() {
MultiFieldValueClassRepresentation<SimpleType> representation = original.getMultiFieldValueClassRepresentation();
public ValueClassRepresentation<SimpleType> getValueClassRepresentation() {
ValueClassRepresentation<SimpleType> representation = original.getValueClassRepresentation();
if (representation == null) {
return null;
}
List<Pair<Name, SimpleType>> underlyingList = new ArrayList<Pair<Name, SimpleType>>(representation.getUnderlyingPropertyNamesToTypes());
for (int i = 0; i < underlyingList.size(); i++) {
Pair<Name, SimpleType> pair = underlyingList.get(i);
Name name = pair.getFirst();
SimpleType simpleType = pair.getSecond();
underlyingList.set(i, new Pair<Name, SimpleType>(name, substituteSimpleType(simpleType)));
}
return new MultiFieldValueClassRepresentation<SimpleType>(underlyingList);
return representation.mapUnderlyingType(new Function1<SimpleType, SimpleType>() {
@Override
public SimpleType invoke(SimpleType type) {
return substituteSimpleType(type);
}
});
}
@Nullable
@@ -191,13 +191,7 @@ public class MutableClassDescriptor extends ClassDescriptorBase {
@Nullable
@Override
public InlineClassRepresentation<SimpleType> getInlineClassRepresentation() {
return null;
}
@Nullable
@Override
public MultiFieldValueClassRepresentation<SimpleType> getMultiFieldValueClassRepresentation() {
public ValueClassRepresentation<SimpleType> getValueClassRepresentation() {
return null;
}
@@ -30,7 +30,6 @@ import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner
import org.jetbrains.kotlin.types.checker.REFINER_CAPABILITY
import org.jetbrains.kotlin.types.checker.TypeRefinementSupport
import org.jetbrains.kotlin.types.TypeRefinement
import org.jetbrains.kotlin.types.typeUtil.contains
import org.jetbrains.kotlin.types.typeUtil.isAnyOrNullableAny
import org.jetbrains.kotlin.types.typeUtil.makeNullable
@@ -450,3 +449,9 @@ fun <D : CallableDescriptor> D.shouldBeSubstituteWithStubTypes() =
&& dispatchReceiverParameter?.type?.isError != true
&& extensionReceiverParameter?.type?.isError != true
&& containsStubTypes()
val ClassDescriptor?.inlineClassRepresentation: InlineClassRepresentation<SimpleType>?
get() = this?.valueClassRepresentation as? InlineClassRepresentation<SimpleType>
val ClassDescriptor?.multiFieldValueClassRepresentation: MultiFieldValueClassRepresentation<SimpleType>?
get() = this?.valueClassRepresentation as? MultiFieldValueClassRepresentation<SimpleType>
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.resolve
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.resolve.descriptorUtil.inlineClassRepresentation
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.TypeSubstitutor
import org.jetbrains.kotlin.types.TypeUtils
@@ -19,16 +20,12 @@ val JVM_INLINE_ANNOTATION_CLASS_ID = ClassId.topLevel(JVM_INLINE_ANNOTATION_FQ_N
// FIXME: DeserializedClassDescriptor in reflection do not have @JvmInline annotation, that we
// FIXME: would like to check as well.
fun DeclarationDescriptor.isInlineClass(): Boolean = when {
this !is ClassDescriptor -> false
isInline -> true
else -> isValue && unsubstitutedPrimaryConstructor?.valueParameters?.size?.let { it == 1 } ?: true
}
fun DeclarationDescriptor.isInlineClass(): Boolean = this is ClassDescriptor && this.valueClassRepresentation is InlineClassRepresentation
fun DeclarationDescriptor.isValueClass(): Boolean =
this is ClassDescriptor && isValue
fun DeclarationDescriptor.isMultiFieldValueClass(): Boolean =
this is ClassDescriptor && this.valueClassRepresentation is MultiFieldValueClassRepresentation
fun DeclarationDescriptor.isInlineOrValueClass(): Boolean = isInlineClass() || isValueClass()
fun DeclarationDescriptor.isValueClass(): Boolean = isInlineClass() || isMultiFieldValueClass()
fun KotlinType.unsubstitutedUnderlyingType(): KotlinType? =
constructor.declarationDescriptor.safeAs<ClassDescriptor>()?.inlineClassRepresentation?.underlyingType
@@ -37,7 +34,7 @@ fun KotlinType.unsubstitutedUnderlyingTypes(): List<KotlinType> {
val declarationDescriptor = constructor.declarationDescriptor.safeAs<ClassDescriptor>() ?: return emptyList()
return when {
declarationDescriptor.isInlineClass() -> listOfNotNull(unsubstitutedUnderlyingType())
declarationDescriptor.isValueClass() ->
declarationDescriptor.isMultiFieldValueClass() ->
declarationDescriptor.unsubstitutedPrimaryConstructor?.valueParameters?.map { it.type } ?: emptyList()
else -> emptyList()
}
@@ -56,8 +53,8 @@ fun KotlinType.isRecursiveInlineOrValueClassType(): Boolean =
isRecursiveInlineOrValueClassTypeInner(hashSetOf())
private fun KotlinType.isRecursiveInlineOrValueClassTypeInner(visited: HashSet<ClassifierDescriptor>): Boolean {
val types = when (val descriptor = constructor.declarationDescriptor?.original?.takeIf { it.isInlineOrValueClass() }) {
is ClassDescriptor -> if (descriptor.isInlineOrValueClass()) unsubstitutedUnderlyingTypes() else emptyList()
val types = when (val descriptor = constructor.declarationDescriptor?.original?.takeIf { it.isValueClass() }) {
is ClassDescriptor -> if (descriptor.isValueClass()) unsubstitutedUnderlyingTypes() else emptyList()
is TypeParameterDescriptor -> descriptor.upperBounds
else -> emptyList()
}
@@ -20,7 +20,6 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.calls.inference.CapturedType
import org.jetbrains.kotlin.resolve.constants.IntegerLiteralTypeConstructor
import org.jetbrains.kotlin.resolve.descriptorUtil.*
import org.jetbrains.kotlin.resolve.isInlineClass
import org.jetbrains.kotlin.resolve.substitutedUnderlyingType
import org.jetbrains.kotlin.resolve.unsubstitutedUnderlyingType
import org.jetbrains.kotlin.types.*
@@ -31,10 +30,10 @@ import org.jetbrains.kotlin.utils.addIfNotNull
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
import org.jetbrains.kotlin.types.typeUtil.isSignedOrUnsignedNumberType as classicIsSignedOrUnsignedNumberType
import org.jetbrains.kotlin.types.typeUtil.isStubTypeForVariableInSubtyping as isSimpleTypeStubTypeForVariableInSubtyping
import org.jetbrains.kotlin.types.typeUtil.isStubTypeForBuilderInference as isSimpleTypeStubTypeForBuilderInference
import org.jetbrains.kotlin.types.typeUtil.isStubType as isSimpleTypeStubType
import org.jetbrains.kotlin.types.typeUtil.isStubTypeForBuilderInference as isSimpleTypeStubTypeForBuilderInference
import org.jetbrains.kotlin.types.error.ErrorUtils
import org.jetbrains.kotlin.types.typeUtil.isStubTypeForVariableInSubtyping as isSimpleTypeStubTypeForVariableInSubtyping
interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSystemCommonBackendContext {
override fun TypeConstructorMarker.isDenotable(): Boolean {
@@ -742,7 +741,17 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSy
override fun TypeConstructorMarker.isInlineClass(): Boolean {
require(this is TypeConstructor, this::errorMessage)
return (declarationDescriptor as? ClassDescriptor)?.isInlineClass() == true
return (declarationDescriptor as? ClassDescriptor)?.valueClassRepresentation is InlineClassRepresentation
}
override fun TypeConstructorMarker.isMultiFieldValueClass(): Boolean {
require(this is TypeConstructor, this::errorMessage)
return (declarationDescriptor as? ClassDescriptor)?.valueClassRepresentation is MultiFieldValueClassRepresentation
}
override fun TypeConstructorMarker.valueClassRepresentationTypeMarkersList(): List<Pair<Name, SimpleTypeMarker>>? {
require(this is TypeConstructor, this::errorMessage)
return (declarationDescriptor as? ClassDescriptor)?.valueClassRepresentation?.underlyingPropertyNamesToTypes
}
override fun TypeConstructorMarker.isInnerClass(): Boolean {
@@ -17,7 +17,10 @@ import org.jetbrains.kotlin.incremental.record
import org.jetbrains.kotlin.metadata.ProtoBuf
import org.jetbrains.kotlin.metadata.deserialization.*
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.*
import org.jetbrains.kotlin.resolve.CliSealedClassInheritorsProvider
import org.jetbrains.kotlin.resolve.DescriptorFactory
import org.jetbrains.kotlin.resolve.NonReportingOverrideStrategy
import org.jetbrains.kotlin.resolve.OverridingUtil
import org.jetbrains.kotlin.resolve.descriptorUtil.classId
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
import org.jetbrains.kotlin.resolve.scopes.MemberScope
@@ -68,9 +71,7 @@ class DeserializedClassDescriptor(
private val constructors = c.storageManager.createLazyValue { computeConstructors() }
private val companionObjectDescriptor = c.storageManager.createNullableLazyValue { computeCompanionObjectDescriptor() }
private val sealedSubclasses = c.storageManager.createLazyValue { computeSubclassesForSealedClass() }
private val inlineClassRepresentation = c.storageManager.createNullableLazyValue { computeInlineClassRepresentation() }
private val multiFieldValueClassRepresentation =
c.storageManager.createNullableLazyValue { computeMultiFieldValueClassRepresentation() }
private val valueClassRepresentation = c.storageManager.createNullableLazyValue { computeValueClassRepresentation() }
internal val thisAsProtoContainer: ProtoContainer.Class = ProtoContainer.Class(
classProto, c.nameResolver, c.typeTable, sourceElement,
@@ -182,12 +183,28 @@ class DeserializedClassDescriptor(
override fun getSealedSubclasses() = sealedSubclasses()
override fun getInlineClassRepresentation(): InlineClassRepresentation<SimpleType>? = inlineClassRepresentation()
override fun getMultiFieldValueClassRepresentation(): MultiFieldValueClassRepresentation<SimpleType>? =
multiFieldValueClassRepresentation()
override fun getValueClassRepresentation(): ValueClassRepresentation<SimpleType>? = valueClassRepresentation()
private fun computeValueClassRepresentation(): ValueClassRepresentation<SimpleType>? {
val inlineClassRepresentation = computeInlineClassRepresentation()
val multiFieldValueClassRepresentation = computeMultiFieldValueClassRepresentation()
return when {
inlineClassRepresentation != null && multiFieldValueClassRepresentation != null ->
throw IllegalArgumentException("Class cannot have both inline class representation and multi field class representation: $this")
(isValue || isInline) && inlineClassRepresentation == null && multiFieldValueClassRepresentation == null ->
throw IllegalArgumentException("Value class has no value class representation: $this")
else -> inlineClassRepresentation ?: multiFieldValueClassRepresentation
}
}
private fun computeInlineClassRepresentation(): InlineClassRepresentation<SimpleType>? {
if (!isInlineClass()) return null
if (!isInline && !isValue) return null
if (isValue &&
!classProto.hasInlineClassUnderlyingPropertyName() &&
!classProto.hasInlineClassUnderlyingType() &&
!classProto.hasInlineClassUnderlyingTypeId() &&
classProto.multiFieldValueClassUnderlyingNameCount > 0
) return null
val propertyName = when {
classProto.hasInlineClassUnderlyingPropertyName() ->
@@ -201,34 +218,27 @@ class DeserializedClassDescriptor(
else -> error("Inline class has no underlying property name in metadata: $this")
}
val type = classProto.inlineClassUnderlyingType(c.typeTable)?.let(c.typeDeserializer::simpleType)
?: getPropertyTypeFromContributedVariables(propertyName)
val type = classProto.inlineClassUnderlyingType(c.typeTable)?.let(c.typeDeserializer::simpleType) ?: run {
val underlyingProperty = memberScope.getContributedVariables(propertyName, NoLookupLocation.FROM_DESERIALIZATION)
.singleOrNull { it.extensionReceiverParameter == null } ?: error("Value class has no underlying property: $this")
underlyingProperty.type as SimpleType
}
return InlineClassRepresentation(propertyName, type)
}
private fun getPropertyTypeFromContributedVariables(propertyName: Name): SimpleType {
val underlyingProperty = memberScope.getContributedVariables(propertyName, NoLookupLocation.FROM_DESERIALIZATION)
.singleOrNull { it.extensionReceiverParameter == null } ?: error("Value class has no underlying property: $this")
return underlyingProperty.type as SimpleType
}
private fun computeMultiFieldValueClassRepresentation(): MultiFieldValueClassRepresentation<SimpleType>? {
if (!isValueClass() || isInlineClass()) return null
val representation = classProto.multiFieldValueClassRepresentation
?: error("No multiFieldValueClassRepresentation for multi-field value class: $this")
val propertyList = representation.propertyList.map { valueClassProperty ->
val name: Name = c.nameResolver.getName(valueClassProperty.name)
val protoType: ProtoBuf.Type = when {
valueClassProperty.hasType() -> valueClassProperty.type
valueClassProperty.hasTypeId() -> c.typeTable[valueClassProperty.typeId]
else -> error("Unlike inline classes before 1.5.0, multi-field value classes always have intermediate representation")
}
name to c.typeDeserializer.simpleType(protoType)
}
require(propertyList.size > 1)
require(propertyList.distinctBy { (name, _) -> name }.size == propertyList.size)
return MultiFieldValueClassRepresentation(propertyList)
val names = classProto.multiFieldValueClassUnderlyingNameList.map { c.nameResolver.getName(it) }.takeIf { it.isNotEmpty() }
?: return null
require(isValue) { "Not a value class: $this" }
val typeIdCount = classProto.multiFieldValueClassUnderlyingTypeIdCount
val typeCount = classProto.multiFieldValueClassUnderlyingTypeCount
val types = when (typeIdCount to typeCount) {
names.size to 0 -> classProto.multiFieldValueClassUnderlyingTypeIdList.map { c.typeTable[it] }
0 to names.size -> classProto.multiFieldValueClassUnderlyingTypeList
else -> error("Illegal multi-field value class representation: $this")
}.map { c.typeDeserializer.simpleType(it) }
return MultiFieldValueClassRepresentation(names zip types)
}
override fun toString() =
@@ -283,7 +293,7 @@ class DeserializedClassDescriptor(
private inner class DeserializedClassMemberScope(private val kotlinTypeRefiner: KotlinTypeRefiner) : DeserializedMemberScope(
c, classProto.functionList, classProto.propertyList, classProto.typeAliasList,
classProto.nestedClassNameList.map(c.nameResolver::getName).let { list -> { list } } // workaround KT-13454
classProto.nestedClassNameList.map(c.nameResolver::getName).let { { it } } // workaround KT-13454
) {
private val classDescriptor: DeserializedClassDescriptor get() = this@DeserializedClassDescriptor
+3 -12
View File
@@ -242,18 +242,9 @@ message Class {
optional Type inline_class_underlying_type = 18;
optional int32 inline_class_underlying_type_id = 19 [(type_id_in_table) = true];
message MultiFieldValueClassRepresentation {
message MultiFieldValueClassProperty {
required int32 name = 1;
oneof type_representation {
Type type = 2;
int32 type_id = 3;
}
}
repeated MultiFieldValueClassProperty property = 1;
}
optional MultiFieldValueClassRepresentation multi_field_value_class_representation = 22;
repeated int32 multi_field_value_class_underlying_name = 22 [packed = true, (name_id_in_table) = true];
repeated Type multi_field_value_class_underlying_type = 23;
repeated int32 multi_field_value_class_underlying_type_id = 24 [packed = true, (type_id_in_table) = true];
optional TypeTable type_table = 30;
File diff suppressed because it is too large Load Diff
@@ -109,27 +109,27 @@ class AndroidSymbols(
val kotlinUByte: IrClassSymbol =
createClass(kotlin, "UByte", ClassKind.CLASS, Modality.FINAL, true).apply {
owner.inlineClassRepresentation = InlineClassRepresentation(Name.identifier("data"), irBuiltIns.byteType as IrSimpleType)
owner.valueClassRepresentation = InlineClassRepresentation(Name.identifier("data"), irBuiltIns.byteType as IrSimpleType)
}
val kotlinUShort: IrClassSymbol =
createClass(kotlin, "UShort", ClassKind.CLASS, Modality.FINAL, true).apply {
owner.inlineClassRepresentation = InlineClassRepresentation(Name.identifier("data"), irBuiltIns.shortType as IrSimpleType)
owner.valueClassRepresentation = InlineClassRepresentation(Name.identifier("data"), irBuiltIns.shortType as IrSimpleType)
}
val kotlinUInt: IrClassSymbol =
createClass(kotlin, "UInt", ClassKind.CLASS, Modality.FINAL, true).apply {
owner.inlineClassRepresentation = InlineClassRepresentation(Name.identifier("data"), irBuiltIns.intType as IrSimpleType)
owner.valueClassRepresentation = InlineClassRepresentation(Name.identifier("data"), irBuiltIns.intType as IrSimpleType)
}
val kotlinULong: IrClassSymbol =
createClass(kotlin, "ULong", ClassKind.CLASS, Modality.FINAL, true).apply {
owner.inlineClassRepresentation = InlineClassRepresentation(Name.identifier("data"), irBuiltIns.longType as IrSimpleType)
owner.valueClassRepresentation = InlineClassRepresentation(Name.identifier("data"), irBuiltIns.longType as IrSimpleType)
}
val kotlinUByteArray: IrClassSymbol =
createClass(kotlin, "UByteArray", ClassKind.CLASS, Modality.FINAL, true).apply {
owner.inlineClassRepresentation = InlineClassRepresentation(
owner.valueClassRepresentation = InlineClassRepresentation(
Name.identifier("storage"),
irBuiltIns.primitiveArrayForType.getValue(irBuiltIns.byteType).owner.defaultType
)
@@ -137,7 +137,7 @@ class AndroidSymbols(
val kotlinUShortArray: IrClassSymbol =
createClass(kotlin, "UShortArray", ClassKind.CLASS, Modality.FINAL, true).apply {
owner.inlineClassRepresentation = InlineClassRepresentation(
owner.valueClassRepresentation = InlineClassRepresentation(
Name.identifier("storage"),
irBuiltIns.primitiveArrayForType.getValue(irBuiltIns.shortType).owner.defaultType
)
@@ -145,7 +145,7 @@ class AndroidSymbols(
val kotlinUIntArray: IrClassSymbol =
createClass(kotlin, "UIntArray", ClassKind.CLASS, Modality.FINAL, true).apply {
owner.inlineClassRepresentation = InlineClassRepresentation(
owner.valueClassRepresentation = InlineClassRepresentation(
Name.identifier("storage"),
irBuiltIns.primitiveArrayForType.getValue(irBuiltIns.intType).owner.defaultType
)
@@ -153,7 +153,7 @@ class AndroidSymbols(
val kotlinULongArray: IrClassSymbol =
createClass(kotlin, "ULongArray", ClassKind.CLASS, Modality.FINAL, true).apply {
owner.inlineClassRepresentation = InlineClassRepresentation(
owner.valueClassRepresentation = InlineClassRepresentation(
Name.identifier("storage"),
irBuiltIns.primitiveArrayForType.getValue(irBuiltIns.longType).owner.defaultType
)