Use new lookup tracker only when experimental incremental compilation is enabled
Original commit: 67878fe13a
This commit is contained in:
@@ -35,6 +35,7 @@ import org.jetbrains.jps.incremental.fs.CompilationRound
|
|||||||
import org.jetbrains.jps.incremental.java.JavaBuilder
|
import org.jetbrains.jps.incremental.java.JavaBuilder
|
||||||
import org.jetbrains.jps.incremental.messages.BuildMessage
|
import org.jetbrains.jps.incremental.messages.BuildMessage
|
||||||
import org.jetbrains.jps.incremental.messages.CompilerMessage
|
import org.jetbrains.jps.incremental.messages.CompilerMessage
|
||||||
|
import org.jetbrains.jps.incremental.storage.BuildDataManager
|
||||||
import org.jetbrains.jps.model.JpsProject
|
import org.jetbrains.jps.model.JpsProject
|
||||||
import org.jetbrains.jps.model.JpsSimpleElement
|
import org.jetbrains.jps.model.JpsSimpleElement
|
||||||
import org.jetbrains.jps.model.ex.JpsElementChildRoleBase
|
import org.jetbrains.jps.model.ex.JpsElementChildRoleBase
|
||||||
@@ -53,6 +54,7 @@ import org.jetbrains.kotlin.config.CompilerRunnerConstants.INTERNAL_ERROR_PREFIX
|
|||||||
import org.jetbrains.kotlin.config.IncrementalCompilation
|
import org.jetbrains.kotlin.config.IncrementalCompilation
|
||||||
import org.jetbrains.kotlin.config.Services
|
import org.jetbrains.kotlin.config.Services
|
||||||
import org.jetbrains.kotlin.incremental.components.LookupTracker
|
import org.jetbrains.kotlin.incremental.components.LookupTracker
|
||||||
|
import org.jetbrains.kotlin.incremental.components.ScopeKind
|
||||||
import org.jetbrains.kotlin.jps.JpsKotlinCompilerSettings
|
import org.jetbrains.kotlin.jps.JpsKotlinCompilerSettings
|
||||||
import org.jetbrains.kotlin.jps.incremental.*
|
import org.jetbrains.kotlin.jps.incremental.*
|
||||||
import org.jetbrains.kotlin.load.kotlin.ModuleMapping
|
import org.jetbrains.kotlin.load.kotlin.ModuleMapping
|
||||||
@@ -151,9 +153,8 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR
|
|||||||
messageCollector.report(INFO, "Kotlin JPS plugin version " + KotlinVersion.VERSION, CompilerMessageLocation.NO_LOCATION)
|
messageCollector.report(INFO, "Kotlin JPS plugin version " + KotlinVersion.VERSION, CompilerMessageLocation.NO_LOCATION)
|
||||||
|
|
||||||
val project = projectDescriptor.project
|
val project = projectDescriptor.project
|
||||||
|
val (lookupTracker, lookupStorage) = getLookupTrackerAndStorage(dataManager, project)
|
||||||
val lookupTracker = dataManager.getStorage(LOOKUP_TRACKER_TARGET, LOOKUP_TRACKER_STORAGE_PROVIDER)
|
val incrementalCaches = getIncrementalCaches(chunk, context, lookupStorage)
|
||||||
val incrementalCaches = getIncrementalCaches(chunk, context, lookupTracker)
|
|
||||||
val environment = createCompileEnvironment(incrementalCaches, lookupTracker, context)
|
val environment = createCompileEnvironment(incrementalCaches, lookupTracker, context)
|
||||||
if (!environment.success()) {
|
if (!environment.success()) {
|
||||||
environment.reportErrorsTo(messageCollector)
|
environment.reportErrorsTo(messageCollector)
|
||||||
@@ -623,7 +624,37 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR
|
|||||||
private val Iterable<BuildTarget<*>>.moduleTargets: Iterable<ModuleBuildTarget>
|
private val Iterable<BuildTarget<*>>.moduleTargets: Iterable<ModuleBuildTarget>
|
||||||
get() = filterIsInstance(javaClass<ModuleBuildTarget>())
|
get() = filterIsInstance(javaClass<ModuleBuildTarget>())
|
||||||
|
|
||||||
private fun getIncrementalCaches(chunk: ModuleChunk, context: CompileContext, lookupTrackerImpl: LookupTrackerImpl?): Map<ModuleBuildTarget, IncrementalCacheImpl> {
|
private fun getLookupTrackerAndStorage(dataManager: BuildDataManager, project: JpsProject): Pair<LookupTracker, LookupStorage> {
|
||||||
|
var lookupTracker = LookupTracker.DO_NOTHING
|
||||||
|
var lookupStorage = LookupStorage.DO_NOTHING
|
||||||
|
|
||||||
|
if (IncrementalCompilation.isExperimental()) {
|
||||||
|
val lookupTrackerImpl = dataManager.getStorage(LOOKUP_TRACKER_TARGET, LOOKUP_TRACKER_STORAGE_PROVIDER)
|
||||||
|
lookupTracker = lookupTrackerImpl
|
||||||
|
lookupStorage = lookupTrackerImpl
|
||||||
|
}
|
||||||
|
|
||||||
|
val inTest = "true".equals(System.getProperty("kotlin.jps.tests"), ignoreCase = true)
|
||||||
|
if (inTest) {
|
||||||
|
val testTracker = project.container.getChild(KotlinBuilder.LOOKUP_TRACKER)?.data
|
||||||
|
|
||||||
|
if (testTracker != null) {
|
||||||
|
lookupTracker = CopyingLookupTracker(lookupTracker, testTracker)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return lookupTracker to lookupStorage
|
||||||
|
}
|
||||||
|
|
||||||
|
private class CopyingLookupTracker(private val lookupTrackers: Collection<LookupTracker>) : LookupTracker {
|
||||||
|
constructor(vararg lookupTrackers: LookupTracker) : this(lookupTrackers.toList())
|
||||||
|
|
||||||
|
override fun record(lookupContainingFile: String, lookupLine: Int?, lookupColumn: Int?, scopeFqName: String, scopeKind: ScopeKind, name: String) {
|
||||||
|
lookupTrackers.forEach { it.record(lookupContainingFile, lookupLine, lookupColumn, scopeFqName, scopeKind, name) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getIncrementalCaches(chunk: ModuleChunk, context: CompileContext, lookupStorage: LookupStorage): Map<ModuleBuildTarget, IncrementalCacheImpl> {
|
||||||
val dataManager = context.projectDescriptor.dataManager
|
val dataManager = context.projectDescriptor.dataManager
|
||||||
val targets = chunk.targets
|
val targets = chunk.targets
|
||||||
|
|
||||||
@@ -654,7 +685,7 @@ private fun getIncrementalCaches(chunk: ModuleChunk, context: CompileContext, lo
|
|||||||
cache.addDependentCache(caches[it]!!)
|
cache.addDependentCache(caches[it]!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
cache.setLookupTracker(lookupTrackerImpl)
|
cache.setLookupStorage(lookupStorage)
|
||||||
}
|
}
|
||||||
|
|
||||||
return caches
|
return caches
|
||||||
|
|||||||
@@ -89,10 +89,10 @@ public class IncrementalCacheImpl(
|
|||||||
private val cacheFormatVersion = CacheFormatVersion(targetDataRoot)
|
private val cacheFormatVersion = CacheFormatVersion(targetDataRoot)
|
||||||
private val dependents = arrayListOf<IncrementalCacheImpl>()
|
private val dependents = arrayListOf<IncrementalCacheImpl>()
|
||||||
private val outputDir = requireNotNull(target.outputDir) { "Target is expected to have output directory: $target" }
|
private val outputDir = requireNotNull(target.outputDir) { "Target is expected to have output directory: $target" }
|
||||||
private var lookupTrackerImpl: LookupTrackerImpl? = null
|
private var _lookupStorage: LookupStorage = LookupStorage.DO_NOTHING
|
||||||
|
|
||||||
public fun setLookupTracker(lookupTrackerImpl: LookupTrackerImpl?) {
|
public fun setLookupStorage(lookupStorage: LookupStorage) {
|
||||||
this.lookupTrackerImpl = lookupTrackerImpl
|
this._lookupStorage = lookupStorage
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun registerInline(fromPath: String, jvmSignature: String, toPath: String) {
|
override fun registerInline(fromPath: String, jvmSignature: String, toPath: String) {
|
||||||
@@ -503,7 +503,7 @@ public class IncrementalCacheImpl(
|
|||||||
|
|
||||||
private fun remove(path: String) {
|
private fun remove(path: String) {
|
||||||
storage.remove(path)
|
storage.remove(path)
|
||||||
lookupTrackerImpl?.removeLookupsFrom(File(path))
|
_lookupStorage.removeLookupsFrom(File(path))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,17 @@ object LOOKUP_TRACKER_STORAGE_PROVIDER : StorageProvider<LookupTrackerImpl>() {
|
|||||||
override fun createStorage(targetDataDir: File): LookupTrackerImpl = LookupTrackerImpl(targetDataDir)
|
override fun createStorage(targetDataDir: File): LookupTrackerImpl = LookupTrackerImpl(targetDataDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
class LookupTrackerImpl(private val targetDataDir: File) : BasicMapsOwner(), LookupTracker {
|
interface LookupStorage {
|
||||||
|
fun removeLookupsFrom(file: File)
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val DO_NOTHING: LookupStorage = object : LookupStorage {
|
||||||
|
override fun removeLookupsFrom(file: File) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class LookupTrackerImpl(private val targetDataDir: File) : BasicMapsOwner(), LookupTracker, LookupStorage {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val DELETED_TO_SIZE_TRESHOLD = 0.5
|
private val DELETED_TO_SIZE_TRESHOLD = 0.5
|
||||||
@@ -60,7 +70,7 @@ class LookupTrackerImpl(private val targetDataDir: File) : BasicMapsOwner(), Loo
|
|||||||
lookupMap.add(name, scopeFqName, fileId)
|
lookupMap.add(name, scopeFqName, fileId)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun removeLookupsFrom(file: File) {
|
override fun removeLookupsFrom(file: File) {
|
||||||
val id = fileToId[file] ?: return
|
val id = fileToId[file] ?: return
|
||||||
idToFile.remove(id)
|
idToFile.remove(id)
|
||||||
fileToId.remove(file)
|
fileToId.remove(file)
|
||||||
|
|||||||
Reference in New Issue
Block a user