@@ -477,7 +477,7 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR
|
||||
|
||||
if (lookupTracker !is LookupTrackerImpl) throw AssertionError("Lookup tracker is expected to be LookupTrackerImpl, got ${lookupTracker.javaClass}")
|
||||
|
||||
val lookupStorage = dataManager.getStorage(LOOKUP_TRACKER_TARGET, LOOKUP_TRACKER_STORAGE_PROVIDER)
|
||||
val lookupStorage = dataManager.getStorage(KotlinDataContainerTarget, LookupStorageProvider)
|
||||
|
||||
filesToCompile.values().forEach { lookupStorage.removeLookupsFrom(it) }
|
||||
val removedFiles = chunk.targets.flatMap { KotlinSourceFileCollector.getRemovedKotlinFiles(dirtyFilesHolder, it) }
|
||||
|
||||
+11
-10
@@ -24,20 +24,21 @@ import org.jetbrains.jps.indices.ModuleExcludeIndex
|
||||
import org.jetbrains.jps.model.JpsModel
|
||||
import java.io.File
|
||||
|
||||
private val KOTLIN_LOOKUP_TRACKER = "kotlin-lookup-tracker"
|
||||
private val KOTLIN_DATA_CONTAINER = "kotlin-data-container"
|
||||
|
||||
object LOOKUP_TRACKER_TARGET_TYPE : BuildTargetType<LOOKUP_TRACKER_TARGET>(KOTLIN_LOOKUP_TRACKER) {
|
||||
override fun computeAllTargets(model: JpsModel): List<LOOKUP_TRACKER_TARGET> = listOf(LOOKUP_TRACKER_TARGET)
|
||||
object KotlinDataContainerTargetType : BuildTargetType<KotlinDataContainerTarget>(KOTLIN_DATA_CONTAINER) {
|
||||
override fun computeAllTargets(model: JpsModel): List<KotlinDataContainerTarget> = listOf(KotlinDataContainerTarget)
|
||||
|
||||
override fun createLoader(model: JpsModel): BuildTargetLoader<LOOKUP_TRACKER_TARGET> =
|
||||
object : BuildTargetLoader<LOOKUP_TRACKER_TARGET>() {
|
||||
override fun createTarget(targetId: String): LOOKUP_TRACKER_TARGET? = LOOKUP_TRACKER_TARGET
|
||||
override fun createLoader(model: JpsModel): BuildTargetLoader<KotlinDataContainerTarget> =
|
||||
object : BuildTargetLoader<KotlinDataContainerTarget>() {
|
||||
override fun createTarget(targetId: String): KotlinDataContainerTarget? = KotlinDataContainerTarget
|
||||
}
|
||||
}
|
||||
|
||||
object LOOKUP_TRACKER_TARGET : BuildTarget<BuildRootDescriptor>(LOOKUP_TRACKER_TARGET_TYPE) {
|
||||
override fun getId(): String? = KOTLIN_LOOKUP_TRACKER
|
||||
override fun getPresentableName(): String = KOTLIN_LOOKUP_TRACKER
|
||||
// Fake target to store data per project for incremental compilation
|
||||
object KotlinDataContainerTarget : BuildTarget<BuildRootDescriptor>(KotlinDataContainerTargetType) {
|
||||
override fun getId(): String? = KOTLIN_DATA_CONTAINER
|
||||
override fun getPresentableName(): String = KOTLIN_DATA_CONTAINER
|
||||
|
||||
override fun computeRootDescriptors(
|
||||
model: JpsModel?,
|
||||
@@ -49,7 +50,7 @@ object LOOKUP_TRACKER_TARGET : BuildTarget<BuildRootDescriptor>(LOOKUP_TRACKER_T
|
||||
override fun getOutputRoots(context: CompileContext): Collection<File> {
|
||||
val dataManager = context.projectDescriptor.dataManager
|
||||
val storageRoot = dataManager.dataPaths.dataStorageRoot
|
||||
return listOf(File(storageRoot, KOTLIN_LOOKUP_TRACKER))
|
||||
return listOf(File(storageRoot, KOTLIN_DATA_CONTAINER))
|
||||
}
|
||||
|
||||
override fun findRootDescriptor(rootId: String?, rootIndex: BuildRootIndex?): BuildRootDescriptor? = null
|
||||
@@ -27,7 +27,7 @@ import org.jetbrains.kotlin.utils.Printer
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
object LOOKUP_TRACKER_STORAGE_PROVIDER : StorageProvider<LookupStorage>() {
|
||||
object LookupStorageProvider : StorageProvider<LookupStorage>() {
|
||||
override fun createStorage(targetDataDir: File): LookupStorage = LookupStorage(targetDataDir)
|
||||
}
|
||||
|
||||
@@ -55,9 +55,9 @@ class LookupStorage(private val targetDataDir: File) : BasicMapsOwner() {
|
||||
}
|
||||
}
|
||||
|
||||
public fun add(lookupSymbol: LookupSymbol, containingFiles: Collection<File>) {
|
||||
val key = lookupSymbol.toHashPair()
|
||||
val fileIds = containingFiles.map { addFileIfNeeded(it) }.toHashSet()
|
||||
public fun add(lookupSymbol: LookupSymbol, containingPaths: Collection<String>) {
|
||||
val key = LookupSymbolKey(lookupSymbol.name, lookupSymbol.scope)
|
||||
val fileIds = containingPaths.map { addFileIfNeeded(File(it)) }.toHashSet()
|
||||
fileIds.addAll(lookupMap[key] ?: emptySet())
|
||||
lookupMap[key] = fileIds
|
||||
}
|
||||
@@ -115,7 +115,7 @@ class LookupStorage(private val targetDataDir: File) : BasicMapsOwner() {
|
||||
lookupMap[hash] = lookupMap[hash]!!.filter { it in idToFile }.toSet()
|
||||
}
|
||||
|
||||
val oldFileToId = fileToId.copyAsMap()
|
||||
val oldFileToId = fileToId.toMap()
|
||||
val oldIdToNewId = HashMap<Int, Int>(oldFileToId.size)
|
||||
idToFile.clean()
|
||||
fileToId.clean()
|
||||
@@ -151,10 +151,11 @@ class LookupStorage(private val targetDataDir: File) : BasicMapsOwner() {
|
||||
|
||||
val sb = StringBuilder()
|
||||
val p = Printer(sb)
|
||||
val lookupsStrings = lookupSymbols.groupBy { LookupHashPair(it.name, it.scope) }
|
||||
val lookups = lookupMap.copyAsMap()
|
||||
val lookupsStrings = lookupSymbols.groupBy { LookupSymbolKey(it.name, it.scope) }
|
||||
|
||||
for (lookup in lookupMap.keys.sorted()) {
|
||||
val fileIds = lookupMap[lookup]!!
|
||||
|
||||
for ((lookup, fileIds) in lookups.entries.sortedBy { it.key }) {
|
||||
val key = if (lookup in lookupsStrings) {
|
||||
lookupsStrings[lookup]!!.map { "${it.scope}#${it.name}" }.sorted().joinToString(", ")
|
||||
}
|
||||
@@ -171,14 +172,12 @@ class LookupStorage(private val targetDataDir: File) : BasicMapsOwner() {
|
||||
}
|
||||
|
||||
class LookupTrackerImpl(private val delegate: LookupTracker) : LookupTracker {
|
||||
val lookups = MultiMap<LookupSymbol, File>()
|
||||
val lookups = MultiMap<LookupSymbol, String>()
|
||||
|
||||
override fun record(locationInfo: LocationInfo, scopeFqName: String, scopeKind: ScopeKind, name: String) {
|
||||
lookups.putValue(LookupSymbol(name, scopeFqName), File(locationInfo.filePath))
|
||||
lookups.putValue(LookupSymbol(name, scopeFqName), locationInfo.filePath)
|
||||
delegate.record(locationInfo, scopeFqName, scopeKind, name)
|
||||
}
|
||||
}
|
||||
|
||||
data class LookupSymbol(val name: String, val scope: String)
|
||||
|
||||
fun LookupSymbol.toHashPair() = LookupHashPair(name, scope)
|
||||
|
||||
@@ -21,7 +21,6 @@ import com.intellij.util.io.EnumeratorStringDescriptor
|
||||
import com.intellij.util.io.KeyDescriptor
|
||||
import org.jetbrains.annotations.TestOnly
|
||||
import org.jetbrains.kotlin.utils.Printer
|
||||
import org.jetbrains.kotlin.utils.keysToMap
|
||||
import java.io.File
|
||||
|
||||
internal abstract class BasicMap<K : Comparable<K>, V>(
|
||||
@@ -43,8 +42,6 @@ internal abstract class BasicMap<K : Comparable<K>, V>(
|
||||
storage.close()
|
||||
}
|
||||
|
||||
public fun copyAsMap(): Map<K, V> = storage.keys.keysToMap { storage[it]!! }
|
||||
|
||||
@TestOnly
|
||||
fun dump(): String {
|
||||
return with(StringBuilder()) {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.jps.incremental.storage
|
||||
|
||||
import org.jetbrains.kotlin.utils.keysToMap
|
||||
import java.io.File
|
||||
|
||||
class FileToIdMap(file: File) : BasicMap<File, Int>(file, FileKeyDescriptor, IntExternalizer) {
|
||||
@@ -32,4 +33,6 @@ class FileToIdMap(file: File) : BasicMap<File, Int>(file, FileKeyDescriptor, Int
|
||||
public fun remove(file: File) {
|
||||
storage.remove(file)
|
||||
}
|
||||
|
||||
public fun toMap(): Map<File, Int> = storage.keys.keysToMap { storage[it]!! }
|
||||
}
|
||||
|
||||
@@ -18,25 +18,25 @@ package org.jetbrains.kotlin.jps.incremental.storage
|
||||
|
||||
import java.io.File
|
||||
|
||||
class LookupMap(storage: File) : BasicMap<LookupHashPair, Set<Int>>(storage, LookupHashPairKeyDescriptor, IntSetExternalizer) {
|
||||
override fun dumpKey(key: LookupHashPair): String = key.toString()
|
||||
class LookupMap(storage: File) : BasicMap<LookupSymbolKey, Set<Int>>(storage, LookupSymbolKeyDescriptor, IntSetExternalizer) {
|
||||
override fun dumpKey(key: LookupSymbolKey): String = key.toString()
|
||||
|
||||
override fun dumpValue(value: Set<Int>): String = value.toString()
|
||||
|
||||
public fun add(name: String, scope: String, fileId: Int) {
|
||||
storage.append(LookupHashPair(name, scope)) { out -> out.writeInt(fileId) }
|
||||
storage.append(LookupSymbolKey(name, scope)) { out -> out.writeInt(fileId) }
|
||||
}
|
||||
|
||||
public operator fun get(lookupHash: LookupHashPair): Set<Int>? = storage[lookupHash]
|
||||
public operator fun get(key: LookupSymbolKey): Set<Int>? = storage[key]
|
||||
|
||||
public operator fun set(key: LookupHashPair, fileIds: Set<Int>) {
|
||||
storage.set(key, fileIds)
|
||||
public operator fun set(key: LookupSymbolKey, fileIds: Set<Int>) {
|
||||
storage[key] = fileIds
|
||||
}
|
||||
|
||||
public fun remove(key: LookupHashPair) {
|
||||
public fun remove(key: LookupSymbolKey) {
|
||||
storage.remove(key)
|
||||
}
|
||||
|
||||
public val keys: Collection<LookupHashPair>
|
||||
public val keys: Collection<LookupSymbolKey>
|
||||
get() = storage.keys
|
||||
}
|
||||
|
||||
@@ -29,22 +29,22 @@ import java.io.DataOutput
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
object LookupHashPairKeyDescriptor : KeyDescriptor<LookupHashPair> {
|
||||
override fun read(input: DataInput): LookupHashPair {
|
||||
object LookupSymbolKeyDescriptor : KeyDescriptor<LookupSymbolKey> {
|
||||
override fun read(input: DataInput): LookupSymbolKey {
|
||||
val first = input.readInt()
|
||||
val second = input.readInt()
|
||||
|
||||
return LookupHashPair(first, second)
|
||||
return LookupSymbolKey(first, second)
|
||||
}
|
||||
|
||||
override fun save(output: DataOutput, value: LookupHashPair) {
|
||||
override fun save(output: DataOutput, value: LookupSymbolKey) {
|
||||
output.writeInt(value.nameHash)
|
||||
output.writeInt(value.scopeHash)
|
||||
}
|
||||
|
||||
override fun getHashCode(value: LookupHashPair): Int = value.hashCode()
|
||||
override fun getHashCode(value: LookupSymbolKey): Int = value.hashCode()
|
||||
|
||||
override fun isEqual(val1: LookupHashPair, val2: LookupHashPair): Boolean = val1 == val2
|
||||
override fun isEqual(val1: LookupSymbolKey, val2: LookupSymbolKey): Boolean = val1 == val2
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -18,10 +18,10 @@ package org.jetbrains.kotlin.jps.incremental.storage
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
|
||||
data class LookupHashPair(val nameHash: Int, val scopeHash: Int) : Comparable<LookupHashPair> {
|
||||
data class LookupSymbolKey(val nameHash: Int, val scopeHash: Int) : Comparable<LookupSymbolKey> {
|
||||
public constructor(name: String, scope: String) : this(name.hashCode(), scope.hashCode())
|
||||
|
||||
override fun compareTo(other: LookupHashPair): Int {
|
||||
override fun compareTo(other: LookupSymbolKey): Int {
|
||||
val nameCmp = nameHash.compareTo(other.nameHash)
|
||||
|
||||
if (nameCmp != 0) return nameCmp
|
||||
|
||||
@@ -46,8 +46,8 @@ import org.jetbrains.jps.util.JpsPathUtil
|
||||
import org.jetbrains.kotlin.config.IncrementalCompilation
|
||||
import org.jetbrains.kotlin.incremental.components.LookupTracker
|
||||
import org.jetbrains.kotlin.jps.build.classFilesComparison.assertEqualDirectories
|
||||
import org.jetbrains.kotlin.jps.incremental.LOOKUP_TRACKER_STORAGE_PROVIDER
|
||||
import org.jetbrains.kotlin.jps.incremental.LOOKUP_TRACKER_TARGET
|
||||
import org.jetbrains.kotlin.jps.incremental.LookupStorageProvider
|
||||
import org.jetbrains.kotlin.jps.incremental.KotlinDataContainerTarget
|
||||
import org.jetbrains.kotlin.jps.incremental.LookupSymbol
|
||||
import org.jetbrains.kotlin.jps.incremental.getKotlinCache
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
@@ -355,7 +355,7 @@ public abstract class AbstractIncrementalJpsTest(
|
||||
p.println("Begin of Lookup Maps")
|
||||
p.println()
|
||||
|
||||
val lookupStorage = project.dataManager.getStorage(LOOKUP_TRACKER_TARGET, LOOKUP_TRACKER_STORAGE_PROVIDER)
|
||||
val lookupStorage = project.dataManager.getStorage(KotlinDataContainerTarget, LookupStorageProvider)
|
||||
lookupStorage.forceGC()
|
||||
p.print(lookupStorage.dump(lookupsDuringTest))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user