From 4c211426485d19feb550d40366a5e408dc27b417 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Fri, 9 Oct 2015 04:47:16 +0300 Subject: [PATCH] Store type parameter names sometimes instead of ids This helps to reuse instances of types when TypeTable is enabled in cases when a file or a class contains a lot of functions with type parameters with the same name (like Maps.kt in the stdlib with "Map") --- .../serialization/DescriptorSerializer.java | 29 +- .../kotlin/serialization/DebugProtoBuf.java | 269 +++++++++++++----- core/deserialization/src/descriptors.proto | 2 + .../kotlin/serialization/ProtoBuf.java | 113 ++++++++ .../deserialization/TypeDeserializer.kt | 14 + .../stubBuilder/TypeClsStubBuilder.kt | 15 +- .../jps/incremental/ProtoCompareGenerated.kt | 9 + 7 files changed, 358 insertions(+), 93 deletions(-) diff --git a/compiler/serialization/src/org/jetbrains/kotlin/serialization/DescriptorSerializer.java b/compiler/serialization/src/org/jetbrains/kotlin/serialization/DescriptorSerializer.java index 25735484b80..1d426efb288 100644 --- a/compiler/serialization/src/org/jetbrains/kotlin/serialization/DescriptorSerializer.java +++ b/compiler/serialization/src/org/jetbrains/kotlin/serialization/DescriptorSerializer.java @@ -39,17 +39,20 @@ import java.util.*; import static org.jetbrains.kotlin.resolve.DescriptorUtils.isEnumEntry; public class DescriptorSerializer { + private final DeclarationDescriptor containingDeclaration; private final Interner typeParameters; private final SerializerExtension extension; private final MutableTypeTable typeTable; private final boolean serializeTypeTableToFunction; private DescriptorSerializer( + @Nullable DeclarationDescriptor containingDeclaration, @NotNull Interner typeParameters, @NotNull SerializerExtension extension, @NotNull MutableTypeTable typeTable, boolean serializeTypeTableToFunction ) { + this.containingDeclaration = containingDeclaration; this.typeParameters = typeParameters; this.extension = extension; this.typeTable = typeTable; @@ -71,12 +74,12 @@ public class DescriptorSerializer { @NotNull public static DescriptorSerializer createTopLevel(@NotNull SerializerExtension extension) { - return new DescriptorSerializer(new Interner(), extension, new MutableTypeTable(), false); + return new DescriptorSerializer(null, new Interner(), extension, new MutableTypeTable(), false); } @NotNull public static DescriptorSerializer createForLambda(@NotNull SerializerExtension extension) { - return new DescriptorSerializer(new Interner(), extension, new MutableTypeTable(), true); + return new DescriptorSerializer(null, new Interner(), extension, new MutableTypeTable(), true); } @NotNull @@ -91,6 +94,7 @@ public class DescriptorSerializer { // serializing outer classes before nested classes. // Otherwise our interner can get wrong ids because we may serialize classes in any order. DescriptorSerializer serializer = new DescriptorSerializer( + descriptor, new Interner(parentSerializer.typeParameters), parentSerializer.extension, new MutableTypeTable(), @@ -103,8 +107,8 @@ public class DescriptorSerializer { } @NotNull - private DescriptorSerializer createChildSerializer() { - return new DescriptorSerializer(new Interner(typeParameters), extension, typeTable, false); + private DescriptorSerializer createChildSerializer(@NotNull CallableDescriptor callable) { + return new DescriptorSerializer(callable, new Interner(typeParameters), extension, typeTable, false); } @NotNull @@ -191,7 +195,7 @@ public class DescriptorSerializer { public ProtoBuf.Property.Builder propertyProto(@NotNull PropertyDescriptor descriptor) { ProtoBuf.Property.Builder builder = ProtoBuf.Property.newBuilder(); - DescriptorSerializer local = createChildSerializer(); + DescriptorSerializer local = createChildSerializer(descriptor); boolean hasGetter = false; boolean hasSetter = false; @@ -228,8 +232,9 @@ public class DescriptorSerializer { } if (!setter.isDefault()) { + DescriptorSerializer setterLocal = local.createChildSerializer(setter); for (ValueParameterDescriptor valueParameterDescriptor : setter.getValueParameters()) { - builder.setSetterValueParameter(local.valueParameter(valueParameterDescriptor)); + builder.setSetterValueParameter(setterLocal.valueParameter(valueParameterDescriptor)); } } } @@ -274,7 +279,7 @@ public class DescriptorSerializer { public ProtoBuf.Function.Builder functionProto(@NotNull FunctionDescriptor descriptor) { ProtoBuf.Function.Builder builder = ProtoBuf.Function.newBuilder(); - DescriptorSerializer local = createChildSerializer(); + DescriptorSerializer local = createChildSerializer(descriptor); int flags = Flags.getFunctionFlags( hasAnnotations(descriptor), descriptor.getVisibility(), descriptor.getModality(), descriptor.getKind(), @@ -329,7 +334,7 @@ public class DescriptorSerializer { public ProtoBuf.Constructor.Builder constructorProto(@NotNull ConstructorDescriptor descriptor) { ProtoBuf.Constructor.Builder builder = ProtoBuf.Constructor.newBuilder(); - DescriptorSerializer local = createChildSerializer(); + DescriptorSerializer local = createChildSerializer(descriptor); int flags = Flags.getConstructorFlags(hasAnnotations(descriptor), descriptor.getVisibility(), !descriptor.isPrimary()); if (flags != builder.getFlags()) { @@ -459,7 +464,13 @@ public class DescriptorSerializer { builder.setClassName(getClassId((ClassDescriptor) descriptor)); } if (descriptor instanceof TypeParameterDescriptor) { - builder.setTypeParameter(getTypeParameterId((TypeParameterDescriptor) descriptor)); + TypeParameterDescriptor typeParameter = (TypeParameterDescriptor) descriptor; + if (typeParameter.getContainingDeclaration() == containingDeclaration) { + builder.setTypeParameterName(getSimpleNameIndex(typeParameter.getName())); + } + else { + builder.setTypeParameter(getTypeParameterId(typeParameter)); + } } for (TypeProjection projection : type.getArguments()) { diff --git a/compiler/tests/org/jetbrains/kotlin/serialization/DebugProtoBuf.java b/compiler/tests/org/jetbrains/kotlin/serialization/DebugProtoBuf.java index 73c9768c954..5462b9f9707 100644 --- a/compiler/tests/org/jetbrains/kotlin/serialization/DebugProtoBuf.java +++ b/compiler/tests/org/jetbrains/kotlin/serialization/DebugProtoBuf.java @@ -5461,6 +5461,24 @@ public final class DebugProtoBuf { * */ int getTypeParameter(); + + // optional int32 type_parameter_name = 9; + /** + * optional int32 type_parameter_name = 9; + * + *
+     * Name of the type parameter in the immediate owner
+     * 
+ */ + boolean hasTypeParameterName(); + /** + * optional int32 type_parameter_name = 9; + * + *
+     * Name of the type parameter in the immediate owner
+     * 
+ */ + int getTypeParameterName(); } /** * Protobuf type {@code org.jetbrains.kotlin.serialization.Type} @@ -5559,6 +5577,11 @@ public final class DebugProtoBuf { flexibleUpperBoundId_ = input.readInt32(); break; } + case 72: { + bitField0_ |= 0x00000040; + typeParameterName_ = input.readInt32(); + break; + } } } } catch (com.google.protobuf.InvalidProtocolBufferException e) { @@ -6608,6 +6631,30 @@ public final class DebugProtoBuf { return typeParameter_; } + // optional int32 type_parameter_name = 9; + public static final int TYPE_PARAMETER_NAME_FIELD_NUMBER = 9; + private int typeParameterName_; + /** + * optional int32 type_parameter_name = 9; + * + *
+     * Name of the type parameter in the immediate owner
+     * 
+ */ + public boolean hasTypeParameterName() { + return ((bitField0_ & 0x00000040) == 0x00000040); + } + /** + * optional int32 type_parameter_name = 9; + * + *
+     * Name of the type parameter in the immediate owner
+     * 
+ */ + public int getTypeParameterName() { + return typeParameterName_; + } + private void initFields() { argument_ = java.util.Collections.emptyList(); nullable_ = false; @@ -6616,6 +6663,7 @@ public final class DebugProtoBuf { flexibleUpperBoundId_ = 0; className_ = 0; typeParameter_ = 0; + typeParameterName_ = 0; } private byte memoizedIsInitialized = -1; public final boolean isInitialized() { @@ -6669,6 +6717,9 @@ public final class DebugProtoBuf { if (((bitField0_ & 0x00000008) == 0x00000008)) { output.writeInt32(8, flexibleUpperBoundId_); } + if (((bitField0_ & 0x00000040) == 0x00000040)) { + output.writeInt32(9, typeParameterName_); + } extensionWriter.writeUntil(200, output); getUnknownFields().writeTo(output); } @@ -6707,6 +6758,10 @@ public final class DebugProtoBuf { size += com.google.protobuf.CodedOutputStream .computeInt32Size(8, flexibleUpperBoundId_); } + if (((bitField0_ & 0x00000040) == 0x00000040)) { + size += com.google.protobuf.CodedOutputStream + .computeInt32Size(9, typeParameterName_); + } size += extensionsSerializedSize(); size += getUnknownFields().getSerializedSize(); memoizedSerializedSize = size; @@ -6848,6 +6903,8 @@ public final class DebugProtoBuf { bitField0_ = (bitField0_ & ~0x00000020); typeParameter_ = 0; bitField0_ = (bitField0_ & ~0x00000040); + typeParameterName_ = 0; + bitField0_ = (bitField0_ & ~0x00000080); return this; } @@ -6913,6 +6970,10 @@ public final class DebugProtoBuf { to_bitField0_ |= 0x00000020; } result.typeParameter_ = typeParameter_; + if (((from_bitField0_ & 0x00000080) == 0x00000080)) { + to_bitField0_ |= 0x00000040; + } + result.typeParameterName_ = typeParameterName_; result.bitField0_ = to_bitField0_; onBuilt(); return result; @@ -6973,6 +7034,9 @@ public final class DebugProtoBuf { if (other.hasTypeParameter()) { setTypeParameter(other.getTypeParameter()); } + if (other.hasTypeParameterName()) { + setTypeParameterName(other.getTypeParameterName()); + } this.mergeExtensionFields(other); this.mergeUnknownFields(other.getUnknownFields()); return this; @@ -7575,6 +7639,55 @@ public final class DebugProtoBuf { return this; } + // optional int32 type_parameter_name = 9; + private int typeParameterName_ ; + /** + * optional int32 type_parameter_name = 9; + * + *
+       * Name of the type parameter in the immediate owner
+       * 
+ */ + public boolean hasTypeParameterName() { + return ((bitField0_ & 0x00000080) == 0x00000080); + } + /** + * optional int32 type_parameter_name = 9; + * + *
+       * Name of the type parameter in the immediate owner
+       * 
+ */ + public int getTypeParameterName() { + return typeParameterName_; + } + /** + * optional int32 type_parameter_name = 9; + * + *
+       * Name of the type parameter in the immediate owner
+       * 
+ */ + public Builder setTypeParameterName(int value) { + bitField0_ |= 0x00000080; + typeParameterName_ = value; + onChanged(); + return this; + } + /** + * optional int32 type_parameter_name = 9; + * + *
+       * Name of the type parameter in the immediate owner
+       * 
+ */ + public Builder clearTypeParameterName() { + bitField0_ = (bitField0_ & ~0x00000080); + typeParameterName_ = 0; + onChanged(); + return this; + } + // @@protoc_insertion_point(builder_scope:org.jetbrains.kotlin.serialization.Type) } @@ -20494,7 +20607,7 @@ public final class DebugProtoBuf { "\n\004BYTE\020\000\022\010\n\004CHAR\020\001\022\t\n\005SHORT\020\002\022\007\n\003INT\020\003\022\010" + "\n\004LONG\020\004\022\t\n\005FLOAT\020\005\022\n\n\006DOUBLE\020\006\022\013\n\007BOOLE", "AN\020\007\022\n\n\006STRING\020\010\022\t\n\005CLASS\020\t\022\010\n\004ENUM\020\n\022\016\n" + - "\nANNOTATION\020\013\022\t\n\005ARRAY\020\014\"\222\004\n\004Type\022C\n\010arg" + + "\nANNOTATION\020\013\022\t\n\005ARRAY\020\014\"\265\004\n\004Type\022C\n\010arg" + "ument\030\002 \003(\01321.org.jetbrains.kotlin.seria" + "lization.Type.Argument\022\027\n\010nullable\030\003 \001(\010" + ":\005false\022+\n\035flexible_type_capabilities_id" + @@ -20502,83 +20615,84 @@ public final class DebugProtoBuf { "(\0132(.org.jetbrains.kotlin.serialization." + "Type\022\037\n\027flexible_upper_bound_id\030\010 \001(\005\022\030\n" + "\nclass_name\030\006 \001(\005B\004\220\265\030\001\022\026\n\016type_paramete" + - "r\030\007 \001(\005\032\334\001\n\010Argument\022U\n\nprojection\030\001 \001(\016", - "2<.org.jetbrains.kotlin.serialization.Ty" + - "pe.Argument.Projection:\003INV\0226\n\004type\030\002 \001(" + + "r\030\007 \001(\005\022!\n\023type_parameter_name\030\t \001(\005B\004\210\265", + "\030\001\032\334\001\n\010Argument\022U\n\nprojection\030\001 \001(\0162<.or" + + "g.jetbrains.kotlin.serialization.Type.Ar" + + "gument.Projection:\003INV\0226\n\004type\030\002 \001(\0132(.o" + + "rg.jetbrains.kotlin.serialization.Type\022\017" + + "\n\007type_id\030\003 \001(\005\"0\n\nProjection\022\006\n\002IN\020\000\022\007\n" + + "\003OUT\020\001\022\007\n\003INV\020\002\022\010\n\004STAR\020\003*\005\010d\020\310\001\"\227\002\n\rTyp" + + "eParameter\022\n\n\002id\030\001 \002(\005\022\022\n\004name\030\002 \002(\005B\004\210\265" + + "\030\001\022\026\n\007reified\030\003 \001(\010:\005false\022Q\n\010variance\030\004" + + " \001(\0162:.org.jetbrains.kotlin.serializatio" + + "n.TypeParameter.Variance:\003INV\022=\n\013upper_b", + "ound\030\005 \003(\0132(.org.jetbrains.kotlin.serial" + + "ization.Type\022\026\n\016upper_bound_id\030\006 \003(\005\"$\n\010" + + "Variance\022\006\n\002IN\020\000\022\007\n\003OUT\020\001\022\007\n\003INV\020\002\"\300\005\n\005C" + + "lass\022\020\n\005flags\030\001 \001(\005:\0016\022\025\n\007fq_name\030\003 \002(\005B" + + "\004\220\265\030\001\022#\n\025companion_object_name\030\004 \001(\005B\004\210\265" + + "\030\001\022I\n\016type_parameter\030\005 \003(\01321.org.jetbrai" + + "ns.kotlin.serialization.TypeParameter\022;\n" + + "\tsupertype\030\006 \003(\0132(.org.jetbrains.kotlin." + + "serialization.Type\022\030\n\014supertype_id\030\002 \003(\005" + + "B\002\020\001\022!\n\021nested_class_name\030\007 \003(\005B\006\020\001\210\265\030\001\022", + "D\n\013constructor\030\010 \003(\0132/.org.jetbrains.kot" + + "lin.serialization.Constructor\022>\n\010functio" + + "n\030\t \003(\0132,.org.jetbrains.kotlin.serializa" + + "tion.Function\022>\n\010property\030\n \003(\0132,.org.je" + + "tbrains.kotlin.serialization.Property\022\032\n" + + "\nenum_entry\030\014 \003(\005B\006\020\001\210\265\030\001\022A\n\ntype_table\030" + + "\036 \001(\0132-.org.jetbrains.kotlin.serializati" + + "on.TypeTable\"x\n\004Kind\022\t\n\005CLASS\020\000\022\r\n\tINTER" + + "FACE\020\001\022\016\n\nENUM_CLASS\020\002\022\016\n\nENUM_ENTRY\020\003\022\024" + + "\n\020ANNOTATION_CLASS\020\004\022\n\n\006OBJECT\020\005\022\024\n\020COMP", + "ANION_OBJECT\020\006*\005\010d\020\310\001\"\323\001\n\007Package\022>\n\010fun" + + "ction\030\003 \003(\0132,.org.jetbrains.kotlin.seria" + + "lization.Function\022>\n\010property\030\004 \003(\0132,.or" + + "g.jetbrains.kotlin.serialization.Propert" + + "y\022A\n\ntype_table\030\036 \001(\0132-.org.jetbrains.ko" + + "tlin.serialization.TypeTable*\005\010d\020\310\001\"_\n\tT" + + "ypeTable\0226\n\004type\030\001 \003(\0132(.org.jetbrains.k" + + "otlin.serialization.Type\022\032\n\016first_nullab" + + "le\030\002 \001(\005:\002-1\"s\n\013Constructor\022\020\n\005flags\030\001 \001" + + "(\005:\0016\022K\n\017value_parameter\030\002 \003(\01322.org.jet", + "brains.kotlin.serialization.ValueParamet" + + "er*\005\010d\020\310\001\"\304\003\n\010Function\022\020\n\005flags\030\001 \001(\005:\0016" + + "\022\022\n\004name\030\002 \002(\005B\004\210\265\030\001\022=\n\013return_type\030\003 \001(" + "\0132(.org.jetbrains.kotlin.serialization.T" + - "ype\022\017\n\007type_id\030\003 \001(\005\"0\n\nProjection\022\006\n\002IN" + - "\020\000\022\007\n\003OUT\020\001\022\007\n\003INV\020\002\022\010\n\004STAR\020\003*\005\010d\020\310\001\"\227\002" + - "\n\rTypeParameter\022\n\n\002id\030\001 \002(\005\022\022\n\004name\030\002 \002(" + - "\005B\004\210\265\030\001\022\026\n\007reified\030\003 \001(\010:\005false\022Q\n\010varia" + - "nce\030\004 \001(\0162:.org.jetbrains.kotlin.seriali" + - "zation.TypeParameter.Variance:\003INV\022=\n\013up" + - "per_bound\030\005 \003(\0132(.org.jetbrains.kotlin.s", - "erialization.Type\022\026\n\016upper_bound_id\030\006 \003(" + - "\005\"$\n\010Variance\022\006\n\002IN\020\000\022\007\n\003OUT\020\001\022\007\n\003INV\020\002\"" + - "\300\005\n\005Class\022\020\n\005flags\030\001 \001(\005:\0016\022\025\n\007fq_name\030\003" + - " \002(\005B\004\220\265\030\001\022#\n\025companion_object_name\030\004 \001(" + - "\005B\004\210\265\030\001\022I\n\016type_parameter\030\005 \003(\01321.org.je" + - "tbrains.kotlin.serialization.TypeParamet" + - "er\022;\n\tsupertype\030\006 \003(\0132(.org.jetbrains.ko" + - "tlin.serialization.Type\022\030\n\014supertype_id\030" + - "\002 \003(\005B\002\020\001\022!\n\021nested_class_name\030\007 \003(\005B\006\020\001" + - "\210\265\030\001\022D\n\013constructor\030\010 \003(\0132/.org.jetbrain", - "s.kotlin.serialization.Constructor\022>\n\010fu" + - "nction\030\t \003(\0132,.org.jetbrains.kotlin.seri" + - "alization.Function\022>\n\010property\030\n \003(\0132,.o" + - "rg.jetbrains.kotlin.serialization.Proper" + - "ty\022\032\n\nenum_entry\030\014 \003(\005B\006\020\001\210\265\030\001\022A\n\ntype_t" + + "ype\022\026\n\016return_type_id\030\007 \001(\005\022I\n\016type_para" + + "meter\030\004 \003(\01321.org.jetbrains.kotlin.seria" + + "lization.TypeParameter\022?\n\rreceiver_type\030" + + "\005 \001(\0132(.org.jetbrains.kotlin.serializati" + + "on.Type\022\030\n\020receiver_type_id\030\010 \001(\005\022K\n\017val" + + "ue_parameter\030\006 \003(\01322.org.jetbrains.kotli", + "n.serialization.ValueParameter\022A\n\ntype_t" + "able\030\036 \001(\0132-.org.jetbrains.kotlin.serial" + - "ization.TypeTable\"x\n\004Kind\022\t\n\005CLASS\020\000\022\r\n\t" + - "INTERFACE\020\001\022\016\n\nENUM_CLASS\020\002\022\016\n\nENUM_ENTR" + - "Y\020\003\022\024\n\020ANNOTATION_CLASS\020\004\022\n\n\006OBJECT\020\005\022\024\n" + - "\020COMPANION_OBJECT\020\006*\005\010d\020\310\001\"\323\001\n\007Package\022>", - "\n\010function\030\003 \003(\0132,.org.jetbrains.kotlin." + - "serialization.Function\022>\n\010property\030\004 \003(\013" + - "2,.org.jetbrains.kotlin.serialization.Pr" + - "operty\022A\n\ntype_table\030\036 \001(\0132-.org.jetbrai" + - "ns.kotlin.serialization.TypeTable*\005\010d\020\310\001" + - "\"_\n\tTypeTable\0226\n\004type\030\001 \003(\0132(.org.jetbra" + - "ins.kotlin.serialization.Type\022\032\n\016first_n" + - "ullable\030\002 \001(\005:\002-1\"s\n\013Constructor\022\020\n\005flag" + - "s\030\001 \001(\005:\0016\022K\n\017value_parameter\030\002 \003(\01322.or" + - "g.jetbrains.kotlin.serialization.ValuePa", - "rameter*\005\010d\020\310\001\"\304\003\n\010Function\022\020\n\005flags\030\001 \001" + - "(\005:\0016\022\022\n\004name\030\002 \002(\005B\004\210\265\030\001\022=\n\013return_type" + - "\030\003 \001(\0132(.org.jetbrains.kotlin.serializat" + - "ion.Type\022\026\n\016return_type_id\030\007 \001(\005\022I\n\016type" + - "_parameter\030\004 \003(\01321.org.jetbrains.kotlin." + - "serialization.TypeParameter\022?\n\rreceiver_" + - "type\030\005 \001(\0132(.org.jetbrains.kotlin.serial" + - "ization.Type\022\030\n\020receiver_type_id\030\010 \001(\005\022K" + - "\n\017value_parameter\030\006 \003(\01322.org.jetbrains." + - "kotlin.serialization.ValueParameter\022A\n\nt", - "ype_table\030\036 \001(\0132-.org.jetbrains.kotlin.s" + - "erialization.TypeTable*\005\010d\020\310\001\"\266\003\n\010Proper" + - "ty\022\022\n\005flags\030\001 \001(\005:\003262\022\022\n\004name\030\002 \002(\005B\004\210\265" + - "\030\001\022=\n\013return_type\030\003 \001(\0132(.org.jetbrains." + - "kotlin.serialization.Type\022\026\n\016return_type" + - "_id\030\t \001(\005\022I\n\016type_parameter\030\004 \003(\01321.org." + - "jetbrains.kotlin.serialization.TypeParam" + - "eter\022?\n\rreceiver_type\030\005 \001(\0132(.org.jetbra" + - "ins.kotlin.serialization.Type\022\030\n\020receive" + - "r_type_id\030\n \001(\005\022R\n\026setter_value_paramete", - "r\030\006 \001(\01322.org.jetbrains.kotlin.serializa" + - "tion.ValueParameter\022\024\n\014getter_flags\030\007 \001(" + - "\005\022\024\n\014setter_flags\030\010 \001(\005*\005\010d\020\310\001\"\355\001\n\016Value" + - "Parameter\022\020\n\005flags\030\001 \001(\005:\0010\022\022\n\004name\030\002 \002(" + - "\005B\004\210\265\030\001\0226\n\004type\030\003 \001(\0132(.org.jetbrains.ko" + - "tlin.serialization.Type\022\017\n\007type_id\030\005 \001(\005" + - "\022E\n\023vararg_element_type\030\004 \001(\0132(.org.jetb" + - "rains.kotlin.serialization.Type\022\036\n\026varar" + - "g_element_type_id\030\006 \001(\005*\005\010d\020\310\001*9\n\010Modali" + - "ty\022\t\n\005FINAL\020\000\022\010\n\004OPEN\020\001\022\014\n\010ABSTRACT\020\002\022\n\n", - "\006SEALED\020\003*b\n\nVisibility\022\014\n\010INTERNAL\020\000\022\013\n" + - "\007PRIVATE\020\001\022\r\n\tPROTECTED\020\002\022\n\n\006PUBLIC\020\003\022\023\n" + - "\017PRIVATE_TO_THIS\020\004\022\t\n\005LOCAL\020\005*Q\n\nMemberK" + - "ind\022\017\n\013DECLARATION\020\000\022\021\n\rFAKE_OVERRIDE\020\001\022" + - "\016\n\nDELEGATION\020\002\022\017\n\013SYNTHESIZED\020\003B\022B\rDebu" + - "gProtoBuf\210\001\000" + "ization.TypeTable*\005\010d\020\310\001\"\266\003\n\010Property\022\022\n" + + "\005flags\030\001 \001(\005:\003262\022\022\n\004name\030\002 \002(\005B\004\210\265\030\001\022=\n" + + "\013return_type\030\003 \001(\0132(.org.jetbrains.kotli" + + "n.serialization.Type\022\026\n\016return_type_id\030\t" + + " \001(\005\022I\n\016type_parameter\030\004 \003(\01321.org.jetbr" + + "ains.kotlin.serialization.TypeParameter\022" + + "?\n\rreceiver_type\030\005 \001(\0132(.org.jetbrains.k" + + "otlin.serialization.Type\022\030\n\020receiver_typ", + "e_id\030\n \001(\005\022R\n\026setter_value_parameter\030\006 \001" + + "(\01322.org.jetbrains.kotlin.serialization." + + "ValueParameter\022\024\n\014getter_flags\030\007 \001(\005\022\024\n\014" + + "setter_flags\030\010 \001(\005*\005\010d\020\310\001\"\355\001\n\016ValueParam" + + "eter\022\020\n\005flags\030\001 \001(\005:\0010\022\022\n\004name\030\002 \002(\005B\004\210\265" + + "\030\001\0226\n\004type\030\003 \001(\0132(.org.jetbrains.kotlin." + + "serialization.Type\022\017\n\007type_id\030\005 \001(\005\022E\n\023v" + + "ararg_element_type\030\004 \001(\0132(.org.jetbrains" + + ".kotlin.serialization.Type\022\036\n\026vararg_ele" + + "ment_type_id\030\006 \001(\005*\005\010d\020\310\001*9\n\010Modality\022\t\n", + "\005FINAL\020\000\022\010\n\004OPEN\020\001\022\014\n\010ABSTRACT\020\002\022\n\n\006SEAL" + + "ED\020\003*b\n\nVisibility\022\014\n\010INTERNAL\020\000\022\013\n\007PRIV" + + "ATE\020\001\022\r\n\tPROTECTED\020\002\022\n\n\006PUBLIC\020\003\022\023\n\017PRIV" + + "ATE_TO_THIS\020\004\022\t\n\005LOCAL\020\005*Q\n\nMemberKind\022\017" + + "\n\013DECLARATION\020\000\022\021\n\rFAKE_OVERRIDE\020\001\022\016\n\nDE" + + "LEGATION\020\002\022\017\n\013SYNTHESIZED\020\003B\022B\rDebugProt" + + "oBuf\210\001\000" }; com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() { @@ -20626,7 +20740,7 @@ public final class DebugProtoBuf { internal_static_org_jetbrains_kotlin_serialization_Type_fieldAccessorTable = new com.google.protobuf.GeneratedMessage.FieldAccessorTable( internal_static_org_jetbrains_kotlin_serialization_Type_descriptor, - new java.lang.String[] { "Argument", "Nullable", "FlexibleTypeCapabilitiesId", "FlexibleUpperBound", "FlexibleUpperBoundId", "ClassName", "TypeParameter", }); + new java.lang.String[] { "Argument", "Nullable", "FlexibleTypeCapabilitiesId", "FlexibleUpperBound", "FlexibleUpperBoundId", "ClassName", "TypeParameter", "TypeParameterName", }); internal_static_org_jetbrains_kotlin_serialization_Type_Argument_descriptor = internal_static_org_jetbrains_kotlin_serialization_Type_descriptor.getNestedTypes().get(0); internal_static_org_jetbrains_kotlin_serialization_Type_Argument_fieldAccessorTable = new @@ -20691,6 +20805,7 @@ public final class DebugProtoBuf { registry.add(org.jetbrains.kotlin.serialization.DebugExtOptionsProtoBuf.stringIdInTable); registry.add(org.jetbrains.kotlin.serialization.DebugExtOptionsProtoBuf.fqNameIdInTable); registry.add(org.jetbrains.kotlin.serialization.DebugExtOptionsProtoBuf.nameIdInTable); + registry.add(org.jetbrains.kotlin.serialization.DebugExtOptionsProtoBuf.nameIdInTable); registry.add(org.jetbrains.kotlin.serialization.DebugExtOptionsProtoBuf.fqNameIdInTable); registry.add(org.jetbrains.kotlin.serialization.DebugExtOptionsProtoBuf.nameIdInTable); registry.add(org.jetbrains.kotlin.serialization.DebugExtOptionsProtoBuf.nameIdInTable); diff --git a/core/deserialization/src/descriptors.proto b/core/deserialization/src/descriptors.proto index 875cc4540ce..f8be78a0aac 100644 --- a/core/deserialization/src/descriptors.proto +++ b/core/deserialization/src/descriptors.proto @@ -126,6 +126,8 @@ message Type { optional int32 class_name = 6 [(fq_name_id_in_table) = true]; optional int32 type_parameter = 7; // id of the type parameter + // Name of the type parameter in the immediate owner + optional int32 type_parameter_name = 9 [(name_id_in_table) = true]; extensions 100 to 199; } diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/ProtoBuf.java b/core/deserialization/src/org/jetbrains/kotlin/serialization/ProtoBuf.java index 4d904b47f06..21d5c670d78 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/ProtoBuf.java +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/ProtoBuf.java @@ -4335,6 +4335,24 @@ public final class ProtoBuf { * */ int getTypeParameter(); + + // optional int32 type_parameter_name = 9; + /** + * optional int32 type_parameter_name = 9; + * + *
+     * Name of the type parameter in the immediate owner
+     * 
+ */ + boolean hasTypeParameterName(); + /** + * optional int32 type_parameter_name = 9; + * + *
+     * Name of the type parameter in the immediate owner
+     * 
+ */ + int getTypeParameterName(); } /** * Protobuf type {@code org.jetbrains.kotlin.serialization.Type} @@ -4425,6 +4443,11 @@ public final class ProtoBuf { flexibleUpperBoundId_ = input.readInt32(); break; } + case 72: { + bitField0_ |= 0x00000040; + typeParameterName_ = input.readInt32(); + break; + } } } } catch (com.google.protobuf.InvalidProtocolBufferException e) { @@ -5269,6 +5292,30 @@ public final class ProtoBuf { return typeParameter_; } + // optional int32 type_parameter_name = 9; + public static final int TYPE_PARAMETER_NAME_FIELD_NUMBER = 9; + private int typeParameterName_; + /** + * optional int32 type_parameter_name = 9; + * + *
+     * Name of the type parameter in the immediate owner
+     * 
+ */ + public boolean hasTypeParameterName() { + return ((bitField0_ & 0x00000040) == 0x00000040); + } + /** + * optional int32 type_parameter_name = 9; + * + *
+     * Name of the type parameter in the immediate owner
+     * 
+ */ + public int getTypeParameterName() { + return typeParameterName_; + } + private void initFields() { argument_ = java.util.Collections.emptyList(); nullable_ = false; @@ -5277,6 +5324,7 @@ public final class ProtoBuf { flexibleUpperBoundId_ = 0; className_ = 0; typeParameter_ = 0; + typeParameterName_ = 0; } private byte memoizedIsInitialized = -1; public final boolean isInitialized() { @@ -5330,6 +5378,9 @@ public final class ProtoBuf { if (((bitField0_ & 0x00000008) == 0x00000008)) { output.writeInt32(8, flexibleUpperBoundId_); } + if (((bitField0_ & 0x00000040) == 0x00000040)) { + output.writeInt32(9, typeParameterName_); + } extensionWriter.writeUntil(200, output); } @@ -5367,6 +5418,10 @@ public final class ProtoBuf { size += com.google.protobuf.CodedOutputStream .computeInt32Size(8, flexibleUpperBoundId_); } + if (((bitField0_ & 0x00000040) == 0x00000040)) { + size += com.google.protobuf.CodedOutputStream + .computeInt32Size(9, typeParameterName_); + } size += extensionsSerializedSize(); memoizedSerializedSize = size; return size; @@ -5472,6 +5527,8 @@ public final class ProtoBuf { bitField0_ = (bitField0_ & ~0x00000020); typeParameter_ = 0; bitField0_ = (bitField0_ & ~0x00000040); + typeParameterName_ = 0; + bitField0_ = (bitField0_ & ~0x00000080); return this; } @@ -5524,6 +5581,10 @@ public final class ProtoBuf { to_bitField0_ |= 0x00000020; } result.typeParameter_ = typeParameter_; + if (((from_bitField0_ & 0x00000080) == 0x00000080)) { + to_bitField0_ |= 0x00000040; + } + result.typeParameterName_ = typeParameterName_; result.bitField0_ = to_bitField0_; return result; } @@ -5558,6 +5619,9 @@ public final class ProtoBuf { if (other.hasTypeParameter()) { setTypeParameter(other.getTypeParameter()); } + if (other.hasTypeParameterName()) { + setTypeParameterName(other.getTypeParameterName()); + } this.mergeExtensionFields(other); return this; } @@ -5988,6 +6052,55 @@ public final class ProtoBuf { return this; } + // optional int32 type_parameter_name = 9; + private int typeParameterName_ ; + /** + * optional int32 type_parameter_name = 9; + * + *
+       * Name of the type parameter in the immediate owner
+       * 
+ */ + public boolean hasTypeParameterName() { + return ((bitField0_ & 0x00000080) == 0x00000080); + } + /** + * optional int32 type_parameter_name = 9; + * + *
+       * Name of the type parameter in the immediate owner
+       * 
+ */ + public int getTypeParameterName() { + return typeParameterName_; + } + /** + * optional int32 type_parameter_name = 9; + * + *
+       * Name of the type parameter in the immediate owner
+       * 
+ */ + public Builder setTypeParameterName(int value) { + bitField0_ |= 0x00000080; + typeParameterName_ = value; + + return this; + } + /** + * optional int32 type_parameter_name = 9; + * + *
+       * Name of the type parameter in the immediate owner
+       * 
+ */ + public Builder clearTypeParameterName() { + bitField0_ = (bitField0_ & ~0x00000080); + typeParameterName_ = 0; + + return this; + } + // @@protoc_insertion_point(builder_scope:org.jetbrains.kotlin.serialization.Type) } diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/TypeDeserializer.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/TypeDeserializer.kt index e5d34b4811d..2ada1539f2a 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/TypeDeserializer.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/TypeDeserializer.kt @@ -16,6 +16,7 @@ package org.jetbrains.kotlin.serialization.deserialization +import org.jetbrains.kotlin.descriptors.CallableDescriptor import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor import org.jetbrains.kotlin.descriptors.annotations.Annotations @@ -74,6 +75,17 @@ public class TypeDeserializer( classDescriptors(proto.className)?.typeConstructor proto.hasTypeParameter() -> typeParameterTypeConstructor(proto.typeParameter) + proto.hasTypeParameterName() -> { + val container = c.containingDeclaration + val typeParameters = when (container) { + is ClassDescriptor -> container.typeConstructor.parameters + is CallableDescriptor -> container.typeParameters + else -> emptyList() + } + val name = c.nameResolver.getString(proto.typeParameterName) + val parameter = typeParameters.find { it.name.asString() == name } + parameter?.typeConstructor ?: ErrorUtils.createErrorType("Deserialized type parameter $name in $container").constructor + } else -> null } ?: ErrorUtils.createErrorType(presentableTextForErrorType(proto)).constructor @@ -83,6 +95,8 @@ public class TypeDeserializer( c.nameResolver.getClassId(proto.className).asSingleFqName().asString() proto.hasTypeParameter() -> "Unknown type parameter ${proto.typeParameter}" + proto.hasTypeParameterName() -> + "Unknown type parameter ${c.nameResolver.getString(proto.typeParameterName)}" else -> "Unknown type" } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/TypeClsStubBuilder.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/TypeClsStubBuilder.kt index ea298d5f812..cb5b93c4abe 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/TypeClsStubBuilder.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/TypeClsStubBuilder.kt @@ -56,14 +56,15 @@ class TypeClsStubBuilder(private val c: ClsStubBuilderContext) { if (type.getNullable()) KotlinPlaceHolderStubImpl(typeReference, JetStubElementTypes.NULLABLE_TYPE) else typeReference + fun createTypeParameterStub(name: Name) { + createTypeAnnotationStubs(effectiveParent, annotations) + createStubForTypeName(ClassId.topLevel(FqName.topLevel(name)), effectiveParent) + } + when { - type.hasClassName() -> - createClassReferenceTypeStub(effectiveParent, type, annotations) - type.hasTypeParameter() -> { - createTypeAnnotationStubs(effectiveParent, annotations) - val typeParameterName = c.typeParameters[type.typeParameter] - createStubForTypeName(ClassId.topLevel(FqName.topLevel(typeParameterName)), effectiveParent) - } + type.hasClassName() -> createClassReferenceTypeStub(effectiveParent, type, annotations) + type.hasTypeParameter() -> createTypeParameterStub(c.typeParameters[type.typeParameter]) + type.hasTypeParameterName() -> createTypeParameterStub(c.nameResolver.getName(type.typeParameterName)) } } diff --git a/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/ProtoCompareGenerated.kt b/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/ProtoCompareGenerated.kt index 4401a64b791..12338aa078e 100644 --- a/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/ProtoCompareGenerated.kt +++ b/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/ProtoCompareGenerated.kt @@ -344,6 +344,11 @@ open class ProtoCompareGenerated(public val oldNameResolver: NameResolver, publi if (old.typeParameter != new.typeParameter) return false } + if (old.hasTypeParameterName() != new.hasTypeParameterName()) return false + if (old.hasTypeParameterName()) { + if (!checkStringEquals(old.typeParameterName, new.typeParameterName)) return false + } + if (old.getExtensionCount(JvmProtoBuf.typeAnnotation) != new.getExtensionCount(JvmProtoBuf.typeAnnotation)) return false for(i in 0..old.getExtensionCount(JvmProtoBuf.typeAnnotation) - 1) { @@ -1024,6 +1029,10 @@ public fun ProtoBuf.Type.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes: (I hashCode = 31 * hashCode + typeParameter } + if (hasTypeParameterName()) { + hashCode = 31 * hashCode + stringIndexes(typeParameterName) + } + for(i in 0..getExtensionCount(JvmProtoBuf.typeAnnotation) - 1) { hashCode = 31 * hashCode + getExtension(JvmProtoBuf.typeAnnotation, i).hashCode(stringIndexes, fqNameIndexes) }