[IR] Fix compatibility mode
- pass corresponding flag to mangler - properly handle local declarations in field initializers - fix KT-48912
This commit is contained in:
committed by
TeamCityServer
parent
8f8c59e748
commit
ba759fb61b
+3
-3
@@ -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 classDescriptor = clazz.module.module.findClassAcrossModuleDependencies(classId) ?: return
|
||||
// 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 }
|
||||
|
||||
val descriptorSignatures = descriptorFakeOverrides
|
||||
.map { with(descriptorMangler) { it.signatureString() } }
|
||||
.map { with(descriptorMangler) { it.signatureString(compatibleMode) } }
|
||||
.sorted()
|
||||
|
||||
val irFakeOverrides = clazz.declarations
|
||||
@@ -56,7 +56,7 @@ class FakeOverrideChecker(
|
||||
}
|
||||
|
||||
val irSignatures = irFakeOverrides
|
||||
.map { with(irMangler) { it.signatureString() } }
|
||||
.map { with(irMangler) { it.signatureString(compatibleMode) } }
|
||||
.sorted()
|
||||
|
||||
// We can't have equality here because dependency libraries could have
|
||||
|
||||
+1
-1
@@ -165,7 +165,7 @@ class DescriptorByIdSignatureFinder(
|
||||
// We don't compute id for typealiases and classes.
|
||||
candidate is ClassDescriptor || candidate is TypeAliasDescriptor
|
||||
} else {
|
||||
val candidateHash = with(mangler) { candidate.signatureMangle() }
|
||||
val candidateHash = with(mangler) { candidate.signatureMangle(compatibleMode = false) }
|
||||
candidateHash == id
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -12,5 +12,5 @@ abstract class AbstractKotlinMangler<D : Any> : KotlinMangler<D> {
|
||||
override val String.hashMangle get() = cityHash64()
|
||||
|
||||
abstract fun getExportChecker(compatibleMode: Boolean): KotlinExportChecker<D>
|
||||
abstract fun getMangleComputer(mode: MangleMode): KotlinMangleComputer<D>
|
||||
abstract fun getMangleComputer(mode: MangleMode, compatibleMode: Boolean): KotlinMangleComputer<D>
|
||||
}
|
||||
+3
-3
@@ -52,13 +52,13 @@ class ManglerChecker(vararg _manglers: KotlinMangler<IrDeclaration>) : IrElement
|
||||
private fun KotlinMangler<IrDeclaration>.isExportCheck(declaration: IrDeclaration) =
|
||||
!declaration.shouldBeSkipped() && declaration.isExported(false)
|
||||
private fun KotlinMangler<IrDeclaration>.stringMangle(declaration: IrDeclaration) =
|
||||
declaration.mangleString()
|
||||
declaration.mangleString(compatibleMode = false)
|
||||
|
||||
private fun KotlinMangler<IrDeclaration>.signatureMangle(declaration: IrDeclaration) =
|
||||
declaration.signatureString()
|
||||
declaration.signatureString(compatibleMode = false)
|
||||
|
||||
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 {
|
||||
var prev: T? = null
|
||||
|
||||
+14
-14
@@ -16,18 +16,18 @@ import org.jetbrains.kotlin.ir.util.KotlinMangler
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
abstract class DescriptorBasedKotlinManglerImpl : AbstractKotlinMangler<DeclarationDescriptor>(), KotlinMangler.DescriptorMangler {
|
||||
private fun withMode(mode: MangleMode, descriptor: DeclarationDescriptor): String =
|
||||
getMangleComputer(mode).computeMangle(descriptor)
|
||||
private fun withMode(mode: MangleMode, compatibleMode: Boolean, descriptor: DeclarationDescriptor): String =
|
||||
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)
|
||||
}
|
||||
@@ -41,19 +41,19 @@ class Ir2DescriptorManglerAdapter(private val delegate: DescriptorBasedKotlinMan
|
||||
return delegate.run { descriptor.isExported(compatibleMode) }
|
||||
}
|
||||
|
||||
override fun IrDeclaration.mangleString(): String {
|
||||
override fun IrDeclaration.mangleString(compatibleMode: Boolean): String {
|
||||
return when (this) {
|
||||
is IrEnumEntry -> delegate.run { descriptor.mangleEnumEntryString() }
|
||||
is IrField -> delegate.run { descriptor.mangleFieldString() }
|
||||
else -> delegate.run { descriptor.mangleString() }
|
||||
is IrEnumEntry -> delegate.run { descriptor.mangleEnumEntryString(compatibleMode) }
|
||||
is IrField -> delegate.run { descriptor.mangleFieldString(compatibleMode) }
|
||||
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")
|
||||
|
||||
override fun getExportChecker(compatibleMode: Boolean): KotlinExportChecker<IrDeclaration> {
|
||||
|
||||
+3
-3
@@ -13,11 +13,11 @@ import org.jetbrains.kotlin.ir.util.KotlinMangler
|
||||
|
||||
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 =
|
||||
getExportChecker(compatibleMode).check(this, SpecialDeclarationType.REGULAR)
|
||||
|
||||
+5
-4
@@ -20,7 +20,7 @@ import org.jetbrains.kotlin.ir.visitors.acceptVoid
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
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> {
|
||||
|
||||
private val typeParameterContainer = ArrayList<IrDeclaration>(4)
|
||||
@@ -260,10 +260,11 @@ abstract class IrMangleComputer(protected val builder: StringBuilder, private va
|
||||
|
||||
override fun visitField(declaration: IrField) {
|
||||
val prop = declaration.correspondingPropertySymbol
|
||||
if (prop != null) {
|
||||
visitProperty(prop.owner)
|
||||
} else {
|
||||
if (compatibleMode || prop == null) { // act as used to be (KT-48912)
|
||||
// test compiler/testData/codegen/box/ir/serializationRegressions/anonFakeOverride.kt
|
||||
declaration.mangleSimpleDeclaration(declaration.name.asString())
|
||||
} else {
|
||||
visitProperty(prop.owner)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-5
@@ -72,7 +72,7 @@ open class IdSignatureDescriptor(private val mangler: KotlinMangler.DescriptorMa
|
||||
|
||||
override fun visitFunctionDescriptor(descriptor: FunctionDescriptor, data: Nothing?) {
|
||||
collectParents(descriptor)
|
||||
hashId = mangler.run { descriptor.signatureMangle() }
|
||||
hashId = mangler.run { descriptor.signatureMangle(compatibleMode = false) }
|
||||
isTopLevelPrivate = isTopLevelPrivate or descriptor.isTopLevelPrivate
|
||||
setDescription(descriptor)
|
||||
setExpected(descriptor.isExpect)
|
||||
@@ -116,7 +116,7 @@ open class IdSignatureDescriptor(private val mangler: KotlinMangler.DescriptorMa
|
||||
|
||||
override fun visitConstructorDescriptor(constructorDescriptor: ConstructorDescriptor, data: Nothing?) {
|
||||
collectParents(constructorDescriptor)
|
||||
hashId = mangler.run { constructorDescriptor.signatureMangle() }
|
||||
hashId = mangler.run { constructorDescriptor.signatureMangle(compatibleMode = false) }
|
||||
platformSpecificConstructor(constructorDescriptor)
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ open class IdSignatureDescriptor(private val mangler: KotlinMangler.DescriptorMa
|
||||
isTopLevelPrivate = isTopLevelPrivate or actualDeclaration.isTopLevelPrivate
|
||||
|
||||
|
||||
hashId = mangler.run { actualDeclaration.signatureMangle() }
|
||||
hashId = mangler.run { actualDeclaration.signatureMangle(compatibleMode = false) }
|
||||
setExpected(actualDeclaration.isExpect)
|
||||
platformSpecificProperty(actualDeclaration)
|
||||
if (type == SpecialDeclarationType.BACKING_FIELD) {
|
||||
@@ -150,7 +150,7 @@ open class IdSignatureDescriptor(private val mangler: KotlinMangler.DescriptorMa
|
||||
|
||||
override fun visitPropertyGetterDescriptor(descriptor: PropertyGetterDescriptor, data: Nothing?) {
|
||||
descriptor.correspondingProperty.accept(this, null)
|
||||
hashIdAcc = mangler.run { descriptor.signatureMangle() }
|
||||
hashIdAcc = mangler.run { descriptor.signatureMangle(compatibleMode = false) }
|
||||
classFqnSegments.add(descriptor.name.asString())
|
||||
setExpected(descriptor.isExpect)
|
||||
platformSpecificGetter(descriptor)
|
||||
@@ -158,7 +158,7 @@ open class IdSignatureDescriptor(private val mangler: KotlinMangler.DescriptorMa
|
||||
|
||||
override fun visitPropertySetterDescriptor(descriptor: PropertySetterDescriptor, data: Nothing?) {
|
||||
descriptor.correspondingProperty.accept(this, null)
|
||||
hashIdAcc = mangler.run { descriptor.signatureMangle() }
|
||||
hashIdAcc = mangler.run { descriptor.signatureMangle(compatibleMode = false) }
|
||||
classFqnSegments.add(descriptor.name.asString())
|
||||
setExpected(descriptor.isExpect)
|
||||
platformSpecificSetter(descriptor)
|
||||
|
||||
+7
-6
@@ -60,7 +60,7 @@ class PublicIdSignatureComputer(val mangler: KotlinMangler.IrMangler) : IdSignat
|
||||
scopeCounter = 0
|
||||
}
|
||||
|
||||
private inner class PublicIdSigBuilder(private val containerSig: IdSignature? = null) : IdSignatureBuilder<IrDeclaration>(),
|
||||
private inner class PublicIdSigBuilder : IdSignatureBuilder<IrDeclaration>(),
|
||||
IrElementVisitorVoid {
|
||||
|
||||
override val currentFileSignature: IdSignature.FileSignature?
|
||||
@@ -115,7 +115,8 @@ class PublicIdSignatureComputer(val mangler: KotlinMangler.IrMangler) : IdSignat
|
||||
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) {
|
||||
val property = declaration.correspondingPropertySymbol
|
||||
@@ -243,18 +244,18 @@ class IdSignatureSerializer(
|
||||
is IrAnonymousInitializer -> IdSignature.ScopeLocalDeclaration(scopeIndex++, "ANON INIT")
|
||||
is IrLocalDelegatedProperty -> IdSignature.ScopeLocalDeclaration(scopeIndex++, declaration.name.asString())
|
||||
is IrField -> {
|
||||
val p = declaration.correspondingPropertySymbol?.let { composeSignatureForDeclaration(it.owner, true) }
|
||||
val p = declaration.correspondingPropertySymbol?.let { composeSignatureForDeclaration(it.owner, compatibleMode) }
|
||||
?: composeContainerIdSignature(declaration.parent, compatibleMode)
|
||||
IdSignature.FileLocalSignature(p, ++localIndex)
|
||||
}
|
||||
is IrSimpleFunction -> {
|
||||
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)
|
||||
IdSignature.FileLocalSignature(
|
||||
p,
|
||||
if (declaration.isOverridableFunction()) {
|
||||
mangler.run { declaration.signatureMangle() }
|
||||
mangler.run { declaration.signatureMangle(compatibleMode) }
|
||||
} else {
|
||||
++localIndex
|
||||
},
|
||||
@@ -266,7 +267,7 @@ class IdSignatureSerializer(
|
||||
IdSignature.FileLocalSignature(
|
||||
composeContainerIdSignature(parent, compatibleMode),
|
||||
if (declaration.isOverridableProperty()) {
|
||||
mangler.run { declaration.signatureMangle() }
|
||||
mangler.run { declaration.signatureMangle(compatibleMode) }
|
||||
} else {
|
||||
++localIndex
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user