[JS IR] IC: support per-module in K2JsIrCompiler

This commit is contained in:
Anton Bannykh
2021-12-17 16:35:58 +03:00
parent ca60caa7e9
commit 4c33cb8016
5 changed files with 22 additions and 23 deletions
@@ -287,7 +287,14 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
val translationMode = TranslationMode.fromFlags(false, arguments.irPerModule) val translationMode = TranslationMode.fromFlags(false, arguments.irPerModule)
val compiledModule = generateJsFromAst(moduleName, moduleKind, SourceMapsInfo.from(configurationJs), setOf(translationMode), caches) val compiledModule = generateJsFromAst(
moduleName,
moduleKind,
SourceMapsInfo.from(configurationJs),
setOf(translationMode),
caches,
relativeRequirePath = true
)
val outputs = compiledModule.outputs.values.single() val outputs = compiledModule.outputs.values.single()
@@ -102,8 +102,6 @@ fun compileWithIC(
val ast = transformer.generateBinaryAst(dirtyFiles) val ast = transformer.generateBinaryAst(dirtyFiles)
ast.entries.forEach { (path, bytes) -> cacheConsumer.commitBinaryAst(path, bytes) } ast.entries.forEach { (path, bytes) -> cacheConsumer.commitBinaryAst(path, bytes) }
cacheConsumer.commitModuleName(module.name.asString())
} }
fun lowerPreservingTags(modules: Iterable<IrModuleFragment>, context: JsIrBackendContext, phaseConfig: PhaseConfig, controller: WholeWorldStageController) { fun lowerPreservingTags(modules: Iterable<IrModuleFragment>, context: JsIrBackendContext, phaseConfig: PhaseConfig, controller: WholeWorldStageController) {
@@ -128,6 +126,7 @@ fun generateJsFromAst(
sourceMapsInfo: SourceMapsInfo?, sourceMapsInfo: SourceMapsInfo?,
translationModes: Set<TranslationMode>, translationModes: Set<TranslationMode>,
caches: Map<String, ModuleCache>, caches: Map<String, ModuleCache>,
relativeRequirePath: Boolean = false,
): CompilerResult { ): CompilerResult {
fun compilationOutput(multiModule: Boolean): CompilationOutputs { fun compilationOutput(multiModule: Boolean): CompilationOutputs {
val deserializer = JsIrAstDeserializer() val deserializer = JsIrAstDeserializer()
@@ -144,7 +143,7 @@ fun generateJsFromAst(
moduleKind = moduleKind, moduleKind = moduleKind,
jsIrProgram, jsIrProgram,
sourceMapsInfo = sourceMapsInfo, sourceMapsInfo = sourceMapsInfo,
relativeRequirePath = false, relativeRequirePath = relativeRequirePath,
generateScriptModule = false, generateScriptModule = false,
) )
} }
@@ -205,7 +205,7 @@ private fun buildCacheForModule(
cacheExecutor.execute(irModule, dependencies, deserializer, configuration, dirtyFiles, deletedFiles, cacheConsumer, emptySet(), mainArguments) cacheExecutor.execute(irModule, dependencies, deserializer, configuration, dirtyFiles, deletedFiles, cacheConsumer, emptySet(), mainArguments)
cacheConsumer.commitLibraryPath(libraryInfo.libPath.toCanonicalPath(), libraryInfo.flatHash, libraryInfo.transHash) cacheConsumer.commitLibraryInfo(libraryInfo.libPath.toCanonicalPath(), libraryInfo.flatHash, libraryInfo.transHash, irModule.name.asString())
} }
private fun loadModules( private fun loadModules(
@@ -548,6 +548,7 @@ private fun actualizeCacheForModule(
return CacheUpdateStatus.DIRTY // invalidated and re-built return CacheUpdateStatus.DIRTY // invalidated and re-built
} }
// Used for tests only
fun rebuildCacheForDirtyFiles( fun rebuildCacheForDirtyFiles(
library: KotlinLibrary, library: KotlinLibrary,
configuration: CompilerConfiguration, configuration: CompilerConfiguration,
@@ -585,6 +586,8 @@ fun rebuildCacheForDirtyFiles(
val currentIrModule = irModules.find { it.second == library }?.first!! val currentIrModule = irModules.find { it.second == library }?.first!!
cacheConsumer.commitLibraryInfo(library.libraryFile.path.toCanonicalPath(), 0UL, 0UL, currentIrModule.name.asString())
buildCacheForModuleFiles( buildCacheForModuleFiles(
currentIrModule, currentIrModule,
irModules.map { it.first }, irModules.map { it.first },
@@ -634,7 +637,7 @@ fun loadModuleCaches(icCachePaths: Collection<String>): Map<String, ModuleCache>
return icCacheMap.entries.associate { (lib, cache) -> return icCacheMap.entries.associate { (lib, cache) ->
val provider = createCacheProvider(cache.path) val provider = createCacheProvider(cache.path)
val files = provider.filePaths() val files = provider.filePaths()
lib to ModuleCache(lib, files.associate { f -> lib to ModuleCache(provider.moduleName(), files.associate { f ->
f to FileCache(f, provider.binaryAst(f), provider.dts(f), provider.sourceMap(f)) f to FileCache(f, provider.binaryAst(f), provider.dts(f), provider.sourceMap(f))
}) })
} }
@@ -200,7 +200,8 @@ class PersistentCacheProviderImpl(private val cachePath: String) : PersistentCac
} }
override fun moduleName(): String { override fun moduleName(): String {
TODO("Not yet implemented") val infoFile = File(File(cachePath), "info")
return infoFile.readLines()[3]
} }
} }
@@ -214,8 +215,7 @@ interface PersistentCacheConsumer {
fun commitSourceMap(path: String, mapData: ByteArray) fun commitSourceMap(path: String, mapData: ByteArray)
fun invalidateForFile(path: String) fun invalidateForFile(path: String)
fun commitLibraryPath(libraryPath: String, flatHash: ULong, transHash: ULong) fun commitLibraryInfo(libraryPath: String, flatHash: ULong, transHash: ULong, moduleName: String)
fun commitModuleName(moduleName: String)
companion object { companion object {
val EMPTY = object : PersistentCacheConsumer { val EMPTY = object : PersistentCacheConsumer {
@@ -246,7 +246,7 @@ interface PersistentCacheConsumer {
} }
override fun commitLibraryPath(libraryPath: String, flatHash: ULong, transHash: ULong) { override fun commitLibraryInfo(libraryPath: String, flatHash: ULong, transHash: ULong, moduleName: String) {
} }
@@ -257,9 +257,6 @@ interface PersistentCacheConsumer {
override fun commitSourceMap(path: String, mapData: ByteArray) { override fun commitSourceMap(path: String, mapData: ByteArray) {
} }
override fun commitModuleName(moduleName: String) {
}
} }
} }
} }
@@ -348,7 +345,7 @@ class PersistentCacheConsumerImpl(private val cachePath: String) : PersistentCac
commitByteArrayToCacheFile(path, fileSourceMap, mapData) commitByteArrayToCacheFile(path, fileSourceMap, mapData)
} }
override fun commitLibraryPath(libraryPath: String, flatHash: ULong, transHash: ULong) { override fun commitLibraryInfo(libraryPath: String, flatHash: ULong, transHash: ULong, moduleName: String) {
val infoFile = File(File(cachePath), "info") val infoFile = File(File(cachePath), "info")
if (infoFile.exists()) { if (infoFile.exists()) {
infoFile.delete() infoFile.delete()
@@ -359,10 +356,7 @@ class PersistentCacheConsumerImpl(private val cachePath: String) : PersistentCac
it.println(libraryPath) it.println(libraryPath)
it.println(flatHash.toString(16)) it.println(flatHash.toString(16))
it.println(transHash.toString(16)) it.println(transHash.toString(16))
it.println(moduleName)
} }
} }
override fun commitModuleName(moduleName: String) {
TODO("Not yet implemented")
}
} }
@@ -120,11 +120,7 @@ class TestModuleCache(val files: MutableMap<String, FileCache>) {
files.remove(path) files.remove(path)
} }
override fun commitLibraryPath(libraryPath: String, flatHash: ULong, transHash: ULong) { override fun commitLibraryInfo(libraryPath: String, flatHash: ULong, transHash: ULong, moduleName: String) {
}
override fun commitModuleName(moduleName: String) {
storedModuleName = moduleName storedModuleName = moduleName
} }
} }