[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 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()
@@ -102,8 +102,6 @@ fun compileWithIC(
val ast = transformer.generateBinaryAst(dirtyFiles)
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) {
@@ -128,6 +126,7 @@ fun generateJsFromAst(
sourceMapsInfo: SourceMapsInfo?,
translationModes: Set<TranslationMode>,
caches: Map<String, ModuleCache>,
relativeRequirePath: Boolean = false,
): CompilerResult {
fun compilationOutput(multiModule: Boolean): CompilationOutputs {
val deserializer = JsIrAstDeserializer()
@@ -144,7 +143,7 @@ fun generateJsFromAst(
moduleKind = moduleKind,
jsIrProgram,
sourceMapsInfo = sourceMapsInfo,
relativeRequirePath = false,
relativeRequirePath = relativeRequirePath,
generateScriptModule = false,
)
}
@@ -205,7 +205,7 @@ private fun buildCacheForModule(
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(
@@ -548,6 +548,7 @@ private fun actualizeCacheForModule(
return CacheUpdateStatus.DIRTY // invalidated and re-built
}
// Used for tests only
fun rebuildCacheForDirtyFiles(
library: KotlinLibrary,
configuration: CompilerConfiguration,
@@ -585,6 +586,8 @@ fun rebuildCacheForDirtyFiles(
val currentIrModule = irModules.find { it.second == library }?.first!!
cacheConsumer.commitLibraryInfo(library.libraryFile.path.toCanonicalPath(), 0UL, 0UL, currentIrModule.name.asString())
buildCacheForModuleFiles(
currentIrModule,
irModules.map { it.first },
@@ -634,7 +637,7 @@ fun loadModuleCaches(icCachePaths: Collection<String>): Map<String, ModuleCache>
return icCacheMap.entries.associate { (lib, cache) ->
val provider = createCacheProvider(cache.path)
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))
})
}
@@ -200,7 +200,8 @@ class PersistentCacheProviderImpl(private val cachePath: String) : PersistentCac
}
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 invalidateForFile(path: String)
fun commitLibraryPath(libraryPath: String, flatHash: ULong, transHash: ULong)
fun commitModuleName(moduleName: String)
fun commitLibraryInfo(libraryPath: String, flatHash: ULong, transHash: ULong, moduleName: String)
companion object {
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 commitModuleName(moduleName: String) {
}
}
}
}
@@ -348,7 +345,7 @@ class PersistentCacheConsumerImpl(private val cachePath: String) : PersistentCac
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")
if (infoFile.exists()) {
infoFile.delete()
@@ -359,10 +356,7 @@ class PersistentCacheConsumerImpl(private val cachePath: String) : PersistentCac
it.println(libraryPath)
it.println(flatHash.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)
}
override fun commitLibraryPath(libraryPath: String, flatHash: ULong, transHash: ULong) {
}
override fun commitModuleName(moduleName: String) {
override fun commitLibraryInfo(libraryPath: String, flatHash: ULong, transHash: ULong, moduleName: String) {
storedModuleName = moduleName
}
}