[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 inlineFunctionsFile = "inline.functions"
private const val fileInfoFile = "file.info" private const val fileInfoFile = "file.info"
private const val fileBinaryAst = "binary.ast" 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 Hash = Long // Any long hash
typealias FlatHash = Hash // Hash of inline function without its underlying inline call tree 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 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 { interface PersistentCacheProvider {
fun fileFingerPrint(path: String): Hash fun fileFingerPrint(path: String): Hash
@@ -41,6 +46,10 @@ interface PersistentCacheProvider {
fun binaryAst(path: String): ByteArray? fun binaryAst(path: String): ByteArray?
fun dts(path: String): ByteArray?
fun sourceMap(path: String): ByteArray?
companion object { companion object {
val EMPTY = object : PersistentCacheProvider { val EMPTY = object : PersistentCacheProvider {
override fun fileFingerPrint(path: String): Hash { override fun fileFingerPrint(path: String): Hash {
@@ -67,6 +76,13 @@ interface PersistentCacheProvider {
return ByteArray(0) 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 return result
} }
override fun binaryAst(path: String): ByteArray? { private fun readBytesFromCacheFile(fileName: String, cacheName: String): ByteArray? {
val cachePath = path.fileDir val cachePath = fileName.fileDir
val astFile = File(cachePath, fileBinaryAst) val cacheFile = File(cachePath, cacheName)
if (astFile.exists()) return astFile.readBytes() if (cacheFile.exists()) return cacheFile.readBytes()
return null 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 { interface PersistentCacheConsumer {
@@ -159,6 +186,8 @@ interface PersistentCacheConsumer {
fun commitInlineGraph(path: String, hashes: Collection<Pair<IdSignature, TransHash>>, sigResolver: (IdSignature) -> Int) fun commitInlineGraph(path: String, hashes: Collection<Pair<IdSignature, TransHash>>, sigResolver: (IdSignature) -> Int)
fun commitICCacheData(path: String, icData: SerializedIcDataForFile) fun commitICCacheData(path: String, icData: SerializedIcDataForFile)
fun commitBinaryAst(path: String, astData: ByteArray) fun commitBinaryAst(path: String, astData: ByteArray)
fun commitBinaryDts(path: String, dstData: ByteArray)
fun commitSourceMap(path: String, mapData: ByteArray)
fun invalidateForFile(path: String) fun invalidateForFile(path: String)
fun commitLibraryPath(libraryPath: 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() //fileDir.deleteRecursively()
} }
override fun commitBinaryAst(path: String, astData: ByteArray) { private fun commitByteArrayToCacheFile(fileName: String, cacheName: String, data: ByteArray) {
val fileId = createFileCacheId(path) val fileId = createFileCacheId(fileName)
val cacheDir = File(File(cachePath), fileId) val cacheDir = File(File(cachePath), fileId)
val astFile = File(cacheDir, fileBinaryAst) val cacheFile = File(cacheDir, cacheName)
if (astFile.exists()) astFile.delete() if (cacheFile.exists()) cacheFile.delete()
astFile.createNewFile() cacheFile.createNewFile()
astFile.writeBytes(astData) 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) { override fun commitLibraryPath(libraryPath: String) {