FIR IDE: Remove typesCache from KtSymbolByFirBuilder

This cache wasn't working too well, because ConeTypes have
equals/hashCode implementations which do not account for types'
attributes (like annotations, for example).

Because of that, `String` and `@Annotated String` were considered the
same type, and the cache was remembering whichever came first.
This commit is contained in:
Roman Golyshev
2022-01-26 14:00:18 +03:00
committed by TeamCityServer
parent 10ac98b029
commit 9ff46004e4
2 changed files with 8 additions and 14 deletions
@@ -9,10 +9,7 @@ import com.intellij.openapi.project.Project
import com.intellij.psi.JavaPsiFacade
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.util.containers.ContainerUtil
import org.jetbrains.kotlin.analysis.api.KtStarProjectionTypeArgument
import org.jetbrains.kotlin.analysis.api.KtTypeArgument
import org.jetbrains.kotlin.analysis.api.KtTypeArgumentWithVariance
import org.jetbrains.kotlin.analysis.api.ValidityTokenOwner
import org.jetbrains.kotlin.analysis.api.*
import org.jetbrains.kotlin.analysis.api.fir.symbols.*
import org.jetbrains.kotlin.analysis.api.fir.types.*
import org.jetbrains.kotlin.analysis.api.fir.utils.weakRef
@@ -63,7 +60,6 @@ internal class KtSymbolByFirBuilder private constructor(
private val extensionReceiverSymbolsCache: BuilderCache<FirCallableSymbol<*>, KtSymbol>,
private val filesCache: BuilderCache<FirFileSymbol, KtFileSymbol>,
private val backingFieldCache: BuilderCache<FirBackingFieldSymbol, KtBackingFieldSymbol>,
private val typesCache: BuilderCache<ConeKotlinType, KtType>,
) : ValidityTokenOwner {
private val resolveState by weakRef(resolveState)
@@ -88,7 +84,6 @@ internal class KtSymbolByFirBuilder private constructor(
withReadOnlyCaching = false,
symbolsCache = BuilderCache(),
extensionReceiverSymbolsCache = BuilderCache(),
typesCache = BuilderCache(),
backingFieldCache = BuilderCache(),
filesCache = BuilderCache(),
)
@@ -102,7 +97,6 @@ internal class KtSymbolByFirBuilder private constructor(
withReadOnlyCaching = true,
symbolsCache = symbolsCache.createReadOnlyCopy(),
extensionReceiverSymbolsCache = extensionReceiverSymbolsCache.createReadOnlyCopy(),
typesCache = typesCache.createReadOnlyCopy(),
filesCache = filesCache.createReadOnlyCopy(),
backingFieldCache = backingFieldCache.createReadOnlyCopy(),
)
@@ -427,7 +421,7 @@ internal class KtSymbolByFirBuilder private constructor(
inner class TypeBuilder {
fun buildKtType(coneType: ConeKotlinType): KtType {
return typesCache.cache(coneType) {
return withValidityAssertion {
when (coneType) {
is ConeClassLikeTypeImpl -> {
if (hasFunctionalClassId(coneType)) KtFirFunctionalType(coneType, token, this@KtSymbolByFirBuilder)
@@ -149,9 +149,9 @@ KtFunctionSymbol:
origin: SOURCE
receiverType: null
returnType: [
Anno2()
Anno3()
psi: KtAnnotationEntry
] @R|Anno2|() I
] @R|Anno3|() I
symbolKind: CLASS_MEMBER
typeParameters: []
valueParameters: [
@@ -182,9 +182,9 @@ KtKotlinPropertySymbol:
origin: SOURCE
receiverType: null
returnType: [
Anno2()
Anno4()
psi: KtAnnotationEntry
] @R|Anno2|() I
] @R|Anno4|() I
setter: null
symbolKind: CLASS_MEMBER
typeParameters: []
@@ -211,9 +211,9 @@ KtNamedClassOrObjectSymbol:
origin: SOURCE
superTypes: [
[
Anno2()
Anno1()
psi: KtAnnotationEntry
] @R|Anno2|() I
] @R|Anno1|() I
]
symbolKind: TOP_LEVEL
typeParameters: []