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.JavaPsiFacade
import com.intellij.psi.search.GlobalSearchScope import com.intellij.psi.search.GlobalSearchScope
import com.intellij.util.containers.ContainerUtil import com.intellij.util.containers.ContainerUtil
import org.jetbrains.kotlin.analysis.api.KtStarProjectionTypeArgument import org.jetbrains.kotlin.analysis.api.*
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.fir.symbols.* import org.jetbrains.kotlin.analysis.api.fir.symbols.*
import org.jetbrains.kotlin.analysis.api.fir.types.* import org.jetbrains.kotlin.analysis.api.fir.types.*
import org.jetbrains.kotlin.analysis.api.fir.utils.weakRef 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 extensionReceiverSymbolsCache: BuilderCache<FirCallableSymbol<*>, KtSymbol>,
private val filesCache: BuilderCache<FirFileSymbol, KtFileSymbol>, private val filesCache: BuilderCache<FirFileSymbol, KtFileSymbol>,
private val backingFieldCache: BuilderCache<FirBackingFieldSymbol, KtBackingFieldSymbol>, private val backingFieldCache: BuilderCache<FirBackingFieldSymbol, KtBackingFieldSymbol>,
private val typesCache: BuilderCache<ConeKotlinType, KtType>,
) : ValidityTokenOwner { ) : ValidityTokenOwner {
private val resolveState by weakRef(resolveState) private val resolveState by weakRef(resolveState)
@@ -88,7 +84,6 @@ internal class KtSymbolByFirBuilder private constructor(
withReadOnlyCaching = false, withReadOnlyCaching = false,
symbolsCache = BuilderCache(), symbolsCache = BuilderCache(),
extensionReceiverSymbolsCache = BuilderCache(), extensionReceiverSymbolsCache = BuilderCache(),
typesCache = BuilderCache(),
backingFieldCache = BuilderCache(), backingFieldCache = BuilderCache(),
filesCache = BuilderCache(), filesCache = BuilderCache(),
) )
@@ -102,7 +97,6 @@ internal class KtSymbolByFirBuilder private constructor(
withReadOnlyCaching = true, withReadOnlyCaching = true,
symbolsCache = symbolsCache.createReadOnlyCopy(), symbolsCache = symbolsCache.createReadOnlyCopy(),
extensionReceiverSymbolsCache = extensionReceiverSymbolsCache.createReadOnlyCopy(), extensionReceiverSymbolsCache = extensionReceiverSymbolsCache.createReadOnlyCopy(),
typesCache = typesCache.createReadOnlyCopy(),
filesCache = filesCache.createReadOnlyCopy(), filesCache = filesCache.createReadOnlyCopy(),
backingFieldCache = backingFieldCache.createReadOnlyCopy(), backingFieldCache = backingFieldCache.createReadOnlyCopy(),
) )
@@ -427,7 +421,7 @@ internal class KtSymbolByFirBuilder private constructor(
inner class TypeBuilder { inner class TypeBuilder {
fun buildKtType(coneType: ConeKotlinType): KtType { fun buildKtType(coneType: ConeKotlinType): KtType {
return typesCache.cache(coneType) { return withValidityAssertion {
when (coneType) { when (coneType) {
is ConeClassLikeTypeImpl -> { is ConeClassLikeTypeImpl -> {
if (hasFunctionalClassId(coneType)) KtFirFunctionalType(coneType, token, this@KtSymbolByFirBuilder) if (hasFunctionalClassId(coneType)) KtFirFunctionalType(coneType, token, this@KtSymbolByFirBuilder)
@@ -149,9 +149,9 @@ KtFunctionSymbol:
origin: SOURCE origin: SOURCE
receiverType: null receiverType: null
returnType: [ returnType: [
Anno2() Anno3()
psi: KtAnnotationEntry psi: KtAnnotationEntry
] @R|Anno2|() I ] @R|Anno3|() I
symbolKind: CLASS_MEMBER symbolKind: CLASS_MEMBER
typeParameters: [] typeParameters: []
valueParameters: [ valueParameters: [
@@ -182,9 +182,9 @@ KtKotlinPropertySymbol:
origin: SOURCE origin: SOURCE
receiverType: null receiverType: null
returnType: [ returnType: [
Anno2() Anno4()
psi: KtAnnotationEntry psi: KtAnnotationEntry
] @R|Anno2|() I ] @R|Anno4|() I
setter: null setter: null
symbolKind: CLASS_MEMBER symbolKind: CLASS_MEMBER
typeParameters: [] typeParameters: []
@@ -211,9 +211,9 @@ KtNamedClassOrObjectSymbol:
origin: SOURCE origin: SOURCE
superTypes: [ superTypes: [
[ [
Anno2() Anno1()
psi: KtAnnotationEntry psi: KtAnnotationEntry
] @R|Anno2|() I ] @R|Anno1|() I
] ]
symbolKind: TOP_LEVEL symbolKind: TOP_LEVEL
typeParameters: [] typeParameters: []