Fix incremental compilation in some compiler plugins

If compiler plugin removes source files between rounds of incremental
compilation, it may result into incorrect state of stubs. But rebuilding
stubs may require services available in UI mode only and cause
compiler failure.
This commit contains work-around allowing to avoid incorrect state of
stubs.
#KT-49340 Fixed
This commit is contained in:
Andrey Uskov
2021-11-25 23:52:31 +03:00
committed by TeamCityServer
parent a1be855d17
commit 95648f1a9e
3 changed files with 7 additions and 15 deletions
@@ -5,8 +5,6 @@
package org.jetbrains.kotlin.cli.common
import com.intellij.openapi.util.text.StringUtil
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.util.PerformanceCounter
import java.io.File
import java.lang.management.GarbageCollectorMXBean
@@ -28,7 +26,6 @@ abstract class CommonCompilerPerformanceManager(private val presentableName: Str
private var irGenerationStart: Long = 0
private var targetDescription: String? = null
private var sourceFiles: List<KtFile>? = null
protected var files: Int? = null
protected var lines: Int? = null
@@ -45,19 +42,12 @@ abstract class CommonCompilerPerformanceManager(private val presentableName: Str
private fun deltaTime(start: Long): Long = PerformanceCounter.currentTime() - start
private fun countLinesOfCode(sourceFiles: List<KtFile>): Int =
sourceFiles.sumBy { sourceFile ->
val text = sourceFile.text
StringUtil.getLineBreakCount(text) + (if (StringUtil.endsWithLineBreak(text)) 0 else 1)
}
open fun notifyCompilerInitialized(sourceFiles: List<KtFile>, targetDescription: String) {
open fun notifyCompilerInitialized(files: Int, lines: Int, targetDescription: String) {
if (!isEnabled) return
recordInitializationTime()
this.sourceFiles = sourceFiles
this.files = sourceFiles.size
this.lines = countLinesOfCode(sourceFiles)
this.files = files
this.lines = lines
this.targetDescription = targetDescription
}
@@ -230,7 +230,7 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
val sourceFiles = environment.getSourceFiles()
configuration[CLIConfigurationKeys.PERF_MANAGER]?.notifyCompilerInitialized(
sourceFiles, targetDescription
sourceFiles.size, environment.countLinesOfCode(sourceFiles), targetDescription
)
return if (messageCollector.hasErrors()) null else environment
@@ -96,7 +96,9 @@ class K2MetadataCompiler : CLICompiler<K2MetadataCompilerArguments>() {
KotlinCoreEnvironment.createForProduction(rootDisposable, configuration, EnvironmentConfigFiles.METADATA_CONFIG_FILES)
val mode = if(arguments.expectActualLinker) "KLib" else "metadata"
performanceManager.notifyCompilerInitialized(environment.getSourceFiles(), "$mode mode for $moduleName module")
val sourceFiles = environment.getSourceFiles()
performanceManager.notifyCompilerInitialized(sourceFiles.size, environment.countLinesOfCode(sourceFiles), "$mode mode for $moduleName module")
if (environment.getSourceFiles().isEmpty()) {
if (arguments.version) {