From 0e0c188e0538220cbd9515d3a628111f3f6e8715 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Tue, 2 Apr 2019 16:57:43 +0300 Subject: [PATCH] Rebuild fir-provider indexes on changes --- .../fir/resolve/impl/FirProviderImpl.kt | 63 ++++++++++++++----- 1 file changed, 48 insertions(+), 15 deletions(-) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/impl/FirProviderImpl.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/impl/FirProviderImpl.kt index 7d491561040..18b6beed5a9 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/impl/FirProviderImpl.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/impl/FirProviderImpl.kt @@ -99,6 +99,20 @@ class FirProviderImpl(val session: FirSession) : FirProvider { val classifierContainerFileMap = mutableMapOf() val callableMap = mutableMapOf>() val callableContainerMap = mutableMapOf() + + fun setFrom(other: State) { + fileMap.clear() + classifierMap.clear() + classifierContainerFileMap.clear() + callableMap.clear() + callableContainerMap.clear() + + fileMap.putAll(other.fileMap) + classifierMap.putAll(other.classifierMap) + classifierContainerFileMap.putAll(other.classifierContainerFileMap) + callableMap.putAll(other.callableMap) + callableContainerMap.putAll(other.callableContainerMap) + } } override fun getFirFilesByPackage(fqName: FqName): List { @@ -114,25 +128,37 @@ class FirProviderImpl(val session: FirSession) : FirProvider { val newState = State() files.forEach { recordFile(it, newState) } - fun checkMapDiff(a: Map, b: Map, equal: (old: V?, new: V?) -> Boolean = { old, new -> old === new }) { + val failures = mutableListOf() + + fun checkMapDiff( + title: String, + a: Map, + b: Map, + equal: (old: V?, new: V?) -> Boolean = { old, new -> old === new } + ) { + var hasTitle = false val unionKeys = a.keys + b.keys - val failures = mutableListOf() + for ((key, aValue, bValue) in unionKeys.map { Triple(it, a[it], b[it]) }) { if (!equal(aValue, bValue)) { + if (!hasTitle) { + failures += title + hasTitle = true + } failures += "diff at key = '$key': was: '$aValue', become: '$bValue'" } } - - assert(failures.isEmpty()) { - failures.joinToString(separator = "\n") - } } - fun checkMMapDiff(a: Map>, b: Map>) { + fun checkMMapDiff(title: String, a: Map>, b: Map>) { + var hasTitle = false val unionKeys = a.keys + b.keys - val failures = mutableListOf() - for ((key, aValue, bValue) in unionKeys.map { Triple(it, a[it], b[it])}) { + for ((key, aValue, bValue) in unionKeys.map { Triple(it, a[it], b[it]) }) { if (aValue == null || bValue == null) { + if (!hasTitle) { + failures += title + hasTitle = true + } failures += "diff at key = '$key': was: $aValue, become: $bValue" } else { val aSet = aValue.toSet() @@ -150,16 +176,21 @@ class FirProviderImpl(val session: FirSession) : FirProvider { } } + } + + checkMMapDiff("fileMap", state.fileMap, newState.fileMap) + checkMapDiff("classifierMap", state.classifierMap, newState.classifierMap) + checkMapDiff("classifierContainerFileMap", state.classifierContainerFileMap, newState.classifierContainerFileMap) + checkMMapDiff("callableMap", state.callableMap, newState.callableMap) + checkMapDiff("callableContainerMap", state.callableContainerMap, newState.callableContainerMap) + + if (!rebuildIndex) { assert(failures.isEmpty()) { failures.joinToString(separator = "\n") } + } else { + state.setFrom(newState) } - - checkMMapDiff(state.fileMap, newState.fileMap) - checkMapDiff(state.classifierMap, newState.classifierMap) - checkMapDiff(state.classifierContainerFileMap, newState.classifierContainerFileMap) - checkMMapDiff(state.callableMap, newState.callableMap) - checkMapDiff(state.callableContainerMap, newState.callableContainerMap) } override fun getClassUseSiteMemberScope(classId: ClassId, useSiteSession: FirSession): FirScope? { @@ -168,3 +199,5 @@ class FirProviderImpl(val session: FirSession) : FirProvider { } } + +private const val rebuildIndex = true