[IR] Fix compatibility mode

- pass corresponding flag to mangler
 - properly handle local declarations in field initializers
 - fix KT-48912
This commit is contained in:
Roman Artemev
2021-10-05 10:37:11 +03:00
committed by TeamCityServer
parent 8f8c59e748
commit ba759fb61b
17 changed files with 75 additions and 74 deletions
@@ -14,15 +14,15 @@ import org.jetbrains.kotlin.fir.signaturer.FirMangler
@NoMutableState @NoMutableState
class FirJvmKotlinMangler(private val session: FirSession) : AbstractKotlinMangler<FirDeclaration>(), FirMangler { class FirJvmKotlinMangler(private val session: FirSession) : AbstractKotlinMangler<FirDeclaration>(), FirMangler {
override fun FirDeclaration.mangleString(): String = getMangleComputer(MangleMode.FULL).computeMangle(this) override fun FirDeclaration.mangleString(compatibleMode: Boolean): String = getMangleComputer(MangleMode.FULL, compatibleMode).computeMangle(this)
override fun FirDeclaration.signatureString(): String = getMangleComputer(MangleMode.SIGNATURE).computeMangle(this) override fun FirDeclaration.signatureString(compatibleMode: Boolean): String = getMangleComputer(MangleMode.SIGNATURE, compatibleMode).computeMangle(this)
override fun FirDeclaration.fqnString(): String = getMangleComputer(MangleMode.FQNAME).computeMangle(this) override fun FirDeclaration.fqnString(compatibleMode: Boolean): String = getMangleComputer(MangleMode.FQNAME, compatibleMode).computeMangle(this)
override fun FirDeclaration.isExported(compatibleMode: Boolean): Boolean = true override fun FirDeclaration.isExported(compatibleMode: Boolean): Boolean = true
override fun getExportChecker(compatibleMode: Boolean): KotlinExportChecker<FirDeclaration> { override fun getExportChecker(compatibleMode: Boolean): KotlinExportChecker<FirDeclaration> {
return object : KotlinExportChecker<FirDeclaration> { return object : KotlinExportChecker<FirDeclaration> {
override fun check(declaration: FirDeclaration, type: SpecialDeclarationType): Boolean = true override fun check(declaration: FirDeclaration, type: SpecialDeclarationType): Boolean = true
@@ -30,7 +30,7 @@ class FirJvmKotlinMangler(private val session: FirSession) : AbstractKotlinMangl
} }
} }
override fun getMangleComputer(mode: MangleMode): KotlinMangleComputer<FirDeclaration> { override fun getMangleComputer(mode: MangleMode, compatibleMode: Boolean): KotlinMangleComputer<FirDeclaration> {
return FirJvmMangleComputer(StringBuilder(256), mode, session) return FirJvmMangleComputer(StringBuilder(256), mode, session)
} }
} }
@@ -40,17 +40,17 @@ class FirBasedSignatureComposer(private val mangler: FirMangler) : Fir2IrSignatu
} }
override fun visitConstructor(constructor: FirConstructor, data: Any?) { override fun visitConstructor(constructor: FirConstructor, data: Any?) {
hashId = mangler.run { constructor.signatureMangle() } hashId = mangler.run { constructor.signatureMangle(compatibleMode = false) }
setExpected(constructor.isExpect) setExpected(constructor.isExpect)
} }
override fun visitSimpleFunction(simpleFunction: FirSimpleFunction, data: Any?) { override fun visitSimpleFunction(simpleFunction: FirSimpleFunction, data: Any?) {
hashId = mangler.run { simpleFunction.signatureMangle() } hashId = mangler.run { simpleFunction.signatureMangle(compatibleMode = false) }
setExpected(simpleFunction.isExpect) setExpected(simpleFunction.isExpect)
} }
override fun visitProperty(property: FirProperty, data: Any?) { override fun visitProperty(property: FirProperty, data: Any?) {
hashId = mangler.run { property.signatureMangle() } hashId = mangler.run { property.signatureMangle(compatibleMode = false) }
setExpected(property.isExpect) setExpected(property.isExpect)
} }
@@ -32,7 +32,7 @@ import kotlin.math.abs
private fun <T> mapToKey(declaration: T): String { private fun <T> mapToKey(declaration: T): String {
return with(JsManglerIr) { return with(JsManglerIr) {
if (declaration is IrDeclaration) { if (declaration is IrDeclaration) {
declaration.hashedMangle().toString() declaration.hashedMangle(compatibleMode = false).toString()
} else if (declaration is String) { } else if (declaration is String) {
declaration.hashMangle.toString() declaration.hashMangle.toString()
} else { } else {
@@ -15,13 +15,13 @@ interface KotlinMangler<D : Any> {
val String.hashMangle: Long val String.hashMangle: Long
fun D.isExported(compatibleMode: Boolean): Boolean fun D.isExported(compatibleMode: Boolean): Boolean
fun D.mangleString(): String fun D.mangleString(compatibleMode: Boolean): String
fun D.signatureString(): String fun D.signatureString(compatibleMode: Boolean): String
fun D.fqnString(): String fun D.fqnString(compatibleMode: Boolean): String
fun D.hashedMangle(): Long = mangleString().hashMangle fun D.hashedMangle(compatibleMode: Boolean): Long = mangleString(compatibleMode).hashMangle
fun D.signatureMangle(): Long = signatureString().hashMangle fun D.signatureMangle(compatibleMode: Boolean): Long = signatureString(compatibleMode).hashMangle
fun D.fqnMangle(): Long = fqnString().hashMangle fun D.fqnMangle(compatibleMode: Boolean): Long = fqnString(compatibleMode).hashMangle
fun D.isPlatformSpecificExport(): Boolean = false fun D.isPlatformSpecificExport(): Boolean = false
@@ -31,9 +31,9 @@ interface KotlinMangler<D : Any> {
override val manglerName: String override val manglerName: String
get() = "Descriptor" get() = "Descriptor"
fun ClassDescriptor.mangleEnumEntryString(): String fun ClassDescriptor.mangleEnumEntryString(compatibleMode: Boolean): String
fun PropertyDescriptor.mangleFieldString(): String fun PropertyDescriptor.mangleFieldString(compatibleMode: Boolean): String
} }
interface IrMangler : KotlinMangler<IrDeclaration> { interface IrMangler : KotlinMangler<IrDeclaration> {
@@ -31,7 +31,7 @@ class FakeOverrideChecker(
} }
} }
private fun validateFakeOverrides(clazz: IrClass) { private fun validateFakeOverrides(clazz: IrClass, compatibleMode: Boolean = false) {
val classId = clazz.classId ?: return val classId = clazz.classId ?: return
val classDescriptor = clazz.module.module.findClassAcrossModuleDependencies(classId) ?: return val classDescriptor = clazz.module.module.findClassAcrossModuleDependencies(classId) ?: return
// All enum entry overrides look like fake overrides in descriptor enum entries // All enum entry overrides look like fake overrides in descriptor enum entries
@@ -44,7 +44,7 @@ class FakeOverrideChecker(
.filterNot { it.visibility == DescriptorVisibilities.PRIVATE || it.visibility == DescriptorVisibilities.INVISIBLE_FAKE } .filterNot { it.visibility == DescriptorVisibilities.PRIVATE || it.visibility == DescriptorVisibilities.INVISIBLE_FAKE }
val descriptorSignatures = descriptorFakeOverrides val descriptorSignatures = descriptorFakeOverrides
.map { with(descriptorMangler) { it.signatureString() } } .map { with(descriptorMangler) { it.signatureString(compatibleMode) } }
.sorted() .sorted()
val irFakeOverrides = clazz.declarations val irFakeOverrides = clazz.declarations
@@ -56,7 +56,7 @@ class FakeOverrideChecker(
} }
val irSignatures = irFakeOverrides val irSignatures = irFakeOverrides
.map { with(irMangler) { it.signatureString() } } .map { with(irMangler) { it.signatureString(compatibleMode) } }
.sorted() .sorted()
// We can't have equality here because dependency libraries could have // We can't have equality here because dependency libraries could have
@@ -165,7 +165,7 @@ class DescriptorByIdSignatureFinder(
// We don't compute id for typealiases and classes. // We don't compute id for typealiases and classes.
candidate is ClassDescriptor || candidate is TypeAliasDescriptor candidate is ClassDescriptor || candidate is TypeAliasDescriptor
} else { } else {
val candidateHash = with(mangler) { candidate.signatureMangle() } val candidateHash = with(mangler) { candidate.signatureMangle(compatibleMode = false) }
candidateHash == id candidateHash == id
} }
} }
@@ -12,5 +12,5 @@ abstract class AbstractKotlinMangler<D : Any> : KotlinMangler<D> {
override val String.hashMangle get() = cityHash64() override val String.hashMangle get() = cityHash64()
abstract fun getExportChecker(compatibleMode: Boolean): KotlinExportChecker<D> abstract fun getExportChecker(compatibleMode: Boolean): KotlinExportChecker<D>
abstract fun getMangleComputer(mode: MangleMode): KotlinMangleComputer<D> abstract fun getMangleComputer(mode: MangleMode, compatibleMode: Boolean): KotlinMangleComputer<D>
} }
@@ -52,13 +52,13 @@ class ManglerChecker(vararg _manglers: KotlinMangler<IrDeclaration>) : IrElement
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) = private fun KotlinMangler<IrDeclaration>.stringMangle(declaration: IrDeclaration) =
declaration.mangleString() declaration.mangleString(compatibleMode = false)
private fun KotlinMangler<IrDeclaration>.signatureMangle(declaration: IrDeclaration) = private fun KotlinMangler<IrDeclaration>.signatureMangle(declaration: IrDeclaration) =
declaration.signatureString() declaration.signatureString(compatibleMode = false)
private fun KotlinMangler<IrDeclaration>.fqnMangle(declaration: IrDeclaration) = private fun KotlinMangler<IrDeclaration>.fqnMangle(declaration: IrDeclaration) =
declaration.fqnString() declaration.fqnString(compatibleMode = false)
private fun <T : Any, R> Iterable<T>.checkAllEqual(init: R, op: T.() -> R, onError: (T, R, T, R) -> Unit): R { private fun <T : Any, R> Iterable<T>.checkAllEqual(init: R, op: T.() -> R, onError: (T, R, T, R) -> Unit): R {
var prev: T? = null var prev: T? = null
@@ -16,18 +16,18 @@ import org.jetbrains.kotlin.ir.util.KotlinMangler
import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.KotlinType
abstract class DescriptorBasedKotlinManglerImpl : AbstractKotlinMangler<DeclarationDescriptor>(), KotlinMangler.DescriptorMangler { abstract class DescriptorBasedKotlinManglerImpl : AbstractKotlinMangler<DeclarationDescriptor>(), KotlinMangler.DescriptorMangler {
private fun withMode(mode: MangleMode, descriptor: DeclarationDescriptor): String = private fun withMode(mode: MangleMode, compatibleMode: Boolean, descriptor: DeclarationDescriptor): String =
getMangleComputer(mode).computeMangle(descriptor) getMangleComputer(mode, compatibleMode).computeMangle(descriptor)
override fun ClassDescriptor.mangleEnumEntryString(): String = withMode(MangleMode.FQNAME, this) override fun ClassDescriptor.mangleEnumEntryString(compatibleMode: Boolean): String = withMode(MangleMode.FQNAME, compatibleMode, this)
override fun PropertyDescriptor.mangleFieldString(): String = mangleString() override fun PropertyDescriptor.mangleFieldString(compatibleMode: Boolean): String = mangleString(compatibleMode)
override fun DeclarationDescriptor.mangleString(): String = withMode(MangleMode.FULL, this) override fun DeclarationDescriptor.mangleString(compatibleMode: Boolean): String = withMode(MangleMode.FULL, compatibleMode, this)
override fun DeclarationDescriptor.signatureString(): String = withMode(MangleMode.SIGNATURE, this) override fun DeclarationDescriptor.signatureString(compatibleMode: Boolean): String = withMode(MangleMode.SIGNATURE, compatibleMode, this)
override fun DeclarationDescriptor.fqnString(): String = withMode(MangleMode.FQNAME, this) override fun DeclarationDescriptor.fqnString(compatibleMode: Boolean): String = withMode(MangleMode.FQNAME, 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)
} }
@@ -41,19 +41,19 @@ class Ir2DescriptorManglerAdapter(private val delegate: DescriptorBasedKotlinMan
return delegate.run { descriptor.isExported(compatibleMode) } return delegate.run { descriptor.isExported(compatibleMode) }
} }
override fun IrDeclaration.mangleString(): String { override fun IrDeclaration.mangleString(compatibleMode: Boolean): String {
return when (this) { return when (this) {
is IrEnumEntry -> delegate.run { descriptor.mangleEnumEntryString() } is IrEnumEntry -> delegate.run { descriptor.mangleEnumEntryString(compatibleMode) }
is IrField -> delegate.run { descriptor.mangleFieldString() } is IrField -> delegate.run { descriptor.mangleFieldString(compatibleMode) }
else -> delegate.run { descriptor.mangleString() } else -> delegate.run { descriptor.mangleString(compatibleMode) }
} }
} }
override fun IrDeclaration.signatureString(): String = delegate.run { descriptor.signatureString() } override fun IrDeclaration.signatureString(compatibleMode: Boolean): String = delegate.run { descriptor.signatureString(compatibleMode) }
override fun IrDeclaration.fqnString(): String = delegate.run { descriptor.fqnString() } override fun IrDeclaration.fqnString(compatibleMode: Boolean): String = delegate.run { descriptor.fqnString(compatibleMode) }
override fun getMangleComputer(mode: MangleMode): KotlinMangleComputer<IrDeclaration> = override fun getMangleComputer(mode: MangleMode, compatibleMode: Boolean): KotlinMangleComputer<IrDeclaration> =
error("Should not have been reached") error("Should not have been reached")
override fun getExportChecker(compatibleMode: Boolean): KotlinExportChecker<IrDeclaration> { override fun getExportChecker(compatibleMode: Boolean): KotlinExportChecker<IrDeclaration> {
@@ -13,11 +13,11 @@ import org.jetbrains.kotlin.ir.util.KotlinMangler
abstract class IrBasedKotlinManglerImpl : AbstractKotlinMangler<IrDeclaration>(), KotlinMangler.IrMangler { abstract class IrBasedKotlinManglerImpl : AbstractKotlinMangler<IrDeclaration>(), KotlinMangler.IrMangler {
override fun IrDeclaration.mangleString(): String = getMangleComputer(MangleMode.FULL).computeMangle(this) override fun IrDeclaration.mangleString(compatibleMode: Boolean): String = getMangleComputer(MangleMode.FULL, compatibleMode).computeMangle(this)
override fun IrDeclaration.signatureString(): String = getMangleComputer(MangleMode.SIGNATURE).computeMangle(this) override fun IrDeclaration.signatureString(compatibleMode: Boolean): String = getMangleComputer(MangleMode.SIGNATURE, compatibleMode).computeMangle(this)
override fun IrDeclaration.fqnString(): String = getMangleComputer(MangleMode.FQNAME).computeMangle(this) override fun IrDeclaration.fqnString(compatibleMode: Boolean): String = getMangleComputer(MangleMode.FQNAME, compatibleMode).computeMangle(this)
override fun IrDeclaration.isExported(compatibleMode: Boolean): Boolean = override fun IrDeclaration.isExported(compatibleMode: Boolean): Boolean =
getExportChecker(compatibleMode).check(this, SpecialDeclarationType.REGULAR) getExportChecker(compatibleMode).check(this, SpecialDeclarationType.REGULAR)
@@ -20,7 +20,7 @@ import org.jetbrains.kotlin.ir.visitors.acceptVoid
import org.jetbrains.kotlin.types.Variance import org.jetbrains.kotlin.types.Variance
import org.jetbrains.kotlin.utils.addToStdlib.ifNotEmpty import org.jetbrains.kotlin.utils.addToStdlib.ifNotEmpty
abstract class IrMangleComputer(protected val builder: StringBuilder, private val mode: MangleMode) : abstract class IrMangleComputer(protected val builder: StringBuilder, private val mode: MangleMode, protected val compatibleMode: Boolean) :
IrElementVisitorVoid, KotlinMangleComputer<IrDeclaration> { IrElementVisitorVoid, KotlinMangleComputer<IrDeclaration> {
private val typeParameterContainer = ArrayList<IrDeclaration>(4) private val typeParameterContainer = ArrayList<IrDeclaration>(4)
@@ -260,10 +260,11 @@ abstract class IrMangleComputer(protected val builder: StringBuilder, private va
override fun visitField(declaration: IrField) { override fun visitField(declaration: IrField) {
val prop = declaration.correspondingPropertySymbol val prop = declaration.correspondingPropertySymbol
if (prop != null) { if (compatibleMode || prop == null) { // act as used to be (KT-48912)
visitProperty(prop.owner) // test compiler/testData/codegen/box/ir/serializationRegressions/anonFakeOverride.kt
} else {
declaration.mangleSimpleDeclaration(declaration.name.asString()) declaration.mangleSimpleDeclaration(declaration.name.asString())
} else {
visitProperty(prop.owner)
} }
} }
@@ -72,7 +72,7 @@ open class IdSignatureDescriptor(private val mangler: KotlinMangler.DescriptorMa
override fun visitFunctionDescriptor(descriptor: FunctionDescriptor, data: Nothing?) { override fun visitFunctionDescriptor(descriptor: FunctionDescriptor, data: Nothing?) {
collectParents(descriptor) collectParents(descriptor)
hashId = mangler.run { descriptor.signatureMangle() } hashId = mangler.run { descriptor.signatureMangle(compatibleMode = false) }
isTopLevelPrivate = isTopLevelPrivate or descriptor.isTopLevelPrivate isTopLevelPrivate = isTopLevelPrivate or descriptor.isTopLevelPrivate
setDescription(descriptor) setDescription(descriptor)
setExpected(descriptor.isExpect) setExpected(descriptor.isExpect)
@@ -116,7 +116,7 @@ open class IdSignatureDescriptor(private val mangler: KotlinMangler.DescriptorMa
override fun visitConstructorDescriptor(constructorDescriptor: ConstructorDescriptor, data: Nothing?) { override fun visitConstructorDescriptor(constructorDescriptor: ConstructorDescriptor, data: Nothing?) {
collectParents(constructorDescriptor) collectParents(constructorDescriptor)
hashId = mangler.run { constructorDescriptor.signatureMangle() } hashId = mangler.run { constructorDescriptor.signatureMangle(compatibleMode = false) }
platformSpecificConstructor(constructorDescriptor) platformSpecificConstructor(constructorDescriptor)
} }
@@ -133,7 +133,7 @@ open class IdSignatureDescriptor(private val mangler: KotlinMangler.DescriptorMa
isTopLevelPrivate = isTopLevelPrivate or actualDeclaration.isTopLevelPrivate isTopLevelPrivate = isTopLevelPrivate or actualDeclaration.isTopLevelPrivate
hashId = mangler.run { actualDeclaration.signatureMangle() } hashId = mangler.run { actualDeclaration.signatureMangle(compatibleMode = false) }
setExpected(actualDeclaration.isExpect) setExpected(actualDeclaration.isExpect)
platformSpecificProperty(actualDeclaration) platformSpecificProperty(actualDeclaration)
if (type == SpecialDeclarationType.BACKING_FIELD) { if (type == SpecialDeclarationType.BACKING_FIELD) {
@@ -150,7 +150,7 @@ open class IdSignatureDescriptor(private val mangler: KotlinMangler.DescriptorMa
override fun visitPropertyGetterDescriptor(descriptor: PropertyGetterDescriptor, data: Nothing?) { override fun visitPropertyGetterDescriptor(descriptor: PropertyGetterDescriptor, data: Nothing?) {
descriptor.correspondingProperty.accept(this, null) descriptor.correspondingProperty.accept(this, null)
hashIdAcc = mangler.run { descriptor.signatureMangle() } hashIdAcc = mangler.run { descriptor.signatureMangle(compatibleMode = false) }
classFqnSegments.add(descriptor.name.asString()) classFqnSegments.add(descriptor.name.asString())
setExpected(descriptor.isExpect) setExpected(descriptor.isExpect)
platformSpecificGetter(descriptor) platformSpecificGetter(descriptor)
@@ -158,7 +158,7 @@ open class IdSignatureDescriptor(private val mangler: KotlinMangler.DescriptorMa
override fun visitPropertySetterDescriptor(descriptor: PropertySetterDescriptor, data: Nothing?) { override fun visitPropertySetterDescriptor(descriptor: PropertySetterDescriptor, data: Nothing?) {
descriptor.correspondingProperty.accept(this, null) descriptor.correspondingProperty.accept(this, null)
hashIdAcc = mangler.run { descriptor.signatureMangle() } hashIdAcc = mangler.run { descriptor.signatureMangle(compatibleMode = false) }
classFqnSegments.add(descriptor.name.asString()) classFqnSegments.add(descriptor.name.asString())
setExpected(descriptor.isExpect) setExpected(descriptor.isExpect)
platformSpecificSetter(descriptor) platformSpecificSetter(descriptor)
@@ -60,7 +60,7 @@ class PublicIdSignatureComputer(val mangler: KotlinMangler.IrMangler) : IdSignat
scopeCounter = 0 scopeCounter = 0
} }
private inner class PublicIdSigBuilder(private val containerSig: IdSignature? = null) : IdSignatureBuilder<IrDeclaration>(), private inner class PublicIdSigBuilder : IdSignatureBuilder<IrDeclaration>(),
IrElementVisitorVoid { IrElementVisitorVoid {
override val currentFileSignature: IdSignature.FileSignature? override val currentFileSignature: IdSignature.FileSignature?
@@ -115,7 +115,8 @@ class PublicIdSignatureComputer(val mangler: KotlinMangler.IrMangler) : IdSignat
setExpected(declaration.isExpect) setExpected(declaration.isExpect)
} }
private fun IrDeclarationWithName.hashId(): Long = mangler.run { signatureMangle() } // Note: `false` because `compatibleMode` is not applied to public signatures
private fun IrDeclarationWithName.hashId(): Long = mangler.run { signatureMangle(compatibleMode = false) }
override fun visitSimpleFunction(declaration: IrSimpleFunction) { override fun visitSimpleFunction(declaration: IrSimpleFunction) {
val property = declaration.correspondingPropertySymbol val property = declaration.correspondingPropertySymbol
@@ -243,18 +244,18 @@ class IdSignatureSerializer(
is IrAnonymousInitializer -> IdSignature.ScopeLocalDeclaration(scopeIndex++, "ANON INIT") is IrAnonymousInitializer -> IdSignature.ScopeLocalDeclaration(scopeIndex++, "ANON INIT")
is IrLocalDelegatedProperty -> IdSignature.ScopeLocalDeclaration(scopeIndex++, declaration.name.asString()) is IrLocalDelegatedProperty -> IdSignature.ScopeLocalDeclaration(scopeIndex++, declaration.name.asString())
is IrField -> { is IrField -> {
val p = declaration.correspondingPropertySymbol?.let { composeSignatureForDeclaration(it.owner, true) } val p = declaration.correspondingPropertySymbol?.let { composeSignatureForDeclaration(it.owner, compatibleMode) }
?: composeContainerIdSignature(declaration.parent, compatibleMode) ?: composeContainerIdSignature(declaration.parent, compatibleMode)
IdSignature.FileLocalSignature(p, ++localIndex) IdSignature.FileLocalSignature(p, ++localIndex)
} }
is IrSimpleFunction -> { is IrSimpleFunction -> {
val parent = declaration.parent val parent = declaration.parent
val p = declaration.correspondingPropertySymbol?.let { composeSignatureForDeclaration(it.owner, true) } val p = declaration.correspondingPropertySymbol?.let { composeSignatureForDeclaration(it.owner, compatibleMode) }
?: composeContainerIdSignature(parent, compatibleMode) ?: composeContainerIdSignature(parent, compatibleMode)
IdSignature.FileLocalSignature( IdSignature.FileLocalSignature(
p, p,
if (declaration.isOverridableFunction()) { if (declaration.isOverridableFunction()) {
mangler.run { declaration.signatureMangle() } mangler.run { declaration.signatureMangle(compatibleMode) }
} else { } else {
++localIndex ++localIndex
}, },
@@ -266,7 +267,7 @@ class IdSignatureSerializer(
IdSignature.FileLocalSignature( IdSignature.FileLocalSignature(
composeContainerIdSignature(parent, compatibleMode), composeContainerIdSignature(parent, compatibleMode),
if (declaration.isOverridableProperty()) { if (declaration.isOverridableProperty()) {
mangler.run { declaration.signatureMangle() } mangler.run { declaration.signatureMangle(compatibleMode) }
} else { } else {
++localIndex ++localIndex
}, },
@@ -23,14 +23,14 @@ abstract class AbstractJsManglerIr : IrBasedKotlinManglerImpl() {
override fun IrDeclaration.isPlatformSpecificExported() = false override fun IrDeclaration.isPlatformSpecificExported() = false
} }
private class JsIrManglerComputer(builder: StringBuilder, mode: MangleMode) : IrMangleComputer(builder, mode) { private class JsIrManglerComputer(builder: StringBuilder, mode: MangleMode, compatibleMode: Boolean) : IrMangleComputer(builder, mode, compatibleMode) {
override fun copy(newMode: MangleMode): IrMangleComputer = JsIrManglerComputer(builder, newMode) override fun copy(newMode: MangleMode): IrMangleComputer = JsIrManglerComputer(builder, newMode, compatibleMode)
} }
override fun getExportChecker(compatibleMode: Boolean): KotlinExportChecker<IrDeclaration> = JsIrExportChecker(compatibleMode) override fun getExportChecker(compatibleMode: Boolean): KotlinExportChecker<IrDeclaration> = JsIrExportChecker(compatibleMode)
override fun getMangleComputer(mode: MangleMode): KotlinMangleComputer<IrDeclaration> { override fun getMangleComputer(mode: MangleMode, compatibleMode: Boolean): KotlinMangleComputer<IrDeclaration> {
return JsIrManglerComputer(StringBuilder(256), mode) return JsIrManglerComputer(StringBuilder(256), mode, compatibleMode)
} }
} }
@@ -52,7 +52,7 @@ abstract class AbstractJsDescriptorMangler : DescriptorBasedKotlinManglerImpl()
override fun getExportChecker(compatibleMode: Boolean): KotlinExportChecker<DeclarationDescriptor> = exportChecker override fun getExportChecker(compatibleMode: Boolean): KotlinExportChecker<DeclarationDescriptor> = exportChecker
override fun getMangleComputer(mode: MangleMode): KotlinMangleComputer<DeclarationDescriptor> { override fun getMangleComputer(mode: MangleMode, compatibleMode: Boolean): KotlinMangleComputer<DeclarationDescriptor> {
return JsDescriptorManglerComputer(StringBuilder(256), mode) return JsDescriptorManglerComputer(StringBuilder(256), mode)
} }
} }
@@ -37,9 +37,9 @@ object JvmIrMangler : IrBasedKotlinManglerImpl() {
override fun IrDeclaration.isPlatformSpecificExported() = false override fun IrDeclaration.isPlatformSpecificExported() = false
} }
private class JvmIrManglerComputer(builder: StringBuilder, mode: MangleMode) : IrMangleComputer(builder, mode) { private class JvmIrManglerComputer(builder: StringBuilder, mode: MangleMode, compatibleMode: Boolean) : IrMangleComputer(builder, mode, compatibleMode) {
override fun copy(newMode: MangleMode): IrMangleComputer = override fun copy(newMode: MangleMode): IrMangleComputer =
JvmIrManglerComputer(builder, newMode) JvmIrManglerComputer(builder, newMode, compatibleMode)
override fun addReturnTypeSpecialCase(irFunction: IrFunction): Boolean = override fun addReturnTypeSpecialCase(irFunction: IrFunction): Boolean =
irFunction.isFromJava() irFunction.isFromJava()
@@ -53,8 +53,8 @@ object JvmIrMangler : IrBasedKotlinManglerImpl() {
override fun getExportChecker(compatibleMode: Boolean): KotlinExportChecker<IrDeclaration> = JvmIrExportChecker(compatibleMode) override fun getExportChecker(compatibleMode: Boolean): KotlinExportChecker<IrDeclaration> = JvmIrExportChecker(compatibleMode)
override fun getMangleComputer(mode: MangleMode): KotlinMangleComputer<IrDeclaration> = override fun getMangleComputer(mode: MangleMode, compatibleMode: Boolean): KotlinMangleComputer<IrDeclaration> =
JvmIrManglerComputer(StringBuilder(256), mode) JvmIrManglerComputer(StringBuilder(256), mode, compatibleMode)
} }
class JvmDescriptorMangler(private val mainDetector: MainFunctionDetector?) : DescriptorBasedKotlinManglerImpl() { class JvmDescriptorMangler(private val mainDetector: MainFunctionDetector?) : DescriptorBasedKotlinManglerImpl() {
@@ -101,6 +101,6 @@ class JvmDescriptorMangler(private val mainDetector: MainFunctionDetector?) : De
override fun getExportChecker(compatibleMode: Boolean): KotlinExportChecker<DeclarationDescriptor> = ExportChecker override fun getExportChecker(compatibleMode: Boolean): KotlinExportChecker<DeclarationDescriptor> = ExportChecker
override fun getMangleComputer(mode: MangleMode): KotlinMangleComputer<DeclarationDescriptor> = override fun getMangleComputer(mode: MangleMode, compatibleMode: Boolean): KotlinMangleComputer<DeclarationDescriptor> =
JvmDescriptorManglerComputer(StringBuilder(256), mainDetector, mode) JvmDescriptorManglerComputer(StringBuilder(256), mainDetector, mode)
} }
@@ -36,7 +36,7 @@ object KonanBinaryInterface {
private val exportChecker = mangler.getExportChecker(compatibleMode = true) private val exportChecker = mangler.getExportChecker(compatibleMode = true)
val IrFunction.functionName: String get() = mangler.run { signatureString() } val IrFunction.functionName: String get() = mangler.run { signatureString(compatibleMode = true) }
val IrFunction.symbolName: String get() = funSymbolNameImpl() val IrFunction.symbolName: String get() = funSymbolNameImpl()
val IrField.symbolName: String get() = val IrField.symbolName: String get() =
@@ -65,7 +65,7 @@ object KonanBinaryInterface {
return name // no wrapping currently required return name // no wrapping currently required
} }
return withPrefix(MangleConstant.FUN_PREFIX, mangler.run { mangleString() }) return withPrefix(MangleConstant.FUN_PREFIX, mangler.run { mangleString(compatibleMode = true) })
} }
private fun IrField.fieldSymbolNameImpl(): String { private fun IrField.fieldSymbolNameImpl(): String {
@@ -13,12 +13,11 @@ import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.types.getClass import org.jetbrains.kotlin.ir.types.getClass
import org.jetbrains.kotlin.ir.util.hasAnnotation import org.jetbrains.kotlin.ir.util.hasAnnotation
import org.jetbrains.kotlin.types.KotlinType
abstract class AbstractKonanIrMangler(private val withReturnType: Boolean) : IrBasedKotlinManglerImpl() { abstract class AbstractKonanIrMangler(private val withReturnType: Boolean) : IrBasedKotlinManglerImpl() {
override fun getExportChecker(compatibleMode: Boolean): IrExportCheckerVisitor = KonanIrExportChecker(compatibleMode) override fun getExportChecker(compatibleMode: Boolean): IrExportCheckerVisitor = KonanIrExportChecker(compatibleMode)
override fun getMangleComputer(mode: MangleMode): IrMangleComputer = KonanIrManglerComputer(StringBuilder(256), mode, withReturnType) override fun getMangleComputer(mode: MangleMode, compatibleMode: Boolean): IrMangleComputer = KonanIrManglerComputer(StringBuilder(256), mode, compatibleMode, withReturnType)
override fun IrDeclaration.isPlatformSpecificExport(): Boolean { override fun IrDeclaration.isPlatformSpecificExport(): Boolean {
if (this is IrSimpleFunction) if (isFakeOverride) return false if (this is IrSimpleFunction) if (isFakeOverride) return false
@@ -51,8 +50,8 @@ abstract class AbstractKonanIrMangler(private val withReturnType: Boolean) : IrB
override fun IrDeclaration.isPlatformSpecificExported(): Boolean = isPlatformSpecificExport() override fun IrDeclaration.isPlatformSpecificExported(): Boolean = isPlatformSpecificExport()
} }
private class KonanIrManglerComputer(builder: StringBuilder, mode: MangleMode, private val withReturnType: Boolean) : IrMangleComputer(builder, mode) { private class KonanIrManglerComputer(builder: StringBuilder, mode: MangleMode, compatibleMode: Boolean, private val withReturnType: Boolean) : IrMangleComputer(builder, mode, compatibleMode) {
override fun copy(newMode: MangleMode): IrMangleComputer = KonanIrManglerComputer(builder, newMode, withReturnType) override fun copy(newMode: MangleMode): IrMangleComputer = KonanIrManglerComputer(builder, newMode, compatibleMode, withReturnType)
override fun addReturnType(): Boolean = withReturnType override fun addReturnType(): Boolean = withReturnType
@@ -93,7 +92,7 @@ object KonanManglerIr : AbstractKonanIrMangler(false)
abstract class AbstractKonanDescriptorMangler : DescriptorBasedKotlinManglerImpl() { abstract class AbstractKonanDescriptorMangler : DescriptorBasedKotlinManglerImpl() {
override fun getExportChecker(compatibleMode: Boolean): KotlinExportChecker<DeclarationDescriptor> = KonanDescriptorExportChecker() override fun getExportChecker(compatibleMode: Boolean): KotlinExportChecker<DeclarationDescriptor> = KonanDescriptorExportChecker()
override fun getMangleComputer(mode: MangleMode): DescriptorMangleComputer = KonanDescriptorMangleComputer(StringBuilder(256), mode) override fun getMangleComputer(mode: MangleMode, compatibleMode: Boolean): DescriptorMangleComputer = KonanDescriptorMangleComputer(StringBuilder(256), mode)
private inner class KonanDescriptorExportChecker : DescriptorExportCheckerVisitor() { private inner class KonanDescriptorExportChecker : DescriptorExportCheckerVisitor() {
override fun DeclarationDescriptor.isPlatformSpecificExported(): Boolean = isPlatformSpecificExport() override fun DeclarationDescriptor.isPlatformSpecificExported(): Boolean = isPlatformSpecificExport()