[JS IC] Make API to store d.ts and sourceMap IC data

This commit is contained in:
Roman Artemev
2021-09-14 15:30:11 +07:00
committed by teamcityserver
parent f85a59b7f3
commit 7f424732bf
@@ -15,6 +15,8 @@ private const val inlineGraphFile = "inline.graph"
private const val inlineFunctionsFile = "inline.functions"
private const val fileInfoFile = "file.info"
private const val fileBinaryAst = "binary.ast"
private const val fileBinaryDts = "binary.dst"
private const val fileSourceMap = "source.map"
typealias Hash = Long // Any long hash
typealias FlatHash = Hash // Hash of inline function without its underlying inline call tree
@@ -28,6 +30,9 @@ private fun createFileCacheId(fileName: String): String = md5.digest(fileName.en
class ICCache(val dataProvider: PersistentCacheProvider, val dataConsumer: PersistentCacheConsumer, val serializedIcData: SerializedIcData)
class FileCache(val name: String, var ast: ByteArray?, var dts: ByteArray?, var sourceMap: ByteArray?)
class ModuleCache(val name: String, val asts: Map<String, FileCache>)
interface PersistentCacheProvider {
fun fileFingerPrint(path: String): Hash
@@ -41,6 +46,10 @@ interface PersistentCacheProvider {
fun binaryAst(path: String): ByteArray?
fun dts(path: String): ByteArray?
fun sourceMap(path: String): ByteArray?
companion object {
val EMPTY = object : PersistentCacheProvider {
override fun fileFingerPrint(path: String): Hash {
@@ -67,6 +76,13 @@ interface PersistentCacheProvider {
return ByteArray(0)
}
override fun dts(path: String): ByteArray? {
return null
}
override fun sourceMap(path: String): ByteArray? {
return null
}
}
}
}
@@ -144,13 +160,24 @@ class PersistentCacheProviderImpl(private val cachePath: String) : PersistentCac
return result
}
override fun binaryAst(path: String): ByteArray? {
val cachePath = path.fileDir
val astFile = File(cachePath, fileBinaryAst)
if (astFile.exists()) return astFile.readBytes()
private fun readBytesFromCacheFile(fileName: String, cacheName: String): ByteArray? {
val cachePath = fileName.fileDir
val cacheFile = File(cachePath, cacheName)
if (cacheFile.exists()) return cacheFile.readBytes()
return null
}
override fun binaryAst(path: String): ByteArray? {
return readBytesFromCacheFile(path, fileBinaryAst)
}
override fun dts(path: String): ByteArray? {
return readBytesFromCacheFile(path, fileBinaryDts)
}
override fun sourceMap(path: String): ByteArray? {
return readBytesFromCacheFile(path, fileSourceMap)
}
}
interface PersistentCacheConsumer {
@@ -159,6 +186,8 @@ interface PersistentCacheConsumer {
fun commitInlineGraph(path: String, hashes: Collection<Pair<IdSignature, TransHash>>, sigResolver: (IdSignature) -> Int)
fun commitICCacheData(path: String, icData: SerializedIcDataForFile)
fun commitBinaryAst(path: String, astData: ByteArray)
fun commitBinaryDts(path: String, dstData: ByteArray)
fun commitSourceMap(path: String, mapData: ByteArray)
fun invalidateForFile(path: String)
fun commitLibraryPath(libraryPath: String)
@@ -196,6 +225,13 @@ interface PersistentCacheConsumer {
}
override fun commitBinaryDts(path: String, dstData: ByteArray) {
}
override fun commitSourceMap(path: String, mapData: ByteArray) {
}
}
}
}
@@ -263,13 +299,25 @@ class PersistentCacheConsumerImpl(private val cachePath: String) : PersistentCac
//fileDir.deleteRecursively()
}
override fun commitBinaryAst(path: String, astData: ByteArray) {
val fileId = createFileCacheId(path)
private fun commitByteArrayToCacheFile(fileName: String, cacheName: String, data: ByteArray) {
val fileId = createFileCacheId(fileName)
val cacheDir = File(File(cachePath), fileId)
val astFile = File(cacheDir, fileBinaryAst)
if (astFile.exists()) astFile.delete()
astFile.createNewFile()
astFile.writeBytes(astData)
val cacheFile = File(cacheDir, cacheName)
if (cacheFile.exists()) cacheFile.delete()
cacheFile.createNewFile()
cacheFile.writeBytes(data)
}
override fun commitBinaryAst(path: String, astData: ByteArray) {
commitByteArrayToCacheFile(path, fileBinaryAst, astData)
}
override fun commitBinaryDts(path: String, dstData: ByteArray) {
commitByteArrayToCacheFile(path, fileBinaryDts, dstData)
}
override fun commitSourceMap(path: String, mapData: ByteArray) {
commitByteArrayToCacheFile(path, fileSourceMap, mapData)
}
override fun commitLibraryPath(libraryPath: String) {