[IR] Clean up linker interface
This commit is contained in:
@@ -78,8 +78,7 @@ object JvmBackendFacade {
|
|||||||
|
|
||||||
stubGenerator.setIrProviders(irProviders)
|
stubGenerator.setIrProviders(irProviders)
|
||||||
|
|
||||||
val irModuleFragment =
|
val irModuleFragment = psi2ir.generateModuleFragment(psi2irContext, files, irProviders, expectDescriptorToSymbol = null)
|
||||||
psi2ir.generateModuleFragment(psi2irContext, files, irProviders, expectDescriptorToSymbol = null, pluginExtensions)
|
|
||||||
irLinker.postProcess()
|
irLinker.postProcess()
|
||||||
|
|
||||||
stubGenerator.unboundSymbolGeneration = true
|
stubGenerator.unboundSymbolGeneration = true
|
||||||
|
|||||||
@@ -74,8 +74,7 @@ class Psi2IrTranslator(
|
|||||||
context: GeneratorContext,
|
context: GeneratorContext,
|
||||||
ktFiles: Collection<KtFile>,
|
ktFiles: Collection<KtFile>,
|
||||||
irProviders: List<IrProvider>,
|
irProviders: List<IrProvider>,
|
||||||
expectDescriptorToSymbol: MutableMap<DeclarationDescriptor, IrSymbol>? = null,
|
expectDescriptorToSymbol: MutableMap<DeclarationDescriptor, IrSymbol>? = null
|
||||||
pluginExtensions: Collection<IrExtensionGenerator> = emptyList()
|
|
||||||
): IrModuleFragment {
|
): IrModuleFragment {
|
||||||
val moduleGenerator = ModuleGenerator(context)
|
val moduleGenerator = ModuleGenerator(context)
|
||||||
val irModule = moduleGenerator.generateModuleFragmentWithoutDependencies(ktFiles)
|
val irModule = moduleGenerator.generateModuleFragmentWithoutDependencies(ktFiles)
|
||||||
@@ -84,7 +83,7 @@ class Psi2IrTranslator(
|
|||||||
expectDescriptorToSymbol?.let { referenceExpectsForUsedActuals(it, context.symbolTable, irModule) }
|
expectDescriptorToSymbol?.let { referenceExpectsForUsedActuals(it, context.symbolTable, irModule) }
|
||||||
postprocess(context, irModule)
|
postprocess(context, irModule)
|
||||||
|
|
||||||
irProviders.filterIsInstance<IrDeserializer>().forEach { it.init(irModule, emptyList()) }
|
irProviders.filterIsInstance<IrDeserializer>().forEach { it.init(irModule) }
|
||||||
|
|
||||||
moduleGenerator.generateUnboundSymbolsAsDependencies(irProviders)
|
moduleGenerator.generateUnboundSymbolsAsDependencies(irProviders)
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -16,7 +16,7 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils
|
|||||||
|
|
||||||
class IrSyntheticDeclarationGenerator(context: GeneratorContext) : IrElementVisitorVoid {
|
class IrSyntheticDeclarationGenerator(context: GeneratorContext) : IrElementVisitorVoid {
|
||||||
|
|
||||||
private val descriptorGenerator = SyntheticDeclarationsGenerator(context, emptyList())
|
private val descriptorGenerator = SyntheticDeclarationsGenerator(context)
|
||||||
private val symbolTable = context.symbolTable
|
private val symbolTable = context.symbolTable
|
||||||
|
|
||||||
override fun visitElement(element: IrElement) {
|
override fun visitElement(element: IrElement) {
|
||||||
|
|||||||
+8
-34
@@ -9,13 +9,9 @@ import org.jetbrains.kotlin.descriptors.*
|
|||||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.symbols.*
|
import org.jetbrains.kotlin.ir.symbols.*
|
||||||
import org.jetbrains.kotlin.ir.util.IrExtensionGenerator
|
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||||
|
|
||||||
class SyntheticDeclarationsGenerator(
|
class SyntheticDeclarationsGenerator(context: GeneratorContext) : DeclarationDescriptorVisitor<Unit, IrDeclarationContainer?> {
|
||||||
private val context: GeneratorContext,
|
|
||||||
private val pluginProviders: Collection<IrExtensionGenerator>
|
|
||||||
) : DeclarationDescriptorVisitor<Unit, IrDeclarationContainer?> {
|
|
||||||
|
|
||||||
private val generator = StandaloneDeclarationGenerator(context)
|
private val generator = StandaloneDeclarationGenerator(context)
|
||||||
private val symbolTable = context.symbolTable
|
private val symbolTable = context.symbolTable
|
||||||
@@ -30,17 +26,6 @@ class SyntheticDeclarationsGenerator(
|
|||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
private inline fun <S : IrSymbol, R : IrDeclaration> 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?) {
|
override fun visitPackageFragmentDescriptor(descriptor: PackageFragmentDescriptor, data: IrDeclarationContainer?) {
|
||||||
error("Unexpected declaration descriptor $descriptor")
|
error("Unexpected declaration descriptor $descriptor")
|
||||||
}
|
}
|
||||||
@@ -54,9 +39,7 @@ class SyntheticDeclarationsGenerator(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun createFunctionStub(descriptor: FunctionDescriptor, symbol: IrSimpleFunctionSymbol): IrSimpleFunction {
|
private fun createFunctionStub(descriptor: FunctionDescriptor, symbol: IrSimpleFunctionSymbol): IrSimpleFunction {
|
||||||
return generateOrDefault(symbol) {
|
return generator.generateSimpleFunction(offset, offset, IrDeclarationOrigin.DEFINED, descriptor, symbol)
|
||||||
generator.generateSimpleFunction(offset, offset, IrDeclarationOrigin.DEFINED, descriptor, symbol)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitFunctionDescriptor(descriptor: FunctionDescriptor, data: IrDeclarationContainer?) {
|
override fun visitFunctionDescriptor(descriptor: FunctionDescriptor, data: IrDeclarationContainer?) {
|
||||||
@@ -74,16 +57,13 @@ class SyntheticDeclarationsGenerator(
|
|||||||
|
|
||||||
private fun createClassStub(descriptor: ClassDescriptor, symbol: IrClassSymbol): IrClass {
|
private fun createClassStub(descriptor: ClassDescriptor, symbol: IrClassSymbol): IrClass {
|
||||||
assert(!DescriptorUtils.isEnumEntry(descriptor))
|
assert(!DescriptorUtils.isEnumEntry(descriptor))
|
||||||
return generateOrDefault(symbol) {
|
return generator.generateClass(offset, offset, IrDeclarationOrigin.DEFINED, descriptor, symbol)
|
||||||
generator.generateClass(offset, offset, IrDeclarationOrigin.DEFINED, descriptor, symbol)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createEnumEntruStub(descriptor: ClassDescriptor, symbol: IrEnumEntrySymbol): IrEnumEntry {
|
private fun createEnumEntruStub(descriptor: ClassDescriptor, symbol: IrEnumEntrySymbol): IrEnumEntry {
|
||||||
assert(DescriptorUtils.isEnumEntry(descriptor))
|
assert(DescriptorUtils.isEnumEntry(descriptor))
|
||||||
return generateOrDefault(symbol) {
|
return generator.generateEnumEntry(offset, offset, IrDeclarationOrigin.DEFINED, descriptor, symbol)
|
||||||
generator.generateEnumEntry(offset, offset, IrDeclarationOrigin.DEFINED, descriptor, symbol)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitClassDescriptor(descriptor: ClassDescriptor, data: IrDeclarationContainer?) {
|
override fun visitClassDescriptor(descriptor: ClassDescriptor, data: IrDeclarationContainer?) {
|
||||||
@@ -101,9 +81,7 @@ class SyntheticDeclarationsGenerator(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun declareTypeAliasStub(descriptor: TypeAliasDescriptor, symbol: IrTypeAliasSymbol): IrTypeAlias {
|
private fun declareTypeAliasStub(descriptor: TypeAliasDescriptor, symbol: IrTypeAliasSymbol): IrTypeAlias {
|
||||||
return generateOrDefault(symbol) {
|
return generator.generateTypeAlias(offset, offset, IrDeclarationOrigin.DEFINED, descriptor, symbol)
|
||||||
generator.generateTypeAlias(offset, offset, IrDeclarationOrigin.DEFINED, descriptor, symbol)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitTypeAliasDescriptor(descriptor: TypeAliasDescriptor, data: IrDeclarationContainer?) {
|
override fun visitTypeAliasDescriptor(descriptor: TypeAliasDescriptor, data: IrDeclarationContainer?) {
|
||||||
@@ -119,9 +97,7 @@ class SyntheticDeclarationsGenerator(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun createConstructorStub(descriptor: ClassConstructorDescriptor, symbol: IrConstructorSymbol): IrConstructor {
|
private fun createConstructorStub(descriptor: ClassConstructorDescriptor, symbol: IrConstructorSymbol): IrConstructor {
|
||||||
return generateOrDefault(symbol) {
|
return generator.generateConstructor(offset, offset, IrDeclarationOrigin.DEFINED, descriptor, symbol)
|
||||||
generator.generateConstructor(offset, offset, IrDeclarationOrigin.DEFINED, descriptor, symbol)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitConstructorDescriptor(constructorDescriptor: ConstructorDescriptor, data: IrDeclarationContainer?) {
|
override fun visitConstructorDescriptor(constructorDescriptor: ConstructorDescriptor, data: IrDeclarationContainer?) {
|
||||||
@@ -137,9 +113,7 @@ class SyntheticDeclarationsGenerator(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun createPropertyStub(descriptor: PropertyDescriptor, symbol: IrPropertySymbol): IrProperty {
|
private fun createPropertyStub(descriptor: PropertyDescriptor, symbol: IrPropertySymbol): IrProperty {
|
||||||
return generateOrDefault(symbol) {
|
return generator.generateProperty(offset, offset, IrDeclarationOrigin.DEFINED, descriptor, symbol)
|
||||||
generator.generateProperty(offset, offset, IrDeclarationOrigin.DEFINED, descriptor, symbol)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun declareAccessor(accessorDescriptor: PropertyAccessorDescriptor, property: IrProperty): IrSimpleFunction {
|
private fun declareAccessor(accessorDescriptor: PropertyAccessorDescriptor, property: IrProperty): IrSimpleFunction {
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ interface IrExtensionGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface IrDeserializer : IrProvider {
|
interface IrDeserializer : IrProvider {
|
||||||
fun init(moduleFragment: IrModuleFragment?, extensions: Collection<IrExtensionGenerator>) {}
|
fun init(moduleFragment: IrModuleFragment?) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ReferenceSymbolTable {
|
interface ReferenceSymbolTable {
|
||||||
|
|||||||
+1
-1
@@ -525,7 +525,7 @@ abstract class KotlinIrLinker(
|
|||||||
protected open fun createCurrentModuleDeserializer(moduleFragment: IrModuleFragment, dependencies: Collection<IrModuleDeserializer>): IrModuleDeserializer =
|
protected open fun createCurrentModuleDeserializer(moduleFragment: IrModuleFragment, dependencies: Collection<IrModuleDeserializer>): IrModuleDeserializer =
|
||||||
CurrentModuleDeserializer(moduleFragment, dependencies)
|
CurrentModuleDeserializer(moduleFragment, dependencies)
|
||||||
|
|
||||||
override fun init(moduleFragment: IrModuleFragment?, extensions: Collection<IrExtensionGenerator>) {
|
override fun init(moduleFragment: IrModuleFragment?) {
|
||||||
if (moduleFragment != null) {
|
if (moduleFragment != null) {
|
||||||
val currentModuleDependencies = moduleFragment.descriptor.allDependencyModules.map {
|
val currentModuleDependencies = moduleFragment.descriptor.allDependencyModules.map {
|
||||||
deserializersForModules[it] ?: error("No deserializer found for $it")
|
deserializersForModules[it] ?: error("No deserializer found for $it")
|
||||||
|
|||||||
@@ -259,7 +259,7 @@ fun loadIr(
|
|||||||
|
|
||||||
val moduleFragment = deserializedModuleFragments.last()
|
val moduleFragment = deserializedModuleFragments.last()
|
||||||
|
|
||||||
irLinker.init(null, emptyList())
|
irLinker.init(null)
|
||||||
ExternalDependenciesGenerator(symbolTable, listOf(irLinker), configuration.languageVersionSettings).generateUnboundSymbolsAsDependencies()
|
ExternalDependenciesGenerator(symbolTable, listOf(irLinker), configuration.languageVersionSettings).generateUnboundSymbolsAsDependencies()
|
||||||
irLinker.postProcess()
|
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) {}
|
private fun createBuiltIns(storageManager: StorageManager) = object : KotlinBuiltIns(storageManager) {}
|
||||||
|
|||||||
-2
@@ -14,8 +14,6 @@ import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
|||||||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
||||||
import org.jetbrains.kotlin.ir.descriptors.IrAbstractFunctionFactory
|
import org.jetbrains.kotlin.ir.descriptors.IrAbstractFunctionFactory
|
||||||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
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.ir.util.SymbolTable
|
||||||
import org.jetbrains.kotlin.library.IrLibrary
|
import org.jetbrains.kotlin.library.IrLibrary
|
||||||
import org.jetbrains.kotlin.library.SerializedIrFile
|
import org.jetbrains.kotlin.library.SerializedIrFile
|
||||||
|
|||||||
Reference in New Issue
Block a user