Reflect the absence of parent fqname index in the absence of protobuf extension.
This commit is contained in:
committed by
alexander-gorshenev
parent
0cc3fa56ab
commit
31c490e14e
+4
-2
@@ -134,7 +134,7 @@ internal class IrDescriptorSerializer(
|
||||
val classOrPackage = descriptor.classOrPackage
|
||||
val parentFqNameIndex = if (classOrPackage is ClassOrPackageFragmentDescriptor) {
|
||||
stringTable.getClassOrPackageFqNameIndex(classOrPackage)
|
||||
} else { -1 }
|
||||
} else null
|
||||
|
||||
val index = descriptorTable.indexByValue(descriptor)
|
||||
// For getters and setters we use
|
||||
@@ -150,7 +150,9 @@ internal class IrDescriptorSerializer(
|
||||
.setKind(kotlinDescriptorKind(descriptor))
|
||||
.setIndex(index)
|
||||
.setOriginalIndex(originalIndex)
|
||||
.setClassOrPackage(parentFqNameIndex)
|
||||
|
||||
if (parentFqNameIndex != null)
|
||||
proto.setClassOrPackage(parentFqNameIndex)
|
||||
|
||||
when (descriptor) {
|
||||
is FunctionDescriptor ->
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ message KotlinDescriptor {
|
||||
required UniqId uniq_id = 3;
|
||||
required UniqId original_uniq_id = 4;
|
||||
// index in fq name table
|
||||
required int32 class_or_package = 5;
|
||||
optional int32 class_or_package = 5;
|
||||
// Descriptor kind specific fields.
|
||||
optional KotlinType type = 6;
|
||||
repeated KotlinDescriptor value_parameter = 7;
|
||||
|
||||
+5
-5
@@ -53,14 +53,14 @@ internal class KonanSerializerExtension(val context: Context, val util: KonanSer
|
||||
super.serializeEnumEntry(descriptor, proto)
|
||||
}
|
||||
|
||||
fun DeclarationDescriptor.parentFqNameIndex(): Int {
|
||||
fun DeclarationDescriptor.parentFqNameIndex(): Int? {
|
||||
|
||||
if (this.containingDeclaration is ClassOrPackageFragmentDescriptor) {
|
||||
val parentIndex = stringTable.getClassOrPackageFqNameIndex(
|
||||
this.containingDeclaration as ClassOrPackageFragmentDescriptor)
|
||||
return parentIndex
|
||||
} else {
|
||||
return -1
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ internal class KonanSerializerExtension(val context: Context, val util: KonanSer
|
||||
proto.setConstructorIndex(
|
||||
inlineDescriptorTable.indexByValue(descriptor))
|
||||
val parentIndex = descriptor.parentFqNameIndex()
|
||||
proto.setExtension(KonanLinkData.constructorParent, parentIndex)
|
||||
if (parentIndex != null) proto.setExtension(KonanLinkData.constructorParent, parentIndex)
|
||||
|
||||
super.serializeConstructor(descriptor, proto)
|
||||
}
|
||||
@@ -86,7 +86,7 @@ internal class KonanSerializerExtension(val context: Context, val util: KonanSer
|
||||
proto.setFunctionIndex(
|
||||
inlineDescriptorTable.indexByValue(descriptor))
|
||||
val parentIndex = descriptor.parentFqNameIndex()
|
||||
proto.setExtension(KonanLinkData.functionParent, parentIndex)
|
||||
if (parentIndex != null) proto.setExtension(KonanLinkData.functionParent, parentIndex)
|
||||
super.serializeFunction(descriptor, proto)
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ internal class KonanSerializerExtension(val context: Context, val util: KonanSer
|
||||
|
||||
override fun serializeProperty(descriptor: PropertyDescriptor, proto: ProtoBuf.Property.Builder) {
|
||||
val parentIndex = descriptor.parentFqNameIndex()
|
||||
proto.setExtension(KonanLinkData.propertyParent, parentIndex)
|
||||
if (parentIndex != null) proto.setExtension(KonanLinkData.propertyParent, parentIndex)
|
||||
val variable = originalVariables[descriptor]
|
||||
if (variable != null) {
|
||||
proto.setExtension(KonanLinkData.usedAsVariable, true)
|
||||
|
||||
+12
-21
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.serialization.deserialization.descriptors.*
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.SinceKotlinInfoTable
|
||||
import org.jetbrains.kotlin.serialization.deserialization.findClassAcrossModuleDependencies
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.protobuf.GeneratedMessageLite
|
||||
|
||||
// This class knows how to construct contexts for
|
||||
// MemberDeserializer to deserialize descriptors declared in IR.
|
||||
@@ -84,9 +85,9 @@ class LocalDeclarationDeserializer(val rootDescriptor: DeserializedCallableMembe
|
||||
}
|
||||
}
|
||||
|
||||
fun memberDeserializerByParentFqNameIndex(fqName: Int): MemberDeserializer {
|
||||
fun memberDeserializerByParentFqNameIndex(fqNameIndex: Int): MemberDeserializer {
|
||||
|
||||
val parent = getDescriptorByFqNameIndex(module, fqName)
|
||||
val parent = getDescriptorByFqNameIndex(module, fqNameIndex)
|
||||
val typeParameters = if (parent is DeserializedClassDescriptor) {
|
||||
parent.classProto.typeParameterList
|
||||
} else listOf<ProtoBuf.TypeParameter>()
|
||||
@@ -96,18 +97,17 @@ class LocalDeclarationDeserializer(val rootDescriptor: DeserializedCallableMembe
|
||||
|
||||
}
|
||||
|
||||
fun deserializeFunction(proto: ProtoBuf.Function): FunctionDescriptor {
|
||||
val containingFqName = proto.getExtension(KonanLinkData.functionParent)
|
||||
// TODO: learn to take the containing IR declaration
|
||||
val memberDeserializer = if (containingFqName == -1)
|
||||
this.memberDeserializer
|
||||
else
|
||||
private fun memberDeserializer(proto: GeneratedMessageLite): MemberDeserializer {
|
||||
val containingFqName = proto.parent
|
||||
return if (containingFqName != null) {
|
||||
memberDeserializerByParentFqNameIndex(containingFqName)
|
||||
|
||||
val function = memberDeserializer.loadFunction(proto)
|
||||
return function
|
||||
// TODO: learn to take the containing IR declaration
|
||||
} else this.memberDeserializer
|
||||
}
|
||||
|
||||
fun deserializeFunction(proto: ProtoBuf.Function): FunctionDescriptor =
|
||||
memberDeserializer(proto).loadFunction(proto)
|
||||
|
||||
fun deserializeConstructor(proto: ProtoBuf.Constructor): ConstructorDescriptor {
|
||||
|
||||
val containingFqName = proto.getExtension(KonanLinkData.constructorParent)
|
||||
@@ -118,17 +118,8 @@ class LocalDeclarationDeserializer(val rootDescriptor: DeserializedCallableMembe
|
||||
return constructor
|
||||
}
|
||||
|
||||
|
||||
fun deserializeProperty(proto: ProtoBuf.Property): VariableDescriptor {
|
||||
val containingFqName = proto.getExtension(KonanLinkData.propertyParent)
|
||||
|
||||
// TODO: learn to take the containing IR declaration
|
||||
val memberDeserializer = if (containingFqName == -1)
|
||||
this.memberDeserializer
|
||||
else
|
||||
memberDeserializerByParentFqNameIndex(containingFqName)
|
||||
|
||||
val property = memberDeserializer.loadProperty(proto)
|
||||
val property = memberDeserializer(proto).loadProperty(proto)
|
||||
|
||||
return if (proto.getExtension(KonanLinkData.usedAsVariable)) {
|
||||
propertyToVariable(property)
|
||||
|
||||
+32
@@ -4,6 +4,7 @@ import org.jetbrains.kotlin.serialization.KonanIr
|
||||
import org.jetbrains.kotlin.serialization.KonanLinkData
|
||||
import org.jetbrains.kotlin.serialization.KonanLinkData.*
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf
|
||||
import org.jetbrains.kotlin.protobuf.GeneratedMessageLite
|
||||
|
||||
fun newUniqId(index: Long): KonanLinkData.UniqId =
|
||||
KonanLinkData.UniqId.newBuilder().setIndex(index).build()
|
||||
@@ -84,6 +85,37 @@ fun inlineBody(encodedIR: String)
|
||||
.setEncodedIr(encodedIR)
|
||||
.build()
|
||||
|
||||
// -----------------------------------------------------------
|
||||
|
||||
val ProtoBuf.Function.parent: Int?
|
||||
get() = if (this.hasExtension(KonanLinkData.functionParent))
|
||||
this.getExtension(KonanLinkData.functionParent)
|
||||
else null
|
||||
|
||||
val ProtoBuf.Property.parent: Int?
|
||||
get() = if (this.hasExtension(KonanLinkData.propertyParent))
|
||||
this.getExtension(KonanLinkData.propertyParent)
|
||||
else null
|
||||
|
||||
|
||||
val ProtoBuf.Constructor.parent: Int?
|
||||
get() = if (this.hasExtension(KonanLinkData.constructorParent))
|
||||
this.getExtension(KonanLinkData.constructorParent)
|
||||
else null
|
||||
|
||||
val GeneratedMessageLite.parent: Int?
|
||||
get() = when (this) {
|
||||
is ProtoBuf.Function
|
||||
-> this.parent
|
||||
is ProtoBuf.Property
|
||||
-> this.parent
|
||||
is ProtoBuf.Constructor
|
||||
-> this.parent
|
||||
else
|
||||
-> error("Unexpected protobuf message")
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------
|
||||
|
||||
internal fun printType(proto: ProtoBuf.Type) {
|
||||
|
||||
Reference in New Issue
Block a user