diff --git a/compiler/cli/cli-js-klib/src/GenerateJsIrKlib.kt b/compiler/cli/cli-js-klib/src/GenerateJsIrKlib.kt index 44586cd43cc..6eedb3d3519 100644 --- a/compiler/cli/cli-js-klib/src/GenerateJsIrKlib.kt +++ b/compiler/cli/cli-js-klib/src/GenerateJsIrKlib.kt @@ -88,7 +88,7 @@ fun buildKLib( configuration = configuration, allDependencies = allDependencies, friendDependencies = emptyList(), - irFactory = PersistentIrFactory, + irFactory = PersistentIrFactory(), // TODO: IrFactoryImpl? outputKlibPath = outputPath, nopack = true ) diff --git a/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt b/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt index a359dc22cf1..9d08c4548bd 100644 --- a/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt +++ b/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt @@ -199,7 +199,7 @@ class K2JsIrCompiler : CLICompiler() { configuration = config.configuration, allDependencies = resolvedLibraries, friendDependencies = friendDependencies, - irFactory = PersistentIrFactory, + irFactory = PersistentIrFactory(), // TODO IrFactoryImpl? outputKlibPath = outputFile.path, nopack = arguments.irProduceKlibDir ) diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/Lower.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/Lower.kt index 34932c56eab..c10fc4cfa06 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/Lower.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/Lower.kt @@ -19,8 +19,10 @@ package org.jetbrains.kotlin.backend.common import org.jetbrains.kotlin.ir.IrElement import org.jetbrains.kotlin.ir.IrStatement import org.jetbrains.kotlin.ir.declarations.* +import org.jetbrains.kotlin.ir.expressions.IrBlockBody import org.jetbrains.kotlin.ir.expressions.IrBody import org.jetbrains.kotlin.ir.expressions.IrStatementContainer +import org.jetbrains.kotlin.ir.expressions.IrExpressionBody import org.jetbrains.kotlin.ir.util.transformFlat import org.jetbrains.kotlin.ir.util.transformSubsetFlat import org.jetbrains.kotlin.ir.visitors.IrElementVisitor @@ -151,8 +153,8 @@ private class BodyLoweringVisitor( if (allowDeclarationModification) { loweringPass.lower(body, data!!) } else { - stageController.bodyLowering { - loweringPass.lower(body, data!!) + data!!.factory.stageController.bodyLowering { + loweringPass.lower(body, data) } } } @@ -178,7 +180,7 @@ interface DeclarationTransformer : FileLoweringPass { } private fun transformFlatRestricted(declaration: IrDeclaration): List? { - return stageController.restrictTo(declaration) { + return declaration.factory.stageController.restrictTo(declaration) { transformFlat(declaration) } } diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/ir/IrUtils.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/ir/IrUtils.kt index ccc4a17a685..b45bab06a28 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/ir/IrUtils.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/ir/IrUtils.kt @@ -355,7 +355,7 @@ fun IrType.remapTypeParameters( /* Copied from K/N */ fun IrDeclarationContainer.addChild(declaration: IrDeclaration) { - stageController.unrestrictDeclarationListsAccess { + declaration.factory.stageController.unrestrictDeclarationListsAccess { this.declarations += declaration } declaration.setDeclarationsParent(this) diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/InnerClassesLowering.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/InnerClassesLowering.kt index 8b19b60b57f..255d82e1f82 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/InnerClassesLowering.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/InnerClassesLowering.kt @@ -35,7 +35,7 @@ class InnerClassesLowering(val context: BackendContext, private val innerClasses override fun transformFlat(declaration: IrDeclaration): List? { if (declaration is IrClass && declaration.isInner) { - stageController.unrestrictDeclarationListsAccess { + context.irFactory.stageController.unrestrictDeclarationListsAccess { declaration.declarations += innerClassesSupport.getOuterThisField(declaration) } } else if (declaration is IrConstructor) { diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/Dce.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/Dce.kt index a07ba642801..282cc71884e 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/Dce.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/Dce.kt @@ -29,11 +29,11 @@ fun eliminateDeadDeclarations( context: JsIrBackendContext ) { - val allRoots = stageController.withInitialIr { buildRoots(modules, context) } + val allRoots = context.irFactory.stageController.withInitialIr { buildRoots(modules, context) } val usefulDeclarations = usefulDeclarations(allRoots, context) - stageController.unrestrictDeclarationListsAccess { + context.irFactory.stageController.unrestrictDeclarationListsAccess { removeUselessDeclarations(modules, usefulDeclarations) } } @@ -169,7 +169,7 @@ fun usefulDeclarations(roots: Iterable, context: JsIrBackendConte } // use withInitialIr to avoid ConcurrentModificationException in dce-driven lowering when adding roots' nested declarations (members) - stageController.withInitialIr { + context.irFactory.stageController.withInitialIr { // Add roots roots.forEach { it.enqueue(null, null, altFromFqn = "") diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIntrinsics.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIntrinsics.kt index 1bac938a8c6..6ba799b9622 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIntrinsics.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIntrinsics.kt @@ -204,12 +204,12 @@ class JsIntrinsics(private val irBuiltIns: IrBuiltIns, val context: JsIrBackendC val anyConstructorSymbol = anyClassSymbol.constructors.single() val jsObjectClassSymbol = getInternalClassWithoutPackage("kotlin.js.JsObject") - val jsObjectConstructorSymbol by lazy2 { jsObjectClassSymbol.constructors.single() } + val jsObjectConstructorSymbol by context.lazy2 { jsObjectClassSymbol.constructors.single() } - val uByteClassSymbol by lazy2 { getInternalClassWithoutPackage("kotlin.UByte") } - val uShortClassSymbol by lazy2 { getInternalClassWithoutPackage("kotlin.UShort") } - val uIntClassSymbol by lazy2 { getInternalClassWithoutPackage("kotlin.UInt") } - val uLongClassSymbol by lazy2 { getInternalClassWithoutPackage("kotlin.ULong") } + val uByteClassSymbol by context.lazy2 { getInternalClassWithoutPackage("kotlin.UByte") } + val uShortClassSymbol by context.lazy2 { getInternalClassWithoutPackage("kotlin.UShort") } + val uIntClassSymbol by context.lazy2 { getInternalClassWithoutPackage("kotlin.UInt") } + val uLongClassSymbol by context.lazy2 { getInternalClassWithoutPackage("kotlin.ULong") } val unreachable = defineUnreachableIntrinsic() @@ -285,16 +285,16 @@ class JsIntrinsics(private val irBuiltIns: IrBuiltIns, val context: JsIrBackendC // TODO move CharSequence-related stiff to IntrinsifyCallsLowering val charSequenceClassSymbol = context.symbolTable.referenceClass(context.getClass(FqName("kotlin.CharSequence"))) - val charSequenceLengthPropertyGetterSymbol by lazy2 { + val charSequenceLengthPropertyGetterSymbol by context.lazy2 { with(charSequenceClassSymbol.owner.declarations) { filterIsInstance().firstOrNull { it.name.asString() == "length" }?.getter ?: filterIsInstance().first { it.name.asString() == "" } }.symbol } - val charSequenceGetFunctionSymbol by lazy2 { + val charSequenceGetFunctionSymbol by context.lazy2 { charSequenceClassSymbol.owner.declarations.filterIsInstance().single { it.name.asString() == "get" }.symbol } - val charSequenceSubSequenceFunctionSymbol by lazy2 { + val charSequenceSubSequenceFunctionSymbol by context.lazy2 { charSequenceClassSymbol.owner.declarations.filterIsInstance().single { it.name.asString() == "subSequence" }.symbol } diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIrBackendContext.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIrBackendContext.kt index 07a6285df25..799cfe84db2 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIrBackendContext.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIrBackendContext.kt @@ -115,7 +115,7 @@ class JsIrBackendContext( val testRoots: Map get() = testContainerFuns - override val mapping = JsMapping() + override val mapping = JsMapping(irFactory) override val inlineClassesUtils = JsInlineClassesUtils(this) @@ -362,7 +362,7 @@ class JsIrBackendContext( /*TODO*/ print(message) } -} -// TODO: investigate if it could be removed -fun lazy2(fn: () -> T) = lazy { stageController.withInitialIr(fn) } \ No newline at end of file + // TODO: investigate if it could be removed + fun lazy2(fn: () -> T) = lazy { irFactory.stageController.withInitialIr(fn) } +} \ No newline at end of file diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsMapping.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsMapping.kt index 344820b5b88..1879b045266 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsMapping.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsMapping.kt @@ -9,7 +9,7 @@ import org.jetbrains.kotlin.backend.common.DefaultMapping import org.jetbrains.kotlin.backend.common.Mapping import org.jetbrains.kotlin.ir.declarations.* -class JsMapping : DefaultMapping() { +class JsMapping(private val irFactory: IrFactory) : DefaultMapping() { val outerThisFieldSymbols = newMapping() val innerClassConstructors = newMapping() val originalInnerClassPrimaryConstructorByClass = newMapping() @@ -35,12 +35,12 @@ class JsMapping : DefaultMapping() { private val map: MutableMap = mutableMapOf() override operator fun get(key: K): V? { - stageController.lazyLower(key) + irFactory.stageController.lazyLower(key) return map[key] } override operator fun set(key: K, value: V?) { - stageController.lazyLower(key) + irFactory.stageController.lazyLower(key) if (value == null) { map.remove(key) } else { diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/compiler.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/compiler.kt index ccc1d64bf62..8801d53a744 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/compiler.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/compiler.kt @@ -18,7 +18,6 @@ import org.jetbrains.kotlin.ir.declarations.IrModuleFragment import org.jetbrains.kotlin.ir.declarations.StageController import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl import org.jetbrains.kotlin.ir.declarations.persistent.PersistentIrFactory -import org.jetbrains.kotlin.ir.declarations.stageController import org.jetbrains.kotlin.ir.util.ExternalDependenciesGenerator import org.jetbrains.kotlin.ir.util.noUnboundLeft import org.jetbrains.kotlin.library.KotlinLibrary @@ -51,9 +50,7 @@ fun compile( relativeRequirePath: Boolean = false, propertyLazyInitialization: Boolean, ): CompilerResult { - stageController = StageController() - - val irFactory = if (dceDriven) PersistentIrFactory else IrFactoryImpl + val irFactory = if (dceDriven) PersistentIrFactory() else IrFactoryImpl val (moduleFragment: IrModuleFragment, dependencyModules, irBuiltIns, symbolTable, deserializer) = loadIr(project, mainModule, analyzer, configuration, allDependencies, friendDependencies, irFactory) @@ -93,14 +90,15 @@ fun compile( if (dceDriven) { val controller = MutableController(context, pirLowerings) - stageController = controller + + check(irFactory is PersistentIrFactory) + irFactory.stageController = controller controller.currentStage = controller.lowerings.size + 1 eliminateDeadDeclarations(allModules, context) - // TODO investigate whether this is needed anymore - stageController = StageController(controller.currentStage) + irFactory.stageController = StageController(controller.currentStage) val transformer = IrModuleToJsTransformer( context, diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/BlockDecomposerLowering.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/BlockDecomposerLowering.kt index fb41a8dc6c1..7f790cee076 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/BlockDecomposerLowering.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/BlockDecomposerLowering.kt @@ -72,7 +72,7 @@ abstract class AbstractBlockDecomposerLowering( val lastStatement = newBody.statements.last() val actualParent = if (newBody.statements.size > 1 || lastStatement !is IrReturn || lastStatement.value != expression) { expression = JsIrBuilder.buildCall(initFunction.symbol, expression.type) - stageController.unrestrictDeclarationListsAccess { + context.irFactory.stageController.unrestrictDeclarationListsAccess { (container.parent as IrDeclarationContainer).declarations += initFunction } initFunction diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/EnumClassLowering.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/EnumClassLowering.kt index 18fb7306805..059ad88674d 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/EnumClassLowering.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/EnumClassLowering.kt @@ -353,7 +353,7 @@ class EnumClassCreateInitializerLowering(val context: JsCommonBackendContext) : // TODO Why not move to upper level? // TODO Also doesn't fit the transformFlat-ish API - stageController.unrestrictDeclarationListsAccess { + context.irFactory.stageController.unrestrictDeclarationListsAccess { declaration.declarations += entryInstancesInitializedVar declaration.declarations += initEntryInstancesFun } @@ -414,7 +414,7 @@ class EnumEntryCreateGetInstancesFunsLowering(val context: JsCommonBackendContex // TODO prettify entryGetInstanceFun.parent = irClass.parent - stageController.unrestrictDeclarationListsAccess { + context.irFactory.stageController.unrestrictDeclarationListsAccess { (irClass.parent as IrDeclarationContainer).declarations += entryGetInstanceFun } diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/ExternalEnumUsagesLowering.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/ExternalEnumUsagesLowering.kt index 3c0cf4559c9..b9970eb41e4 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/ExternalEnumUsagesLowering.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/ExternalEnumUsagesLowering.kt @@ -53,7 +53,7 @@ class ExternalEnumUsagesLowering(val context: JsIrBackendContext) : BodyLowering it.parent = irClass // TODO need a way to emerge local declarations from BodyLoweringPass - stageController.unrestrictDeclarationListsAccess { + context.irFactory.stageController.unrestrictDeclarationListsAccess { irClass.declarations += it } } diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/JsSingleAbstractMethodLowering.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/JsSingleAbstractMethodLowering.kt index 5ebede73f40..a55fecdfb78 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/JsSingleAbstractMethodLowering.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/JsSingleAbstractMethodLowering.kt @@ -45,7 +45,7 @@ class JsSingleAbstractMethodLowering(context: JsIrBackendContext) : SingleAbstra for (wrapper in cachedImplementations.values + inlineCachedImplementations.values) { val parentClass = wrapper.parent as IrDeclarationContainer - stageController.unrestrictDeclarationListsAccess { + context.irFactory.stageController.unrestrictDeclarationListsAccess { parentClass.declarations += wrapper } } diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/PrimaryConstructorLowering.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/PrimaryConstructorLowering.kt index 4319416ea54..37f24e09f39 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/PrimaryConstructorLowering.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/PrimaryConstructorLowering.kt @@ -22,7 +22,7 @@ import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid // Create primary constructor if it doesn't exist -class PrimaryConstructorLowering(context: JsCommonBackendContext) : DeclarationTransformer { +class PrimaryConstructorLowering(val context: JsCommonBackendContext) : DeclarationTransformer { private var IrClass.syntheticPrimaryConstructor by context.mapping.classToSyntheticPrimaryConstructor @@ -44,7 +44,7 @@ class PrimaryConstructorLowering(context: JsCommonBackendContext) : DeclarationT private fun createPrimaryConstructor(irClass: IrClass): IrConstructor { // TODO better API for declaration creation. This case doesn't fit the usual transformFlat-like API. - val declaration = stageController.unrestrictDeclarationListsAccess { + val declaration = context.irFactory.stageController.unrestrictDeclarationListsAccess { irClass.addConstructor { origin = SYNTHETIC_PRIMARY_CONSTRUCTOR isPrimary = true diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/PropertyLazyInitLowering.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/PropertyLazyInitLowering.kt index 9bf85282574..2985400d775 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/PropertyLazyInitLowering.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/PropertyLazyInitLowering.kt @@ -296,7 +296,7 @@ private val IrDeclaration.correspondingProperty: IrProperty? } private fun IrDeclaration.propertyWithPersistentSafe(transform: IrDeclaration.() -> IrProperty?): IrProperty? = - if (((this as? PersistentIrElementBase<*>)?.createdOn ?: 0) <= stageController.currentStage) { + if (this !is PersistentIrElementBase<*> || this.createdOn <= this.factory.stageController.currentStage) { transform() } else null diff --git a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/WasmBackendContext.kt b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/WasmBackendContext.kt index 5a346fc52c9..a73569d759b 100644 --- a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/WasmBackendContext.kt +++ b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/WasmBackendContext.kt @@ -37,7 +37,7 @@ class WasmBackendContext( @Suppress("UNUSED_PARAMETER") symbolTable: SymbolTable, @Suppress("UNUSED_PARAMETER") irModuleFragment: IrModuleFragment, val additionalExportedDeclarations: Set, - override val configuration: CompilerConfiguration + override val configuration: CompilerConfiguration, ) : JsCommonBackendContext { override val builtIns = module.builtIns override var inVerbosePhase: Boolean = false @@ -55,7 +55,7 @@ class WasmBackendContext( ) } - override val mapping = JsMapping() + override val mapping = JsMapping(irFactory) val innerClassesSupport = JsInnerClassesSupport(mapping, irFactory) diff --git a/compiler/ir/ir.tree.impl/src/org/jetbrains/kotlin/ir/declarations/impl/IrFactoryImpl.kt b/compiler/ir/ir.tree.impl/src/org/jetbrains/kotlin/ir/declarations/impl/IrFactoryImpl.kt index f1939e4a0ae..68a6a1917ea 100644 --- a/compiler/ir/ir.tree.impl/src/org/jetbrains/kotlin/ir/declarations/impl/IrFactoryImpl.kt +++ b/compiler/ir/ir.tree.impl/src/org/jetbrains/kotlin/ir/declarations/impl/IrFactoryImpl.kt @@ -20,6 +20,8 @@ import org.jetbrains.kotlin.serialization.deserialization.descriptors.Deserializ import org.jetbrains.kotlin.types.Variance object IrFactoryImpl : IrFactory { + override val stageController: StageController = StageController() + override fun createAnonymousInitializer( startOffset: Int, endOffset: Int, diff --git a/compiler/ir/ir.tree.persistent/gen/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrAnonymousInitializer.kt b/compiler/ir/ir.tree.persistent/gen/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrAnonymousInitializer.kt index b051c05adbf..04328f0b3fe 100644 --- a/compiler/ir/ir.tree.persistent/gen/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrAnonymousInitializer.kt +++ b/compiler/ir/ir.tree.persistent/gen/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrAnonymousInitializer.kt @@ -12,7 +12,6 @@ import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin import org.jetbrains.kotlin.ir.declarations.IrDeclarationParent import org.jetbrains.kotlin.ir.declarations.persistent.carriers.AnonymousInitializerCarrier import org.jetbrains.kotlin.ir.declarations.persistent.carriers.Carrier -import org.jetbrains.kotlin.ir.declarations.stageController import org.jetbrains.kotlin.ir.expressions.IrBlockBody import org.jetbrains.kotlin.ir.expressions.IrConstructorCall import org.jetbrains.kotlin.ir.symbols.IrAnonymousInitializerSymbol @@ -24,7 +23,8 @@ internal class PersistentIrAnonymousInitializer( override val endOffset: Int, origin: IrDeclarationOrigin, override val symbol: IrAnonymousInitializerSymbol, - override val isStatic: Boolean = false + override val isStatic: Boolean = false, + override val factory: PersistentIrFactory ) : IrAnonymousInitializer(), PersistentIrDeclarationBase, AnonymousInitializerCarrier { @@ -33,10 +33,10 @@ internal class PersistentIrAnonymousInitializer( symbol.bind(this) } - override var lastModified: Int = stageController.currentStage - override var loweredUpTo: Int = stageController.currentStage + override var lastModified: Int = factory.stageController.currentStage + override var loweredUpTo: Int = factory.stageController.currentStage override var values: Array? = null - override val createdOn: Int = stageController.currentStage + override val createdOn: Int = factory.stageController.currentStage override var parentField: IrDeclarationParent? = null override var originField: IrDeclarationOrigin = origin diff --git a/compiler/ir/ir.tree.persistent/gen/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrClass.kt b/compiler/ir/ir.tree.persistent/gen/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrClass.kt index e62208b4947..ac0b04f8a0f 100644 --- a/compiler/ir/ir.tree.persistent/gen/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrClass.kt +++ b/compiler/ir/ir.tree.persistent/gen/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrClass.kt @@ -23,7 +23,6 @@ import org.jetbrains.kotlin.ir.declarations.IrValueParameter import org.jetbrains.kotlin.ir.declarations.MetadataSource import org.jetbrains.kotlin.ir.declarations.persistent.carriers.Carrier import org.jetbrains.kotlin.ir.declarations.persistent.carriers.ClassCarrier -import org.jetbrains.kotlin.ir.declarations.stageController import org.jetbrains.kotlin.ir.expressions.IrConstructorCall import org.jetbrains.kotlin.ir.symbols.IrClassSymbol import org.jetbrains.kotlin.ir.types.IrType @@ -47,7 +46,8 @@ internal class PersistentIrClass( override val isInline: Boolean = false, override val isExpect: Boolean = false, override val isFun: Boolean = false, - override val source: SourceElement = SourceElement.NO_SOURCE + override val source: SourceElement = SourceElement.NO_SOURCE, + override val factory: PersistentIrFactory ) : IrClass(), PersistentIrDeclarationBase, ClassCarrier { @@ -56,10 +56,10 @@ internal class PersistentIrClass( symbol.bind(this) } - override var lastModified: Int = stageController.currentStage - override var loweredUpTo: Int = stageController.currentStage + override var lastModified: Int = factory.stageController.currentStage + override var loweredUpTo: Int = factory.stageController.currentStage override var values: Array? = null - override val createdOn: Int = stageController.currentStage + override val createdOn: Int = factory.stageController.currentStage override var parentField: IrDeclarationParent? = null override var originField: IrDeclarationOrigin = origin @@ -94,11 +94,11 @@ internal class PersistentIrClass( override val declarations: MutableList = ArrayList() get() { - if (createdOn < stageController.currentStage && initialDeclarations == null) { + if (createdOn < factory.stageController.currentStage && initialDeclarations == null) { initialDeclarations = Collections.unmodifiableList(ArrayList(field)) } - return if (stageController.canAccessDeclarationsOf(this)) { + return if (factory.stageController.canAccessDeclarationsOf(this)) { ensureLowered() field } else { diff --git a/compiler/ir/ir.tree.persistent/gen/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrConstructor.kt b/compiler/ir/ir.tree.persistent/gen/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrConstructor.kt index d44f6daeb74..6781318e5f3 100644 --- a/compiler/ir/ir.tree.persistent/gen/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrConstructor.kt +++ b/compiler/ir/ir.tree.persistent/gen/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrConstructor.kt @@ -16,7 +16,6 @@ import org.jetbrains.kotlin.ir.declarations.IrValueParameter import org.jetbrains.kotlin.ir.declarations.MetadataSource import org.jetbrains.kotlin.ir.declarations.persistent.carriers.Carrier import org.jetbrains.kotlin.ir.declarations.persistent.carriers.ConstructorCarrier -import org.jetbrains.kotlin.ir.declarations.stageController import org.jetbrains.kotlin.ir.expressions.IrBody import org.jetbrains.kotlin.ir.expressions.IrConstructorCall import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol @@ -40,7 +39,8 @@ internal class PersistentIrConstructor( isExternal: Boolean, override val isPrimary: Boolean, override val isExpect: Boolean, - override val containerSource: DeserializedContainerSource? + override val containerSource: DeserializedContainerSource?, + override val factory: PersistentIrFactory ) : IrConstructor(), PersistentIrDeclarationBase, ConstructorCarrier { @@ -49,10 +49,10 @@ internal class PersistentIrConstructor( symbol.bind(this) } - override var lastModified: Int = stageController.currentStage - override var loweredUpTo: Int = stageController.currentStage + override var lastModified: Int = factory.stageController.currentStage + override var loweredUpTo: Int = factory.stageController.currentStage override var values: Array? = null - override val createdOn: Int = stageController.currentStage + override val createdOn: Int = factory.stageController.currentStage override var parentField: IrDeclarationParent? = null override var originField: IrDeclarationOrigin = origin diff --git a/compiler/ir/ir.tree.persistent/gen/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrEnumEntry.kt b/compiler/ir/ir.tree.persistent/gen/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrEnumEntry.kt index a681c2a9844..a450d50985e 100644 --- a/compiler/ir/ir.tree.persistent/gen/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrEnumEntry.kt +++ b/compiler/ir/ir.tree.persistent/gen/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrEnumEntry.kt @@ -13,7 +13,6 @@ import org.jetbrains.kotlin.ir.declarations.IrDeclarationParent import org.jetbrains.kotlin.ir.declarations.IrEnumEntry import org.jetbrains.kotlin.ir.declarations.persistent.carriers.Carrier import org.jetbrains.kotlin.ir.declarations.persistent.carriers.EnumEntryCarrier -import org.jetbrains.kotlin.ir.declarations.stageController import org.jetbrains.kotlin.ir.expressions.IrConstructorCall import org.jetbrains.kotlin.ir.expressions.IrExpressionBody import org.jetbrains.kotlin.ir.symbols.IrEnumEntrySymbol @@ -26,7 +25,8 @@ internal class PersistentIrEnumEntry( override val endOffset: Int, origin: IrDeclarationOrigin, override val symbol: IrEnumEntrySymbol, - override val name: Name + override val name: Name, + override val factory: PersistentIrFactory ) : IrEnumEntry(), PersistentIrDeclarationBase, EnumEntryCarrier { @@ -35,10 +35,10 @@ internal class PersistentIrEnumEntry( symbol.bind(this) } - override var lastModified: Int = stageController.currentStage - override var loweredUpTo: Int = stageController.currentStage + override var lastModified: Int = factory.stageController.currentStage + override var loweredUpTo: Int = factory.stageController.currentStage override var values: Array? = null - override val createdOn: Int = stageController.currentStage + override val createdOn: Int = factory.stageController.currentStage override var parentField: IrDeclarationParent? = null override var originField: IrDeclarationOrigin = origin diff --git a/compiler/ir/ir.tree.persistent/gen/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrErrorDeclaration.kt b/compiler/ir/ir.tree.persistent/gen/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrErrorDeclaration.kt index 9611f86ab7f..6c4c6958959 100644 --- a/compiler/ir/ir.tree.persistent/gen/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrErrorDeclaration.kt +++ b/compiler/ir/ir.tree.persistent/gen/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrErrorDeclaration.kt @@ -12,7 +12,6 @@ import org.jetbrains.kotlin.ir.declarations.IrDeclarationParent import org.jetbrains.kotlin.ir.declarations.IrErrorDeclaration import org.jetbrains.kotlin.ir.declarations.persistent.carriers.Carrier import org.jetbrains.kotlin.ir.declarations.persistent.carriers.ErrorDeclarationCarrier -import org.jetbrains.kotlin.ir.declarations.stageController import org.jetbrains.kotlin.ir.descriptors.toIrBasedDescriptor import org.jetbrains.kotlin.ir.expressions.IrConstructorCall @@ -22,17 +21,18 @@ import org.jetbrains.kotlin.ir.expressions.IrConstructorCall internal class PersistentIrErrorDeclaration( override val startOffset: Int, override val endOffset: Int, - private val _descriptor: DeclarationDescriptor? + private val _descriptor: DeclarationDescriptor?, + override val factory: PersistentIrFactory ) : IrErrorDeclaration(), PersistentIrDeclarationBase, ErrorDeclarationCarrier { override val descriptor: DeclarationDescriptor get() = _descriptor ?: this.toIrBasedDescriptor() - override var lastModified: Int = stageController.currentStage - override var loweredUpTo: Int = stageController.currentStage + override var lastModified: Int = factory.stageController.currentStage + override var loweredUpTo: Int = factory.stageController.currentStage override var values: Array? = null - override val createdOn: Int = stageController.currentStage + override val createdOn: Int = factory.stageController.currentStage override var parentField: IrDeclarationParent? = null override var originField: IrDeclarationOrigin = IrDeclarationOrigin.DEFINED diff --git a/compiler/ir/ir.tree.persistent/gen/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrField.kt b/compiler/ir/ir.tree.persistent/gen/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrField.kt index 1c222461f04..179a13850e3 100644 --- a/compiler/ir/ir.tree.persistent/gen/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrField.kt +++ b/compiler/ir/ir.tree.persistent/gen/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrField.kt @@ -14,7 +14,6 @@ import org.jetbrains.kotlin.ir.declarations.IrField import org.jetbrains.kotlin.ir.declarations.MetadataSource import org.jetbrains.kotlin.ir.declarations.persistent.carriers.Carrier import org.jetbrains.kotlin.ir.declarations.persistent.carriers.FieldCarrier -import org.jetbrains.kotlin.ir.declarations.stageController import org.jetbrains.kotlin.ir.expressions.IrConstructorCall import org.jetbrains.kotlin.ir.expressions.IrExpressionBody import org.jetbrains.kotlin.ir.symbols.IrFieldSymbol @@ -34,7 +33,8 @@ internal class PersistentIrField( override var visibility: DescriptorVisibility, override val isFinal: Boolean, isExternal: Boolean, - override val isStatic: Boolean + override val isStatic: Boolean, + override val factory: PersistentIrFactory ) : IrField(), PersistentIrDeclarationBase, FieldCarrier { @@ -43,10 +43,10 @@ internal class PersistentIrField( symbol.bind(this) } - override var lastModified: Int = stageController.currentStage - override var loweredUpTo: Int = stageController.currentStage + override var lastModified: Int = factory.stageController.currentStage + override var loweredUpTo: Int = factory.stageController.currentStage override var values: Array? = null - override val createdOn: Int = stageController.currentStage + override val createdOn: Int = factory.stageController.currentStage override var parentField: IrDeclarationParent? = null override var originField: IrDeclarationOrigin = origin diff --git a/compiler/ir/ir.tree.persistent/gen/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrFunctionCommon.kt b/compiler/ir/ir.tree.persistent/gen/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrFunctionCommon.kt index a6327bdf99d..10abfab2522 100644 --- a/compiler/ir/ir.tree.persistent/gen/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrFunctionCommon.kt +++ b/compiler/ir/ir.tree.persistent/gen/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrFunctionCommon.kt @@ -15,7 +15,6 @@ import org.jetbrains.kotlin.ir.declarations.IrValueParameter import org.jetbrains.kotlin.ir.declarations.MetadataSource import org.jetbrains.kotlin.ir.declarations.persistent.carriers.Carrier import org.jetbrains.kotlin.ir.declarations.persistent.carriers.FunctionCarrier -import org.jetbrains.kotlin.ir.declarations.stageController import org.jetbrains.kotlin.ir.expressions.IrBody import org.jetbrains.kotlin.ir.expressions.IrConstructorCall import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol @@ -42,15 +41,16 @@ internal abstract class PersistentIrFunctionCommon( override val isOperator: Boolean, override val isInfix: Boolean, override val isExpect: Boolean, - override val containerSource: DeserializedContainerSource? = null + override val containerSource: DeserializedContainerSource? = null, + override val factory: PersistentIrFactory ) : IrSimpleFunction(), PersistentIrDeclarationBase, FunctionCarrier { - override var lastModified: Int = stageController.currentStage - override var loweredUpTo: Int = stageController.currentStage + override var lastModified: Int = factory.stageController.currentStage + override var loweredUpTo: Int = factory.stageController.currentStage override var values: Array? = null - override val createdOn: Int = stageController.currentStage + override val createdOn: Int = factory.stageController.currentStage override var parentField: IrDeclarationParent? = null override var originField: IrDeclarationOrigin = origin diff --git a/compiler/ir/ir.tree.persistent/gen/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrLocalDelegatedProperty.kt b/compiler/ir/ir.tree.persistent/gen/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrLocalDelegatedProperty.kt index 77e87a25393..479c2ade98f 100644 --- a/compiler/ir/ir.tree.persistent/gen/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrLocalDelegatedProperty.kt +++ b/compiler/ir/ir.tree.persistent/gen/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrLocalDelegatedProperty.kt @@ -15,7 +15,6 @@ import org.jetbrains.kotlin.ir.declarations.IrVariable import org.jetbrains.kotlin.ir.declarations.MetadataSource import org.jetbrains.kotlin.ir.declarations.persistent.carriers.Carrier import org.jetbrains.kotlin.ir.declarations.persistent.carriers.LocalDelegatedPropertyCarrier -import org.jetbrains.kotlin.ir.declarations.stageController import org.jetbrains.kotlin.ir.expressions.IrConstructorCall import org.jetbrains.kotlin.ir.symbols.IrLocalDelegatedPropertySymbol import org.jetbrains.kotlin.ir.types.IrType @@ -31,7 +30,8 @@ internal class PersistentIrLocalDelegatedProperty( override val symbol: IrLocalDelegatedPropertySymbol, override val name: Name, type: IrType, - override val isVar: Boolean + override val isVar: Boolean, + override val factory: PersistentIrFactory ) : IrLocalDelegatedProperty(), PersistentIrDeclarationBase, LocalDelegatedPropertyCarrier { @@ -40,10 +40,10 @@ internal class PersistentIrLocalDelegatedProperty( symbol.bind(this) } - override var lastModified: Int = stageController.currentStage - override var loweredUpTo: Int = stageController.currentStage + override var lastModified: Int = factory.stageController.currentStage + override var loweredUpTo: Int = factory.stageController.currentStage override var values: Array? = null - override val createdOn: Int = stageController.currentStage + override val createdOn: Int = factory.stageController.currentStage override var parentField: IrDeclarationParent? = null override var originField: IrDeclarationOrigin = origin diff --git a/compiler/ir/ir.tree.persistent/gen/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrPropertyCommon.kt b/compiler/ir/ir.tree.persistent/gen/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrPropertyCommon.kt index b86f839f78a..79c3c00383c 100644 --- a/compiler/ir/ir.tree.persistent/gen/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrPropertyCommon.kt +++ b/compiler/ir/ir.tree.persistent/gen/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrPropertyCommon.kt @@ -15,7 +15,6 @@ import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction import org.jetbrains.kotlin.ir.declarations.MetadataSource import org.jetbrains.kotlin.ir.declarations.persistent.carriers.Carrier import org.jetbrains.kotlin.ir.declarations.persistent.carriers.PropertyCarrier -import org.jetbrains.kotlin.ir.declarations.stageController import org.jetbrains.kotlin.ir.expressions.IrConstructorCall import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedContainerSource @@ -34,15 +33,16 @@ internal abstract class PersistentIrPropertyCommon( override val isDelegated: Boolean, isExternal: Boolean, override val isExpect: Boolean, - override val containerSource: DeserializedContainerSource? + override val containerSource: DeserializedContainerSource?, + override val factory: PersistentIrFactory ) : IrProperty(), PersistentIrDeclarationBase, PropertyCarrier { - override var lastModified: Int = stageController.currentStage - override var loweredUpTo: Int = stageController.currentStage + override var lastModified: Int = factory.stageController.currentStage + override var loweredUpTo: Int = factory.stageController.currentStage override var values: Array? = null - override val createdOn: Int = stageController.currentStage + override val createdOn: Int = factory.stageController.currentStage override var parentField: IrDeclarationParent? = null override var originField: IrDeclarationOrigin = origin diff --git a/compiler/ir/ir.tree.persistent/gen/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrTypeAlias.kt b/compiler/ir/ir.tree.persistent/gen/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrTypeAlias.kt index fc7860e0eba..a6635d84b22 100644 --- a/compiler/ir/ir.tree.persistent/gen/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrTypeAlias.kt +++ b/compiler/ir/ir.tree.persistent/gen/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrTypeAlias.kt @@ -14,7 +14,6 @@ import org.jetbrains.kotlin.ir.declarations.IrTypeAlias import org.jetbrains.kotlin.ir.declarations.IrTypeParameter import org.jetbrains.kotlin.ir.declarations.persistent.carriers.Carrier import org.jetbrains.kotlin.ir.declarations.persistent.carriers.TypeAliasCarrier -import org.jetbrains.kotlin.ir.declarations.stageController import org.jetbrains.kotlin.ir.expressions.IrConstructorCall import org.jetbrains.kotlin.ir.symbols.IrTypeAliasSymbol import org.jetbrains.kotlin.ir.types.IrType @@ -30,7 +29,8 @@ internal class PersistentIrTypeAlias( override var visibility: DescriptorVisibility, expandedType: IrType, override val isActual: Boolean, - origin: IrDeclarationOrigin + origin: IrDeclarationOrigin, + override val factory: PersistentIrFactory ) : IrTypeAlias(), PersistentIrDeclarationBase, TypeAliasCarrier { @@ -39,10 +39,10 @@ internal class PersistentIrTypeAlias( symbol.bind(this) } - override var lastModified: Int = stageController.currentStage - override var loweredUpTo: Int = stageController.currentStage + override var lastModified: Int = factory.stageController.currentStage + override var loweredUpTo: Int = factory.stageController.currentStage override var values: Array? = null - override val createdOn: Int = stageController.currentStage + override val createdOn: Int = factory.stageController.currentStage override var parentField: IrDeclarationParent? = null override var originField: IrDeclarationOrigin = origin diff --git a/compiler/ir/ir.tree.persistent/gen/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrTypeParameter.kt b/compiler/ir/ir.tree.persistent/gen/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrTypeParameter.kt index 0fa5b40fbb2..dead2eb5d89 100644 --- a/compiler/ir/ir.tree.persistent/gen/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrTypeParameter.kt +++ b/compiler/ir/ir.tree.persistent/gen/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrTypeParameter.kt @@ -12,7 +12,6 @@ import org.jetbrains.kotlin.ir.declarations.IrDeclarationParent import org.jetbrains.kotlin.ir.declarations.IrTypeParameter import org.jetbrains.kotlin.ir.declarations.persistent.carriers.Carrier import org.jetbrains.kotlin.ir.declarations.persistent.carriers.TypeParameterCarrier -import org.jetbrains.kotlin.ir.declarations.stageController import org.jetbrains.kotlin.ir.expressions.IrConstructorCall import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol import org.jetbrains.kotlin.ir.types.IrType @@ -29,7 +28,8 @@ internal class PersistentIrTypeParameter( override val name: Name, override val index: Int, override val isReified: Boolean, - override val variance: Variance + override val variance: Variance, + override val factory: PersistentIrFactory ) : IrTypeParameter(), PersistentIrDeclarationBase, TypeParameterCarrier { @@ -38,10 +38,10 @@ internal class PersistentIrTypeParameter( symbol.bind(this) } - override var lastModified: Int = stageController.currentStage - override var loweredUpTo: Int = stageController.currentStage + override var lastModified: Int = factory.stageController.currentStage + override var loweredUpTo: Int = factory.stageController.currentStage override var values: Array? = null - override val createdOn: Int = stageController.currentStage + override val createdOn: Int = factory.stageController.currentStage override var parentField: IrDeclarationParent? = null override var originField: IrDeclarationOrigin = origin diff --git a/compiler/ir/ir.tree.persistent/gen/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrValueParameter.kt b/compiler/ir/ir.tree.persistent/gen/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrValueParameter.kt index 241521ee85e..b8702386221 100644 --- a/compiler/ir/ir.tree.persistent/gen/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrValueParameter.kt +++ b/compiler/ir/ir.tree.persistent/gen/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrValueParameter.kt @@ -12,7 +12,6 @@ import org.jetbrains.kotlin.ir.declarations.IrDeclarationParent import org.jetbrains.kotlin.ir.declarations.IrValueParameter import org.jetbrains.kotlin.ir.declarations.persistent.carriers.Carrier import org.jetbrains.kotlin.ir.declarations.persistent.carriers.ValueParameterCarrier -import org.jetbrains.kotlin.ir.declarations.stageController import org.jetbrains.kotlin.ir.expressions.IrConstructorCall import org.jetbrains.kotlin.ir.expressions.IrExpressionBody import org.jetbrains.kotlin.ir.symbols.IrValueParameterSymbol @@ -33,7 +32,8 @@ internal class PersistentIrValueParameter( override val isCrossinline: Boolean, override val isNoinline: Boolean, override val isHidden: Boolean, - override val isAssignable: Boolean + override val isAssignable: Boolean, + override val factory: PersistentIrFactory ) : IrValueParameter(), PersistentIrDeclarationBase, ValueParameterCarrier { @@ -46,10 +46,10 @@ internal class PersistentIrValueParameter( symbol.bind(this) } - override var lastModified: Int = stageController.currentStage - override var loweredUpTo: Int = stageController.currentStage + override var lastModified: Int = factory.stageController.currentStage + override var loweredUpTo: Int = factory.stageController.currentStage override var values: Array? = null - override val createdOn: Int = stageController.currentStage + override val createdOn: Int = factory.stageController.currentStage override var parentField: IrDeclarationParent? = null override var originField: IrDeclarationOrigin = origin diff --git a/compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/AnonymousInitializer.kt b/compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/AnonymousInitializer.kt index 0790f993898..62caa036963 100644 --- a/compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/AnonymousInitializer.kt +++ b/compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/AnonymousInitializer.kt @@ -18,6 +18,7 @@ internal fun PersistentIrGenerator.generateAnonymousInitializer() { origin, +"override val symbol: " + IrAnonymousInitializerSymbol, isStatic + " = false", + irFactory, ).join(separator = ",\n").indent(), +") : " + baseClasses("AnonymousInitializer") + " " + blockSpaced( initBlock, diff --git a/compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/Class.kt b/compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/Class.kt index 870379a130c..8705859e10f 100644 --- a/compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/Class.kt +++ b/compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/Class.kt @@ -36,6 +36,7 @@ internal fun PersistentIrGenerator.generateClass() { isExpect + " = false", isFun, source, + irFactory, ).join(separator = ",\n").indent(), +") : " + baseClasses("Class") + " " + blockSpaced( initBlock, @@ -49,12 +50,12 @@ internal fun PersistentIrGenerator.generateClass() { +"override val declarations: MutableList = " + import("ArrayList", "java.util") + "()", lines( +"get() " + block( - +"if (createdOn < stageController.currentStage && initialDeclarations == null) " + block( + +"if (createdOn < factory.stageController.currentStage && initialDeclarations == null) " + block( +"initialDeclarations = " + import("Collections", "java.util") + ".unmodifiableList(ArrayList(field))" ), id, +""" - return if (stageController.canAccessDeclarationsOf(this)) { + return if (factory.stageController.canAccessDeclarationsOf(this)) { ensureLowered() field } else { diff --git a/compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/Constructor.kt b/compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/Constructor.kt index a75134ab61d..f6588ffc7dd 100644 --- a/compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/Constructor.kt +++ b/compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/Constructor.kt @@ -33,6 +33,7 @@ internal fun PersistentIrGenerator.generateConstructor() { isPrimary, isExpect, containerSource, + irFactory, ).join(separator = ",\n").indent(), +") : " + baseClasses("Constructor") + " " + blockSpaced( initBlock, diff --git a/compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/EnumEntry.kt b/compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/EnumEntry.kt index 1346b4e6c1a..8481431a91f 100644 --- a/compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/EnumEntry.kt +++ b/compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/EnumEntry.kt @@ -19,6 +19,7 @@ internal fun PersistentIrGenerator.generateEnumEntry() { origin, +"override val symbol: " + irSymbol("IrEnumEntrySymbol"), name, + irFactory, ).join(separator = ",\n").indent(), +") : " + baseClasses("EnumEntry") + " " + blockSpaced( initBlock, diff --git a/compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/ErrorDeclaration.kt b/compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/ErrorDeclaration.kt index 9f5bc61d59a..3a39539dbc2 100644 --- a/compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/ErrorDeclaration.kt +++ b/compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/ErrorDeclaration.kt @@ -15,7 +15,8 @@ internal fun PersistentIrGenerator.generateErrorDeclaration() { arrayOf( startOffset, endOffset, - +"private val _descriptor: " + DeclarationDescriptor + "?" + +"private val _descriptor: " + DeclarationDescriptor + "?", + irFactory, ).join(separator = ",\n").indent(), +") : " + baseClasses("ErrorDeclaration") + " " + block( lines( diff --git a/compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/Field.kt b/compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/Field.kt index f440e7d0324..8c913d57b18 100644 --- a/compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/Field.kt +++ b/compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/Field.kt @@ -27,6 +27,7 @@ internal fun PersistentIrGenerator.generateField() { isFinal, isExternal, isStatic, + irFactory, ).join(separator = ",\n").indent(), +") : " + baseClasses("Field") + " " + blockSpaced( initBlock, diff --git a/compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/Function.kt b/compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/Function.kt index 0d3d21c20db..1940f5c32e0 100644 --- a/compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/Function.kt +++ b/compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/Function.kt @@ -39,6 +39,7 @@ internal fun PersistentIrGenerator.generateFunction() { +"override val isInfix: Boolean", isExpect, containerSource + " = null", + irFactory, ).join(separator = ",\n").indent(), +") : " + baseClasses("Function", baseClass = "IrSimpleFunction") + " " + blockSpaced( commonFields, diff --git a/compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/LocalDelegatedProperty.kt b/compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/LocalDelegatedProperty.kt index 468cfbaa17a..6ff921d3ea0 100644 --- a/compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/LocalDelegatedProperty.kt +++ b/compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/LocalDelegatedProperty.kt @@ -25,6 +25,7 @@ internal fun PersistentIrGenerator.generateLocalDelegatedProperty() { name, +"type: " + IrType, +"override val isVar: Boolean", + irFactory, ).join(separator = ",\n").indent(), +") : " + baseClasses("LocalDelegatedProperty") + " " + blockSpaced( initBlock, diff --git a/compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/PersistentIrGenerator.kt b/compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/PersistentIrGenerator.kt index 7b2dad9d8d1..7aca1583594 100644 --- a/compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/PersistentIrGenerator.kt +++ b/compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/PersistentIrGenerator.kt @@ -53,8 +53,6 @@ internal object PersistentIrGenerator { val ObsoleteDescriptorBasedAPI = import("ObsoleteDescriptorBasedAPI", "org.jetbrains.kotlin.ir") - val stageController = import("stageController", "org.jetbrains.kotlin.ir.declarations") - val IrType = import("IrType", "org.jetbrains.kotlin.ir.types") val IrPropertySymbol = irSymbol("IrPropertySymbol") @@ -82,15 +80,17 @@ internal object PersistentIrGenerator { val isPrimary = +"override val isPrimary: Boolean" val containerSource = +"override val containerSource: " + import("DeserializedContainerSource", "org.jetbrains.kotlin.serialization.deserialization.descriptors") + "?" + val irFactory = +"override val factory: PersistentIrFactory" + val initBlock = +"init " + block( +"symbol.bind(this)" ) // Fields - val lastModified = +"override var lastModified: Int = " + stageController + ".currentStage" - val loweredUpTo = +"override var loweredUpTo: Int = " + stageController + ".currentStage" + val lastModified = +"override var lastModified: Int = factory.stageController.currentStage" + val loweredUpTo = +"override var loweredUpTo: Int = factory.stageController.currentStage" val values = +"override var values: Array<" + Carrier + ">? = null" - val createdOn = +"override val createdOn: Int = " + stageController + ".currentStage" + val createdOn = +"override val createdOn: Int = factory.stageController.currentStage" val parentField = +"override var parentField: " + IrDeclarationParent + "? = null" val originField = +"override var originField: " + IrDeclarationOrigin + " = origin" diff --git a/compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/Property.kt b/compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/Property.kt index 462726a92ed..58fe12d906a 100644 --- a/compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/Property.kt +++ b/compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/Property.kt @@ -29,7 +29,8 @@ internal fun PersistentIrGenerator.generateProperty() { +"override val isDelegated: Boolean", isExternal, isExpect, - containerSource + containerSource, + irFactory, ).join(separator = ",\n").indent(), +") : " + baseClasses("Property") + " " + blockSpaced( commonFields, diff --git a/compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/TypeAlias.kt b/compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/TypeAlias.kt index 6bfa5dcabd9..d7c5fda0839 100644 --- a/compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/TypeAlias.kt +++ b/compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/TypeAlias.kt @@ -22,6 +22,7 @@ internal fun PersistentIrGenerator.generateTypeAlias() { +"expandedType: " + IrType, +"override val isActual: Boolean", origin, + irFactory, ).join(separator = ",\n").indent(), +") : " + baseClasses("TypeAlias") + " " + blockSpaced( initBlock, diff --git a/compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/TypeParameter.kt b/compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/TypeParameter.kt index dd03e385006..ff04267b62a 100644 --- a/compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/TypeParameter.kt +++ b/compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/TypeParameter.kt @@ -20,7 +20,8 @@ internal fun PersistentIrGenerator.generateTypeParameter() { name, +"override val index: Int", +"override val isReified: Boolean", - +"override val variance: " + import("Variance", "org.jetbrains.kotlin.types") + +"override val variance: " + import("Variance", "org.jetbrains.kotlin.types"), + irFactory, ).join(separator = ",\n").indent(), +") : " + baseClasses("TypeParameter") + " " + blockSpaced( initBlock, diff --git a/compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/ValueParameter.kt b/compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/ValueParameter.kt index 703a4c8b11d..395f1ee1635 100644 --- a/compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/ValueParameter.kt +++ b/compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/ValueParameter.kt @@ -27,7 +27,8 @@ internal fun PersistentIrGenerator.generateValueParameter() { +"override val isCrossinline: Boolean", +"override val isNoinline: Boolean", +"override val isHidden: Boolean", - +"override val isAssignable: Boolean" + +"override val isAssignable: Boolean", + irFactory, ).join(separator = ",\n").indent(), +") : " + baseClasses("ValueParameter") + " " + blockSpaced( descriptor(descriptorType("ParameterDescriptor")), diff --git a/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrDeclarationBase.kt b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrDeclarationBase.kt index c9b93bc9073..9d6b42a6f79 100644 --- a/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrDeclarationBase.kt +++ b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrDeclarationBase.kt @@ -17,9 +17,6 @@ import org.jetbrains.kotlin.ir.expressions.IrConstructorCall interface PersistentIrDeclarationBase : PersistentIrElementBase, IrDeclaration, DeclarationCarrier { var removedOn: Int - override val factory: IrFactory - get() = PersistentIrFactory - // TODO reduce boilerplate override var parent: IrDeclarationParent get() = getCarrier().parentField ?: throw UninitializedPropertyAccessException("Parent not initialized: $this") @@ -46,13 +43,16 @@ interface PersistentIrDeclarationBase : PersistentIrElem } override fun ensureLowered() { - if (stageController.currentStage > loweredUpTo) { - stageController.lazyLower(this) + if (factory.stageController.currentStage > loweredUpTo) { + factory.stageController.lazyLower(this) } } } interface PersistentIrElementBase : IrElement, Carrier { + + val factory: PersistentIrFactory + override var lastModified: Int var loweredUpTo: Int @@ -66,7 +66,7 @@ interface PersistentIrElementBase : IrElement, Carrier { @Suppress("UNCHECKED_CAST") fun getCarrier(): T { - stageController.currentStage.let { stage -> + factory.stageController.currentStage.let { stage -> ensureLowered() if (stage >= lastModified) return this as T @@ -97,11 +97,11 @@ interface PersistentIrElementBase : IrElement, Carrier { // TODO naming? e.g. `mutableCarrier` @Suppress("UNCHECKED_CAST") fun setCarrier(): T { - val stage = stageController.currentStage + val stage = factory.stageController.currentStage ensureLowered() - if (!stageController.canModify(this)) { + if (!factory.stageController.canModify(this)) { error("Cannot modify this element!") } @@ -136,7 +136,7 @@ interface PersistentIrBodyBase> : PersistentIrElemen } fun checkEnabled(fn: () -> T): T { - if (!stageController.bodiesEnabled) error("Bodies disabled!") + if (!factory.stageController.bodiesEnabled) error("Bodies disabled!") ensureLowered() return fn() } @@ -145,14 +145,14 @@ interface PersistentIrBodyBase> : PersistentIrElemen override fun ensureLowered() { initializer?.let { initFn -> initializer = null - stageController.withStage(createdOn) { - stageController.bodyLowering { + factory.stageController.withStage(createdOn) { + factory.stageController.bodyLowering { initFn.invoke(this as B) } } } - if (loweredUpTo + 1 < stageController.currentStage) { - stageController.lazyLower(this as IrBody) + if (loweredUpTo + 1 < factory.stageController.currentStage) { + factory.stageController.lazyLower(this as IrBody) } } } diff --git a/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrFactory.kt b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrFactory.kt index 1cbbd63941c..64ed078cbb9 100644 --- a/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrFactory.kt +++ b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrFactory.kt @@ -19,7 +19,10 @@ import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedContainerSource import org.jetbrains.kotlin.types.Variance -object PersistentIrFactory : IrFactory { +class PersistentIrFactory : IrFactory { + + override var stageController = StageController() + override fun createAnonymousInitializer( startOffset: Int, endOffset: Int, @@ -27,7 +30,7 @@ object PersistentIrFactory : IrFactory { symbol: IrAnonymousInitializerSymbol, isStatic: Boolean, ): IrAnonymousInitializer = - PersistentIrAnonymousInitializer(startOffset, endOffset, origin, symbol, isStatic) + PersistentIrAnonymousInitializer(startOffset, endOffset, origin, symbol, isStatic, this) override fun createClass( startOffset: Int, @@ -50,6 +53,7 @@ object PersistentIrFactory : IrFactory { PersistentIrClass( startOffset, endOffset, origin, symbol, name, kind, visibility, modality, isCompanion, isInner, isData, isExternal, isInline, isExpect, isFun, source, + this ) override fun createConstructor( @@ -68,7 +72,7 @@ object PersistentIrFactory : IrFactory { ): IrConstructor = PersistentIrConstructor( startOffset, endOffset, origin, symbol, name, visibility, returnType, isInline, isExternal, isPrimary, isExpect, - containerSource, + containerSource, this ) override fun createEnumEntry( @@ -78,14 +82,14 @@ object PersistentIrFactory : IrFactory { symbol: IrEnumEntrySymbol, name: Name, ): IrEnumEntry = - PersistentIrEnumEntry(startOffset, endOffset, origin, symbol, name) + PersistentIrEnumEntry(startOffset, endOffset, origin, symbol, name, this) override fun createErrorDeclaration( startOffset: Int, endOffset: Int, descriptor: DeclarationDescriptor?, ): IrErrorDeclaration = - PersistentIrErrorDeclaration(startOffset, endOffset, descriptor) + PersistentIrErrorDeclaration(startOffset, endOffset, descriptor, this) override fun createField( startOffset: Int, @@ -99,7 +103,7 @@ object PersistentIrFactory : IrFactory { isExternal: Boolean, isStatic: Boolean, ): IrField = - PersistentIrField(startOffset, endOffset, origin, symbol, name, type, visibility, isFinal, isExternal, isStatic) + PersistentIrField(startOffset, endOffset, origin, symbol, name, type, visibility, isFinal, isExternal, isStatic, this) override fun createFunction( startOffset: Int, @@ -123,7 +127,7 @@ object PersistentIrFactory : IrFactory { PersistentIrFunction( startOffset, endOffset, origin, symbol, name, visibility, modality, returnType, isInline, isExternal, isTailrec, isSuspend, isOperator, isInfix, isExpect, isFakeOverride, - containerSource + containerSource, this ) override fun createFakeOverrideFunction( @@ -144,7 +148,7 @@ object PersistentIrFactory : IrFactory { ): IrSimpleFunction = PersistentIrFakeOverrideFunction( startOffset, endOffset, origin, name, visibility, modality, returnType, - isInline, isExternal, isTailrec, isSuspend, isOperator, isInfix, isExpect, + isInline, isExternal, isTailrec, isSuspend, isOperator, isInfix, isExpect, this ) override fun createLocalDelegatedProperty( @@ -157,7 +161,7 @@ object PersistentIrFactory : IrFactory { isVar: Boolean, ): IrLocalDelegatedProperty = PersistentIrLocalDelegatedProperty( - startOffset, endOffset, origin, symbol, name, type, isVar + startOffset, endOffset, origin, symbol, name, type, isVar, this ) override fun createProperty( @@ -180,7 +184,7 @@ object PersistentIrFactory : IrFactory { PersistentIrProperty( startOffset, endOffset, origin, symbol, name, visibility, modality, isVar, isConst, isLateinit, isDelegated, isExternal, isExpect, isFakeOverride, - containerSource + containerSource, this ) override fun createFakeOverrideProperty( @@ -200,6 +204,7 @@ object PersistentIrFactory : IrFactory { PersistentIrFakeOverrideProperty( startOffset, endOffset, origin, name, visibility, modality, isVar, isConst, isLateinit, isDelegated, isExternal, isExpect, + this ) override fun createTypeAlias( @@ -212,7 +217,7 @@ object PersistentIrFactory : IrFactory { isActual: Boolean, origin: IrDeclarationOrigin, ): IrTypeAlias = - PersistentIrTypeAlias(startOffset, endOffset, symbol, name, visibility, expandedType, isActual, origin) + PersistentIrTypeAlias(startOffset, endOffset, symbol, name, visibility, expandedType, isActual, origin, this) override fun createTypeParameter( startOffset: Int, @@ -224,7 +229,7 @@ object PersistentIrFactory : IrFactory { isReified: Boolean, variance: Variance, ): IrTypeParameter = - PersistentIrTypeParameter(startOffset, endOffset, origin, symbol, name, index, isReified, variance) + PersistentIrTypeParameter(startOffset, endOffset, origin, symbol, name, index, isReified, variance, this) override fun createValueParameter( startOffset: Int, @@ -241,7 +246,7 @@ object PersistentIrFactory : IrFactory { isAssignable: Boolean ): IrValueParameter = PersistentIrValueParameter( - startOffset, endOffset, origin, symbol, name, index, type, varargElementType, isCrossinline, isNoinline, isHidden, isAssignable + startOffset, endOffset, origin, symbol, name, index, type, varargElementType, isCrossinline, isNoinline, isHidden, isAssignable, this ) override fun createExpressionBody( @@ -249,37 +254,37 @@ object PersistentIrFactory : IrFactory { endOffset: Int, initializer: IrExpressionBody.() -> Unit, ): IrExpressionBody = - PersistentIrExpressionBody(startOffset, endOffset, initializer) + PersistentIrExpressionBody(startOffset, endOffset, this, initializer) override fun createExpressionBody( startOffset: Int, endOffset: Int, expression: IrExpression, ): IrExpressionBody = - PersistentIrExpressionBody(startOffset, endOffset, expression) + PersistentIrExpressionBody(startOffset, endOffset, expression, this) override fun createExpressionBody( expression: IrExpression, ): IrExpressionBody = - PersistentIrExpressionBody(expression) + PersistentIrExpressionBody(expression, this) override fun createBlockBody( startOffset: Int, endOffset: Int, ): IrBlockBody = - PersistentIrBlockBody(startOffset, endOffset) + PersistentIrBlockBody(startOffset, endOffset, this) override fun createBlockBody( startOffset: Int, endOffset: Int, statements: List, ): IrBlockBody = - PersistentIrBlockBody(startOffset, endOffset, statements) + PersistentIrBlockBody(startOffset, endOffset, statements, this) override fun createBlockBody( startOffset: Int, endOffset: Int, initializer: IrBlockBody.() -> Unit, ): IrBlockBody = - PersistentIrBlockBody(startOffset, endOffset, initializer) + PersistentIrBlockBody(startOffset, endOffset, this, initializer) } diff --git a/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrFunction.kt b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrFunction.kt index 9cf6f61b6ab..f84fa22c18c 100644 --- a/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrFunction.kt +++ b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrFunction.kt @@ -33,11 +33,12 @@ internal class PersistentIrFunction( isInfix: Boolean, isExpect: Boolean, override val isFakeOverride: Boolean = origin == IrDeclarationOrigin.FAKE_OVERRIDE, - containerSource: DeserializedContainerSource? + containerSource: DeserializedContainerSource?, + factory: PersistentIrFactory, ) : PersistentIrFunctionCommon( startOffset, endOffset, origin, name, visibility, returnType, isInline, isExternal, isTailrec, isSuspend, isOperator, isInfix, isExpect, - containerSource + containerSource, factory ) { @ObsoleteDescriptorBasedAPI override val descriptor: FunctionDescriptor @@ -63,9 +64,10 @@ internal class PersistentIrFakeOverrideFunction( isOperator: Boolean, isInfix: Boolean, isExpect: Boolean, + factory: PersistentIrFactory, ) : PersistentIrFunctionCommon( startOffset, endOffset, origin, name, visibility, returnType, isInline, - isExternal, isTailrec, isSuspend, isOperator, isInfix, isExpect, + isExternal, isTailrec, isSuspend, isOperator, isInfix, isExpect, factory = factory ), IrFakeOverrideFunction { override val isFakeOverride: Boolean get() = true diff --git a/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrProperty.kt b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrProperty.kt index eba7bdafa13..9f2f8eb6e2d 100644 --- a/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrProperty.kt +++ b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrProperty.kt @@ -35,9 +35,10 @@ internal class PersistentIrProperty( isExpect: Boolean = false, override val isFakeOverride: Boolean = origin == IrDeclarationOrigin.FAKE_OVERRIDE, containerSource: DeserializedContainerSource?, + factory: PersistentIrFactory, ) : PersistentIrPropertyCommon( startOffset, endOffset, origin, name, visibility, isVar, isConst, isLateinit, isDelegated, isExternal, isExpect, - containerSource, + containerSource, factory ) { init { symbol.bind(this) @@ -61,10 +62,11 @@ internal class PersistentIrFakeOverrideProperty( isDelegated: Boolean, isExternal: Boolean, isExpect: Boolean, + factory: PersistentIrFactory, ) : PersistentIrPropertyCommon( startOffset, endOffset, origin, name, visibility, isVar, isConst, isLateinit, isDelegated, isExternal, isExpect, - containerSource = null, + containerSource = null, factory ), IrFakeOverrideProperty { override val isFakeOverride: Boolean get() = true diff --git a/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/expressions/persistent/PersistentIrBlockBody.kt b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/expressions/persistent/PersistentIrBlockBody.kt index cf82524f88e..15b82da46d9 100644 --- a/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/expressions/persistent/PersistentIrBlockBody.kt +++ b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/expressions/persistent/PersistentIrBlockBody.kt @@ -18,26 +18,25 @@ package org.jetbrains.kotlin.ir.expressions.persistent import org.jetbrains.kotlin.ir.IrStatement import org.jetbrains.kotlin.ir.declarations.IrDeclaration -import org.jetbrains.kotlin.ir.declarations.IrFactory import org.jetbrains.kotlin.ir.declarations.persistent.PersistentIrBodyBase import org.jetbrains.kotlin.ir.declarations.persistent.PersistentIrFactory import org.jetbrains.kotlin.ir.declarations.persistent.carriers.Carrier -import org.jetbrains.kotlin.ir.declarations.stageController import org.jetbrains.kotlin.ir.expressions.IrBlockBody internal class PersistentIrBlockBody( override val startOffset: Int, override val endOffset: Int, + override val factory: PersistentIrFactory, override var initializer: (PersistentIrBlockBody.() -> Unit)? = null ) : IrBlockBody(), PersistentIrBodyBase { - override var lastModified: Int = stageController.currentStage - override var loweredUpTo: Int = stageController.currentStage + override var lastModified: Int = factory.stageController.currentStage + override var loweredUpTo: Int = factory.stageController.currentStage override var values: Array? = null - override val createdOn: Int = stageController.currentStage + override val createdOn: Int = factory.stageController.currentStage override var containerField: IrDeclaration? = null - constructor(startOffset: Int, endOffset: Int, statements: List) : this(startOffset, endOffset) { + constructor(startOffset: Int, endOffset: Int, statements: List, factory: PersistentIrFactory) : this(startOffset, endOffset, factory) { statementsField.addAll(statements) } @@ -45,7 +44,4 @@ internal class PersistentIrBlockBody( override val statements: MutableList get() = checkEnabled { statementsField } - - override val factory: IrFactory - get() = PersistentIrFactory } diff --git a/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/expressions/persistent/PersistentIrExpressionBody.kt b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/expressions/persistent/PersistentIrExpressionBody.kt index 9bb3540d55a..aed229f8ea3 100644 --- a/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/expressions/persistent/PersistentIrExpressionBody.kt +++ b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/expressions/persistent/PersistentIrExpressionBody.kt @@ -17,40 +17,36 @@ package org.jetbrains.kotlin.ir.expressions.persistent import org.jetbrains.kotlin.ir.declarations.IrDeclaration -import org.jetbrains.kotlin.ir.declarations.IrFactory import org.jetbrains.kotlin.ir.declarations.persistent.PersistentIrBodyBase import org.jetbrains.kotlin.ir.declarations.persistent.PersistentIrFactory import org.jetbrains.kotlin.ir.declarations.persistent.carriers.Carrier -import org.jetbrains.kotlin.ir.declarations.stageController import org.jetbrains.kotlin.ir.expressions.IrExpression import org.jetbrains.kotlin.ir.expressions.IrExpressionBody internal class PersistentIrExpressionBody private constructor( override val startOffset: Int, override val endOffset: Int, + override val factory: PersistentIrFactory, private var expressionField: IrExpression? = null, - override var initializer: (PersistentIrExpressionBody.() -> Unit)? = null + override var initializer: (PersistentIrExpressionBody.() -> Unit)? = null, ) : IrExpressionBody(), PersistentIrBodyBase { - override var lastModified: Int = stageController.currentStage - override var loweredUpTo: Int = stageController.currentStage + override var lastModified: Int = factory.stageController.currentStage + override var loweredUpTo: Int = factory.stageController.currentStage override var values: Array? = null - override val createdOn: Int = stageController.currentStage + override val createdOn: Int = factory.stageController.currentStage override var containerField: IrDeclaration? = null - constructor(expression: IrExpression) : this(expression.startOffset, expression.endOffset, expression, null) + constructor(expression: IrExpression, factory: PersistentIrFactory) : this(expression.startOffset, expression.endOffset, factory, expression, null) - constructor(startOffset: Int, endOffset: Int, expression: IrExpression) : this(startOffset, endOffset, expression, null) + constructor(startOffset: Int, endOffset: Int, expression: IrExpression,factory: PersistentIrFactory) : this(startOffset, endOffset, factory, expression, null) - constructor(startOffset: Int, endOffset: Int, initializer: IrExpressionBody.() -> Unit) : - this(startOffset, endOffset, null, initializer) + constructor(startOffset: Int, endOffset: Int, factory: PersistentIrFactory, initializer: IrExpressionBody.() -> Unit) : + this(startOffset, endOffset, factory, null, initializer) override var expression: IrExpression get() = checkEnabled { expressionField!! } set(e) { checkEnabled { expressionField = e } } - - override val factory: IrFactory - get() = PersistentIrFactory } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrFactory.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrFactory.kt index 2735fa12fc8..3d7b8b93a58 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrFactory.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrFactory.kt @@ -17,6 +17,8 @@ import org.jetbrains.kotlin.serialization.deserialization.descriptors.Deserializ import org.jetbrains.kotlin.types.Variance interface IrFactory { + val stageController: StageController + fun createAnonymousInitializer( startOffset: Int, endOffset: Int, diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/PersistentApi.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/PersistentApi.kt index fa1834ec5d5..423906922db 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/PersistentApi.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/PersistentApi.kt @@ -8,11 +8,6 @@ package org.jetbrains.kotlin.ir.declarations import org.jetbrains.kotlin.ir.IrElement import org.jetbrains.kotlin.ir.expressions.IrBody -// TODO threadlocal -// TODO make a IrDeclarationBase field? (requires IR factory) -var stageController: StageController = StageController() - -// TODO make a class open class StageController(open val currentStage: Int = 0) { open fun lazyLower(declaration: IrDeclaration) {} @@ -33,9 +28,4 @@ open class StageController(open val currentStage: Int = 0) { open fun unrestrictDeclarationListsAccess(fn: () -> T): T = fn() open fun canAccessDeclarationsOf(irClass: IrClass): Boolean = true -} - -@Suppress("NOTHING_TO_INLINE") -inline fun withInitialIr(noinline fn: () -> T): T { - return stageController.withInitialIr(fn) -} +} \ No newline at end of file diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrScriptImpl.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrScriptImpl.kt index f72b8e59e3b..b91e299bd8e 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrScriptImpl.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrScriptImpl.kt @@ -24,7 +24,8 @@ private val SCRIPT_ORIGIN = object : IrDeclarationOriginImpl("SCRIPT") {} class IrScriptImpl( override val symbol: IrScriptSymbol, - override val name: Name + override val name: Name, + override val factory: IrFactory, ) : IrScript() { override val startOffset: Int get() = UNDEFINED_OFFSET override val endOffset: Int get() = UNDEFINED_OFFSET @@ -55,9 +56,6 @@ class IrScriptImpl( override val descriptor: ScriptDescriptor get() = symbol.descriptor - override val factory: IrFactory - get() = error("Create IrScriptImpl directly") - init { symbol.bind(this) } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyTypeAlias.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyTypeAlias.kt index ac2c36ec6af..51fcdb47ed4 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyTypeAlias.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyTypeAlias.kt @@ -44,10 +44,8 @@ class IrLazyTypeAlias( } override var expandedType: IrType by lazyVar { - withInitialIr { - typeTranslator.buildWithScope(this) { - descriptor.expandedType.toIrType() - } + typeTranslator.buildWithScope(this) { + descriptor.expandedType.toIrType() } } } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyTypeParameter.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyTypeParameter.kt index 11be239e09f..ab1c7c2a586 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyTypeParameter.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyTypeParameter.kt @@ -39,11 +39,9 @@ class IrLazyTypeParameter( override var annotations: List by createLazyAnnotations() override var superTypes: List by lazyVar { - withInitialIr { - typeTranslator.buildWithScope(this.parent as IrTypeParametersContainer) { - val descriptor = symbol.descriptor - descriptor.upperBounds.mapTo(arrayListOf()) { it.toIrType() } - } + typeTranslator.buildWithScope(this.parent as IrTypeParametersContainer) { + val descriptor = symbol.descriptor + descriptor.upperBounds.mapTo(arrayListOf()) { it.toIrType() } } } } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/lazyUtil.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/lazyUtil.kt index 39836138eb8..79d9135a90f 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/lazyUtil.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/lazyUtil.kt @@ -5,7 +5,6 @@ package org.jetbrains.kotlin.ir.declarations.lazy -import org.jetbrains.kotlin.ir.declarations.withInitialIr import kotlin.properties.ReadWriteProperty import kotlin.reflect.KProperty @@ -19,7 +18,7 @@ private class UnsafeLazyVar(initializer: () -> T) : ReadWriteProperty scriptCopy.thisReceiver = declaration.thisReceiver.transform() declaration.statements.mapTo(scriptCopy.statements) { it.transform() } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/SymbolTable.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/SymbolTable.kt index 83582141539..d2eb45738d0 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/SymbolTable.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/SymbolTable.kt @@ -362,7 +362,7 @@ class SymbolTable( fun declareScript( descriptor: ScriptDescriptor, scriptFactory: (IrScriptSymbol) -> IrScript = { symbol: IrScriptSymbol -> - IrScriptImpl(symbol, nameProvider.nameForDeclaration(descriptor)) + IrScriptImpl(symbol, nameProvider.nameForDeclaration(descriptor), irFactory) } ): IrScript { return scriptSymbolTable.declare( diff --git a/js/js.tests/test/org/jetbrains/kotlin/benchmarks/GenerateIrRuntime.kt b/js/js.tests/test/org/jetbrains/kotlin/benchmarks/GenerateIrRuntime.kt index d6d220ad8b9..e8b655ecf24 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/benchmarks/GenerateIrRuntime.kt +++ b/js/js.tests/test/org/jetbrains/kotlin/benchmarks/GenerateIrRuntime.kt @@ -447,7 +447,7 @@ class GenerateIrRuntime { private fun doPsi2Ir(files: List, analysisResult: AnalysisResult): IrModuleFragment { val psi2Ir = Psi2IrTranslator(languageVersionSettings, Psi2IrConfiguration()) - val symbolTable = SymbolTable(IdSignatureDescriptor(JsManglerDesc), PersistentIrFactory) + val symbolTable = SymbolTable(IdSignatureDescriptor(JsManglerDesc), PersistentIrFactory()) val psi2IrContext = psi2Ir.createGeneratorContext(analysisResult.moduleDescriptor, analysisResult.bindingContext, symbolTable) val irBuiltIns = psi2IrContext.irBuiltIns @@ -510,7 +510,7 @@ class GenerateIrRuntime { private fun doDeserializeIrModule(moduleDescriptor: ModuleDescriptorImpl): DeserializedModuleInfo { val mangler = JsManglerDesc val signaturer = IdSignatureDescriptor(mangler) - val symbolTable = SymbolTable(signaturer, PersistentIrFactory) + val symbolTable = SymbolTable(signaturer, PersistentIrFactory()) val typeTranslator = TypeTranslator(symbolTable, languageVersionSettings, moduleDescriptor.builtIns).also { it.constantValueGenerator = ConstantValueGenerator(moduleDescriptor, symbolTable) } @@ -539,7 +539,7 @@ class GenerateIrRuntime { val moduleDescriptor = doDeserializeModuleMetadata(moduleRef) val mangler = JsManglerDesc val signaturer = IdSignatureDescriptor(mangler) - val symbolTable = SymbolTable(signaturer, PersistentIrFactory) + val symbolTable = SymbolTable(signaturer, PersistentIrFactory()) val typeTranslator = TypeTranslator(symbolTable, languageVersionSettings, moduleDescriptor.builtIns).also { it.constantValueGenerator = ConstantValueGenerator(moduleDescriptor, symbolTable) } @@ -567,7 +567,7 @@ class GenerateIrRuntime { private fun doBackEnd(module: IrModuleFragment, symbolTable: SymbolTable, irBuiltIns: IrBuiltIns, jsLinker: JsIrLinker): CompilerResult { - val context = JsIrBackendContext(module.descriptor, irBuiltIns, symbolTable, module, emptySet(), configuration) + val context = JsIrBackendContext(module.descriptor, irBuiltIns, symbolTable, module, emptySet(), configuration, irFactory = PersistentIrFactory()) ExternalDependenciesGenerator(symbolTable, listOf(jsLinker)).generateUnboundSymbolsAsDependencies() diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicIrBoxTest.kt b/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicIrBoxTest.kt index 8456dbd2f6e..3d72e268468 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicIrBoxTest.kt +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicIrBoxTest.kt @@ -12,7 +12,7 @@ import org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport import org.jetbrains.kotlin.cli.common.messages.MessageCollector import org.jetbrains.kotlin.cli.js.messageCollectorLogger import org.jetbrains.kotlin.ir.backend.js.* -import org.jetbrains.kotlin.ir.declarations.persistent.PersistentIrFactory +import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl import org.jetbrains.kotlin.js.config.JSConfigurationKeys import org.jetbrains.kotlin.js.config.JsConfig import org.jetbrains.kotlin.js.facade.MainCallParameters @@ -183,7 +183,7 @@ abstract class BasicIrBoxTest( configuration = config.configuration, allDependencies = resolvedLibraries, friendDependencies = emptyList(), - irFactory = PersistentIrFactory, + irFactory = IrFactoryImpl, outputKlibPath = actualOutputFile, nopack = true )