[JS IR] Rework incremental cache invalidation
Replace loading the whole world IR with loading only exported (reachable) IR.
For that purpose the direct and inverse dependency graph is used.
It is stored in a cache directory and the cache updater keeps it up to date.
If after loading it is found that other files must be also implicitly rebuilt
(see rebuilt reasons below), IR for that files also will be loaded.
This algorithm repeats until the number of implicitly rebuilt files is not 0.
More rebuilt reasons (dirty state) have been added:
- added file: this is a new file;
- modified ir: ir of the file has been updated;
- updated exports: exports from the file have been added or removed
(e.g. a function has been used from another file);
- updated inline imports: imported inline function has been modified
(transitively);
- removed inverse depends: a dependent file has been removed;
- removed direct depends: a dependency file has been removed;
- removed file: this file has been removed.
Incremental cache tests has been refactored:
- The supporting of all rebuilt reasons (dirty states) has been added;
- New file name format "*.$suffix.kt" for the test steps has been allowed,
so the syntax highlight works now;
- Explicit stdlib dependency usage has been removed.
This commit is contained in:
committed by
Space
parent
f003f19e1d
commit
9e780afdca
@@ -213,43 +213,42 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
|
||||
messageCollector.report(INFO, arguments.cacheDirectories ?: "")
|
||||
messageCollector.report(INFO, libraries.toString())
|
||||
|
||||
val includes = arguments.includes!!
|
||||
|
||||
var start = System.currentTimeMillis()
|
||||
val start = System.currentTimeMillis()
|
||||
|
||||
val cacheUpdater = CacheUpdater(
|
||||
includes,
|
||||
libraries,
|
||||
configurationJs,
|
||||
cacheDirectories,
|
||||
{ IrFactoryImplForJsIC(WholeWorldStageController()) },
|
||||
mainCallArguments,
|
||||
::buildCacheForModuleFiles
|
||||
mainModule = arguments.includes!!,
|
||||
allModules = libraries,
|
||||
icCachePaths = cacheDirectories,
|
||||
compilerConfiguration = configurationJs,
|
||||
irFactory = { IrFactoryImplForJsIC(WholeWorldStageController()) },
|
||||
mainArguments = mainCallArguments,
|
||||
executor = ::buildCacheForModuleFiles
|
||||
)
|
||||
cacheUpdater.actualizeCaches { updateStatus, updatedModule ->
|
||||
|
||||
var tp = System.currentTimeMillis()
|
||||
messageCollector.report(INFO, "IC cache updater initialization: ${tp - start}ms")
|
||||
|
||||
val artifacts = cacheUpdater.actualizeCaches {
|
||||
val now = System.currentTimeMillis()
|
||||
fun reportCacheStatus(status: String, removed: Set<String> = emptySet(), updated: Set<String> = emptySet()) {
|
||||
messageCollector.report(INFO, "IC per-file is $status duration ${now - start}ms; module [${File(updatedModule).name}]")
|
||||
removed.forEach { messageCollector.report(INFO, " Removed: $it") }
|
||||
updated.forEach { messageCollector.report(INFO, " Updated: $it") }
|
||||
}
|
||||
when (updateStatus) {
|
||||
is CacheUpdateStatus.FastPath -> reportCacheStatus("up-to-date; fast check")
|
||||
is CacheUpdateStatus.NoDirtyFiles -> reportCacheStatus("up-to-date; full check", updateStatus.removed)
|
||||
is CacheUpdateStatus.Dirty -> {
|
||||
var updated = updateStatus.updated
|
||||
val status = StringBuilder("dirty").apply {
|
||||
if (updateStatus.updatedAll) {
|
||||
append("; all ${updated.size} sources updated")
|
||||
updated = emptySet()
|
||||
}
|
||||
append("; cache building")
|
||||
}.toString()
|
||||
reportCacheStatus(status, updateStatus.removed, updated)
|
||||
messageCollector.report(INFO, "IC $it: ${now - tp}ms")
|
||||
tp = now
|
||||
}
|
||||
|
||||
messageCollector.report(INFO, "IC rebuilt overall time: ${System.currentTimeMillis() - start}ms")
|
||||
|
||||
for ((libFile, srcFiles) in cacheUpdater.getDirtyFileStats()) {
|
||||
val isCleanBuild = srcFiles.values.all { it.contains(DirtyFileState.ADDED_FILE) }
|
||||
val msg = if (isCleanBuild) "fully rebuilt" else "partially rebuilt"
|
||||
messageCollector.report(INFO, "module [${File(libFile.path).name}] was $msg")
|
||||
if (!isCleanBuild) {
|
||||
for ((srcFile, stat) in srcFiles) {
|
||||
val statStr = stat.joinToString { it.str }
|
||||
messageCollector.report(INFO, " file [${File(srcFile.path).name}]: ($statStr)")
|
||||
}
|
||||
}
|
||||
start = now
|
||||
}
|
||||
|
||||
artifacts
|
||||
} else emptyList()
|
||||
|
||||
// Run analysis if main module is sources
|
||||
|
||||
Reference in New Issue
Block a user