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<K, V>")
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -4335,6 +4335,24 @@ public final class ProtoBuf {
|
||||
* </pre>
|
||||
*/
|
||||
int getTypeParameter();
|
||||
|
||||
// optional int32 type_parameter_name = 9;
|
||||
/**
|
||||
* <code>optional int32 type_parameter_name = 9;</code>
|
||||
*
|
||||
* <pre>
|
||||
* Name of the type parameter in the immediate owner
|
||||
* </pre>
|
||||
*/
|
||||
boolean hasTypeParameterName();
|
||||
/**
|
||||
* <code>optional int32 type_parameter_name = 9;</code>
|
||||
*
|
||||
* <pre>
|
||||
* Name of the type parameter in the immediate owner
|
||||
* </pre>
|
||||
*/
|
||||
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_;
|
||||
/**
|
||||
* <code>optional int32 type_parameter_name = 9;</code>
|
||||
*
|
||||
* <pre>
|
||||
* Name of the type parameter in the immediate owner
|
||||
* </pre>
|
||||
*/
|
||||
public boolean hasTypeParameterName() {
|
||||
return ((bitField0_ & 0x00000040) == 0x00000040);
|
||||
}
|
||||
/**
|
||||
* <code>optional int32 type_parameter_name = 9;</code>
|
||||
*
|
||||
* <pre>
|
||||
* Name of the type parameter in the immediate owner
|
||||
* </pre>
|
||||
*/
|
||||
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_ ;
|
||||
/**
|
||||
* <code>optional int32 type_parameter_name = 9;</code>
|
||||
*
|
||||
* <pre>
|
||||
* Name of the type parameter in the immediate owner
|
||||
* </pre>
|
||||
*/
|
||||
public boolean hasTypeParameterName() {
|
||||
return ((bitField0_ & 0x00000080) == 0x00000080);
|
||||
}
|
||||
/**
|
||||
* <code>optional int32 type_parameter_name = 9;</code>
|
||||
*
|
||||
* <pre>
|
||||
* Name of the type parameter in the immediate owner
|
||||
* </pre>
|
||||
*/
|
||||
public int getTypeParameterName() {
|
||||
return typeParameterName_;
|
||||
}
|
||||
/**
|
||||
* <code>optional int32 type_parameter_name = 9;</code>
|
||||
*
|
||||
* <pre>
|
||||
* Name of the type parameter in the immediate owner
|
||||
* </pre>
|
||||
*/
|
||||
public Builder setTypeParameterName(int value) {
|
||||
bitField0_ |= 0x00000080;
|
||||
typeParameterName_ = value;
|
||||
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>optional int32 type_parameter_name = 9;</code>
|
||||
*
|
||||
* <pre>
|
||||
* Name of the type parameter in the immediate owner
|
||||
* </pre>
|
||||
*/
|
||||
public Builder clearTypeParameterName() {
|
||||
bitField0_ = (bitField0_ & ~0x00000080);
|
||||
typeParameterName_ = 0;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
// @@protoc_insertion_point(builder_scope:org.jetbrains.kotlin.serialization.Type)
|
||||
}
|
||||
|
||||
|
||||
+14
@@ -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<TypeParameterDescriptor>()
|
||||
}
|
||||
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"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user