[Fir2IR] Get rid of simple symbol table usages
We have two sources of truth in Fir2Ir - declaration storages, which maps fir to ir symbols and symbolTable which maps IdSignature to ir symbol. The long-term goal is to have only one - declaration storages. This commit goes to this goal by removing all symbolTable usages that are straightforward to remove, i.e., all except: 1. classes as there is some code, that uses signature inside ClassSymbol 2. functions/properties as sometimes declaration storage fails to match symbols correctly (i.e. for generated data class members) 3. type parameters, as we need to remove functions first. As a side effect, it fixes some of the signature clash cases on valid code, as we no longer rely on signature uniqueness, except cases mentioned above. ^KT-65274 Fixed ^KT-64990
This commit is contained in:
committed by
Space Team
parent
06684f207a
commit
1cc138431d
+6
@@ -19352,6 +19352,12 @@ public class LLFirBlackBoxCodegenBasedTestGenerated extends AbstractLLFirBlackBo
|
||||
runTest("compiler/testData/codegen/box/fakeOverride/kt65116.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt65274.kt")
|
||||
public void testKt65274() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/fakeOverride/kt65274.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("methodOfAnyFromInterface.kt")
|
||||
public void testMethodOfAnyFromInterface() throws Exception {
|
||||
|
||||
+6
@@ -19352,6 +19352,12 @@ public class LLFirReversedBlackBoxCodegenBasedTestGenerated extends AbstractLLFi
|
||||
runTest("compiler/testData/codegen/box/fakeOverride/kt65116.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt65274.kt")
|
||||
public void testKt65274() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/fakeOverride/kt65274.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("methodOfAnyFromInterface.kt")
|
||||
public void testMethodOfAnyFromInterface() throws Exception {
|
||||
|
||||
@@ -586,7 +586,7 @@ internal fun IrDeclarationParent.declareThisReceiverParameter(
|
||||
explicitReceiver: FirReceiverParameter? = null,
|
||||
isAssignable: Boolean = false
|
||||
): IrValueParameter {
|
||||
return symbolTable.irFactory.createValueParameter(
|
||||
return irFactory.createValueParameter(
|
||||
startOffset = startOffset,
|
||||
endOffset = endOffset,
|
||||
origin = thisOrigin,
|
||||
|
||||
+3
-19
@@ -358,7 +358,7 @@ class Fir2IrClassifierStorage(
|
||||
} else {
|
||||
irParent.origin
|
||||
}
|
||||
val symbol = createEnumEntrySymbol(enumEntry)
|
||||
val symbol = IrEnumEntrySymbolImpl()
|
||||
return classifiersGenerator.createIrEnumEntry(
|
||||
enumEntry,
|
||||
irParent = irParent,
|
||||
@@ -369,34 +369,18 @@ class Fir2IrClassifierStorage(
|
||||
}
|
||||
}
|
||||
|
||||
private fun createEnumEntrySymbol(enumEntry: FirEnumEntry): IrEnumEntrySymbol {
|
||||
val signature = signatureComposer.composeSignature(enumEntry)
|
||||
return when {
|
||||
signature != null -> symbolTable.referenceEnumEntry(signature)
|
||||
else -> IrEnumEntrySymbolImpl()
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------ typealiases ------------------------------------
|
||||
|
||||
fun createAndCacheIrTypeAlias(
|
||||
typeAlias: FirTypeAlias,
|
||||
parent: IrDeclarationParent
|
||||
): IrTypeAlias {
|
||||
val symbol = createTypeAliasSymbol(typeAlias)
|
||||
val symbol = IrTypeAliasSymbolImpl()
|
||||
return classifiersGenerator.createIrTypeAlias(typeAlias, parent, symbol).also {
|
||||
typeAliasCache[typeAlias] = it
|
||||
}
|
||||
}
|
||||
|
||||
private fun createTypeAliasSymbol(typeAlias: FirTypeAlias): IrTypeAliasSymbol {
|
||||
val signature = signatureComposer.composeSignature(typeAlias)
|
||||
return when {
|
||||
signature != null -> symbolTable.referenceTypeAlias(signature)
|
||||
else -> IrTypeAliasSymbolImpl()
|
||||
}
|
||||
}
|
||||
|
||||
internal fun getCachedTypeAlias(firTypeAlias: FirTypeAlias): IrTypeAlias? = typeAliasCache[firTypeAlias]
|
||||
|
||||
fun referenceTypeAlias(firTypeAliasSymbol: FirTypeAliasSymbol): IrTypeAlias {
|
||||
@@ -413,7 +397,7 @@ class Fir2IrClassifierStorage(
|
||||
firTypeAlias.origin
|
||||
)!!
|
||||
|
||||
val symbol = createTypeAliasSymbol(firTypeAlias)
|
||||
val symbol = IrTypeAliasSymbolImpl()
|
||||
val irTypeAlias = lazyDeclarationsGenerator.createIrLazyTypeAlias(firTypeAlias, irParent, symbol)
|
||||
typeAliasCache[firTypeAlias] = irTypeAlias
|
||||
irTypeAlias.prepareTypeParameters()
|
||||
|
||||
+5
-16
@@ -598,7 +598,7 @@ class Fir2IrDeclarationStorage(
|
||||
}
|
||||
|
||||
val backingFieldSymbol = runIf(property.delegate != null || property.hasBackingField) {
|
||||
createFieldSymbol(signature = null)
|
||||
createFieldSymbol()
|
||||
}
|
||||
|
||||
return PropertySymbols(propertySymbol, getterSymbol, setterSymbol, backingFieldSymbol)
|
||||
@@ -888,8 +888,7 @@ class Fir2IrDeclarationStorage(
|
||||
origin: IrDeclarationOrigin = IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB
|
||||
): IrField {
|
||||
val containingClassLookupTag = (irParent as IrClass?)?.classId?.toLookupTag()
|
||||
val signature = signatureComposer.composeSignature(field, containingClassLookupTag)
|
||||
val symbol = createFieldSymbol(signature)
|
||||
val symbol = createFieldSymbol()
|
||||
|
||||
val irField = callablesGenerator.createIrField(field, irParent, symbol, type, origin)
|
||||
|
||||
@@ -902,11 +901,8 @@ class Fir2IrDeclarationStorage(
|
||||
return irField
|
||||
}
|
||||
|
||||
private fun createFieldSymbol(signature: IdSignature?): IrFieldSymbol {
|
||||
return when {
|
||||
signature != null -> symbolTable.referenceField(signature)
|
||||
else -> IrFieldSymbolImpl()
|
||||
}
|
||||
private fun createFieldSymbol(): IrFieldSymbol {
|
||||
return IrFieldSymbolImpl()
|
||||
}
|
||||
|
||||
// This function returns null if this field/ownerClassId combination does not describe static fake override
|
||||
@@ -1374,19 +1370,12 @@ class Fir2IrDeclarationStorage(
|
||||
|
||||
fun createIrScript(script: FirScript): IrScript {
|
||||
getCachedIrScript(script)?.let { error("IrScript already created: ${script.render()}") }
|
||||
val symbol = createScriptSymbol(signatureComposer.composeSignature(script))
|
||||
val symbol = IrScriptSymbolImpl()
|
||||
return callablesGenerator.createIrScript(script, symbol).also {
|
||||
scriptCache[script] = it
|
||||
}
|
||||
}
|
||||
|
||||
private fun createScriptSymbol(signature: IdSignature?): IrScriptSymbol {
|
||||
return when {
|
||||
signature != null -> symbolTable.referenceScript(signature)
|
||||
else -> IrScriptSymbolImpl()
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------ scoping ------------------------------------
|
||||
|
||||
fun enterScope(symbol: IrSymbol) {
|
||||
|
||||
@@ -59,7 +59,7 @@ class IrBuiltInsOverFir(
|
||||
private val symbolProvider: FirSymbolProvider
|
||||
get() = session.symbolProvider
|
||||
|
||||
override val irFactory: IrFactory = components.symbolTable.irFactory
|
||||
override val irFactory: IrFactory = components.irFactory
|
||||
|
||||
private val kotlinPackage = StandardClassIds.BASE_KOTLIN_PACKAGE
|
||||
|
||||
|
||||
+6
@@ -19341,6 +19341,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr
|
||||
runTest("compiler/testData/codegen/box/fakeOverride/kt65116.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt65274.kt")
|
||||
public void testKt65274() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/fakeOverride/kt65274.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("methodOfAnyFromInterface.kt")
|
||||
public void testMethodOfAnyFromInterface() throws Exception {
|
||||
|
||||
+6
@@ -19341,6 +19341,12 @@ public class FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated
|
||||
runTest("compiler/testData/codegen/box/fakeOverride/kt65116.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt65274.kt")
|
||||
public void testKt65274() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/fakeOverride/kt65274.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("methodOfAnyFromInterface.kt")
|
||||
public void testMethodOfAnyFromInterface() throws Exception {
|
||||
|
||||
+6
@@ -19341,6 +19341,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo
|
||||
runTest("compiler/testData/codegen/box/fakeOverride/kt65116.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt65274.kt")
|
||||
public void testKt65274() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/fakeOverride/kt65274.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("methodOfAnyFromInterface.kt")
|
||||
public void testMethodOfAnyFromInterface() throws Exception {
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
// FILE: a/A.java
|
||||
package a;
|
||||
|
||||
public class A {
|
||||
static final String X = "Fail";
|
||||
}
|
||||
|
||||
// FILE: B.java
|
||||
public class B extends a.A {
|
||||
private final String X = "OK";
|
||||
|
||||
public String get() { return X; }
|
||||
}
|
||||
|
||||
// FILE: box.kt
|
||||
class C : B()
|
||||
|
||||
fun box(): String = C().get()
|
||||
+6
@@ -19341,6 +19341,12 @@ public class JvmAbiConsistencyTestBoxGenerated extends AbstractJvmAbiConsistency
|
||||
runTest("compiler/testData/codegen/box/fakeOverride/kt65116.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt65274.kt")
|
||||
public void testKt65274() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/fakeOverride/kt65274.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("methodOfAnyFromInterface.kt")
|
||||
public void testMethodOfAnyFromInterface() throws Exception {
|
||||
|
||||
+6
@@ -18489,6 +18489,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/fakeOverride/kt49371.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt65274.kt")
|
||||
public void testKt65274() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/fakeOverride/kt65274.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("methodOfAnyFromInterface.kt")
|
||||
public void testMethodOfAnyFromInterface() throws Exception {
|
||||
|
||||
+6
@@ -19341,6 +19341,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/fakeOverride/kt65116.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt65274.kt")
|
||||
public void testKt65274() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/fakeOverride/kt65274.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("methodOfAnyFromInterface.kt")
|
||||
public void testMethodOfAnyFromInterface() throws Exception {
|
||||
|
||||
+6
@@ -19341,6 +19341,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack
|
||||
runTest("compiler/testData/codegen/box/fakeOverride/kt65116.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt65274.kt")
|
||||
public void testKt65274() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/fakeOverride/kt65274.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("methodOfAnyFromInterface.kt")
|
||||
public void testMethodOfAnyFromInterface() throws Exception {
|
||||
|
||||
+5
@@ -16114,6 +16114,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/fakeOverride/kt65116.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt65274.kt")
|
||||
public void testKt65274() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/fakeOverride/kt65274.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("methodOfAnyFromInterface.kt")
|
||||
public void testMethodOfAnyFromInterface() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/fakeOverride/methodOfAnyFromInterface.kt");
|
||||
|
||||
Reference in New Issue
Block a user