jps: implement mpp and js daemon compiler services
#KT-24635 fixed
This commit is contained in:
@@ -16,6 +16,7 @@ dependencies {
|
||||
compileOnly(project(":compiler:cli-common"))
|
||||
compileOnly(project(":compiler:daemon-common"))
|
||||
compileOnly(project(":kotlin-reflect-api"))
|
||||
compileOnly(project(":js:js.frontend"))
|
||||
compileOnly(commonDep("net.rubygrapefruit", "native-platform"))
|
||||
compileOnly(intellijDep()) { includeIntellijCoreJarDependencies(project) }
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ dependencies {
|
||||
compileOnly(project(":compiler:cli-common"))
|
||||
compileOnly(project(":compiler:daemon-common"))
|
||||
compileOnly(project(":kotlin-reflect-api"))
|
||||
compileOnly(project(":js:js.frontend"))
|
||||
compileOnly(commonDep("net.rubygrapefruit", "native-platform"))
|
||||
|
||||
embeddedComponents(project(":compiler:daemon-common")) { isTransitive = false }
|
||||
|
||||
+63
-22
@@ -16,61 +16,70 @@
|
||||
|
||||
package org.jetbrains.kotlin.daemon.client
|
||||
|
||||
import org.jetbrains.kotlin.daemon.common.CompilerCallbackServicesFacade
|
||||
import org.jetbrains.kotlin.daemon.common.LoopbackNetworkInterface
|
||||
import org.jetbrains.kotlin.daemon.common.RmiFriendlyCompilationCanceledException
|
||||
import org.jetbrains.kotlin.daemon.common.SOCKET_ANY_FREE_PORT
|
||||
import org.jetbrains.kotlin.daemon.common.*
|
||||
import org.jetbrains.kotlin.incremental.components.ExpectActualTracker
|
||||
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.load.kotlin.incremental.components.IncrementalCompilationComponents
|
||||
import org.jetbrains.kotlin.load.kotlin.incremental.components.JvmPackagePartProto
|
||||
import org.jetbrains.kotlin.modules.TargetId
|
||||
import org.jetbrains.kotlin.progress.CompilationCanceledStatus
|
||||
import org.jetbrains.kotlin.utils.isProcessCanceledException
|
||||
import java.io.File
|
||||
import java.rmi.server.UnicastRemoteObject
|
||||
import kotlin.reflect.full.allSuperclasses
|
||||
|
||||
|
||||
open class CompilerCallbackServicesFacadeServer(
|
||||
val incrementalCompilationComponents: IncrementalCompilationComponents? = null,
|
||||
val lookupTracker: LookupTracker? = null,
|
||||
val compilationCanceledStatus: CompilationCanceledStatus? = null,
|
||||
port: Int = SOCKET_ANY_FREE_PORT
|
||||
val incrementalCompilationComponents: IncrementalCompilationComponents? = null,
|
||||
val lookupTracker: LookupTracker? = null,
|
||||
val compilationCanceledStatus: CompilationCanceledStatus? = null,
|
||||
val expectActualTracker: ExpectActualTracker? = null,
|
||||
val incrementalResultsConsumer: IncrementalResultsConsumer? = null,
|
||||
val incrementalDataProvider: IncrementalDataProvider? = null,
|
||||
port: Int = SOCKET_ANY_FREE_PORT
|
||||
) : CompilerCallbackServicesFacade,
|
||||
UnicastRemoteObject(
|
||||
port,
|
||||
LoopbackNetworkInterface.clientLoopbackSocketFactory,
|
||||
LoopbackNetworkInterface.serverLoopbackSocketFactory
|
||||
) {
|
||||
UnicastRemoteObject(
|
||||
port,
|
||||
LoopbackNetworkInterface.clientLoopbackSocketFactory,
|
||||
LoopbackNetworkInterface.serverLoopbackSocketFactory
|
||||
) {
|
||||
override fun hasIncrementalCaches(): Boolean = incrementalCompilationComponents != null
|
||||
|
||||
override fun hasLookupTracker(): Boolean = lookupTracker != null
|
||||
|
||||
override fun hasCompilationCanceledStatus(): Boolean = compilationCanceledStatus != null
|
||||
|
||||
override fun hasExpectActualTracker(): Boolean = expectActualTracker != null
|
||||
|
||||
override fun hasIncrementalResultsConsumer(): Boolean = incrementalResultsConsumer != null
|
||||
|
||||
override fun hasIncrementalDataProvider(): Boolean = incrementalDataProvider != null
|
||||
|
||||
// TODO: consider replacing NPE with other reporting, although NPE here means most probably incorrect usage
|
||||
|
||||
override fun incrementalCache_getObsoletePackageParts(target: TargetId): Collection<String> =
|
||||
incrementalCompilationComponents!!.getIncrementalCache(target).getObsoletePackageParts()
|
||||
incrementalCompilationComponents!!.getIncrementalCache(target).getObsoletePackageParts()
|
||||
|
||||
override fun incrementalCache_getObsoleteMultifileClassFacades(target: TargetId): Collection<String> =
|
||||
incrementalCompilationComponents!!.getIncrementalCache(target).getObsoleteMultifileClasses()
|
||||
incrementalCompilationComponents!!.getIncrementalCache(target).getObsoleteMultifileClasses()
|
||||
|
||||
override fun incrementalCache_getMultifileFacadeParts(target: TargetId, internalName: String): Collection<String>? =
|
||||
incrementalCompilationComponents!!.getIncrementalCache(target).getStableMultifileFacadeParts(internalName)
|
||||
incrementalCompilationComponents!!.getIncrementalCache(target).getStableMultifileFacadeParts(internalName)
|
||||
|
||||
override fun incrementalCache_getPackagePartData(target: TargetId, partInternalName: String): JvmPackagePartProto? =
|
||||
incrementalCompilationComponents!!.getIncrementalCache(target).getPackagePartData(partInternalName)
|
||||
incrementalCompilationComponents!!.getIncrementalCache(target).getPackagePartData(partInternalName)
|
||||
|
||||
override fun incrementalCache_getModuleMappingData(target: TargetId): ByteArray? =
|
||||
incrementalCompilationComponents!!.getIncrementalCache(target).getModuleMappingData()
|
||||
incrementalCompilationComponents!!.getIncrementalCache(target).getModuleMappingData()
|
||||
|
||||
// todo: remove (the method it called was relevant only for old IC)
|
||||
override fun incrementalCache_registerInline(target: TargetId, fromPath: String, jvmSignature: String, toPath: String) {
|
||||
}
|
||||
|
||||
override fun incrementalCache_getClassFilePath(target: TargetId, internalClassName: String): String =
|
||||
incrementalCompilationComponents!!.getIncrementalCache(target).getClassFilePath(internalClassName)
|
||||
incrementalCompilationComponents!!.getIncrementalCache(target).getClassFilePath(internalClassName)
|
||||
|
||||
override fun incrementalCache_close(target: TargetId) {
|
||||
incrementalCompilationComponents!!.getIncrementalCache(target).close()
|
||||
@@ -94,8 +103,7 @@ open class CompilerCallbackServicesFacadeServer(
|
||||
try {
|
||||
compilationCanceledStatus!!.checkCanceled()
|
||||
return null
|
||||
}
|
||||
catch (e: Exception) {
|
||||
} catch (e: Exception) {
|
||||
// avoid passing exceptions that may have different serialVersionUID on across rmi border
|
||||
// removing dependency from openapi (this is obsolete part anyway, and will be removed soon)
|
||||
if (e.isProcessCanceledException())
|
||||
@@ -103,4 +111,37 @@ open class CompilerCallbackServicesFacadeServer(
|
||||
else throw e
|
||||
}
|
||||
}
|
||||
|
||||
override fun expectActualTracker_report(expectedFilePath: String, actualFilePath: String) {
|
||||
expectActualTracker!!.report(File(expectedFilePath), File(actualFilePath))
|
||||
}
|
||||
|
||||
override fun incrementalResultsConsumer_processHeader(headerMetadata: ByteArray) {
|
||||
incrementalResultsConsumer!!.processHeader(headerMetadata)
|
||||
}
|
||||
|
||||
override fun incrementalResultsConsumer_processPackagePart(
|
||||
sourceFilePath: String,
|
||||
packagePartMetadata: ByteArray,
|
||||
binaryAst: ByteArray
|
||||
) {
|
||||
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 incrementalDataProvider_getHeaderMetadata(): ByteArray = incrementalDataProvider!!.headerMetadata
|
||||
|
||||
override fun incrementalDataProvider_getCompiledPackageParts() =
|
||||
incrementalDataProvider!!.compiledPackageParts.entries.map {
|
||||
CompiledPackagePart(it.key.path, it.value.metadata, it.value.binaryAst)
|
||||
}
|
||||
}
|
||||
|
||||
+43
-2
@@ -29,7 +29,10 @@ import java.rmi.RemoteException
|
||||
* the reason for having common facade is attempt to reduce number of connections between client and daemon
|
||||
* Note: non-standard naming convention used to denote combining several entities in one facade - prefix <entityName>_ is used for every function belonging to the entity
|
||||
*/
|
||||
@Deprecated("The usages should be replaced with `compile` method and `CompilerServicesFacadeBase` implementations", ReplaceWith("CompilerServicesFacadeBase"))
|
||||
@Deprecated(
|
||||
"The usages should be replaced with `compile` method and `CompilerServicesFacadeBase` implementations",
|
||||
ReplaceWith("CompilerServicesFacadeBase")
|
||||
)
|
||||
interface CompilerCallbackServicesFacade : Remote {
|
||||
|
||||
@Throws(RemoteException::class)
|
||||
@@ -41,6 +44,15 @@ interface CompilerCallbackServicesFacade : Remote {
|
||||
@Throws(RemoteException::class)
|
||||
fun hasCompilationCanceledStatus(): Boolean
|
||||
|
||||
@Throws(RemoteException::class)
|
||||
fun hasExpectActualTracker(): Boolean
|
||||
|
||||
@Throws(RemoteException::class)
|
||||
fun hasIncrementalResultsConsumer(): Boolean
|
||||
|
||||
@Throws(RemoteException::class)
|
||||
fun hasIncrementalDataProvider(): Boolean
|
||||
|
||||
// ----------------------------------------------------
|
||||
// IncrementalCache
|
||||
@Throws(RemoteException::class)
|
||||
@@ -82,11 +94,40 @@ interface CompilerCallbackServicesFacade : Remote {
|
||||
// CompilationCanceledStatus
|
||||
@Throws(RemoteException::class, RmiFriendlyCompilationCanceledException::class)
|
||||
fun compilationCanceledStatus_checkCanceled(): Void?
|
||||
|
||||
// ---------------------------------------------------
|
||||
// ExpectActualTracker
|
||||
@Throws(RemoteException::class)
|
||||
fun expectActualTracker_report(expectedFilePath: String, actualFilePath: String)
|
||||
|
||||
// ---------------------------------------------------
|
||||
// IncrementalResultsConsumer (js)
|
||||
@Throws(RemoteException::class)
|
||||
fun incrementalResultsConsumer_processHeader(headerMetadata: ByteArray)
|
||||
|
||||
@Throws(RemoteException::class)
|
||||
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)
|
||||
|
||||
// ---------------------------------------------------
|
||||
// IncrementalDataProvider (js)
|
||||
@Throws(RemoteException::class)
|
||||
fun incrementalDataProvider_getHeaderMetadata(): ByteArray
|
||||
|
||||
@Throws(RemoteException::class)
|
||||
fun incrementalDataProvider_getCompiledPackageParts(): Collection<CompiledPackagePart>
|
||||
}
|
||||
|
||||
class CompiledPackagePart(
|
||||
val filePath: String,
|
||||
val metadata: ByteArray, val binaryAst: ByteArray
|
||||
) : Serializable
|
||||
|
||||
class RmiFriendlyCompilationCanceledException : Exception(), Serializable {
|
||||
companion object {
|
||||
private val serialVersionUID: Long = 8228357578L // just a random number, but should never be changed to avoid deserialization problems
|
||||
private val serialVersionUID: Long =
|
||||
8228357578L // just a random number, but should never be changed to avoid deserialization problems
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,10 @@ import org.jetbrains.kotlin.daemon.report.DaemonMessageReporter
|
||||
import org.jetbrains.kotlin.daemon.report.DaemonMessageReporterPrintStreamAdapter
|
||||
import org.jetbrains.kotlin.daemon.report.RemoteICReporter
|
||||
import org.jetbrains.kotlin.incremental.*
|
||||
import org.jetbrains.kotlin.incremental.components.ExpectActualTracker
|
||||
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.parsing.classesFqNames
|
||||
import org.jetbrains.kotlin.incremental.multiproject.ModulesApiHistoryAndroid
|
||||
import org.jetbrains.kotlin.incremental.multiproject.ModulesApiHistoryJvm
|
||||
@@ -944,6 +947,16 @@ class CompileServiceImpl(
|
||||
if (facade.hasCompilationCanceledStatus()) {
|
||||
builder.register(CompilationCanceledStatus::class.java, RemoteCompilationCanceledStatusClient(facade, rpcProfiler))
|
||||
}
|
||||
if (facade.hasExpectActualTracker()) {
|
||||
builder.register(ExpectActualTracker::class.java, RemoteExpectActualTracker(facade, rpcProfiler))
|
||||
}
|
||||
if (facade.hasIncrementalResultsConsumer()) {
|
||||
builder.register(IncrementalResultsConsumer::class.java, RemoteIncrementalResultsConsumer(facade, rpcProfiler))
|
||||
}
|
||||
if (facade.hasIncrementalDataProvider()) {
|
||||
builder.register(IncrementalDataProvider::class.java, RemoteIncrementalDataProvider(facade, rpcProfiler))
|
||||
}
|
||||
|
||||
return builder.build()
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.daemon
|
||||
|
||||
import org.jetbrains.kotlin.daemon.common.CompilerCallbackServicesFacade
|
||||
import org.jetbrains.kotlin.daemon.common.DummyProfiler
|
||||
import org.jetbrains.kotlin.daemon.common.Profiler
|
||||
import org.jetbrains.kotlin.incremental.components.ExpectActualTracker
|
||||
import java.io.File
|
||||
|
||||
class RemoteExpectActualTracker(
|
||||
val facade: CompilerCallbackServicesFacade,
|
||||
val profiler: Profiler = DummyProfiler()
|
||||
): ExpectActualTracker {
|
||||
override fun report(expectedFile: File, actualFile: File) {
|
||||
profiler.withMeasure(this) {
|
||||
facade.expectActualTracker_report(expectedFile.path, actualFile.path)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
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.IncrementalDataProvider
|
||||
import org.jetbrains.kotlin.incremental.js.TranslationResultValue
|
||||
import java.io.File
|
||||
|
||||
class RemoteIncrementalDataProvider(val facade: CompilerCallbackServicesFacade, val rpcProfiler: Profiler) :
|
||||
IncrementalDataProvider {
|
||||
override val headerMetadata: ByteArray
|
||||
get() = rpcProfiler.withMeasure(this) {
|
||||
facade.incrementalDataProvider_getHeaderMetadata()
|
||||
}
|
||||
|
||||
override val compiledPackageParts: Map<File, TranslationResultValue>
|
||||
get() = rpcProfiler.withMeasure(this) {
|
||||
val result = mutableMapOf<File, TranslationResultValue>()
|
||||
facade.incrementalDataProvider_getCompiledPackageParts().forEach {
|
||||
val prev = result.put(File(it.filePath), TranslationResultValue(it.metadata, it.binaryAst))
|
||||
check(prev == null) { "compiledPackageParts: duplicated entry for file `${it.filePath}`" }
|
||||
}
|
||||
result
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
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.IncrementalResultsConsumer
|
||||
import java.io.File
|
||||
|
||||
class RemoteIncrementalResultsConsumer(val facade: CompilerCallbackServicesFacade, val rpcProfiler: Profiler) :
|
||||
IncrementalResultsConsumer {
|
||||
override fun processHeader(headerMetadata: ByteArray) {
|
||||
rpcProfiler.withMeasure(this) {
|
||||
facade.incrementalResultsConsumer_processHeader(headerMetadata)
|
||||
}
|
||||
}
|
||||
|
||||
override fun processPackagePart(sourceFile: File, packagePartMetadata: ByteArray, binaryAst: ByteArray) {
|
||||
rpcProfiler.withMeasure(this) {
|
||||
facade.incrementalResultsConsumer_processPackagePart(sourceFile.path, packagePartMetadata, binaryAst)
|
||||
}
|
||||
}
|
||||
|
||||
override fun processInlineFunction(sourceFile: File, fqName: String, inlineFunction: Any, line: Int, column: Int) {
|
||||
rpcProfiler.withMeasure(this) {
|
||||
facade.incrementalResultsConsumer_processInlineFunction(sourceFile.path, fqName, inlineFunction, line, column)
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
-5
@@ -20,7 +20,10 @@ import org.jetbrains.kotlin.daemon.client.CompilerCallbackServicesFacadeServer
|
||||
import org.jetbrains.kotlin.daemon.client.reportFromDaemon
|
||||
import org.jetbrains.kotlin.daemon.common.JpsCompilerServicesFacade
|
||||
import org.jetbrains.kotlin.daemon.common.SOCKET_ANY_FREE_PORT
|
||||
import org.jetbrains.kotlin.incremental.components.ExpectActualTracker
|
||||
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.load.kotlin.incremental.components.IncrementalCompilationComponents
|
||||
import org.jetbrains.kotlin.progress.CompilationCanceledStatus
|
||||
import java.io.Serializable
|
||||
@@ -29,12 +32,14 @@ internal class JpsCompilerServicesFacadeImpl(
|
||||
private val env: JpsCompilerEnvironment,
|
||||
port: Int = SOCKET_ANY_FREE_PORT
|
||||
) : CompilerCallbackServicesFacadeServer(
|
||||
env.services.get(IncrementalCompilationComponents::class.java),
|
||||
env.services.get(LookupTracker::class.java),
|
||||
env.services.get(CompilationCanceledStatus::class.java),
|
||||
env.services[IncrementalCompilationComponents::class.java],
|
||||
env.services[LookupTracker::class.java],
|
||||
env.services[CompilationCanceledStatus::class.java],
|
||||
env.services[ExpectActualTracker::class.java],
|
||||
env.services[IncrementalResultsConsumer::class.java],
|
||||
env.services[IncrementalDataProvider::class.java],
|
||||
port
|
||||
),
|
||||
JpsCompilerServicesFacade {
|
||||
), JpsCompilerServicesFacade {
|
||||
|
||||
override fun report(category: Int, severity: Int, message: String?, attachment: Serializable?) {
|
||||
env.messageCollector.reportFromDaemon(
|
||||
|
||||
Reference in New Issue
Block a user