IR: use IrFactory in SymbolTable

This commit is contained in:
Alexander Udalov
2020-07-13 17:48:07 +02:00
parent c6a127e87e
commit db4cbe7103
23 changed files with 92 additions and 62 deletions
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.cli.common.messages.*
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
import org.jetbrains.kotlin.config.* import org.jetbrains.kotlin.config.*
import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl
import org.jetbrains.kotlin.js.config.JSConfigurationKeys import org.jetbrains.kotlin.js.config.JSConfigurationKeys
import org.jetbrains.kotlin.library.resolver.KotlinLibraryResolveResult import org.jetbrains.kotlin.library.resolver.KotlinLibraryResolveResult
import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.psi.KtFile
@@ -87,6 +88,7 @@ fun buildKLib(
configuration = configuration, configuration = configuration,
allDependencies = allDependencies, allDependencies = allDependencies,
friendDependencies = emptyList(), friendDependencies = emptyList(),
irFactory = IrFactoryImpl,
outputKlibPath = outputPath, outputKlibPath = outputPath,
nopack = true nopack = true
) )
@@ -24,13 +24,17 @@ import org.jetbrains.kotlin.cli.common.messages.MessageUtil
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
import org.jetbrains.kotlin.cli.jvm.plugins.PluginCliParser import org.jetbrains.kotlin.cli.jvm.plugins.PluginCliParser
import org.jetbrains.kotlin.config.* import org.jetbrains.kotlin.config.CommonConfigurationKeys
import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.config.IncrementalCompilation
import org.jetbrains.kotlin.config.Services
import org.jetbrains.kotlin.incremental.components.ExpectActualTracker import org.jetbrains.kotlin.incremental.components.ExpectActualTracker
import org.jetbrains.kotlin.incremental.components.LookupTracker import org.jetbrains.kotlin.incremental.components.LookupTracker
import org.jetbrains.kotlin.incremental.js.IncrementalDataProvider import org.jetbrains.kotlin.incremental.js.IncrementalDataProvider
import org.jetbrains.kotlin.incremental.js.IncrementalNextRoundChecker import org.jetbrains.kotlin.incremental.js.IncrementalNextRoundChecker
import org.jetbrains.kotlin.incremental.js.IncrementalResultsConsumer import org.jetbrains.kotlin.incremental.js.IncrementalResultsConsumer
import org.jetbrains.kotlin.ir.backend.js.* import org.jetbrains.kotlin.ir.backend.js.*
import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl
import org.jetbrains.kotlin.js.config.EcmaVersion import org.jetbrains.kotlin.js.config.EcmaVersion
import org.jetbrains.kotlin.js.config.JSConfigurationKeys import org.jetbrains.kotlin.js.config.JSConfigurationKeys
import org.jetbrains.kotlin.js.config.JsConfig import org.jetbrains.kotlin.js.config.JsConfig
@@ -193,6 +197,7 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
configuration = config.configuration, configuration = config.configuration,
allDependencies = resolvedLibraries, allDependencies = resolvedLibraries,
friendDependencies = friendDependencies, friendDependencies = friendDependencies,
irFactory = IrFactoryImpl,
outputKlibPath = outputKlibPath, outputKlibPath = outputKlibPath,
nopack = arguments.irProduceKlibDir nopack = arguments.irProduceKlibDir
) )
@@ -71,6 +71,7 @@ import org.jetbrains.kotlin.fir.resolve.transformers.FirTotalResolveProcessor
import org.jetbrains.kotlin.idea.MainFunctionDetector import org.jetbrains.kotlin.idea.MainFunctionDetector
import org.jetbrains.kotlin.ir.backend.jvm.jvmResolveLibraries import org.jetbrains.kotlin.ir.backend.jvm.jvmResolveLibraries
import org.jetbrains.kotlin.ir.backend.jvm.serialization.JvmManglerDesc import org.jetbrains.kotlin.ir.backend.jvm.serialization.JvmManglerDesc
import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl
import org.jetbrains.kotlin.javac.JavacWrapper import org.jetbrains.kotlin.javac.JavacWrapper
import org.jetbrains.kotlin.load.kotlin.ModuleVisibilityManager import org.jetbrains.kotlin.load.kotlin.ModuleVisibilityManager
import org.jetbrains.kotlin.modules.Module import org.jetbrains.kotlin.modules.Module
@@ -378,9 +379,8 @@ object KotlinToJVMBytecodeCompiler {
val (moduleFragment, symbolTable, sourceManager, components) = val (moduleFragment, symbolTable, sourceManager, components) =
Fir2IrConverter.createModuleFragment( Fir2IrConverter.createModuleFragment(
session, resolveTransformer.scopeSession, firFiles, session, resolveTransformer.scopeSession, firFiles,
moduleConfiguration.languageVersionSettings, signaturer = signaturer, moduleConfiguration.languageVersionSettings, signaturer,
generatorExtensions = JvmGeneratorExtensions(), JvmGeneratorExtensions(), FirJvmKotlinMangler(session), IrFactoryImpl
mangler = FirJvmKotlinMangler(session)
) )
performanceManager?.notifyIRTranslationFinished(ktFiles.size, codeLines, debugTargetDescription) performanceManager?.notifyIRTranslationFinished(ktFiles.size, codeLines, debugTargetDescription)
@@ -7,10 +7,10 @@ package org.jetbrains.kotlin.fir.backend
import org.jetbrains.kotlin.config.LanguageVersionSettings import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.backend.evaluate.evaluateConstants
import org.jetbrains.kotlin.fir.backend.generators.AnnotationGenerator import org.jetbrains.kotlin.fir.backend.generators.AnnotationGenerator
import org.jetbrains.kotlin.fir.backend.generators.CallAndReferenceGenerator import org.jetbrains.kotlin.fir.backend.generators.CallAndReferenceGenerator
import org.jetbrains.kotlin.fir.backend.generators.FakeOverrideGenerator import org.jetbrains.kotlin.fir.backend.generators.FakeOverrideGenerator
import org.jetbrains.kotlin.fir.backend.evaluate.evaluateConstants
import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.descriptors.FirModuleDescriptor import org.jetbrains.kotlin.fir.descriptors.FirModuleDescriptor
import org.jetbrains.kotlin.fir.psi import org.jetbrains.kotlin.fir.psi
@@ -199,13 +199,13 @@ class Fir2IrConverter(
scopeSession: ScopeSession, scopeSession: ScopeSession,
firFiles: List<FirFile>, firFiles: List<FirFile>,
languageVersionSettings: LanguageVersionSettings, languageVersionSettings: LanguageVersionSettings,
fakeOverrideMode: FakeOverrideMode = FakeOverrideMode.NORMAL,
signaturer: IdSignatureComposer, signaturer: IdSignatureComposer,
generatorExtensions: GeneratorExtensions, generatorExtensions: GeneratorExtensions,
mangler: FirMangler mangler: FirMangler,
irFactory: IrFactory,
): Fir2IrResult { ): Fir2IrResult {
val moduleDescriptor = FirModuleDescriptor(session) val moduleDescriptor = FirModuleDescriptor(session)
val symbolTable = SymbolTable(signaturer) val symbolTable = SymbolTable(signaturer, irFactory)
val constantValueGenerator = ConstantValueGenerator(moduleDescriptor, symbolTable) val constantValueGenerator = ConstantValueGenerator(moduleDescriptor, symbolTable)
val typeTranslator = TypeTranslator( val typeTranslator = TypeTranslator(
symbolTable, symbolTable,
@@ -247,7 +247,7 @@ class Fir2IrConverter(
converter.processClassHeaders(firFile) converter.processClassHeaders(firFile)
} }
val fakeOverrideGenerator = FakeOverrideGenerator( val fakeOverrideGenerator = FakeOverrideGenerator(
session, scopeSession, classifierStorage, declarationStorage, conversionScope, fakeOverrideMode session, scopeSession, classifierStorage, declarationStorage, conversionScope, FakeOverrideMode.NORMAL
) )
components.fakeOverrideGenerator = fakeOverrideGenerator components.fakeOverrideGenerator = fakeOverrideGenerator
val fir2irVisitor = Fir2IrVisitor(converter, components, conversionScope) val fir2irVisitor = Fir2IrVisitor(converter, components, conversionScope)
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.fir.resolve.transformers.FirTotalResolveProcessor
import org.jetbrains.kotlin.ir.AbstractIrTextTestCase import org.jetbrains.kotlin.ir.AbstractIrTextTestCase
import org.jetbrains.kotlin.ir.backend.jvm.serialization.JvmManglerDesc import org.jetbrains.kotlin.ir.backend.jvm.serialization.JvmManglerDesc
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl
import java.io.File import java.io.File
abstract class AbstractFir2IrTextTest : AbstractIrTextTestCase() { abstract class AbstractFir2IrTextTest : AbstractIrTextTestCase() {
@@ -87,10 +88,11 @@ abstract class AbstractFir2IrTextTest : AbstractIrTextTestCase() {
return Fir2IrConverter.createModuleFragment( return Fir2IrConverter.createModuleFragment(
session, resolveTransformer.scopeSession, firFiles, session, resolveTransformer.scopeSession, firFiles,
myEnvironment.configuration.languageVersionSettings, myEnvironment.configuration.languageVersionSettings,
signaturer = signaturer, signaturer,
// TODO: differentiate JVM resolve from other targets, such as JS resolve. // TODO: differentiate JVM resolve from other targets, such as JS resolve.
generatorExtensions = JvmGeneratorExtensions(generateFacades = false), JvmGeneratorExtensions(generateFacades = false),
mangler = FirJvmKotlinMangler(session) FirJvmKotlinMangler(session),
IrFactoryImpl,
).irModuleFragment ).irModuleFragment
} }
} }
@@ -17,6 +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.backend.js.utils.NameTables
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
import org.jetbrains.kotlin.ir.declarations.StageController import org.jetbrains.kotlin.ir.declarations.StageController
import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl
import org.jetbrains.kotlin.ir.declarations.stageController import org.jetbrains.kotlin.ir.declarations.stageController
import org.jetbrains.kotlin.ir.util.ExternalDependenciesGenerator import org.jetbrains.kotlin.ir.util.ExternalDependenciesGenerator
import org.jetbrains.kotlin.ir.util.noUnboundLeft import org.jetbrains.kotlin.ir.util.noUnboundLeft
@@ -52,7 +53,7 @@ fun compile(
stageController = StageController() stageController = StageController()
val (moduleFragment: IrModuleFragment, dependencyModules, irBuiltIns, symbolTable, deserializer) = val (moduleFragment: IrModuleFragment, dependencyModules, irBuiltIns, symbolTable, deserializer) =
loadIr(project, mainModule, analyzer, configuration, allDependencies, friendDependencies) loadIr(project, mainModule, analyzer, configuration, allDependencies, friendDependencies, IrFactoryImpl)
val moduleDescriptor = moduleFragment.descriptor val moduleDescriptor = moduleFragment.descriptor
@@ -17,7 +17,7 @@ import org.jetbrains.kotlin.ir.declarations.IrValueParameter
import org.jetbrains.kotlin.ir.types.IrType import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
// This is a temporary class for migration to IrDeclarationFactory. Usages should be refactored to use the factory directly once possible, // This is a temporary class for migration to IrFactory. Usages should be refactored to use the factory directly once possible,
// since it doesn't add sufficient value on its own. // since it doesn't add sufficient value on its own.
class JsIrDeclarationBuilder { class JsIrDeclarationBuilder {
fun buildValueParameter(parent: IrDeclarationParent, name: String, index: Int, type: IrType): IrValueParameter = fun buildValueParameter(parent: IrDeclarationParent, name: String, index: Int, type: IrType): IrValueParameter =
@@ -23,10 +23,14 @@ import org.jetbrains.kotlin.ir.backend.jvm.serialization.JvmManglerDesc
import org.jetbrains.kotlin.ir.declarations.IrClass import org.jetbrains.kotlin.ir.declarations.IrClass
import org.jetbrains.kotlin.ir.declarations.IrFunction import org.jetbrains.kotlin.ir.declarations.IrFunction
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl
import org.jetbrains.kotlin.ir.descriptors.IrFunctionFactory import org.jetbrains.kotlin.ir.descriptors.IrFunctionFactory
import org.jetbrains.kotlin.ir.linkage.IrProvider import org.jetbrains.kotlin.ir.linkage.IrProvider
import org.jetbrains.kotlin.ir.types.defaultType import org.jetbrains.kotlin.ir.types.defaultType
import org.jetbrains.kotlin.ir.util.* import org.jetbrains.kotlin.ir.util.DeclarationStubGenerator
import org.jetbrains.kotlin.ir.util.ExternalDependenciesGenerator
import org.jetbrains.kotlin.ir.util.SymbolTable
import org.jetbrains.kotlin.ir.util.render
import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.psi2ir.Psi2IrConfiguration import org.jetbrains.kotlin.psi2ir.Psi2IrConfiguration
import org.jetbrains.kotlin.psi2ir.Psi2IrTranslator import org.jetbrains.kotlin.psi2ir.Psi2IrTranslator
@@ -37,7 +41,7 @@ object JvmBackendFacade {
val extensions = JvmGeneratorExtensions() val extensions = JvmGeneratorExtensions()
val mangler = JvmManglerDesc(MainFunctionDetector(state.bindingContext, state.languageVersionSettings)) val mangler = JvmManglerDesc(MainFunctionDetector(state.bindingContext, state.languageVersionSettings))
val psi2ir = Psi2IrTranslator(state.languageVersionSettings, Psi2IrConfiguration()) val psi2ir = Psi2IrTranslator(state.languageVersionSettings, Psi2IrConfiguration())
val symbolTable = SymbolTable(JvmIdSignatureDescriptor(mangler), JvmNameProvider) val symbolTable = SymbolTable(JvmIdSignatureDescriptor(mangler), IrFactoryImpl, JvmNameProvider)
val psi2irContext = psi2ir.createGeneratorContext(state.module, state.bindingContext, symbolTable, extensions) val psi2irContext = psi2ir.createGeneratorContext(state.module, state.bindingContext, symbolTable, extensions)
val pluginExtensions = IrGenerationExtension.getInstances(state.project) val pluginExtensions = IrGenerationExtension.getInstances(state.project)
val functionFactory = IrFunctionFactory(psi2irContext.irBuiltIns, symbolTable) val functionFactory = IrFunctionFactory(psi2irContext.irBuiltIns, symbolTable)
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.config.languageVersionSettings import org.jetbrains.kotlin.config.languageVersionSettings
import org.jetbrains.kotlin.ir.backend.js.MainModule import org.jetbrains.kotlin.ir.backend.js.MainModule
import org.jetbrains.kotlin.ir.backend.js.loadIr import org.jetbrains.kotlin.ir.backend.js.loadIr
import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl
import org.jetbrains.kotlin.ir.util.ExternalDependenciesGenerator import org.jetbrains.kotlin.ir.util.ExternalDependenciesGenerator
import org.jetbrains.kotlin.ir.util.generateTypicalIrProviderList import org.jetbrains.kotlin.ir.util.generateTypicalIrProviderList
import org.jetbrains.kotlin.ir.util.patchDeclarationParents import org.jetbrains.kotlin.ir.util.patchDeclarationParents
@@ -35,7 +36,9 @@ fun compileWasm(
exportedDeclarations: Set<FqName> = emptySet() exportedDeclarations: Set<FqName> = emptySet()
): WasmCompilerResult { ): WasmCompilerResult {
val (moduleFragment, dependencyModules, irBuiltIns, symbolTable, deserializer) = val (moduleFragment, dependencyModules, irBuiltIns, symbolTable, deserializer) =
loadIr(project, MainModule.SourceFiles(files), analyzer, configuration, allDependencies, friendDependencies) loadIr(
project, MainModule.SourceFiles(files), analyzer, configuration, allDependencies, friendDependencies, IrFactoryImpl
)
val moduleDescriptor = moduleFragment.descriptor val moduleDescriptor = moduleFragment.descriptor
val context = WasmBackendContext(moduleDescriptor, irBuiltIns, symbolTable, moduleFragment, exportedDeclarations, configuration) val context = WasmBackendContext(moduleDescriptor, irBuiltIns, symbolTable, moduleFragment, exportedDeclarations, configuration)
@@ -14,14 +14,14 @@
* limitations under the License. * limitations under the License.
*/ */
@file:Suppress("DEPRECATION")
package org.jetbrains.kotlin.ir.util package org.jetbrains.kotlin.ir.util
import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.declarations.impl.* import org.jetbrains.kotlin.ir.declarations.impl.IrExternalPackageFragmentImpl
import org.jetbrains.kotlin.ir.declarations.impl.IrScriptImpl
import org.jetbrains.kotlin.ir.declarations.impl.IrVariableImpl
import org.jetbrains.kotlin.ir.declarations.lazy.IrLazySymbolTable import org.jetbrains.kotlin.ir.declarations.lazy.IrLazySymbolTable
import org.jetbrains.kotlin.ir.descriptors.WrappedDeclarationDescriptor import org.jetbrains.kotlin.ir.descriptors.WrappedDeclarationDescriptor
import org.jetbrains.kotlin.ir.descriptors.WrappedFunctionDescriptorWithContainerSource import org.jetbrains.kotlin.ir.descriptors.WrappedFunctionDescriptorWithContainerSource
@@ -74,8 +74,9 @@ interface ReferenceSymbolTable {
fun leaveScope(owner: IrDeclaration) fun leaveScope(owner: IrDeclaration)
} }
open class SymbolTable( class SymbolTable(
val signaturer: IdSignatureComposer, val signaturer: IdSignatureComposer,
val irFactory: IrFactory,
val nameProvider: NameProvider = NameProvider.DEFAULT val nameProvider: NameProvider = NameProvider.DEFAULT
) : ReferenceSymbolTable { ) : ReferenceSymbolTable {
@@ -374,7 +375,7 @@ open class SymbolTable(
origin: IrDeclarationOrigin, origin: IrDeclarationOrigin,
descriptor: ClassDescriptor descriptor: ClassDescriptor
): IrAnonymousInitializer = ): IrAnonymousInitializer =
IrAnonymousInitializerImpl( irFactory.createAnonymousInitializer(
startOffset, endOffset, origin, startOffset, endOffset, origin,
IrAnonymousInitializerSymbolImpl(descriptor) IrAnonymousInitializerSymbolImpl(descriptor)
) )
@@ -524,7 +525,7 @@ open class SymbolTable(
fun declareEnumEntry( fun declareEnumEntry(
startOffset: Int, endOffset: Int, origin: IrDeclarationOrigin, descriptor: ClassDescriptor, startOffset: Int, endOffset: Int, origin: IrDeclarationOrigin, descriptor: ClassDescriptor,
factory: (IrEnumEntrySymbol) -> IrEnumEntry = { factory: (IrEnumEntrySymbol) -> IrEnumEntry = {
IrEnumEntryImpl(startOffset, endOffset, origin, it, nameProvider.nameForDeclaration(descriptor)) irFactory.createEnumEntry(startOffset, endOffset, origin, it, nameProvider.nameForDeclaration(descriptor))
} }
): IrEnumEntry = ): IrEnumEntry =
enumEntrySymbolTable.declare( enumEntrySymbolTable.declare(
@@ -581,7 +582,7 @@ open class SymbolTable(
type: IrType, type: IrType,
visibility: Visibility? = null, visibility: Visibility? = null,
fieldFactory: (IrFieldSymbol) -> IrField = { fieldFactory: (IrFieldSymbol) -> IrField = {
IrFieldImpl( irFactory.createField(
startOffset, endOffset, origin, it, nameProvider.nameForDeclaration(descriptor), type, startOffset, endOffset, origin, it, nameProvider.nameForDeclaration(descriptor), type,
visibility ?: it.descriptor.visibility, !it.descriptor.isVar, it.descriptor.isEffectivelyExternal(), visibility ?: it.descriptor.visibility, !it.descriptor.isVar, it.descriptor.isEffectivelyExternal(),
it.descriptor.dispatchReceiverParameter == null it.descriptor.dispatchReceiverParameter == null
@@ -630,6 +631,7 @@ open class SymbolTable(
val propertyTable = HashMap<PropertyDescriptor, IrProperty>() val propertyTable = HashMap<PropertyDescriptor, IrProperty>()
override fun referenceProperty(descriptor: PropertyDescriptor, generate: () -> IrProperty): IrProperty = override fun referenceProperty(descriptor: PropertyDescriptor, generate: () -> IrProperty): IrProperty =
@Suppress("DEPRECATION")
propertyTable.getOrPut(descriptor, generate) propertyTable.getOrPut(descriptor, generate)
private fun createPropertySymbol(descriptor: PropertyDescriptor): IrPropertySymbol { private fun createPropertySymbol(descriptor: PropertyDescriptor): IrPropertySymbol {
@@ -647,7 +649,7 @@ open class SymbolTable(
descriptor: PropertyDescriptor, descriptor: PropertyDescriptor,
isDelegated: Boolean = descriptor.isDelegated, isDelegated: Boolean = descriptor.isDelegated,
propertyFactory: (IrPropertySymbol) -> IrProperty = { symbol -> propertyFactory: (IrPropertySymbol) -> IrProperty = { symbol ->
IrPropertyImpl( irFactory.createProperty(
startOffset, endOffset, origin, symbol, isDelegated = isDelegated, startOffset, endOffset, origin, symbol, isDelegated = isDelegated,
name = nameProvider.nameForDeclaration(descriptor), name = nameProvider.nameForDeclaration(descriptor),
visibility = descriptor.visibility, visibility = descriptor.visibility,
@@ -830,7 +832,7 @@ open class SymbolTable(
origin: IrDeclarationOrigin, origin: IrDeclarationOrigin,
descriptor: TypeParameterDescriptor, descriptor: TypeParameterDescriptor,
typeParameterFactory: (IrTypeParameterSymbol) -> IrTypeParameter = { typeParameterFactory: (IrTypeParameterSymbol) -> IrTypeParameter = {
IrTypeParameterImpl( irFactory.createTypeParameter(
startOffset, endOffset, origin, it, nameProvider.nameForDeclaration(descriptor), startOffset, endOffset, origin, it, nameProvider.nameForDeclaration(descriptor),
it.descriptor.index, it.descriptor.isReified, it.descriptor.variance it.descriptor.index, it.descriptor.isReified, it.descriptor.variance
) )
@@ -858,7 +860,7 @@ open class SymbolTable(
origin: IrDeclarationOrigin, origin: IrDeclarationOrigin,
descriptor: TypeParameterDescriptor, descriptor: TypeParameterDescriptor,
typeParameterFactory: (IrTypeParameterSymbol) -> IrTypeParameter = { typeParameterFactory: (IrTypeParameterSymbol) -> IrTypeParameter = {
IrTypeParameterImpl( irFactory.createTypeParameter(
startOffset, endOffset, origin, it, nameProvider.nameForDeclaration(descriptor), startOffset, endOffset, origin, it, nameProvider.nameForDeclaration(descriptor),
it.descriptor.index, it.descriptor.isReified, it.descriptor.variance it.descriptor.index, it.descriptor.isReified, it.descriptor.variance
) )
@@ -890,7 +892,7 @@ open class SymbolTable(
type: IrType, type: IrType,
varargElementType: IrType? = null, varargElementType: IrType? = null,
valueParameterFactory: (IrValueParameterSymbol) -> IrValueParameter = { valueParameterFactory: (IrValueParameterSymbol) -> IrValueParameter = {
IrValueParameterImpl( irFactory.createValueParameter(
startOffset, endOffset, origin, it, nameProvider.nameForDeclaration(descriptor), startOffset, endOffset, origin, it, nameProvider.nameForDeclaration(descriptor),
descriptor.indexOrMinusOne, type, varargElementType, descriptor.isCrossinline, descriptor.isNoinline descriptor.indexOrMinusOne, type, varargElementType, descriptor.isCrossinline, descriptor.isNoinline
) )
@@ -968,7 +970,7 @@ open class SymbolTable(
descriptor, descriptor,
{ IrLocalDelegatedPropertySymbolImpl(descriptor) }, { IrLocalDelegatedPropertySymbolImpl(descriptor) },
) { ) {
IrLocalDelegatedPropertyImpl( irFactory.createLocalDelegatedProperty(
startOffset, endOffset, origin, it, nameProvider.nameForDeclaration(descriptor), type, descriptor.isVar startOffset, endOffset, origin, it, nameProvider.nameForDeclaration(descriptor), type, descriptor.isVar
).apply { ).apply {
metadata = MetadataSource.LocalDelegatedProperty(descriptor) metadata = MetadataSource.LocalDelegatedProperty(descriptor)
@@ -10,7 +10,6 @@ import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
import org.jetbrains.kotlin.ir.declarations.MetadataSource import org.jetbrains.kotlin.ir.declarations.MetadataSource
import org.jetbrains.kotlin.ir.declarations.impl.IrFunctionImpl
import org.jetbrains.kotlin.ir.types.impl.IrUninitializedType import org.jetbrains.kotlin.ir.types.impl.IrUninitializedType
@ObsoleteDescriptorBasedAPI @ObsoleteDescriptorBasedAPI
@@ -22,7 +21,7 @@ fun SymbolTable.declareSimpleFunctionWithOverrides(
) = ) =
declareSimpleFunction(descriptor) { declareSimpleFunction(descriptor) {
with(descriptor) { with(descriptor) {
IrFunctionImpl( irFactory.createFunction(
startOffset, endOffset, origin, it, nameProvider.nameForDeclaration(this), startOffset, endOffset, origin, it, nameProvider.nameForDeclaration(this),
visibility, modality, IrUninitializedType, isInline, isExternal, isTailrec, isSuspend, isOperator, isInfix, isExpect visibility, modality, IrUninitializedType, isInline, isExternal, isTailrec, isSuspend, isOperator, isInfix, isExpect
).also { declaration -> ).also { declaration ->
@@ -33,6 +33,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.lower.serialization.ir.JsManglerDesc
import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsManglerIr import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsManglerIr
import org.jetbrains.kotlin.ir.backend.js.lower.serialization.metadata.KlibMetadataIncrementalSerializer import org.jetbrains.kotlin.ir.backend.js.lower.serialization.metadata.KlibMetadataIncrementalSerializer
import org.jetbrains.kotlin.ir.declarations.IrFactory
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
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.descriptors.IrFunctionFactory
@@ -100,6 +101,7 @@ fun generateKLib(
configuration: CompilerConfiguration, configuration: CompilerConfiguration,
allDependencies: KotlinLibraryResolveResult, allDependencies: KotlinLibraryResolveResult,
friendDependencies: List<KotlinLibrary>, friendDependencies: List<KotlinLibrary>,
irFactory: IrFactory,
outputKlibPath: String, outputKlibPath: String,
nopack: Boolean nopack: Boolean
) { ) {
@@ -138,7 +140,7 @@ fun generateKLib(
val depsDescriptors = val depsDescriptors =
ModulesStructure(project, MainModule.SourceFiles(files), analyzer, configuration, allDependencies, friendDependencies) ModulesStructure(project, MainModule.SourceFiles(files), analyzer, configuration, allDependencies, friendDependencies)
val psi2IrContext = runAnalysisAndPreparePsi2Ir(depsDescriptors) val psi2IrContext = runAnalysisAndPreparePsi2Ir(depsDescriptors, irFactory)
val irBuiltIns = psi2IrContext.irBuiltIns val irBuiltIns = psi2IrContext.irBuiltIns
val functionFactory = IrFunctionFactory(irBuiltIns, psi2IrContext.symbolTable) val functionFactory = IrFunctionFactory(irBuiltIns, psi2IrContext.symbolTable)
irBuiltIns.functionFactory = functionFactory irBuiltIns.functionFactory = functionFactory
@@ -212,14 +214,15 @@ fun loadIr(
analyzer: AbstractAnalyzerWithCompilerReport, analyzer: AbstractAnalyzerWithCompilerReport,
configuration: CompilerConfiguration, configuration: CompilerConfiguration,
allDependencies: KotlinLibraryResolveResult, allDependencies: KotlinLibraryResolveResult,
friendDependencies: List<KotlinLibrary> friendDependencies: List<KotlinLibrary>,
irFactory: IrFactory,
): IrModuleInfo { ): IrModuleInfo {
val depsDescriptors = ModulesStructure(project, mainModule, analyzer, configuration, allDependencies, friendDependencies) val depsDescriptors = ModulesStructure(project, mainModule, analyzer, configuration, allDependencies, friendDependencies)
val deserializeFakeOverrides = configuration.getBoolean(CommonConfigurationKeys.DESERIALIZE_FAKE_OVERRIDES) val deserializeFakeOverrides = configuration.getBoolean(CommonConfigurationKeys.DESERIALIZE_FAKE_OVERRIDES)
when (mainModule) { when (mainModule) {
is MainModule.SourceFiles -> { is MainModule.SourceFiles -> {
val psi2IrContext: GeneratorContext = runAnalysisAndPreparePsi2Ir(depsDescriptors) val psi2IrContext: GeneratorContext = runAnalysisAndPreparePsi2Ir(depsDescriptors, irFactory)
val irBuiltIns = psi2IrContext.irBuiltIns val irBuiltIns = psi2IrContext.irBuiltIns
val symbolTable = psi2IrContext.symbolTable val symbolTable = psi2IrContext.symbolTable
val functionFactory = IrFunctionFactory(irBuiltIns, symbolTable) val functionFactory = IrFunctionFactory(irBuiltIns, symbolTable)
@@ -249,7 +252,7 @@ fun loadIr(
val moduleDescriptor = depsDescriptors.getModuleDescriptor(mainModule.lib) val moduleDescriptor = depsDescriptors.getModuleDescriptor(mainModule.lib)
val mangler = JsManglerDesc val mangler = JsManglerDesc
val signaturer = IdSignatureDescriptor(mangler) val signaturer = IdSignatureDescriptor(mangler)
val symbolTable = SymbolTable(signaturer) val symbolTable = SymbolTable(signaturer, irFactory)
val constantValueGenerator = ConstantValueGenerator(moduleDescriptor, symbolTable) val constantValueGenerator = ConstantValueGenerator(moduleDescriptor, symbolTable)
val typeTranslator = TypeTranslator( val typeTranslator = TypeTranslator(
symbolTable, symbolTable,
@@ -284,10 +287,10 @@ fun loadIr(
} }
} }
private fun runAnalysisAndPreparePsi2Ir(depsDescriptors: ModulesStructure): GeneratorContext { private fun runAnalysisAndPreparePsi2Ir(depsDescriptors: ModulesStructure, irFactory: IrFactory): GeneratorContext {
val (bindingContext, moduleDescriptor) = depsDescriptors.runAnalysis() val (bindingContext, moduleDescriptor) = depsDescriptors.runAnalysis()
val psi2Ir = Psi2IrTranslator(depsDescriptors.compilerConfiguration.languageVersionSettings, Psi2IrConfiguration()) val psi2Ir = Psi2IrTranslator(depsDescriptors.compilerConfiguration.languageVersionSettings, Psi2IrConfiguration())
val symbolTable = SymbolTable(IdSignatureDescriptor(JsManglerDesc)) val symbolTable = SymbolTable(IdSignatureDescriptor(JsManglerDesc), irFactory)
return psi2Ir.createGeneratorContext(moduleDescriptor, bindingContext, symbolTable) return psi2Ir.createGeneratorContext(moduleDescriptor, bindingContext, symbolTable)
} }
@@ -52,6 +52,7 @@ import org.jetbrains.kotlin.fir.resolve.providers.impl.FirProviderImpl
import org.jetbrains.kotlin.fir.resolve.transformers.FirTotalResolveProcessor import org.jetbrains.kotlin.fir.resolve.transformers.FirTotalResolveProcessor
import org.jetbrains.kotlin.ir.backend.jvm.jvmResolveLibraries import org.jetbrains.kotlin.ir.backend.jvm.jvmResolveLibraries
import org.jetbrains.kotlin.ir.backend.jvm.serialization.JvmManglerDesc import org.jetbrains.kotlin.ir.backend.jvm.serialization.JvmManglerDesc
import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl
import org.jetbrains.kotlin.load.kotlin.PackagePartProvider import org.jetbrains.kotlin.load.kotlin.PackagePartProvider
import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.resolve.AnalyzingUtils import org.jetbrains.kotlin.resolve.AnalyzingUtils
@@ -144,10 +145,11 @@ object GenerationUtils {
Fir2IrConverter.createModuleFragment( Fir2IrConverter.createModuleFragment(
session, resolveTransformer.scopeSession, firFiles, session, resolveTransformer.scopeSession, firFiles,
configuration.languageVersionSettings, configuration.languageVersionSettings,
signaturer = IdSignatureDescriptor(JvmManglerDesc()), IdSignatureDescriptor(JvmManglerDesc()),
// TODO: differentiate JVM resolve from other targets, such as JS resolve. // TODO: differentiate JVM resolve from other targets, such as JS resolve.
generatorExtensions = JvmGeneratorExtensions(), JvmGeneratorExtensions(),
mangler = FirJvmKotlinMangler(session) FirJvmKotlinMangler(session),
IrFactoryImpl,
) )
val dummyBindingContext = NoScopeRecordCliBindingTrace().bindingContext val dummyBindingContext = NoScopeRecordCliBindingTrace().bindingContext
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.config.languageVersionSettings
import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsManglerDesc import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsManglerDesc
import org.jetbrains.kotlin.ir.declarations.IrFile import org.jetbrains.kotlin.ir.declarations.IrFile
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl
import org.jetbrains.kotlin.ir.util.NameProvider import org.jetbrains.kotlin.ir.util.NameProvider
import org.jetbrains.kotlin.ir.util.SymbolTable import org.jetbrains.kotlin.ir.util.SymbolTable
import org.jetbrains.kotlin.ir.util.generateTypicalIrProviderList import org.jetbrains.kotlin.ir.util.generateTypicalIrProviderList
@@ -141,7 +142,7 @@ abstract class AbstractIrGeneratorTestCase : CodegenTestCase() {
val context = psi2ir.createGeneratorContext( val context = psi2ir.createGeneratorContext(
moduleDescriptor, moduleDescriptor,
bindingContext, bindingContext,
SymbolTable(IdSignatureDescriptor(JsManglerDesc), NameProvider.DEFAULT), SymbolTable(IdSignatureDescriptor(JsManglerDesc), IrFactoryImpl, NameProvider.DEFAULT),
generatorExtensions generatorExtensions
) )
val irProviders = generateTypicalIrProviderList( val irProviders = generateTypicalIrProviderList(
@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.descriptors.findClassAcrossModuleDependencies import org.jetbrains.kotlin.descriptors.findClassAcrossModuleDependencies
import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsManglerDesc import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsManglerDesc
import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl
import org.jetbrains.kotlin.ir.expressions.* import org.jetbrains.kotlin.ir.expressions.*
import org.jetbrains.kotlin.ir.symbols.IrSymbol import org.jetbrains.kotlin.ir.symbols.IrSymbol
import org.jetbrains.kotlin.ir.util.* import org.jetbrains.kotlin.ir.util.*
@@ -68,7 +69,7 @@ abstract class AbstractIrTextTestCase : AbstractIrGeneratorTestCase() {
val stubGenerator = DeclarationStubGenerator( val stubGenerator = DeclarationStubGenerator(
irModule.descriptor, irModule.descriptor,
SymbolTable(signaturer), // TODO SymbolTable(signaturer, IrFactoryImpl), // TODO
myEnvironment.configuration.languageVersionSettings myEnvironment.configuration.languageVersionSettings
) )
@@ -15,12 +15,13 @@ import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
import org.jetbrains.kotlin.generators.util.GeneratorsFileUtil import org.jetbrains.kotlin.generators.util.GeneratorsFileUtil
import org.jetbrains.kotlin.ir.declarations.IrFunction import org.jetbrains.kotlin.ir.declarations.IrFunction
import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
import org.jetbrains.kotlin.ir.types.impl.originalKotlinType import org.jetbrains.kotlin.ir.types.impl.originalKotlinType
import org.jetbrains.kotlin.ir.util.* import org.jetbrains.kotlin.ir.util.*
import org.jetbrains.kotlin.utils.Printer
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.storage.LockBasedStorageManager import org.jetbrains.kotlin.storage.LockBasedStorageManager
import org.jetbrains.kotlin.utils.Printer
import java.io.File import java.io.File
val DESTINATION = File("compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/builtins/IrBuiltInsMapGenerated.kt") val DESTINATION = File("compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/builtins/IrBuiltInsMapGenerated.kt")
@@ -201,7 +202,7 @@ private fun getIrBuiltIns(): IrBuiltIns {
override fun composeEnumEntrySignature(descriptor: ClassDescriptor): IdSignature? = null override fun composeEnumEntrySignature(descriptor: ClassDescriptor): IdSignature? = null
} }
val symbolTable = SymbolTable(signaturer) val symbolTable = SymbolTable(signaturer, IrFactoryImpl)
val constantValueGenerator = ConstantValueGenerator(moduleDescriptor, symbolTable) val constantValueGenerator = ConstantValueGenerator(moduleDescriptor, symbolTable)
val typeTranslator = TypeTranslator(symbolTable, languageSettings, builtIns) val typeTranslator = TypeTranslator(symbolTable, languageSettings, builtIns)
constantValueGenerator.typeTranslator = typeTranslator constantValueGenerator.typeTranslator = typeTranslator
@@ -37,6 +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.lower.serialization.ir.JsManglerDesc
import org.jetbrains.kotlin.ir.backend.js.transformers.irToJs.IrModuleToJsTransformer import org.jetbrains.kotlin.ir.backend.js.transformers.irToJs.IrModuleToJsTransformer
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl
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.descriptors.IrFunctionFactory
import org.jetbrains.kotlin.ir.util.* import org.jetbrains.kotlin.ir.util.*
@@ -447,7 +448,7 @@ class GenerateIrRuntime {
private fun doPsi2Ir(files: List<KtFile>, analysisResult: AnalysisResult): IrModuleFragment { private fun doPsi2Ir(files: List<KtFile>, analysisResult: AnalysisResult): IrModuleFragment {
val psi2Ir = Psi2IrTranslator(languageVersionSettings, Psi2IrConfiguration()) val psi2Ir = Psi2IrTranslator(languageVersionSettings, Psi2IrConfiguration())
val symbolTable = SymbolTable(IdSignatureDescriptor(JsManglerDesc)) val symbolTable = SymbolTable(IdSignatureDescriptor(JsManglerDesc), IrFactoryImpl)
val psi2IrContext = psi2Ir.createGeneratorContext(analysisResult.moduleDescriptor, analysisResult.bindingContext, symbolTable) val psi2IrContext = psi2Ir.createGeneratorContext(analysisResult.moduleDescriptor, analysisResult.bindingContext, symbolTable)
val irBuiltIns = psi2IrContext.irBuiltIns val irBuiltIns = psi2IrContext.irBuiltIns
@@ -507,7 +508,7 @@ class GenerateIrRuntime {
private fun doDeserializeIrModule(moduleDescriptor: ModuleDescriptorImpl): DeserializedModuleInfo { private fun doDeserializeIrModule(moduleDescriptor: ModuleDescriptorImpl): DeserializedModuleInfo {
val mangler = JsManglerDesc val mangler = JsManglerDesc
val signaturer = IdSignatureDescriptor(mangler) val signaturer = IdSignatureDescriptor(mangler)
val symbolTable = SymbolTable(signaturer) val symbolTable = SymbolTable(signaturer, IrFactoryImpl)
val typeTranslator = TypeTranslator(symbolTable, languageVersionSettings, moduleDescriptor.builtIns).also { val typeTranslator = TypeTranslator(symbolTable, languageVersionSettings, moduleDescriptor.builtIns).also {
it.constantValueGenerator = ConstantValueGenerator(moduleDescriptor, symbolTable) it.constantValueGenerator = ConstantValueGenerator(moduleDescriptor, symbolTable)
} }
@@ -536,7 +537,7 @@ class GenerateIrRuntime {
val moduleDescriptor = doDeserializeModuleMetadata(moduleRef) val moduleDescriptor = doDeserializeModuleMetadata(moduleRef)
val mangler = JsManglerDesc val mangler = JsManglerDesc
val signaturer = IdSignatureDescriptor(mangler) val signaturer = IdSignatureDescriptor(mangler)
val symbolTable = SymbolTable(signaturer) val symbolTable = SymbolTable(signaturer, IrFactoryImpl)
val typeTranslator = TypeTranslator(symbolTable, languageVersionSettings, moduleDescriptor.builtIns).also { val typeTranslator = TypeTranslator(symbolTable, languageVersionSettings, moduleDescriptor.builtIns).also {
it.constantValueGenerator = ConstantValueGenerator(moduleDescriptor, symbolTable) it.constantValueGenerator = ConstantValueGenerator(moduleDescriptor, symbolTable)
} }
@@ -18,6 +18,7 @@ import org.jetbrains.kotlin.descriptors.impl.EnumEntrySyntheticClassDescriptor
import org.jetbrains.kotlin.ir.backend.js.MainModule import org.jetbrains.kotlin.ir.backend.js.MainModule
import org.jetbrains.kotlin.ir.backend.js.jsResolveLibraries import org.jetbrains.kotlin.ir.backend.js.jsResolveLibraries
import org.jetbrains.kotlin.ir.backend.js.loadIr import org.jetbrains.kotlin.ir.backend.js.loadIr
import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl
import org.jetbrains.kotlin.js.config.JSConfigurationKeys import org.jetbrains.kotlin.js.config.JSConfigurationKeys
import org.jetbrains.kotlin.js.config.JsConfig import org.jetbrains.kotlin.js.config.JsConfig
import org.jetbrains.kotlin.jvm.compiler.ExpectedLoadErrorsUtil import org.jetbrains.kotlin.jvm.compiler.ExpectedLoadErrorsUtil
@@ -26,7 +27,6 @@ import org.jetbrains.kotlin.renderer.*
import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.MemberComparator import org.jetbrains.kotlin.resolve.MemberComparator
import org.jetbrains.kotlin.resolve.descriptorUtil.isEffectivelyPublicApi import org.jetbrains.kotlin.resolve.descriptorUtil.isEffectivelyPublicApi
import org.jetbrains.kotlin.resolve.descriptorUtil.module
import org.jetbrains.kotlin.test.KotlinTestUtils import org.jetbrains.kotlin.test.KotlinTestUtils
import org.jetbrains.kotlin.test.KotlinTestWithEnvironment import org.jetbrains.kotlin.test.KotlinTestWithEnvironment
import java.io.File import java.io.File
@@ -83,7 +83,8 @@ class ApiTest : KotlinTestWithEnvironment() {
AnalyzerWithCompilerReport(configuration), AnalyzerWithCompilerReport(configuration),
configuration, configuration,
resolvedLibraries, resolvedLibraries,
listOf() listOf(),
IrFactoryImpl,
).module.descriptor.packagesSerialized() ).module.descriptor.packagesSerialized()
} }
@@ -11,13 +11,13 @@ import org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport
import org.jetbrains.kotlin.cli.common.messages.MessageCollector import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.cli.js.messageCollectorLogger import org.jetbrains.kotlin.cli.js.messageCollectorLogger
import org.jetbrains.kotlin.ir.backend.js.* import org.jetbrains.kotlin.ir.backend.js.*
import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl
import org.jetbrains.kotlin.js.config.JSConfigurationKeys import org.jetbrains.kotlin.js.config.JSConfigurationKeys
import org.jetbrains.kotlin.js.config.JsConfig import org.jetbrains.kotlin.js.config.JsConfig
import org.jetbrains.kotlin.js.facade.MainCallParameters import org.jetbrains.kotlin.js.facade.MainCallParameters
import org.jetbrains.kotlin.js.facade.TranslationUnit import org.jetbrains.kotlin.js.facade.TranslationUnit
import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.parsing.parseBoolean import org.jetbrains.kotlin.parsing.parseBoolean
import org.jetbrains.kotlin.serialization.js.ModuleKind
import org.jetbrains.kotlin.test.TargetBackend import org.jetbrains.kotlin.test.TargetBackend
import org.jetbrains.kotlin.utils.fileUtils.withReplacedExtensionOrNull import org.jetbrains.kotlin.utils.fileUtils.withReplacedExtensionOrNull
import java.io.File import java.io.File
@@ -180,6 +180,7 @@ abstract class BasicIrBoxTest(
configuration = config.configuration, configuration = config.configuration,
allDependencies = resolvedLibraries, allDependencies = resolvedLibraries,
friendDependencies = emptyList(), friendDependencies = emptyList(),
irFactory = IrFactoryImpl,
outputKlibPath = actualOutputFile, outputKlibPath = actualOutputFile,
nopack = true nopack = true
) )
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.scripting.repl.js.test
import org.jetbrains.kotlin.backend.common.serialization.signature.IdSignatureDescriptor import org.jetbrains.kotlin.backend.common.serialization.signature.IdSignatureDescriptor
import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsManglerDesc import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsManglerDesc
import org.jetbrains.kotlin.ir.backend.js.utils.NameTables import org.jetbrains.kotlin.ir.backend.js.utils.NameTables
import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl
import org.jetbrains.kotlin.ir.util.SymbolTable import org.jetbrains.kotlin.ir.util.SymbolTable
import org.jetbrains.kotlin.js.engine.ScriptEngineNashorn import org.jetbrains.kotlin.js.engine.ScriptEngineNashorn
import org.jetbrains.kotlin.scripting.compiler.plugin.repl.ReplCodeAnalyzerBase import org.jetbrains.kotlin.scripting.compiler.plugin.repl.ReplCodeAnalyzerBase
@@ -23,9 +24,7 @@ class JsReplTestAgainstBinaries : AbstractJsReplTest() {
init { init {
val nameTable = NameTables(emptyList()) val nameTable = NameTables(emptyList())
val mangler = JsManglerDesc val compiler = JsScriptDependencyCompiler(environment.configuration, nameTable, createSymbolTable())
val signaturer = IdSignatureDescriptor(mangler)
val compiler = JsScriptDependencyCompiler(environment.configuration, nameTable, SymbolTable(signaturer))
val runtimeBinary = compiler.compile(dependencies) val runtimeBinary = compiler.compile(dependencies)
dependencyLoader.saveScriptDependencyBinary(runtimeBinary) dependencyLoader.saveScriptDependencyBinary(runtimeBinary)
@@ -34,11 +33,12 @@ class JsReplTestAgainstBinaries : AbstractJsReplTest() {
override fun createCompilationState(): JsReplCompilationState { override fun createCompilationState(): JsReplCompilationState {
val replState = ReplCodeAnalyzerBase.ResettableAnalyzerState() val replState = ReplCodeAnalyzerBase.ResettableAnalyzerState()
val mangler = JsManglerDesc return JsReplCompilationState(ReentrantReadWriteLock(), dependencyLoader.loadNames(), dependencies, replState, createSymbolTable())
val signaturer = IdSignatureDescriptor(mangler)
return JsReplCompilationState(ReentrantReadWriteLock(), dependencyLoader.loadNames(), dependencies, replState, SymbolTable(signaturer))
} }
private fun createSymbolTable(): SymbolTable =
SymbolTable(IdSignatureDescriptor(JsManglerDesc), IrFactoryImpl)
override fun createEvaluationState(): JsEvaluationState { override fun createEvaluationState(): JsEvaluationState {
val state = JsEvaluationState(ReentrantReadWriteLock(), ScriptEngineNashorn()) val state = JsEvaluationState(ReentrantReadWriteLock(), ScriptEngineNashorn())
JsReplEvaluator().eval(state, createCompileResult(dependencyLoader.loadScriptDependencyBinary())) JsReplEvaluator().eval(state, createCompileResult(dependencyLoader.loadScriptDependencyBinary()))
@@ -9,6 +9,7 @@ import com.intellij.openapi.util.Disposer
import org.jetbrains.kotlin.backend.common.serialization.signature.IdSignatureDescriptor import org.jetbrains.kotlin.backend.common.serialization.signature.IdSignatureDescriptor
import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsManglerDesc import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsManglerDesc
import org.jetbrains.kotlin.ir.backend.js.utils.NameTables import org.jetbrains.kotlin.ir.backend.js.utils.NameTables
import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl
import org.jetbrains.kotlin.ir.util.SymbolTable import org.jetbrains.kotlin.ir.util.SymbolTable
import org.jetbrains.kotlin.js.engine.ScriptEngineNashorn import org.jetbrains.kotlin.js.engine.ScriptEngineNashorn
import org.jetbrains.kotlin.scripting.compiler.plugin.repl.ReplCodeAnalyzerBase import org.jetbrains.kotlin.scripting.compiler.plugin.repl.ReplCodeAnalyzerBase
@@ -21,9 +22,7 @@ class JsReplTestAgainstKlib : AbstractJsReplTest() {
override fun createCompilationState(): JsReplCompilationState { override fun createCompilationState(): JsReplCompilationState {
val nameTables = NameTables(emptyList()) val nameTables = NameTables(emptyList())
val mangler = JsManglerDesc val symbolTable = SymbolTable(IdSignatureDescriptor(JsManglerDesc), IrFactoryImpl)
val signaturer = IdSignatureDescriptor(mangler)
val symbolTable = SymbolTable(signaturer)
val dependencyCompiler = JsScriptDependencyCompiler(environment.configuration, nameTables, symbolTable) val dependencyCompiler = JsScriptDependencyCompiler(environment.configuration, nameTables, symbolTable)
val dependencies = readLibrariesFromConfiguration(environment.configuration) val dependencies = readLibrariesFromConfiguration(environment.configuration)
dependencyCode = dependencyCompiler.compile(dependencies) dependencyCode = dependencyCompiler.compile(dependencies)
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
import org.jetbrains.kotlin.descriptors.ModuleDescriptor import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsManglerDesc import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsManglerDesc
import org.jetbrains.kotlin.ir.backend.js.utils.NameTables import org.jetbrains.kotlin.ir.backend.js.utils.NameTables
import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl
import org.jetbrains.kotlin.ir.util.SymbolTable import org.jetbrains.kotlin.ir.util.SymbolTable
import org.jetbrains.kotlin.scripting.compiler.plugin.ScriptCompilerProxy import org.jetbrains.kotlin.scripting.compiler.plugin.ScriptCompilerProxy
import org.jetbrains.kotlin.scripting.repl.js.JsCompiledScript import org.jetbrains.kotlin.scripting.repl.js.JsCompiledScript
@@ -22,7 +23,7 @@ import kotlin.script.experimental.api.*
class JsScriptCompilerWithDependenciesProxy(private val environment: KotlinCoreEnvironment) : ScriptCompilerProxy { class JsScriptCompilerWithDependenciesProxy(private val environment: KotlinCoreEnvironment) : ScriptCompilerProxy {
private val nameTables = NameTables(emptyList()) private val nameTables = NameTables(emptyList())
private val symbolTable = SymbolTable(IdSignatureDescriptor(JsManglerDesc)) private val symbolTable = SymbolTable(IdSignatureDescriptor(JsManglerDesc), IrFactoryImpl)
private val dependencies: List<ModuleDescriptor> = readLibrariesFromConfiguration(environment.configuration) private val dependencies: List<ModuleDescriptor> = readLibrariesFromConfiguration(environment.configuration)
private val compiler = JsCoreScriptingCompiler(environment, nameTables, symbolTable, dependencies) private val compiler = JsCoreScriptingCompiler(environment, nameTables, symbolTable, dependencies)
private var scriptDependencyCompiler: JsScriptDependencyCompiler? = private var scriptDependencyCompiler: JsScriptDependencyCompiler? =
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.cli.common.repl.*
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsManglerDesc import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsManglerDesc
import org.jetbrains.kotlin.ir.backend.js.utils.NameTables import org.jetbrains.kotlin.ir.backend.js.utils.NameTables
import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl
import org.jetbrains.kotlin.ir.util.SymbolTable import org.jetbrains.kotlin.ir.util.SymbolTable
import org.jetbrains.kotlin.scripting.compiler.plugin.repl.ReplCodeAnalyzerBase import org.jetbrains.kotlin.scripting.compiler.plugin.repl.ReplCodeAnalyzerBase
import java.util.concurrent.locks.ReentrantReadWriteLock import java.util.concurrent.locks.ReentrantReadWriteLock
@@ -23,7 +24,7 @@ class JsReplCompiler(private val environment: KotlinCoreEnvironment) : ReplCompi
NameTables(emptyList()), NameTables(emptyList()),
readLibrariesFromConfiguration(environment.configuration), readLibrariesFromConfiguration(environment.configuration),
ReplCodeAnalyzerBase.ResettableAnalyzerState(), ReplCodeAnalyzerBase.ResettableAnalyzerState(),
SymbolTable(IdSignatureDescriptor(JsManglerDesc)) SymbolTable(IdSignatureDescriptor(JsManglerDesc), IrFactoryImpl)
) )
} }