From a01d9b77c3f2eb63f200b8bd63fcef1099de882a Mon Sep 17 00:00:00 2001 From: Roman Artemev Date: Tue, 23 Nov 2021 20:43:46 +0300 Subject: [PATCH] [JS IR] Delegate invalidated files processing to the caller This change is needed to test invalidation somehow --- .../jetbrains/kotlin/cli/js/K2JsIrCompiler.kt | 2 +- .../kotlin/ir/backend/js/ic/invalidation.kt | 29 +++++++++++++++---- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt b/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt index 2a985e188e7..9e236df37a3 100644 --- a/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt +++ b/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt @@ -219,7 +219,7 @@ class K2JsIrCompiler : CLICompiler() { val start = System.currentTimeMillis() val updated = if (perFileCache) { - actualizeCacheForModule(includes, outputFilePath, configurationJs, libraries, icCaches, IrFactoryImpl) + actualizeCacheForModule(includes, outputFilePath, configurationJs, libraries, icCaches, IrFactoryImpl, ::buildCacheForModuleFiles) } else { buildCache( cachePath = outputFilePath, diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/ic/invalidation.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/ic/invalidation.kt index a2c25050d22..2d02c932948 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/ic/invalidation.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/ic/invalidation.kt @@ -151,7 +151,8 @@ private fun buildCacheForModule( cleanInlineHashes: Map, cacheConsumer: PersistentCacheConsumer, signatureDeserializers: Map>, - fileFingerPrints: Map + fileFingerPrints: Map, + cacheExecutor: CacheExecutor ) { val dirtyIrFiles = irModule.files.filter { it.fileEntry.name in dirtyFiles } @@ -191,7 +192,8 @@ private fun buildCacheForModule( } // TODO: actual way of building a cache could change in future - buildCacheForModuleFiles(irModule, dependencies, deserializer, configuration, dirtyFiles, cacheConsumer, emptySet(), null) // TODO: main arguments? + + cacheExecutor.execute(irModule, dependencies, deserializer, configuration, dirtyFiles, cacheConsumer, emptySet(), null) // TODO: main arguments? cacheConsumer.commitLibraryPath(libraryPath) } @@ -288,6 +290,20 @@ typealias ModuleName = String typealias ModulePath = String typealias FilePath = String + +fun interface CacheExecutor { + fun execute( + currentModule: IrModuleFragment, + dependencies: Collection, + deserializer: JsIrLinker, + configuration: CompilerConfiguration, + dirtyFiles: Collection?, // if null consider the whole module dirty + cacheConsumer: PersistentCacheConsumer, + exportedDeclarations: Set, + mainArguments: List?, + ) +} + fun actualizeCacheForModule( moduleName: String, cachePath: String, @@ -295,6 +311,7 @@ fun actualizeCacheForModule( dependencies: Collection, icCachePaths: Collection, irFactory: IrFactory, + executor: CacheExecutor ): Boolean { val icCacheMap: Map = loadCacheInfo(icCachePaths).also { it[moduleName.toCanonicalPath()] = cachePath @@ -317,7 +334,7 @@ fun actualizeCacheForModule( val currentModule = libraries[moduleName.toCanonicalPath()] ?: error("No loaded library found for path $moduleName") val persistentCacheConsumer = createCacheConsumer(cachePath) - return actualizeCacheForModule(currentModule, compilerConfiguration, dependencyGraph, persistentCacheProviders, persistentCacheConsumer, irFactory) + return actualizeCacheForModule(currentModule, compilerConfiguration, dependencyGraph, persistentCacheProviders, persistentCacheConsumer, irFactory, executor) } @@ -328,6 +345,7 @@ private fun actualizeCacheForModule( persistentCacheProviders: Map, persistentCacheConsumer: PersistentCacheConsumer, irFactory: IrFactory, + cacheExecutor: CacheExecutor ): Boolean { // 1. Invalidate val dependencies = dependencyGraph[library]!! @@ -422,7 +440,8 @@ private fun actualizeCacheForModule( sigHashes, persistentCacheConsumer, deserializers, - fileFingerPrints + fileFingerPrints, + cacheExecutor ) return false // invalidated and re-built } @@ -477,7 +496,7 @@ fun rebuildCacheForDirtyFiles( } @Suppress("UNUSED_PARAMETER") -private fun buildCacheForModuleFiles( +fun buildCacheForModuleFiles( currentModule: IrModuleFragment, dependencies: Collection, deserializer: JsIrLinker,