From 4c7f207309465917d1a90e2aba533c729ec027c9 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Tue, 23 Mar 2021 14:51:31 +0100 Subject: [PATCH] Use new getInlineClassRepresentation in some utilities --- .../kotlin/codegen/ClosureCodegen.java | 14 +++-- .../codegen/ErasedInlineClassBodyCodegen.kt | 4 +- .../kotlin/codegen/ExpressionCodegen.java | 12 ++-- .../kotlin/codegen/FunctionCodegen.java | 16 ++--- .../codegen/ImplementationBodyCodegen.java | 20 +++--- .../codegen/inlineClassesCodegenUtil.kt | 9 +-- .../resolve/InlineClassDescriptorResolver.kt | 61 +++++++------------ .../evaluate/ConstantExpressionEvaluator.kt | 10 ++- .../serialization/DescriptorSerializer.kt | 11 ++-- .../kotlin/resolve/inlineClassesUtils.kt | 14 ++--- 10 files changed, 74 insertions(+), 97 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ClosureCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ClosureCodegen.java index f4ecc1e718a..6baf41a3e11 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ClosureCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ClosureCodegen.java @@ -12,6 +12,7 @@ import kotlin.Unit; import kotlin.collections.CollectionsKt; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.kotlin.backend.common.SamType; import org.jetbrains.kotlin.builtins.KotlinBuiltIns; import org.jetbrains.kotlin.codegen.binding.CalculatedClosure; import org.jetbrains.kotlin.codegen.context.ClosureContext; @@ -31,7 +32,6 @@ import org.jetbrains.kotlin.load.kotlin.header.KotlinClassHeader; import org.jetbrains.kotlin.metadata.ProtoBuf; import org.jetbrains.kotlin.psi.KtElement; import org.jetbrains.kotlin.resolve.DescriptorUtils; -import org.jetbrains.kotlin.resolve.InlineClassesUtilsKt; import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall; import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt; import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOriginKt; @@ -40,7 +40,7 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.TransientReceiver; import org.jetbrains.kotlin.serialization.DescriptorSerializer; import org.jetbrains.kotlin.types.KotlinType; import org.jetbrains.kotlin.types.SimpleType; -import org.jetbrains.kotlin.backend.common.SamType; +import org.jetbrains.kotlin.types.TypeUtils; import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils; import org.jetbrains.kotlin.util.OperatorNameConventions; import org.jetbrains.org.objectweb.asm.MethodVisitor; @@ -376,10 +376,12 @@ public class ClosureCodegen extends MemberCodegen { value = StackValue.local(slot, type, bridgeParameterKotlinTypes.get(i)); slot += type.getSize(); } - if (InlineClassesCodegenUtilKt.isInlineClassWithUnderlyingTypeAnyOrAnyN(parameterType) && - functionReferenceCall == null - ) { - parameterType = InlineClassesUtilsKt.unsubstitutedUnderlyingParameter(parameterType).getType(); + if (InlineClassesCodegenUtilKt.isInlineClassWithUnderlyingTypeAnyOrAnyN(parameterType) && functionReferenceCall == null) { + ClassDescriptor descriptor = TypeUtils.getClassDescriptor(parameterType); + InlineClassRepresentation representation = + descriptor != null ? descriptor.getInlineClassRepresentation() : null; + assert representation != null : "Not an inline class type: " + parameterType; + parameterType = representation.getUnderlyingType(); } value.put(typeMapper.mapType(calleeParameter), parameterType, iv); } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ErasedInlineClassBodyCodegen.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/ErasedInlineClassBodyCodegen.kt index bad25a8b3de..6b1437305f9 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ErasedInlineClassBodyCodegen.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ErasedInlineClassBodyCodegen.kt @@ -72,7 +72,7 @@ class ErasedInlineClassBodyCodegen( } private fun generateUnboxMethod() { - val boxMethodDescriptor = InlineClassDescriptorResolver.createBoxFunctionDescriptor(descriptor) ?: return + val boxMethodDescriptor = InlineClassDescriptorResolver.createBoxFunctionDescriptor(descriptor) functionCodegen.generateMethod( Synthetic(null, boxMethodDescriptor), boxMethodDescriptor, object : FunctionGenerationStrategy.CodegenBased(state) { @@ -103,7 +103,7 @@ class ErasedInlineClassBodyCodegen( } private fun generateSpecializedEqualsStub() { - val specializedEqualsDescriptor = InlineClassDescriptorResolver.createSpecializedEqualsDescriptor(descriptor) ?: return + val specializedEqualsDescriptor = InlineClassDescriptorResolver.createSpecializedEqualsDescriptor(descriptor) functionCodegen.generateMethod( Synthetic(null, specializedEqualsDescriptor), specializedEqualsDescriptor, object : FunctionGenerationStrategy.CodegenBased(state) { diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java index d55e3a1c8e1..e826b9d513c 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java @@ -20,6 +20,7 @@ import kotlin.text.StringsKt; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.backend.common.CodegenUtil; +import org.jetbrains.kotlin.backend.common.SamType; import org.jetbrains.kotlin.builtins.KotlinBuiltIns; import org.jetbrains.kotlin.codegen.binding.CalculatedClosure; import org.jetbrains.kotlin.codegen.binding.CodegenBinding; @@ -92,7 +93,6 @@ import org.jetbrains.kotlin.types.model.KotlinTypeMarker; import org.jetbrains.kotlin.types.model.TypeParameterMarker; import org.jetbrains.kotlin.types.typesApproximation.CapturedTypeApproximationKt; import org.jetbrains.kotlin.util.OperatorNameConventions; -import org.jetbrains.kotlin.backend.common.SamType; import org.jetbrains.org.objectweb.asm.Label; import org.jetbrains.org.objectweb.asm.MethodVisitor; import org.jetbrains.org.objectweb.asm.Opcodes; @@ -2024,10 +2024,12 @@ public class ExpressionCodegen extends KtVisitor impleme // Do not unbox parameters of suspend lambda, they are unboxed in `invoke` method !CoroutineCodegenUtilKt.isInvokeSuspendOfLambda(context.getFunctionDescriptor()) ) { - KotlinType underlyingType = InlineClassesUtilsKt.underlyingRepresentation( - (ClassDescriptor) inlineClassType.getConstructor().getDeclarationDescriptor()).getType(); - return StackValue.underlyingValueOfInlineClass( - typeMapper.mapType(underlyingType), underlyingType, localOrCaptured); + ClassDescriptor inlineClass = (ClassDescriptor) inlineClassType.getConstructor().getDeclarationDescriptor(); + InlineClassRepresentation representation = + inlineClass != null ? inlineClass.getInlineClassRepresentation() : null; + assert representation != null : "Not an inline class: " + inlineClassType; + KotlinType underlyingType = representation.getUnderlyingType(); + return StackValue.underlyingValueOfInlineClass(typeMapper.mapType(underlyingType), underlyingType, localOrCaptured); } } return localOrCaptured; diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java index 897634124ef..034127a78ed 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java @@ -53,6 +53,7 @@ import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterKind; import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterSignature; import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature; import org.jetbrains.kotlin.types.KotlinType; +import org.jetbrains.kotlin.types.SimpleType; import org.jetbrains.kotlin.types.TypeUtils; import org.jetbrains.org.objectweb.asm.Label; import org.jetbrains.org.objectweb.asm.MethodVisitor; @@ -369,23 +370,22 @@ public class FunctionCodegen { public static void generateMethodInsideInlineClassWrapper( @NotNull JvmDeclarationOrigin origin, @NotNull FunctionDescriptor functionDescriptor, - @NotNull ClassDescriptor containingDeclaration, + @NotNull ClassDescriptor inlineClass, @NotNull MethodVisitor mv, @NotNull KotlinTypeMapper typeMapper ) { mv.visitCode(); - Type fieldOwnerType = typeMapper.mapClass(containingDeclaration); + Type fieldOwnerType = typeMapper.mapClass(inlineClass); Method erasedMethodImpl = typeMapper.mapAsmMethod(functionDescriptor.getOriginal(), OwnerKind.ERASED_INLINE_CLASS); - ValueParameterDescriptor valueRepresentation = InlineClassesUtilsKt.underlyingRepresentation(containingDeclaration); - if (valueRepresentation == null) return; - - Type fieldType = typeMapper.mapType(valueRepresentation); + InlineClassRepresentation representation = inlineClass.getInlineClassRepresentation(); + assert representation != null : "Not an inline class: " + inlineClass; generateDelegateToStaticErasedVersion( - mv, erasedMethodImpl, - fieldOwnerType, valueRepresentation.getName().asString(), fieldType + mv, erasedMethodImpl, fieldOwnerType, + representation.getUnderlyingPropertyName().asString(), + typeMapper.mapType(representation.getUnderlyingType()) ); endVisit(mv, null, origin.getElement()); diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java index a7063ee9de6..9c6afccca8a 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java @@ -55,6 +55,7 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.ImplicitReceiver; import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue; import org.jetbrains.kotlin.serialization.DescriptorSerializer; import org.jetbrains.kotlin.types.KotlinType; +import org.jetbrains.kotlin.types.SimpleType; import org.jetbrains.org.objectweb.asm.FieldVisitor; import org.jetbrains.org.objectweb.asm.MethodVisitor; import org.jetbrains.org.objectweb.asm.Type; @@ -274,26 +275,25 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { @Override protected void generateUnboxMethodForInlineClass() { if (!(myClass instanceof KtClass)) return; - if (!InlineClassesUtilsKt.isInlineClass(descriptor)) return; + InlineClassRepresentation inlineClassRepresentation = descriptor.getInlineClassRepresentation(); + if (inlineClassRepresentation == null) return; Type ownerType = typeMapper.mapClass(descriptor); - ValueParameterDescriptor inlinedValue = InlineClassesUtilsKt.underlyingRepresentation(this.descriptor); - if (inlinedValue == null) return; - - Type valueType = typeMapper.mapType(inlinedValue.getType()); + Type valueType = typeMapper.mapType(inlineClassRepresentation.getUnderlyingType()); SimpleFunctionDescriptor functionDescriptor = InlineClassDescriptorResolver.createUnboxFunctionDescriptor(this.descriptor); - assert functionDescriptor != null : "FunctionDescriptor for unbox method should be not null during codegen"; functionCodegen.generateMethod( JvmDeclarationOriginKt.UnboxMethodOfInlineClass(functionDescriptor), functionDescriptor, new FunctionGenerationStrategy.CodegenBased(state) { @Override - public void doGenerateBody( - @NotNull ExpressionCodegen codegen, @NotNull JvmMethodSignature signature - ) { + public void doGenerateBody(@NotNull ExpressionCodegen codegen, @NotNull JvmMethodSignature signature) { InstructionAdapter iv = codegen.v; iv.load(0, OBJECT_TYPE); - iv.getfield(ownerType.getInternalName(), inlinedValue.getName().asString(), valueType.getDescriptor()); + iv.getfield( + ownerType.getInternalName(), + inlineClassRepresentation.getUnderlyingPropertyName().asString(), + valueType.getDescriptor() + ); iv.areturn(valueType); } } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inlineClassesCodegenUtil.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/inlineClassesCodegenUtil.kt index 3c4754923a8..10f062d4f7a 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inlineClassesCodegenUtil.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inlineClassesCodegenUtil.kt @@ -12,8 +12,6 @@ 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.isInlineClassType -import org.jetbrains.kotlin.resolve.underlyingRepresentation import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedClassDescriptor import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedSimpleFunctionDescriptor import org.jetbrains.kotlin.types.KotlinType @@ -26,9 +24,8 @@ import org.jetbrains.org.objectweb.asm.Opcodes import org.jetbrains.org.objectweb.asm.commons.Method fun KotlinType.isInlineClassWithUnderlyingTypeAnyOrAnyN(): Boolean { - if (!isInlineClassType()) return false - val classDescriptor = constructor.declarationDescriptor as? ClassDescriptor ?: return false - return classDescriptor.underlyingRepresentation()?.type?.isAnyOrNullableAny() == true + val classDescriptor = constructor.declarationDescriptor + return classDescriptor is ClassDescriptor && classDescriptor.inlineClassRepresentation?.underlyingType?.isAnyOrNullableAny() == true } fun CallableDescriptor.isGenericParameter(): Boolean { @@ -79,4 +76,4 @@ fun classFileContainsMethod(classId: ClassId, state: GenerationState, method: Me } }, ClassReader.SKIP_FRAMES) return found -} \ No newline at end of file +} diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/InlineClassDescriptorResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/InlineClassDescriptorResolver.kt index b1bf17b41ef..a2db715cb67 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/InlineClassDescriptorResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/InlineClassDescriptorResolver.kt @@ -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.types.KotlinType object InlineClassDescriptorResolver { @JvmField @@ -28,11 +29,11 @@ object InlineClassDescriptorResolver { val SPECIALIZED_EQUALS_SECOND_PARAMETER_NAME = Name.identifier("p2") @JvmStatic - fun createBoxFunctionDescriptor(owner: ClassDescriptor): SimpleFunctionDescriptor? = + fun createBoxFunctionDescriptor(owner: ClassDescriptor): SimpleFunctionDescriptor = createConversionFunctionDescriptor(true, owner) @JvmStatic - fun createUnboxFunctionDescriptor(owner: ClassDescriptor): SimpleFunctionDescriptor? = + fun createUnboxFunctionDescriptor(owner: ClassDescriptor): SimpleFunctionDescriptor = createConversionFunctionDescriptor(false, owner) @JvmStatic @@ -57,9 +58,7 @@ object InlineClassDescriptorResolver { private fun isSynthesizedInlineClassMember(descriptor: CallableMemberDescriptor) = descriptor.kind == CallableMemberDescriptor.Kind.SYNTHESIZED && descriptor.containingDeclaration.isInlineClass() - fun createSpecializedEqualsDescriptor(owner: ClassDescriptor): SimpleFunctionDescriptor? { - val inlinedValue = owner.underlyingRepresentation() ?: return null - + fun createSpecializedEqualsDescriptor(owner: ClassDescriptor): SimpleFunctionDescriptor { val functionDescriptor = SimpleFunctionDescriptorImpl.create( owner, Annotations.EMPTY, @@ -72,7 +71,7 @@ object InlineClassDescriptorResolver { null, null, emptyList(), - createValueParametersForSpecializedEquals(functionDescriptor, inlinedValue), + createValueParametersForSpecializedEquals(functionDescriptor, owner.inlineClassRepresentation!!.underlyingType), owner.builtIns.booleanType, Modality.FINAL, DescriptorVisibilities.PUBLIC @@ -81,12 +80,7 @@ object InlineClassDescriptorResolver { return functionDescriptor } - private fun createConversionFunctionDescriptor( - isBoxMethod: Boolean, - owner: ClassDescriptor - ): SimpleFunctionDescriptor? { - val inlinedValue = owner.underlyingRepresentation() ?: return null - + private fun createConversionFunctionDescriptor(isBoxMethod: Boolean, owner: ClassDescriptor): SimpleFunctionDescriptor { val functionDescriptor = SimpleFunctionDescriptorImpl.create( owner, Annotations.EMPTY, @@ -95,12 +89,13 @@ object InlineClassDescriptorResolver { SourceElement.NO_SOURCE ) + val underlyingType = owner.inlineClassRepresentation!!.underlyingType functionDescriptor.initialize( null, if (isBoxMethod) null else owner.thisAsReceiverParameter, emptyList(), - if (isBoxMethod) listOf(createValueParameterForBoxing(functionDescriptor, inlinedValue)) else emptyList(), - if (isBoxMethod) owner.defaultType else inlinedValue.returnType, + if (isBoxMethod) listOf(createValueParameterForBoxing(functionDescriptor, underlyingType)) else emptyList(), + if (isBoxMethod) owner.defaultType else underlyingType, Modality.FINAL, DescriptorVisibilities.PUBLIC ) @@ -109,36 +104,22 @@ object InlineClassDescriptorResolver { } private fun createValueParameterForBoxing( - functionDescriptor: FunctionDescriptor, - inlinedValue: ValueParameterDescriptor - ): ValueParameterDescriptorImpl { - return createValueParameter(functionDescriptor, inlinedValue, BOXING_VALUE_PARAMETER_NAME, 0) - } + functionDescriptor: FunctionDescriptor, underlyingType: KotlinType + ): ValueParameterDescriptorImpl = + createValueParameter(functionDescriptor, underlyingType, BOXING_VALUE_PARAMETER_NAME, 0) private fun createValueParametersForSpecializedEquals( - functionDescriptor: FunctionDescriptor, - inlinedValue: ValueParameterDescriptor - ): List { - return listOf( - createValueParameter(functionDescriptor, inlinedValue, SPECIALIZED_EQUALS_FIRST_PARAMETER_NAME, 0), - createValueParameter(functionDescriptor, inlinedValue, SPECIALIZED_EQUALS_SECOND_PARAMETER_NAME, 1) + functionDescriptor: FunctionDescriptor, underlyingType: KotlinType + ): List = + listOf( + createValueParameter(functionDescriptor, underlyingType, SPECIALIZED_EQUALS_FIRST_PARAMETER_NAME, 0), + createValueParameter(functionDescriptor, underlyingType, SPECIALIZED_EQUALS_SECOND_PARAMETER_NAME, 1) ) - } private fun createValueParameter( - functionDescriptor: FunctionDescriptor, - inlinedValue: ValueParameterDescriptor, - name: Name, - index: Int - ): ValueParameterDescriptorImpl { - return ValueParameterDescriptorImpl( - functionDescriptor, - null, - index, - Annotations.EMPTY, - name, - inlinedValue.type, - false, false, false, null, SourceElement.NO_SOURCE + functionDescriptor: FunctionDescriptor, type: KotlinType, name: Name, index: Int + ): ValueParameterDescriptorImpl = + ValueParameterDescriptorImpl( + functionDescriptor, null, index, Annotations.EMPTY, name, type, false, false, false, null, SourceElement.NO_SOURCE ) - } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/constants/evaluate/ConstantExpressionEvaluator.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/constants/evaluate/ConstantExpressionEvaluator.kt index 95da06dd7d1..a1debf896c6 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/constants/evaluate/ConstantExpressionEvaluator.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/constants/evaluate/ConstantExpressionEvaluator.kt @@ -39,6 +39,7 @@ 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.types.KotlinType +import org.jetbrains.kotlin.types.SimpleType import org.jetbrains.kotlin.types.TypeUtils import org.jetbrains.kotlin.types.checker.KotlinTypeChecker import org.jetbrains.kotlin.types.expressions.DoubleColonLHS @@ -857,7 +858,7 @@ private class ConstantExpressionEvaluatorVisitor( } classDescriptor.isInlineClass() && UnsignedTypes.isUnsignedClass(classDescriptor) -> - createConstantValueForUnsignedTypeConstructor(call, resultingDescriptor, classDescriptor) + createConstantValueForUnsignedTypeConstructor(call, resultingDescriptor, classDescriptor.inlineClassRepresentation!!) else -> null } @@ -869,20 +870,17 @@ private class ConstantExpressionEvaluatorVisitor( private fun createConstantValueForUnsignedTypeConstructor( call: ResolvedCall<*>, constructorDescriptor: ConstructorDescriptor, - classDescriptor: ClassDescriptor + representation: InlineClassRepresentation, ): TypedCompileTimeConstant<*>? { - assert(classDescriptor.isInlineClass()) { "Unsigned type should be an inline class type, but it is: $classDescriptor" } - if (!constructorDescriptor.isPrimary) return null val valueArguments = call.valueArguments if (valueArguments.size > 1) return null - val underlyingType = classDescriptor.underlyingRepresentation()?.type ?: return null - val argument = valueArguments.values.singleOrNull()?.arguments?.singleOrNull() ?: return null val argumentExpression = argument.getArgumentExpression() ?: return null + val underlyingType = representation.underlyingType val compileTimeConstant = evaluate(argumentExpression, underlyingType) val evaluatedArgument = compileTimeConstant?.toConstantValue(underlyingType) ?: return null diff --git a/compiler/serialization/src/org/jetbrains/kotlin/serialization/DescriptorSerializer.kt b/compiler/serialization/src/org/jetbrains/kotlin/serialization/DescriptorSerializer.kt index 96552b10840..24b58bb01a2 100644 --- a/compiler/serialization/src/org/jetbrains/kotlin/serialization/DescriptorSerializer.kt +++ b/compiler/serialization/src/org/jetbrains/kotlin/serialization/DescriptorSerializer.kt @@ -165,17 +165,18 @@ class DescriptorSerializer private constructor( builder.typeTable = typeTableProto } - classDescriptor.underlyingRepresentation()?.let { parameter -> - builder.inlineClassUnderlyingPropertyName = getSimpleNameIndex(parameter.name) + val representation = classDescriptor.inlineClassRepresentation + if (representation != null) { + builder.inlineClassUnderlyingPropertyName = getSimpleNameIndex(representation.underlyingPropertyName) val property = callableMembers.single { - it is PropertyDescriptor && it.extensionReceiverParameter == null && it.name == parameter.name + it is PropertyDescriptor && it.extensionReceiverParameter == null && it.name == representation.underlyingPropertyName } if (!property.visibility.isPublicAPI) { if (useTypeTable()) { - builder.inlineClassUnderlyingTypeId = typeId(parameter.type) + builder.inlineClassUnderlyingTypeId = typeId(representation.underlyingType) } else { - builder.setInlineClassUnderlyingType(type(parameter.type)) + builder.setInlineClassUnderlyingType(type(representation.underlyingType)) } } } diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/inlineClassesUtils.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/inlineClassesUtils.kt index 2e3652765b8..341a233db7e 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/inlineClassesUtils.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/inlineClassesUtils.kt @@ -15,7 +15,7 @@ import org.jetbrains.kotlin.utils.addToStdlib.safeAs val JVM_INLINE_ANNOTATION_FQ_NAME = FqName("kotlin.jvm.JvmInline") -fun ClassDescriptor.underlyingRepresentation(): ValueParameterDescriptor? { +private fun ClassDescriptor.underlyingRepresentation(): ValueParameterDescriptor? { if (!isInlineClass()) return null return unsubstitutedPrimaryConstructor?.valueParameters?.singleOrNull() } @@ -24,7 +24,7 @@ fun ClassDescriptor.underlyingRepresentation(): ValueParameterDescriptor? { // FIXME: would like to check as well. fun DeclarationDescriptor.isInlineClass() = this is ClassDescriptor && (isInline || isValue) -fun KotlinType.unsubstitutedUnderlyingParameter(): ValueParameterDescriptor? { +private fun KotlinType.unsubstitutedUnderlyingParameter(): ValueParameterDescriptor? { return constructor.declarationDescriptor.safeAs()?.underlyingRepresentation() } @@ -67,10 +67,6 @@ fun KotlinType.isNullableUnderlyingType(): Boolean { fun CallableDescriptor.isGetterOfUnderlyingPropertyOfInlineClass() = this is PropertyGetterDescriptor && correspondingProperty.isUnderlyingPropertyOfInlineClass() -fun VariableDescriptor.isUnderlyingPropertyOfInlineClass(): Boolean { - if (extensionReceiverParameter != null) return false - val containingDeclaration = this.containingDeclaration - if (!containingDeclaration.isInlineClass()) return false - - return (containingDeclaration as ClassDescriptor).underlyingRepresentation()?.name == this.name -} +fun VariableDescriptor.isUnderlyingPropertyOfInlineClass(): Boolean = + extensionReceiverParameter == null && + (containingDeclaration as? ClassDescriptor)?.inlineClassRepresentation?.underlyingPropertyName == this.name