jps, daemon: fix javascript inline functions tracking
inline function hash should computed after compilation
This commit is contained in:
+8
-2
@@ -58,9 +58,15 @@ abstract class KotlinCompilerRunner<in Env : CompilerEnvironment> {
|
||||
clientAliveFlagFile: File,
|
||||
sessionAliveFlagFile: File,
|
||||
environment: Env,
|
||||
daemonOptions: DaemonOptions = configureDaemonOptions()
|
||||
daemonOptions: DaemonOptions = configureDaemonOptions(),
|
||||
additionalJvmParams: Array<String> = arrayOf()
|
||||
): CompileServiceSession? {
|
||||
val daemonJVMOptions = configureDaemonJVMOptions(inheritMemoryLimits = true, inheritOtherJvmOptions = false, inheritAdditionalProperties = true)
|
||||
val daemonJVMOptions = configureDaemonJVMOptions(
|
||||
additionalParams = *additionalJvmParams,
|
||||
inheritMemoryLimits = true,
|
||||
inheritOtherJvmOptions = false,
|
||||
inheritAdditionalProperties = true
|
||||
)
|
||||
|
||||
val daemonReportMessages = ArrayList<DaemonReportMessage>()
|
||||
val daemonReportingTargets = DaemonReportingTargets(messages = daemonReportMessages)
|
||||
|
||||
+3
-8
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.incremental.components.LookupInfo
|
||||
import org.jetbrains.kotlin.incremental.components.LookupTracker
|
||||
import org.jetbrains.kotlin.incremental.js.IncrementalDataProvider
|
||||
import org.jetbrains.kotlin.incremental.js.IncrementalResultsConsumer
|
||||
import org.jetbrains.kotlin.incremental.js.JsInlineFunctionHash
|
||||
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCompilationComponents
|
||||
import org.jetbrains.kotlin.load.kotlin.incremental.components.JvmPackagePartProto
|
||||
import org.jetbrains.kotlin.modules.TargetId
|
||||
@@ -128,14 +129,8 @@ open class CompilerCallbackServicesFacadeServer(
|
||||
incrementalResultsConsumer!!.processPackagePart(File(sourceFilePath), packagePartMetadata, binaryAst)
|
||||
}
|
||||
|
||||
override fun incrementalResultsConsumer_processInlineFunction(
|
||||
sourceFilePath: String,
|
||||
fqName: String,
|
||||
inlineFunction: Any,
|
||||
line: Int,
|
||||
column: Int
|
||||
) {
|
||||
incrementalResultsConsumer!!.processInlineFunction(File(sourceFilePath), fqName, inlineFunction, line, column)
|
||||
override fun incrementalResultsConsumer_processInlineFunctions(functions: Collection<JsInlineFunctionHash>) {
|
||||
incrementalResultsConsumer!!.processInlineFunctions(functions)
|
||||
}
|
||||
|
||||
override fun incrementalDataProvider_getHeaderMetadata(): ByteArray = incrementalDataProvider!!.headerMetadata
|
||||
|
||||
@@ -12,6 +12,7 @@ dependencies {
|
||||
compile(project(":compiler:util"))
|
||||
compile(project(":compiler:cli-common"))
|
||||
compile(projectDist(":kotlin-stdlib"))
|
||||
compileOnly(project(":js:js.frontend"))
|
||||
compileOnly(intellijCoreDep()) { includeJars("intellij-core") }
|
||||
compileOnly(intellijDep()) { includeIntellijCoreJarDependencies(project) }
|
||||
}
|
||||
|
||||
+2
-1
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.kotlin.daemon.common
|
||||
|
||||
import org.jetbrains.kotlin.incremental.components.LookupInfo
|
||||
import org.jetbrains.kotlin.incremental.js.JsInlineFunctionHash
|
||||
import org.jetbrains.kotlin.load.kotlin.incremental.components.JvmPackagePartProto
|
||||
import org.jetbrains.kotlin.modules.TargetId
|
||||
import java.io.Serializable
|
||||
@@ -109,7 +110,7 @@ interface CompilerCallbackServicesFacade : Remote {
|
||||
fun incrementalResultsConsumer_processPackagePart(sourceFilePath: String, packagePartMetadata: ByteArray, binaryAst: ByteArray)
|
||||
|
||||
@Throws(RemoteException::class)
|
||||
fun incrementalResultsConsumer_processInlineFunction(sourceFilePath: String, fqName: String, inlineFunction: Any, line: Int, column: Int)
|
||||
fun incrementalResultsConsumer_processInlineFunctions(functions: Collection<JsInlineFunctionHash>)
|
||||
|
||||
// ---------------------------------------------------
|
||||
// IncrementalDataProvider (js)
|
||||
|
||||
@@ -951,7 +951,7 @@ class CompileServiceImpl(
|
||||
builder.register(ExpectActualTracker::class.java, RemoteExpectActualTracker(facade, rpcProfiler))
|
||||
}
|
||||
if (facade.hasIncrementalResultsConsumer()) {
|
||||
builder.register(IncrementalResultsConsumer::class.java, RemoteIncrementalResultsConsumer(facade, rpcProfiler))
|
||||
builder.register(IncrementalResultsConsumer::class.java, RemoteIncrementalResultsConsumer(facade, eventManager, rpcProfiler))
|
||||
}
|
||||
if (facade.hasIncrementalDataProvider()) {
|
||||
builder.register(IncrementalDataProvider::class.java, RemoteIncrementalDataProvider(facade, rpcProfiler))
|
||||
|
||||
+20
-2
@@ -7,11 +7,17 @@ package org.jetbrains.kotlin.daemon
|
||||
|
||||
import org.jetbrains.kotlin.daemon.common.CompilerCallbackServicesFacade
|
||||
import org.jetbrains.kotlin.daemon.common.Profiler
|
||||
import org.jetbrains.kotlin.incremental.js.FunctionWithSourceInfo
|
||||
import org.jetbrains.kotlin.incremental.js.IncrementalResultsConsumer
|
||||
import org.jetbrains.kotlin.incremental.js.JsInlineFunctionHash
|
||||
import java.io.File
|
||||
|
||||
class RemoteIncrementalResultsConsumer(val facade: CompilerCallbackServicesFacade, val rpcProfiler: Profiler) :
|
||||
class RemoteIncrementalResultsConsumer(val facade: CompilerCallbackServicesFacade, eventManager: EventManager, val rpcProfiler: Profiler) :
|
||||
IncrementalResultsConsumer {
|
||||
init {
|
||||
eventManager.onCompilationFinished(this::flush)
|
||||
}
|
||||
|
||||
override fun processHeader(headerMetadata: ByteArray) {
|
||||
rpcProfiler.withMeasure(this) {
|
||||
facade.incrementalResultsConsumer_processHeader(headerMetadata)
|
||||
@@ -24,9 +30,21 @@ class RemoteIncrementalResultsConsumer(val facade: CompilerCallbackServicesFacad
|
||||
}
|
||||
}
|
||||
|
||||
private class JsInlineFunction(val sourceFilePath: String, val fqName: String, val inlineFunction: FunctionWithSourceInfo)
|
||||
|
||||
private val deferInlineFuncs = mutableListOf<JsInlineFunction>()
|
||||
|
||||
override fun processInlineFunction(sourceFile: File, fqName: String, inlineFunction: Any, line: Int, column: Int) {
|
||||
deferInlineFuncs.add(JsInlineFunction(sourceFile.path, fqName, FunctionWithSourceInfo(inlineFunction, line, column)))
|
||||
}
|
||||
|
||||
override fun processInlineFunctions(functions: Collection<JsInlineFunctionHash>) = error("Should not be called in Daemon Server")
|
||||
|
||||
fun flush() {
|
||||
rpcProfiler.withMeasure(this) {
|
||||
facade.incrementalResultsConsumer_processInlineFunction(sourceFile.path, fqName, inlineFunction.toString(), line, column)
|
||||
facade.incrementalResultsConsumer_processInlineFunctions(deferInlineFuncs.map {
|
||||
JsInlineFunctionHash(it.sourceFilePath, it.fqName, it.inlineFunction.md5)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+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