[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:
committed by
teamcity
parent
668684ca13
commit
3a30d74096
@@ -620,7 +620,11 @@ class Fir2IrClassifierStorage(
|
||||
fun getIrClassSymbolForNotFoundClass(classLikeLookupTag: ConeClassLikeLookupTag): IrClassSymbol {
|
||||
val classId = classLikeLookupTag.classId
|
||||
val signature = IdSignature.CommonSignature(
|
||||
classId.packageFqName.asString(), classId.relativeClassName.asString(), 0, 0,
|
||||
packageFqName = classId.packageFqName.asString(),
|
||||
declarationFqName = classId.relativeClassName.asString(),
|
||||
id = 0,
|
||||
mask = 0,
|
||||
description = null,
|
||||
)
|
||||
|
||||
val parentId = classId.outerClassId
|
||||
|
||||
+27
-9
@@ -126,13 +126,21 @@ class FirBasedSignatureComposer(override val mangler: FirMangler) : Fir2IrSignat
|
||||
// TODO: private classes are probably not acceptable here too
|
||||
val classId = declaration.classId
|
||||
IdSignature.CommonSignature(
|
||||
classId.packageFqName.asString(), classId.relativeClassName.asString(), builder.hashId, builder.mask
|
||||
packageFqName = classId.packageFqName.asString(),
|
||||
declarationFqName = classId.relativeClassName.asString(),
|
||||
id = builder.hashId,
|
||||
mask = builder.mask,
|
||||
description = null, // TODO(KT-59486): Save mangled name here
|
||||
)
|
||||
}
|
||||
is FirTypeAlias -> {
|
||||
val classId = declaration.symbol.classId
|
||||
IdSignature.CommonSignature(
|
||||
classId.packageFqName.asString(), classId.relativeClassName.asString(), builder.hashId, builder.mask
|
||||
packageFqName = classId.packageFqName.asString(),
|
||||
declarationFqName = classId.relativeClassName.asString(),
|
||||
id = builder.hashId,
|
||||
mask = builder.mask,
|
||||
description = null, // TODO(KT-59486): Save mangled name here
|
||||
)
|
||||
}
|
||||
is FirCallableDeclaration -> {
|
||||
@@ -141,16 +149,20 @@ class FirBasedSignatureComposer(override val mangler: FirMangler) : Fir2IrSignat
|
||||
val callableName = declaration.irName
|
||||
|
||||
IdSignature.CommonSignature(
|
||||
packageName.asString(),
|
||||
classId?.relativeClassName?.child(callableName)?.asString() ?: callableName.asString(),
|
||||
builder.hashId, builder.mask
|
||||
packageFqName = packageName.asString(),
|
||||
declarationFqName = classId?.relativeClassName?.child(callableName)?.asString() ?: callableName.asString(),
|
||||
id = builder.hashId,
|
||||
mask = builder.mask,
|
||||
description = null, // TODO(KT-59486): Save mangled name here
|
||||
)
|
||||
}
|
||||
is FirScript -> {
|
||||
IdSignature.CommonSignature(
|
||||
declaration.name.asString(), // TODO: find package id
|
||||
declaration.name.asString(),
|
||||
builder.hashId, builder.mask
|
||||
packageFqName = declaration.name.asString(), // TODO: find package id
|
||||
declarationFqName = declaration.name.asString(),
|
||||
id = builder.hashId,
|
||||
mask = builder.mask,
|
||||
description = null, // TODO(KT-59486): Save mangled name here
|
||||
)
|
||||
}
|
||||
else -> error("Unsupported FIR declaration in signature composer: ${declaration.render()}")
|
||||
@@ -200,7 +212,13 @@ class FirBasedSignatureComposer(override val mangler: FirMangler) : Fir2IrSignat
|
||||
} else {
|
||||
propSig.declarationFqName + ".<get-${property.name.asString()}>"
|
||||
}
|
||||
val commonSig = IdSignature.CommonSignature(propSig.packageFqName, accessorFqName, id, propSig.mask)
|
||||
val commonSig = IdSignature.CommonSignature(
|
||||
packageFqName = propSig.packageFqName,
|
||||
declarationFqName = accessorFqName,
|
||||
id = id,
|
||||
mask = propSig.mask,
|
||||
description = null, // TODO(KT-59486): Save mangled name here
|
||||
)
|
||||
val accessorSig = IdSignature.AccessorSignature(propSig, commonSig)
|
||||
return if (fileSig != null) {
|
||||
IdSignature.CompositeSignature(fileSig, accessorSig)
|
||||
|
||||
+7
-1
@@ -88,7 +88,13 @@ internal class IdSignatureSerialization(private val library: KotlinLibraryHeader
|
||||
null
|
||||
}
|
||||
val mask = input.readInt64()
|
||||
return IdSignature.CommonSignature(packageFqName, declarationFqName, id, mask)
|
||||
return IdSignature.CommonSignature(
|
||||
packageFqName = packageFqName,
|
||||
declarationFqName = declarationFqName,
|
||||
id = id,
|
||||
mask = mask,
|
||||
description = null, // TODO(KT-59486): Deserialize mangled name and save it here
|
||||
)
|
||||
}
|
||||
IdSignatureProtoType.COMPOSITE_SIGNATURE.id -> {
|
||||
val containerSignature = deserializeIdSignature(input)
|
||||
|
||||
@@ -45,14 +45,26 @@ object IdSignatureValues {
|
||||
@JvmField val iterable = getPublicSignature(StandardNames.COLLECTIONS_PACKAGE_FQ_NAME, "Iterable")
|
||||
@JvmField val continuation = getPublicSignature(StandardNames.COROUTINES_PACKAGE_FQ_NAME, "Continuation")
|
||||
@JvmField val result = getPublicSignature(StandardNames.BUILT_INS_PACKAGE_FQ_NAME, "Result")
|
||||
@JvmField val sequence = IdSignature.CommonSignature("kotlin.sequences", "Sequence", null, 0)
|
||||
@JvmField val sequence = IdSignature.CommonSignature(
|
||||
packageFqName = "kotlin.sequences",
|
||||
declarationFqName = "Sequence",
|
||||
id = null,
|
||||
mask = 0,
|
||||
description = "kotlin.sequences.Sequence",
|
||||
)
|
||||
}
|
||||
|
||||
private fun IrType.isNotNullClassType(signature: IdSignature.CommonSignature) = isClassType(signature, nullable = false)
|
||||
private fun IrType.isNullableClassType(signature: IdSignature.CommonSignature) = isClassType(signature, nullable = true)
|
||||
|
||||
fun getPublicSignature(packageFqName: FqName, name: String) =
|
||||
IdSignature.CommonSignature(packageFqName.asString(), name, null, 0)
|
||||
IdSignature.CommonSignature(
|
||||
packageFqName = packageFqName.asString(),
|
||||
declarationFqName = name,
|
||||
id = null,
|
||||
mask = 0,
|
||||
description = packageFqName.child(Name.identifier(name)).asString(),
|
||||
)
|
||||
|
||||
private fun IrType.isClassType(signature: IdSignature.CommonSignature, nullable: Boolean? = null): Boolean {
|
||||
if (this !is IrSimpleType) return false
|
||||
|
||||
@@ -266,8 +266,17 @@ sealed class IdSignature {
|
||||
|
||||
/**
|
||||
* This signature corresponds to a publicly accessible Kotlin declaration.
|
||||
*
|
||||
* @property description This property does not affect linkage and is used only for showing humnan-readable error messages.
|
||||
* Note: currently, we store here the mangled name from which [id] was computed. Later we can reconsider.
|
||||
*/
|
||||
class CommonSignature(val packageFqName: String, val declarationFqName: String, val id: Long?, val mask: Long) : IdSignature() {
|
||||
class CommonSignature(
|
||||
val packageFqName: String,
|
||||
val declarationFqName: String,
|
||||
val id: Long?,
|
||||
val mask: Long,
|
||||
val description: String?,
|
||||
) : IdSignature() {
|
||||
override val isPubliclyVisible: Boolean get() = true
|
||||
|
||||
override fun packageFqName(): FqName = FqName(packageFqName)
|
||||
@@ -295,7 +304,13 @@ sealed class IdSignature {
|
||||
val adaptedMask = adaptMask(mask)
|
||||
if (nameSegments.size == 1 && mask == adaptedMask) return this
|
||||
|
||||
return CommonSignature(packageFqName, nameSegments.first(), null, adaptedMask)
|
||||
return CommonSignature(
|
||||
packageFqName = packageFqName,
|
||||
declarationFqName = nameSegments.first(),
|
||||
id = null,
|
||||
mask = adaptedMask,
|
||||
description = null
|
||||
)
|
||||
}
|
||||
|
||||
override fun isPackageSignature(): Boolean = id == null && declarationFqName.isEmpty()
|
||||
|
||||
@@ -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 {
|
||||
|
||||
+14
-2
@@ -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)
|
||||
}
|
||||
|
||||
+69
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
+9
@@ -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();
|
||||
}
|
||||
+14
-2
@@ -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()
|
||||
|
||||
+7
-1
@@ -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()}")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user