[Linker][IdSignature] Rename classFqn property

classFqn is incorrect since this property represents
FqName of any declaration, including properties, functions and
type aliases.
This commit is contained in:
Sergey Bogolepov
2020-02-21 12:55:43 +07:00
committed by Sergey Bogolepov
parent 221d24c597
commit 71cc288a14
8 changed files with 84 additions and 85 deletions
@@ -364,13 +364,13 @@ class DeclarationStubGenerator(
private fun findDescriptorForAccessorSignature(signature: IdSignature.AccessorSignature): DeclarationDescriptor? { private fun findDescriptorForAccessorSignature(signature: IdSignature.AccessorSignature): DeclarationDescriptor? {
val propertyDescriptor = findDescriptorBySignature(signature.propertySignature) as? PropertyDescriptor ?: return null val propertyDescriptor = findDescriptorBySignature(signature.propertySignature) as? PropertyDescriptor ?: return null
return propertyDescriptor.accessors.singleOrNull { return propertyDescriptor.accessors.singleOrNull {
it.name == signature.accessorSignature.classFqn.shortName() it.name == signature.accessorSignature.declarationFqn.shortName()
} }
} }
private fun findDescriptorForPublicSignature(signature: IdSignature.PublicSignature): DeclarationDescriptor? { private fun findDescriptorForPublicSignature(signature: IdSignature.PublicSignature): DeclarationDescriptor? {
val packageDescriptor = moduleDescriptor.getPackage(signature.packageFqName()) val packageDescriptor = moduleDescriptor.getPackage(signature.packageFqName())
val pathSegments = signature.classFqn.pathSegments() val pathSegments = signature.declarationFqn.pathSegments()
val toplevelDescriptors = packageDescriptor.memberScope.getContributedDescriptors { name -> name == pathSegments.first() } val toplevelDescriptors = packageDescriptor.memberScope.getContributedDescriptors { name -> name == pathSegments.first() }
.filter { it.name == pathSegments.first() } .filter { it.name == pathSegments.first() }
val candidates = pathSegments.drop(1).fold(toplevelDescriptors) { acc, current -> val candidates = pathSegments.drop(1).fold(toplevelDescriptors) { acc, current ->
@@ -7,7 +7,6 @@ package org.jetbrains.kotlin.ir.util
import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.FqName
sealed class IdSignature { sealed class IdSignature {
@@ -47,7 +46,7 @@ sealed class IdSignature {
return "${if (isPublic) "public" else "private"} ${render()}" return "${if (isPublic) "public" else "private"} ${render()}"
} }
data class PublicSignature(val packageFqn: FqName, val classFqn: FqName, val id: Long?, val mask: Long) : IdSignature() { data class PublicSignature(val packageFqn: FqName, val declarationFqn: FqName, val id: Long?, val mask: Long) : IdSignature() {
override val isPublic = true override val isPublic = true
override fun packageFqName() = packageFqn override fun packageFqName() = packageFqn
@@ -60,26 +59,26 @@ sealed class IdSignature {
} }
override fun topLevelSignature(): IdSignature { override fun topLevelSignature(): IdSignature {
if (classFqn.isRoot) { if (declarationFqn.isRoot) {
assert(id == null) assert(id == null)
// package signature // package signature
return this return this
} }
val pathSegments = classFqn.pathSegments() val pathSegments = declarationFqn.pathSegments()
if (pathSegments.size == 1) return this if (pathSegments.size == 1) return this
return PublicSignature(packageFqn, FqName(pathSegments.first().asString()), null, adaptMask(mask)) return PublicSignature(packageFqn, FqName(pathSegments.first().asString()), null, adaptMask(mask))
} }
override fun isPackageSignature(): Boolean = id == null && classFqn.isRoot override fun isPackageSignature(): Boolean = id == null && declarationFqn.isRoot
override fun nearestPublicSig(): PublicSignature = this override fun nearestPublicSig(): PublicSignature = this
override fun flags(): Long = mask override fun flags(): Long = mask
override fun render(): String = "${packageFqn.asString()}/${classFqn.asString()}|$id[${mask.toString(2)}]" override fun render(): String = "${packageFqn.asString()}/${declarationFqn.asString()}|$id[${mask.toString(2)}]"
override fun toString() = super.toString() override fun toString() = super.toString()
@@ -117,7 +116,7 @@ sealed class IdSignature {
override fun topLevelSignature(): IdSignature { override fun topLevelSignature(): IdSignature {
val topLevelContainer = container.topLevelSignature() val topLevelContainer = container.topLevelSignature()
if (topLevelContainer === container) { if (topLevelContainer === container) {
if (topLevelContainer is PublicSignature && topLevelContainer.classFqn.isRoot) { if (topLevelContainer is PublicSignature && topLevelContainer.declarationFqn.isRoot) {
// private top level // private top level
return this return this
} }
@@ -25,7 +25,7 @@ message IrFile {
message PublicIdSignature { message PublicIdSignature {
repeated int32 package_fq_name = 1 [packed=true]; repeated int32 package_fq_name = 1 [packed=true];
repeated int32 class_fq_name = 2 [packed=true]; repeated int32 declaration_fq_name = 2 [packed = true];
optional int64 member_uniq_id = 3; optional int64 member_uniq_id = 3;
optional int64 flags = 4 [default = 0]; optional int64 flags = 4 [default = 0];
} }
@@ -201,7 +201,7 @@ abstract class IrFileDeserializer(val logger: LoggingContext, val builtIns: IrBu
private fun deserializePublicIdSignature(proto: ProtoPublicIdSignature): IdSignature.PublicSignature { private fun deserializePublicIdSignature(proto: ProtoPublicIdSignature): IdSignature.PublicSignature {
val pkg = deserializeFqName(proto.packageFqNameList) val pkg = deserializeFqName(proto.packageFqNameList)
val cls = deserializeFqName(proto.classFqNameList) val cls = deserializeFqName(proto.declarationFqNameList)
val memberId = if (proto.hasMemberUniqId()) proto.memberUniqId else null val memberId = if (proto.hasMemberUniqId()) proto.memberUniqId else null
return IdSignature.PublicSignature(pkg, cls, memberId, proto.flags) return IdSignature.PublicSignature(pkg, cls, memberId, proto.flags)
@@ -215,7 +215,7 @@ abstract class IrFileDeserializer(val logger: LoggingContext, val builtIns: IrBu
val mask = proto.flags val mask = proto.flags
val accessorSignature = with(propertySignature) { val accessorSignature = with(propertySignature) {
IdSignature.PublicSignature(packageFqn, classFqn.child(Name.special(name)), hash, mask) IdSignature.PublicSignature(packageFqn, declarationFqn.child(Name.special(name)), hash, mask)
} }
return IdSignature.AccessorSignature(propertySignature, accessorSignature) return IdSignature.AccessorSignature(propertySignature, accessorSignature)
@@ -184,7 +184,7 @@ open class IrFileSerializer(
private fun serializePublicSignature(signature: IdSignature.PublicSignature): ProtoPublicIdSignature { private fun serializePublicSignature(signature: IdSignature.PublicSignature): ProtoPublicIdSignature {
val proto = ProtoPublicIdSignature.newBuilder() val proto = ProtoPublicIdSignature.newBuilder()
proto.addAllPackageFqName(serializeFqName(signature.packageFqn)) proto.addAllPackageFqName(serializeFqName(signature.packageFqn))
proto.addAllClassFqName(serializeFqName(signature.classFqn)) proto.addAllDeclarationFqName(serializeFqName(signature.declarationFqn))
signature.id?.let { proto.memberUniqId = it } signature.id?.let { proto.memberUniqId = it }
if (signature.mask != 0L) { if (signature.mask != 0L) {
@@ -199,7 +199,7 @@ open class IrFileSerializer(
proto.propertySignature = protoIdSignature(signature.propertySignature) proto.propertySignature = protoIdSignature(signature.propertySignature)
with(signature.accessorSignature) { with(signature.accessorSignature) {
proto.name = serializeString(classFqn.shortName().asString()) proto.name = serializeString(declarationFqn.shortName().asString())
proto.accessorHashId = id ?: error("Expected hash Id") proto.accessorHashId = id ?: error("Expected hash Id")
if (mask != 0L) { if (mask != 0L) {
proto.flags = mask proto.flags = mask
@@ -568,11 +568,11 @@ abstract class KotlinIrLinker(
if (publicSig.packageFqn !in functionalPackages) return false if (publicSig.packageFqn !in functionalPackages) return false
val classFqn = publicSig.classFqn val declarationFqn = publicSig.declarationFqn
if (classFqn.isRoot) return false if (declarationFqn.isRoot) return false
val fqnParts = classFqn.pathSegments() val fqnParts = declarationFqn.pathSegments()
val className = fqnParts.first() val className = fqnParts.first()
@@ -583,7 +583,7 @@ abstract class KotlinIrLinker(
if (isSpecialFunctionDescriptor(idSig)) { if (isSpecialFunctionDescriptor(idSig)) {
val publicSig = idSig.asPublic() ?: error("$idSig has to be public") val publicSig = idSig.asPublic() ?: error("$idSig has to be public")
val fqnParts = publicSig.classFqn.pathSegments() val fqnParts = publicSig.declarationFqn.pathSegments()
val className = fqnParts.first() val className = fqnParts.first()
val classDescriptor = builtIns.builtIns.getBuiltInClassByFqName(publicSig.packageFqn.child(className)) val classDescriptor = builtIns.builtIns.getBuiltInClassByFqName(publicSig.packageFqn.child(className))
@@ -76,21 +76,21 @@ public final class PublicIdSignature extends
} }
case 16: { case 16: {
if (!((mutable_bitField0_ & 0x00000002) == 0x00000002)) { if (!((mutable_bitField0_ & 0x00000002) == 0x00000002)) {
classFqName_ = new java.util.ArrayList<java.lang.Integer>(); declarationFqName_ = new java.util.ArrayList<java.lang.Integer>();
mutable_bitField0_ |= 0x00000002; mutable_bitField0_ |= 0x00000002;
} }
classFqName_.add(input.readInt32()); declarationFqName_.add(input.readInt32());
break; break;
} }
case 18: { case 18: {
int length = input.readRawVarint32(); int length = input.readRawVarint32();
int limit = input.pushLimit(length); int limit = input.pushLimit(length);
if (!((mutable_bitField0_ & 0x00000002) == 0x00000002) && input.getBytesUntilLimit() > 0) { if (!((mutable_bitField0_ & 0x00000002) == 0x00000002) && input.getBytesUntilLimit() > 0) {
classFqName_ = new java.util.ArrayList<java.lang.Integer>(); declarationFqName_ = new java.util.ArrayList<java.lang.Integer>();
mutable_bitField0_ |= 0x00000002; mutable_bitField0_ |= 0x00000002;
} }
while (input.getBytesUntilLimit() > 0) { while (input.getBytesUntilLimit() > 0) {
classFqName_.add(input.readInt32()); declarationFqName_.add(input.readInt32());
} }
input.popLimit(limit); input.popLimit(limit);
break; break;
@@ -117,7 +117,7 @@ public final class PublicIdSignature extends
packageFqName_ = java.util.Collections.unmodifiableList(packageFqName_); packageFqName_ = java.util.Collections.unmodifiableList(packageFqName_);
} }
if (((mutable_bitField0_ & 0x00000002) == 0x00000002)) { if (((mutable_bitField0_ & 0x00000002) == 0x00000002)) {
classFqName_ = java.util.Collections.unmodifiableList(classFqName_); declarationFqName_ = java.util.Collections.unmodifiableList(declarationFqName_);
} }
try { try {
unknownFieldsCodedOutput.flush(); unknownFieldsCodedOutput.flush();
@@ -168,28 +168,28 @@ public final class PublicIdSignature extends
} }
private int packageFqNameMemoizedSerializedSize = -1; private int packageFqNameMemoizedSerializedSize = -1;
public static final int CLASS_FQ_NAME_FIELD_NUMBER = 2; public static final int DECLARATION_FQ_NAME_FIELD_NUMBER = 2;
private java.util.List<java.lang.Integer> classFqName_; private java.util.List<java.lang.Integer> declarationFqName_;
/** /**
* <code>repeated int32 class_fq_name = 2 [packed = true];</code> * <code>repeated int32 declaration_fq_name = 2 [packed = true];</code>
*/ */
public java.util.List<java.lang.Integer> public java.util.List<java.lang.Integer>
getClassFqNameList() { getDeclarationFqNameList() {
return classFqName_; return declarationFqName_;
} }
/** /**
* <code>repeated int32 class_fq_name = 2 [packed = true];</code> * <code>repeated int32 declaration_fq_name = 2 [packed = true];</code>
*/ */
public int getClassFqNameCount() { public int getDeclarationFqNameCount() {
return classFqName_.size(); return declarationFqName_.size();
} }
/** /**
* <code>repeated int32 class_fq_name = 2 [packed = true];</code> * <code>repeated int32 declaration_fq_name = 2 [packed = true];</code>
*/ */
public int getClassFqName(int index) { public int getDeclarationFqName(int index) {
return classFqName_.get(index); return declarationFqName_.get(index);
} }
private int classFqNameMemoizedSerializedSize = -1; private int declarationFqNameMemoizedSerializedSize = -1;
public static final int MEMBER_UNIQ_ID_FIELD_NUMBER = 3; public static final int MEMBER_UNIQ_ID_FIELD_NUMBER = 3;
private long memberUniqId_; private long memberUniqId_;
@@ -223,7 +223,7 @@ public final class PublicIdSignature extends
private void initFields() { private void initFields() {
packageFqName_ = java.util.Collections.emptyList(); packageFqName_ = java.util.Collections.emptyList();
classFqName_ = java.util.Collections.emptyList(); declarationFqName_ = java.util.Collections.emptyList();
memberUniqId_ = 0L; memberUniqId_ = 0L;
flags_ = 0L; flags_ = 0L;
} }
@@ -247,12 +247,12 @@ public final class PublicIdSignature extends
for (int i = 0; i < packageFqName_.size(); i++) { for (int i = 0; i < packageFqName_.size(); i++) {
output.writeInt32NoTag(packageFqName_.get(i)); output.writeInt32NoTag(packageFqName_.get(i));
} }
if (getClassFqNameList().size() > 0) { if (getDeclarationFqNameList().size() > 0) {
output.writeRawVarint32(18); output.writeRawVarint32(18);
output.writeRawVarint32(classFqNameMemoizedSerializedSize); output.writeRawVarint32(declarationFqNameMemoizedSerializedSize);
} }
for (int i = 0; i < classFqName_.size(); i++) { for (int i = 0; i < declarationFqName_.size(); i++) {
output.writeInt32NoTag(classFqName_.get(i)); output.writeInt32NoTag(declarationFqName_.get(i));
} }
if (((bitField0_ & 0x00000001) == 0x00000001)) { if (((bitField0_ & 0x00000001) == 0x00000001)) {
output.writeInt64(3, memberUniqId_); output.writeInt64(3, memberUniqId_);
@@ -285,17 +285,17 @@ public final class PublicIdSignature extends
} }
{ {
int dataSize = 0; int dataSize = 0;
for (int i = 0; i < classFqName_.size(); i++) { for (int i = 0; i < declarationFqName_.size(); i++) {
dataSize += org.jetbrains.kotlin.protobuf.CodedOutputStream dataSize += org.jetbrains.kotlin.protobuf.CodedOutputStream
.computeInt32SizeNoTag(classFqName_.get(i)); .computeInt32SizeNoTag(declarationFqName_.get(i));
} }
size += dataSize; size += dataSize;
if (!getClassFqNameList().isEmpty()) { if (!getDeclarationFqNameList().isEmpty()) {
size += 1; size += 1;
size += org.jetbrains.kotlin.protobuf.CodedOutputStream size += org.jetbrains.kotlin.protobuf.CodedOutputStream
.computeInt32SizeNoTag(dataSize); .computeInt32SizeNoTag(dataSize);
} }
classFqNameMemoizedSerializedSize = dataSize; declarationFqNameMemoizedSerializedSize = dataSize;
} }
if (((bitField0_ & 0x00000001) == 0x00000001)) { if (((bitField0_ & 0x00000001) == 0x00000001)) {
size += org.jetbrains.kotlin.protobuf.CodedOutputStream size += org.jetbrains.kotlin.protobuf.CodedOutputStream
@@ -401,7 +401,7 @@ public final class PublicIdSignature extends
super.clear(); super.clear();
packageFqName_ = java.util.Collections.emptyList(); packageFqName_ = java.util.Collections.emptyList();
bitField0_ = (bitField0_ & ~0x00000001); bitField0_ = (bitField0_ & ~0x00000001);
classFqName_ = java.util.Collections.emptyList(); declarationFqName_ = java.util.Collections.emptyList();
bitField0_ = (bitField0_ & ~0x00000002); bitField0_ = (bitField0_ & ~0x00000002);
memberUniqId_ = 0L; memberUniqId_ = 0L;
bitField0_ = (bitField0_ & ~0x00000004); bitField0_ = (bitField0_ & ~0x00000004);
@@ -436,10 +436,10 @@ public final class PublicIdSignature extends
} }
result.packageFqName_ = packageFqName_; result.packageFqName_ = packageFqName_;
if (((bitField0_ & 0x00000002) == 0x00000002)) { if (((bitField0_ & 0x00000002) == 0x00000002)) {
classFqName_ = java.util.Collections.unmodifiableList(classFqName_); declarationFqName_ = java.util.Collections.unmodifiableList(declarationFqName_);
bitField0_ = (bitField0_ & ~0x00000002); bitField0_ = (bitField0_ & ~0x00000002);
} }
result.classFqName_ = classFqName_; result.declarationFqName_ = declarationFqName_;
if (((from_bitField0_ & 0x00000004) == 0x00000004)) { if (((from_bitField0_ & 0x00000004) == 0x00000004)) {
to_bitField0_ |= 0x00000001; to_bitField0_ |= 0x00000001;
} }
@@ -464,13 +464,13 @@ public final class PublicIdSignature extends
} }
} }
if (!other.classFqName_.isEmpty()) { if (!other.declarationFqName_.isEmpty()) {
if (classFqName_.isEmpty()) { if (declarationFqName_.isEmpty()) {
classFqName_ = other.classFqName_; declarationFqName_ = other.declarationFqName_;
bitField0_ = (bitField0_ & ~0x00000002); bitField0_ = (bitField0_ & ~0x00000002);
} else { } else {
ensureClassFqNameIsMutable(); ensureDeclarationFqNameIsMutable();
classFqName_.addAll(other.classFqName_); declarationFqName_.addAll(other.declarationFqName_);
} }
} }
@@ -574,67 +574,67 @@ public final class PublicIdSignature extends
return this; return this;
} }
private java.util.List<java.lang.Integer> classFqName_ = java.util.Collections.emptyList(); private java.util.List<java.lang.Integer> declarationFqName_ = java.util.Collections.emptyList();
private void ensureClassFqNameIsMutable() { private void ensureDeclarationFqNameIsMutable() {
if (!((bitField0_ & 0x00000002) == 0x00000002)) { if (!((bitField0_ & 0x00000002) == 0x00000002)) {
classFqName_ = new java.util.ArrayList<java.lang.Integer>(classFqName_); declarationFqName_ = new java.util.ArrayList<java.lang.Integer>(declarationFqName_);
bitField0_ |= 0x00000002; bitField0_ |= 0x00000002;
} }
} }
/** /**
* <code>repeated int32 class_fq_name = 2 [packed = true];</code> * <code>repeated int32 declaration_fq_name = 2 [packed = true];</code>
*/ */
public java.util.List<java.lang.Integer> public java.util.List<java.lang.Integer>
getClassFqNameList() { getDeclarationFqNameList() {
return java.util.Collections.unmodifiableList(classFqName_); return java.util.Collections.unmodifiableList(declarationFqName_);
} }
/** /**
* <code>repeated int32 class_fq_name = 2 [packed = true];</code> * <code>repeated int32 declaration_fq_name = 2 [packed = true];</code>
*/ */
public int getClassFqNameCount() { public int getDeclarationFqNameCount() {
return classFqName_.size(); return declarationFqName_.size();
} }
/** /**
* <code>repeated int32 class_fq_name = 2 [packed = true];</code> * <code>repeated int32 declaration_fq_name = 2 [packed = true];</code>
*/ */
public int getClassFqName(int index) { public int getDeclarationFqName(int index) {
return classFqName_.get(index); return declarationFqName_.get(index);
} }
/** /**
* <code>repeated int32 class_fq_name = 2 [packed = true];</code> * <code>repeated int32 declaration_fq_name = 2 [packed = true];</code>
*/ */
public Builder setClassFqName( public Builder setDeclarationFqName(
int index, int value) { int index, int value) {
ensureClassFqNameIsMutable(); ensureDeclarationFqNameIsMutable();
classFqName_.set(index, value); declarationFqName_.set(index, value);
return this; return this;
} }
/** /**
* <code>repeated int32 class_fq_name = 2 [packed = true];</code> * <code>repeated int32 declaration_fq_name = 2 [packed = true];</code>
*/ */
public Builder addClassFqName(int value) { public Builder addDeclarationFqName(int value) {
ensureClassFqNameIsMutable(); ensureDeclarationFqNameIsMutable();
classFqName_.add(value); declarationFqName_.add(value);
return this; return this;
} }
/** /**
* <code>repeated int32 class_fq_name = 2 [packed = true];</code> * <code>repeated int32 declaration_fq_name = 2 [packed = true];</code>
*/ */
public Builder addAllClassFqName( public Builder addAllDeclarationFqName(
java.lang.Iterable<? extends java.lang.Integer> values) { java.lang.Iterable<? extends java.lang.Integer> values) {
ensureClassFqNameIsMutable(); ensureDeclarationFqNameIsMutable();
org.jetbrains.kotlin.protobuf.AbstractMessageLite.Builder.addAll( org.jetbrains.kotlin.protobuf.AbstractMessageLite.Builder.addAll(
values, classFqName_); values, declarationFqName_);
return this; return this;
} }
/** /**
* <code>repeated int32 class_fq_name = 2 [packed = true];</code> * <code>repeated int32 declaration_fq_name = 2 [packed = true];</code>
*/ */
public Builder clearClassFqName() { public Builder clearDeclarationFqName() {
classFqName_ = java.util.Collections.emptyList(); declarationFqName_ = java.util.Collections.emptyList();
bitField0_ = (bitField0_ & ~0x00000002); bitField0_ = (bitField0_ & ~0x00000002);
return this; return this;
@@ -21,17 +21,17 @@ public interface PublicIdSignatureOrBuilder extends
int getPackageFqName(int index); int getPackageFqName(int index);
/** /**
* <code>repeated int32 class_fq_name = 2 [packed = true];</code> * <code>repeated int32 declaration_fq_name = 2 [packed = true];</code>
*/ */
java.util.List<java.lang.Integer> getClassFqNameList(); java.util.List<java.lang.Integer> getDeclarationFqNameList();
/** /**
* <code>repeated int32 class_fq_name = 2 [packed = true];</code> * <code>repeated int32 declaration_fq_name = 2 [packed = true];</code>
*/ */
int getClassFqNameCount(); int getDeclarationFqNameCount();
/** /**
* <code>repeated int32 class_fq_name = 2 [packed = true];</code> * <code>repeated int32 declaration_fq_name = 2 [packed = true];</code>
*/ */
int getClassFqName(int index); int getDeclarationFqName(int index);
/** /**
* <code>optional int64 member_uniq_id = 3;</code> * <code>optional int64 member_uniq_id = 3;</code>