Disambiguate upper bounds in the mangling.

This commit is contained in:
Alexander Gorshenev
2017-04-06 03:42:59 +03:00
committed by alexander-gorshenev
parent a69def4254
commit f91bc457db
@@ -82,13 +82,27 @@ private val exportForCppRuntimeAnnotation = FqName("konan.internal.ExportForCppR
private val exportForCompilerAnnotation = FqName("konan.internal.ExportForCompiler")
private fun typeToHashString(type: KotlinType): String {
if (TypeUtils.isTypeParameter(type)) return "GENERIC"
private fun acyclicTypeMangler(visited: MutableSet<TypeParameterDescriptor>, type: KotlinType): String {
val descriptor = TypeUtils.getTypeParameterDescriptorOrNull(type)
if (descriptor != null) {
val upperBounds = if (visited.contains(descriptor)) "" else {
visited.add(descriptor)
descriptor.upperBounds.map {
val bound = acyclicTypeMangler(visited, it)
if (bound == "kotlin.Any?") "" else "_$bound"
}.joinToString("")
}
return "GENERIC" + upperBounds
}
var hashString = TypeUtils.getClassDescriptor(type)!!.fqNameSafe.asString()
if (!type.arguments.isEmpty()) {
hashString += "<${type.arguments.map {
typeToHashString(it.type)
val variance = it.projectionKind.label
val projection = if (variance == "") "" else "${variance}_"
projection + acyclicTypeMangler(visited, it.type)
}.joinToString(",")}>"
}
@@ -96,9 +110,12 @@ private fun typeToHashString(type: KotlinType): String {
return hashString
}
private fun typeToHashString(type: KotlinType)
= acyclicTypeMangler(mutableSetOf<TypeParameterDescriptor>(), type)
private val FunctionDescriptor.signature: String
get() {
val extensionReceiverPart = this.extensionReceiverParameter?.let { "${it.type}." } ?: ""
val extensionReceiverPart = this.extensionReceiverParameter?.let { "@${typeToHashString(it.type)}." } ?: ""
val argsPart = this.valueParameters.map {
typeToHashString(it.type)
@@ -180,4 +197,4 @@ internal val ClassDescriptor.objectInstanceFieldSymbolName: String
assert (!this.isUnit())
return "kobjref:$fqNameSafe"
}
}