[FIR2IR] Allow symbolTable cache lookups for mapped JVM declarations

This commit is contained in:
Dmitriy Novozhilov
2023-09-13 13:47:50 +03:00
committed by Space Team
parent 0e92f98031
commit 85c2226335
8 changed files with 89 additions and 3 deletions
@@ -19,6 +19,7 @@ import org.jetbrains.kotlin.fir.declarations.utils.visibility
import org.jetbrains.kotlin.fir.descriptors.FirBuiltInsPackageFragment
import org.jetbrains.kotlin.fir.descriptors.FirModuleDescriptor
import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression
import org.jetbrains.kotlin.fir.java.symbols.FirJavaOverriddenSyntheticPropertySymbol
import org.jetbrains.kotlin.fir.lazy.Fir2IrLazyClass
import org.jetbrains.kotlin.fir.lazy.Fir2IrLazyConstructor
import org.jetbrains.kotlin.fir.references.toResolvedValueParameterSymbol
@@ -1025,7 +1026,6 @@ class Fir2IrDeclarationStorage(
fakeOverrideOwnerLookupTag ?: declaration.containingClassLookupTag()!!
)
irFakeOverridesForFirFakeOverrideMap[key] = cachedInSymbolTable
return cachedInSymbolTable
}
configuration.useIrFakeOverrideBuilder -> {
/*
@@ -1036,12 +1036,27 @@ 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
return cachedInSymbolTable
}
declaration.initialSignatureAttr != null -> {
/*
* FIR creates remapped functions for builtin JVM classes based on use-site session, not declaration site
* 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
}
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
}
else -> {
error("IR declaration with signature $signature found in SymbolTable and not found in declaration storage")
error("IR declaration with signature \"$signature\" found in SymbolTable and not found in declaration storage")
}
}
return cachedInSymbolTable
}
return null
@@ -34044,6 +34044,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr
runTest("compiler/testData/codegen/box/multiplatform/k2/javaMethodWithTypeParameter.kt");
}
@Test
@TestMetadata("jvmDeclarationsUpdatedMembersInCommonModule.kt")
public void testJvmDeclarationsUpdatedMembersInCommonModule() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/k2/jvmDeclarationsUpdatedMembersInCommonModule.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/box/multiplatform/k2/annotations")
@TestDataPath("$PROJECT_ROOT")
@@ -34044,6 +34044,12 @@ public class FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated
runTest("compiler/testData/codegen/box/multiplatform/k2/javaMethodWithTypeParameter.kt");
}
@Test
@TestMetadata("jvmDeclarationsUpdatedMembersInCommonModule.kt")
public void testJvmDeclarationsUpdatedMembersInCommonModule() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/k2/jvmDeclarationsUpdatedMembersInCommonModule.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/box/multiplatform/k2/annotations")
@TestDataPath("$PROJECT_ROOT")
@@ -34044,6 +34044,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo
runTest("compiler/testData/codegen/box/multiplatform/k2/javaMethodWithTypeParameter.kt");
}
@Test
@TestMetadata("jvmDeclarationsUpdatedMembersInCommonModule.kt")
public void testJvmDeclarationsUpdatedMembersInCommonModule() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/k2/jvmDeclarationsUpdatedMembersInCommonModule.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/box/multiplatform/k2/annotations")
@TestDataPath("$PROJECT_ROOT")
@@ -0,0 +1,36 @@
// TARGET_BACKEND: JVM_IR
// LANGUAGE: +MultiPlatformProjects
// WITH_STDLIB
// FULL_JDK
// MODULE: common
// FILE: common.kt
/*
* During JVM compilation compiler creates mapped function for java.util.HashMap.contains twice (because they are session-dependant)
* The same happens with renamed synthetic properties based on real kotlin properties (LinkedHashMap.keySet() -> LinkedHashMap.keys)
*/
fun boxCommon(x: LinkedHashMap<Int, Int>?): String {
val res = hashSetOf<Int>().contains(12)
x?.keys
return if (res) {
"Error"
} else {
"O"
}
}
// MODULE: platform()()(common)
// FILE: platform.kt
fun boxPlatform(x: LinkedHashMap<Int, Int>?): String {
val res = hashSetOf<Int>().contains(12)
x?.keys
return if (res) {
"Error"
} else {
"K"
}
}
fun box(): String {
return boxCommon(null) + boxPlatform(null)
}
@@ -34044,6 +34044,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/multiplatform/k2/javaMethodWithTypeParameter.kt");
}
@Test
@TestMetadata("jvmDeclarationsUpdatedMembersInCommonModule.kt")
public void testJvmDeclarationsUpdatedMembersInCommonModule() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/k2/jvmDeclarationsUpdatedMembersInCommonModule.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/box/multiplatform/k2/annotations")
@TestDataPath("$PROJECT_ROOT")
@@ -34044,6 +34044,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack
runTest("compiler/testData/codegen/box/multiplatform/k2/javaMethodWithTypeParameter.kt");
}
@Test
@TestMetadata("jvmDeclarationsUpdatedMembersInCommonModule.kt")
public void testJvmDeclarationsUpdatedMembersInCommonModule() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/k2/jvmDeclarationsUpdatedMembersInCommonModule.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/box/multiplatform/k2/annotations")
@TestDataPath("$PROJECT_ROOT")
@@ -29011,6 +29011,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/multiplatform/k2/javaMethodWithTypeParameter.kt");
}
@TestMetadata("jvmDeclarationsUpdatedMembersInCommonModule.kt")
public void testJvmDeclarationsUpdatedMembersInCommonModule() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/k2/jvmDeclarationsUpdatedMembersInCommonModule.kt");
}
@TestMetadata("compiler/testData/codegen/box/multiplatform/k2/annotations")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)