Revert "Fix performance issue for case when there are a lot of warnings in file"

This reverts commit 3d8e5c4f8e.

 Temporarily reverting this commit due to new flaky tests
This commit is contained in:
Mikhail Zarechenskiy
2019-10-12 00:42:43 +03:00
parent c13f55f0ad
commit 83bb07e5ac
6 changed files with 10 additions and 32 deletions
@@ -336,9 +336,6 @@ private class LazyJvmDiagnostics(compute: () -> Diagnostics) : Diagnostics {
override fun noSuppression() = delegate.noSuppression()
override fun hasDiagnostic(diagnostic: Diagnostic) =
delegate.hasDiagnostic(diagnostic)
override fun iterator() = delegate.iterator()
}
@@ -112,9 +112,9 @@ fun ResolutionContext<*>.reportTypeMismatchDueToTypeProjection(
}
fun BindingTrace.reportDiagnosticOnce(diagnostic: Diagnostic) {
if (!bindingContext.diagnostics.hasDiagnostic(diagnostic)) {
report(diagnostic)
}
if (bindingContext.diagnostics.forElement(diagnostic.psiElement).any { it.factory == diagnostic.factory }) return
report(diagnostic)
}
class TypeMismatchDueToTypeProjectionsData(
@@ -93,9 +93,5 @@ class CompositeBindingContext private constructor(
override fun noSuppression(): Diagnostics {
return CompositeDiagnostics(delegates.map { it.noSuppression() })
}
override fun hasDiagnostic(diagnostic: Diagnostic): Boolean {
return delegates.any { it.hasDiagnostic(diagnostic) }
}
}
}
@@ -34,10 +34,6 @@ interface Diagnostics : Iterable<Diagnostic> {
fun noSuppression(): Diagnostics
@JvmDefault
fun hasDiagnostic(diagnostic: Diagnostic): Boolean =
forElement(diagnostic.psiElement).any { it.factory == diagnostic.factory }
override fun iterator() = all().iterator()
companion object {
@@ -46,7 +42,6 @@ interface Diagnostics : Iterable<Diagnostic> {
override val modificationTracker: ModificationTracker = ModificationTracker.NEVER_CHANGED
override fun all() = listOf<Diagnostic>()
override fun forElement(psiElement: PsiElement) = listOf<Diagnostic>()
override fun hasDiagnostic(diagnostic: Diagnostic): Boolean = false
}
}
}
@@ -17,11 +17,11 @@
package org.jetbrains.kotlin.resolve.diagnostics
import org.jetbrains.kotlin.diagnostics.Diagnostic
import java.util.ArrayList
import com.intellij.openapi.util.CompositeModificationTracker
import com.intellij.util.CachedValueImpl
import com.intellij.psi.util.CachedValueProvider
import com.intellij.psi.PsiElement
import com.intellij.util.SmartList
import org.jetbrains.annotations.TestOnly
import org.jetbrains.kotlin.resolve.BindingContext
@@ -29,12 +29,11 @@ class MutableDiagnosticsWithSuppression @JvmOverloads constructor(
private val bindingContext: BindingContext,
private val delegateDiagnostics: Diagnostics = Diagnostics.EMPTY
) : Diagnostics {
// Usually, we don't report on an element more than one diagnostic, so it's better to use SmartList here
private val diagnosticMap = HashMap<PsiElement, SmartList<Diagnostic>>()
private val diagnosticList = ArrayList<Diagnostic>()
//NOTE: CachedValuesManager is not used because it requires Project passed to this object
private val cache = CachedValueImpl(CachedValueProvider {
val allDiagnostics = delegateDiagnostics.noSuppression().all() + getOwnDiagnostics()
val allDiagnostics = delegateDiagnostics.noSuppression().all() + diagnosticList
CachedValueProvider.Result(DiagnosticsWithSuppression(bindingContext, allDiagnostics), modificationTracker)
})
@@ -48,29 +47,19 @@ class MutableDiagnosticsWithSuppression @JvmOverloads constructor(
//essential that this list is readonly
fun getOwnDiagnostics(): List<Diagnostic> {
return diagnosticMap.values.flatten()
return diagnosticList
}
fun report(diagnostic: Diagnostic) {
diagnosticMap.getOrPut(diagnostic.psiElement, { SmartList() }).add(diagnostic)
diagnosticList.add(diagnostic)
modificationTracker.incModificationCount()
}
fun clear() {
diagnosticMap.clear()
diagnosticList.clear()
modificationTracker.incModificationCount()
}
override fun hasDiagnostic(diagnostic: Diagnostic): Boolean {
if (cache.hasUpToDateValue()) return cache.value.hasDiagnostic(diagnostic)
if (delegateDiagnostics.hasDiagnostic(diagnostic)) return true
// It's totally fine to check without any suppression logic as if passed diagnostic has the same factory & psiElement,
// then it has the same suppression logic, so it doesn't matter if we add it or not later
val list = diagnosticMap[diagnostic.psiElement] ?: return false
return list.any { it.factory == diagnostic.factory && it.psiElement == diagnostic.psiElement }
}
@TestOnly
fun getReadonlyView(): DiagnosticsWithSuppression = readonlyView()
}
@@ -16,6 +16,7 @@
package org.jetbrains.kotlin.resolve.diagnostics
import com.intellij.openapi.util.Condition
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.diagnostics.Diagnostic
import java.util.ArrayList