From ba0ce92159ba88a80c7b90d5341ce90c3a317219 Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov Date: Mon, 13 Jan 2020 12:38:52 +0300 Subject: [PATCH] Report messages only after IC scope expansion converged Incremental compilation scope (set of files to be compiled) could be expanded, even if the frontend reported some errors to a message collector. The next iteration of IC could produce a different set of compiler messages, so we want to report them only after scope expansion converged. --- .../incremental/IncrementalCompilerRunner.kt | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/IncrementalCompilerRunner.kt b/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/IncrementalCompilerRunner.kt index e726b5822b1..506e8778c2a 100644 --- a/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/IncrementalCompilerRunner.kt +++ b/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/IncrementalCompilerRunner.kt @@ -20,6 +20,8 @@ import org.jetbrains.kotlin.build.DEFAULT_KOTLIN_SOURCE_FILES_EXTENSIONS import org.jetbrains.kotlin.build.GeneratedFile import org.jetbrains.kotlin.cli.common.ExitCode import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments +import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation +import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity import org.jetbrains.kotlin.cli.common.messages.MessageCollector import org.jetbrains.kotlin.compilerRunner.MessageCollectorToOutputItemsCollectorAdapter import org.jetbrains.kotlin.compilerRunner.OutputItemsCollectorImpl @@ -233,14 +235,13 @@ abstract class IncrementalCompilerRunner< args.reportOutputFiles = true val outputItemsCollector = OutputItemsCollectorImpl() - val messageCollectorAdapter = MessageCollectorToOutputItemsCollectorAdapter(messageCollector, outputItemsCollector) + val temporaryMessageCollector = TemporaryMessageCollector(messageCollector) + val messageCollectorAdapter = MessageCollectorToOutputItemsCollectorAdapter(temporaryMessageCollector, outputItemsCollector) exitCode = runCompiler(sourcesToCompile.toSet(), args, caches, services, messageCollectorAdapter) postCompilationHook(exitCode) - reporter.reportCompileIteration(compilationMode is CompilationMode.Incremental, sourcesToCompile, exitCode) val generatedFiles = outputItemsCollector.outputs.map(SimpleOutputItem::toGeneratedFile) - if (compilationMode is CompilationMode.Incremental) { // todo: feels dirty, can this be refactored? val dirtySourcesSet = dirtySources.toHashSet() @@ -250,6 +251,10 @@ abstract class IncrementalCompilerRunner< continue } } + + reporter.reportCompileIteration(compilationMode is CompilationMode.Incremental, sourcesToCompile, exitCode) + temporaryMessageCollector.flush() + if (exitCode != ExitCode.OK) break dirtySourcesSinceLastTimeFile.delete() @@ -347,3 +352,24 @@ abstract class IncrementalCompilerRunner< } } } + +private class TemporaryMessageCollector(private val delegate: MessageCollector) : MessageCollector { + private class Message(val severity: CompilerMessageSeverity, val message: String, val location: CompilerMessageLocation?) + + private val messages = ArrayList() + + override fun clear() { + messages.clear() + } + + override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation?) { + messages.add(Message(severity, message, location)) + } + + override fun hasErrors(): Boolean = + messages.any { it.severity.isError } + + fun flush() { + messages.forEach { delegate.report(it.severity, it.message, it.location) } + } +}