[IR] Add the description field to CommonIdSignature

This field shall be used for storing a human-readable representation
of the declaration, that would be a mangled name for now.

This field is not yet serialized. Serialization will be implemented in
follow-up commits.

See KT-59486
This commit is contained in:
Sergej Jaskiewicz
2023-06-19 13:41:51 +02:00
committed by teamcity
parent 668684ca13
commit 3a30d74096
11 changed files with 184 additions and 20 deletions
@@ -30,6 +30,7 @@ message CommonIdSignature {
repeated int32 declaration_fq_name = 2 [packed = true];
optional int64 member_uniq_id = 3;
optional int64 flags = 4 [default = 0];
optional int64 debug_info = 5;
}
message AccessorIdSignature {
@@ -40,7 +40,13 @@ class IdSignatureDeserializer(
val cls = internationService.string(libraryFile.deserializeFqName(proto.declarationFqNameList))
val memberId = if (proto.hasMemberUniqId()) proto.memberUniqId else null
return IdSignature.CommonSignature(pkg, cls, memberId, proto.flags)
return IdSignature.CommonSignature(
packageFqName = pkg,
declarationFqName = cls,
id = memberId,
mask = proto.flags,
description = null, // TODO(KT-59486): Deserialize mangled name and save it here
)
}
private fun deserializeAccessorIdSignature(proto: ProtoAccessorIdSignature): IdSignature.AccessorSignature {
@@ -52,7 +58,13 @@ class IdSignatureDeserializer(
val declarationFqName = internationService.string("${propertySignature.declarationFqName}.$name")
val accessorSignature =
IdSignature.CommonSignature(propertySignature.packageFqName, declarationFqName, hash, mask)
IdSignature.CommonSignature(
packageFqName = propertySignature.packageFqName,
declarationFqName = declarationFqName,
id = hash,
mask = mask,
description = null, // TODO(KT-59486): Deserialize mangled name and save it here
)
return IdSignature.AccessorSignature(propertySignature, accessorSignature)
}
@@ -105,6 +105,11 @@ public final class CommonIdSignature extends
flags_ = input.readInt64();
break;
}
case 40: {
bitField0_ |= 0x00000004;
debugInfo_ = input.readInt64();
break;
}
}
}
} catch (org.jetbrains.kotlin.protobuf.InvalidProtocolBufferException e) {
@@ -221,11 +226,27 @@ public final class CommonIdSignature extends
return flags_;
}
public static final int DEBUG_INFO_FIELD_NUMBER = 5;
private long debugInfo_;
/**
* <code>optional int64 debug_info = 5;</code>
*/
public boolean hasDebugInfo() {
return ((bitField0_ & 0x00000004) == 0x00000004);
}
/**
* <code>optional int64 debug_info = 5;</code>
*/
public long getDebugInfo() {
return debugInfo_;
}
private void initFields() {
packageFqName_ = java.util.Collections.emptyList();
declarationFqName_ = java.util.Collections.emptyList();
memberUniqId_ = 0L;
flags_ = 0L;
debugInfo_ = 0L;
}
private byte memoizedIsInitialized = -1;
public final boolean isInitialized() {
@@ -260,6 +281,9 @@ public final class CommonIdSignature extends
if (((bitField0_ & 0x00000002) == 0x00000002)) {
output.writeInt64(4, flags_);
}
if (((bitField0_ & 0x00000004) == 0x00000004)) {
output.writeInt64(5, debugInfo_);
}
output.writeRawBytes(unknownFields);
}
@@ -305,6 +329,10 @@ public final class CommonIdSignature extends
size += org.jetbrains.kotlin.protobuf.CodedOutputStream
.computeInt64Size(4, flags_);
}
if (((bitField0_ & 0x00000004) == 0x00000004)) {
size += org.jetbrains.kotlin.protobuf.CodedOutputStream
.computeInt64Size(5, debugInfo_);
}
size += unknownFields.size();
memoizedSerializedSize = size;
return size;
@@ -407,6 +435,8 @@ public final class CommonIdSignature extends
bitField0_ = (bitField0_ & ~0x00000004);
flags_ = 0L;
bitField0_ = (bitField0_ & ~0x00000008);
debugInfo_ = 0L;
bitField0_ = (bitField0_ & ~0x00000010);
return this;
}
@@ -448,6 +478,10 @@ public final class CommonIdSignature extends
to_bitField0_ |= 0x00000002;
}
result.flags_ = flags_;
if (((from_bitField0_ & 0x00000010) == 0x00000010)) {
to_bitField0_ |= 0x00000004;
}
result.debugInfo_ = debugInfo_;
result.bitField0_ = to_bitField0_;
return result;
}
@@ -480,6 +514,9 @@ public final class CommonIdSignature extends
if (other.hasFlags()) {
setFlags(other.getFlags());
}
if (other.hasDebugInfo()) {
setDebugInfo(other.getDebugInfo());
}
setUnknownFields(
getUnknownFields().concat(other.unknownFields));
return this;
@@ -704,6 +741,38 @@ public final class CommonIdSignature extends
return this;
}
private long debugInfo_ ;
/**
* <code>optional int64 debug_info = 5;</code>
*/
public boolean hasDebugInfo() {
return ((bitField0_ & 0x00000010) == 0x00000010);
}
/**
* <code>optional int64 debug_info = 5;</code>
*/
public long getDebugInfo() {
return debugInfo_;
}
/**
* <code>optional int64 debug_info = 5;</code>
*/
public Builder setDebugInfo(long value) {
bitField0_ |= 0x00000010;
debugInfo_ = value;
return this;
}
/**
* <code>optional int64 debug_info = 5;</code>
*/
public Builder clearDebugInfo() {
bitField0_ = (bitField0_ & ~0x00000010);
debugInfo_ = 0L;
return this;
}
// @@protoc_insertion_point(builder_scope:org.jetbrains.kotlin.backend.common.serialization.proto.CommonIdSignature)
}
@@ -50,4 +50,13 @@ public interface CommonIdSignatureOrBuilder extends
* <code>optional int64 flags = 4 [default = 0];</code>
*/
long getFlags();
/**
* <code>optional int64 debug_info = 5;</code>
*/
boolean hasDebugInfo();
/**
* <code>optional int64 debug_info = 5;</code>
*/
long getDebugInfo();
}
@@ -69,10 +69,22 @@ abstract class IdSignatureBuilder<D> {
}
hashIdAcc == null -> {
IdSignature.CommonSignature(packageFqName, classFqName, hashId, mask)
IdSignature.CommonSignature(
packageFqName = packageFqName,
declarationFqName = classFqName,
id = hashId,
mask = mask,
description = null, // TODO(KT-59486): Save mangled name here
)
}
else -> {
val accessorSignature = IdSignature.CommonSignature(packageFqName, classFqName, hashIdAcc, mask)
val accessorSignature = IdSignature.CommonSignature(
packageFqName = packageFqName,
declarationFqName = classFqName,
id = hashIdAcc,
mask = mask,
description = null, // TODO(KT-59486): Save mangled name here
)
hashIdAcc = null
classFqnSegments.run { removeAt(lastIndex) }
val propertySignature = build()
@@ -231,7 +231,13 @@ class IdSignatureSerializer(
private fun composeContainerIdSignature(container: IrDeclarationParent, compatibleMode: Boolean): IdSignature =
when (container) {
is IrPackageFragment -> IdSignature.CommonSignature(container.packageFqName.asString(), "", null, 0)
is IrPackageFragment -> IdSignature.CommonSignature(
packageFqName = container.packageFqName.asString(),
declarationFqName = "",
id = null,
mask = 0,
description = null,
)
is IrDeclaration -> table.signatureByDeclaration(container, compatibleMode)
else -> error("Unexpected container ${container.render()}")
}