Implement server side IC

This commit is contained in:
Alexey Tsvetkov
2016-12-06 16:30:17 +03:00
parent f411bb0b4b
commit 51a8f6ee4f
14 changed files with 375 additions and 51 deletions
@@ -125,6 +125,16 @@ interface CompileService : Remote {
operationsTracer: RemoteOperationsTracer?
): CallResult<Int>
@Throws(RemoteException::class)
fun serverSideJvmIC(
sessionId: Int,
args: Array<out String>,
servicesFacade: IncrementalCompilationServicesFacade,
compilerOutputStream: RemoteOutputStream,
serviceOutputStream: RemoteOutputStream,
operationsTracer: RemoteOperationsTracer?
): CallResult<Int>
@Throws(RemoteException::class)
fun leaseReplSession(
aliveFlagPath: String?,
@@ -0,0 +1,56 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.daemon.common
import java.io.File
import java.rmi.Remote
import java.rmi.RemoteException
interface IncrementalCompilationServicesFacade : Remote {
@Throws(RemoteException::class)
fun areFileChangesKnown(): Boolean
@Throws(RemoteException::class)
fun modifiedFiles(): List<File>?
@Throws(RemoteException::class)
fun deletedFiles(): List<File>?
@Throws(RemoteException::class)
fun workingDir(): File
// ICReporter
@Throws(RemoteException::class)
fun shouldReportIC(): Boolean
@Throws(RemoteException::class)
fun reportIC(message: String)
@Throws(RemoteException::class)
fun reportCompileIteration(files: Iterable<File>, exitCode: Int)
// AnnotationFileUpdater
@Throws(RemoteException::class)
fun hasAnnotationsFileUpdater(): Boolean
@Throws(RemoteException::class)
fun updateAnnotations(outdatedClassesJvmNames: Iterable<String>)
@Throws(RemoteException::class)
fun revert()
}
+3
View File
@@ -12,5 +12,8 @@
<orderEntry type="module" module-name="util" />
<orderEntry type="library" name="intellij-core" level="project" />
<orderEntry type="module" module-name="frontend" />
<orderEntry type="module" module-name="incremental-compilation-impl" />
<orderEntry type="module" module-name="build-common" />
<orderEntry type="module" module-name="descriptor.loader.java" />
</component>
</module>
@@ -20,20 +20,31 @@ import com.intellij.openapi.Disposable
import com.intellij.openapi.util.Disposer
import com.intellij.openapi.vfs.impl.ZipHandler
import com.intellij.openapi.vfs.impl.jar.CoreJarFileSystem
import org.jetbrains.kotlin.annotation.AnnotationFileUpdater
import org.jetbrains.kotlin.cli.common.CLICompiler
import org.jetbrains.kotlin.cli.common.ExitCode
import org.jetbrains.kotlin.cli.common.KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
import org.jetbrains.kotlin.cli.common.messages.*
import org.jetbrains.kotlin.cli.common.modules.ModuleXmlParser
import org.jetbrains.kotlin.cli.common.repl.ReplCheckResult
import org.jetbrains.kotlin.cli.common.repl.ReplCodeLine
import org.jetbrains.kotlin.cli.common.repl.ReplCompileResult
import org.jetbrains.kotlin.cli.common.repl.ReplEvalResult
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
import org.jetbrains.kotlin.config.IncrementalCompilation
import org.jetbrains.kotlin.config.Services
import org.jetbrains.kotlin.daemon.common.*
import org.jetbrains.kotlin.incremental.*
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCompilationComponents
import org.jetbrains.kotlin.modules.Module
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.progress.CompilationCanceledStatus
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
import org.jetbrains.kotlin.utils.addToStdlib.check
import java.io.BufferedOutputStream
import java.io.ByteArrayOutputStream
import java.io.File
import java.io.PrintStream
import java.rmi.NoSuchObjectException
@@ -306,6 +317,58 @@ class CompileServiceImpl(
}
}
override fun serverSideJvmIC(
sessionId: Int,
args: Array<out String>,
servicesFacade: IncrementalCompilationServicesFacade,
compilerOutputStream: RemoteOutputStream,
serviceOutputStream: RemoteOutputStream,
operationsTracer: RemoteOperationsTracer?
): CompileService.CallResult<Int> {
return doCompile(sessionId, args, compilerOutputStream, serviceOutputStream, operationsTracer) { printStream, eventManager, profiler ->
val reporter = RemoteICReporter(servicesFacade)
val annotationFileUpdater = if (servicesFacade.hasAnnotationsFileUpdater()) RemoteAnnotationsFileUpdater(servicesFacade) else null
// these flags do not have any effect on the compiler (only on caches, incremental compilation logic, jps plugin)
// so it's OK to just set them true
IncrementalCompilation.setIsEnabled(true)
IncrementalCompilation.setIsExperimental(true)
val k2jvmArgs = K2JVMCompilerArguments()
(compiler[CompileService.TargetPlatform.JVM] as K2JVMCompiler).parseArguments(args, k2jvmArgs)
val moduleFile = k2jvmArgs.module?.let(::File)
assert(moduleFile?.exists() ?: false) { "Module does not exist ${k2jvmArgs.module}" }
val renderer = MessageRenderer.XML
val messageCollector = PrintingMessageCollector(printStream, renderer, k2jvmArgs.verbose)
val filteringMessageCollector = FilteringMessageCollector(messageCollector) { it == CompilerMessageSeverity.ERROR }
val parsedModule = ModuleXmlParser.parseModuleScript(k2jvmArgs.module, filteringMessageCollector)
val javaSourceRoots = parsedModule.modules.flatMapTo(HashSet()) { it.getJavaSourceRoots().map { File(it.path) } }
val allKotlinFiles = parsedModule.modules.flatMap { it.getSourceFiles().map(::File) }
k2jvmArgs.friendPaths = parsedModule.modules.flatMap(Module::getFriendPaths).toTypedArray()
val changedFiles = if (servicesFacade.areFileChangesKnown()) {
ChangedFiles.Known(servicesFacade.modifiedFiles()!!, servicesFacade.deletedFiles()!!)
}
else {
ChangedFiles.Unknown()
}
val workingDir = servicesFacade.workingDir()
val versions = commonCacheVersions(workingDir) + standaloneCacheVersion(workingDir, forceEnable = true)
try {
printStream.print(renderer.renderPreamble())
IncrementalJvmCompilerRunner(workingDir, javaSourceRoots, versions, reporter, annotationFileUpdater)
.compile(allKotlinFiles, k2jvmArgs, messageCollector, { changedFiles })
}
finally {
printStream.print(renderer.renderConclusion())
}
}
}
override fun leaseReplSession(
aliveFlagPath: String?,
targetPlatform: CompileService.TargetPlatform,
@@ -0,0 +1,34 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.daemon
import org.jetbrains.kotlin.annotation.AnnotationFileUpdater
import org.jetbrains.kotlin.cli.common.ExitCode
import org.jetbrains.kotlin.daemon.common.IncrementalCompilationServicesFacade
import org.jetbrains.kotlin.incremental.ICReporter
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
import java.io.File
internal class RemoteAnnotationsFileUpdater(private val servicesFacade: IncrementalCompilationServicesFacade) : AnnotationFileUpdater {
override fun updateAnnotations(outdatedClasses: Iterable<JvmClassName>) {
servicesFacade.updateAnnotations(outdatedClasses.map { it.internalName })
}
override fun revert() {
servicesFacade.revert()
}
}
@@ -0,0 +1,36 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.daemon
import org.jetbrains.kotlin.cli.common.ExitCode
import org.jetbrains.kotlin.daemon.common.IncrementalCompilationServicesFacade
import org.jetbrains.kotlin.incremental.ICReporter
import java.io.File
internal class RemoteICReporter(private val servicesFacade: IncrementalCompilationServicesFacade) : ICReporter() {
override fun report(message: () -> String) {
if (servicesFacade.shouldReportIC()) {
servicesFacade.reportIC(message())
}
}
override fun reportCompileIteration(sourceFiles: Iterable<File>, exitCode: ExitCode) {
if (servicesFacade.shouldReportIC()) {
servicesFacade.reportCompileIteration(sourceFiles, exitCode.code)
}
}
}