IR: rename and move deepCopyWithVariables

Rename it to `deepCopyWithoutPatchingParents`, move to
`org.jetbrains.kotlin.ir.util`, make it inline+reified, and extract the
common implementation with `deepCopyWithSymbols` into `deepCopyImpl`.
This commit is contained in:
Alexander Udalov
2024-03-07 14:14:40 +01:00
committed by Space Team
parent 1d38c01afc
commit d5c2aa4c0c
11 changed files with 35 additions and 36 deletions
@@ -1,19 +0,0 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.ir
import org.jetbrains.kotlin.ir.util.DeepCopyIrTreeWithSymbols
import org.jetbrains.kotlin.ir.util.DeepCopySymbolRemapper
import org.jetbrains.kotlin.ir.util.NullDescriptorsRemapper
import org.jetbrains.kotlin.ir.visitors.acceptVoid
@Suppress("UNCHECKED_CAST")
fun <T : IrElement> T.deepCopyWithVariables(): T {
val symbolsRemapper = DeepCopySymbolRemapper(NullDescriptorsRemapper)
acceptVoid(symbolsRemapper)
return this.transform(DeepCopyIrTreeWithSymbols(symbolsRemapper), null) as T
}
@@ -27,10 +27,19 @@ inline fun <reified T : IrElement> T.deepCopyWithSymbols(
initialParent: IrDeclarationParent? = null,
createTypeRemapper: (SymbolRemapper) -> TypeRemapper = ::DeepCopyTypeRemapper
): T {
return (deepCopyImpl(createTypeRemapper) as T).patchDeclarationParents(initialParent)
}
inline fun <reified T : IrElement> T.deepCopyWithoutPatchingParents(): T {
return deepCopyImpl(::DeepCopyTypeRemapper) as T
}
@PublishedApi
internal inline fun <T : IrElement> T.deepCopyImpl(createTypeRemapper: (SymbolRemapper) -> TypeRemapper): IrElement {
val symbolRemapper = DeepCopySymbolRemapper()
acceptVoid(symbolRemapper)
val typeRemapper = createTypeRemapper(symbolRemapper)
return transform(DeepCopyIrTreeWithSymbols(symbolRemapper, typeRemapper), null).patchDeclarationParents(initialParent) as T
return transform(DeepCopyIrTreeWithSymbols(symbolRemapper, typeRemapper), null)
}
@OptIn(ObsoleteDescriptorBasedAPI::class)
@@ -7,7 +7,9 @@ package org.jetbrains.kotlin.ir.util
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.IrFileEntry
import org.jetbrains.kotlin.ir.declarations.IrDeclarationParent
import org.jetbrains.kotlin.ir.declarations.IrFile
import org.jetbrains.kotlin.ir.visitors.acceptVoid
@Deprecated(
"Use the overload with DumpIrTreeOptions instead.",
@@ -69,3 +71,16 @@ abstract class SymbolRenamer private constructor() {
@Deprecated("Used from Compose.")
companion object DEFAULT : SymbolRenamer()
}
// This member is left for compatibility with compose.
@Deprecated("Use the other deepCopyWithSymbols instead.")
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
@kotlin.internal.LowPriorityInOverloadResolution // To fix bootstrap with K1 which cannot distinguish between the other deepCopyWithSymbols by lambda type.
inline fun <reified T : IrElement> T.deepCopyWithSymbols(
initialParent: IrDeclarationParent?,
createCopier: (SymbolRemapper, TypeRemapper) -> DeepCopyIrTreeWithSymbols,
): T {
val symbolRemapper = DeepCopySymbolRemapper()
acceptVoid(symbolRemapper)
return transform(createCopier(symbolRemapper, DeepCopyTypeRemapper(symbolRemapper)), null).patchDeclarationParents(initialParent) as T
}