[FIR2IR] Use IrSymbols directly instead of referencing via SymbolTable
This commit is contained in:
@@ -350,12 +350,11 @@ class Fir2IrClassifierStorage(
|
||||
|
||||
fun getIrClassSymbol(firClassSymbol: FirClassSymbol<*>): IrClassSymbol {
|
||||
val firClass = firClassSymbol.fir
|
||||
getCachedIrClass(firClass)?.let { return symbolTable.referenceClass(it.descriptor) }
|
||||
// TODO: remove all this code and change to unbound symbol creation
|
||||
getCachedIrClass(firClass)?.let { return it.symbol }
|
||||
if (firClass is FirAnonymousObject || firClass is FirRegularClass && firClass.visibility == Visibilities.LOCAL) {
|
||||
val irClass = createIrClass(firClass)
|
||||
return symbolTable.referenceClass(irClass.descriptor)
|
||||
return createIrClass(firClass).symbol
|
||||
}
|
||||
// TODO: remove all this code and change to unbound symbol creation
|
||||
val classId = firClassSymbol.classId
|
||||
val parentId = classId.outerClassId
|
||||
val irParent = declarationStorage.findIrParent(classId.packageFqName, parentId, firClassSymbol)
|
||||
@@ -365,15 +364,14 @@ class Fir2IrClassifierStorage(
|
||||
declarationStorage.addDeclarationsToExternalClass(firClass as FirRegularClass, irClass)
|
||||
}
|
||||
|
||||
return symbolTable.referenceClass(irClass.descriptor)
|
||||
return irClass.symbol
|
||||
}
|
||||
|
||||
fun getIrTypeParameterSymbol(
|
||||
firTypeParameterSymbol: FirTypeParameterSymbol,
|
||||
typeContext: ConversionTypeContext
|
||||
): IrTypeParameterSymbol {
|
||||
val irTypeParameter = getCachedIrTypeParameter(firTypeParameterSymbol.fir, typeContext = typeContext)
|
||||
return getCachedIrTypeParameter(firTypeParameterSymbol.fir, typeContext = typeContext)?.symbol
|
||||
?: throw AssertionError("Cannot find cached type parameter by FIR symbol: ${firTypeParameterSymbol.name}")
|
||||
return symbolTable.referenceTypeParameter(irTypeParameter.descriptor)
|
||||
}
|
||||
}
|
||||
+19
-26
@@ -857,26 +857,25 @@ class Fir2IrDeclarationStorage(
|
||||
|
||||
fun getIrConstructorSymbol(firConstructorSymbol: FirConstructorSymbol): IrConstructorSymbol {
|
||||
val firConstructor = firConstructorSymbol.fir
|
||||
getCachedIrConstructor(firConstructor)?.let { return symbolTable.referenceConstructor(it.descriptor) }
|
||||
getCachedIrConstructor(firConstructor)?.let { return it.symbol }
|
||||
|
||||
val irParent = findIrParent(firConstructor) as IrClass
|
||||
val parentOrigin = (irParent as? IrDeclaration)?.origin ?: IrDeclarationOrigin.DEFINED
|
||||
val irDeclaration = createIrConstructor(firConstructor, irParent, origin = parentOrigin).apply {
|
||||
setAndModifyParent(irParent)
|
||||
}
|
||||
return symbolTable.referenceConstructor(irDeclaration.descriptor)
|
||||
return irDeclaration.symbol
|
||||
}
|
||||
|
||||
fun getIrFunctionSymbol(firFunctionSymbol: FirFunctionSymbol<*>): IrFunctionSymbol {
|
||||
return when (val firDeclaration = firFunctionSymbol.fir) {
|
||||
is FirSimpleFunction, is FirAnonymousFunction -> {
|
||||
getCachedIrFunction(firDeclaration)?.let { return symbolTable.referenceSimpleFunction(it.descriptor) }
|
||||
getCachedIrFunction(firDeclaration)?.let { return it.symbol }
|
||||
val irParent = findIrParent(firDeclaration)
|
||||
val parentOrigin = (irParent as? IrDeclaration)?.origin ?: IrDeclarationOrigin.DEFINED
|
||||
val irDeclaration = createIrFunction(firDeclaration, irParent, origin = parentOrigin).apply {
|
||||
createIrFunction(firDeclaration, irParent, origin = parentOrigin).apply {
|
||||
setAndModifyParent(irParent)
|
||||
}
|
||||
symbolTable.referenceSimpleFunction(irDeclaration.descriptor)
|
||||
}.symbol
|
||||
}
|
||||
is FirConstructor -> {
|
||||
getIrConstructorSymbol(firDeclaration.symbol)
|
||||
@@ -888,20 +887,18 @@ class Fir2IrDeclarationStorage(
|
||||
fun getIrPropertyOrFieldSymbol(firVariableSymbol: FirVariableSymbol<*>): IrSymbol {
|
||||
return when (val fir = firVariableSymbol.fir) {
|
||||
is FirProperty -> {
|
||||
propertyCache[fir]?.let { return symbolTable.referenceProperty(it.descriptor) }
|
||||
propertyCache[fir]?.let { return it.symbol }
|
||||
val irParent = findIrParent(fir)
|
||||
val parentOrigin = (irParent as? IrDeclaration)?.origin ?: IrDeclarationOrigin.DEFINED
|
||||
val irProperty = createIrProperty(fir, irParent, origin = parentOrigin).apply {
|
||||
createIrProperty(fir, irParent, origin = parentOrigin).apply {
|
||||
setAndModifyParent(irParent)
|
||||
}
|
||||
symbolTable.referenceProperty(irProperty.descriptor)
|
||||
}.symbol
|
||||
}
|
||||
is FirField -> {
|
||||
fieldCache[fir]?.let { return symbolTable.referenceField(it.descriptor) }
|
||||
val irField = createIrField(fir).apply {
|
||||
fieldCache[fir]?.let { return it.symbol }
|
||||
createIrField(fir).apply {
|
||||
setAndModifyParent(findIrParent(fir))
|
||||
}
|
||||
symbolTable.referenceField(irField.descriptor)
|
||||
}.symbol
|
||||
}
|
||||
else -> throw IllegalArgumentException("Unexpected fir in property symbol: ${fir.render()}")
|
||||
}
|
||||
@@ -910,13 +907,12 @@ class Fir2IrDeclarationStorage(
|
||||
fun getIrBackingFieldSymbol(firVariableSymbol: FirVariableSymbol<*>): IrSymbol {
|
||||
return when (val fir = firVariableSymbol.fir) {
|
||||
is FirProperty -> {
|
||||
propertyCache[fir]?.let { return symbolTable.referenceField(it.backingField!!.descriptor) }
|
||||
propertyCache[fir]?.let { return it.backingField!!.symbol }
|
||||
val irParent = findIrParent(fir)
|
||||
val parentOrigin = (irParent as? IrDeclaration)?.origin ?: IrDeclarationOrigin.DEFINED
|
||||
val irProperty = createIrProperty(fir, irParent, origin = parentOrigin).apply {
|
||||
createIrProperty(fir, irParent, origin = parentOrigin).apply {
|
||||
setAndModifyParent(irParent)
|
||||
}
|
||||
symbolTable.referenceField(irProperty.backingField!!.descriptor)
|
||||
}.backingField!!.symbol
|
||||
}
|
||||
else -> {
|
||||
getIrVariableSymbol(fir)
|
||||
@@ -925,31 +921,28 @@ class Fir2IrDeclarationStorage(
|
||||
}
|
||||
|
||||
private fun getIrVariableSymbol(firVariable: FirVariable<*>): IrVariableSymbol {
|
||||
val irDeclaration = localStorage.getVariable(firVariable)
|
||||
return localStorage.getVariable(firVariable)?.symbol
|
||||
?: throw IllegalArgumentException("Cannot find variable ${firVariable.render()} in local storage")
|
||||
return symbolTable.referenceVariable(irDeclaration.descriptor)
|
||||
}
|
||||
|
||||
fun getIrValueSymbol(firVariableSymbol: FirVariableSymbol<*>): IrSymbol {
|
||||
return when (val firDeclaration = firVariableSymbol.fir) {
|
||||
is FirEnumEntry -> {
|
||||
classifierStorage.getCachedIrEnumEntry(firDeclaration)?.let { return symbolTable.referenceEnumEntry(it.descriptor) }
|
||||
classifierStorage.getCachedIrEnumEntry(firDeclaration)?.let { return it.symbol }
|
||||
val containingFile = firProvider.getFirCallableContainerFile(firVariableSymbol)
|
||||
val parentClassSymbol = firVariableSymbol.callableId.classId?.let { firSymbolProvider.getClassLikeSymbolByFqName(it) }
|
||||
val irParentClass = (parentClassSymbol?.fir as? FirClass<*>)?.let { classifierStorage.getCachedIrClass(it) }
|
||||
val irEnumEntry = classifierStorage.createIrEnumEntry(
|
||||
classifierStorage.createIrEnumEntry(
|
||||
firDeclaration,
|
||||
irParent = irParentClass,
|
||||
origin = if (containingFile != null) IrDeclarationOrigin.DEFINED else
|
||||
(parentClassSymbol?.fir as? FirClass<*>)?.irOrigin(firProvider) ?: IrDeclarationOrigin.IR_EXTERNAL_DECLARATION_STUB
|
||||
)
|
||||
symbolTable.referenceEnumEntry(irEnumEntry.descriptor)
|
||||
).symbol
|
||||
}
|
||||
is FirValueParameter -> {
|
||||
val irDeclaration = localStorage.getParameter(firDeclaration)
|
||||
localStorage.getParameter(firDeclaration)?.symbol
|
||||
// catch parameter is FirValueParameter in FIR but IrVariable in IR
|
||||
?: return getIrVariableSymbol(firDeclaration)
|
||||
symbolTable.referenceValueParameter(irDeclaration.descriptor)
|
||||
}
|
||||
else -> {
|
||||
getIrVariableSymbol(firDeclaration)
|
||||
|
||||
@@ -233,12 +233,12 @@ class Fir2IrVisitor(
|
||||
val irTarget = conversionScope.returnTarget(returnExpression)
|
||||
return returnExpression.convertWithOffsets { startOffset, endOffset ->
|
||||
val result = returnExpression.result
|
||||
val descriptor = irTarget.descriptor
|
||||
IrReturnImpl(
|
||||
startOffset, endOffset, irBuiltIns.nothingType,
|
||||
when (descriptor) {
|
||||
is ClassConstructorDescriptor -> symbolTable.referenceConstructor(descriptor)
|
||||
else -> symbolTable.referenceSimpleFunction(descriptor)
|
||||
when (irTarget) {
|
||||
is IrConstructor -> irTarget.symbol
|
||||
is IrSimpleFunction -> irTarget.symbol
|
||||
else -> throw AssertionError("Should not be here: $irTarget")
|
||||
},
|
||||
convertToIrExpression(result)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user