Format and cleanup incremental-compilation-impl

This commit is contained in:
Alexey Tsvetkov
2019-08-06 22:28:28 +03:00
parent 5816722a64
commit a950226602
11 changed files with 119 additions and 112 deletions
@@ -55,8 +55,7 @@ data class BuildDiffsStorage(val buildDiffs: List<BuildDifference>) {
} }
return result return result
} }
} } catch (e: IOException) {
catch (e: IOException) {
reportFail(e.toString()) reportFail(e.toString())
} }
@@ -76,8 +75,7 @@ data class BuildDiffsStorage(val buildDiffs: List<BuildDifference>) {
output.writeBuildDifference(diff) output.writeBuildDifference(diff)
} }
} }
} } catch (e: IOException) {
catch (e: IOException) {
reporter?.report { "Could not write diff to file $file: $e" } reporter?.report { "Could not write diff to file $file: $e" }
} }
} }
@@ -129,7 +127,7 @@ data class BuildDiffsStorage(val buildDiffs: List<BuildDifference>) {
} }
} }
internal val MAX_DIFFS_ENTRIES: Int = 10 internal const val MAX_DIFFS_ENTRIES: Int = 10
@set:TestOnly @set:TestOnly
var CURRENT_VERSION: Int = 0 var CURRENT_VERSION: Int = 0
@@ -25,8 +25,7 @@ data class BuildInfo(val startTS: Long) : Serializable {
ObjectInputStream(FileInputStream(file)).use { ObjectInputStream(FileInputStream(file)).use {
it.readObject() as BuildInfo it.readObject() as BuildInfo
} }
} } catch (e: Exception) {
catch (e: Exception) {
null null
} }
@@ -23,5 +23,6 @@ internal sealed class ChangesEither {
val lookupSymbols: Collection<LookupSymbol> = emptyList(), val lookupSymbols: Collection<LookupSymbol> = emptyList(),
val fqNames: Collection<FqName> = emptyList() val fqNames: Collection<FqName> = emptyList()
) : ChangesEither() ) : ChangesEither()
internal class Unknown(val reason: String? = null) : ChangesEither() internal class Unknown(val reason: String? = null) : ChangesEither()
} }
@@ -37,7 +37,7 @@ import java.util.*
abstract class IncrementalCompilerRunner< abstract class IncrementalCompilerRunner<
Args : CommonCompilerArguments, Args : CommonCompilerArguments,
CacheManager : IncrementalCachesManager<*> CacheManager : IncrementalCachesManager<*>
>( >(
private val workingDir: File, private val workingDir: File,
cacheDirName: String, cacheDirName: String,
protected val reporter: ICReporter, protected val reporter: ICReporter,
@@ -48,7 +48,7 @@ abstract class IncrementalCompilerRunner<
) { ) {
protected val cacheDirectory = File(workingDir, cacheDirName) protected val cacheDirectory = File(workingDir, cacheDirName)
protected val dirtySourcesSinceLastTimeFile = File(workingDir, DIRTY_SOURCES_FILE_NAME) private val dirtySourcesSinceLastTimeFile = File(workingDir, DIRTY_SOURCES_FILE_NAME)
protected val lastBuildInfoFile = File(workingDir, LAST_BUILD_INFO_FILE_NAME) protected val lastBuildInfoFile = File(workingDir, LAST_BUILD_INFO_FILE_NAME)
protected open val kotlinSourceFilesExtensions: List<String> = DEFAULT_KOTLIN_SOURCE_FILES_EXTENSIONS protected open val kotlinSourceFilesExtensions: List<String> = DEFAULT_KOTLIN_SOURCE_FILES_EXTENSIONS
@@ -95,8 +95,7 @@ abstract class IncrementalCompilerRunner<
if (!caches.close(flush = true)) throw RuntimeException("Could not flush caches") if (!caches.close(flush = true)) throw RuntimeException("Could not flush caches")
return exitCode return exitCode
} } catch (e: Exception) {
catch (e: Exception) {
// todo: warn? // todo: warn?
rebuild { "Possible cache corruption. Rebuilding. $e" } rebuild { "Possible cache corruption. Rebuilding. $e" }
} }
@@ -264,10 +263,17 @@ abstract class IncrementalCompilerRunner<
val (dirtyLookupSymbols, dirtyClassFqNames) = changesCollector.getDirtyData(listOf(caches.platformCache), reporter) val (dirtyLookupSymbols, dirtyClassFqNames) = changesCollector.getDirtyData(listOf(caches.platformCache), reporter)
val compiledInThisIterationSet = sourcesToCompile.toHashSet() val compiledInThisIterationSet = sourcesToCompile.toHashSet()
with (dirtySources) { with(dirtySources) {
clear() clear()
addAll(mapLookupSymbolsToFiles(caches.lookupCache, dirtyLookupSymbols, reporter, excludes = compiledInThisIterationSet)) addAll(mapLookupSymbolsToFiles(caches.lookupCache, dirtyLookupSymbols, reporter, excludes = compiledInThisIterationSet))
addAll(mapClassesFqNamesToFiles(listOf(caches.platformCache), dirtyClassFqNames, reporter, excludes = compiledInThisIterationSet)) addAll(
mapClassesFqNamesToFiles(
listOf(caches.platformCache),
dirtyClassFqNames,
reporter,
excludes = compiledInThisIterationSet
)
)
} }
buildDirtyLookupSymbols.addAll(dirtyLookupSymbols) buildDirtyLookupSymbols.addAll(dirtyLookupSymbols)
@@ -26,7 +26,10 @@ import org.jetbrains.kotlin.config.IncrementalCompilation
import org.jetbrains.kotlin.config.Services import org.jetbrains.kotlin.config.Services
import org.jetbrains.kotlin.incremental.components.ExpectActualTracker import org.jetbrains.kotlin.incremental.components.ExpectActualTracker
import org.jetbrains.kotlin.incremental.components.LookupTracker import org.jetbrains.kotlin.incremental.components.LookupTracker
import org.jetbrains.kotlin.incremental.js.* import org.jetbrains.kotlin.incremental.js.IncrementalDataProvider
import org.jetbrains.kotlin.incremental.js.IncrementalDataProviderFromCache
import org.jetbrains.kotlin.incremental.js.IncrementalResultsConsumer
import org.jetbrains.kotlin.incremental.js.IncrementalResultsConsumerImpl
import org.jetbrains.kotlin.incremental.multiproject.EmptyModulesApiHistory import org.jetbrains.kotlin.incremental.multiproject.EmptyModulesApiHistory
import org.jetbrains.kotlin.incremental.multiproject.ModulesApiHistory import org.jetbrains.kotlin.incremental.multiproject.ModulesApiHistory
import org.jetbrains.kotlin.library.metadata.KlibMetadataSerializerProtocol import org.jetbrains.kotlin.library.metadata.KlibMetadataSerializerProtocol
@@ -145,7 +148,7 @@ class IncrementalJsCompilerRunner(
generatedFiles: List<GeneratedFile>, generatedFiles: List<GeneratedFile>,
changesCollector: ChangesCollector changesCollector: ChangesCollector
) { ) {
val incrementalResults = services.get(IncrementalResultsConsumer::class.java) as IncrementalResultsConsumerImpl val incrementalResults = services[IncrementalResultsConsumer::class.java] as IncrementalResultsConsumerImpl
val jsCache = caches.platformCache val jsCache = caches.platformCache
jsCache.header = incrementalResults.headerMetadata jsCache.header = incrementalResults.headerMetadata
@@ -25,7 +25,6 @@ import com.intellij.psi.PsiJavaFile
import org.jetbrains.kotlin.build.DEFAULT_KOTLIN_SOURCE_FILES_EXTENSIONS import org.jetbrains.kotlin.build.DEFAULT_KOTLIN_SOURCE_FILES_EXTENSIONS
import org.jetbrains.kotlin.build.GeneratedFile import org.jetbrains.kotlin.build.GeneratedFile
import org.jetbrains.kotlin.build.GeneratedJvmClass import org.jetbrains.kotlin.build.GeneratedJvmClass
import org.jetbrains.kotlin.build.JvmSourceRoot
import org.jetbrains.kotlin.cli.common.ExitCode import org.jetbrains.kotlin.cli.common.ExitCode
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
import org.jetbrains.kotlin.cli.common.messages.MessageCollector import org.jetbrains.kotlin.cli.common.messages.MessageCollector
@@ -47,7 +46,6 @@ import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
import java.io.File import java.io.File
import java.io.ObjectOutputStream
fun makeIncrementally( fun makeIncrementally(
cachesDir: File, cachesDir: File,
@@ -90,14 +88,13 @@ object EmptyICReporter : ICReporterBase() {
} }
} }
inline fun <R> withIC(enabled: Boolean = true, fn: ()->R): R { inline fun <R> withIC(enabled: Boolean = true, fn: () -> R): R {
val isEnabledBackup = IncrementalCompilation.isEnabledForJvm() val isEnabledBackup = IncrementalCompilation.isEnabledForJvm()
IncrementalCompilation.setIsEnabledForJvm(enabled) IncrementalCompilation.setIsEnabledForJvm(enabled)
try { try {
return fn() return fn()
} } finally {
finally {
IncrementalCompilation.setIsEnabledForJvm(isEnabledBackup) IncrementalCompilation.setIsEnabledForJvm(isEnabledBackup)
} }
} }
@@ -126,7 +123,7 @@ class IncrementalJvmCompilerRunner(
override fun destinationDir(args: K2JVMCompilerArguments): File = override fun destinationDir(args: K2JVMCompilerArguments): File =
args.destinationAsFile args.destinationAsFile
private var dirtyClasspathChanges: Collection<FqName> = emptySet<FqName>() private var dirtyClasspathChanges: Collection<FqName> = emptySet()
private val psiFileFactory: PsiFileFactory by lazy { private val psiFileFactory: PsiFileFactory by lazy {
val rootDisposable = Disposer.newDisposable() val rootDisposable = Disposer.newDisposable()
@@ -354,8 +351,12 @@ class IncrementalJvmCompilerRunner(
var K2JVMCompilerArguments.destinationAsFile: File var K2JVMCompilerArguments.destinationAsFile: File
get() = File(destination) get() = File(destination)
set(value) { destination = value.path } set(value) {
destination = value.path
}
var K2JVMCompilerArguments.classpathAsList: List<File> var K2JVMCompilerArguments.classpathAsList: List<File>
get() = classpath.orEmpty().split(File.pathSeparator).map(::File) get() = classpath.orEmpty().split(File.pathSeparator).map(::File)
set(value) { classpath = value.joinToString(separator = File.pathSeparator, transform = { it.path }) } set(value) {
classpath = value.joinToString(separator = File.pathSeparator, transform = { it.path })
}
@@ -19,18 +19,17 @@ package org.jetbrains.kotlin.incremental
import com.intellij.util.containers.MultiMap import com.intellij.util.containers.MultiMap
import org.jetbrains.kotlin.build.GeneratedFile import org.jetbrains.kotlin.build.GeneratedFile
import org.jetbrains.kotlin.incremental.snapshots.FileSnapshotMap import org.jetbrains.kotlin.incremental.snapshots.FileSnapshotMap
import org.jetbrains.kotlin.incremental.storage.* import org.jetbrains.kotlin.incremental.storage.BasicMapsOwner
import org.jetbrains.kotlin.incremental.storage.SourceToOutputFilesMap
import java.io.File import java.io.File
import java.util.*
import kotlin.collections.HashSet
class InputsCache( class InputsCache(
workingDir: File, workingDir: File,
private val reporter: ICReporter private val reporter: ICReporter
) : BasicMapsOwner(workingDir) { ) : BasicMapsOwner(workingDir) {
companion object { companion object {
private val SOURCE_SNAPSHOTS = "source-snapshot" private const val SOURCE_SNAPSHOTS = "source-snapshot"
private val SOURCE_TO_OUTPUT_FILES = "source-to-output" private const val SOURCE_TO_OUTPUT_FILES = "source-to-output"
} }
internal val sourceSnapshotMap = registerMap(FileSnapshotMap(SOURCE_SNAPSHOTS.storageFile)) internal val sourceSnapshotMap = registerMap(FileSnapshotMap(SOURCE_SNAPSHOTS.storageFile))
@@ -38,7 +37,7 @@ class InputsCache(
fun removeOutputForSourceFiles(sources: Iterable<File>) { fun removeOutputForSourceFiles(sources: Iterable<File>) {
for (sourceFile in sources) { for (sourceFile in sources) {
sourceToOutputMap.remove(sourceFile).forEach { it -> sourceToOutputMap.remove(sourceFile).forEach {
reporter.reportVerbose { "Deleting $it on clearing cache for $sourceFile" } reporter.reportVerbose { "Deleting $it on clearing cache for $sourceFile" }
it.delete() it.delete()
} }
@@ -192,7 +192,7 @@ class ModulesApiHistoryAndroid(modulesInfo: IncrementalModuleInfo) : ModulesApiH
private fun getHistoryForModuleNames(path: Path, moduleNames: Iterable<String>): Either<Set<File>> { private fun getHistoryForModuleNames(path: Path, moduleNames: Iterable<String>): Either<Set<File>> {
val possibleModules = val possibleModules =
moduleNames.flatMapTo(HashSet<IncrementalModuleEntry>()) { modulesInfo.nameToModules[it] ?: emptySet() } moduleNames.flatMapTo(HashSet()) { modulesInfo.nameToModules[it] ?: emptySet() }
val modules = possibleModules.filter { Paths.get(it.buildDir.absolutePath).isParentOf(path) } val modules = possibleModules.filter { Paths.get(it.buildDir.absolutePath).isParentOf(path) }
if (modules.isEmpty()) return Either.Error("Unknown module for $path (candidates: ${possibleModules.joinToString()})") if (modules.isEmpty()) return Either.Error("Unknown module for $path (candidates: ${possibleModules.joinToString()})")