[FIR] Fix handling of type parameters in FIR mangling

#KT-57429 Fixed
This commit is contained in:
Kirill Rakhman
2023-06-05 17:31:27 +02:00
committed by Space Team
parent 938dd65881
commit 67fc46a190
48 changed files with 199 additions and 141 deletions
@@ -33,28 +33,6 @@ class FirJvmMangleComputer(
override fun copy(newMode: MangleMode): FirJvmMangleComputer =
FirJvmMangleComputer(builder, newMode)
// FIXME this implementation causes the mangler to deliver different result than IR mangler. Consider using base method instead
override fun getEffectiveParent(typeParameter: ConeTypeParameterLookupTag): FirMemberDeclaration = typeParameter.symbol.fir.run {
fun FirTypeParameter.sameAs(other: FirTypeParameter) =
this === other ||
(name == other.name && bounds.size == other.bounds.size &&
bounds.zip(other.bounds).all { it.first.coneType == it.second.coneType })
for (parent in typeParameterContainers) {
if (parent.typeParameters.any { this.sameAs(it.symbol.fir) }) {
return parent
}
if (parent is FirCallableDeclaration) {
val overriddenFir = parent.originalForSubstitutionOverride
if (overriddenFir is FirTypeParametersOwner && overriddenFir.typeParameters.any { this.sameAs(it) }) {
return parent
}
}
}
throw IllegalStateException("Should not be here!")
}
private inner class JvmVisitor : Visitor() {
override fun visitField(field: FirField) {
if (field is FirJavaField) {
@@ -12,7 +12,6 @@ import org.jetbrains.kotlin.backend.common.serialization.mangle.collectForMangle
import org.jetbrains.kotlin.fir.*
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.declarations.synthetic.FirSyntheticPropertyAccessor
import org.jetbrains.kotlin.fir.declarations.utils.isExpect
import org.jetbrains.kotlin.fir.declarations.utils.isStatic
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
@@ -108,8 +107,17 @@ open class FirMangleComputer(
override fun isUnit(type: ConeKotlinType) = type.isUnit
@OptIn(SymbolInternals::class)
override fun getEffectiveParent(typeParameter: ConeTypeParameterLookupTag): FirMemberDeclaration = typeParameter.symbol.fir.run {
this.containingDeclarationSymbol.fir as FirMemberDeclaration
override fun getEffectiveParent(typeParameter: ConeTypeParameterLookupTag): FirMemberDeclaration =
typeParameter.symbol.containingDeclarationSymbol.fir as FirMemberDeclaration
override fun getContainerIndex(parent: FirMemberDeclaration): Int {
// If a type parameter is declared in a java method, typeParameterContainers will contain the enhanced declaration,
// but parent will be the non-enhanced version.
// To work around this, we additionally compare declarations using their callable IDs.
val callableId = (parent as? FirCallableDeclaration)?.symbol?.callableId
return typeParameterContainers.indexOfFirst {
it == parent || it is FirCallableDeclaration && it.symbol.callableId == callableId
}
}
override fun renderDeclaration(declaration: FirDeclaration) = declaration.render()
@@ -279,4 +287,4 @@ open class FirMangleComputer(
}
}
}
}
}