IR: remove usages of SymbolRenamer
Its only implementation was DEFAULT so now it's inlined.
This commit is contained in:
committed by
Space Team
parent
be4e81fbce
commit
d659b76de5
+5
-2
@@ -8,7 +8,10 @@ package org.jetbrains.kotlin.backend.common.actualizer
|
|||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.symbols.*
|
import org.jetbrains.kotlin.ir.symbols.*
|
||||||
import org.jetbrains.kotlin.ir.types.IrSimpleType
|
import org.jetbrains.kotlin.ir.types.IrSimpleType
|
||||||
import org.jetbrains.kotlin.ir.util.*
|
import org.jetbrains.kotlin.ir.util.DeepCopyIrTreeWithSymbols
|
||||||
|
import org.jetbrains.kotlin.ir.util.SymbolRemapper
|
||||||
|
import org.jetbrains.kotlin.ir.util.TypeRemapper
|
||||||
|
import org.jetbrains.kotlin.ir.util.render
|
||||||
import org.jetbrains.kotlin.utils.memoryOptimizedMap
|
import org.jetbrains.kotlin.utils.memoryOptimizedMap
|
||||||
|
|
||||||
internal class ActualizerSymbolRemapper(private val expectActualMap: Map<IrSymbol, IrSymbol>) : SymbolRemapper {
|
internal class ActualizerSymbolRemapper(private val expectActualMap: Map<IrSymbol, IrSymbol>) : SymbolRemapper {
|
||||||
@@ -74,7 +77,7 @@ internal class ActualizerSymbolRemapper(private val expectActualMap: Map<IrSymbo
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal open class ActualizerVisitor(private val symbolRemapper: SymbolRemapper, typeRemapper: TypeRemapper) :
|
internal open class ActualizerVisitor(private val symbolRemapper: SymbolRemapper, typeRemapper: TypeRemapper) :
|
||||||
DeepCopyIrTreeWithSymbols(symbolRemapper, typeRemapper, SymbolRenamer.DEFAULT) {
|
DeepCopyIrTreeWithSymbols(symbolRemapper, typeRemapper) {
|
||||||
|
|
||||||
// We shouldn't touch attributes, because Fir2Ir wouldn't set them to anything meaningful anyway.
|
// We shouldn't touch attributes, because Fir2Ir wouldn't set them to anything meaningful anyway.
|
||||||
// So it would be better to have them as is, i.e. referring to `this`, not some random node removed from the tree
|
// So it would be better to have them as is, i.e. referring to `this`, not some random node removed from the tree
|
||||||
|
|||||||
@@ -12,57 +12,43 @@ import org.jetbrains.kotlin.ir.declarations.*
|
|||||||
import org.jetbrains.kotlin.ir.declarations.impl.*
|
import org.jetbrains.kotlin.ir.declarations.impl.*
|
||||||
import org.jetbrains.kotlin.ir.expressions.*
|
import org.jetbrains.kotlin.ir.expressions.*
|
||||||
import org.jetbrains.kotlin.ir.expressions.impl.*
|
import org.jetbrains.kotlin.ir.expressions.impl.*
|
||||||
import org.jetbrains.kotlin.ir.symbols.*
|
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
||||||
|
import org.jetbrains.kotlin.ir.symbols.IrReturnTargetSymbol
|
||||||
|
import org.jetbrains.kotlin.ir.symbols.IrReturnableBlockSymbol
|
||||||
|
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
||||||
import org.jetbrains.kotlin.ir.symbols.impl.IrAnonymousInitializerSymbolImpl
|
import org.jetbrains.kotlin.ir.symbols.impl.IrAnonymousInitializerSymbolImpl
|
||||||
import org.jetbrains.kotlin.ir.types.IrSimpleType
|
import org.jetbrains.kotlin.ir.types.IrSimpleType
|
||||||
import org.jetbrains.kotlin.ir.types.IrType
|
import org.jetbrains.kotlin.ir.types.IrType
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
||||||
import org.jetbrains.kotlin.ir.visitors.acceptVoid
|
import org.jetbrains.kotlin.ir.visitors.acceptVoid
|
||||||
import org.jetbrains.kotlin.name.FqName
|
|
||||||
import org.jetbrains.kotlin.name.Name
|
|
||||||
import org.jetbrains.kotlin.utils.memoryOptimizedMap
|
import org.jetbrains.kotlin.utils.memoryOptimizedMap
|
||||||
|
|
||||||
inline fun <reified T : IrElement> T.deepCopyWithSymbols(
|
inline fun <reified T : IrElement> T.deepCopyWithSymbols(
|
||||||
initialParent: IrDeclarationParent? = null,
|
initialParent: IrDeclarationParent? = null,
|
||||||
createCopier: (SymbolRemapper, TypeRemapper) -> DeepCopyIrTreeWithSymbols = ::DeepCopyIrTreeWithSymbols
|
createCopier: (SymbolRemapper, TypeRemapper) -> DeepCopyIrTreeWithSymbols =
|
||||||
|
{ symbolRemapper, typeRemapper -> DeepCopyIrTreeWithSymbols(symbolRemapper, typeRemapper) },
|
||||||
): T = deepCopyWithSymbols(initialParent, DeepCopySymbolRemapper(), createCopier)
|
): T = deepCopyWithSymbols(initialParent, DeepCopySymbolRemapper(), createCopier)
|
||||||
|
|
||||||
inline fun <reified T : IrElement> T.deepCopyWithSymbols(
|
inline fun <reified T : IrElement> T.deepCopyWithSymbols(
|
||||||
initialParent: IrDeclarationParent?,
|
initialParent: IrDeclarationParent?,
|
||||||
symbolRemapper: DeepCopySymbolRemapper,
|
symbolRemapper: DeepCopySymbolRemapper,
|
||||||
createCopier: (SymbolRemapper, TypeRemapper) -> DeepCopyIrTreeWithSymbols = ::DeepCopyIrTreeWithSymbols
|
createCopier: (SymbolRemapper, TypeRemapper) -> DeepCopyIrTreeWithSymbols =
|
||||||
|
{ symbolRemapper, typeRemapper -> DeepCopyIrTreeWithSymbols(symbolRemapper, typeRemapper) },
|
||||||
): T {
|
): T {
|
||||||
acceptVoid(symbolRemapper)
|
acceptVoid(symbolRemapper)
|
||||||
val typeRemapper = DeepCopyTypeRemapper(symbolRemapper)
|
val typeRemapper = DeepCopyTypeRemapper(symbolRemapper)
|
||||||
return transform(createCopier(symbolRemapper, typeRemapper), null).patchDeclarationParents(initialParent) as T
|
return transform(createCopier(symbolRemapper, typeRemapper), null).patchDeclarationParents(initialParent) as T
|
||||||
}
|
}
|
||||||
|
|
||||||
interface SymbolRenamer {
|
|
||||||
fun getClassName(symbol: IrClassSymbol): Name = symbol.owner.name
|
|
||||||
fun getFunctionName(symbol: IrSimpleFunctionSymbol): Name = symbol.owner.name
|
|
||||||
fun getFieldName(symbol: IrFieldSymbol): Name = symbol.owner.name
|
|
||||||
fun getFileName(symbol: IrFileSymbol): FqName = symbol.owner.packageFqName
|
|
||||||
fun getExternalPackageFragmentName(symbol: IrExternalPackageFragmentSymbol): FqName = symbol.owner.packageFqName
|
|
||||||
fun getEnumEntryName(symbol: IrEnumEntrySymbol): Name = symbol.owner.name
|
|
||||||
fun getVariableName(symbol: IrVariableSymbol): Name = symbol.owner.name
|
|
||||||
fun getTypeParameterName(symbol: IrTypeParameterSymbol): Name = symbol.owner.name
|
|
||||||
fun getValueParameterName(symbol: IrValueParameterSymbol): Name = symbol.owner.name
|
|
||||||
fun getTypeAliasName(symbol: IrTypeAliasSymbol): Name = symbol.owner.name
|
|
||||||
|
|
||||||
object DEFAULT : SymbolRenamer
|
|
||||||
}
|
|
||||||
|
|
||||||
@OptIn(ObsoleteDescriptorBasedAPI::class)
|
@OptIn(ObsoleteDescriptorBasedAPI::class)
|
||||||
open class DeepCopyIrTreeWithSymbols(
|
open class DeepCopyIrTreeWithSymbols(
|
||||||
private val symbolRemapper: SymbolRemapper,
|
private val symbolRemapper: SymbolRemapper,
|
||||||
private val typeRemapper: TypeRemapper,
|
private val typeRemapper: TypeRemapper,
|
||||||
private val symbolRenamer: SymbolRenamer
|
// This parameter is not used meaningfully, but is left for compatibility with compose.
|
||||||
|
@Suppress("UNUSED_PARAMETER") symbolRenamer: SymbolRenamer? = null,
|
||||||
) : IrElementTransformerVoid() {
|
) : IrElementTransformerVoid() {
|
||||||
|
|
||||||
private var transformedModule: IrModuleFragment? = null
|
private var transformedModule: IrModuleFragment? = null
|
||||||
|
|
||||||
constructor(symbolRemapper: SymbolRemapper, typeRemapper: TypeRemapper) : this(symbolRemapper, typeRemapper, SymbolRenamer.DEFAULT)
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
// TODO refactor
|
// TODO refactor
|
||||||
(typeRemapper as? DeepCopyTypeRemapper)?.let {
|
(typeRemapper as? DeepCopyTypeRemapper)?.let {
|
||||||
@@ -107,7 +93,7 @@ open class DeepCopyIrTreeWithSymbols(
|
|||||||
override fun visitExternalPackageFragment(declaration: IrExternalPackageFragment): IrExternalPackageFragment =
|
override fun visitExternalPackageFragment(declaration: IrExternalPackageFragment): IrExternalPackageFragment =
|
||||||
IrExternalPackageFragmentImpl(
|
IrExternalPackageFragmentImpl(
|
||||||
symbolRemapper.getDeclaredExternalPackageFragment(declaration.symbol),
|
symbolRemapper.getDeclaredExternalPackageFragment(declaration.symbol),
|
||||||
symbolRenamer.getExternalPackageFragmentName(declaration.symbol)
|
declaration.packageFqName
|
||||||
).apply {
|
).apply {
|
||||||
declaration.transformDeclarationsTo(this)
|
declaration.transformDeclarationsTo(this)
|
||||||
}
|
}
|
||||||
@@ -116,7 +102,7 @@ open class DeepCopyIrTreeWithSymbols(
|
|||||||
IrFileImpl(
|
IrFileImpl(
|
||||||
declaration.fileEntry,
|
declaration.fileEntry,
|
||||||
symbolRemapper.getDeclaredFile(declaration.symbol),
|
symbolRemapper.getDeclaredFile(declaration.symbol),
|
||||||
symbolRenamer.getFileName(declaration.symbol),
|
declaration.packageFqName,
|
||||||
transformedModule ?: declaration.module
|
transformedModule ?: declaration.module
|
||||||
).apply {
|
).apply {
|
||||||
transformAnnotations(declaration)
|
transformAnnotations(declaration)
|
||||||
@@ -150,7 +136,7 @@ open class DeepCopyIrTreeWithSymbols(
|
|||||||
startOffset = declaration.startOffset,
|
startOffset = declaration.startOffset,
|
||||||
endOffset = declaration.endOffset,
|
endOffset = declaration.endOffset,
|
||||||
origin = mapDeclarationOrigin(declaration.origin),
|
origin = mapDeclarationOrigin(declaration.origin),
|
||||||
name = symbolRenamer.getClassName(declaration.symbol),
|
name = declaration.name,
|
||||||
visibility = declaration.visibility,
|
visibility = declaration.visibility,
|
||||||
symbol = symbolRemapper.getDeclaredClass(declaration.symbol),
|
symbol = symbolRemapper.getDeclaredClass(declaration.symbol),
|
||||||
kind = declaration.kind,
|
kind = declaration.kind,
|
||||||
@@ -183,7 +169,7 @@ open class DeepCopyIrTreeWithSymbols(
|
|||||||
startOffset = declaration.startOffset,
|
startOffset = declaration.startOffset,
|
||||||
endOffset = declaration.endOffset,
|
endOffset = declaration.endOffset,
|
||||||
origin = mapDeclarationOrigin(declaration.origin),
|
origin = mapDeclarationOrigin(declaration.origin),
|
||||||
name = symbolRenamer.getFunctionName(declaration.symbol),
|
name = declaration.name,
|
||||||
visibility = declaration.visibility,
|
visibility = declaration.visibility,
|
||||||
isInline = declaration.isInline,
|
isInline = declaration.isInline,
|
||||||
isExpect = declaration.isExpect,
|
isExpect = declaration.isExpect,
|
||||||
@@ -279,7 +265,7 @@ open class DeepCopyIrTreeWithSymbols(
|
|||||||
startOffset = declaration.startOffset,
|
startOffset = declaration.startOffset,
|
||||||
endOffset = declaration.endOffset,
|
endOffset = declaration.endOffset,
|
||||||
origin = mapDeclarationOrigin(declaration.origin),
|
origin = mapDeclarationOrigin(declaration.origin),
|
||||||
name = symbolRenamer.getFieldName(declaration.symbol),
|
name = declaration.name,
|
||||||
visibility = declaration.visibility,
|
visibility = declaration.visibility,
|
||||||
symbol = symbolRemapper.getDeclaredField(declaration.symbol),
|
symbol = symbolRemapper.getDeclaredField(declaration.symbol),
|
||||||
type = declaration.type.remapType(),
|
type = declaration.type.remapType(),
|
||||||
@@ -312,7 +298,7 @@ open class DeepCopyIrTreeWithSymbols(
|
|||||||
startOffset = declaration.startOffset,
|
startOffset = declaration.startOffset,
|
||||||
endOffset = declaration.endOffset,
|
endOffset = declaration.endOffset,
|
||||||
origin = mapDeclarationOrigin(declaration.origin),
|
origin = mapDeclarationOrigin(declaration.origin),
|
||||||
name = symbolRenamer.getEnumEntryName(declaration.symbol),
|
name = declaration.name,
|
||||||
symbol = symbolRemapper.getDeclaredEnumEntry(declaration.symbol),
|
symbol = symbolRemapper.getDeclaredEnumEntry(declaration.symbol),
|
||||||
).apply {
|
).apply {
|
||||||
transformAnnotations(declaration)
|
transformAnnotations(declaration)
|
||||||
@@ -335,7 +321,7 @@ open class DeepCopyIrTreeWithSymbols(
|
|||||||
declaration.startOffset, declaration.endOffset,
|
declaration.startOffset, declaration.endOffset,
|
||||||
mapDeclarationOrigin(declaration.origin),
|
mapDeclarationOrigin(declaration.origin),
|
||||||
symbolRemapper.getDeclaredVariable(declaration.symbol),
|
symbolRemapper.getDeclaredVariable(declaration.symbol),
|
||||||
symbolRenamer.getVariableName(declaration.symbol),
|
declaration.name,
|
||||||
declaration.type.remapType(),
|
declaration.type.remapType(),
|
||||||
declaration.isVar,
|
declaration.isVar,
|
||||||
declaration.isConst,
|
declaration.isConst,
|
||||||
@@ -356,7 +342,7 @@ open class DeepCopyIrTreeWithSymbols(
|
|||||||
startOffset = declaration.startOffset,
|
startOffset = declaration.startOffset,
|
||||||
endOffset = declaration.endOffset,
|
endOffset = declaration.endOffset,
|
||||||
origin = mapDeclarationOrigin(declaration.origin),
|
origin = mapDeclarationOrigin(declaration.origin),
|
||||||
name = symbolRenamer.getTypeParameterName(declaration.symbol),
|
name = declaration.name,
|
||||||
symbol = symbolRemapper.getDeclaredTypeParameter(declaration.symbol),
|
symbol = symbolRemapper.getDeclaredTypeParameter(declaration.symbol),
|
||||||
variance = declaration.variance,
|
variance = declaration.variance,
|
||||||
index = declaration.index,
|
index = declaration.index,
|
||||||
@@ -384,7 +370,7 @@ open class DeepCopyIrTreeWithSymbols(
|
|||||||
startOffset = declaration.startOffset,
|
startOffset = declaration.startOffset,
|
||||||
endOffset = declaration.endOffset,
|
endOffset = declaration.endOffset,
|
||||||
origin = mapDeclarationOrigin(declaration.origin),
|
origin = mapDeclarationOrigin(declaration.origin),
|
||||||
name = symbolRenamer.getValueParameterName(declaration.symbol),
|
name = declaration.name,
|
||||||
type = declaration.type.remapType(),
|
type = declaration.type.remapType(),
|
||||||
isAssignable = declaration.isAssignable,
|
isAssignable = declaration.isAssignable,
|
||||||
symbol = symbolRemapper.getDeclaredValueParameter(declaration.symbol),
|
symbol = symbolRemapper.getDeclaredValueParameter(declaration.symbol),
|
||||||
@@ -403,7 +389,7 @@ open class DeepCopyIrTreeWithSymbols(
|
|||||||
startOffset = declaration.startOffset,
|
startOffset = declaration.startOffset,
|
||||||
endOffset = declaration.endOffset,
|
endOffset = declaration.endOffset,
|
||||||
origin = mapDeclarationOrigin(declaration.origin),
|
origin = mapDeclarationOrigin(declaration.origin),
|
||||||
name = symbolRenamer.getTypeAliasName(declaration.symbol),
|
name = declaration.name,
|
||||||
visibility = declaration.visibility,
|
visibility = declaration.visibility,
|
||||||
symbol = symbolRemapper.getDeclaredTypeAlias(declaration.symbol),
|
symbol = symbolRemapper.getDeclaredTypeAlias(declaration.symbol),
|
||||||
isActual = declaration.isActual,
|
isActual = declaration.isActual,
|
||||||
|
|||||||
@@ -16,15 +16,12 @@ fun <T : IrElement> T.deepCopySavingMetadata(
|
|||||||
acceptVoid(symbolRemapper)
|
acceptVoid(symbolRemapper)
|
||||||
val typeRemapper = DeepCopyTypeRemapper(symbolRemapper)
|
val typeRemapper = DeepCopyTypeRemapper(symbolRemapper)
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
return transform(DeepCopySavingMetadata(symbolRemapper, typeRemapper, SymbolRenamer.DEFAULT), null)
|
return transform(DeepCopySavingMetadata(symbolRemapper, typeRemapper), null)
|
||||||
.patchDeclarationParents(initialParent) as T
|
.patchDeclarationParents(initialParent) as T
|
||||||
}
|
}
|
||||||
|
|
||||||
private class DeepCopySavingMetadata(
|
private class DeepCopySavingMetadata(symbolRemapper: SymbolRemapper, typeRemapper: TypeRemapper) :
|
||||||
symbolRemapper: SymbolRemapper,
|
DeepCopyIrTreeWithSymbols(symbolRemapper, typeRemapper) {
|
||||||
typeRemapper: TypeRemapper,
|
|
||||||
symbolRenamer: SymbolRenamer
|
|
||||||
) : DeepCopyIrTreeWithSymbols(symbolRemapper, typeRemapper, symbolRenamer) {
|
|
||||||
override fun visitFile(declaration: IrFile): IrFile =
|
override fun visitFile(declaration: IrFile): IrFile =
|
||||||
super.visitFile(declaration).apply {
|
super.visitFile(declaration).apply {
|
||||||
metadata = declaration.metadata
|
metadata = declaration.metadata
|
||||||
@@ -60,4 +57,4 @@ private class DeepCopySavingMetadata(
|
|||||||
super.visitLocalDelegatedProperty(declaration).apply {
|
super.visitLocalDelegatedProperty(declaration).apply {
|
||||||
metadata = declaration.metadata
|
metadata = declaration.metadata
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,4 +62,10 @@ fun DumpIrTreeVisitor(out: Appendable, normalizeNames: Boolean = false, stableOr
|
|||||||
DeprecationLevel.ERROR,
|
DeprecationLevel.ERROR,
|
||||||
)
|
)
|
||||||
fun RenderIrElementVisitor(normalizeNames: Boolean = false, verboseErrorTypes: Boolean = true) =
|
fun RenderIrElementVisitor(normalizeNames: Boolean = false, verboseErrorTypes: Boolean = true) =
|
||||||
RenderIrElementVisitor(DumpIrTreeOptions(normalizeNames = normalizeNames, verboseErrorTypes = verboseErrorTypes))
|
RenderIrElementVisitor(DumpIrTreeOptions(normalizeNames = normalizeNames, verboseErrorTypes = verboseErrorTypes))
|
||||||
|
|
||||||
|
// This class is not used meaningfully, but is left for compatibility with compose.
|
||||||
|
abstract class SymbolRenamer private constructor() {
|
||||||
|
@Deprecated("Used from Compose.")
|
||||||
|
companion object DEFAULT : SymbolRenamer()
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user