From 9f9909478066a1e756e11b9a17ca166e4174b3d1 Mon Sep 17 00:00:00 2001 From: Roman Artemev Date: Wed, 6 May 2020 10:39:54 +0300 Subject: [PATCH] [IR] Clean up linker interface --- .../kotlin/backend/jvm/JvmBackendFacade.kt | 3 +- .../kotlin/psi2ir/Psi2IrTranslator.kt | 5 +-- .../IrSyntheticDeclarationGenerator.kt | 2 +- .../SyntheticDeclarationsGenerator.kt | 42 ++++--------------- .../jetbrains/kotlin/ir/util/SymbolTable.kt | 2 +- .../common/serialization/KotlinIrLinker.kt | 2 +- .../jetbrains/kotlin/ir/backend/js/klib.kt | 4 +- .../js/lower/serialization/ir/JsIrLinker.kt | 2 - 8 files changed, 16 insertions(+), 46 deletions(-) diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmBackendFacade.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmBackendFacade.kt index 287fa3f53c4..17a123ebf74 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmBackendFacade.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmBackendFacade.kt @@ -78,8 +78,7 @@ object JvmBackendFacade { stubGenerator.setIrProviders(irProviders) - val irModuleFragment = - psi2ir.generateModuleFragment(psi2irContext, files, irProviders, expectDescriptorToSymbol = null, pluginExtensions) + val irModuleFragment = psi2ir.generateModuleFragment(psi2irContext, files, irProviders, expectDescriptorToSymbol = null) irLinker.postProcess() stubGenerator.unboundSymbolGeneration = true diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/Psi2IrTranslator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/Psi2IrTranslator.kt index 59719c9961e..58ec79838bc 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/Psi2IrTranslator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/Psi2IrTranslator.kt @@ -74,8 +74,7 @@ class Psi2IrTranslator( context: GeneratorContext, ktFiles: Collection, irProviders: List, - expectDescriptorToSymbol: MutableMap? = null, - pluginExtensions: Collection = emptyList() + expectDescriptorToSymbol: MutableMap? = null ): IrModuleFragment { val moduleGenerator = ModuleGenerator(context) val irModule = moduleGenerator.generateModuleFragmentWithoutDependencies(ktFiles) @@ -84,7 +83,7 @@ class Psi2IrTranslator( expectDescriptorToSymbol?.let { referenceExpectsForUsedActuals(it, context.symbolTable, irModule) } postprocess(context, irModule) - irProviders.filterIsInstance().forEach { it.init(irModule, emptyList()) } + irProviders.filterIsInstance().forEach { it.init(irModule) } moduleGenerator.generateUnboundSymbolsAsDependencies(irProviders) diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/IrSyntheticDeclarationGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/IrSyntheticDeclarationGenerator.kt index 5d5e74bdd8e..febcb6fe83a 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/IrSyntheticDeclarationGenerator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/IrSyntheticDeclarationGenerator.kt @@ -16,7 +16,7 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils class IrSyntheticDeclarationGenerator(context: GeneratorContext) : IrElementVisitorVoid { - private val descriptorGenerator = SyntheticDeclarationsGenerator(context, emptyList()) + private val descriptorGenerator = SyntheticDeclarationsGenerator(context) private val symbolTable = context.symbolTable override fun visitElement(element: IrElement) { diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/SyntheticDeclarationsGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/SyntheticDeclarationsGenerator.kt index 0414483a21d..a0c4a324bbf 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/SyntheticDeclarationsGenerator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/SyntheticDeclarationsGenerator.kt @@ -9,13 +9,9 @@ import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.symbols.* -import org.jetbrains.kotlin.ir.util.IrExtensionGenerator import org.jetbrains.kotlin.resolve.DescriptorUtils -class SyntheticDeclarationsGenerator( - private val context: GeneratorContext, - private val pluginProviders: Collection -) : DeclarationDescriptorVisitor { +class SyntheticDeclarationsGenerator(context: GeneratorContext) : DeclarationDescriptorVisitor { private val generator = StandaloneDeclarationGenerator(context) private val symbolTable = context.symbolTable @@ -30,17 +26,6 @@ class SyntheticDeclarationsGenerator( return this } - private inline fun generateOrDefault(symbol: S, onDefault: (S) -> R): R { - for (p in pluginProviders) { - p.declare(symbol)?.let { - @Suppress("UNCHECKED_CAST") - return it as R - } - } - - return onDefault(symbol) - } - override fun visitPackageFragmentDescriptor(descriptor: PackageFragmentDescriptor, data: IrDeclarationContainer?) { error("Unexpected declaration descriptor $descriptor") } @@ -54,9 +39,7 @@ class SyntheticDeclarationsGenerator( } private fun createFunctionStub(descriptor: FunctionDescriptor, symbol: IrSimpleFunctionSymbol): IrSimpleFunction { - return generateOrDefault(symbol) { - generator.generateSimpleFunction(offset, offset, IrDeclarationOrigin.DEFINED, descriptor, symbol) - } + return generator.generateSimpleFunction(offset, offset, IrDeclarationOrigin.DEFINED, descriptor, symbol) } override fun visitFunctionDescriptor(descriptor: FunctionDescriptor, data: IrDeclarationContainer?) { @@ -74,16 +57,13 @@ class SyntheticDeclarationsGenerator( private fun createClassStub(descriptor: ClassDescriptor, symbol: IrClassSymbol): IrClass { assert(!DescriptorUtils.isEnumEntry(descriptor)) - return generateOrDefault(symbol) { - generator.generateClass(offset, offset, IrDeclarationOrigin.DEFINED, descriptor, symbol) - } + return generator.generateClass(offset, offset, IrDeclarationOrigin.DEFINED, descriptor, symbol) } private fun createEnumEntruStub(descriptor: ClassDescriptor, symbol: IrEnumEntrySymbol): IrEnumEntry { assert(DescriptorUtils.isEnumEntry(descriptor)) - return generateOrDefault(symbol) { - generator.generateEnumEntry(offset, offset, IrDeclarationOrigin.DEFINED, descriptor, symbol) - } + return generator.generateEnumEntry(offset, offset, IrDeclarationOrigin.DEFINED, descriptor, symbol) + } override fun visitClassDescriptor(descriptor: ClassDescriptor, data: IrDeclarationContainer?) { @@ -101,9 +81,7 @@ class SyntheticDeclarationsGenerator( } private fun declareTypeAliasStub(descriptor: TypeAliasDescriptor, symbol: IrTypeAliasSymbol): IrTypeAlias { - return generateOrDefault(symbol) { - generator.generateTypeAlias(offset, offset, IrDeclarationOrigin.DEFINED, descriptor, symbol) - } + return generator.generateTypeAlias(offset, offset, IrDeclarationOrigin.DEFINED, descriptor, symbol) } override fun visitTypeAliasDescriptor(descriptor: TypeAliasDescriptor, data: IrDeclarationContainer?) { @@ -119,9 +97,7 @@ class SyntheticDeclarationsGenerator( } private fun createConstructorStub(descriptor: ClassConstructorDescriptor, symbol: IrConstructorSymbol): IrConstructor { - return generateOrDefault(symbol) { - generator.generateConstructor(offset, offset, IrDeclarationOrigin.DEFINED, descriptor, symbol) - } + return generator.generateConstructor(offset, offset, IrDeclarationOrigin.DEFINED, descriptor, symbol) } override fun visitConstructorDescriptor(constructorDescriptor: ConstructorDescriptor, data: IrDeclarationContainer?) { @@ -137,9 +113,7 @@ class SyntheticDeclarationsGenerator( } private fun createPropertyStub(descriptor: PropertyDescriptor, symbol: IrPropertySymbol): IrProperty { - return generateOrDefault(symbol) { - generator.generateProperty(offset, offset, IrDeclarationOrigin.DEFINED, descriptor, symbol) - } + return generator.generateProperty(offset, offset, IrDeclarationOrigin.DEFINED, descriptor, symbol) } private fun declareAccessor(accessorDescriptor: PropertyAccessorDescriptor, property: IrProperty): IrSimpleFunction { diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/SymbolTable.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/SymbolTable.kt index e9b2c85a4fc..13c73e4f9ef 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/SymbolTable.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/SymbolTable.kt @@ -52,7 +52,7 @@ interface IrExtensionGenerator { } interface IrDeserializer : IrProvider { - fun init(moduleFragment: IrModuleFragment?, extensions: Collection) {} + fun init(moduleFragment: IrModuleFragment?) {} } interface ReferenceSymbolTable { diff --git a/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/serialization/KotlinIrLinker.kt b/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/serialization/KotlinIrLinker.kt index fff608d0631..6243c186d7d 100644 --- a/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/serialization/KotlinIrLinker.kt +++ b/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/serialization/KotlinIrLinker.kt @@ -525,7 +525,7 @@ abstract class KotlinIrLinker( protected open fun createCurrentModuleDeserializer(moduleFragment: IrModuleFragment, dependencies: Collection): IrModuleDeserializer = CurrentModuleDeserializer(moduleFragment, dependencies) - override fun init(moduleFragment: IrModuleFragment?, extensions: Collection) { + override fun init(moduleFragment: IrModuleFragment?) { if (moduleFragment != null) { val currentModuleDependencies = moduleFragment.descriptor.allDependencyModules.map { deserializersForModules[it] ?: error("No deserializer found for $it") diff --git a/compiler/ir/serialization.js/src/org/jetbrains/kotlin/ir/backend/js/klib.kt b/compiler/ir/serialization.js/src/org/jetbrains/kotlin/ir/backend/js/klib.kt index b551fc7d19b..e1beb373bfe 100644 --- a/compiler/ir/serialization.js/src/org/jetbrains/kotlin/ir/backend/js/klib.kt +++ b/compiler/ir/serialization.js/src/org/jetbrains/kotlin/ir/backend/js/klib.kt @@ -259,7 +259,7 @@ fun loadIr( val moduleFragment = deserializedModuleFragments.last() - irLinker.init(null, emptyList()) + irLinker.init(null) ExternalDependenciesGenerator(symbolTable, listOf(irLinker), configuration.languageVersionSettings).generateUnboundSymbolsAsDependencies() irLinker.postProcess() @@ -311,7 +311,7 @@ fun GeneratorContext.generateModuleFragmentWithPlugins( } } - return psi2Ir.generateModuleFragment(this, files, listOf(irLinker), expectDescriptorToSymbol, extensions) + return psi2Ir.generateModuleFragment(this, files, listOf(irLinker), expectDescriptorToSymbol) } private fun createBuiltIns(storageManager: StorageManager) = object : KotlinBuiltIns(storageManager) {} diff --git a/compiler/ir/serialization.js/src/org/jetbrains/kotlin/ir/backend/js/lower/serialization/ir/JsIrLinker.kt b/compiler/ir/serialization.js/src/org/jetbrains/kotlin/ir/backend/js/lower/serialization/ir/JsIrLinker.kt index afe4cf25f38..868356b74cd 100644 --- a/compiler/ir/serialization.js/src/org/jetbrains/kotlin/ir/backend/js/lower/serialization/ir/JsIrLinker.kt +++ b/compiler/ir/serialization.js/src/org/jetbrains/kotlin/ir/backend/js/lower/serialization/ir/JsIrLinker.kt @@ -14,8 +14,6 @@ import org.jetbrains.kotlin.descriptors.ModuleDescriptor import org.jetbrains.kotlin.ir.declarations.IrModuleFragment import org.jetbrains.kotlin.ir.descriptors.IrAbstractFunctionFactory import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns -import org.jetbrains.kotlin.ir.descriptors.IrFunctionFactory -import org.jetbrains.kotlin.ir.util.IrExtensionGenerator import org.jetbrains.kotlin.ir.util.SymbolTable import org.jetbrains.kotlin.library.IrLibrary import org.jetbrains.kotlin.library.SerializedIrFile