From 76e629340fb66b9d34cb1b1ca62061fc4b48ba8c Mon Sep 17 00:00:00 2001 From: Artem Kobzar Date: Fri, 2 Dec 2022 13:28:18 +0000 Subject: [PATCH] [K/JS] Add miss LazyIr into klib Ir generation process --- .../jetbrains/kotlin/cli/js/klib/irForKlib.kt | 20 +++- .../jetbrains/kotlin/ir/backend/js/klib.kt | 98 ------------------- 2 files changed, 18 insertions(+), 100 deletions(-) diff --git a/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/klib/irForKlib.kt b/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/klib/irForKlib.kt index 70d437b0220..acfd2172be7 100644 --- a/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/klib/irForKlib.kt +++ b/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/klib/irForKlib.kt @@ -14,6 +14,7 @@ import com.intellij.openapi.project.Project import org.jetbrains.kotlin.analyzer.AnalysisResult import org.jetbrains.kotlin.backend.common.lower.ExpectDeclarationRemover import org.jetbrains.kotlin.backend.common.overrides.FakeOverrideChecker +import org.jetbrains.kotlin.backend.common.serialization.DescriptorByIdSignatureFinderImpl import org.jetbrains.kotlin.backend.common.serialization.ICData import org.jetbrains.kotlin.backend.common.serialization.linkerissues.checkNoUnboundSymbols import org.jetbrains.kotlin.backend.common.serialization.mangle.ManglerChecker @@ -41,6 +42,7 @@ import org.jetbrains.kotlin.library.KotlinLibrary import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.psi2ir.Psi2IrConfiguration import org.jetbrains.kotlin.psi2ir.Psi2IrTranslator +import org.jetbrains.kotlin.psi2ir.generators.DeclarationStubGeneratorImpl fun generateIrForKlibSerialization( project: Project, @@ -69,6 +71,12 @@ fun generateIrForKlibSerialization( val feContext = psi2IrContext.run { JsIrLinker.JsFePluginContext(moduleDescriptor, symbolTable, typeTranslator, irBuiltIns) } + val stubGenerator = DeclarationStubGeneratorImpl( + psi2IrContext.moduleDescriptor, + symbolTable, + irBuiltIns, + DescriptorByIdSignatureFinderImpl(psi2IrContext.moduleDescriptor, JsManglerDesc), + ) val irLinker = JsIrLinker( psi2IrContext.moduleDescriptor, messageLogger, @@ -76,12 +84,20 @@ fun generateIrForKlibSerialization( psi2IrContext.symbolTable, partialLinkageEnabled = configuration[JSConfigurationKeys.PARTIAL_LINKAGE] ?: false, feContext, - ICData(icData.map { it.irData }, errorPolicy.allowErrors) + ICData(icData.map { it.irData }, errorPolicy.allowErrors), + stubGenerator = stubGenerator ) sortedDependencies.map { irLinker.deserializeOnlyHeaderModule(getDescriptorByLibrary(it), it) } - val moduleFragment = psi2IrContext.generateModuleFragmentWithPlugins(project, files, irLinker, messageLogger, expectDescriptorToSymbol) + val moduleFragment = psi2IrContext.generateModuleFragmentWithPlugins( + project, + files, + irLinker, + messageLogger, + expectDescriptorToSymbol, + stubGenerator + ) if (verifySignatures) { moduleFragment.acceptVoid(ManglerChecker(JsManglerIr, Ir2DescriptorManglerAdapter(JsManglerDesc))) 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 9b135c9874d..251397954e8 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 @@ -110,104 +110,6 @@ val CompilerConfiguration.resolverLogger: Logger class KotlinFileSerializedData(val metadata: ByteArray, val irData: SerializedIrFile) -fun generateIrForKlibSerialization( - project: Project, - files: List, - configuration: CompilerConfiguration, - analysisResult: AnalysisResult, - sortedDependencies: Collection, - icData: MutableList, - expectDescriptorToSymbol: MutableMap, - irFactory: IrFactory, - verifySignatures: Boolean = true, - getDescriptorByLibrary: (KotlinLibrary) -> ModuleDescriptor, -): IrModuleFragment { - val incrementalDataProvider = configuration.get(JSConfigurationKeys.INCREMENTAL_DATA_PROVIDER) - val errorPolicy = configuration.get(JSConfigurationKeys.ERROR_TOLERANCE_POLICY) ?: ErrorTolerancePolicy.DEFAULT - val messageLogger = configuration.irMessageLogger - val partialLinkageEnabled = configuration[JSConfigurationKeys.PARTIAL_LINKAGE] ?: false - - val serializedIrFiles = mutableListOf() - - if (incrementalDataProvider != null) { - val nonCompiledSources = files.map { VfsUtilCore.virtualToIoFile(it.virtualFile) to it }.toMap() - val compiledIrFiles = incrementalDataProvider.serializedIrFiles - val compiledMetaFiles = incrementalDataProvider.compiledPackageParts - - assert(compiledIrFiles.size == compiledMetaFiles.size) - - val storage = mutableListOf() - - for (f in compiledIrFiles.keys) { - if (f in nonCompiledSources) continue - - val irData = compiledIrFiles[f] ?: error("No Ir Data found for file $f") - val metaFile = compiledMetaFiles[f] ?: error("No Meta Data found for file $f") - val irFile = with(irData) { - SerializedIrFile(fileData, String(fqn), f.path.replace('\\', '/'), types, signatures, strings, bodies, declarations, debugInfo) - } - storage.add(KotlinFileSerializedData(metaFile.metadata, irFile)) - } - - icData.addAll(storage) - serializedIrFiles.addAll(storage.map { it.irData }) - } - - val symbolTable = SymbolTable(IdSignatureDescriptor(JsManglerDesc), irFactory) - val psi2Ir = Psi2IrTranslator( - configuration.languageVersionSettings, - Psi2IrConfiguration(errorPolicy.allowErrors, partialLinkageEnabled), - messageLogger::checkNoUnboundSymbols - ) - val psi2IrContext = psi2Ir.createGeneratorContext(analysisResult.moduleDescriptor, analysisResult.bindingContext, symbolTable) - val irBuiltIns = psi2IrContext.irBuiltIns - - val feContext = psi2IrContext.run { - JsIrLinker.JsFePluginContext(moduleDescriptor, symbolTable, typeTranslator, irBuiltIns) - } - val stubGenerator = DeclarationStubGeneratorImpl( - psi2IrContext.moduleDescriptor, - symbolTable, - irBuiltIns, - DescriptorByIdSignatureFinderImpl(psi2IrContext.moduleDescriptor, JsManglerDesc), - ) - val irLinker = JsIrLinker( - psi2IrContext.moduleDescriptor, - messageLogger, - psi2IrContext.irBuiltIns, - psi2IrContext.symbolTable, - partialLinkageEnabled = partialLinkageEnabled, - feContext, - ICData(serializedIrFiles, errorPolicy.allowErrors), - stubGenerator = stubGenerator - ) - - sortedDependencies.map { irLinker.deserializeOnlyHeaderModule(getDescriptorByLibrary(it), it) } - - val moduleFragment = psi2IrContext.generateModuleFragmentWithPlugins( - project, - files, - irLinker, - messageLogger, - expectDescriptorToSymbol, - stubGenerator - ) - - if (verifySignatures) { - moduleFragment.acceptVoid(ManglerChecker(JsManglerIr, Ir2DescriptorManglerAdapter(JsManglerDesc))) - } - if (configuration.getBoolean(JSConfigurationKeys.FAKE_OVERRIDE_VALIDATOR)) { - val fakeOverrideChecker = FakeOverrideChecker(JsManglerIr, JsManglerDesc) - irLinker.modules.forEach { fakeOverrideChecker.check(it) } - } - - if (!configuration.expectActualLinker) { - moduleFragment.transform(ExpectDeclarationRemover(psi2IrContext.symbolTable, false), null) - } - - return moduleFragment -} - fun generateKLib( depsDescriptors: ModulesStructure, outputKlibPath: String,