[FIR2IR] Generate fake-override symbols for properties
^KT-63644 Fixed
This commit is contained in:
committed by
Space Team
parent
1d2601ccae
commit
9609ac6908
+57
-9
@@ -333,19 +333,26 @@ class Fir2IrDeclarationStorage(
|
|||||||
) {
|
) {
|
||||||
return createFunctionSymbol(signature)
|
return createFunctionSymbol(signature)
|
||||||
}
|
}
|
||||||
val containingClassLookupTag = when {
|
val containingClassSymbol = findContainingIrClassSymbol(function, fakeOverrideOwnerLookupTag)
|
||||||
fakeOverrideOwnerLookupTag != null -> fakeOverrideOwnerLookupTag
|
|
||||||
function.isSubstitutionOrIntersectionOverride -> function.containingClassLookupTag()
|
|
||||||
else -> shouldNotBeCalled()
|
|
||||||
}
|
|
||||||
requireNotNull(containingClassLookupTag) { "Containing class not found for ${function.render()}"}
|
|
||||||
val containingClassSymbol = classifierStorage.findIrClass(containingClassLookupTag)?.symbol
|
|
||||||
?: error("IR class for $containingClassLookupTag not found")
|
|
||||||
val originalFirFunction = function.unwrapFakeOverrides()
|
val originalFirFunction = function.unwrapFakeOverrides()
|
||||||
val originalSymbol = getIrFunctionSymbol(originalFirFunction.symbol) as IrSimpleFunctionSymbol
|
val originalSymbol = getIrFunctionSymbol(originalFirFunction.symbol) as IrSimpleFunctionSymbol
|
||||||
return IrFunctionFakeOverrideSymbol(originalSymbol, containingClassSymbol, signature)
|
return IrFunctionFakeOverrideSymbol(originalSymbol, containingClassSymbol, signature)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun findContainingIrClassSymbol(
|
||||||
|
callable: FirCallableDeclaration,
|
||||||
|
fakeOverrideOwnerLookupTag: ConeClassLikeLookupTag?,
|
||||||
|
): IrClassSymbol {
|
||||||
|
val containingClassLookupTag = when {
|
||||||
|
fakeOverrideOwnerLookupTag != null -> fakeOverrideOwnerLookupTag
|
||||||
|
callable.isSubstitutionOrIntersectionOverride -> callable.containingClassLookupTag()
|
||||||
|
else -> shouldNotBeCalled()
|
||||||
|
}
|
||||||
|
requireNotNull(containingClassLookupTag) { "Containing class not found for ${callable.render()}"}
|
||||||
|
return classifierStorage.findIrClass(containingClassLookupTag)?.symbol
|
||||||
|
?: error("IR class for $containingClassLookupTag not found")
|
||||||
|
}
|
||||||
|
|
||||||
private fun cacheIrFunctionSymbol(
|
private fun cacheIrFunctionSymbol(
|
||||||
function: FirFunction,
|
function: FirFunction,
|
||||||
irFunctionSymbol: IrSimpleFunctionSymbol,
|
irFunctionSymbol: IrSimpleFunctionSymbol,
|
||||||
@@ -526,7 +533,16 @@ class Fir2IrDeclarationStorage(
|
|||||||
signature: IdSignature?,
|
signature: IdSignature?,
|
||||||
property: FirProperty,
|
property: FirProperty,
|
||||||
fakeOverrideOwnerLookupTag: ConeClassLikeLookupTag?,
|
fakeOverrideOwnerLookupTag: ConeClassLikeLookupTag?,
|
||||||
|
parentIsExternal: Boolean
|
||||||
): PropertySymbols {
|
): PropertySymbols {
|
||||||
|
if (
|
||||||
|
configuration.useIrFakeOverrideBuilder &&
|
||||||
|
!parentIsExternal &&
|
||||||
|
property.isFakeOverride(fakeOverrideOwnerLookupTag)
|
||||||
|
) {
|
||||||
|
return createFakeOverridePropertySymbols(signature, property, fakeOverrideOwnerLookupTag)
|
||||||
|
}
|
||||||
|
|
||||||
val propertySymbol = when {
|
val propertySymbol = when {
|
||||||
signature != null -> when (property.isStubPropertyForPureField) {
|
signature != null -> when (property.isStubPropertyForPureField) {
|
||||||
// Very special case when two similar properties can exist so conflicts in SymbolTable are possible.
|
// Very special case when two similar properties can exist so conflicts in SymbolTable are possible.
|
||||||
@@ -557,6 +573,34 @@ class Fir2IrDeclarationStorage(
|
|||||||
return PropertySymbols(propertySymbol, getterSymbol, setterSymbol, backingFieldSymbol)
|
return PropertySymbols(propertySymbol, getterSymbol, setterSymbol, backingFieldSymbol)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun createFakeOverridePropertySymbols(
|
||||||
|
signature: IdSignature?,
|
||||||
|
property: FirProperty,
|
||||||
|
fakeOverrideOwnerLookupTag: ConeClassLikeLookupTag?,
|
||||||
|
): PropertySymbols {
|
||||||
|
val originalFirProperty = property.unwrapFakeOverrides()
|
||||||
|
val originalSymbols = getIrPropertySymbols(originalFirProperty.symbol, isLocal = false)
|
||||||
|
require(property.isStubPropertyForPureField != true) {
|
||||||
|
"What are we doing here?"
|
||||||
|
}
|
||||||
|
|
||||||
|
val containingClassSymbol = findContainingIrClassSymbol(property, fakeOverrideOwnerLookupTag)
|
||||||
|
val propertySymbol = IrPropertyFakeOverrideSymbol(originalSymbols.propertySymbol, containingClassSymbol, signature)
|
||||||
|
|
||||||
|
val getterSignature = runIf(signature != null) {
|
||||||
|
signatureComposer.composeAccessorSignature(property, isSetter = false, fakeOverrideOwnerLookupTag)
|
||||||
|
}
|
||||||
|
val getterSymbol = IrFunctionFakeOverrideSymbol(originalSymbols.getterSymbol, containingClassSymbol, getterSignature)
|
||||||
|
|
||||||
|
val setterSymbol = runIf(property.isVar) {
|
||||||
|
val setterSignature = runIf(signature != null) {
|
||||||
|
signatureComposer.composeAccessorSignature(property, isSetter = true, fakeOverrideOwnerLookupTag)
|
||||||
|
}
|
||||||
|
IrFunctionFakeOverrideSymbol(originalSymbols.setterSymbol!!, containingClassSymbol, setterSignature)
|
||||||
|
}
|
||||||
|
return PropertySymbols(propertySymbol, getterSymbol, setterSymbol, backingFieldSymbol = null)
|
||||||
|
}
|
||||||
|
|
||||||
private fun cacheIrPropertySymbols(
|
private fun cacheIrPropertySymbols(
|
||||||
property: FirProperty,
|
property: FirProperty,
|
||||||
symbols: PropertySymbols,
|
symbols: PropertySymbols,
|
||||||
@@ -636,9 +680,9 @@ class Fir2IrDeclarationStorage(
|
|||||||
val signature = runIf(!isLocal && configuration.linkViaSignatures) {
|
val signature = runIf(!isLocal && configuration.linkViaSignatures) {
|
||||||
signatureComposer.composeSignature(property, fakeOverrideOwnerLookupTag)
|
signatureComposer.composeSignature(property, fakeOverrideOwnerLookupTag)
|
||||||
}
|
}
|
||||||
val symbols = createPropertySymbols(signature, property, fakeOverrideOwnerLookupTag)
|
|
||||||
val irParent = findIrParent(property, fakeOverrideOwnerLookupTag)
|
val irParent = findIrParent(property, fakeOverrideOwnerLookupTag)
|
||||||
if (irParent?.isExternalParent() == true) {
|
if (irParent?.isExternalParent() == true) {
|
||||||
|
val symbols = createPropertySymbols(signature, property, fakeOverrideOwnerLookupTag, parentIsExternal = true)
|
||||||
val firForLazyProperty = calculateFirForLazyDeclaration(
|
val firForLazyProperty = calculateFirForLazyDeclaration(
|
||||||
property, fakeOverrideOwnerLookupTag, irParent,
|
property, fakeOverrideOwnerLookupTag, irParent,
|
||||||
fakeOverrideGenerator::createFirPropertyFakeOverrideIfNeeded
|
fakeOverrideGenerator::createFirPropertyFakeOverrideIfNeeded
|
||||||
@@ -653,8 +697,12 @@ class Fir2IrDeclarationStorage(
|
|||||||
).also {
|
).also {
|
||||||
check(it is Fir2IrLazyProperty)
|
check(it is Fir2IrLazyProperty)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cacheIrPropertySymbols(property, symbols, fakeOverrideOwnerLookupTag)
|
||||||
|
return symbols
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val symbols = createPropertySymbols(signature, property, fakeOverrideOwnerLookupTag, parentIsExternal = false)
|
||||||
cacheIrPropertySymbols(property, symbols, fakeOverrideOwnerLookupTag)
|
cacheIrPropertySymbols(property, symbols, fakeOverrideOwnerLookupTag)
|
||||||
|
|
||||||
return symbols
|
return symbols
|
||||||
|
|||||||
@@ -57,3 +57,11 @@ class IrFunctionFakeOverrideSymbol(
|
|||||||
) : IrFakeOverrideSymbolBase<IrSimpleFunctionSymbol, IrSimpleFunction, FunctionDescriptor>(
|
) : IrFakeOverrideSymbolBase<IrSimpleFunctionSymbol, IrSimpleFunction, FunctionDescriptor>(
|
||||||
originalSymbol, containingClassSymbol, idSignature
|
originalSymbol, containingClassSymbol, idSignature
|
||||||
), IrSimpleFunctionSymbol
|
), IrSimpleFunctionSymbol
|
||||||
|
|
||||||
|
class IrPropertyFakeOverrideSymbol(
|
||||||
|
originalSymbol: IrPropertySymbol,
|
||||||
|
containingClassSymbol: IrClassSymbol,
|
||||||
|
idSignature: IdSignature?
|
||||||
|
) : IrFakeOverrideSymbolBase<IrPropertySymbol, IrProperty, PropertyDescriptor>(
|
||||||
|
originalSymbol, containingClassSymbol, idSignature
|
||||||
|
), IrPropertySymbol
|
||||||
|
|||||||
Reference in New Issue
Block a user