diff --git a/build.gradle.kts b/build.gradle.kts index 01d9181ed5c..5a652ab6b51 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -229,6 +229,7 @@ extra["compilerModules"] = arrayOf( ":compiler:frontend.java", ":compiler:cli-common", ":compiler:ir.tree", + ":compiler:ir.tree.persistent", ":compiler:ir.psi2ir", ":compiler:ir.backend.common", ":compiler:backend.jvm", diff --git a/compiler/cli/cli-js-klib/build.gradle.kts b/compiler/cli/cli-js-klib/build.gradle.kts index 95459ea60cf..f1fa227487d 100644 --- a/compiler/cli/cli-js-klib/build.gradle.kts +++ b/compiler/cli/cli-js-klib/build.gradle.kts @@ -6,6 +6,7 @@ plugins { dependencies { compile(project(":compiler:cli")) compile(project(":compiler:ir.serialization.js")) + compileOnly(project(":compiler:ir.tree.persistent")) runtimeOnly(project(":kotlin-reflect")) if (Platform[193].orLower()) { compile(intellijDep()) { includeJars("picocontainer", rootProject = rootProject) } diff --git a/compiler/cli/cli-js-klib/src/GenerateJsIrKlib.kt b/compiler/cli/cli-js-klib/src/GenerateJsIrKlib.kt index 563083446a8..b174de5c487 100644 --- a/compiler/cli/cli-js-klib/src/GenerateJsIrKlib.kt +++ b/compiler/cli/cli-js-klib/src/GenerateJsIrKlib.kt @@ -16,7 +16,7 @@ import org.jetbrains.kotlin.cli.common.messages.* import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment import org.jetbrains.kotlin.config.* -import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl +import org.jetbrains.kotlin.ir.declarations.persistent.PersistentIrFactory import org.jetbrains.kotlin.js.config.JSConfigurationKeys import org.jetbrains.kotlin.library.resolver.KotlinLibraryResolveResult import org.jetbrains.kotlin.psi.KtFile @@ -88,7 +88,7 @@ fun buildKLib( configuration = configuration, allDependencies = allDependencies, friendDependencies = emptyList(), - irFactory = IrFactoryImpl, + irFactory = PersistentIrFactory, 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 4873452f092..012c1dd2221 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 @@ -34,7 +34,7 @@ import org.jetbrains.kotlin.incremental.js.IncrementalDataProvider import org.jetbrains.kotlin.incremental.js.IncrementalNextRoundChecker import org.jetbrains.kotlin.incremental.js.IncrementalResultsConsumer import org.jetbrains.kotlin.ir.backend.js.* -import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl +import org.jetbrains.kotlin.ir.declarations.persistent.PersistentIrFactory import org.jetbrains.kotlin.js.config.EcmaVersion import org.jetbrains.kotlin.js.config.JSConfigurationKeys import org.jetbrains.kotlin.js.config.JsConfig @@ -197,7 +197,7 @@ class K2JsIrCompiler : CLICompiler() { configuration = config.configuration, allDependencies = resolvedLibraries, friendDependencies = friendDependencies, - irFactory = IrFactoryImpl, + irFactory = PersistentIrFactory, outputKlibPath = outputKlibPath, nopack = arguments.irProduceKlibDir ) diff --git a/compiler/ir/backend.js/build.gradle.kts b/compiler/ir/backend.js/build.gradle.kts index 046b692db67..75b5b825be1 100644 --- a/compiler/ir/backend.js/build.gradle.kts +++ b/compiler/ir/backend.js/build.gradle.kts @@ -12,6 +12,7 @@ dependencies { compile(project(":compiler:ir.backend.common")) compile(project(":compiler:ir.serialization.common")) compile(project(":compiler:ir.serialization.js")) + compile(project(":compiler:ir.tree.persistent")) compile(project(":js:js.ast")) compile(project(":js:js.frontend")) @@ -22,4 +23,3 @@ sourceSets { "main" { projectDefault() } "test" {} } - 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 e8870b80643..b4c894f6b64 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 @@ -20,8 +20,8 @@ import org.jetbrains.kotlin.ir.backend.js.utils.OperatorNames import org.jetbrains.kotlin.ir.builders.declarations.addFunction import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.declarations.impl.IrExternalPackageFragmentImpl -import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl import org.jetbrains.kotlin.ir.declarations.impl.IrFileImpl +import org.jetbrains.kotlin.ir.declarations.persistent.PersistentIrFactory import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns import org.jetbrains.kotlin.ir.symbols.* import org.jetbrains.kotlin.ir.types.* @@ -55,7 +55,7 @@ class JsIrBackendContext( override var inVerbosePhase: Boolean = false - override val irFactory: IrFactory = IrFactoryImpl + override val irFactory: IrFactory = PersistentIrFactory val devMode = configuration[JSConfigurationKeys.DEVELOPER_MODE] ?: false diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/MutableController.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/MutableController.kt index da4e7b949ff..1bc3b9710bd 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/MutableController.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/MutableController.kt @@ -8,8 +8,8 @@ package org.jetbrains.kotlin.ir.backend.js import org.jetbrains.kotlin.descriptors.Visibilities import org.jetbrains.kotlin.ir.IrElement import org.jetbrains.kotlin.ir.declarations.* -import org.jetbrains.kotlin.ir.declarations.impl.IrBodyBase -import org.jetbrains.kotlin.ir.declarations.impl.IrDeclarationBase +import org.jetbrains.kotlin.ir.declarations.persistent.PersistentIrBodyBase +import org.jetbrains.kotlin.ir.declarations.persistent.PersistentIrDeclarationBase import org.jetbrains.kotlin.ir.expressions.IrBody import org.jetbrains.kotlin.ir.util.isLocal @@ -18,7 +18,7 @@ open class MutableController(val context: JsIrBackendContext, val lowerings: Lis override var currentStage: Int = 0 override fun lazyLower(declaration: IrDeclaration) { - if (declaration is IrDeclarationBase<*>) { + if (declaration is PersistentIrDeclarationBase<*>) { while (declaration.loweredUpTo + 1 < currentStage) { val i = declaration.loweredUpTo + 1 withStage(i) { @@ -44,7 +44,7 @@ open class MutableController(val context: JsIrBackendContext, val lowerings: Lis } override fun lazyLower(body: IrBody) { - if (body is IrBodyBase<*>) { + if (body is PersistentIrBodyBase<*>) { for (i in (body.loweredUpTo + 1) until currentStage) { withStage(i) { if (body.container !in context.externalDeclarations) { @@ -63,7 +63,7 @@ open class MutableController(val context: JsIrBackendContext, val lowerings: Lis } // Launches a lowering and applies it's results - private fun DeclarationLowering.doApplyLoweringTo(declaration: IrDeclarationBase<*>) { + private fun DeclarationLowering.doApplyLoweringTo(declaration: PersistentIrDeclarationBase<*>) { val parentBefore = declaration.parent val result = restrictTo(declaration) { this.declarationTransformer(context).transformFlat(declaration) } if (result != null) { @@ -184,4 +184,4 @@ open class MutableController(val context: JsIrBackendContext, val lowerings: Lis declarationListsRestricted = wereDeclarationListsRestricted } } -} \ No newline at end of file +} 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 11ba0610578..bf466560798 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 @@ -17,7 +17,7 @@ import org.jetbrains.kotlin.ir.backend.js.transformers.irToJs.IrModuleToJsTransf import org.jetbrains.kotlin.ir.backend.js.utils.NameTables 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 @@ -53,7 +53,7 @@ fun compile( stageController = StageController() val (moduleFragment: IrModuleFragment, dependencyModules, irBuiltIns, symbolTable, deserializer) = - loadIr(project, mainModule, analyzer, configuration, allDependencies, friendDependencies, IrFactoryImpl) + loadIr(project, mainModule, analyzer, configuration, allDependencies, friendDependencies, PersistentIrFactory) val moduleDescriptor = moduleFragment.descriptor 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 9bb7f47ea8b..065bf942167 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 @@ -18,7 +18,7 @@ import org.jetbrains.kotlin.ir.backend.js.JsSharedVariablesManager import org.jetbrains.kotlin.ir.backend.js.lower.JsInnerClassesSupport import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.declarations.impl.IrExternalPackageFragmentImpl -import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl +import org.jetbrains.kotlin.ir.declarations.persistent.PersistentIrFactory import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns import org.jetbrains.kotlin.ir.symbols.IrClassSymbol import org.jetbrains.kotlin.ir.symbols.IrExternalPackageFragmentSymbol @@ -42,7 +42,7 @@ class WasmBackendContext( override val transformedFunction = mutableMapOf() override val lateinitNullableFields = mutableMapOf() override val extractedLocalClasses: MutableSet = hashSetOf() - override val irFactory: IrFactory = IrFactoryImpl + override val irFactory: IrFactory = PersistentIrFactory // Place to store declarations excluded from code generation val excludedDeclarations: IrPackageFragment by lazy { diff --git a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/compiler.kt b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/compiler.kt index c0b6fd86102..968eb6635ef 100644 --- a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/compiler.kt +++ b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/compiler.kt @@ -14,7 +14,7 @@ import org.jetbrains.kotlin.config.CompilerConfiguration import org.jetbrains.kotlin.config.languageVersionSettings import org.jetbrains.kotlin.ir.backend.js.MainModule import org.jetbrains.kotlin.ir.backend.js.loadIr -import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl +import org.jetbrains.kotlin.ir.declarations.persistent.PersistentIrFactory import org.jetbrains.kotlin.ir.util.ExternalDependenciesGenerator import org.jetbrains.kotlin.ir.util.generateTypicalIrProviderList import org.jetbrains.kotlin.ir.util.patchDeclarationParents @@ -37,7 +37,8 @@ fun compileWasm( ): WasmCompilerResult { val (moduleFragment, dependencyModules, irBuiltIns, symbolTable, deserializer) = loadIr( - project, MainModule.SourceFiles(files), analyzer, configuration, allDependencies, friendDependencies, IrFactoryImpl + project, MainModule.SourceFiles(files), analyzer, configuration, allDependencies, friendDependencies, + PersistentIrFactory ) val moduleDescriptor = moduleFragment.descriptor diff --git a/compiler/ir/ir.tree.persistent/build.gradle.kts b/compiler/ir/ir.tree.persistent/build.gradle.kts new file mode 100644 index 00000000000..c4a6e3034f2 --- /dev/null +++ b/compiler/ir/ir.tree.persistent/build.gradle.kts @@ -0,0 +1,13 @@ +plugins { + kotlin("jvm") + id("jps-compatible") +} + +dependencies { + compileOnly(project(":compiler:ir.tree")) +} + +sourceSets { + "main" { projectDefault() } + "test" {} +} diff --git a/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrAnonymousInitializer.kt b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrAnonymousInitializer.kt new file mode 100644 index 00000000000..6f2ff5d336d --- /dev/null +++ b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrAnonymousInitializer.kt @@ -0,0 +1,57 @@ +/* + * Copyright 2010-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.ir.declarations.persistent + +import org.jetbrains.kotlin.descriptors.ClassDescriptor +import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI +import org.jetbrains.kotlin.ir.declarations.IrAnonymousInitializer +import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin +import org.jetbrains.kotlin.ir.declarations.persistent.carriers.AnonymousInitializerCarrier +import org.jetbrains.kotlin.ir.expressions.IrBlockBody +import org.jetbrains.kotlin.ir.symbols.IrAnonymousInitializerSymbol + +class PersistentIrAnonymousInitializer( + startOffset: Int, + endOffset: Int, + origin: IrDeclarationOrigin, + override val symbol: IrAnonymousInitializerSymbol, + override val isStatic: Boolean = false +) : PersistentIrDeclarationBase(startOffset, endOffset, origin), + IrAnonymousInitializer, + AnonymousInitializerCarrier { + + init { + symbol.bind(this) + } + + @ObsoleteDescriptorBasedAPI + override val descriptor: ClassDescriptor + get() = symbol.descriptor + + override var bodyField: IrBlockBody? = null + + override var body: IrBlockBody + get() = getCarrier().bodyField!! + set(v) { + if (getCarrier().bodyField !== v) { + if (v is PersistentIrBodyBase<*>) { + v.container = this + } + setCarrier().bodyField = v + } + } +} diff --git a/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrClass.kt b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrClass.kt new file mode 100644 index 00000000000..ee1608df2a4 --- /dev/null +++ b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrClass.kt @@ -0,0 +1,143 @@ +/* + * Copyright 2010-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.ir.declarations.persistent + +import org.jetbrains.kotlin.descriptors.* +import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI +import org.jetbrains.kotlin.ir.declarations.* +import org.jetbrains.kotlin.ir.declarations.persistent.carriers.ClassCarrier +import org.jetbrains.kotlin.ir.symbols.IrClassSymbol +import org.jetbrains.kotlin.ir.types.IrType +import org.jetbrains.kotlin.name.Name +import java.util.* + +class PersistentIrClass( + startOffset: Int, + endOffset: Int, + origin: IrDeclarationOrigin, + override val symbol: IrClassSymbol, + override val name: Name, + override val kind: ClassKind, + visibility: Visibility, + modality: Modality, + override val isCompanion: Boolean = false, + override val isInner: Boolean = false, + override val isData: Boolean = false, + override val isExternal: Boolean = false, + override val isInline: Boolean = false, + override val isExpect: Boolean = false, + override val isFun: Boolean = false, + override val source: SourceElement = SourceElement.NO_SOURCE +) : + PersistentIrDeclarationBase(startOffset, endOffset, origin), + IrClass, + ClassCarrier { + + init { + symbol.bind(this) + } + + @ObsoleteDescriptorBasedAPI + override val descriptor: ClassDescriptor + get() = symbol.descriptor + + override var visibilityField: Visibility = visibility + + override var visibility: Visibility + get() = getCarrier().visibilityField + set(v) { + if (visibility !== v) { + setCarrier().visibilityField = v + } + } + + override var thisReceiverField: IrValueParameter? = null + + override var thisReceiver: IrValueParameter? + get() = getCarrier().thisReceiverField + set(v) { + if (thisReceiver !== v) { + setCarrier().thisReceiverField = v + } + } + + private var initialDeclarations: MutableList? = null + + override val declarations: MutableList = ArrayList() + get() { + if (createdOn < stageController.currentStage && initialDeclarations == null) { + initialDeclarations = Collections.unmodifiableList(ArrayList(field)) + } + + return if (stageController.canAccessDeclarationsOf(this)) { + ensureLowered() + field + } else { + initialDeclarations ?: field + } + } + + override var typeParametersField: List = emptyList() + + override var typeParameters: List + get() = getCarrier().typeParametersField + set(v) { + if (typeParameters !== v) { + setCarrier().typeParametersField = v + } + } + + override var superTypesField: List = emptyList() + + override var superTypes: List + get() = getCarrier().superTypesField + set(v) { + if (superTypes !== v) { + setCarrier().superTypesField = v + } + } + + override var metadataField: MetadataSource? = null + + override var metadata: MetadataSource? + get() = getCarrier().metadataField + set(v) { + if (metadata !== v) { + setCarrier().metadataField = v + } + } + + override var modalityField: Modality = modality + + override var modality: Modality + get() = getCarrier().modalityField + set(v) { + if (modality !== v) { + setCarrier().modalityField = v + } + } + + override var attributeOwnerIdField: IrAttributeContainer = this + + override var attributeOwnerId: IrAttributeContainer + get() = getCarrier().attributeOwnerIdField + set(v) { + if (attributeOwnerId !== v) { + setCarrier().attributeOwnerIdField = v + } + } +} diff --git a/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrConstructor.kt b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrConstructor.kt new file mode 100644 index 00000000000..0a002f06202 --- /dev/null +++ b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrConstructor.kt @@ -0,0 +1,58 @@ +/* + * Copyright 2010-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.ir.declarations.persistent + +import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor +import org.jetbrains.kotlin.descriptors.Visibility +import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI +import org.jetbrains.kotlin.ir.declarations.IrConstructor +import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin +import org.jetbrains.kotlin.ir.declarations.persistent.carriers.ConstructorCarrier +import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol +import org.jetbrains.kotlin.ir.types.IrType +import org.jetbrains.kotlin.name.Name + +class PersistentIrConstructor( + startOffset: Int, + endOffset: Int, + origin: IrDeclarationOrigin, + override val symbol: IrConstructorSymbol, + name: Name, + visibility: Visibility, + returnType: IrType, + isInline: Boolean, + isExternal: Boolean, + override val isPrimary: Boolean, + isExpect: Boolean +) : + PersistentIrFunctionBase( + startOffset, endOffset, origin, name, + visibility, + isInline, isExternal, isExpect, + returnType + ), + IrConstructor, + ConstructorCarrier { + + init { + symbol.bind(this) + } + + @ObsoleteDescriptorBasedAPI + override val descriptor: ClassConstructorDescriptor + get() = symbol.descriptor +} 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 new file mode 100644 index 00000000000..ec7029da4a6 --- /dev/null +++ b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrDeclarationBase.kt @@ -0,0 +1,188 @@ +/* + * Copyright 2010-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.ir.declarations.persistent + +import org.jetbrains.kotlin.ir.IrElementBase +import org.jetbrains.kotlin.ir.declarations.* +import org.jetbrains.kotlin.ir.declarations.persistent.carriers.BodyCarrier +import org.jetbrains.kotlin.ir.declarations.persistent.carriers.Carrier +import org.jetbrains.kotlin.ir.declarations.persistent.carriers.DeclarationCarrier +import org.jetbrains.kotlin.ir.expressions.IrBody +import org.jetbrains.kotlin.ir.expressions.IrConstructorCall + +abstract class PersistentIrDeclarationBase( + startOffset: Int, + endOffset: Int, + origin: IrDeclarationOrigin +) : PersistentIrElementBase(startOffset, endOffset), + IrDeclaration, + DeclarationCarrier { + + override val factory: IrFactory + get() = PersistentIrFactory + + override var parentField: IrDeclarationParent? = null + + // TODO reduce boilerplate + override var parent: IrDeclarationParent + get() = getCarrier().parentField ?: throw UninitializedPropertyAccessException("Parent not initialized: $this") + set(p) { + if (getCarrier().parentField !== p) { + setCarrier().parentField = p + } + } + + override var originField: IrDeclarationOrigin = origin + + override var origin: IrDeclarationOrigin + get() = getCarrier().originField + set(p) { + if (getCarrier().originField !== p) { + setCarrier().originField = p + } + } + + var removedOn: Int = Int.MAX_VALUE + + override var annotationsField: List = emptyList() + + override var annotations: List + get() = getCarrier().annotationsField + set(v) { + if (getCarrier().annotationsField !== v) { + setCarrier().annotationsField = v + } + } + + override fun ensureLowered() { + if (stageController.currentStage > loweredUpTo) { + stageController.lazyLower(this) + } + } +} + +@Suppress("UNCHECKED_CAST") +abstract class PersistentIrElementBase( + startOffset: Int, + endOffset: Int +) : IrElementBase(startOffset, endOffset), + Carrier { + + override var lastModified: Int = stageController.currentStage + + var loweredUpTo = stageController.currentStage + + // TODO Array? + private var values: Array? = null + + val createdOn: Int = stageController.currentStage +// get() = values?.let { (it[0] as T).lastModified } ?: lastModified + + abstract fun ensureLowered() + + protected fun getCarrier(): T { + stageController.currentStage.let { stage -> + ensureLowered() + + if (stage >= lastModified) return this as T + + if (stage < createdOn) error("Access before creation") + + val v = values + ?: error("How come?") + + var l = -1 + var r = v.size + while (r - l > 1) { + val m = (l + r) / 2 + if ((v[m] as T).lastModified <= stage) { + l = m + } else { + r = m + } + } + if (l < 0) { + error("access before creation") + } + + return v[l] as T + } + } + + // TODO naming? e.g. `mutableCarrier` + protected fun setCarrier(): T { + val stage = stageController.currentStage + + ensureLowered() + + if (!stageController.canModify(this)) { + error("Cannot modify this element!") + } + + if (loweredUpTo > stage) { + error("retrospective modification") + } + + // TODO move up? i.e. fast path + if (stage == lastModified) { + return this as T + } else { + values = (values ?: emptyArray()) + this.clone() as T + } + + this.lastModified = stage + + return this as T + } +} + +abstract class PersistentIrBodyBase>( + startOffset: Int, + endOffset: Int, + private var initializer: (B.() -> Unit)? +) : PersistentIrElementBase(startOffset, endOffset), IrBody, BodyCarrier { + override var containerField: IrDeclaration? = null + + var container: IrDeclaration + get() = getCarrier().containerField!! + set(p) { + if (getCarrier().containerField !== p) { + setCarrier().containerField = p + } + } + + protected fun checkEnabled(fn: () -> T): T { + if (!stageController.bodiesEnabled) error("Bodies disabled!") + ensureLowered() + return fn() + } + + @Suppress("UNCHECKED_CAST") + override fun ensureLowered() { + initializer?.let { initFn -> + initializer = null + stageController.withStage(createdOn) { + stageController.bodyLowering { + initFn.invoke(this as B) + } + } + } + if (loweredUpTo + 1 < stageController.currentStage) { + stageController.lazyLower(this) + } + } +} diff --git a/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrEnumEntry.kt b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrEnumEntry.kt new file mode 100644 index 00000000000..ff86895819e --- /dev/null +++ b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrEnumEntry.kt @@ -0,0 +1,69 @@ +/* + * Copyright 2010-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.ir.declarations.persistent + +import org.jetbrains.kotlin.descriptors.ClassDescriptor +import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI +import org.jetbrains.kotlin.ir.declarations.IrClass +import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin +import org.jetbrains.kotlin.ir.declarations.IrEnumEntry +import org.jetbrains.kotlin.ir.declarations.persistent.carriers.EnumEntryCarrier +import org.jetbrains.kotlin.ir.expressions.IrExpressionBody +import org.jetbrains.kotlin.ir.symbols.IrEnumEntrySymbol +import org.jetbrains.kotlin.name.Name + +class PersistentIrEnumEntry( + startOffset: Int, + endOffset: Int, + origin: IrDeclarationOrigin, + override val symbol: IrEnumEntrySymbol, + override val name: Name +) : PersistentIrDeclarationBase(startOffset, endOffset, origin), + IrEnumEntry, + EnumEntryCarrier { + + init { + symbol.bind(this) + } + + @ObsoleteDescriptorBasedAPI + override val descriptor: ClassDescriptor + get() = symbol.descriptor + + override var correspondingClassField: IrClass? = null + + override var correspondingClass: IrClass? + get() = getCarrier().correspondingClassField + set(v) { + if (correspondingClass !== v) { + setCarrier().correspondingClassField = v + } + } + + override var initializerExpressionField: IrExpressionBody? = null + + override var initializerExpression: IrExpressionBody? + get() = getCarrier().initializerExpressionField + set(v) { + if (initializerExpression !== v) { + if (v is PersistentIrBodyBase<*>) { + v.container = this + } + setCarrier().initializerExpressionField = v + } + } +} diff --git a/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrErrorDeclaration.kt b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrErrorDeclaration.kt new file mode 100644 index 00000000000..89b5225fb40 --- /dev/null +++ b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrErrorDeclaration.kt @@ -0,0 +1,30 @@ +/* + * Copyright 2010-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.ir.declarations.persistent + +import org.jetbrains.kotlin.descriptors.DeclarationDescriptor +import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI +import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin +import org.jetbrains.kotlin.ir.declarations.IrErrorDeclaration +import org.jetbrains.kotlin.ir.declarations.persistent.carriers.ErrorCarrier + +@OptIn(ObsoleteDescriptorBasedAPI::class) +class PersistentIrErrorDeclaration( + startOffset: Int, + endOffset: Int, + override val descriptor: DeclarationDescriptor +) : PersistentIrDeclarationBase(startOffset, endOffset, IrDeclarationOrigin.DEFINED), IrErrorDeclaration, ErrorCarrier 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 new file mode 100644 index 00000000000..f7d7566a0c5 --- /dev/null +++ b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrFactory.kt @@ -0,0 +1,274 @@ +/* + * Copyright 2010-2020 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.declarations.persistent + +import org.jetbrains.kotlin.descriptors.* +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.IrExpression +import org.jetbrains.kotlin.ir.expressions.IrExpressionBody +import org.jetbrains.kotlin.ir.expressions.persistent.PersistentIrBlockBody +import org.jetbrains.kotlin.ir.expressions.persistent.PersistentIrExpressionBody +import org.jetbrains.kotlin.ir.symbols.* +import org.jetbrains.kotlin.ir.types.IrType +import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.types.Variance + +object PersistentIrFactory : IrFactory { + override fun createAnonymousInitializer( + startOffset: Int, + endOffset: Int, + origin: IrDeclarationOrigin, + symbol: IrAnonymousInitializerSymbol, + isStatic: Boolean, + ): IrAnonymousInitializer = + PersistentIrAnonymousInitializer(startOffset, endOffset, origin, symbol, isStatic) + + override fun createClass( + startOffset: Int, + endOffset: Int, + origin: IrDeclarationOrigin, + symbol: IrClassSymbol, + name: Name, + kind: ClassKind, + visibility: Visibility, + modality: Modality, + isCompanion: Boolean, + isInner: Boolean, + isData: Boolean, + isExternal: Boolean, + isInline: Boolean, + isExpect: Boolean, + isFun: Boolean, + source: SourceElement, + ): IrClass = + PersistentIrClass( + startOffset, endOffset, origin, symbol, name, kind, visibility, modality, + isCompanion, isInner, isData, isExternal, isInline, isExpect, isFun, source, + ) + + override fun createConstructor( + startOffset: Int, + endOffset: Int, + origin: IrDeclarationOrigin, + symbol: IrConstructorSymbol, + name: Name, + visibility: Visibility, + returnType: IrType, + isInline: Boolean, + isExternal: Boolean, + isPrimary: Boolean, + isExpect: Boolean, + ): IrConstructor = + PersistentIrConstructor( + startOffset, endOffset, origin, symbol, name, visibility, returnType, isInline, isExternal, isPrimary, isExpect + ) + + override fun createEnumEntry( + startOffset: Int, + endOffset: Int, + origin: IrDeclarationOrigin, + symbol: IrEnumEntrySymbol, + name: Name, + ): IrEnumEntry = + PersistentIrEnumEntry(startOffset, endOffset, origin, symbol, name) + + override fun createErrorDeclaration( + startOffset: Int, + endOffset: Int, + descriptor: DeclarationDescriptor, + ): IrErrorDeclaration = + PersistentIrErrorDeclaration(startOffset, endOffset, descriptor) + + override fun createField( + startOffset: Int, + endOffset: Int, + origin: IrDeclarationOrigin, + symbol: IrFieldSymbol, + name: Name, + type: IrType, + visibility: Visibility, + isFinal: Boolean, + isExternal: Boolean, + isStatic: Boolean, + ): IrField = + PersistentIrField(startOffset, endOffset, origin, symbol, name, type, visibility, isFinal, isExternal, isStatic) + + override fun createFunction( + startOffset: Int, + endOffset: Int, + origin: IrDeclarationOrigin, + symbol: IrSimpleFunctionSymbol, + name: Name, + visibility: Visibility, + modality: Modality, + returnType: IrType, + isInline: Boolean, + isExternal: Boolean, + isTailrec: Boolean, + isSuspend: Boolean, + isOperator: Boolean, + isInfix: Boolean, + isExpect: Boolean, + isFakeOverride: Boolean, + ): IrSimpleFunction = + PersistentIrFunction( + startOffset, endOffset, origin, symbol, name, visibility, modality, returnType, + isInline, isExternal, isTailrec, isSuspend, isOperator, isInfix, isExpect, isFakeOverride, + ) + + override fun createFakeOverrideFunction( + startOffset: Int, + endOffset: Int, + origin: IrDeclarationOrigin, + name: Name, + visibility: Visibility, + modality: Modality, + returnType: IrType, + isInline: Boolean, + isExternal: Boolean, + isTailrec: Boolean, + isSuspend: Boolean, + isOperator: Boolean, + isInfix: Boolean, + isExpect: Boolean, + ): IrSimpleFunction = + PersistentIrFakeOverrideFunction( + startOffset, endOffset, origin, name, visibility, modality, returnType, + isInline, isExternal, isTailrec, isSuspend, isOperator, isInfix, isExpect, + ) + + override fun createLocalDelegatedProperty( + startOffset: Int, + endOffset: Int, + origin: IrDeclarationOrigin, + symbol: IrLocalDelegatedPropertySymbol, + name: Name, + type: IrType, + isVar: Boolean, + ): IrLocalDelegatedProperty = + PersistentIrLocalDelegatedProperty( + startOffset, endOffset, origin, symbol, name, type, isVar + ) + + override fun createProperty( + startOffset: Int, + endOffset: Int, + origin: IrDeclarationOrigin, + symbol: IrPropertySymbol, + name: Name, + visibility: Visibility, + modality: Modality, + isVar: Boolean, + isConst: Boolean, + isLateinit: Boolean, + isDelegated: Boolean, + isExternal: Boolean, + isExpect: Boolean, + isFakeOverride: Boolean, + ): IrProperty = + PersistentIrProperty( + startOffset, endOffset, origin, symbol, name, visibility, modality, + isVar, isConst, isLateinit, isDelegated, isExternal, isExpect, isFakeOverride, + ) + + override fun createFakeOverrideProperty( + startOffset: Int, + endOffset: Int, + origin: IrDeclarationOrigin, + name: Name, + visibility: Visibility, + modality: Modality, + isVar: Boolean, + isConst: Boolean, + isLateinit: Boolean, + isDelegated: Boolean, + isExternal: Boolean, + isExpect: Boolean, + ): IrFakeOverrideProperty = + PersistentIrFakeOverrideProperty( + startOffset, endOffset, origin, name, visibility, modality, + isVar, isConst, isLateinit, isDelegated, isExternal, isExpect, + ) + + override fun createTypeAlias( + startOffset: Int, + endOffset: Int, + symbol: IrTypeAliasSymbol, + name: Name, + visibility: Visibility, + expandedType: IrType, + isActual: Boolean, + origin: IrDeclarationOrigin, + ): IrTypeAlias = + PersistentIrTypeAlias(startOffset, endOffset, symbol, name, visibility, expandedType, isActual, origin) + + override fun createTypeParameter( + startOffset: Int, + endOffset: Int, + origin: IrDeclarationOrigin, + symbol: IrTypeParameterSymbol, + name: Name, + index: Int, + isReified: Boolean, + variance: Variance, + ): IrTypeParameter = + PersistentIrTypeParameter(startOffset, endOffset, origin, symbol, name, index, isReified, variance) + + override fun createValueParameter( + startOffset: Int, + endOffset: Int, + origin: IrDeclarationOrigin, + symbol: IrValueParameterSymbol, + name: Name, + index: Int, + type: IrType, + varargElementType: IrType?, + isCrossinline: Boolean, + isNoinline: Boolean, + ): IrValueParameter = + PersistentIrValueParameter(startOffset, endOffset, origin, symbol, name, index, type, varargElementType, isCrossinline, isNoinline) + + override fun createExpressionBody( + startOffset: Int, + endOffset: Int, + initializer: IrExpressionBody.() -> Unit, + ): IrExpressionBody = + PersistentIrExpressionBody(startOffset, endOffset, initializer) + + override fun createExpressionBody( + startOffset: Int, + endOffset: Int, + expression: IrExpression, + ): IrExpressionBody = + PersistentIrExpressionBody(startOffset, endOffset, expression) + + override fun createExpressionBody( + expression: IrExpression, + ): IrExpressionBody = + PersistentIrExpressionBody(expression) + + override fun createBlockBody( + startOffset: Int, + endOffset: Int, + ): IrBlockBody = + PersistentIrBlockBody(startOffset, endOffset) + + override fun createBlockBody( + startOffset: Int, + endOffset: Int, + statements: List, + ): IrBlockBody = + PersistentIrBlockBody(startOffset, endOffset, statements) + + override fun createBlockBody( + startOffset: Int, + endOffset: Int, + initializer: IrBlockBody.() -> Unit, + ): IrBlockBody = + PersistentIrBlockBody(startOffset, endOffset, initializer) +} diff --git a/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrField.kt b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrField.kt new file mode 100644 index 00000000000..9df5c79a639 --- /dev/null +++ b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrField.kt @@ -0,0 +1,87 @@ +/* + * Copyright 2010-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.ir.declarations.persistent + +import org.jetbrains.kotlin.descriptors.PropertyDescriptor +import org.jetbrains.kotlin.descriptors.Visibility +import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI +import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin +import org.jetbrains.kotlin.ir.declarations.IrField +import org.jetbrains.kotlin.ir.declarations.MetadataSource +import org.jetbrains.kotlin.ir.declarations.persistent.carriers.FieldCarrier +import org.jetbrains.kotlin.ir.expressions.IrExpressionBody +import org.jetbrains.kotlin.ir.symbols.IrFieldSymbol +import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol +import org.jetbrains.kotlin.ir.types.IrType +import org.jetbrains.kotlin.name.Name + +class PersistentIrField( + startOffset: Int, + endOffset: Int, + origin: IrDeclarationOrigin, + override val symbol: IrFieldSymbol, + override val name: Name, + override val type: IrType, + override var visibility: Visibility, + override val isFinal: Boolean, + override val isExternal: Boolean, + override val isStatic: Boolean +) : PersistentIrDeclarationBase(startOffset, endOffset, origin), + IrField, + FieldCarrier { + + init { + symbol.bind(this) + } + + @ObsoleteDescriptorBasedAPI + override val descriptor: PropertyDescriptor + get() = symbol.descriptor + + override var initializerField: IrExpressionBody? = null + + override var initializer: IrExpressionBody? + get() = getCarrier().initializerField + set(v) { + if (initializer !== v) { + if (v is PersistentIrBodyBase<*>) { + v.container = this + } + setCarrier().initializerField = v + } + } + + override var correspondingPropertySymbolField: IrPropertySymbol? = null + + override var correspondingPropertySymbol: IrPropertySymbol? + get() = getCarrier().correspondingPropertySymbolField + set(v) { + if (correspondingPropertySymbol !== v) { + setCarrier().correspondingPropertySymbolField = v + } + } + + override var metadataField: MetadataSource? = null + + override var metadata: MetadataSource? + get() = getCarrier().metadataField + set(v) { + if (metadata !== v) { + setCarrier().metadataField = v + } + } +} 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 new file mode 100644 index 00000000000..9793d95e4fa --- /dev/null +++ b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrFunction.kt @@ -0,0 +1,142 @@ +/* + * Copyright 2010-2019 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.declarations.persistent + +import org.jetbrains.kotlin.descriptors.FunctionDescriptor +import org.jetbrains.kotlin.descriptors.Modality +import org.jetbrains.kotlin.descriptors.Visibility +import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI +import org.jetbrains.kotlin.ir.declarations.IrAttributeContainer +import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin +import org.jetbrains.kotlin.ir.declarations.IrFakeOverrideFunction +import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction +import org.jetbrains.kotlin.ir.declarations.persistent.carriers.FunctionCarrier +import org.jetbrains.kotlin.ir.descriptors.WrappedSimpleFunctionDescriptor +import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol +import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol +import org.jetbrains.kotlin.ir.types.IrType +import org.jetbrains.kotlin.name.Name + +abstract class PersistentIrFunctionCommon( + startOffset: Int, + endOffset: Int, + origin: IrDeclarationOrigin, + name: Name, + visibility: Visibility, + returnType: IrType, + isInline: Boolean, + isExternal: Boolean, + override val isTailrec: Boolean, + override val isSuspend: Boolean, + override val isOperator: Boolean, + override val isInfix: Boolean, + isExpect: Boolean, +) : + PersistentIrFunctionBase(startOffset, endOffset, origin, name, visibility, isInline, isExternal, isExpect, returnType), + IrSimpleFunction, + FunctionCarrier { + + override var overriddenSymbolsField: List = emptyList() + + override var overriddenSymbols: List + get() = getCarrier().overriddenSymbolsField + set(v) { + if (overriddenSymbols !== v) { + setCarrier().overriddenSymbolsField = v + } + } + + @Suppress("LeakingThis") + override var attributeOwnerIdField: IrAttributeContainer = this + + override var attributeOwnerId: IrAttributeContainer + get() = getCarrier().attributeOwnerIdField + set(v) { + if (attributeOwnerId !== v) { + setCarrier().attributeOwnerIdField = v + } + } + + override var correspondingPropertySymbolField: IrPropertySymbol? = null + + override var correspondingPropertySymbol: IrPropertySymbol? + get() = getCarrier().correspondingPropertySymbolField + set(v) { + if (correspondingPropertySymbol !== v) { + setCarrier().correspondingPropertySymbolField = v + } + } +} + +class PersistentIrFunction( + startOffset: Int, + endOffset: Int, + origin: IrDeclarationOrigin, + override val symbol: IrSimpleFunctionSymbol, + name: Name, + visibility: Visibility, + override val modality: Modality, + returnType: IrType, + isInline: Boolean, + isExternal: Boolean, + isTailrec: Boolean, + isSuspend: Boolean, + isOperator: Boolean, + isInfix: Boolean, + isExpect: Boolean, + override val isFakeOverride: Boolean = origin == IrDeclarationOrigin.FAKE_OVERRIDE, +) : PersistentIrFunctionCommon( + startOffset, endOffset, origin, name, visibility, returnType, isInline, + isExternal, isTailrec, isSuspend, isOperator, isInfix, isExpect, +) { + @ObsoleteDescriptorBasedAPI + override val descriptor: FunctionDescriptor + get() = symbol.descriptor + + init { + symbol.bind(this) + } +} + +class PersistentIrFakeOverrideFunction( + startOffset: Int, + endOffset: Int, + origin: IrDeclarationOrigin, + name: Name, + override var visibility: Visibility, + override var modality: Modality, + returnType: IrType, + isInline: Boolean, + isExternal: Boolean, + isTailrec: Boolean, + isSuspend: Boolean, + isOperator: Boolean, + isInfix: Boolean, + isExpect: Boolean, +) : PersistentIrFunctionCommon( + startOffset, endOffset, origin, name, visibility, returnType, isInline, + isExternal, isTailrec, isSuspend, isOperator, isInfix, isExpect, +), IrFakeOverrideFunction { + override val isFakeOverride: Boolean + get() = true + + private var _symbol: IrSimpleFunctionSymbol? = null + + override val symbol: IrSimpleFunctionSymbol + get() = _symbol ?: error("$this has not acquired a symbol yet") + + @ObsoleteDescriptorBasedAPI + override val descriptor + get() = _symbol?.descriptor ?: WrappedSimpleFunctionDescriptor() + + @OptIn(ObsoleteDescriptorBasedAPI::class) + override fun acquireSymbol(symbol: IrSimpleFunctionSymbol) { + assert(_symbol == null) { "$this already has symbol _symbol" } + _symbol = symbol + symbol.bind(this) + (symbol.descriptor as? WrappedSimpleFunctionDescriptor)?.bind(this) + } +} diff --git a/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrFunctionBase.kt b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrFunctionBase.kt new file mode 100644 index 00000000000..02de7db485f --- /dev/null +++ b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrFunctionBase.kt @@ -0,0 +1,132 @@ +/* + * Copyright 2010-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.ir.declarations.persistent + +import org.jetbrains.kotlin.descriptors.Visibility +import org.jetbrains.kotlin.ir.declarations.* +import org.jetbrains.kotlin.ir.declarations.persistent.carriers.FunctionBaseCarrier +import org.jetbrains.kotlin.ir.expressions.IrBody +import org.jetbrains.kotlin.ir.types.IrType +import org.jetbrains.kotlin.name.Name + +abstract class PersistentIrFunctionBase( + startOffset: Int, + endOffset: Int, + origin: IrDeclarationOrigin, + override val name: Name, + visibility: Visibility, + override val isInline: Boolean, + override val isExternal: Boolean, + override val isExpect: Boolean, + returnType: IrType +) : + PersistentIrDeclarationBase(startOffset, endOffset, origin), + IrFunction, + FunctionBaseCarrier { + + override var returnTypeFieldField: IrType = returnType + + private var returnTypeField: IrType + get() = getCarrier().returnTypeFieldField + set(v) { + if (returnTypeField !== v) { + setCarrier().returnTypeFieldField = v + } + } + + @Suppress("DEPRECATION") + final override var returnType: IrType + get() = returnTypeField.let { + if (it !== org.jetbrains.kotlin.ir.types.impl.IrUninitializedType) it else error("Return type is not initialized") + } + set(c) { + returnTypeField = c + } + + override var typeParametersField: List = emptyList() + + override var typeParameters: List + get() = getCarrier().typeParametersField + set(v) { + if (typeParameters !== v) { + setCarrier().typeParametersField = v + } + } + + override var dispatchReceiverParameterField: IrValueParameter? = null + + override var dispatchReceiverParameter: IrValueParameter? + get() = getCarrier().dispatchReceiverParameterField + set(v) { + if (dispatchReceiverParameter !== v) { + setCarrier().dispatchReceiverParameterField = v + } + } + + override var extensionReceiverParameterField: IrValueParameter? = null + + override var extensionReceiverParameter: IrValueParameter? + get() = getCarrier().extensionReceiverParameterField + set(v) { + if (extensionReceiverParameter !== v) { + setCarrier().extensionReceiverParameterField = v + } + } + + override var valueParametersField: List = emptyList() + + override var valueParameters: List + get() = getCarrier().valueParametersField + set(v) { + if (valueParameters !== v) { + setCarrier().valueParametersField = v + } + } + + override var bodyField: IrBody? = null + + final override var body: IrBody? + get() = getCarrier().bodyField + set(v) { + if (body !== v) { + if (v is PersistentIrBodyBase<*>) { + v.container = this + } + setCarrier().bodyField = v + } + } + + override var metadataField: MetadataSource? = null + + override var metadata: MetadataSource? + get() = getCarrier().metadataField + set(v) { + if (metadata !== v) { + setCarrier().metadataField = v + } + } + + override var visibilityField: Visibility = visibility + + override var visibility: Visibility + get() = getCarrier().visibilityField + set(v) { + if (visibility !== v) { + setCarrier().visibilityField = v + } + } +} diff --git a/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrLocalDelegatedProperty.kt b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrLocalDelegatedProperty.kt new file mode 100644 index 00000000000..a4eeb3c1ffe --- /dev/null +++ b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrLocalDelegatedProperty.kt @@ -0,0 +1,88 @@ +/* + * Copyright 2010-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.ir.declarations.persistent + +import org.jetbrains.kotlin.descriptors.VariableDescriptorWithAccessors +import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI +import org.jetbrains.kotlin.ir.declarations.* +import org.jetbrains.kotlin.ir.declarations.persistent.carriers.LocalDelegatedPropertyCarrier +import org.jetbrains.kotlin.ir.symbols.IrLocalDelegatedPropertySymbol +import org.jetbrains.kotlin.ir.types.IrType +import org.jetbrains.kotlin.name.Name + +// TODO make not persistent +class PersistentIrLocalDelegatedProperty( + startOffset: Int, + endOffset: Int, + origin: IrDeclarationOrigin, + override val symbol: IrLocalDelegatedPropertySymbol, + override val name: Name, + override val type: IrType, + override val isVar: Boolean +) : + PersistentIrDeclarationBase(startOffset, endOffset, origin), + IrLocalDelegatedProperty, + LocalDelegatedPropertyCarrier { + + init { + symbol.bind(this) + } + + @ObsoleteDescriptorBasedAPI + override val descriptor: VariableDescriptorWithAccessors + get() = symbol.descriptor + + override var delegateField: IrVariable? = null + + override var delegate: IrVariable + get() = getCarrier().delegateField!! + set(v) { + if (getCarrier().delegateField !== v) { + setCarrier().delegateField = v + } + } + + override var getterField: IrFunction? = null + + override var getter: IrFunction + get() = getCarrier().getterField!! + set(v) { + if (getCarrier().getterField !== v) { + setCarrier().getterField = v + } + } + + override var setterField: IrFunction? = null + + override var setter: IrFunction? + get() = getCarrier().setterField + set(v) { + if (setter !== v) { + setCarrier().setterField = v + } + } + + override var metadataField: MetadataSource? = null + + override var metadata: MetadataSource? + get() = getCarrier().metadataField + set(v) { + if (metadata !== v) { + setCarrier().metadataField = v + } + } +} 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 new file mode 100644 index 00000000000..c25eae874b2 --- /dev/null +++ b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrProperty.kt @@ -0,0 +1,149 @@ +/* + * Copyright 2010-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.ir.declarations.persistent + +import org.jetbrains.kotlin.descriptors.Modality +import org.jetbrains.kotlin.descriptors.PropertyDescriptor +import org.jetbrains.kotlin.descriptors.Visibility +import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI +import org.jetbrains.kotlin.ir.declarations.* +import org.jetbrains.kotlin.ir.declarations.persistent.carriers.PropertyCarrier +import org.jetbrains.kotlin.ir.descriptors.WrappedPropertyDescriptor +import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol +import org.jetbrains.kotlin.name.Name + +abstract class PersistentIrPropertyCommon( + startOffset: Int, + endOffset: Int, + origin: IrDeclarationOrigin, + override val name: Name, + override var visibility: Visibility, + override val isVar: Boolean, + override val isConst: Boolean, + override val isLateinit: Boolean, + override val isDelegated: Boolean, + override val isExternal: Boolean, + override val isExpect: Boolean, +) : PersistentIrDeclarationBase(startOffset, endOffset, origin), + IrProperty, + PropertyCarrier { + + override var backingFieldField: IrField? = null + + override var backingField: IrField? + get() = getCarrier().backingFieldField + set(v) { + if (backingField !== v) { + setCarrier().backingFieldField = v + } + } + + override var getterField: IrSimpleFunction? = null + + override var getter: IrSimpleFunction? + get() = getCarrier().getterField + set(v) { + if (getter !== v) { + setCarrier().getterField = v + } + } + + override var setterField: IrSimpleFunction? = null + + override var setter: IrSimpleFunction? + get() = getCarrier().setterField + set(v) { + if (setter !== v) { + setCarrier().setterField = v + } + } + + override var metadataField: MetadataSource? = null + + override var metadata: MetadataSource? + get() = getCarrier().metadataField + set(v) { + if (metadata !== v) { + setCarrier().metadataField = v + } + } +} + +class PersistentIrProperty( + startOffset: Int, + endOffset: Int, + origin: IrDeclarationOrigin, + override val symbol: IrPropertySymbol, + name: Name, + visibility: Visibility, + override val modality: Modality, + isVar: Boolean, + isConst: Boolean, + isLateinit: Boolean, + isDelegated: Boolean, + isExternal: Boolean, + isExpect: Boolean = false, + override val isFakeOverride: Boolean = origin == IrDeclarationOrigin.FAKE_OVERRIDE, +) : PersistentIrPropertyCommon( + startOffset, endOffset, origin, name, visibility, isVar, isConst, isLateinit, isDelegated, isExternal, isExpect, +) { + init { + symbol.bind(this) + } + + @ObsoleteDescriptorBasedAPI + override val descriptor: PropertyDescriptor + get() = symbol.descriptor +} + +class PersistentIrFakeOverrideProperty( + startOffset: Int, + endOffset: Int, + origin: IrDeclarationOrigin, + name: Name, + visibility: Visibility, + override var modality: Modality, + isVar: Boolean, + isConst: Boolean, + isLateinit: Boolean, + isDelegated: Boolean, + isExternal: Boolean, + isExpect: Boolean, +) : PersistentIrPropertyCommon( + startOffset, endOffset, origin, name, visibility, isVar, isConst, isLateinit, + isDelegated, isExternal, isExpect +), IrFakeOverrideProperty { + override val isFakeOverride: Boolean + get() = true + + private var _symbol: IrPropertySymbol? = null + + override val symbol: IrPropertySymbol + get() = _symbol ?: error("$this has not acquired a symbol yet") + + @ObsoleteDescriptorBasedAPI + override val descriptor + get() = _symbol?.descriptor ?: WrappedPropertyDescriptor() + + @OptIn(ObsoleteDescriptorBasedAPI::class) + override fun acquireSymbol(symbol: IrPropertySymbol) { + assert(_symbol == null) { "$this already has symbol _symbol" } + _symbol = symbol + symbol.bind(this) + (symbol.descriptor as? WrappedPropertyDescriptor)?.bind(this) + } +} diff --git a/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrTypeAlias.kt b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrTypeAlias.kt new file mode 100644 index 00000000000..3a0d93cc2f9 --- /dev/null +++ b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrTypeAlias.kt @@ -0,0 +1,50 @@ +/* + * Copyright 2010-2019 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.declarations.persistent + +import org.jetbrains.kotlin.descriptors.TypeAliasDescriptor +import org.jetbrains.kotlin.descriptors.Visibility +import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI +import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin +import org.jetbrains.kotlin.ir.declarations.IrTypeAlias +import org.jetbrains.kotlin.ir.declarations.IrTypeParameter +import org.jetbrains.kotlin.ir.declarations.persistent.carriers.TypeAliasCarrier +import org.jetbrains.kotlin.ir.symbols.IrTypeAliasSymbol +import org.jetbrains.kotlin.ir.types.IrType +import org.jetbrains.kotlin.name.Name + +class PersistentIrTypeAlias( + startOffset: Int, + endOffset: Int, + override val symbol: IrTypeAliasSymbol, + override val name: Name, + override var visibility: Visibility, + override val expandedType: IrType, + override val isActual: Boolean, + origin: IrDeclarationOrigin +) : + PersistentIrDeclarationBase(startOffset, endOffset, origin), + IrTypeAlias, + TypeAliasCarrier { + + init { + symbol.bind(this) + } + + @ObsoleteDescriptorBasedAPI + override val descriptor: TypeAliasDescriptor + get() = symbol.descriptor + + override var typeParametersField: List = emptyList() + + override var typeParameters: List + get() = getCarrier().typeParametersField + set(v) { + if (typeParameters !== v) { + setCarrier().typeParametersField = v + } + } +} diff --git a/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrTypeParameter.kt b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrTypeParameter.kt new file mode 100644 index 00000000000..e0cd2dbffbf --- /dev/null +++ b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrTypeParameter.kt @@ -0,0 +1,53 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.ir.declarations.persistent + +import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor +import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI +import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin +import org.jetbrains.kotlin.ir.declarations.IrTypeParameter +import org.jetbrains.kotlin.ir.declarations.persistent.carriers.TypeParameterCarrier +import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol +import org.jetbrains.kotlin.ir.types.IrType +import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.types.Variance +import org.jetbrains.kotlin.utils.SmartList + +class PersistentIrTypeParameter( + startOffset: Int, + endOffset: Int, + origin: IrDeclarationOrigin, + override val symbol: IrTypeParameterSymbol, + override val name: Name, + override val index: Int, + override val isReified: Boolean, + override val variance: Variance +) : + PersistentIrDeclarationBase(startOffset, endOffset, origin), + IrTypeParameter, + TypeParameterCarrier { + + init { + symbol.bind(this) + } + + @ObsoleteDescriptorBasedAPI + override val descriptor: TypeParameterDescriptor + get() = symbol.descriptor + + override val superTypes: MutableList = SmartList() +} diff --git a/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrValueParameter.kt b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrValueParameter.kt new file mode 100644 index 00000000000..e1fd8000bba --- /dev/null +++ b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/PersistentIrValueParameter.kt @@ -0,0 +1,65 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.ir.declarations.persistent + +import org.jetbrains.kotlin.descriptors.ParameterDescriptor +import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI +import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin +import org.jetbrains.kotlin.ir.declarations.IrValueParameter +import org.jetbrains.kotlin.ir.declarations.persistent.carriers.ValueParameterCarrier +import org.jetbrains.kotlin.ir.expressions.IrExpressionBody +import org.jetbrains.kotlin.ir.symbols.IrValueParameterSymbol +import org.jetbrains.kotlin.ir.types.IrType +import org.jetbrains.kotlin.name.Name + +class PersistentIrValueParameter( + startOffset: Int, + endOffset: Int, + origin: IrDeclarationOrigin, + override val symbol: IrValueParameterSymbol, + override val name: Name, + override val index: Int, + override val type: IrType, + override val varargElementType: IrType?, + override val isCrossinline: Boolean, + override val isNoinline: Boolean +) : + PersistentIrDeclarationBase(startOffset, endOffset, origin), + IrValueParameter, + ValueParameterCarrier { + + @ObsoleteDescriptorBasedAPI + override val descriptor: ParameterDescriptor + get() = symbol.descriptor + + init { + symbol.bind(this) + } + + override var defaultValueField: IrExpressionBody? = null + + override var defaultValue: IrExpressionBody? + get() = getCarrier().defaultValueField + set(v) { + if (defaultValue !== v) { + if (v is PersistentIrBodyBase<*>) { + v.container = this + } + setCarrier().defaultValueField = v + } + } +} diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/carriers/AnonymousInitializerCarrier.kt b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/carriers/AnonymousInitializerCarrier.kt similarity index 91% rename from compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/carriers/AnonymousInitializerCarrier.kt rename to compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/carriers/AnonymousInitializerCarrier.kt index 9f88a1f6b33..8cfd3a4ca93 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/carriers/AnonymousInitializerCarrier.kt +++ b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/carriers/AnonymousInitializerCarrier.kt @@ -3,7 +3,7 @@ * that can be found in the license/LICENSE.txt file. */ -package org.jetbrains.kotlin.ir.declarations.impl.carriers +package org.jetbrains.kotlin.ir.declarations.persistent.carriers import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin import org.jetbrains.kotlin.ir.declarations.IrDeclarationParent @@ -30,4 +30,4 @@ class AnonymousInitializerCarrierImpl( override var originField: IrDeclarationOrigin, override var annotationsField: List, override var bodyField: IrBlockBody? -) : AnonymousInitializerCarrier \ No newline at end of file +) : AnonymousInitializerCarrier diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/carriers/BodyCarrier.kt b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/carriers/BodyCarrier.kt similarity index 86% rename from compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/carriers/BodyCarrier.kt rename to compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/carriers/BodyCarrier.kt index 982b7feac2c..48ead9d77fe 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/carriers/BodyCarrier.kt +++ b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/carriers/BodyCarrier.kt @@ -3,7 +3,7 @@ * that can be found in the license/LICENSE.txt file. */ -package org.jetbrains.kotlin.ir.declarations.impl.carriers +package org.jetbrains.kotlin.ir.declarations.persistent.carriers import org.jetbrains.kotlin.ir.declarations.IrDeclaration @@ -19,4 +19,4 @@ interface BodyCarrier : Carrier { class BodyCarrierImpl( override val lastModified: Int, override var containerField: IrDeclaration? -) : BodyCarrier \ No newline at end of file +) : BodyCarrier diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/carriers/Carrier.kt b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/carriers/Carrier.kt similarity index 77% rename from compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/carriers/Carrier.kt rename to compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/carriers/Carrier.kt index edb9ae1e3fa..4392d009b1f 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/carriers/Carrier.kt +++ b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/carriers/Carrier.kt @@ -3,10 +3,10 @@ * that can be found in the license/LICENSE.txt file. */ -package org.jetbrains.kotlin.ir.declarations.impl.carriers +package org.jetbrains.kotlin.ir.declarations.persistent.carriers interface Carrier { val lastModified: Int fun clone(): Carrier -} \ No newline at end of file +} diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/carriers/ClassCarrier.kt b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/carriers/ClassCarrier.kt similarity index 96% rename from compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/carriers/ClassCarrier.kt rename to compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/carriers/ClassCarrier.kt index f6180fe5eff..51924084aee 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/carriers/ClassCarrier.kt +++ b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/carriers/ClassCarrier.kt @@ -3,7 +3,7 @@ * that can be found in the license/LICENSE.txt file. */ -package org.jetbrains.kotlin.ir.declarations.impl.carriers +package org.jetbrains.kotlin.ir.declarations.persistent.carriers import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.descriptors.Visibility diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/carriers/ConstructorCarrier.kt b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/carriers/ConstructorCarrier.kt similarity index 94% rename from compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/carriers/ConstructorCarrier.kt rename to compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/carriers/ConstructorCarrier.kt index bd2d8dc92c7..b31ca363952 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/carriers/ConstructorCarrier.kt +++ b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/carriers/ConstructorCarrier.kt @@ -3,7 +3,7 @@ * that can be found in the license/LICENSE.txt file. */ -package org.jetbrains.kotlin.ir.declarations.impl.carriers +package org.jetbrains.kotlin.ir.declarations.persistent.carriers import org.jetbrains.kotlin.descriptors.Visibility import org.jetbrains.kotlin.ir.declarations.* @@ -11,7 +11,6 @@ import org.jetbrains.kotlin.ir.expressions.IrBody import org.jetbrains.kotlin.ir.expressions.IrConstructorCall import org.jetbrains.kotlin.ir.types.IrType - interface ConstructorCarrier : FunctionBaseCarrier { override fun clone(): ConstructorCarrier { @@ -45,4 +44,4 @@ class ConstructorCarrierImpl( override var visibilityField: Visibility, override var typeParametersField: List, override var valueParametersField: List -) : ConstructorCarrier \ No newline at end of file +) : ConstructorCarrier diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/carriers/DeclarationCarrier.kt b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/carriers/DeclarationCarrier.kt similarity index 83% rename from compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/carriers/DeclarationCarrier.kt rename to compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/carriers/DeclarationCarrier.kt index 0b0572c1e70..f39a6ca535a 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/carriers/DeclarationCarrier.kt +++ b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/carriers/DeclarationCarrier.kt @@ -3,15 +3,14 @@ * that can be found in the license/LICENSE.txt file. */ -package org.jetbrains.kotlin.ir.declarations.impl.carriers +package org.jetbrains.kotlin.ir.declarations.persistent.carriers import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin import org.jetbrains.kotlin.ir.declarations.IrDeclarationParent import org.jetbrains.kotlin.ir.expressions.IrConstructorCall -import org.jetbrains.kotlin.utils.SmartList interface DeclarationCarrier: Carrier { var parentField: IrDeclarationParent? var originField: IrDeclarationOrigin var annotationsField: List -} \ No newline at end of file +} diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/carriers/EnumEntryCarrier.kt b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/carriers/EnumEntryCarrier.kt similarity index 93% rename from compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/carriers/EnumEntryCarrier.kt rename to compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/carriers/EnumEntryCarrier.kt index 0427cec6df2..1ec97f78cca 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/carriers/EnumEntryCarrier.kt +++ b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/carriers/EnumEntryCarrier.kt @@ -3,7 +3,7 @@ * that can be found in the license/LICENSE.txt file. */ -package org.jetbrains.kotlin.ir.declarations.impl.carriers +package org.jetbrains.kotlin.ir.declarations.persistent.carriers import org.jetbrains.kotlin.ir.declarations.IrClass import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin @@ -34,4 +34,4 @@ class EnumEntryCarrierImpl( override var annotationsField: List, override var correspondingClassField: IrClass?, override var initializerExpressionField: IrExpressionBody? -) : EnumEntryCarrier \ No newline at end of file +) : EnumEntryCarrier diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/carriers/ErrorCarrier.kt b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/carriers/ErrorCarrier.kt similarity index 90% rename from compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/carriers/ErrorCarrier.kt rename to compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/carriers/ErrorCarrier.kt index 60abf70ccb9..37b6e8ce18b 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/carriers/ErrorCarrier.kt +++ b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/carriers/ErrorCarrier.kt @@ -3,7 +3,7 @@ * that can be found in the license/LICENSE.txt file. */ -package org.jetbrains.kotlin.ir.declarations.impl.carriers +package org.jetbrains.kotlin.ir.declarations.persistent.carriers import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin import org.jetbrains.kotlin.ir.declarations.IrDeclarationParent @@ -21,4 +21,4 @@ class ErrorCarrierImpl( override var parentField: IrDeclarationParent?, override var originField: IrDeclarationOrigin, override var annotationsField: List -) : ErrorCarrier \ No newline at end of file +) : ErrorCarrier diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/carriers/FieldCarrier.kt b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/carriers/FieldCarrier.kt similarity index 94% rename from compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/carriers/FieldCarrier.kt rename to compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/carriers/FieldCarrier.kt index 4e96e56acd7..d1d35cc91be 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/carriers/FieldCarrier.kt +++ b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/carriers/FieldCarrier.kt @@ -3,7 +3,7 @@ * that can be found in the license/LICENSE.txt file. */ -package org.jetbrains.kotlin.ir.declarations.impl.carriers +package org.jetbrains.kotlin.ir.declarations.persistent.carriers import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin import org.jetbrains.kotlin.ir.declarations.IrDeclarationParent @@ -38,4 +38,4 @@ class FieldCarrierImpl( override var initializerField: IrExpressionBody?, override var correspondingPropertySymbolField: IrPropertySymbol?, override var metadataField: MetadataSource? -): FieldCarrier \ No newline at end of file +): FieldCarrier diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/carriers/FunctionBaseCarrier.kt b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/carriers/FunctionBaseCarrier.kt similarity index 93% rename from compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/carriers/FunctionBaseCarrier.kt rename to compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/carriers/FunctionBaseCarrier.kt index 7a1e407750e..0b5433af6ab 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/carriers/FunctionBaseCarrier.kt +++ b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/carriers/FunctionBaseCarrier.kt @@ -3,7 +3,7 @@ * that can be found in the license/LICENSE.txt file. */ -package org.jetbrains.kotlin.ir.declarations.impl.carriers +package org.jetbrains.kotlin.ir.declarations.persistent.carriers import org.jetbrains.kotlin.descriptors.Visibility import org.jetbrains.kotlin.ir.declarations.IrTypeParameter diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/carriers/FunctionCarrier.kt b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/carriers/FunctionCarrier.kt similarity index 96% rename from compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/carriers/FunctionCarrier.kt rename to compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/carriers/FunctionCarrier.kt index 9c7de052ebf..0bef7f1d5f2 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/carriers/FunctionCarrier.kt +++ b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/carriers/FunctionCarrier.kt @@ -3,7 +3,7 @@ * that can be found in the license/LICENSE.txt file. */ -package org.jetbrains.kotlin.ir.declarations.impl.carriers +package org.jetbrains.kotlin.ir.declarations.persistent.carriers import org.jetbrains.kotlin.descriptors.Visibility import org.jetbrains.kotlin.ir.declarations.* @@ -55,4 +55,4 @@ class FunctionCarrierImpl( override var correspondingPropertySymbolField: IrPropertySymbol?, override var overriddenSymbolsField: List, override var attributeOwnerIdField: IrAttributeContainer -) : FunctionCarrier \ No newline at end of file +) : FunctionCarrier diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/carriers/LocalDelegatedPropertyCarrier.kt b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/carriers/LocalDelegatedPropertyCarrier.kt similarity index 95% rename from compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/carriers/LocalDelegatedPropertyCarrier.kt rename to compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/carriers/LocalDelegatedPropertyCarrier.kt index 5c402d37715..09e0475da9b 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/carriers/LocalDelegatedPropertyCarrier.kt +++ b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/carriers/LocalDelegatedPropertyCarrier.kt @@ -3,7 +3,7 @@ * that can be found in the license/LICENSE.txt file. */ -package org.jetbrains.kotlin.ir.declarations.impl.carriers +package org.jetbrains.kotlin.ir.declarations.persistent.carriers import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.expressions.IrConstructorCall diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/carriers/PropertyCarrier.kt b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/carriers/PropertyCarrier.kt similarity index 93% rename from compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/carriers/PropertyCarrier.kt rename to compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/carriers/PropertyCarrier.kt index 16a70cd2658..322132eec48 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/carriers/PropertyCarrier.kt +++ b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/carriers/PropertyCarrier.kt @@ -3,7 +3,7 @@ * that can be found in the license/LICENSE.txt file. */ -package org.jetbrains.kotlin.ir.declarations.impl.carriers +package org.jetbrains.kotlin.ir.declarations.persistent.carriers import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.expressions.IrConstructorCall @@ -37,4 +37,4 @@ class PropertyCarrierImpl( override var getterField: IrSimpleFunction?, override var setterField: IrSimpleFunction?, override var metadataField: MetadataSource? -) : PropertyCarrier \ No newline at end of file +) : PropertyCarrier diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/carriers/TypeAliasCarrier.kt b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/carriers/TypeAliasCarrier.kt similarity index 92% rename from compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/carriers/TypeAliasCarrier.kt rename to compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/carriers/TypeAliasCarrier.kt index 3d88c2c69c2..58663a7b20b 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/carriers/TypeAliasCarrier.kt +++ b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/carriers/TypeAliasCarrier.kt @@ -3,7 +3,7 @@ * 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.declarations.impl.carriers +package org.jetbrains.kotlin.ir.declarations.persistent.carriers import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin import org.jetbrains.kotlin.ir.declarations.IrDeclarationParent @@ -31,4 +31,4 @@ class TypeAliasCarrierImpl( override var originField: IrDeclarationOrigin, override var annotationsField: List, override var typeParametersField: List - ) : TypeAliasCarrier \ No newline at end of file +) : TypeAliasCarrier diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/carriers/TypeParameterCarrier.kt b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/carriers/TypeParameterCarrier.kt similarity index 89% rename from compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/carriers/TypeParameterCarrier.kt rename to compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/carriers/TypeParameterCarrier.kt index 0dcf801a759..26d61efa189 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/carriers/TypeParameterCarrier.kt +++ b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/carriers/TypeParameterCarrier.kt @@ -3,7 +3,7 @@ * that can be found in the license/LICENSE.txt file. */ -package org.jetbrains.kotlin.ir.declarations.impl.carriers +package org.jetbrains.kotlin.ir.declarations.persistent.carriers import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin import org.jetbrains.kotlin.ir.declarations.IrDeclarationParent @@ -21,4 +21,4 @@ class TypeParameterCarrierImpl( override var parentField: IrDeclarationParent?, override var originField: IrDeclarationOrigin, override var annotationsField: List -) : TypeParameterCarrier \ No newline at end of file +) : TypeParameterCarrier diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/carriers/ValueParameterCarrier.kt b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/carriers/ValueParameterCarrier.kt similarity index 91% rename from compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/carriers/ValueParameterCarrier.kt rename to compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/carriers/ValueParameterCarrier.kt index 6024e3c01ee..e90bf3096a2 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/carriers/ValueParameterCarrier.kt +++ b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/declarations/persistent/carriers/ValueParameterCarrier.kt @@ -3,7 +3,7 @@ * that can be found in the license/LICENSE.txt file. */ -package org.jetbrains.kotlin.ir.declarations.impl.carriers +package org.jetbrains.kotlin.ir.declarations.persistent.carriers import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin import org.jetbrains.kotlin.ir.declarations.IrDeclarationParent @@ -24,4 +24,4 @@ class ValueParameterCarrierImpl( override var originField: IrDeclarationOrigin, override var annotationsField: List, override var defaultValueField: IrExpressionBody? -) : ValueParameterCarrier \ No newline at end of file +) : ValueParameterCarrier 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 new file mode 100644 index 00000000000..831cf27db8a --- /dev/null +++ b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/expressions/persistent/PersistentIrBlockBody.kt @@ -0,0 +1,44 @@ +/* + * Copyright 2010-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.ir.expressions.persistent + +import org.jetbrains.kotlin.ir.IrStatement +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.expressions.IrBlockBody + +class PersistentIrBlockBody( + startOffset: Int, + endOffset: Int, + initializer: (IrBlockBody.() -> Unit)? = null +) : + PersistentIrBodyBase(startOffset, endOffset, initializer), + IrBlockBody { + + constructor(startOffset: Int, endOffset: Int, statements: List) : this(startOffset, endOffset) { + statementsField.addAll(statements) + } + + private var statementsField: MutableList = ArrayList() + + 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 new file mode 100644 index 00000000000..8d7bc686070 --- /dev/null +++ b/compiler/ir/ir.tree.persistent/src/org/jetbrains/kotlin/ir/expressions/persistent/PersistentIrExpressionBody.kt @@ -0,0 +1,49 @@ +/* + * Copyright 2010-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.ir.expressions.persistent + +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.expressions.IrExpression +import org.jetbrains.kotlin.ir.expressions.IrExpressionBody + +class PersistentIrExpressionBody private constructor( + startOffset: Int, + endOffset: Int, + private var expressionField: IrExpression? = null, + initializer: (IrExpressionBody.() -> Unit)? = null +) : + PersistentIrBodyBase(startOffset, endOffset, initializer), + IrExpressionBody { + + constructor(expression: IrExpression) : this(expression.startOffset, expression.endOffset, expression, null) + + constructor(startOffset: Int, endOffset: Int, expression: IrExpression) : this(startOffset, endOffset, expression, null) + + constructor(startOffset: Int, endOffset: Int, initializer: IrExpressionBody.() -> Unit) : + this(startOffset, endOffset, null, initializer) + + override var expression: IrExpression + get() = checkEnabled { expressionField!! } + set(e) { + checkEnabled { expressionField = e } + } + + override val factory: IrFactory + get() = PersistentIrFactory +} 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 6308802ab43..04360aa7833 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/benchmarks/GenerateIrRuntime.kt +++ b/js/js.tests/test/org/jetbrains/kotlin/benchmarks/GenerateIrRuntime.kt @@ -37,7 +37,7 @@ import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsIrModuleSeria import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsManglerDesc import org.jetbrains.kotlin.ir.backend.js.transformers.irToJs.IrModuleToJsTransformer import org.jetbrains.kotlin.ir.declarations.IrModuleFragment -import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl +import org.jetbrains.kotlin.ir.declarations.persistent.PersistentIrFactory import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns import org.jetbrains.kotlin.ir.descriptors.IrFunctionFactory import org.jetbrains.kotlin.ir.util.* @@ -448,7 +448,7 @@ class GenerateIrRuntime { private fun doPsi2Ir(files: List, analysisResult: AnalysisResult): IrModuleFragment { val psi2Ir = Psi2IrTranslator(languageVersionSettings, Psi2IrConfiguration()) - val symbolTable = SymbolTable(IdSignatureDescriptor(JsManglerDesc), IrFactoryImpl) + val symbolTable = SymbolTable(IdSignatureDescriptor(JsManglerDesc), PersistentIrFactory) val psi2IrContext = psi2Ir.createGeneratorContext(analysisResult.moduleDescriptor, analysisResult.bindingContext, symbolTable) val irBuiltIns = psi2IrContext.irBuiltIns @@ -508,7 +508,7 @@ class GenerateIrRuntime { private fun doDeserializeIrModule(moduleDescriptor: ModuleDescriptorImpl): DeserializedModuleInfo { val mangler = JsManglerDesc val signaturer = IdSignatureDescriptor(mangler) - val symbolTable = SymbolTable(signaturer, IrFactoryImpl) + val symbolTable = SymbolTable(signaturer, PersistentIrFactory) val typeTranslator = TypeTranslator(symbolTable, languageVersionSettings, moduleDescriptor.builtIns).also { it.constantValueGenerator = ConstantValueGenerator(moduleDescriptor, symbolTable) } @@ -537,7 +537,7 @@ class GenerateIrRuntime { val moduleDescriptor = doDeserializeModuleMetadata(moduleRef) val mangler = JsManglerDesc val signaturer = IdSignatureDescriptor(mangler) - val symbolTable = SymbolTable(signaturer, IrFactoryImpl) + val symbolTable = SymbolTable(signaturer, PersistentIrFactory) val typeTranslator = TypeTranslator(symbolTable, languageVersionSettings, moduleDescriptor.builtIns).also { it.constantValueGenerator = ConstantValueGenerator(moduleDescriptor, symbolTable) } 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 b1c2bbcabce..d08ee6094ed 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 @@ -11,7 +11,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.impl.IrFactoryImpl +import org.jetbrains.kotlin.ir.declarations.persistent.PersistentIrFactory import org.jetbrains.kotlin.js.config.JSConfigurationKeys import org.jetbrains.kotlin.js.config.JsConfig import org.jetbrains.kotlin.js.facade.MainCallParameters @@ -180,7 +180,7 @@ abstract class BasicIrBoxTest( configuration = config.configuration, allDependencies = resolvedLibraries, friendDependencies = emptyList(), - irFactory = IrFactoryImpl, + irFactory = PersistentIrFactory, outputKlibPath = actualOutputFile, nopack = true ) diff --git a/prepare/idea-plugin/build.gradle.kts b/prepare/idea-plugin/build.gradle.kts index e31dd2914dc..6c6416d159e 100644 --- a/prepare/idea-plugin/build.gradle.kts +++ b/prepare/idea-plugin/build.gradle.kts @@ -62,6 +62,7 @@ val projectsToShadow by extra(listOf( ":idea:idea-gradle-native", ":compiler:ir.psi2ir", ":compiler:ir.tree", + ":compiler:ir.tree.persistent", ":js:js.ast", ":js:js.frontend", ":js:js.parser", diff --git a/settings.gradle b/settings.gradle index 3e9775b8150..d0e9c689435 100644 --- a/settings.gradle +++ b/settings.gradle @@ -107,6 +107,7 @@ include ":benchmarks", ":kotlin-compiler-runner", ":compiler:cli-common", ":compiler:ir.tree", + ":compiler:ir.tree.persistent", ":compiler:ir.psi2ir", ":compiler:ir.ir2cfg", ":compiler:ir.backend.common", @@ -444,6 +445,7 @@ project(':kotlin-daemon-tests').projectDir = "$rootDir/compiler/daemon/daemon-te project(':kotlin-compiler-runner').projectDir = "$rootDir/compiler/compiler-runner" as File project(':kotlin-ant').projectDir = "$rootDir/ant" as File project(':compiler:ir.tree').projectDir = "$rootDir/compiler/ir/ir.tree" as File +project(':compiler:ir.tree.persistent').projectDir = "$rootDir/compiler/ir/ir.tree.persistent" as File project(':compiler:ir.psi2ir').projectDir = "$rootDir/compiler/ir/ir.psi2ir" as File project(':compiler:ir.ir2cfg').projectDir = "$rootDir/compiler/ir/ir.ir2cfg" as File project(':compiler:ir.backend.common').projectDir = "$rootDir/compiler/ir/backend.common" as File