JS IC: detect inline function changes
This commit is contained in:
@@ -17,12 +17,18 @@
|
||||
package org.jetbrains.kotlin.incremental.js
|
||||
|
||||
import java.io.File
|
||||
import java.security.MessageDigest
|
||||
|
||||
interface IncrementalResultsConsumer {
|
||||
/** processes new header metadata (serialized [JsProtoBuf.Header]) */
|
||||
fun processHeader(headerMetadata: ByteArray)
|
||||
/** processes new package part metadata and binary tree for compiled source file */
|
||||
fun processPackagePart(sourceFile: File, packagePartMetadata: ByteArray, binaryAst: ByteArray)
|
||||
/** [inlineFunction] is expected to be a body of inline function (an instance of [JsNode]),
|
||||
* but [Any] is used to avoid classloader conflicts in tests where the compiler is isolated
|
||||
* (such as [JsProtoComparisonTestGenerated])
|
||||
*/
|
||||
fun processInlineFunction(sourceFile: File, fqName: String, inlineFunction: Any)
|
||||
}
|
||||
|
||||
class IncrementalResultsConsumerImpl : IncrementalResultsConsumer {
|
||||
@@ -33,6 +39,24 @@ class IncrementalResultsConsumerImpl : IncrementalResultsConsumer {
|
||||
val packageParts: Map<File, TranslationResultValue>
|
||||
get() = _packageParts
|
||||
|
||||
private val _inlineFuncs = hashMapOf<File, MutableMap<String, Any>>()
|
||||
val inlineFunctions: Map<File, Map<String, Long>>
|
||||
get() {
|
||||
val result = HashMap<File, Map<String, Long>>(_inlineFuncs.size)
|
||||
|
||||
for ((file, inlineFnsFromFile) in _inlineFuncs) {
|
||||
val functionsHashes = HashMap<String, Long>(inlineFnsFromFile.size)
|
||||
|
||||
for ((fqName, expression) in inlineFnsFromFile) {
|
||||
functionsHashes[fqName] = expression.toString().toByteArray().md5()
|
||||
}
|
||||
|
||||
result[file] = functionsHashes
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
override fun processHeader(headerMetadata: ByteArray) {
|
||||
this.headerMetadata = headerMetadata
|
||||
}
|
||||
@@ -40,5 +64,22 @@ class IncrementalResultsConsumerImpl : IncrementalResultsConsumer {
|
||||
override fun processPackagePart(sourceFile: File, packagePartMetadata: ByteArray, binaryAst: ByteArray) {
|
||||
_packageParts.put(sourceFile, TranslationResultValue(packagePartMetadata, binaryAst))
|
||||
}
|
||||
|
||||
override fun processInlineFunction(sourceFile: File, fqName: String, inlineFunction: Any) {
|
||||
val mapForSource = _inlineFuncs.getOrPut(sourceFile) { hashMapOf() }
|
||||
mapForSource[fqName] = inlineFunction
|
||||
}
|
||||
|
||||
private fun ByteArray.md5(): Long {
|
||||
val d = MessageDigest.getInstance("MD5").digest(this)!!
|
||||
return ((d[0].toLong() and 0xFFL)
|
||||
or ((d[1].toLong() and 0xFFL) shl 8)
|
||||
or ((d[2].toLong() and 0xFFL) shl 16)
|
||||
or ((d[3].toLong() and 0xFFL) shl 24)
|
||||
or ((d[4].toLong() and 0xFFL) shl 32)
|
||||
or ((d[5].toLong() and 0xFFL) shl 40)
|
||||
or ((d[6].toLong() and 0xFFL) shl 48)
|
||||
or ((d[7].toLong() and 0xFFL) shl 56))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user