Expand compilation scope for IC before backend is run

Sometimes IC raises compilation errors when rebuild succeeds.
This happens because IC uses serialized decriptors
for non-dirty files. Serialized descriptors can be different
from source file descriptors. For example, a source file
may contain an implicit return type or an implicit visibility
for overridden methods, but serialized descriptors always
contain explicit return types & methods' visibilities.

These problems can be solved by expanding a scope of incremental compilation
just after the analysis, but before error reporting & code generation.
In other words, we need to compare descriptors before error reporting and code generation.
If there are new dirty files, current round of IC must be aborted,
next round must be performed with new dirty files.

This commit implements IC scope expansion for JS Klib compiler

    #KT-13677
    #KT-28233
This commit is contained in:
Alexey Tsvetkov
2019-08-23 07:49:20 +03:00
parent 4f3418dc89
commit 2d598d50d7
28 changed files with 1205 additions and 67 deletions
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.config.IncrementalCompilation
import org.jetbrains.kotlin.config.Services
import org.jetbrains.kotlin.incremental.components.ExpectActualTracker
import org.jetbrains.kotlin.incremental.components.LookupTracker
import org.jetbrains.kotlin.incremental.js.IncrementalNextRoundChecker
import org.jetbrains.kotlin.incremental.js.IncrementalDataProvider
import org.jetbrains.kotlin.incremental.js.IncrementalResultsConsumer
import org.jetbrains.kotlin.ir.backend.js.*
@@ -296,6 +297,7 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
configuration.putIfNotNull(JSConfigurationKeys.INCREMENTAL_DATA_PROVIDER, services[IncrementalDataProvider::class.java])
configuration.putIfNotNull(JSConfigurationKeys.INCREMENTAL_RESULTS_CONSUMER, services[IncrementalResultsConsumer::class.java])
configuration.putIfNotNull(JSConfigurationKeys.INCREMENTAL_NEXT_ROUND_CHECKER, services[IncrementalNextRoundChecker::class.java])
configuration.putIfNotNull(CommonConfigurationKeys.LOOKUP_TRACKER, services[LookupTracker::class.java])
configuration.putIfNotNull(CommonConfigurationKeys.EXPECT_ACTUAL_TRACKER, services[ExpectActualTracker::class.java])
@@ -33,6 +33,7 @@ import org.jetbrains.kotlin.config.Services
import org.jetbrains.kotlin.metadata.deserialization.BinaryVersion
import org.jetbrains.kotlin.progress.CompilationCanceledException
import org.jetbrains.kotlin.progress.CompilationCanceledStatus
import org.jetbrains.kotlin.progress.IncrementalNextRoundException
import org.jetbrains.kotlin.progress.ProgressIndicatorAndCompilationCanceledStatus
import org.jetbrains.kotlin.utils.KotlinPaths
import org.jetbrains.kotlin.utils.PathUtil
@@ -96,12 +97,12 @@ abstract class CLICompiler<A : CommonCompilerArguments> : CLITool<A>() {
return if (collector.hasErrors()) COMPILATION_ERROR else code
} catch (e: CompilationCanceledException) {
collector.report(INFO, "Compilation was canceled", null)
collector.reportCompilationCancelled(e)
return ExitCode.OK
} catch (e: RuntimeException) {
val cause = e.cause
if (cause is CompilationCanceledException) {
collector.report(INFO, "Compilation was canceled", null)
collector.reportCompilationCancelled(cause)
return ExitCode.OK
} else {
throw e
@@ -119,6 +120,12 @@ abstract class CLICompiler<A : CommonCompilerArguments> : CLITool<A>() {
}
}
private fun MessageCollector.reportCompilationCancelled(e: CompilationCanceledException) {
if (e !is IncrementalNextRoundException) {
report(INFO, "Compilation was canceled", null)
}
}
private fun setupCommonArguments(configuration: CompilerConfiguration, arguments: A) {
configuration.setupCommonArguments(arguments, this::createMetadataVersion)
}