[FIR2IR] Manage field symbols in declaration storage instead of declaration generator
This is needed to be able to implement creation of unbound symbols for references of corresponding declarations (KT-62856)
This commit is contained in:
committed by
Space Team
parent
aadc9ce6d5
commit
cd0baef087
+11
-4
@@ -578,7 +578,7 @@ class Fir2IrDeclarationStorage(
|
||||
}
|
||||
|
||||
val backingFieldSymbol = runIf(property.delegate != null || property.hasBackingField) {
|
||||
createFieldSymbol()
|
||||
createFieldSymbol(signature = null)
|
||||
}
|
||||
|
||||
return PropertySymbols(propertySymbol, getterSymbol, setterSymbol, backingFieldSymbol)
|
||||
@@ -798,8 +798,12 @@ class Fir2IrDeclarationStorage(
|
||||
type: ConeKotlinType = field.returnTypeRef.coneType,
|
||||
origin: IrDeclarationOrigin = IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB
|
||||
): IrField {
|
||||
val irField = callablesGenerator.createIrField(field, irParent, type, origin)
|
||||
val containingClassLookupTag = (irParent as IrClass?)?.classId?.toLookupTag()
|
||||
val signature = signatureComposer.composeSignature(field, containingClassLookupTag)
|
||||
val symbol = createFieldSymbol(signature)
|
||||
|
||||
val irField = callablesGenerator.createIrField(field, irParent, symbol, type, origin)
|
||||
|
||||
val staticFakeOverrideKey = getFieldStaticFakeOverrideKey(field, containingClassLookupTag)
|
||||
if (staticFakeOverrideKey == null) {
|
||||
fieldCache[field] = irField.symbol
|
||||
@@ -809,8 +813,11 @@ class Fir2IrDeclarationStorage(
|
||||
return irField
|
||||
}
|
||||
|
||||
private fun createFieldSymbol(): IrFieldSymbol {
|
||||
return IrFieldSymbolImpl()
|
||||
private fun createFieldSymbol(signature: IdSignature?): IrFieldSymbol {
|
||||
return when {
|
||||
signature != null -> symbolTable.referenceField(signature)
|
||||
else -> IrFieldSymbolImpl()
|
||||
}
|
||||
}
|
||||
|
||||
// This function returns null if this field/ownerClassId combination does not describe static fake override
|
||||
|
||||
+15
-36
@@ -549,56 +549,35 @@ class Fir2IrCallableDeclarationsGenerator(val components: Fir2IrComponents) : Fi
|
||||
internal fun createIrField(
|
||||
field: FirField,
|
||||
irParent: IrDeclarationParent?,
|
||||
symbol: IrFieldSymbol,
|
||||
type: ConeKotlinType = field.returnTypeRef.coneType,
|
||||
origin: IrDeclarationOrigin = IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB
|
||||
): IrField = convertCatching(field) {
|
||||
val irType = type.toIrType()
|
||||
val classId = (irParent as? IrClass)?.classId
|
||||
val containingClassLookupTag = classId?.toLookupTag()
|
||||
val signature = signatureComposer.composeSignature(field, containingClassLookupTag)
|
||||
|
||||
val parentIsExternal = irParent.isExternalParent()
|
||||
if (field is FirJavaField && field.isStatic && field.isFinal && parentIsExternal && signature != null) {
|
||||
if (field is FirJavaField && field.isStatic && field.isFinal && parentIsExternal) {
|
||||
// We are going to create IR for Java static final fields lazily because they can refer to some Kotlin const.
|
||||
// This way we delay const evaluation of Java fields until IR tree is fully built, and we can run IR interpreter.
|
||||
return lazyDeclarationsGenerator.createIrLazyField(field, signature, irParent!!, origin).apply {
|
||||
return lazyDeclarationsGenerator.createIrLazyField(field, symbol, irParent!!, origin).apply {
|
||||
setParent(irParent)
|
||||
addDeclarationToParent(this, irParent)
|
||||
}
|
||||
}
|
||||
|
||||
return field.convertWithOffsets { startOffset, endOffset ->
|
||||
if (signature != null) {
|
||||
symbolTable.declareField(
|
||||
signature, symbolFactory = { IrFieldPublicSymbolImpl(signature) }
|
||||
) { symbol ->
|
||||
irFactory.createField(
|
||||
startOffset = startOffset,
|
||||
endOffset = endOffset,
|
||||
origin = origin,
|
||||
name = field.name,
|
||||
visibility = components.visibilityConverter.convertToDescriptorVisibility(field.visibility),
|
||||
symbol = symbol,
|
||||
type = irType,
|
||||
isFinal = field.modality == Modality.FINAL,
|
||||
isStatic = field.isStatic,
|
||||
isExternal = false
|
||||
)
|
||||
}
|
||||
} else {
|
||||
irFactory.createField(
|
||||
startOffset = startOffset,
|
||||
endOffset = endOffset,
|
||||
origin = origin,
|
||||
name = field.name,
|
||||
visibility = components.visibilityConverter.convertToDescriptorVisibility(field.visibility),
|
||||
symbol = IrFieldSymbolImpl(),
|
||||
type = irType,
|
||||
isFinal = field.modality == Modality.FINAL,
|
||||
isStatic = field.isStatic,
|
||||
isExternal = false
|
||||
)
|
||||
}.apply {
|
||||
irFactory.createField(
|
||||
startOffset = startOffset,
|
||||
endOffset = endOffset,
|
||||
origin = origin,
|
||||
name = field.name,
|
||||
visibility = components.visibilityConverter.convertToDescriptorVisibility(field.visibility),
|
||||
symbol = symbol,
|
||||
type = irType,
|
||||
isFinal = field.modality == Modality.FINAL,
|
||||
isStatic = field.isStatic,
|
||||
isExternal = false
|
||||
).apply {
|
||||
metadata = FirMetadataSource.Field(field)
|
||||
val initializer = field.unwrapFakeOverrides().initializer
|
||||
if (initializer is FirConstExpression<*>) {
|
||||
|
||||
+5
-6
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.fir.lazy.*
|
||||
import org.jetbrains.kotlin.fir.resolve.providers.firProvider
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrFieldSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.IrFieldPublicSymbolImpl
|
||||
import org.jetbrains.kotlin.ir.util.IdSignature
|
||||
@@ -95,16 +96,14 @@ class Fir2IrLazyDeclarationsGenerator(val components: Fir2IrComponents) : Fir2Ir
|
||||
|
||||
fun createIrLazyField(
|
||||
fir: FirField,
|
||||
signature: IdSignature,
|
||||
symbol: IrFieldSymbol,
|
||||
lazyParent: IrDeclarationParent,
|
||||
declarationOrigin: IrDeclarationOrigin
|
||||
): IrField {
|
||||
return fir.convertWithOffsets { startOffset, endOffset ->
|
||||
symbolTable.declareField(signature, symbolFactory = { IrFieldPublicSymbolImpl(signature) }) { symbol ->
|
||||
Fir2IrLazyField(
|
||||
components, startOffset, endOffset, declarationOrigin, fir, (lazyParent as? Fir2IrLazyClass)?.fir, symbol
|
||||
)
|
||||
}
|
||||
Fir2IrLazyField(
|
||||
components, startOffset, endOffset, declarationOrigin, fir, (lazyParent as? Fir2IrLazyClass)?.fir, symbol
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user