[IR] Unite inline class and multi-field value class representation
#KT-1179
This commit is contained in:
committed by
teamcity
parent
282ab398c6
commit
28bf83ceac
+1
-2
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-7
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
+8
-21
@@ -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
|
||||
|
||||
+1
-7
@@ -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()
|
||||
}
|
||||
|
||||
+13
-4
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user