jps, daemon: fix javascript inline functions tracking
inline function hash should computed after compilation
This commit is contained in:
+47
-20
@@ -17,18 +17,35 @@
|
||||
package org.jetbrains.kotlin.incremental.js
|
||||
|
||||
import java.io.File
|
||||
import java.io.Serializable
|
||||
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]),
|
||||
|
||||
/**
|
||||
* [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])
|
||||
* (such as [JsProtoComparisonTestGenerated]).
|
||||
*/
|
||||
fun processInlineFunction(sourceFile: File, fqName: String, inlineFunction: Any, line: Int, column: Int)
|
||||
|
||||
/**
|
||||
* Alternative to [processInlineFunction]: record all inline functions after it was processed.
|
||||
* Used in daemon RPC.
|
||||
*/
|
||||
fun processInlineFunctions(functions: Collection<JsInlineFunctionHash>)
|
||||
}
|
||||
|
||||
class JsInlineFunctionHash(val sourceFilePath: String, val fqName: String, val inlineFunctionMd5Hash: Long): Serializable
|
||||
|
||||
class FunctionWithSourceInfo(val expression: Any, val line: Int, val column: Int) {
|
||||
val md5: Long
|
||||
get() = "($line:$column)$expression".toByteArray().md5()
|
||||
}
|
||||
|
||||
class IncrementalResultsConsumerImpl : IncrementalResultsConsumer {
|
||||
@@ -39,22 +56,27 @@ class IncrementalResultsConsumerImpl : IncrementalResultsConsumer {
|
||||
val packageParts: Map<File, TranslationResultValue>
|
||||
get() = _packageParts
|
||||
|
||||
private class FunctionWithSourceInfo(val expression: Any, val line: Int, val column: Int)
|
||||
private val _inlineFuncs = hashMapOf<File, MutableMap<String, FunctionWithSourceInfo>>()
|
||||
private val _deferInlineFuncs = hashMapOf<File, MutableMap<String, FunctionWithSourceInfo>>()
|
||||
private var _processedInlineFuncs: Collection<JsInlineFunctionHash>? = null
|
||||
val inlineFunctions: Map<File, Map<String, Long>>
|
||||
get() {
|
||||
val result = HashMap<File, Map<String, Long>>(_inlineFuncs.size)
|
||||
val result = HashMap<File, MutableMap<String, Long>>(_deferInlineFuncs.size)
|
||||
|
||||
for ((file, inlineFnsFromFile) in _inlineFuncs) {
|
||||
for ((file, inlineFnsFromFile) in _deferInlineFuncs) {
|
||||
val functionsHashes = HashMap<String, Long>(inlineFnsFromFile.size)
|
||||
|
||||
for ((fqName, fn) in inlineFnsFromFile) {
|
||||
functionsHashes[fqName] = "(${fn.line}:${fn.column})${fn.expression}".toByteArray().md5()
|
||||
functionsHashes[fqName] = fn.md5
|
||||
}
|
||||
|
||||
result[file] = functionsHashes
|
||||
}
|
||||
|
||||
_processedInlineFuncs?.forEach {
|
||||
val fileFunctions = result.getOrPut(File(it.sourceFilePath)) { mutableMapOf() }
|
||||
fileFunctions[it.fqName] = it.inlineFunctionMd5Hash
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -66,21 +88,26 @@ class IncrementalResultsConsumerImpl : IncrementalResultsConsumer {
|
||||
_packageParts.put(sourceFile, TranslationResultValue(packagePartMetadata, binaryAst))
|
||||
}
|
||||
|
||||
override fun processInlineFunction(sourceFile: File, fqName: String, inlineFunction: Any, line: Int, column: Int) {
|
||||
val mapForSource = _inlineFuncs.getOrPut(sourceFile) { hashMapOf() }
|
||||
mapForSource[fqName] = FunctionWithSourceInfo(inlineFunction, line, column)
|
||||
override fun processInlineFunctions(functions: Collection<JsInlineFunctionHash>) {
|
||||
check(_processedInlineFuncs == null)
|
||||
_processedInlineFuncs = functions
|
||||
}
|
||||
|
||||
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))
|
||||
override fun processInlineFunction(sourceFile: File, fqName: String, inlineFunction: Any, line: Int, column: Int) {
|
||||
val mapForSource = _deferInlineFuncs.getOrPut(sourceFile) { hashMapOf() }
|
||||
mapForSource[fqName] = FunctionWithSourceInfo(inlineFunction, line, column)
|
||||
}
|
||||
}
|
||||
|
||||
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