diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/compiler/based/LowLevelFirAnalyzerFacade.kt b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/compiler/based/LowLevelFirAnalyzerFacade.kt index 296c6824711..530525592d7 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/compiler/based/LowLevelFirAnalyzerFacade.kt +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/compiler/based/LowLevelFirAnalyzerFacade.kt @@ -16,6 +16,7 @@ import org.jetbrains.kotlin.fir.backend.Fir2IrResult import org.jetbrains.kotlin.fir.declarations.FirFile import org.jetbrains.kotlin.fir.psi import org.jetbrains.kotlin.fir.resolve.ScopeSession +import org.jetbrains.kotlin.ir.util.SymbolTable import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.test.model.TestFile @@ -37,7 +38,11 @@ class LowLevelFirAnalyzerFacade( } override fun runResolution(): List = shouldNotBeCalled() - override fun convertToIr(fir2IrExtensions: Fir2IrExtensions, dependentComponents: List): Fir2IrResult = shouldNotBeCalled() + override fun convertToIr( + fir2IrExtensions: Fir2IrExtensions, + dependentComponents: List, + symbolTable: SymbolTable? + ): Fir2IrResult = shouldNotBeCalled() } private fun shouldNotBeCalled(): Nothing = error("Should not be called for LL test") 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 92949a54f20..263433516d0 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 @@ -597,7 +597,8 @@ class K2JsIrCompiler : CLICompiler() { IrGenerationExtension.getInstances(environmentForJS.project), generateSignatures = false, kotlinBuiltIns = builtInsModule ?: DefaultBuiltIns.Instance, // TODO: consider passing externally - dependentComponents = emptyList() + dependentComponents = emptyList(), + currentSymbolTable = null ).also { (it.irModuleFragment.descriptor as? FirModuleDescriptor)?.let { it.allDependencyModules = librariesDescriptors } } diff --git a/compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/pipeline/convertToIr.kt b/compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/pipeline/convertToIr.kt index 312ace2556f..08304350fea 100644 --- a/compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/pipeline/convertToIr.kt +++ b/compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/pipeline/convertToIr.kt @@ -23,6 +23,7 @@ import org.jetbrains.kotlin.fir.resolve.ScopeSession import org.jetbrains.kotlin.ir.backend.jvm.serialization.JvmDescriptorMangler import org.jetbrains.kotlin.ir.backend.jvm.serialization.JvmIrMangler import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl +import org.jetbrains.kotlin.ir.util.SymbolTable data class FirResult( val platformOutput: ModuleCompilerAnalyzedOutput, @@ -47,13 +48,15 @@ fun FirResult.convertToIrAndActualize( fir2IrExtensions, irGeneratorExtensions, linkViaSignatures = linkViaSignatures, - dependentComponents = emptyList() + dependentComponents = emptyList(), + currentSymbolTable = null ) result = platformOutput.convertToIr( fir2IrExtensions, irGeneratorExtensions, linkViaSignatures = linkViaSignatures, - dependentComponents = listOf(commonIrOutput.components) + dependentComponents = listOf(commonIrOutput.components), + currentSymbolTable = commonIrOutput.components.symbolTable ) IrActualizer.actualize( result.irModuleFragment, @@ -64,7 +67,8 @@ fun FirResult.convertToIrAndActualize( fir2IrExtensions, irGeneratorExtensions, linkViaSignatures = linkViaSignatures, - dependentComponents = emptyList() + dependentComponents = emptyList(), + currentSymbolTable = null ) } @@ -75,7 +79,8 @@ private fun ModuleCompilerAnalyzedOutput.convertToIr( fir2IrExtensions: Fir2IrExtensions, irGeneratorExtensions: Collection, linkViaSignatures: Boolean, - dependentComponents: List + dependentComponents: List, + currentSymbolTable: SymbolTable? ): Fir2IrResult { if (linkViaSignatures) { val signaturer = JvmIdSignatureDescriptor(mangler = JvmDescriptorMangler(mainDetector = null)) @@ -88,7 +93,8 @@ private fun ModuleCompilerAnalyzedOutput.convertToIr( irGeneratorExtensions, kotlinBuiltIns = DefaultBuiltIns.Instance, // TODO: consider passing externally generateSignatures = true, - dependentComponents = dependentComponents + dependentComponents = dependentComponents, + currentSymbolTable = currentSymbolTable ) } else { return Fir2IrConverter.createModuleFragmentWithoutSignatures( @@ -99,7 +105,8 @@ private fun ModuleCompilerAnalyzedOutput.convertToIr( Fir2IrJvmSpecialAnnotationSymbolProvider(), irGeneratorExtensions, kotlinBuiltIns = DefaultBuiltIns.Instance, // TODO: consider passing externally, - dependentComponents = dependentComponents + dependentComponents = dependentComponents, + currentSymbolTable = currentSymbolTable ) } } diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrConverter.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrConverter.kt index a890d2ed0b1..54218b1e371 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrConverter.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrConverter.kt @@ -439,21 +439,22 @@ class Fir2IrConverter( irGenerationExtensions: Collection, generateSignatures: Boolean, kotlinBuiltIns: KotlinBuiltIns, - dependentComponents: List + dependentComponents: List, + currentSymbolTable: SymbolTable? ): Fir2IrResult { if (!generateSignatures) { return createModuleFragmentWithoutSignatures( session, scopeSession, firFiles, languageVersionSettings, fir2IrExtensions, mangler, irMangler, irFactory, visibilityConverter, specialSymbolProvider, irGenerationExtensions, - kotlinBuiltIns, dependentComponents + kotlinBuiltIns, dependentComponents, currentSymbolTable ) } val signatureComposer = FirBasedSignatureComposer( mangler, dependentComposers = dependentComponents.map { it.signatureComposer as FirBasedSignatureComposer } ) - val symbolTable = createSymbolTable(signaturer, signatureComposer, irFactory, dependentComponents) + val symbolTable = createSymbolTable(signaturer, signatureComposer, irFactory, currentSymbolTable) return createModuleFragmentWithSymbolTable( session, scopeSession, firFiles, languageVersionSettings, fir2IrExtensions, irMangler, irFactory, visibilityConverter, @@ -475,11 +476,12 @@ class Fir2IrConverter( specialSymbolProvider: Fir2IrSpecialSymbolProvider, irGenerationExtensions: Collection, kotlinBuiltIns: KotlinBuiltIns, - dependentComponents: List + dependentComponents: List, + currentSymbolTable: SymbolTable? ): Fir2IrResult { val signatureComposer = FirBasedSignatureComposer(mangler, dependentComposers = dependentComponents.map { it.signatureComposer as FirBasedSignatureComposer }) val signaturer = DescriptorSignatureComposerStub() - val symbolTable = createSymbolTable(signaturer, signatureComposer, irFactory, dependentComponents) + val symbolTable = createSymbolTable(signaturer, signatureComposer, irFactory, currentSymbolTable) return createModuleFragmentWithSymbolTable( session, scopeSession, firFiles, languageVersionSettings, fir2IrExtensions, irMangler, irFactory, visibilityConverter, @@ -492,9 +494,9 @@ class Fir2IrConverter( signaturer: IdSignatureComposer, signatureComposer: FirBasedSignatureComposer, irFactory: IrFactory, - dependentComponents: List + currentSymbolTable: SymbolTable? ): SymbolTable = - dependentComponents.lastOrNull()?.symbolTable ?: SymbolTable( + currentSymbolTable ?: SymbolTable( signaturer = WrappedDescriptorSignatureComposer(signaturer, signatureComposer), irFactory = irFactory ) diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/fir/Fir2IrJsResultsConverter.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/fir/Fir2IrJsResultsConverter.kt index 7ccd87d56d8..9b9e786779d 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/fir/Fir2IrJsResultsConverter.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/fir/Fir2IrJsResultsConverter.kt @@ -127,7 +127,8 @@ fun AbstractFirAnalyzerFacade.convertToJsIr( irGeneratorExtensions, generateSignatures = false, kotlinBuiltIns = builtIns ?: DefaultBuiltIns.Instance, // TODO: consider passing externally, - dependentComponents = emptyList() + dependentComponents = emptyList(), + currentSymbolTable = null ).also { (it.irModuleFragment.descriptor as? FirModuleDescriptor)?.let { it.allDependencyModules = dependencies } } diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/fir/Fir2IrResultsConverter.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/fir/Fir2IrResultsConverter.kt index 2390dc4a253..02b78fc3313 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/fir/Fir2IrResultsConverter.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/fir/Fir2IrResultsConverter.kt @@ -20,6 +20,7 @@ import org.jetbrains.kotlin.fir.backend.jvm.FirJvmBackendExtension import org.jetbrains.kotlin.fir.backend.jvm.JvmFir2IrExtensions import org.jetbrains.kotlin.fir.psi import org.jetbrains.kotlin.ir.backend.jvm.serialization.JvmIrMangler +import org.jetbrains.kotlin.ir.util.SymbolTable import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.resolve.CompilerEnvironment import org.jetbrains.kotlin.resolve.lazy.declarations.FileBasedDeclarationProviderFactory @@ -67,6 +68,7 @@ class Fir2IrResultsConverter( val dependentIrParts = mutableListOf() lateinit var mainIrPart: JvmIrCodegenFactory.JvmIrBackendInput + var currentSymbolTable: SymbolTable? = null for ((index, firOutputPart) in inputArtifact.partsForDependsOnModules.withIndex()) { val dependentComponents = mutableListOf() if (isMppSupported) { @@ -75,7 +77,10 @@ class Fir2IrResultsConverter( } } - val (irModuleFragment, components, pluginContext) = firOutputPart.firAnalyzerFacade.convertToIr(fir2IrExtensions, dependentComponents) + val (irModuleFragment, components, pluginContext) = firOutputPart.firAnalyzerFacade.convertToIr( + fir2IrExtensions, dependentComponents, currentSymbolTable + ) + currentSymbolTable = components.symbolTable componentsMap[firOutputPart.module.name] = components val irPart = JvmIrCodegenFactory.JvmIrBackendInput( diff --git a/compiler/tests-compiler-utils/tests/org/jetbrains/kotlin/codegen/GenerationUtils.kt b/compiler/tests-compiler-utils/tests/org/jetbrains/kotlin/codegen/GenerationUtils.kt index f05e1c7fe68..e29859b5635 100644 --- a/compiler/tests-compiler-utils/tests/org/jetbrains/kotlin/codegen/GenerationUtils.kt +++ b/compiler/tests-compiler-utils/tests/org/jetbrains/kotlin/codegen/GenerationUtils.kt @@ -123,7 +123,11 @@ object GenerationUtils { generateSignatures = false ) val fir2IrExtensions = JvmFir2IrExtensions(configuration, JvmIrDeserializerImpl(), JvmIrMangler) - val (moduleFragment, components, pluginContext) = firAnalyzerFacade.convertToIr(fir2IrExtensions, dependentComponents = emptyList()) + val (moduleFragment, components, pluginContext) = firAnalyzerFacade.convertToIr( + fir2IrExtensions, + dependentComponents = emptyList(), + symbolTable = null + ) val dummyBindingContext = NoScopeRecordCliBindingTrace().bindingContext val codegenFactory = JvmIrCodegenFactory( diff --git a/compiler/tests-compiler-utils/tests/org/jetbrains/kotlin/fir/FirAnalyzerFacade.kt b/compiler/tests-compiler-utils/tests/org/jetbrains/kotlin/fir/FirAnalyzerFacade.kt index 957722634f8..12ff5063962 100644 --- a/compiler/tests-compiler-utils/tests/org/jetbrains/kotlin/fir/FirAnalyzerFacade.kt +++ b/compiler/tests-compiler-utils/tests/org/jetbrains/kotlin/fir/FirAnalyzerFacade.kt @@ -29,6 +29,7 @@ import org.jetbrains.kotlin.fir.resolve.transformers.FirTotalResolveProcessor import org.jetbrains.kotlin.ir.backend.jvm.serialization.JvmDescriptorMangler import org.jetbrains.kotlin.ir.backend.jvm.serialization.JvmIrMangler import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl +import org.jetbrains.kotlin.ir.util.SymbolTable import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.sourceFiles.LightTreeFile @@ -38,7 +39,11 @@ abstract class AbstractFirAnalyzerFacade { abstract fun runResolution(): List - abstract fun convertToIr(fir2IrExtensions: Fir2IrExtensions, dependentComponents: List): Fir2IrResult + abstract fun convertToIr( + fir2IrExtensions: Fir2IrExtensions, + dependentComponents: List, + symbolTable: SymbolTable? + ): Fir2IrResult } class FirAnalyzerFacade( @@ -87,7 +92,6 @@ class FirAnalyzerFacade( return firFiles!! } - @OptIn(ExperimentalStdlibApi::class) override fun runCheckers(): Map> { if (_scopeSession == null) runResolution() if (collectedDiagnostics != null) return collectedDiagnostics!! @@ -104,7 +108,11 @@ class FirAnalyzerFacade( return collectedDiagnostics!! } - override fun convertToIr(fir2IrExtensions: Fir2IrExtensions, dependentComponents: List): Fir2IrResult { + override fun convertToIr( + fir2IrExtensions: Fir2IrExtensions, + dependentComponents: List, + symbolTable: SymbolTable? + ): Fir2IrResult { if (_scopeSession == null) runResolution() val mangler = JvmDescriptorMangler(null) val signaturer = JvmIdSignatureDescriptor(mangler) @@ -119,7 +127,8 @@ class FirAnalyzerFacade( irGeneratorExtensions, generateSignatures, kotlinBuiltIns = DefaultBuiltIns.Instance, // TODO: consider passing externally, - dependentComponents = dependentComponents + dependentComponents = dependentComponents, + currentSymbolTable = symbolTable ) } } diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/Fir2Ir.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/Fir2Ir.kt index ef35379e049..b6307f8de42 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/Fir2Ir.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/Fir2Ir.kt @@ -79,7 +79,8 @@ internal fun PhaseContext.fir2Ir( IrGenerationExtension.getInstances(config.project), generateSignatures = false, kotlinBuiltIns = builtInsModule ?: DefaultBuiltIns.Instance, // TODO: consider passing externally - dependentComponents = emptyList() + dependentComponents = emptyList(), + currentSymbolTable = null ).also { (it.irModuleFragment.descriptor as? FirModuleDescriptor)?.let { it.allDependencyModules = librariesDescriptors } }