Use a hash of public name as descriptor deserialization id.
This commit is contained in:
committed by
alexander-gorshenev
parent
9b4a1f1569
commit
ff27066502
+25
@@ -163,6 +163,31 @@ internal val FunctionDescriptor.symbolName: String
|
|||||||
return "kfun:$containingDeclarationPart$functionName"
|
return "kfun:$containingDeclarationPart$functionName"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal val PropertyDescriptor.symbolName: String
|
||||||
|
get() {
|
||||||
|
val containingDeclarationPart = containingDeclaration.fqNameSafe.let {
|
||||||
|
if (it.isRoot) "" else "$it."
|
||||||
|
}
|
||||||
|
return "kprop:$containingDeclarationPart$name"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
internal val TypeParameterDescriptor.symbolName: String
|
||||||
|
get() {
|
||||||
|
val containingDeclarationPart = containingDeclaration.fqNameSafe.let {
|
||||||
|
if (it.isRoot) "" else "$it."
|
||||||
|
}
|
||||||
|
return "ktypeparam:$containingDeclarationPart$name"
|
||||||
|
}
|
||||||
|
|
||||||
|
internal val ValueParameterDescriptor.symbolName: String
|
||||||
|
get() {
|
||||||
|
val containingDeclarationPart = containingDeclaration.fqNameSafe.let {
|
||||||
|
if (it.isRoot) "" else "$it."
|
||||||
|
}
|
||||||
|
return "kvalueparam:$containingDeclarationPart$name"
|
||||||
|
}
|
||||||
|
|
||||||
private fun getStringValue(annotation: AnnotationDescriptor): String? {
|
private fun getStringValue(annotation: AnnotationDescriptor): String? {
|
||||||
annotation.allValueArguments.values.ifNotEmpty {
|
annotation.allValueArguments.values.ifNotEmpty {
|
||||||
val stringValue = this.single() as StringValue
|
val stringValue = this.single() as StringValue
|
||||||
|
|||||||
+30
-1
@@ -24,6 +24,31 @@ import org.jetbrains.kotlin.types.KotlinType
|
|||||||
import org.jetbrains.kotlin.serialization.deserialization.NameResolver
|
import org.jetbrains.kotlin.serialization.deserialization.NameResolver
|
||||||
import org.jetbrains.kotlin.serialization.ProtoBuf
|
import org.jetbrains.kotlin.serialization.ProtoBuf
|
||||||
import org.jetbrains.kotlin.serialization.ProtoBuf.QualifiedNameTable.QualifiedName
|
import org.jetbrains.kotlin.serialization.ProtoBuf.QualifiedNameTable.QualifiedName
|
||||||
|
import org.jetbrains.kotlin.backend.konan.llvm.isExported
|
||||||
|
import org.jetbrains.kotlin.backend.konan.llvm.typeInfoSymbolName
|
||||||
|
import org.jetbrains.kotlin.backend.konan.llvm.symbolName
|
||||||
|
import org.jetbrains.kotlin.backend.konan.llvm.localHash
|
||||||
|
|
||||||
|
// TODO: We take Long hash .toInt() here.
|
||||||
|
// Make it long all the way down to the protobuf?
|
||||||
|
internal fun DeclarationDescriptor.uniqId(): Int = when (this) {
|
||||||
|
is FunctionDescriptor -> {
|
||||||
|
this.symbolName.localHash.value.toInt()
|
||||||
|
}
|
||||||
|
is PropertyDescriptor -> {
|
||||||
|
this.symbolName.localHash.value.toInt()
|
||||||
|
}
|
||||||
|
is TypeParameterDescriptor -> {
|
||||||
|
this.symbolName.localHash.value.toInt()
|
||||||
|
}
|
||||||
|
is ValueParameterDescriptor -> {
|
||||||
|
this.symbolName.localHash.value.toInt()
|
||||||
|
}
|
||||||
|
is ClassDescriptor -> {
|
||||||
|
this.typeInfoSymbolName.localHash.value.toInt()
|
||||||
|
}
|
||||||
|
else -> error("Unexpected exported descriptor: $this")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// TODO: we currently just assign each encountered
|
// TODO: we currently just assign each encountered
|
||||||
@@ -48,7 +73,11 @@ class DescriptorTable(val builtIns: IrBuiltIns) {
|
|||||||
|
|
||||||
fun indexByValue(value: DeclarationDescriptor): Int {
|
fun indexByValue(value: DeclarationDescriptor): Int {
|
||||||
val index = table.getOrPut(value) {
|
val index = table.getOrPut(value) {
|
||||||
currentIndex ++
|
if (!value.isExported()) {
|
||||||
|
currentIndex++
|
||||||
|
} else {
|
||||||
|
value.uniqId()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return index
|
return index
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user