[JS IR] Support a module friendship in IC infrastructure
^KT-55097 Fixed
This commit is contained in:
committed by
Space Team
parent
76e629340f
commit
c31705240a
@@ -275,7 +275,15 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
|
||||
// TODO: Handle non-empty main call arguments
|
||||
val mainCallArguments = if (K2JsArgumentConstants.NO_CALL == arguments.main) null else emptyList<String>()
|
||||
|
||||
val icCaches = prepareIcCaches(arguments, messageCollector, outputDir, libraries, configurationJs, mainCallArguments)
|
||||
val icCaches = prepareIcCaches(
|
||||
arguments = arguments,
|
||||
messageCollector = messageCollector,
|
||||
outputDir = outputDir,
|
||||
libraries = libraries,
|
||||
friendLibraries = friendLibraries,
|
||||
configurationJs = configurationJs,
|
||||
mainCallArguments = mainCallArguments
|
||||
)
|
||||
|
||||
// Run analysis if main module is sources
|
||||
var sourceModule: ModulesStructure? = null
|
||||
@@ -638,6 +646,7 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
|
||||
messageCollector: MessageCollector,
|
||||
outputDir: File,
|
||||
libraries: List<String>,
|
||||
friendLibraries: List<String>,
|
||||
configurationJs: CompilerConfiguration,
|
||||
mainCallArguments: List<String>?
|
||||
): List<ModuleArtifact> {
|
||||
@@ -656,6 +665,7 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
|
||||
val cacheUpdater = CacheUpdater(
|
||||
mainModule = arguments.includes!!,
|
||||
allModules = libraries,
|
||||
mainModuleFriends = friendLibraries,
|
||||
cacheDir = cacheDirectory,
|
||||
compilerConfiguration = configurationJs,
|
||||
irFactory = { IrFactoryImplForJsIC(WholeWorldStageController()) },
|
||||
|
||||
@@ -50,6 +50,7 @@ enum class DirtyFileState(val str: String) {
|
||||
class CacheUpdater(
|
||||
mainModule: String,
|
||||
private val allModules: Collection<String>,
|
||||
private val mainModuleFriends: Collection<String>,
|
||||
cacheDir: String,
|
||||
private val compilerConfiguration: CompilerConfiguration,
|
||||
private val irFactory: () -> IrFactory,
|
||||
@@ -105,6 +106,11 @@ class CacheUpdater(
|
||||
}
|
||||
}
|
||||
|
||||
val mainModuleFriendLibraries = libraryDependencies.keys.let { libs ->
|
||||
val friendPaths = mainModuleFriends.mapTo(HashSet(mainModuleFriends.size)) { File(it).canonicalPath }
|
||||
libs.filter { it.libraryFile.canonicalPath in friendPaths }
|
||||
}
|
||||
|
||||
private val incrementalCaches = libraryDependencies.keys.associate { lib ->
|
||||
val libFile = KotlinLibraryFile(lib)
|
||||
val file = File(libFile.path)
|
||||
@@ -591,7 +597,12 @@ class CacheUpdater(
|
||||
val dirtyFileExports = updater.collectExportedSymbolsForDirtyFiles(modifiedFiles)
|
||||
|
||||
stopwatch.startNext("Modified files - loading and linking IR")
|
||||
val jsIrLinkerLoader = JsIrLinkerLoader(compilerConfiguration, updater.libraryDependencies, irFactory())
|
||||
val jsIrLinkerLoader = JsIrLinkerLoader(
|
||||
compilerConfiguration = compilerConfiguration,
|
||||
dependencyGraph = updater.libraryDependencies,
|
||||
mainModuleFriends = updater.mainModuleFriendLibraries,
|
||||
irFactory = irFactory()
|
||||
)
|
||||
var loadedIr = jsIrLinkerLoader.loadIr(dirtyFileExports)
|
||||
|
||||
var iterations = 0
|
||||
@@ -703,7 +714,7 @@ fun rebuildCacheForDirtyFiles(
|
||||
val dirtySrcFiles = dirtyFiles?.map { KotlinSourceFile(it) } ?: KotlinLoadedLibraryHeader(library).sourceFileFingerprints.keys
|
||||
val modifiedFiles = mapOf(libFile to dirtySrcFiles.associateWith { emptyMetadata })
|
||||
|
||||
val jsIrLoader = JsIrLinkerLoader(configuration, dependencyGraph, irFactory)
|
||||
val jsIrLoader = JsIrLinkerLoader(configuration, dependencyGraph, emptyList(), irFactory)
|
||||
val (jsIrLinker, irModules) = jsIrLoader.loadIr(KotlinSourceFileMap<KotlinSourceFileExports>(modifiedFiles), true)
|
||||
|
||||
val currentIrModule = irModules[libFile] ?: notFoundIcError("loaded fragment", libFile)
|
||||
|
||||
+13
-2
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||
import org.jetbrains.kotlin.ir.util.irMessageLogger
|
||||
import org.jetbrains.kotlin.js.config.JSConfigurationKeys
|
||||
import org.jetbrains.kotlin.library.KotlinLibrary
|
||||
import org.jetbrains.kotlin.library.uniqueName
|
||||
import org.jetbrains.kotlin.library.unresolvedDependencies
|
||||
import org.jetbrains.kotlin.psi2ir.descriptors.IrBuiltInsOverDescriptors
|
||||
import org.jetbrains.kotlin.psi2ir.generators.TypeTranslatorImpl
|
||||
@@ -40,8 +41,11 @@ internal fun JsIrLinker.loadUnboundSymbols(checkNoUnbound: Boolean) {
|
||||
internal class JsIrLinkerLoader(
|
||||
private val compilerConfiguration: CompilerConfiguration,
|
||||
private val dependencyGraph: Map<KotlinLibrary, List<KotlinLibrary>>,
|
||||
private val mainModuleFriends: Collection<KotlinLibrary>,
|
||||
private val irFactory: IrFactory
|
||||
) {
|
||||
private val mainLibrary = dependencyGraph.keys.lastOrNull() ?: notFoundIcError("main library")
|
||||
|
||||
@OptIn(ObsoleteDescriptorBasedAPI::class)
|
||||
private fun createLinker(loadedModules: Map<ModuleDescriptor, KotlinLibrary>): JsIrLinker {
|
||||
val signaturer = IdSignatureDescriptor(JsManglerDesc)
|
||||
@@ -50,7 +54,15 @@ internal class JsIrLinkerLoader(
|
||||
val typeTranslator = TypeTranslatorImpl(symbolTable, compilerConfiguration.languageVersionSettings, moduleDescriptor)
|
||||
val irBuiltIns = IrBuiltInsOverDescriptors(moduleDescriptor.builtIns, typeTranslator, symbolTable)
|
||||
val partialLinkageEnabled = compilerConfiguration[JSConfigurationKeys.PARTIAL_LINKAGE] ?: false
|
||||
return JsIrLinker(null, compilerConfiguration.irMessageLogger, irBuiltIns, symbolTable, partialLinkageEnabled, null)
|
||||
return JsIrLinker(
|
||||
currentModule = null,
|
||||
messageLogger = compilerConfiguration.irMessageLogger,
|
||||
builtIns = irBuiltIns,
|
||||
symbolTable = symbolTable,
|
||||
partialLinkageEnabled = partialLinkageEnabled,
|
||||
translationPluginContext = null,
|
||||
friendModules = mapOf(mainLibrary.uniqueName to mainModuleFriends.map { it.uniqueName })
|
||||
)
|
||||
}
|
||||
|
||||
private fun loadModules(): Map<ModuleDescriptor, KotlinLibrary> {
|
||||
@@ -86,7 +98,6 @@ internal class JsIrLinkerLoader(
|
||||
val loadedModules = loadModules()
|
||||
val jsIrLinker = createLinker(loadedModules)
|
||||
|
||||
val mainLibrary = dependencyGraph.keys.lastOrNull() ?: notFoundIcError("main library")
|
||||
val irModules = loadedModules.entries.associate { (descriptor, module) ->
|
||||
val libraryFile = KotlinLibraryFile(module)
|
||||
val modifiedStrategy = when {
|
||||
|
||||
Reference in New Issue
Block a user