[JS IC] Write cache info in per-file mode too

- make sure that file is existed and not crashes the compiler
This commit is contained in:
Roman Artemev
2021-09-13 20:45:27 +07:00
committed by teamcityserver
parent a55be02007
commit f85a59b7f3
2 changed files with 34 additions and 5 deletions
@@ -150,6 +150,7 @@ private fun KotlinLibrary.filesAndSigReaders(): List<Pair<String, IdSignatureDes
} }
private fun buildCacheForModule( private fun buildCacheForModule(
libraryPath: String,
irModule: IrModuleFragment, irModule: IrModuleFragment,
dirtyFiles: Collection<String>, dirtyFiles: Collection<String>,
cleanInlineHashes: Map<IdSignature, Hash>, cleanInlineHashes: Map<IdSignature, Hash>,
@@ -195,6 +196,7 @@ private fun buildCacheForModule(
// TODO: actual way of building a cache could change in future // TODO: actual way of building a cache could change in future
cacheConsumer.buildForFile(irFile) cacheConsumer.buildForFile(irFile)
} }
cacheConsumer.commitLibraryPath(libraryPath)
} }
private fun loadModules( private fun loadModules(
@@ -407,6 +409,14 @@ private fun actualizeCacheForModule(
val deserializers = dirtySet.associateWith { currentModuleDeserializer.signatureDeserializerForFile(it).signatureToIndexMapping() } val deserializers = dirtySet.associateWith { currentModuleDeserializer.signatureDeserializerForFile(it).signatureToIndexMapping() }
buildCacheForModule(currentIrModule, dirtySet, sigHashes, persistentCacheConsumer, deserializers, fileFingerPrints) buildCacheForModule(
library.libraryFile.canonicalPath,
currentIrModule,
dirtySet,
sigHashes,
persistentCacheConsumer,
deserializers,
fileFingerPrints
)
return false // invalidated and re-built return false // invalidated and re-built
} }
@@ -132,12 +132,12 @@ class PersistentCacheProviderImpl(private val cachePath: String) : PersistentCac
override fun allInlineHashes(sigResolver: (String, Int) -> IdSignature): Map<IdSignature, TransHash> { override fun allInlineHashes(sigResolver: (String, Int) -> IdSignature): Map<IdSignature, TransHash> {
val result = mutableMapOf<IdSignature, TransHash>() val result = mutableMapOf<IdSignature, TransHash>()
val cachePath = File(cachePath) val cachePath = File(cachePath)
cachePath.listFiles { file: File -> file.isDirectory }!!.forEach { cachePath.listFiles { file: File -> file.isDirectory }!!.forEach { f ->
val fileInfo = File(it, fileInfoFile) val fileInfo = File(f, fileInfoFile)
if (fileInfo.exists()) { if (fileInfo.exists()) {
val fileName = fileInfo.readLines()[0] val fileName = fileInfo.readLines()[0]
parseHashList(it, inlineFunctionsFile) { id -> sigResolver(fileName, id) }.forEach { parseHashList(f, inlineFunctionsFile) { id -> sigResolver(fileName, id) }.forEach { (sig, hash) ->
result[it.first] = it.second result[sig] = hash
} }
} }
} }
@@ -161,6 +161,8 @@ interface PersistentCacheConsumer {
fun commitBinaryAst(path: String, astData: ByteArray) fun commitBinaryAst(path: String, astData: ByteArray)
fun invalidateForFile(path: String) fun invalidateForFile(path: String)
fun commitLibraryPath(libraryPath: String)
companion object { companion object {
val EMPTY = object : PersistentCacheConsumer { val EMPTY = object : PersistentCacheConsumer {
override fun commitInlineFunctions( override fun commitInlineFunctions(
@@ -190,6 +192,10 @@ interface PersistentCacheConsumer {
} }
override fun commitLibraryPath(libraryPath: String) {
}
} }
} }
} }
@@ -265,4 +271,17 @@ class PersistentCacheConsumerImpl(private val cachePath: String) : PersistentCac
astFile.createNewFile() astFile.createNewFile()
astFile.writeBytes(astData) astFile.writeBytes(astData)
} }
override fun commitLibraryPath(libraryPath: String) {
val infoFile = File(File(cachePath), "info")
if (infoFile.exists()) {
infoFile.delete()
}
infoFile.createNewFile()
PrintWriter(infoFile).use {
it.println(libraryPath)
it.println("0")
}
}
} }