[FIR] Introduce cache for not-yet-enhanced synthetic properties
The original synthetic properties from Java were not cached anywhere and created anew for every session. However, the enhanced properties are (along with their originals) saved inside the session's cache, causing inconsistency with newly created symbols via referential equality.
This commit is contained in:
committed by
Space Team
parent
cb655d2d37
commit
075a80613b
+27
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.fir.java
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.FirSessionComponent
|
||||
import org.jetbrains.kotlin.fir.caches.FirCache
|
||||
import org.jetbrains.kotlin.fir.caches.createCache
|
||||
import org.jetbrains.kotlin.fir.caches.firCachesFactory
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirSyntheticPropertySymbol
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
class FirOriginalSyntheticPropertiesStorage(session: FirSession) : FirSessionComponent {
|
||||
private val cachesFactory = session.firCachesFactory
|
||||
|
||||
val cacheByOwner: FirCache<FirRegularClassSymbol, FirCache<Name, FirSyntheticPropertySymbol, FirSyntheticPropertySymbol>, Nothing?> =
|
||||
cachesFactory.createCache { _ ->
|
||||
cachesFactory.createCache { _, symbol -> symbol }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
val FirSession.originalSyntheticPropertiesStorage: FirOriginalSyntheticPropertiesStorage by FirSession.sessionComponentAccessor()
|
||||
+6
-3
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.fir.java.declarations.FirJavaMethod
|
||||
import org.jetbrains.kotlin.fir.java.declarations.buildJavaMethodCopy
|
||||
import org.jetbrains.kotlin.fir.java.declarations.buildJavaValueParameterCopy
|
||||
import org.jetbrains.kotlin.fir.java.symbols.FirJavaOverriddenSyntheticPropertySymbol
|
||||
import org.jetbrains.kotlin.fir.java.originalSyntheticPropertiesStorage
|
||||
import org.jetbrains.kotlin.fir.java.toConeKotlinTypeProbablyFlexible
|
||||
import org.jetbrains.kotlin.fir.resolve.defaultType
|
||||
import org.jetbrains.kotlin.fir.scopes.*
|
||||
@@ -59,19 +60,21 @@ class JavaClassUseSiteMemberScope(
|
||||
declaredMemberScope
|
||||
) {
|
||||
private val typeParameterStack = klass.javaTypeParameterStack
|
||||
private val syntheticPropertyByNameMap = hashMapOf<Name, FirSyntheticPropertySymbol>()
|
||||
|
||||
private val canUseSpecialGetters: Boolean by lazy { !klass.hasKotlinSuper(session) }
|
||||
|
||||
private val javaOverrideChecker: JavaOverrideChecker get() = overrideChecker as JavaOverrideChecker
|
||||
|
||||
private val syntheticPropertyCache = session.originalSyntheticPropertiesStorage.cacheByOwner.getValue(klass.symbol, null)
|
||||
|
||||
private fun generateSyntheticPropertySymbol(
|
||||
getterSymbol: FirNamedFunctionSymbol,
|
||||
setterSymbol: FirNamedFunctionSymbol?,
|
||||
property: FirProperty,
|
||||
takeModalityFromGetter: Boolean,
|
||||
): FirSyntheticPropertySymbol {
|
||||
return syntheticPropertyByNameMap.getOrPut(property.name) {
|
||||
return syntheticPropertyCache.getValue(
|
||||
property.name,
|
||||
buildSyntheticProperty {
|
||||
moduleData = session.moduleData
|
||||
name = property.name
|
||||
@@ -90,7 +93,7 @@ class JavaClassUseSiteMemberScope(
|
||||
)
|
||||
deprecationsProvider = getDeprecationsProviderFromAccessors(session, delegateGetter, delegateSetter)
|
||||
}.symbol
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
private fun chooseModalityForAccessor(property: FirProperty, getter: FirSimpleFunction): Modality? {
|
||||
|
||||
Reference in New Issue
Block a user