[FIR2IR] Simplify Fir2IrDeclarationStorage.getIrConstructorSymbol
For reasoning refer to the message of the previous commit It is the same as for `getIrFunctionSymbol`
This commit is contained in:
committed by
Space Team
parent
c7c83de528
commit
1e090d45d1
@@ -188,14 +188,14 @@ fun FirClassifierSymbol<*>.toSymbol(
|
||||
}
|
||||
|
||||
context(Fir2IrComponents)
|
||||
fun FirBasedSymbol<*>.toSymbolForCall(
|
||||
private fun FirBasedSymbol<*>.toSymbolForCall(
|
||||
dispatchReceiver: FirExpression?,
|
||||
preferGetter: Boolean,
|
||||
explicitReceiver: FirExpression? = null,
|
||||
isDelegate: Boolean = false,
|
||||
isReference: Boolean = false
|
||||
): IrSymbol? = when (this) {
|
||||
is FirCallableSymbol<*> -> unwrapCallRepresentative().toSymbolForCall(
|
||||
is FirCallableSymbol<*> -> toSymbolForCall(
|
||||
dispatchReceiver,
|
||||
preferGetter,
|
||||
explicitReceiver,
|
||||
@@ -207,16 +207,19 @@ fun FirBasedSymbol<*>.toSymbolForCall(
|
||||
else -> error("Unknown symbol: $this")
|
||||
}
|
||||
|
||||
context(Fir2IrComponents)
|
||||
fun FirReference.extractSymbolForCall(): FirBasedSymbol<*>? {
|
||||
if (this !is FirResolvedNamedReference) {
|
||||
return null
|
||||
}
|
||||
var symbol = resolvedSymbol
|
||||
|
||||
if (symbol is FirCallableSymbol<*> && symbol.origin == FirDeclarationOrigin.SubstitutionOverride.CallSite) {
|
||||
symbol = symbol.fir.unwrapUseSiteSubstitutionOverrides<FirCallableDeclaration>().symbol
|
||||
if (symbol is FirCallableSymbol<*>) {
|
||||
if (symbol.origin == FirDeclarationOrigin.SubstitutionOverride.CallSite) {
|
||||
symbol = symbol.fir.unwrapUseSiteSubstitutionOverrides<FirCallableDeclaration>().symbol
|
||||
}
|
||||
symbol = (symbol as FirCallableSymbol<*>).unwrapCallRepresentative()
|
||||
}
|
||||
|
||||
return symbol
|
||||
}
|
||||
|
||||
@@ -302,7 +305,7 @@ fun FirCallableSymbol<*>.toSymbolForCall(
|
||||
} ?: declarationStorage.getIrPropertySymbol(this)
|
||||
}
|
||||
}
|
||||
|
||||
is FirConstructorSymbol -> declarationStorage.getIrConstructorSymbol(fir.originalConstructorIfTypeAlias?.symbol ?: this)
|
||||
is FirFunctionSymbol<*> -> declarationStorage.getIrFunctionSymbol(this, fakeOverrideOwnerLookupTag)
|
||||
is FirPropertySymbol -> declarationStorage.getIrPropertySymbol(this, fakeOverrideOwnerLookupTag)
|
||||
is FirFieldSymbol -> declarationStorage.getOrCreateIrField(this, fakeOverrideOwnerLookupTag).symbol
|
||||
|
||||
+15
-17
@@ -22,7 +22,6 @@ import org.jetbrains.kotlin.fir.descriptors.FirModuleDescriptor
|
||||
import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression
|
||||
import org.jetbrains.kotlin.fir.java.symbols.FirJavaOverriddenSyntheticPropertySymbol
|
||||
import org.jetbrains.kotlin.fir.lazy.Fir2IrLazyClass
|
||||
import org.jetbrains.kotlin.fir.lazy.Fir2IrLazyConstructor
|
||||
import org.jetbrains.kotlin.fir.references.toResolvedValueParameterSymbol
|
||||
import org.jetbrains.kotlin.fir.resolve.providers.firProvider
|
||||
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
||||
@@ -375,9 +374,19 @@ class Fir2IrDeclarationStorage(
|
||||
irParent: IrClass,
|
||||
predefinedOrigin: IrDeclarationOrigin? = null,
|
||||
isLocal: Boolean = false,
|
||||
): IrConstructor {
|
||||
return getOrCreateIrConstructor(constructor, { irParent }, predefinedOrigin, isLocal)
|
||||
}
|
||||
|
||||
fun getOrCreateIrConstructor(
|
||||
constructor: FirConstructor,
|
||||
irParent: () -> IrClass,
|
||||
predefinedOrigin: IrDeclarationOrigin? = null,
|
||||
isLocal: Boolean = false,
|
||||
): IrConstructor {
|
||||
getCachedIrConstructor(constructor)?.let { return it }
|
||||
return callablesGenerator.createIrConstructor(constructor, irParent, predefinedOrigin, isLocal)
|
||||
// caching of created constructor is not called here, because `callablesGenerator` calls `cacheIrConstructor` by itself
|
||||
return callablesGenerator.createIrConstructor(constructor, irParent(), predefinedOrigin, isLocal)
|
||||
}
|
||||
|
||||
@LeakedDeclarationCaches
|
||||
@@ -387,21 +396,10 @@ class Fir2IrDeclarationStorage(
|
||||
|
||||
fun getIrConstructorSymbol(firConstructorSymbol: FirConstructorSymbol): IrConstructorSymbol {
|
||||
val fir = firConstructorSymbol.fir
|
||||
return getIrCallableSymbol(
|
||||
firConstructorSymbol,
|
||||
fakeOverrideOwnerLookupTag = null,
|
||||
getCachedIrDeclaration = { constructor: FirConstructor, _, calculator -> getCachedIrConstructor(constructor, calculator) },
|
||||
createIrDeclaration = { parent, origin ->
|
||||
callablesGenerator.createIrConstructor(fir, parent as IrClass, predefinedOrigin = origin)
|
||||
},
|
||||
createIrLazyDeclaration = { signature, lazyParent, declarationOrigin ->
|
||||
val irConstructor = lazyDeclarationsGenerator.createIrLazyConstructor(fir, signature, declarationOrigin, lazyParent)
|
||||
constructorCache[fir] = irConstructor
|
||||
// NB: this is needed to prevent recursions in case of self bounds
|
||||
(irConstructor as Fir2IrLazyConstructor).prepareTypeParameters()
|
||||
irConstructor
|
||||
},
|
||||
) as IrConstructorSymbol
|
||||
return getOrCreateIrConstructor(
|
||||
fir,
|
||||
{ findIrParent(fir, fakeOverrideOwnerLookupTag = null) as IrClass }
|
||||
).symbol
|
||||
}
|
||||
|
||||
|
||||
|
||||
+7
-6
@@ -197,12 +197,13 @@ class Fir2IrCallableDeclarationsGenerator(val components: Fir2IrComponents) : Fi
|
||||
predefinedOrigin: IrDeclarationOrigin? = null,
|
||||
isLocal: Boolean = false,
|
||||
): IrConstructor = convertCatching(constructor) {
|
||||
val origin = constructor.computeIrOrigin(predefinedOrigin)
|
||||
val origin = constructor.computeIrOrigin(predefinedOrigin, irParent.origin)
|
||||
val isPrimary = constructor.isPrimary
|
||||
val signature =
|
||||
runUnless(isLocal || !configuration.linkViaSignatures) {
|
||||
signatureComposer.composeSignature(constructor)
|
||||
}
|
||||
// we need to compose signature even if `linkViaSignatures` set to false, because otherwise we will never
|
||||
// create lazy constructor (it requires not nullable signature)
|
||||
val signature = runUnless(isLocal) {
|
||||
signatureComposer.composeSignature(constructor)
|
||||
}
|
||||
|
||||
if (irParent is Fir2IrLazyClass && signature != null) {
|
||||
val lazyConstructor = lazyDeclarationsGenerator.createIrLazyConstructor(constructor, signature, origin, irParent) as Fir2IrLazyConstructor
|
||||
@@ -215,7 +216,7 @@ class Fir2IrCallableDeclarationsGenerator(val components: Fir2IrComponents) : Fi
|
||||
}
|
||||
val visibility = if (irParent.isAnonymousObject) Visibilities.Public else constructor.visibility
|
||||
return constructor.convertWithOffsets { startOffset, endOffset ->
|
||||
declareIrConstructor(signature) { symbol ->
|
||||
declareIrConstructor(signature.takeIf { components.configuration.linkViaSignatures }) { symbol ->
|
||||
classifierStorage.preCacheTypeParameters(constructor, symbol)
|
||||
irFactory.createConstructor(
|
||||
startOffset = startOffset,
|
||||
|
||||
Reference in New Issue
Block a user