Value classes: Add isValue property to class descriptors

Reuse isInline flag in proto and IR.
Check metadata version on deserialization.
This commit is contained in:
Ilmir Usmanov
2020-11-17 03:25:04 +01:00
parent 8eff3a6bb3
commit 361ed117bb
16 changed files with 63 additions and 1 deletions
@@ -83,6 +83,7 @@ class SyntheticClassOrObjectDescriptor(
override fun isExpect() = false
override fun isActual() = false
override fun isFun() = false
override fun isValue() = false
override fun getCompanionObjectDescriptor(): ClassDescriptorWithResolutionScopes? = null
override fun getTypeConstructor(): TypeConstructor = typeConstructor
@@ -87,6 +87,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
private final boolean isExpect;
private final boolean isActual;
private final boolean isFun;
private final boolean isValue;
private final Annotations annotations;
private final Annotations danglingAnnotations;
@@ -160,6 +161,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
containingDeclaration instanceof ClassDescriptor && ((ClassDescriptor) containingDeclaration).isExpect();
this.isFun = modifierList != null && PsiUtilsKt.hasFunModifier(modifierList);
this.isValue = modifierList != null && PsiUtilsKt.hasValueModifier(modifierList);
// Annotation entries are taken from both own annotations (if any) and object literal annotations (if any)
List<KtAnnotationEntry> annotationEntries = new ArrayList<>();
@@ -552,6 +554,11 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
return isFun;
}
@Override
public boolean isValue() {
return isValue;
}
@NotNull
@Override
public Annotations getAnnotations() {
@@ -604,6 +604,9 @@ open class IrBasedClassDescriptor(owner: IrClass) : ClassDescriptor, IrBasedDecl
override fun isFun() = owner.isFun
// In IR, inline and value are synonyms
override fun isValue() = owner.isInline
override fun getThisAsReceiverParameter() = owner.thisReceiver?.toIrBasedDescriptor() as ReceiverParameterDescriptor
override fun getUnsubstitutedPrimaryConstructor() =
@@ -704,6 +707,8 @@ open class IrBasedEnumEntryDescriptor(owner: IrEnumEntry) : ClassDescriptor, IrB
override fun isFun() = false
override fun isValue() = false
override fun getThisAsReceiverParameter() = (owner.parent as IrClass).toIrBasedDescriptor().thisAsReceiverParameter
override fun getUnsubstitutedPrimaryConstructor(): ClassConstructorDescriptor? {
@@ -583,6 +583,8 @@ open class WrappedClassDescriptor : ClassDescriptor, WrappedDeclarationDescripto
override fun isFun() = owner.isFun
override fun isValue() = owner.isInline
override fun getThisAsReceiverParameter() = owner.thisReceiver?.descriptor as ReceiverParameterDescriptor
override fun getUnsubstitutedPrimaryConstructor() =
@@ -682,6 +684,8 @@ open class WrappedScriptDescriptor : ScriptDescriptor, WrappedDeclarationDescrip
override fun isFun() = false
override fun isValue() = false
override fun getThisAsReceiverParameter() = owner.thisReceiver.descriptor as ReceiverParameterDescriptor
override fun getUnsubstitutedPrimaryConstructor() = TODO()
@@ -822,6 +826,8 @@ open class WrappedEnumEntryDescriptor : ClassDescriptor, WrappedDeclarationDescr
override fun isFun() = false
override fun isValue() = false
override fun getThisAsReceiverParameter() = (owner.parent as IrClass).descriptor.thisAsReceiverParameter
override fun getUnsubstitutedPrimaryConstructor(): ClassConstructorDescriptor? {
@@ -452,6 +452,8 @@ fun KtModifierList.hasSuspendModifier() = hasModifier(KtTokens.SUSPEND_KEYWORD)
fun KtModifierList.hasFunModifier() = hasModifier(KtTokens.FUN_KEYWORD)
fun KtModifierList.hasValueModifier() = hasModifier(KtTokens.VALUE_KEYWORD)
fun ASTNode.children() = generateSequence(firstChildNode) { node -> node.treeNext }
fun ASTNode.parents() = generateSequence(treeParent) { node -> node.treeParent }
@@ -105,6 +105,7 @@ class LazyJavaClassDescriptor(
override fun isExpect() = false
override fun isActual() = false
override fun isFun() = false
override fun isValue() = false
private val typeConstructor = LazyJavaClassTypeConstructor()
override fun getTypeConstructor(): TypeConstructor = typeConstructor
@@ -81,6 +81,7 @@ class FunctionClassDescriptor(
override fun isData() = false
override fun isInline() = false
override fun isFun() = false
override fun isValue() = false
override fun isExpect() = false
override fun isActual() = false
override fun isExternal() = false
@@ -72,6 +72,8 @@ public interface ClassDescriptor extends ClassifierDescriptorWithTypeParameters,
boolean isFun();
boolean isValue();
@NotNull
ReceiverParameterDescriptor getThisAsReceiverParameter();
@@ -71,6 +71,7 @@ class NotFoundClasses(private val storageManager: StorageManager, private val mo
override fun isData() = false
override fun isInline() = false
override fun isFun() = false
override fun isValue() = false
override fun isExpect() = false
override fun isActual() = false
override fun isExternal() = false
@@ -148,6 +148,11 @@ public class ClassDescriptorImpl extends ClassDescriptorBase {
return false;
}
@Override
public boolean isValue() {
return false;
}
@Override
public boolean isInner() {
return false;
@@ -138,6 +138,11 @@ public class EnumEntrySyntheticClassDescriptor extends ClassDescriptorBase {
return false;
}
@Override
public boolean isValue() {
return false;
}
@Override
public boolean isFun() {
return false;
@@ -248,6 +248,11 @@ public class LazySubstitutingClassDescriptor extends ModuleAwareClassDescriptor
return original.isFun();
}
@Override
public boolean isValue() {
return original.isValue();
}
@Override
public boolean isExternal() {
return original.isExternal();
@@ -104,6 +104,11 @@ public class MutableClassDescriptor extends ClassDescriptorBase {
return false;
}
@Override
public boolean isValue() {
return false;
}
@Override
public boolean isCompanionObject() {
return false;
@@ -98,7 +98,7 @@ class DeserializedClassDescriptor(
override fun isData() = Flags.IS_DATA.get(classProto.flags)
override fun isInline() = Flags.IS_INLINE_CLASS.get(classProto.flags)
override fun isInline() = Flags.IS_INLINE_CLASS.get(classProto.flags) && metadataVersion.isAtMost(1, 4, 1)
override fun isExpect() = Flags.IS_EXPECT_CLASS.get(classProto.flags)
@@ -108,6 +108,8 @@ class DeserializedClassDescriptor(
override fun isFun() = Flags.IS_FUN_INTERFACE.get(classProto.flags)
override fun isValue() = Flags.IS_INLINE_CLASS.get(classProto.flags) && metadataVersion.isAtLeast(1, 4, 2)
override fun getUnsubstitutedMemberScope(kotlinTypeRefiner: KotlinTypeRefiner): MemberScope =
memberScopeHolder.getScope(kotlinTypeRefiner)
@@ -48,6 +48,19 @@ abstract class BinaryVersion(private vararg val numbers: Int) {
return this.patch >= patch
}
fun isAtMost(version: BinaryVersion): Boolean =
isAtMost(version.major, version.minor, version.patch)
fun isAtMost(major: Int, minor: Int, patch: Int): Boolean {
if (this.major < major) return true
if (this.major > major) return false
if (this.minor < minor) return true
if (this.minor > minor) return false
return this.patch <= patch
}
override fun toString(): String {
val versions = toArray().takeWhile { it != UNKNOWN }
return if (versions.isEmpty()) "unknown" else versions.joinToString(".")
@@ -80,6 +80,7 @@ class CommonizedClassDescriptor(
override fun isExpect() = isExpect
override fun isActual() = isActual
override fun isFun() = false // TODO: modifier "fun" should be accessible from here too
override fun isValue() = false // TODO: modifier "value" should be accessible from here too
override fun getUnsubstitutedMemberScope(kotlinTypeRefiner: KotlinTypeRefiner): CommonizedMemberScope {
check(kotlinTypeRefiner == KotlinTypeRefiner.Default) {