[Fir2Ir] Don't use FirSyntheticProperty as the cache key
^KT-64871
This commit is contained in:
committed by
Space Team
parent
c3c215b6a4
commit
2bf5a58a30
+12
@@ -35385,6 +35385,12 @@ public class LLFirBlackBoxCodegenBasedTestGenerated extends AbstractLLFirBlackBo
|
||||
runTest("compiler/testData/codegen/box/multiplatform/k2/extensionPropertiesOverloads.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("hashSetSize.kt")
|
||||
public void testHashSetSize() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/k2/hashSetSize.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("internalOverride.kt")
|
||||
public void testInternalOverride() throws Exception {
|
||||
@@ -35421,6 +35427,12 @@ public class LLFirBlackBoxCodegenBasedTestGenerated extends AbstractLLFirBlackBo
|
||||
runTest("compiler/testData/codegen/box/multiplatform/k2/staticjavaFieldInCommonCode.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("synteticProperty.kt")
|
||||
public void testSynteticProperty() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/k2/synteticProperty.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/multiplatform/k2/annotations")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
+12
@@ -35385,6 +35385,12 @@ public class LLFirReversedBlackBoxCodegenBasedTestGenerated extends AbstractLLFi
|
||||
runTest("compiler/testData/codegen/box/multiplatform/k2/extensionPropertiesOverloads.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("hashSetSize.kt")
|
||||
public void testHashSetSize() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/k2/hashSetSize.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("internalOverride.kt")
|
||||
public void testInternalOverride() throws Exception {
|
||||
@@ -35421,6 +35427,12 @@ public class LLFirReversedBlackBoxCodegenBasedTestGenerated extends AbstractLLFi
|
||||
runTest("compiler/testData/codegen/box/multiplatform/k2/staticjavaFieldInCommonCode.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("synteticProperty.kt")
|
||||
public void testSynteticProperty() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/k2/synteticProperty.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/multiplatform/k2/annotations")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
@@ -45,6 +45,7 @@ class Fir2IrCommonMemberStorage(
|
||||
val fieldCache: ConcurrentHashMap<FirField, IrFieldSymbol> = ConcurrentHashMap()
|
||||
|
||||
val propertyCache: ConcurrentHashMap<FirProperty, IrPropertySymbol> = ConcurrentHashMap()
|
||||
val syntheticPropertyCache: ConcurrentHashMap<FirFunction, IrPropertySymbol> = ConcurrentHashMap()
|
||||
val getterForPropertyCache: ConcurrentHashMap<IrSymbol, IrSimpleFunctionSymbol> = ConcurrentHashMap()
|
||||
val setterForPropertyCache: ConcurrentHashMap<IrSymbol, IrSimpleFunctionSymbol> = ConcurrentHashMap()
|
||||
val backingFieldForPropertyCache: ConcurrentHashMap<IrPropertySymbol, IrFieldSymbol> = ConcurrentHashMap()
|
||||
|
||||
+42
-12
@@ -82,7 +82,32 @@ class Fir2IrDeclarationStorage(
|
||||
|
||||
private val initializerCache: ConcurrentHashMap<FirAnonymousInitializer, IrAnonymousInitializer> = ConcurrentHashMap()
|
||||
|
||||
private val propertyCache: ConcurrentHashMap<FirProperty, IrPropertySymbol> = commonMemberStorage.propertyCache
|
||||
class PropertyCacheStorage(
|
||||
val normal: ConcurrentHashMap<FirProperty, IrPropertySymbol>,
|
||||
val synthetic: ConcurrentHashMap<FirFunction, IrPropertySymbol>
|
||||
) {
|
||||
/**
|
||||
* Fir synthetic properties are session-dependent, so it can't be used as a cache key
|
||||
* That's why, we are using original java function as a key in that case.
|
||||
*/
|
||||
private val FirSyntheticProperty.cacheKey
|
||||
get() = symbol.getterSymbol!!.delegateFunctionSymbol.fir
|
||||
|
||||
operator fun set(fir: FirProperty, value: IrPropertySymbol) {
|
||||
when (fir) {
|
||||
is FirSyntheticProperty -> synthetic[fir.cacheKey] = value
|
||||
else -> normal[fir] = value
|
||||
}
|
||||
}
|
||||
|
||||
operator fun get(fir: FirProperty): IrPropertySymbol? {
|
||||
return when (fir) {
|
||||
is FirSyntheticProperty -> synthetic[fir.cacheKey]
|
||||
else -> normal[fir]
|
||||
}
|
||||
}
|
||||
}
|
||||
private val propertyCache = PropertyCacheStorage(commonMemberStorage.propertyCache, commonMemberStorage.syntheticPropertyCache)
|
||||
private val getterForPropertyCache: ConcurrentHashMap<IrSymbol, IrSimpleFunctionSymbol> =
|
||||
commonMemberStorage.getterForPropertyCache
|
||||
private val setterForPropertyCache: ConcurrentHashMap<IrSymbol, IrSimpleFunctionSymbol> =
|
||||
@@ -104,7 +129,8 @@ class Fir2IrDeclarationStorage(
|
||||
fun forEachCachedDeclarationSymbol(block: (IrSymbol) -> Unit) {
|
||||
functionCache.values.forEachWithRemapping(symbolsMappingForLazyClasses::remapFunctionSymbol, block)
|
||||
constructorCache.values.forEach(block)
|
||||
propertyCache.values.forEachWithRemapping(symbolsMappingForLazyClasses::remapPropertySymbol, block)
|
||||
propertyCache.normal.values.forEachWithRemapping(symbolsMappingForLazyClasses::remapPropertySymbol, block)
|
||||
propertyCache.synthetic.values.forEachWithRemapping(symbolsMappingForLazyClasses::remapPropertySymbol, block)
|
||||
getterForPropertyCache.values.forEachWithRemapping(symbolsMappingForLazyClasses::remapFunctionSymbol, block)
|
||||
setterForPropertyCache.values.forEachWithRemapping(symbolsMappingForLazyClasses::remapFunctionSymbol, block)
|
||||
backingFieldForPropertyCache.values.forEach(block)
|
||||
@@ -315,7 +341,8 @@ class Fir2IrDeclarationStorage(
|
||||
val cachedIrCallable = getCachedIrCallableSymbol(
|
||||
function,
|
||||
fakeOverrideOwnerLookupTag,
|
||||
functionCache,
|
||||
functionCache::get,
|
||||
functionCache::set,
|
||||
signatureCalculator
|
||||
) { signature ->
|
||||
symbolTable.referenceSimpleFunctionIfAny(signature)
|
||||
@@ -757,7 +784,8 @@ class Fir2IrDeclarationStorage(
|
||||
val symbol = getCachedIrCallableSymbol(
|
||||
property,
|
||||
fakeOverrideOwnerLookupTag,
|
||||
propertyCache,
|
||||
propertyCache::get,
|
||||
propertyCache::set,
|
||||
signatureCalculator
|
||||
) { signature ->
|
||||
symbolTable.referencePropertyIfAny(signature)
|
||||
@@ -1138,7 +1166,8 @@ class Fir2IrDeclarationStorage(
|
||||
private inline fun <reified FC : FirCallableDeclaration, reified IS : IrSymbol> getCachedIrCallableSymbol(
|
||||
declaration: FC,
|
||||
fakeOverrideOwnerLookupTag: ConeClassLikeLookupTag?,
|
||||
cache: MutableMap<FC, IS>,
|
||||
cacheGetter: (FC) -> IS?,
|
||||
cacheSetter: (FC, IS) -> Unit,
|
||||
signatureCalculator: () -> IdSignature?,
|
||||
referenceIfAny: (IdSignature) -> IS?
|
||||
): IS? {
|
||||
@@ -1166,12 +1195,12 @@ class Fir2IrDeclarationStorage(
|
||||
)
|
||||
irForFirSessionDependantDeclarationMap[key]?.let { return it as IS }
|
||||
} else {
|
||||
cache[declaration]?.let { return it }
|
||||
cacheGetter(declaration)?.let { return it }
|
||||
}
|
||||
|
||||
// TODO: Special case mentioned above. Should be removed after fixing creation. KT-61085
|
||||
if (declaration.isSubstitutionOrIntersectionOverride) {
|
||||
cache[declaration]?.let { return it }
|
||||
cacheGetter(declaration)?.let { return it }
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1222,7 +1251,7 @@ class Fir2IrDeclarationStorage(
|
||||
*
|
||||
* TODO: potentially this situation won't happen after migration from FIR2IR f/o generator to IR f/o generator (see KT-58861)
|
||||
*/
|
||||
cache[declaration] = cachedInSymbolTable
|
||||
cacheSetter(declaration, cachedInSymbolTable)
|
||||
}
|
||||
declaration.initialSignatureAttr != null -> {
|
||||
/*
|
||||
@@ -1230,20 +1259,20 @@ class Fir2IrDeclarationStorage(
|
||||
* It leads to the situations when we have two different mapped FIR functions for the same original function
|
||||
* (and same IR function)
|
||||
*/
|
||||
cache[declaration] = cachedInSymbolTable
|
||||
cacheSetter(declaration, cachedInSymbolTable)
|
||||
}
|
||||
declaration.symbol is FirJavaOverriddenSyntheticPropertySymbol -> {
|
||||
/*
|
||||
* Synthetic properties for java classes, if those properties are based on real Kotlin properties are also session
|
||||
* dependant
|
||||
*/
|
||||
cache[declaration] = cachedInSymbolTable
|
||||
cacheSetter(declaration, cachedInSymbolTable)
|
||||
}
|
||||
declaration.origin.generatedAnyMethod -> {
|
||||
/*
|
||||
* Generated methods from Any for data and value classes are session-dependant
|
||||
*/
|
||||
cache[declaration] = cachedInSymbolTable
|
||||
cacheSetter(declaration, cachedInSymbolTable)
|
||||
}
|
||||
else -> {
|
||||
error("IR declaration with signature \"$signature\" found in SymbolTable and not found in declaration storage")
|
||||
@@ -1345,7 +1374,8 @@ class Fir2IrDeclarationStorage(
|
||||
@LeakedDeclarationCaches
|
||||
internal fun fillUnboundSymbols() {
|
||||
fillUnboundSymbols(functionCache)
|
||||
fillUnboundSymbols(propertyCache)
|
||||
fillUnboundSymbols(propertyCache.normal)
|
||||
fillUnboundSymbols(propertyCache.synthetic)
|
||||
}
|
||||
|
||||
@LeakedDeclarationCaches
|
||||
|
||||
+12
@@ -35000,6 +35000,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr
|
||||
runTest("compiler/testData/codegen/box/multiplatform/k2/extensionPropertiesOverloads.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("hashSetSize.kt")
|
||||
public void testHashSetSize() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/k2/hashSetSize.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("internalOverride.kt")
|
||||
public void testInternalOverride() throws Exception {
|
||||
@@ -35036,6 +35042,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr
|
||||
runTest("compiler/testData/codegen/box/multiplatform/k2/staticjavaFieldInCommonCode.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("synteticProperty.kt")
|
||||
public void testSynteticProperty() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/k2/synteticProperty.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/multiplatform/k2/annotations")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
+12
@@ -35000,6 +35000,12 @@ public class FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated
|
||||
runTest("compiler/testData/codegen/box/multiplatform/k2/extensionPropertiesOverloads.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("hashSetSize.kt")
|
||||
public void testHashSetSize() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/k2/hashSetSize.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("internalOverride.kt")
|
||||
public void testInternalOverride() throws Exception {
|
||||
@@ -35036,6 +35042,12 @@ public class FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated
|
||||
runTest("compiler/testData/codegen/box/multiplatform/k2/staticjavaFieldInCommonCode.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("synteticProperty.kt")
|
||||
public void testSynteticProperty() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/k2/synteticProperty.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/multiplatform/k2/annotations")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
+12
@@ -35000,6 +35000,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo
|
||||
runTest("compiler/testData/codegen/box/multiplatform/k2/extensionPropertiesOverloads.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("hashSetSize.kt")
|
||||
public void testHashSetSize() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/k2/hashSetSize.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("internalOverride.kt")
|
||||
public void testInternalOverride() throws Exception {
|
||||
@@ -35036,6 +35042,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo
|
||||
runTest("compiler/testData/codegen/box/multiplatform/k2/staticjavaFieldInCommonCode.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("synteticProperty.kt")
|
||||
public void testSynteticProperty() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/k2/synteticProperty.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/multiplatform/k2/annotations")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
// LANGUAGE: +MultiPlatformProjects
|
||||
// WITH_STDLIB
|
||||
// FULL_JDK
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
|
||||
// MODULE: common
|
||||
// FILE: common.kt
|
||||
|
||||
val p = LinkedHashMap<Any, Any>()
|
||||
|
||||
// MODULE: platform()()(common)
|
||||
// FILE: platform.kt
|
||||
|
||||
val q = object : LinkedHashMap<Any, Any>() {
|
||||
val s = size
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// LANGUAGE: +MultiPlatformProjects
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
|
||||
// MODULE: lib
|
||||
// FILE: Derived.java
|
||||
|
||||
public class Derived extends Base {
|
||||
public String getFoo() { return "OK"; }
|
||||
}
|
||||
|
||||
// FILE: Base.kt
|
||||
open class Base {
|
||||
open val foo: String
|
||||
get() = "FAIL"
|
||||
}
|
||||
|
||||
|
||||
// MODULE: common(lib)
|
||||
// FILE: common.kt
|
||||
|
||||
val p = Derived().foo
|
||||
|
||||
// MODULE: platform(lib)()(common)
|
||||
// FILE: platform.kt
|
||||
|
||||
val q = object : Derived() {
|
||||
val s = foo
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user