[JS IR] IR module to name

Merge-request: KT-MR-5672
Merged-by: Ilya Goncharov <Ilya.Goncharov@jetbrains.com>
This commit is contained in:
Ilya Goncharov
2022-02-03 17:28:46 +00:00
committed by Space
parent 11bbd79c4b
commit a2167200d6
5 changed files with 36 additions and 7 deletions
@@ -410,6 +410,7 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
ir.context,
mainCallArguments,
relativeRequirePath = true,
moduleToName = ir.moduleFragmentToUniqueName
)
transformer.generateModule(ir.allModules, setOf(TranslationMode.fromFlags(arguments.irDce, arguments.irPerModule)))
@@ -421,6 +422,7 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
dceJs = arguments.irDce,
multiModule = arguments.irPerModule,
relativeRequirePath = true,
moduleToName = ir.moduleFragmentToUniqueName
)
transformer.generateModule(ir.allModules)
@@ -41,7 +41,8 @@ class CompilationOutputs(
class LoweredIr(
val context: JsIrBackendContext,
val mainModule: IrModuleFragment,
val allModules: List<IrModuleFragment>
val allModules: List<IrModuleFragment>,
val moduleFragmentToUniqueName: Map<IrModuleFragment, String>,
)
fun compile(
@@ -60,7 +61,7 @@ fun compile(
icCompatibleIr2Js: Boolean = false,
): LoweredIr {
val (moduleFragment: IrModuleFragment, dependencyModules, irBuiltIns, symbolTable, deserializer) =
val (moduleFragment: IrModuleFragment, dependencyModules, irBuiltIns, symbolTable, deserializer, moduleToName) =
loadIr(depsDescriptors, irFactory, verifySignatures, filesToLower, loadFunctionInterfacesIntoStdlib = true)
return compileIr(
@@ -68,6 +69,7 @@ fun compile(
depsDescriptors.mainModule,
depsDescriptors.compilerConfiguration,
dependencyModules,
moduleToName,
irBuiltIns,
symbolTable,
deserializer,
@@ -88,6 +90,7 @@ fun compileIr(
mainModule: MainModule,
configuration: CompilerConfiguration,
dependencyModules: List<IrModuleFragment>,
moduleToName: Map<IrModuleFragment, String>,
irBuiltIns: IrBuiltIns,
symbolTable: SymbolTable,
deserializer: JsIrLinker,
@@ -147,7 +150,7 @@ fun compileIr(
lowerPreservingTags(allModules, context, phaseConfig, it)
} ?: jsPhases.invokeToplevel(phaseConfig, context, allModules)
return LoweredIr(context, moduleFragment, allModules)
return LoweredIr(context, moduleFragment, allModules, moduleToName)
}
fun generateJsCode(
@@ -331,7 +331,7 @@ fun generateWrappedModuleBody(
)
val dependencies = others.map { module ->
val moduleName = module.moduleName
val moduleName = module.externalModuleName
moduleName to generateSingleWrappedModuleBody(
moduleName,
@@ -244,7 +244,8 @@ data class IrModuleInfo(
val allDependencies: List<IrModuleFragment>,
val bultins: IrBuiltIns,
val symbolTable: SymbolTable,
val deserializer: JsIrLinker
val deserializer: JsIrLinker,
val moduleFragmentToUniqueName: Map<IrModuleFragment, String>,
)
fun sortDependencies(mapping: Map<KotlinLibrary, ModuleDescriptor>): Collection<KotlinLibrary> {
@@ -390,7 +391,14 @@ fun getIrModuleInfoForKlib(
ExternalDependenciesGenerator(symbolTable, listOf(irLinker)).generateUnboundSymbolsAsDependencies()
irLinker.postProcess()
return IrModuleInfo(moduleFragment, deserializedModuleFragments, irBuiltIns, symbolTable, irLinker)
return IrModuleInfo(
moduleFragment,
deserializedModuleFragments,
irBuiltIns,
symbolTable,
irLinker,
deserializedModuleFragmentsToLib.getUniqueNameForEachFragment()
)
}
@OptIn(ObsoleteDescriptorBasedAPI::class)
@@ -457,7 +465,14 @@ fun getIrModuleInfoForSourceFiles(
irBuiltIns.knownBuiltins.forEach { it.acceptVoid(mangleChecker) }
}
return IrModuleInfo(moduleFragment, deserializedModuleFragments, irBuiltIns, symbolTable, irLinker)
return IrModuleInfo(
moduleFragment,
deserializedModuleFragments,
irBuiltIns,
symbolTable,
irLinker,
deserializedModuleFragmentsToLib.getUniqueNameForEachFragment()
)
}
fun prepareAnalyzedSourceModule(
@@ -830,3 +845,11 @@ private fun KlibMetadataIncrementalSerializer(configuration: CompilerConfigurati
skipExpects = !configuration.expectActualLinker,
allowErrorTypes = allowErrors
)
private fun Map<IrModuleFragment, KotlinLibrary>.getUniqueNameForEachFragment(): Map<IrModuleFragment, String> {
return this.entries.mapNotNull { (moduleFragment, klib) ->
klib.manifestProperties.getProperty(KLIB_PROPERTY_JS_OUTPUT_NAME)?.let {
moduleFragment to it
}
}.toMap()
}
@@ -128,6 +128,7 @@ class JsIrBackendFacade(
MainModule.Klib(inputArtifact.outputFile.absolutePath),
configuration,
dependencyModules,
emptyMap(),
irModuleFragment.irBuiltins,
symbolTable,
deserializer,