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:
committed by
Space Team
parent
1d38c01afc
commit
d5c2aa4c0c
+1
-2
@@ -19,7 +19,6 @@ import org.jetbrains.kotlin.ir.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.builders.*
|
||||
import org.jetbrains.kotlin.ir.builders.declarations.*
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.deepCopyWithVariables
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrDelegatingConstructorCallImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||
@@ -282,7 +281,7 @@ class JvmAnnotationImplementationTransformer(val jvmContext: JvmBackendContext,
|
||||
fallbackPrimaryCtorParamsMap[propName]?.defaultValue?.takeIf { it.expression !is IrErrorExpression }
|
||||
else -> null
|
||||
}
|
||||
parameter.defaultValue = newDefaultValue?.deepCopyWithVariables()
|
||||
parameter.defaultValue = newDefaultValue?.deepCopyWithoutPatchingParents()
|
||||
?.also { if (defaultValueTransformer != null) it.transformChildrenVoid(defaultValueTransformer) }
|
||||
|
||||
ctorBody.statements += with(ctorBodyBuilder) {
|
||||
|
||||
@@ -24,7 +24,6 @@ import org.jetbrains.kotlin.ir.builders.declarations.buildConstructor
|
||||
import org.jetbrains.kotlin.ir.builders.declarations.buildField
|
||||
import org.jetbrains.kotlin.ir.builders.declarations.buildFun
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.deepCopyWithVariables
|
||||
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
import org.jetbrains.kotlin.ir.types.IrSimpleType
|
||||
@@ -64,7 +63,7 @@ fun createLeafMfvcNode(
|
||||
oldBackingField.metadata = null
|
||||
}.apply {
|
||||
this.parent = oldBackingField.parent
|
||||
this.annotations = fieldAnnotations.map { it.deepCopyWithVariables() }
|
||||
this.annotations = fieldAnnotations.map { it.deepCopyWithoutPatchingParents() }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user