Delete deprecated Type.Constructor message, advance ABI version

This commit is contained in:
Alexander Udalov
2015-09-16 16:21:43 +03:00
parent 42eb413066
commit e749bc262d
11 changed files with 483 additions and 2055 deletions
@@ -349,12 +349,23 @@ public class DescriptorSerializer {
public ProtoBuf.Type.Builder type(@NotNull JetType type) {
assert !type.isError() : "Can't serialize error types: " + type; // TODO
if (TypesPackage.isFlexible(type)) return flexibleType(type);
if (TypesPackage.isFlexible(type)) {
Flexibility flexibility = TypesPackage.flexibility(type);
return type(flexibility.getLowerBound())
.setFlexibleTypeCapabilitiesId(stringTable.getStringIndex(flexibility.getExtraCapabilities().getId()))
.setFlexibleUpperBound(type(flexibility.getUpperBound()));
}
ProtoBuf.Type.Builder builder = ProtoBuf.Type.newBuilder();
builder.setConstructor(typeConstructor(type.getConstructor()));
setTypeConstructorFields(builder, type.getConstructor());
ClassifierDescriptor descriptor = type.getConstructor().getDeclarationDescriptor();
if (descriptor instanceof ClassDescriptor) {
builder.setClassName(getClassId((ClassDescriptor) descriptor));
}
if (descriptor instanceof TypeParameterDescriptor) {
builder.setTypeParameter(getTypeParameterId((TypeParameterDescriptor) descriptor));
}
for (TypeProjection projection : type.getArguments()) {
builder.addArgument(typeArgument(projection));
@@ -370,33 +381,6 @@ public class DescriptorSerializer {
return builder;
}
private void setTypeConstructorFields(@NotNull ProtoBuf.Type.Builder builder, @NotNull TypeConstructor typeConstructor) {
ClassifierDescriptor declarationDescriptor = typeConstructor.getDeclarationDescriptor();
assert declarationDescriptor instanceof TypeParameterDescriptor || declarationDescriptor instanceof ClassDescriptor
: "Unknown declaration descriptor: " + typeConstructor;
if (declarationDescriptor instanceof TypeParameterDescriptor) {
TypeParameterDescriptor typeParameterDescriptor = (TypeParameterDescriptor) declarationDescriptor;
builder.setConstructorTypeParameter(getTypeParameterId(typeParameterDescriptor));
}
else {
ClassDescriptor classDescriptor = (ClassDescriptor) declarationDescriptor;
builder.setConstructorClassName(getClassId(classDescriptor));
}
}
private ProtoBuf.Type.Builder flexibleType(@NotNull JetType type) {
Flexibility flexibility = TypesPackage.flexibility(type);
ProtoBuf.Type.Builder builder = type(flexibility.getLowerBound());
builder.setFlexibleTypeCapabilitiesId(stringTable.getStringIndex(flexibility.getExtraCapabilities().getId()));
builder.setFlexibleUpperBound(type(flexibility.getUpperBound()));
return builder;
}
@NotNull
private ProtoBuf.Type.Argument.Builder typeArgument(@NotNull TypeProjection typeProjection) {
ProtoBuf.Type.Argument.Builder builder = ProtoBuf.Type.Argument.newBuilder();
@@ -417,27 +401,6 @@ public class DescriptorSerializer {
return builder;
}
@NotNull
private ProtoBuf.Type.Constructor.Builder typeConstructor(@NotNull TypeConstructor typeConstructor) {
ProtoBuf.Type.Constructor.Builder builder = ProtoBuf.Type.Constructor.newBuilder();
ClassifierDescriptor declarationDescriptor = typeConstructor.getDeclarationDescriptor();
assert declarationDescriptor instanceof TypeParameterDescriptor || declarationDescriptor instanceof ClassDescriptor
: "Unknown declaration descriptor: " + typeConstructor;
if (declarationDescriptor instanceof TypeParameterDescriptor) {
TypeParameterDescriptor typeParameterDescriptor = (TypeParameterDescriptor) declarationDescriptor;
builder.setKind(ProtoBuf.Type.Constructor.Kind.TYPE_PARAMETER);
builder.setId(getTypeParameterId(typeParameterDescriptor));
}
else {
ClassDescriptor classDescriptor = (ClassDescriptor) declarationDescriptor;
//default: builder.setKind(Type.Constructor.Kind.CLASS);
builder.setId(getClassId(classDescriptor));
}
return builder;
}
@NotNull
public ProtoBuf.Package.Builder packageProto(@NotNull Collection<PackageFragmentDescriptor> fragments) {
return packageProto(fragments, null);
@@ -16,34 +16,30 @@
package org.jetbrains.kotlin.checkers
import org.jetbrains.kotlin.descriptors.Named
import org.jetbrains.kotlin.load.java.structure.JavaNamedElement
import org.jetbrains.kotlin.load.java.structure.impl.JavaClassImpl
import org.jetbrains.kotlin.load.java.structure.impl.JavaTypeImpl
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.descriptors.Named
import java.util.IdentityHashMap
import org.jetbrains.kotlin.resolve.scopes.JetScope
import org.jetbrains.kotlin.load.java.structure.impl.JavaTypeImpl
import org.jetbrains.kotlin.load.java.structure.impl.JavaClassImpl
import java.util.ArrayList
import org.jetbrains.kotlin.utils.Printer
import org.jetbrains.kotlin.load.java.structure.JavaNamedElement
import org.jetbrains.kotlin.serialization.ProtoBuf
import org.jetbrains.kotlin.serialization.deserialization.TypeDeserializer
import org.jetbrains.kotlin.serialization.deserialization.DeserializationContext
import org.jetbrains.kotlin.types.JetType
import org.jetbrains.kotlin.resolve.DescriptorUtils
import java.util.HashMap
import org.jetbrains.kotlin.types.JetTypeImpl
import java.util.regex.Pattern
import org.jetbrains.kotlin.resolve.calls.tasks.ResolutionTaskHolder
import org.jetbrains.kotlin.renderer.DescriptorRenderer
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
import org.jetbrains.kotlin.psi.debugText.getDebugText
import org.jetbrains.kotlin.renderer.DescriptorRenderer
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
import org.jetbrains.kotlin.resolve.calls.tasks.ResolutionCandidate
import org.jetbrains.kotlin.serialization.deserialization.TypeConstructorKind
import org.jetbrains.kotlin.serialization.deserialization.getTypeConstructorData
import org.jetbrains.kotlin.resolve.calls.tasks.ResolutionTaskHolder
import org.jetbrains.kotlin.resolve.scopes.JetScope
import org.jetbrains.kotlin.serialization.ProtoBuf
import org.jetbrains.kotlin.serialization.deserialization.DeserializationContext
import org.jetbrains.kotlin.serialization.deserialization.TypeDeserializer
import org.jetbrains.kotlin.types.JetType
import org.jetbrains.kotlin.types.JetTypeImpl
import org.jetbrains.kotlin.utils.Printer
import java.lang.reflect.Constructor
import java.lang.reflect.GenericDeclaration
import java.lang.reflect.Method
import java.lang.reflect.Constructor
import java.util.*
import java.util.regex.Pattern
class LazyOperationsLog(
val stringSanitizer: (String) -> String
@@ -160,12 +156,11 @@ class LazyOperationsLog(
val typeDeserializer = o.field<TypeDeserializer>("typeDeserializer")
val context = typeDeserializer.field<DeserializationContext>("c")
val typeProto = o.field<ProtoBuf.Type>("typeProto")
val typeConstructorData = typeProto.getTypeConstructorData()
val text = when (typeConstructorData.kind) {
TypeConstructorKind.CLASS -> context.nameResolver.getFqName(typeConstructorData.id).asString()
TypeConstructorKind.TYPE_PARAMETER -> {
val classifier = (o as JetType).getConstructor().getDeclarationDescriptor()!!
"" + classifier.getName() + " in " + DescriptorUtils.getFqName(classifier.getContainingDeclaration())
val text = when {
typeProto.hasClassName() -> context.nameResolver.getFqName(typeProto.className).asString()
typeProto.hasTypeParameter() -> {
val classifier = (o as JetType).constructor.declarationDescriptor!!
"" + classifier.name + " in " + DescriptorUtils.getFqName(classifier.containingDeclaration)
}
else -> "???"
}
File diff suppressed because it is too large Load Diff
@@ -34,7 +34,7 @@ public final class JvmAbi {
* - Patch version can be increased freely and is only supposed to be used for debugging. Increase the patch version when you
* make a change to the metadata format or the bytecode which is both forward- and backward compatible.
*/
public static final BinaryVersion VERSION = BinaryVersion.create(0, 25, 0);
public static final BinaryVersion VERSION = BinaryVersion.create(0, 26, 0);
public static final String TRAIT_IMPL_CLASS_NAME = "$TImpl";
public static final String TRAIT_IMPL_SUFFIX = "$" + TRAIT_IMPL_CLASS_NAME;
+2 -17
View File
@@ -101,19 +101,6 @@ message Annotation {
}
message Type {
message Constructor {
enum Kind {
CLASS = 0;
TYPE_PARAMETER = 1;
}
optional Kind kind = 1 [default = CLASS, (skip_in_comparison) = true];
required int32 id = 2 [(skip_in_comparison) = true]; // CLASS - fqName id, TYPE_PARAMETER - type parameter id
}
required Constructor constructor = 1 [(skip_in_comparison) = true];
message Argument {
enum Projection {
IN = 0;
@@ -142,10 +129,8 @@ message Type {
// Only one of the following values should be present. Consider using `oneof` instead when we upgrade to protobuf 2.6.0+
optional int32 constructor_class_name = 6 [(fq_name_id_in_table) = true]; // fqName id
optional int32 constructor_type_parameter = 7; // type parameter id
optional int32 class_name = 6 [(fq_name_id_in_table) = true]; // fqName id
optional int32 type_parameter = 7; // type parameter id
extensions 100 to 199;
}
File diff suppressed because it is too large Load Diff
@@ -30,7 +30,7 @@ class DeserializedType(
private val typeProto: ProtoBuf.Type,
private val additionalAnnotations: Annotations = Annotations.EMPTY
) : AbstractLazyType(c.storageManager), LazyType {
private val typeDeserializer = c.typeDeserializer
private val typeDeserializer: TypeDeserializer get() = c.typeDeserializer
override fun computeTypeConstructor() = typeDeserializer.typeConstructor(typeProto)
@@ -57,12 +57,5 @@ class DeserializedType(
override fun getCapabilities() = c.components.typeCapabilitiesLoader.loadCapabilities(typeProto)
fun getPresentableText(): String {
val typeConstructorData = typeProto.getTypeConstructorData()
val id = typeConstructorData.id
return if (typeConstructorData.kind == TypeConstructorKind.CLASS)
c.nameResolver.getClassId(id).asSingleFqName().asString()
else
"Unknown type parameter $id"
}
fun getPresentableText(): String = typeDeserializer.presentableTextForErrorType(typeProto)
}
@@ -23,32 +23,7 @@ import org.jetbrains.kotlin.serialization.ProtoBuf
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedTypeParameterDescriptor
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.utils.toReadOnlyList
import java.util.LinkedHashMap
public enum class TypeConstructorKind {
CLASS,
TYPE_PARAMETER
}
public data class TypeConstructorData(val kind: TypeConstructorKind, val id: Int)
public fun ProtoBuf.Type.getTypeConstructorData(): TypeConstructorData {
if (hasConstructorClassName()) {
assert(!hasConstructorTypeParameter(), "constructor_class_name already presents, so constructor_type_parameter should not be here")
return TypeConstructorData(TypeConstructorKind.CLASS, constructorClassName)
}
else if (hasConstructorTypeParameter()) {
assert(!hasConstructorClassName(), "constructor_type_parameter already presents, so constructor_class_name should not be here")
return TypeConstructorData(TypeConstructorKind.TYPE_PARAMETER, constructorTypeParameter)
}
else {
return when (constructor.kind) {
ProtoBuf.Type.Constructor.Kind.CLASS -> TypeConstructorData(TypeConstructorKind.CLASS, constructor.id)
ProtoBuf.Type.Constructor.Kind.TYPE_PARAMETER -> TypeConstructorData(TypeConstructorKind.TYPE_PARAMETER, constructor.id)
else -> throw IllegalStateException("Unknown kind ${constructor.kind}")
}
}
}
import java.util.*
public class TypeDeserializer(
private val c: DeserializationContext,
@@ -95,20 +70,23 @@ public class TypeDeserializer(
return DeserializedType(c, proto, additionalAnnotations)
}
fun typeConstructor(proto: ProtoBuf.Type): TypeConstructor {
val typeConstructorData = proto.getTypeConstructorData()
val id = typeConstructorData.id
return typeConstructor(typeConstructorData) ?: ErrorUtils.createErrorType(
if (typeConstructorData.kind == TypeConstructorKind.CLASS)
c.nameResolver.getClassId(id).asSingleFqName().asString()
else
"Unknown type parameter $id"
).constructor
}
fun typeConstructor(proto: ProtoBuf.Type): TypeConstructor =
when {
proto.hasClassName() ->
classDescriptors(proto.className)?.typeConstructor
proto.hasTypeParameter() ->
typeParameterTypeConstructor(proto.typeParameter)
else ->
null
} ?: ErrorUtils.createErrorType(presentableTextForErrorType(proto)).constructor
private fun typeConstructor(data: TypeConstructorData): TypeConstructor? = when (data.kind) {
TypeConstructorKind.CLASS -> classDescriptors(data.id)?.typeConstructor
TypeConstructorKind.TYPE_PARAMETER -> typeParameterTypeConstructor(data.id)
internal fun presentableTextForErrorType(proto: ProtoBuf.Type): String = when {
proto.hasClassName() ->
c.nameResolver.getClassId(proto.className).asSingleFqName().asString()
proto.hasTypeParameter() ->
"Unknown type parameter ${proto.typeParameter}"
else ->
"Unknown type"
}
private fun typeParameterTypeConstructor(typeParameterId: Int): TypeConstructor? =
@@ -37,9 +37,6 @@ import org.jetbrains.kotlin.psi.stubs.impl.KotlinPlaceHolderStubImpl
import org.jetbrains.kotlin.serialization.Flags
import org.jetbrains.kotlin.serialization.ProtoBuf
import org.jetbrains.kotlin.serialization.deserialization.ProtoContainer
import org.jetbrains.kotlin.serialization.deserialization.TypeConstructorKind
import org.jetbrains.kotlin.serialization.deserialization.getTypeConstructorData
fun createClassStub(parent: StubElement<out PsiElement>, classProto: ProtoBuf.Class, classId: ClassId, context: ClsStubBuilderContext) {
ClassClsStubBuilder(parent, classProto, classId, context).build()
@@ -54,13 +51,8 @@ private class ClassClsStubBuilder(
private val c = outerContext.child(classProto.getTypeParameterList(), classId.getShortClassName())
private val typeStubBuilder = TypeClsStubBuilder(c)
private val classKind = Flags.CLASS_KIND[classProto.getFlags()]
private val supertypeIds = classProto.getSupertypeList().map {
type ->
val typeConstructorData = type.getTypeConstructorData()
assert(typeConstructorData.kind == TypeConstructorKind.CLASS)
c.nameResolver.getClassId(typeConstructorData.id)
}.let {
supertypeIds ->
private val supertypeIds = run {
val supertypeIds = classProto.supertypeList.map { c.nameResolver.getClassId(it.className) }
//empty supertype list if single supertype is Any
if (supertypeIds.singleOrNull()?.let { KotlinBuiltIns.isAny(it.asSingleFqName().toUnsafe()) } ?: false) {
listOf()
@@ -36,11 +36,9 @@ import org.jetbrains.kotlin.serialization.ProtoBuf.Type
import org.jetbrains.kotlin.serialization.ProtoBuf.Type.Argument.Projection
import org.jetbrains.kotlin.serialization.ProtoBuf.TypeParameter.Variance
import org.jetbrains.kotlin.serialization.deserialization.ProtoContainer
import org.jetbrains.kotlin.serialization.deserialization.TypeConstructorKind
import org.jetbrains.kotlin.serialization.deserialization.getTypeConstructorData
import org.jetbrains.kotlin.types.DynamicTypeCapabilities
import org.jetbrains.kotlin.utils.addToStdlib.singletonOrEmptyList
import java.util.ArrayList
import java.util.*
class TypeClsStubBuilder(private val c: ClsStubBuilderContext) {
@@ -56,14 +54,12 @@ class TypeClsStubBuilder(private val c: ClsStubBuilderContext) {
if (type.getNullable()) KotlinPlaceHolderStubImpl<JetNullableType>(typeReference, JetStubElementTypes.NULLABLE_TYPE)
else typeReference
val typeConstructorData = type.getTypeConstructorData()
when (typeConstructorData.kind) {
TypeConstructorKind.CLASS -> {
when {
type.hasClassName() ->
createClassReferenceTypeStub(effectiveParent, type, annotations)
}
TypeConstructorKind.TYPE_PARAMETER -> {
type.hasTypeParameter() -> {
createTypeAnnotationStubs(effectiveParent, annotations)
val typeParameterName = c.typeParameters[typeConstructorData.id]
val typeParameterName = c.typeParameters[type.typeParameter]
createStubForTypeName(ClassId.topLevel(FqName.topLevel(typeParameterName)), effectiveParent)
}
}
@@ -79,7 +75,7 @@ class TypeClsStubBuilder(private val c: ClsStubBuilderContext) {
}
}
val classId = c.nameResolver.getClassId(type.getConstructor().getId())
val classId = c.nameResolver.getClassId(type.className)
val shouldBuildAsFunctionType = KotlinBuiltIns.isNumberedFunctionClassFqName(classId.asSingleFqName().toUnsafe())
&& type.getArgumentList().none { it.getProjection() == Projection.STAR }
if (shouldBuildAsFunctionType) {
@@ -240,11 +236,8 @@ class TypeClsStubBuilder(private val c: ClsStubBuilderContext) {
}
private fun Type.isDefaultUpperBound(): Boolean {
val typeConstructorData = getTypeConstructorData()
if (typeConstructorData.kind != TypeConstructorKind.CLASS) {
return false
}
val classId = c.nameResolver.getClassId(typeConstructorData.id)
return KotlinBuiltIns.isAny(classId.asSingleFqName().toUnsafe()) && this.nullable
return this.hasClassName() &&
c.nameResolver.getClassId(className).let { KotlinBuiltIns.isAny(it.asSingleFqName().toUnsafe()) } &&
this.nullable
}
}
@@ -232,14 +232,14 @@ open class ProtoCompareGenerated(public val oldNameResolver: NameResolver, publi
if (!checkEquals(old.flexibleUpperBound, new.flexibleUpperBound)) return false
}
if (old.hasConstructorClassName() != new.hasConstructorClassName()) return false
if (old.hasConstructorClassName()) {
if (!checkClassIdEquals(old.constructorClassName, new.constructorClassName)) return false
if (old.hasClassName() != new.hasClassName()) return false
if (old.hasClassName()) {
if (!checkClassIdEquals(old.className, new.className)) return false
}
if (old.hasConstructorTypeParameter() != new.hasConstructorTypeParameter()) return false
if (old.hasConstructorTypeParameter()) {
if (old.constructorTypeParameter != new.constructorTypeParameter) return false
if (old.hasTypeParameter() != new.hasTypeParameter()) return false
if (old.hasTypeParameter()) {
if (old.typeParameter != new.typeParameter) return false
}
if (old.getExtensionCount(JvmProtoBuf.typeAnnotation) != new.getExtensionCount(JvmProtoBuf.typeAnnotation)) return false
@@ -746,12 +746,12 @@ public fun ProtoBuf.Type.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes: (I
hashCode = 31 * hashCode + flexibleUpperBound.hashCode(stringIndexes, fqNameIndexes)
}
if (hasConstructorClassName()) {
hashCode = 31 * hashCode + fqNameIndexes(constructorClassName)
if (hasClassName()) {
hashCode = 31 * hashCode + fqNameIndexes(className)
}
if (hasConstructorTypeParameter()) {
hashCode = 31 * hashCode + constructorTypeParameter
if (hasTypeParameter()) {
hashCode = 31 * hashCode + typeParameter
}
for(i in 0..getExtensionCount(JvmProtoBuf.typeAnnotation) - 1) {