[FIR2IR] Introduce an ability to lookup for accessors and backing field without accessing owner of property symbol
^KT-60924
This commit is contained in:
committed by
Space Team
parent
7b00323b89
commit
ff1c38872e
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.fir.declarations.*
|
|||||||
import org.jetbrains.kotlin.fir.signaturer.FirBasedSignatureComposer
|
import org.jetbrains.kotlin.fir.signaturer.FirBasedSignatureComposer
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl
|
import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl
|
||||||
|
import org.jetbrains.kotlin.ir.symbols.*
|
||||||
import org.jetbrains.kotlin.ir.util.IdSignatureComposer
|
import org.jetbrains.kotlin.ir.util.IdSignatureComposer
|
||||||
import org.jetbrains.kotlin.ir.util.SymbolTable
|
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
@@ -34,6 +35,11 @@ class Fir2IrCommonMemberStorage(
|
|||||||
val constructorCache: ConcurrentHashMap<FirConstructor, IrConstructor> = ConcurrentHashMap()
|
val constructorCache: ConcurrentHashMap<FirConstructor, IrConstructor> = ConcurrentHashMap()
|
||||||
|
|
||||||
val propertyCache: ConcurrentHashMap<FirProperty, IrProperty> = ConcurrentHashMap()
|
val propertyCache: ConcurrentHashMap<FirProperty, IrProperty> = ConcurrentHashMap()
|
||||||
|
val getterForPropertyCache: ConcurrentHashMap<IrSymbol, IrSimpleFunctionSymbol> = ConcurrentHashMap()
|
||||||
|
val setterForPropertyCache: ConcurrentHashMap<IrSymbol, IrSimpleFunctionSymbol> = ConcurrentHashMap()
|
||||||
|
val backingFieldForPropertyCache: ConcurrentHashMap<IrPropertySymbol, IrFieldSymbol> = ConcurrentHashMap()
|
||||||
|
val propertyForBackingFieldCache: ConcurrentHashMap<IrFieldSymbol, IrPropertySymbol> = ConcurrentHashMap()
|
||||||
|
val delegateVariableForPropertyCache: ConcurrentHashMap<IrLocalDelegatedPropertySymbol, IrVariableSymbol> = ConcurrentHashMap()
|
||||||
|
|
||||||
val fakeOverridesInClass: MutableMap<IrClass, MutableMap<Fir2IrDeclarationStorage.FakeOverrideKey, FirCallableDeclaration>> = mutableMapOf()
|
val fakeOverridesInClass: MutableMap<IrClass, MutableMap<Fir2IrDeclarationStorage.FakeOverrideKey, FirCallableDeclaration>> = mutableMapOf()
|
||||||
|
|
||||||
|
|||||||
+67
-8
@@ -19,7 +19,6 @@ import org.jetbrains.kotlin.fir.declarations.utils.*
|
|||||||
import org.jetbrains.kotlin.fir.descriptors.FirBuiltInsPackageFragment
|
import org.jetbrains.kotlin.fir.descriptors.FirBuiltInsPackageFragment
|
||||||
import org.jetbrains.kotlin.fir.descriptors.FirModuleDescriptor
|
import org.jetbrains.kotlin.fir.descriptors.FirModuleDescriptor
|
||||||
import org.jetbrains.kotlin.fir.descriptors.FirPackageFragmentDescriptor
|
import org.jetbrains.kotlin.fir.descriptors.FirPackageFragmentDescriptor
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirComponentCall
|
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirConstExpression
|
import org.jetbrains.kotlin.fir.expressions.FirConstExpression
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression
|
import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression
|
||||||
@@ -95,6 +94,16 @@ class Fir2IrDeclarationStorage(
|
|||||||
private val initializerCache: ConcurrentHashMap<FirAnonymousInitializer, IrAnonymousInitializer> = ConcurrentHashMap()
|
private val initializerCache: ConcurrentHashMap<FirAnonymousInitializer, IrAnonymousInitializer> = ConcurrentHashMap()
|
||||||
|
|
||||||
private val propertyCache: ConcurrentHashMap<FirProperty, IrProperty> = commonMemberStorage.propertyCache
|
private val propertyCache: ConcurrentHashMap<FirProperty, IrProperty> = commonMemberStorage.propertyCache
|
||||||
|
private val getterForPropertyCache: ConcurrentHashMap<IrSymbol, IrSimpleFunctionSymbol> =
|
||||||
|
commonMemberStorage.getterForPropertyCache
|
||||||
|
private val setterForPropertyCache: ConcurrentHashMap<IrSymbol, IrSimpleFunctionSymbol> =
|
||||||
|
commonMemberStorage.setterForPropertyCache
|
||||||
|
private val backingFieldForPropertyCache: ConcurrentHashMap<IrPropertySymbol, IrFieldSymbol> =
|
||||||
|
commonMemberStorage.backingFieldForPropertyCache
|
||||||
|
private val propertyForBackingFieldCache: ConcurrentHashMap<IrFieldSymbol, IrPropertySymbol> =
|
||||||
|
commonMemberStorage.propertyForBackingFieldCache
|
||||||
|
private val delegateVariableForPropertyCache: ConcurrentHashMap<IrLocalDelegatedPropertySymbol, IrVariableSymbol> =
|
||||||
|
commonMemberStorage.delegateVariableForPropertyCache
|
||||||
|
|
||||||
// interface A { /* $1 */ fun foo() }
|
// interface A { /* $1 */ fun foo() }
|
||||||
// interface B : A {
|
// interface B : A {
|
||||||
@@ -1023,6 +1032,34 @@ class Fir2IrDeclarationStorage(
|
|||||||
|
|
||||||
private var FirProperty.isStubPropertyForPureField: Boolean? by FirDeclarationDataRegistry.data(IsStubPropertyForPureFieldKey)
|
private var FirProperty.isStubPropertyForPureField: Boolean? by FirDeclarationDataRegistry.data(IsStubPropertyForPureFieldKey)
|
||||||
|
|
||||||
|
fun findGetterOfProperty(propertySymbol: IrPropertySymbol): IrSimpleFunctionSymbol? {
|
||||||
|
return getterForPropertyCache[propertySymbol]
|
||||||
|
}
|
||||||
|
|
||||||
|
fun findSetterOfProperty(propertySymbol: IrPropertySymbol): IrSimpleFunctionSymbol? {
|
||||||
|
return setterForPropertyCache[propertySymbol]
|
||||||
|
}
|
||||||
|
|
||||||
|
fun findBackingFieldOfProperty(propertySymbol: IrPropertySymbol): IrFieldSymbol? {
|
||||||
|
return backingFieldForPropertyCache[propertySymbol]
|
||||||
|
}
|
||||||
|
|
||||||
|
fun findPropertyForBackingField(fieldSymbol: IrFieldSymbol): IrPropertySymbol? {
|
||||||
|
return propertyForBackingFieldCache[fieldSymbol]
|
||||||
|
}
|
||||||
|
|
||||||
|
fun findGetterOfProperty(propertySymbol: IrLocalDelegatedPropertySymbol): IrSimpleFunctionSymbol {
|
||||||
|
return getterForPropertyCache.getValue(propertySymbol)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun findSetterOfProperty(propertySymbol: IrLocalDelegatedPropertySymbol): IrSimpleFunctionSymbol? {
|
||||||
|
return setterForPropertyCache[propertySymbol]
|
||||||
|
}
|
||||||
|
|
||||||
|
fun findDelegateVariableOfProperty(propertySymbol: IrLocalDelegatedPropertySymbol): IrVariableSymbol {
|
||||||
|
return delegateVariableForPropertyCache.getValue(propertySymbol)
|
||||||
|
}
|
||||||
|
|
||||||
fun createIrProperty(
|
fun createIrProperty(
|
||||||
property: FirProperty,
|
property: FirProperty,
|
||||||
irParent: IrDeclarationParent?,
|
irParent: IrDeclarationParent?,
|
||||||
@@ -1078,7 +1115,7 @@ class Fir2IrDeclarationStorage(
|
|||||||
val getter = property.getter
|
val getter = property.getter
|
||||||
val setter = property.setter
|
val setter = property.setter
|
||||||
if (delegate != null || property.hasBackingField) {
|
if (delegate != null || property.hasBackingField) {
|
||||||
backingField = if (delegate != null) {
|
val backingField = if (delegate != null) {
|
||||||
((delegate as? FirQualifiedAccessExpression)?.calleeReference?.toResolvedBaseSymbol()?.fir as? FirTypeParameterRefsOwner)?.let {
|
((delegate as? FirQualifiedAccessExpression)?.calleeReference?.toResolvedBaseSymbol()?.fir as? FirTypeParameterRefsOwner)?.let {
|
||||||
classifierStorage.preCacheTypeParameters(it, symbol)
|
classifierStorage.preCacheTypeParameters(it, symbol)
|
||||||
}
|
}
|
||||||
@@ -1106,6 +1143,11 @@ class Fir2IrDeclarationStorage(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
backingField.symbol.let {
|
||||||
|
backingFieldForPropertyCache[symbol] = it
|
||||||
|
propertyForBackingFieldCache[it] = symbol
|
||||||
|
}
|
||||||
|
this.backingField = backingField
|
||||||
}
|
}
|
||||||
if (irParent != null) {
|
if (irParent != null) {
|
||||||
backingField?.parent = irParent
|
backingField?.parent = irParent
|
||||||
@@ -1124,7 +1166,9 @@ class Fir2IrDeclarationStorage(
|
|||||||
startOffset, endOffset,
|
startOffset, endOffset,
|
||||||
dontUseSignature = signature == null, fakeOverrideOwnerLookupTag,
|
dontUseSignature = signature == null, fakeOverrideOwnerLookupTag,
|
||||||
property.unwrapFakeOverrides().getter,
|
property.unwrapFakeOverrides().getter,
|
||||||
)
|
).also {
|
||||||
|
getterForPropertyCache[symbol] = it.symbol
|
||||||
|
}
|
||||||
if (property.isVar) {
|
if (property.isVar) {
|
||||||
this.setter = createIrPropertyAccessor(
|
this.setter = createIrPropertyAccessor(
|
||||||
setter, property, this, type, irParent, thisReceiverOwner, true,
|
setter, property, this, type, irParent, thisReceiverOwner, true,
|
||||||
@@ -1138,7 +1182,9 @@ class Fir2IrDeclarationStorage(
|
|||||||
startOffset, endOffset,
|
startOffset, endOffset,
|
||||||
dontUseSignature = signature == null, fakeOverrideOwnerLookupTag,
|
dontUseSignature = signature == null, fakeOverrideOwnerLookupTag,
|
||||||
property.unwrapFakeOverrides().setter,
|
property.unwrapFakeOverrides().setter,
|
||||||
)
|
).also {
|
||||||
|
setterForPropertyCache[symbol] = it.symbol
|
||||||
|
}
|
||||||
}
|
}
|
||||||
leaveScope(this)
|
leaveScope(this)
|
||||||
}
|
}
|
||||||
@@ -1509,13 +1555,14 @@ class Fir2IrDeclarationStorage(
|
|||||||
): IrLocalDelegatedProperty = convertCatching(property) {
|
): IrLocalDelegatedProperty = convertCatching(property) {
|
||||||
val type = property.returnTypeRef.toIrType()
|
val type = property.returnTypeRef.toIrType()
|
||||||
val origin = IrDeclarationOrigin.DEFINED
|
val origin = IrDeclarationOrigin.DEFINED
|
||||||
|
val symbol = IrLocalDelegatedPropertySymbolImpl()
|
||||||
val irProperty = property.convertWithOffsets { startOffset, endOffset ->
|
val irProperty = property.convertWithOffsets { startOffset, endOffset ->
|
||||||
irFactory.createLocalDelegatedProperty(
|
irFactory.createLocalDelegatedProperty(
|
||||||
startOffset = startOffset,
|
startOffset = startOffset,
|
||||||
endOffset = endOffset,
|
endOffset = endOffset,
|
||||||
origin = origin,
|
origin = origin,
|
||||||
name = property.name,
|
name = property.name,
|
||||||
symbol = IrLocalDelegatedPropertySymbolImpl(),
|
symbol = symbol,
|
||||||
type = type,
|
type = type,
|
||||||
isVar = property.isVar
|
isVar = property.isVar
|
||||||
)
|
)
|
||||||
@@ -1527,17 +1574,23 @@ class Fir2IrDeclarationStorage(
|
|||||||
startOffset, endOffset, IrDeclarationOrigin.PROPERTY_DELEGATE,
|
startOffset, endOffset, IrDeclarationOrigin.PROPERTY_DELEGATE,
|
||||||
NameUtils.propertyDelegateName(property.name), property.delegate!!.resolvedType.toIrType(),
|
NameUtils.propertyDelegateName(property.name), property.delegate!!.resolvedType.toIrType(),
|
||||||
isVar = false, isConst = false, isLateinit = false
|
isVar = false, isConst = false, isLateinit = false
|
||||||
)
|
).also {
|
||||||
|
delegateVariableForPropertyCache[symbol] = it.symbol
|
||||||
|
}
|
||||||
delegate.parent = irParent
|
delegate.parent = irParent
|
||||||
getter = createIrPropertyAccessor(
|
getter = createIrPropertyAccessor(
|
||||||
property.getter, property, this, type, irParent, null, false,
|
property.getter, property, this, type, irParent, null, false,
|
||||||
IrDeclarationOrigin.DELEGATED_PROPERTY_ACCESSOR, startOffset, endOffset, dontUseSignature = true
|
IrDeclarationOrigin.DELEGATED_PROPERTY_ACCESSOR, startOffset, endOffset, dontUseSignature = true
|
||||||
)
|
).also {
|
||||||
|
getterForPropertyCache[symbol] = it.symbol
|
||||||
|
}
|
||||||
if (property.isVar) {
|
if (property.isVar) {
|
||||||
setter = createIrPropertyAccessor(
|
setter = createIrPropertyAccessor(
|
||||||
property.setter, property, this, type, irParent, null, true,
|
property.setter, property, this, type, irParent, null, true,
|
||||||
IrDeclarationOrigin.DELEGATED_PROPERTY_ACCESSOR, startOffset, endOffset, dontUseSignature = true
|
IrDeclarationOrigin.DELEGATED_PROPERTY_ACCESSOR, startOffset, endOffset, dontUseSignature = true
|
||||||
)
|
).also {
|
||||||
|
setterForPropertyCache[symbol] = it.symbol
|
||||||
|
}
|
||||||
}
|
}
|
||||||
annotationGenerator.generate(this, property)
|
annotationGenerator.generate(this, property)
|
||||||
leaveScope(this)
|
leaveScope(this)
|
||||||
@@ -1745,6 +1798,12 @@ class Fir2IrDeclarationStorage(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
propertyCache[fir] = irProperty
|
propertyCache[fir] = irProperty
|
||||||
|
irProperty.getter?.symbol?.let { getterForPropertyCache[symbol] = it }
|
||||||
|
irProperty.setter?.symbol?.let { setterForPropertyCache[symbol] = it }
|
||||||
|
irProperty.backingField?.symbol?.let {
|
||||||
|
backingFieldForPropertyCache[symbol] = it
|
||||||
|
propertyForBackingFieldCache[it] = symbol
|
||||||
|
}
|
||||||
return irProperty
|
return irProperty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user