[IR] Remove methods for computing full mangled names from non-IR manglers
A full mangled name of a declaration is a mangled name that includes the mangled names of all the declaration's parents. We don't use full mangled names for building `IdSignature`s. We use them in two places: - Generating stable names for JavaScript functions in Kotlin/JS (see `NameTables.kt`) - Generating names for LLVM symbols from lowered IR functions in Kotlin/Native (see `BinaryInterface.kt`) In both of these places we run the IR mangler, hence we don't need this functionality in other manglers.
This commit is contained in:
committed by
Space Team
parent
69aeddcba8
commit
47f8dedfa5
@@ -12,7 +12,6 @@ import org.jetbrains.kotlin.backend.common.serialization.mangle.SpecialDeclarati
|
|||||||
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
|
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
|
||||||
|
|
||||||
abstract class FirMangler : AbstractKotlinMangler<FirDeclaration>() {
|
abstract class FirMangler : AbstractKotlinMangler<FirDeclaration>() {
|
||||||
override fun FirDeclaration.mangleString(compatibleMode: Boolean): String = getMangleComputer(MangleMode.FULL, compatibleMode).computeMangle(this)
|
|
||||||
|
|
||||||
override fun FirDeclaration.signatureString(compatibleMode: Boolean): String = getMangleComputer(MangleMode.SIGNATURE, compatibleMode).computeMangle(this)
|
override fun FirDeclaration.signatureString(compatibleMode: Boolean): String = getMangleComputer(MangleMode.SIGNATURE, compatibleMode).computeMangle(this)
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,9 @@ class Ir2FirManglerAdapter(private val delegate: FirMangler) : AbstractKotlinMan
|
|||||||
|
|
||||||
override fun IrDeclaration.isExported(compatibleMode: Boolean): Boolean = delegate.run { fir().isExported(compatibleMode) }
|
override fun IrDeclaration.isExported(compatibleMode: Boolean): Boolean = delegate.run { fir().isExported(compatibleMode) }
|
||||||
|
|
||||||
override fun IrDeclaration.mangleString(compatibleMode: Boolean): String = delegate.run { fir().mangleString(compatibleMode) }
|
override fun IrDeclaration.mangleString(compatibleMode: Boolean): String {
|
||||||
|
error("Should not be called")
|
||||||
|
}
|
||||||
|
|
||||||
override fun IrDeclaration.signatureString(compatibleMode: Boolean): String = delegate.run { fir().signatureString(compatibleMode) }
|
override fun IrDeclaration.signatureString(compatibleMode: Boolean): String = delegate.run { fir().signatureString(compatibleMode) }
|
||||||
|
|
||||||
|
|||||||
@@ -5,9 +5,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.ir.util
|
package org.jetbrains.kotlin.ir.util
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
|
||||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
||||||
|
|
||||||
interface KotlinMangler<D : Any> {
|
interface KotlinMangler<D : Any> {
|
||||||
@@ -16,25 +14,6 @@ interface KotlinMangler<D : Any> {
|
|||||||
|
|
||||||
fun D.isExported(compatibleMode: Boolean): Boolean
|
fun D.isExported(compatibleMode: Boolean): Boolean
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the mangled name for the declaration [D], prefixed by mangled names of all its parents.
|
|
||||||
*
|
|
||||||
* For example, for `foo`'s getter in the following code:
|
|
||||||
* ```kotlin
|
|
||||||
* class Test {
|
|
||||||
* val foo: Int
|
|
||||||
* }
|
|
||||||
* ```
|
|
||||||
* the result of this function will be `"Test#<get-foo>(){}kotlin.Int"` or `"Test#<get-foo>(){}"` (depending on the target platform).
|
|
||||||
*
|
|
||||||
* The result of this function is only used for assigning names to binary symbols of Kotlin functions in the final executable produced
|
|
||||||
* by Kotlin/Native, and for generating stable names in the JavaScript code produced by Kotlin/JS. **It does not affect klib ABI.**
|
|
||||||
*
|
|
||||||
* @param compatibleMode If `true`, the mangled names of property backing fields are just those fields' names.
|
|
||||||
* Otherwise, mangles such fields exactly as their corresponding properties.
|
|
||||||
*/
|
|
||||||
fun D.mangleString(compatibleMode: Boolean): String
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the mangled name for the declaration [D] to be used for computing that declaration's [IdSignature].
|
* Returns the mangled name for the declaration [D] to be used for computing that declaration's [IdSignature].
|
||||||
*
|
*
|
||||||
@@ -55,16 +34,6 @@ interface KotlinMangler<D : Any> {
|
|||||||
*/
|
*/
|
||||||
fun D.signatureString(compatibleMode: Boolean): String
|
fun D.signatureString(compatibleMode: Boolean): String
|
||||||
|
|
||||||
/**
|
|
||||||
* Computes the hash code of the string returned by [mangleString] using the CityHash64 algorithm.
|
|
||||||
*
|
|
||||||
* **The result of this function does not affect klib ABI.**
|
|
||||||
*
|
|
||||||
* @param compatibleMode If `true`, the mangled names of property backing fields are just those fields' names.
|
|
||||||
* Otherwise, mangles such fields exactly as their corresponding properties.
|
|
||||||
*/
|
|
||||||
fun D.hashedMangle(compatibleMode: Boolean): Long = mangleString(compatibleMode).hashMangle
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Computes the hash code of the string returned by [signatureString] using the CityHash64 algorithm.
|
* Computes the hash code of the string returned by [signatureString] using the CityHash64 algorithm.
|
||||||
*
|
*
|
||||||
@@ -86,13 +55,41 @@ interface KotlinMangler<D : Any> {
|
|||||||
interface DescriptorMangler : KotlinMangler<DeclarationDescriptor> {
|
interface DescriptorMangler : KotlinMangler<DeclarationDescriptor> {
|
||||||
override val manglerName: String
|
override val manglerName: String
|
||||||
get() = "Descriptor"
|
get() = "Descriptor"
|
||||||
|
|
||||||
fun ClassDescriptor.mangleEnumEntryString(compatibleMode: Boolean): String
|
|
||||||
|
|
||||||
fun PropertyDescriptor.mangleFieldString(compatibleMode: Boolean): String
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IrMangler : KotlinMangler<IrDeclaration> {
|
interface IrMangler : KotlinMangler<IrDeclaration> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the mangled name for the declaration, prefixed by mangled names of all its parents.
|
||||||
|
*
|
||||||
|
* For example, for `foo`'s getter in the following code:
|
||||||
|
* ```kotlin
|
||||||
|
* class Test {
|
||||||
|
* val foo: Int
|
||||||
|
* }
|
||||||
|
* ```
|
||||||
|
* the result of this function will be `"Test#<get-foo>(){}kotlin.Int"` or `"Test#<get-foo>(){}"`
|
||||||
|
* (depending on the target platform).
|
||||||
|
*
|
||||||
|
* The result of this function is only used for assigning names to binary symbols of Kotlin functions in the final executable
|
||||||
|
* produced by Kotlin/Native, and for generating stable names in the JavaScript code produced by Kotlin/JS.
|
||||||
|
* **It does not affect klib ABI.**
|
||||||
|
*
|
||||||
|
* @param compatibleMode If `true`, the mangled names of property backing fields are just those fields' names.
|
||||||
|
* Otherwise, mangles such fields exactly as their corresponding properties.
|
||||||
|
*/
|
||||||
|
fun IrDeclaration.mangleString(compatibleMode: Boolean): String
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Computes the hash code of the string returned by [mangleString] using the CityHash64 algorithm.
|
||||||
|
*
|
||||||
|
* **The result of this function does not affect klib ABI.**
|
||||||
|
*
|
||||||
|
* @param compatibleMode If `true`, the mangled names of property backing fields are just those fields' names.
|
||||||
|
* Otherwise, mangles such fields exactly as their corresponding properties.
|
||||||
|
*/
|
||||||
|
fun IrDeclaration.hashedMangle(compatibleMode: Boolean): Long = mangleString(compatibleMode).hashMangle
|
||||||
|
|
||||||
override val manglerName: String
|
override val manglerName: String
|
||||||
get() = "Ir"
|
get() = "Ir"
|
||||||
}
|
}
|
||||||
|
|||||||
-6
@@ -61,8 +61,6 @@ class ManglerChecker(
|
|||||||
private fun IrDeclaration.shouldBeSkipped(): Boolean = accept(skipper, null)
|
private fun IrDeclaration.shouldBeSkipped(): Boolean = accept(skipper, null)
|
||||||
private fun KotlinMangler<IrDeclaration>.isExportCheck(declaration: IrDeclaration) =
|
private fun KotlinMangler<IrDeclaration>.isExportCheck(declaration: IrDeclaration) =
|
||||||
!declaration.shouldBeSkipped() && declaration.isExported(false)
|
!declaration.shouldBeSkipped() && declaration.isExported(false)
|
||||||
private fun KotlinMangler<IrDeclaration>.stringMangle(declaration: IrDeclaration) =
|
|
||||||
declaration.mangleString(compatibleMode = false)
|
|
||||||
|
|
||||||
private fun KotlinMangler<IrDeclaration>.signatureMangle(declaration: IrDeclaration) =
|
private fun KotlinMangler<IrDeclaration>.signatureMangle(declaration: IrDeclaration) =
|
||||||
declaration.signatureString(compatibleMode = false)
|
declaration.signatureString(compatibleMode = false)
|
||||||
@@ -99,10 +97,6 @@ class ManglerChecker(
|
|||||||
|
|
||||||
if (!exported) return
|
if (!exported) return
|
||||||
|
|
||||||
manglers.checkAllEqual("", { stringMangle(declaration) }) { m1, r1, m2, r2 ->
|
|
||||||
error("FULL: ${declaration.render()}\n ${m1.manglerName}: $r1\n ${m2.manglerName}: $r2\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
manglers.checkAllEqual("", { signatureMangle(declaration) }) { m1, r1, m2, r2 ->
|
manglers.checkAllEqual("", { signatureMangle(declaration) }) { m1, r1, m2, r2 ->
|
||||||
error("SIG: ${declaration.render()}\n ${m1.manglerName}: $r1\n ${m2.manglerName}: $r2\n")
|
error("SIG: ${declaration.render()}\n ${m1.manglerName}: $r1\n ${m2.manglerName}: $r2\n")
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-11
@@ -19,12 +19,6 @@ abstract class DescriptorBasedKotlinManglerImpl : AbstractKotlinMangler<Declarat
|
|||||||
private fun withMode(mode: MangleMode, compatibleMode: Boolean, descriptor: DeclarationDescriptor): String =
|
private fun withMode(mode: MangleMode, compatibleMode: Boolean, descriptor: DeclarationDescriptor): String =
|
||||||
getMangleComputer(mode, compatibleMode).computeMangle(descriptor)
|
getMangleComputer(mode, compatibleMode).computeMangle(descriptor)
|
||||||
|
|
||||||
override fun ClassDescriptor.mangleEnumEntryString(compatibleMode: Boolean): String = withMode(MangleMode.FQNAME, compatibleMode, this)
|
|
||||||
|
|
||||||
override fun PropertyDescriptor.mangleFieldString(compatibleMode: Boolean): String = mangleString(compatibleMode)
|
|
||||||
|
|
||||||
override fun DeclarationDescriptor.mangleString(compatibleMode: Boolean): String = withMode(MangleMode.FULL, compatibleMode, this)
|
|
||||||
|
|
||||||
override fun DeclarationDescriptor.signatureString(compatibleMode: Boolean): String = withMode(MangleMode.SIGNATURE, compatibleMode, this)
|
override fun DeclarationDescriptor.signatureString(compatibleMode: Boolean): String = withMode(MangleMode.SIGNATURE, compatibleMode, this)
|
||||||
|
|
||||||
override fun DeclarationDescriptor.isExported(compatibleMode: Boolean): Boolean = getExportChecker(compatibleMode).check(this, SpecialDeclarationType.REGULAR)
|
override fun DeclarationDescriptor.isExported(compatibleMode: Boolean): Boolean = getExportChecker(compatibleMode).check(this, SpecialDeclarationType.REGULAR)
|
||||||
@@ -40,11 +34,7 @@ class Ir2DescriptorManglerAdapter(private val delegate: DescriptorBasedKotlinMan
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun IrDeclaration.mangleString(compatibleMode: Boolean): String {
|
override fun IrDeclaration.mangleString(compatibleMode: Boolean): String {
|
||||||
return when (this) {
|
error("Should not be called")
|
||||||
is IrEnumEntry -> delegate.run { descriptor.mangleEnumEntryString(compatibleMode) }
|
|
||||||
is IrField -> delegate.run { descriptor.mangleFieldString(compatibleMode) }
|
|
||||||
else -> delegate.run { descriptor.mangleString(compatibleMode) }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun IrDeclaration.signatureString(compatibleMode: Boolean): String = delegate.run { descriptor.signatureString(compatibleMode) }
|
override fun IrDeclaration.signatureString(compatibleMode: Boolean): String = delegate.run { descriptor.signatureString(compatibleMode) }
|
||||||
|
|||||||
-9
@@ -20,17 +20,8 @@ object DisabledDescriptorMangler : KotlinMangler.DescriptorMangler {
|
|||||||
override fun DeclarationDescriptor.isExported(compatibleMode: Boolean): Boolean =
|
override fun DeclarationDescriptor.isExported(compatibleMode: Boolean): Boolean =
|
||||||
error("Should not be called")
|
error("Should not be called")
|
||||||
|
|
||||||
override fun DeclarationDescriptor.mangleString(compatibleMode: Boolean): String =
|
|
||||||
error("Should not be called")
|
|
||||||
|
|
||||||
override fun DeclarationDescriptor.signatureString(compatibleMode: Boolean): String =
|
override fun DeclarationDescriptor.signatureString(compatibleMode: Boolean): String =
|
||||||
error("Should not be called")
|
error("Should not be called")
|
||||||
|
|
||||||
override fun ClassDescriptor.mangleEnumEntryString(compatibleMode: Boolean): String =
|
|
||||||
error("Should not be called")
|
|
||||||
|
|
||||||
override fun PropertyDescriptor.mangleFieldString(compatibleMode: Boolean): String =
|
|
||||||
error("Should not be called")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
object DisabledIdSignatureDescriptor : IdSignatureDescriptor(DisabledDescriptorMangler) {
|
object DisabledIdSignatureDescriptor : IdSignatureDescriptor(DisabledDescriptorMangler) {
|
||||||
|
|||||||
Reference in New Issue
Block a user