[FIR2IR] Use symbol instead of IR in Fir2IrDeclarationStorage.enter/leaveScope
^KT-60924
This commit is contained in:
committed by
Space Team
parent
ea3378566d
commit
a76c5a68f6
@@ -37,7 +37,6 @@ import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.name.SpecialNames
|
||||
import org.jetbrains.kotlin.name.StandardClassIds
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.getOrPut
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.runIf
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.runUnless
|
||||
|
||||
@@ -613,7 +612,7 @@ class Fir2IrClassifierStorage(
|
||||
name = enumEntry.name,
|
||||
symbol = symbol,
|
||||
).apply {
|
||||
declarationStorage.enterScope(this)
|
||||
declarationStorage.enterScope(this.symbol)
|
||||
if (irParent != null) {
|
||||
this.parent = irParent
|
||||
}
|
||||
@@ -626,7 +625,7 @@ class Fir2IrClassifierStorage(
|
||||
)
|
||||
this.correspondingClass = klass
|
||||
}
|
||||
declarationStorage.leaveScope(this)
|
||||
declarationStorage.leaveScope(this.symbol)
|
||||
}
|
||||
}
|
||||
enumEntryCache[enumEntry] = result
|
||||
|
||||
@@ -218,7 +218,7 @@ class Fir2IrConverter(
|
||||
// Add synthetic members *before* fake override generations.
|
||||
// Otherwise, redundant members, e.g., synthetic toString _and_ fake override toString, will be added.
|
||||
if (klass is FirRegularClass && irConstructor != null && (irClass.isValue || irClass.isData)) {
|
||||
declarationStorage.enterScope(irConstructor)
|
||||
declarationStorage.enterScope(irConstructor.symbol)
|
||||
val dataClassMembersGenerator = DataClassMembersGenerator(components)
|
||||
if (irClass.isSingleFieldValueClass) {
|
||||
allDeclarations += dataClassMembersGenerator.generateSingleFieldValueClassMembers(klass, irClass)
|
||||
@@ -229,7 +229,7 @@ class Fir2IrConverter(
|
||||
if (irClass.isData) {
|
||||
allDeclarations += dataClassMembersGenerator.generateDataClassMembers(klass, irClass)
|
||||
}
|
||||
declarationStorage.leaveScope(irConstructor)
|
||||
declarationStorage.leaveScope(irConstructor.symbol)
|
||||
}
|
||||
with(fakeOverrideGenerator) {
|
||||
irClass.addFakeOverrides(klass, allDeclarations)
|
||||
@@ -245,7 +245,7 @@ class Fir2IrConverter(
|
||||
): IrClass {
|
||||
val conversionData = codeFragment.conversionData
|
||||
|
||||
declarationStorage.enterScope(irClass)
|
||||
declarationStorage.enterScope(irClass.symbol)
|
||||
|
||||
val signature = irClass.symbol.signature!!
|
||||
|
||||
@@ -321,7 +321,7 @@ class Fir2IrConverter(
|
||||
irClass.declarations.add(irPrimaryConstructor)
|
||||
irClass.declarations.add(irFragmentFunction)
|
||||
|
||||
declarationStorage.leaveScope(irClass)
|
||||
declarationStorage.leaveScope(irClass.symbol)
|
||||
return irClass
|
||||
}
|
||||
|
||||
@@ -428,7 +428,7 @@ class Fir2IrConverter(
|
||||
is FirScript -> {
|
||||
parent as IrFile
|
||||
declarationStorage.getOrCreateIrScript(declaration).also { irScript ->
|
||||
declarationStorage.enterScope(irScript)
|
||||
declarationStorage.enterScope(irScript.symbol)
|
||||
irScript.parent = parent
|
||||
for (scriptStatement in declaration.statements) {
|
||||
when (scriptStatement) {
|
||||
@@ -445,7 +445,7 @@ class Fir2IrConverter(
|
||||
processMemberDeclaration(scriptStatement, null, irScript)
|
||||
}
|
||||
}
|
||||
declarationStorage.leaveScope(irScript)
|
||||
declarationStorage.leaveScope(irScript.symbol)
|
||||
}
|
||||
}
|
||||
is FirSimpleFunction -> {
|
||||
|
||||
+10
-18
@@ -243,14 +243,6 @@ class Fir2IrDeclarationStorage(
|
||||
return fileCache[firFile]!!
|
||||
}
|
||||
|
||||
fun enterScope(declaration: IrDeclaration) {
|
||||
enterScope(declaration.symbol)
|
||||
}
|
||||
|
||||
fun leaveScope(declaration: IrDeclaration) {
|
||||
leaveScope(declaration.symbol)
|
||||
}
|
||||
|
||||
fun enterScope(symbol: IrSymbol) {
|
||||
symbolTable.enterScope(symbol)
|
||||
if (symbol is IrSimpleFunctionSymbol ||
|
||||
@@ -716,14 +708,14 @@ class Fir2IrDeclarationStorage(
|
||||
containerSource = simpleFunction?.containerSource,
|
||||
).apply {
|
||||
metadata = FirMetadataSource.Function(function)
|
||||
enterScope(this)
|
||||
enterScope(this.symbol)
|
||||
bindAndDeclareParameters(
|
||||
function, irParent,
|
||||
thisReceiverOwner, isStatic = simpleFunction?.isStatic == true,
|
||||
forSetter = false,
|
||||
)
|
||||
convertAnnotationsForNonDeclaredMembers(function, origin)
|
||||
leaveScope(this)
|
||||
leaveScope(this.symbol)
|
||||
}
|
||||
}
|
||||
result
|
||||
@@ -825,9 +817,9 @@ class Fir2IrDeclarationStorage(
|
||||
// Add to cache before generating parameters to prevent an infinite loop when an annotation value parameter is annotated
|
||||
// with the annotation itself.
|
||||
constructorCache[constructor] = this
|
||||
enterScope(this)
|
||||
enterScope(this.symbol)
|
||||
bindAndDeclareParameters(constructor, irParent, irParent, isStatic = false, forSetter = false)
|
||||
leaveScope(this)
|
||||
leaveScope(this.symbol)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -915,7 +907,7 @@ class Fir2IrDeclarationStorage(
|
||||
}
|
||||
// NB: we should enter accessor' scope before declaring its parameters
|
||||
// (both setter default and receiver ones, if any)
|
||||
enterScope(this)
|
||||
enterScope(this.symbol)
|
||||
if (propertyAccessor == null && isSetter) {
|
||||
declareDefaultSetterParameter(
|
||||
property.returnTypeRef.toIrType(ConversionTypeOrigin.SETTER),
|
||||
@@ -928,7 +920,7 @@ class Fir2IrDeclarationStorage(
|
||||
forSetter = isSetter,
|
||||
parentPropertyReceiver = property.receiverParameter,
|
||||
)
|
||||
leaveScope(this)
|
||||
leaveScope(this.symbol)
|
||||
if (irParent != null) {
|
||||
parent = irParent
|
||||
}
|
||||
@@ -1114,7 +1106,7 @@ class Fir2IrDeclarationStorage(
|
||||
).apply {
|
||||
metadata = FirMetadataSource.Property(property)
|
||||
convertAnnotationsForNonDeclaredMembers(property, origin)
|
||||
enterScope(this)
|
||||
enterScope(this.symbol)
|
||||
if (irParent != null) {
|
||||
parent = irParent
|
||||
}
|
||||
@@ -1194,7 +1186,7 @@ class Fir2IrDeclarationStorage(
|
||||
setterForPropertyCache[symbol] = it.symbol
|
||||
}
|
||||
}
|
||||
leaveScope(this)
|
||||
leaveScope(this.symbol)
|
||||
}
|
||||
}
|
||||
if (property.isFakeOverride(fakeOverrideOwnerLookupTag)) {
|
||||
@@ -1574,7 +1566,7 @@ class Fir2IrDeclarationStorage(
|
||||
}.apply {
|
||||
parent = irParent
|
||||
metadata = FirMetadataSource.Property(property)
|
||||
enterScope(this)
|
||||
enterScope(this.symbol)
|
||||
delegate = declareIrVariable(
|
||||
startOffset, endOffset, IrDeclarationOrigin.PROPERTY_DELEGATE,
|
||||
NameUtils.propertyDelegateName(property.name), property.delegate!!.resolvedType.toIrType(),
|
||||
@@ -1598,7 +1590,7 @@ class Fir2IrDeclarationStorage(
|
||||
}
|
||||
}
|
||||
annotationGenerator.generate(this, property)
|
||||
leaveScope(this)
|
||||
leaveScope(this.symbol)
|
||||
}
|
||||
localStorage.putDelegatedProperty(property, irProperty)
|
||||
return irProperty
|
||||
|
||||
@@ -142,7 +142,7 @@ class Fir2IrVisitor(
|
||||
val irParentEnumClass = irEnumEntry.parent as? IrClass
|
||||
// If the enum entry has its own members, we need to introduce a synthetic class.
|
||||
if (correspondingClass != null) {
|
||||
declarationStorage.enterScope(irEnumEntry)
|
||||
declarationStorage.enterScope(irEnumEntry.symbol)
|
||||
classifierStorage.putEnumEntryClassInScope(enumEntry, correspondingClass)
|
||||
val anonymousObject = (enumEntry.initializer as FirAnonymousObjectExpression).anonymousObject
|
||||
converter.processAnonymousObjectHeaders(anonymousObject, correspondingClass)
|
||||
@@ -160,7 +160,7 @@ class Fir2IrVisitor(
|
||||
)
|
||||
)
|
||||
}
|
||||
declarationStorage.leaveScope(irEnumEntry)
|
||||
declarationStorage.leaveScope(irEnumEntry.symbol)
|
||||
} else if (initializer is FirAnonymousObjectExpression) {
|
||||
// Otherwise, this is a default-ish enum entry, which doesn't need its own synthetic class.
|
||||
// During raw FIR building, we put the delegated constructor call inside an anonymous object.
|
||||
@@ -217,7 +217,7 @@ class Fir2IrVisitor(
|
||||
override fun visitScript(script: FirScript, data: Any?): IrElement {
|
||||
return declarationStorage.getCachedIrScript(script)!!.also { irScript ->
|
||||
irScript.parent = conversionScope.parentFromStack()
|
||||
declarationStorage.enterScope(irScript)
|
||||
declarationStorage.enterScope(irScript.symbol)
|
||||
|
||||
irScript.explicitCallParameters = script.parameters.map { parameter ->
|
||||
declarationStorage.createIrVariable(parameter, irScript, givenOrigin = IrDeclarationOrigin.SCRIPT_CALL_PARAMETER)
|
||||
@@ -318,7 +318,7 @@ class Fir2IrVisitor(
|
||||
irScript.configure(script) { declarationStorage.getCachedIrScript(it.fir)?.symbol }
|
||||
}
|
||||
}
|
||||
declarationStorage.leaveScope(irScript)
|
||||
declarationStorage.leaveScope(irScript.symbol)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -326,12 +326,12 @@ class Fir2IrVisitor(
|
||||
val irClass = classifierStorage.getCachedIrCodeFragment(codeFragment)!!
|
||||
val irFunction = irClass.declarations.firstIsInstance<IrSimpleFunction>()
|
||||
|
||||
declarationStorage.enterScope(irFunction)
|
||||
declarationStorage.enterScope(irFunction.symbol)
|
||||
conversionScope.withParent(irFunction) {
|
||||
val irBlock = codeFragment.block.convertToIrBlock(forceUnitType = false)
|
||||
irFunction.body = irFactory.createExpressionBody(irBlock)
|
||||
}
|
||||
declarationStorage.leaveScope(irFunction)
|
||||
declarationStorage.leaveScope(irFunction.symbol)
|
||||
|
||||
return irFunction
|
||||
}
|
||||
@@ -384,9 +384,9 @@ class Fir2IrVisitor(
|
||||
data: Any?
|
||||
): IrElement = whileAnalysing(session, anonymousInitializer) {
|
||||
val irAnonymousInitializer = declarationStorage.getCachedIrAnonymousInitializer(anonymousInitializer)!!
|
||||
declarationStorage.enterScope(irAnonymousInitializer)
|
||||
declarationStorage.enterScope(irAnonymousInitializer.symbol)
|
||||
irAnonymousInitializer.body = convertToIrBlockBody(anonymousInitializer.body!!)
|
||||
declarationStorage.leaveScope(irAnonymousInitializer)
|
||||
declarationStorage.leaveScope(irAnonymousInitializer.symbol)
|
||||
return irAnonymousInitializer
|
||||
}
|
||||
|
||||
|
||||
+12
-12
@@ -54,7 +54,7 @@ internal class ClassMemberGenerator(
|
||||
private fun <T : IrDeclaration> applyParentFromStackTo(declaration: T): T = conversionScope.applyParentFromStackTo(declaration)
|
||||
|
||||
fun convertClassContent(irClass: IrClass, klass: FirClass): Unit = conversionScope.withContainingFirClass(klass) {
|
||||
declarationStorage.enterScope(irClass)
|
||||
declarationStorage.enterScope(irClass.symbol)
|
||||
conversionScope.withClass(irClass) {
|
||||
val allDeclarations = buildList {
|
||||
addAll(klass.declarations)
|
||||
@@ -68,7 +68,7 @@ internal class ClassMemberGenerator(
|
||||
val irPrimaryConstructor = primaryConstructor?.let { declarationStorage.getCachedIrConstructor(it)!! }
|
||||
if (irPrimaryConstructor != null) {
|
||||
with(declarationStorage) {
|
||||
enterScope(irPrimaryConstructor)
|
||||
enterScope(irPrimaryConstructor.symbol)
|
||||
irPrimaryConstructor.putParametersInScope(primaryConstructor)
|
||||
convertFunctionContent(irPrimaryConstructor, primaryConstructor, containingClass = klass)
|
||||
}
|
||||
@@ -92,10 +92,10 @@ internal class ClassMemberGenerator(
|
||||
}
|
||||
annotationGenerator.generate(irClass, klass)
|
||||
if (irPrimaryConstructor != null) {
|
||||
declarationStorage.leaveScope(irPrimaryConstructor)
|
||||
declarationStorage.leaveScope(irPrimaryConstructor.symbol)
|
||||
}
|
||||
}
|
||||
declarationStorage.leaveScope(irClass)
|
||||
declarationStorage.leaveScope(irClass.symbol)
|
||||
}
|
||||
|
||||
fun <T : IrFunction> convertFunctionContent(irFunction: T, firFunction: FirFunction?, containingClass: FirClass?): T {
|
||||
@@ -104,7 +104,7 @@ internal class ClassMemberGenerator(
|
||||
if (irFunction !is IrConstructor || !irFunction.isPrimary) {
|
||||
// Scope for primary constructor should be entered before class declaration processing
|
||||
with(declarationStorage) {
|
||||
enterScope(irFunction)
|
||||
enterScope(irFunction.symbol)
|
||||
irFunction.putParametersInScope(firFunction)
|
||||
}
|
||||
}
|
||||
@@ -194,7 +194,7 @@ internal class ClassMemberGenerator(
|
||||
}
|
||||
if (firFunction != null && (irFunction !is IrConstructor || !irFunction.isPrimary)) {
|
||||
// Scope for primary constructor should be left after class declaration
|
||||
declarationStorage.leaveScope(irFunction)
|
||||
declarationStorage.leaveScope(irFunction.symbol)
|
||||
}
|
||||
if (irFunction is IrSimpleFunction && firFunction is FirSimpleFunction && containingClass != null) {
|
||||
irFunction.overriddenSymbols = firFunction.generateOverriddenFunctionSymbols(containingClass)
|
||||
@@ -241,12 +241,12 @@ internal class ClassMemberGenerator(
|
||||
|
||||
fun convertFieldContent(irField: IrField, field: FirField): IrField {
|
||||
conversionScope.withParent(irField) {
|
||||
declarationStorage.enterScope(irField)
|
||||
declarationStorage.enterScope(irField.symbol)
|
||||
val initializerExpression = field.initializer
|
||||
if (irField.initializer == null && initializerExpression != null) {
|
||||
irField.initializer = irFactory.createExpressionBody(visitor.convertToIrExpression(initializerExpression))
|
||||
}
|
||||
declarationStorage.leaveScope(irField)
|
||||
declarationStorage.leaveScope(irField.symbol)
|
||||
}
|
||||
return irField
|
||||
}
|
||||
@@ -257,7 +257,7 @@ internal class ClassMemberGenerator(
|
||||
) {
|
||||
val irField = backingField ?: return
|
||||
conversionScope.withParent(irField) {
|
||||
declarationStorage.enterScope(this@initializeBackingField)
|
||||
declarationStorage.enterScope(this@initializeBackingField.symbol)
|
||||
// NB: initializer can be already converted
|
||||
if (initializer == null && initializerExpression != null) {
|
||||
initializer = irFactory.createExpressionBody(
|
||||
@@ -277,7 +277,7 @@ internal class ClassMemberGenerator(
|
||||
}
|
||||
)
|
||||
}
|
||||
declarationStorage.leaveScope(this@initializeBackingField)
|
||||
declarationStorage.leaveScope(this@initializeBackingField.symbol)
|
||||
}
|
||||
property.backingField?.let { annotationGenerator.generate(irField, it) }
|
||||
}
|
||||
@@ -296,7 +296,7 @@ internal class ClassMemberGenerator(
|
||||
convertFunctionContent(this, propertyAccessor, containingClass = null)
|
||||
if (isDefault) {
|
||||
conversionScope.withParent(this) {
|
||||
declarationStorage.enterScope(this)
|
||||
declarationStorage.enterScope(this.symbol)
|
||||
val backingField = correspondingProperty.backingField
|
||||
val fieldSymbol = backingField?.symbol
|
||||
val declaration = this
|
||||
@@ -318,7 +318,7 @@ internal class ClassMemberGenerator(
|
||||
)
|
||||
)
|
||||
}
|
||||
declarationStorage.leaveScope(this)
|
||||
declarationStorage.leaveScope(this.symbol)
|
||||
}
|
||||
}
|
||||
if (containingClass != null) {
|
||||
|
||||
@@ -108,9 +108,9 @@ abstract class AbstractFir2IrLazyFunction<F : FirCallableDeclaration>(
|
||||
}
|
||||
|
||||
protected fun createThisReceiverParameter(thisType: IrType, explicitReceiver: FirReceiverParameter? = null): IrValueParameter {
|
||||
declarationStorage.enterScope(this)
|
||||
declarationStorage.enterScope(this.symbol)
|
||||
return declareThisReceiverParameter(thisType, origin, explicitReceiver = explicitReceiver).apply {
|
||||
declarationStorage.leaveScope(this@AbstractFir2IrLazyFunction)
|
||||
declarationStorage.leaveScope(this@AbstractFir2IrLazyFunction.symbol)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -84,12 +84,12 @@ class Fir2IrLazyConstructor(
|
||||
val containingClass = parent as? IrClass
|
||||
val outerClass = containingClass?.parentClassOrNull
|
||||
if (containingClass?.isInner == true && outerClass != null) {
|
||||
declarationStorage.enterScope(this)
|
||||
declarationStorage.enterScope(this.symbol)
|
||||
declareThisReceiverParameter(
|
||||
thisType = outerClass.thisReceiver!!.type,
|
||||
thisOrigin = origin
|
||||
).apply {
|
||||
declarationStorage.leaveScope(this@Fir2IrLazyConstructor)
|
||||
declarationStorage.leaveScope(this@Fir2IrLazyConstructor.symbol)
|
||||
}
|
||||
} else null
|
||||
}
|
||||
@@ -99,7 +99,7 @@ class Fir2IrLazyConstructor(
|
||||
override var contextReceiverParametersCount: Int = fir.contextReceivers.size
|
||||
|
||||
override var valueParameters: List<IrValueParameter> by lazyVar(lock) {
|
||||
declarationStorage.enterScope(this)
|
||||
declarationStorage.enterScope(this.symbol)
|
||||
|
||||
buildList {
|
||||
declarationStorage.addContextReceiverParametersTo(
|
||||
@@ -118,7 +118,7 @@ class Fir2IrLazyConstructor(
|
||||
}
|
||||
}
|
||||
}.apply {
|
||||
declarationStorage.leaveScope(this@Fir2IrLazyConstructor)
|
||||
declarationStorage.leaveScope(this@Fir2IrLazyConstructor.symbol)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ class Fir2IrLazyPropertyAccessor(
|
||||
override var valueParameters: List<IrValueParameter> by lazyVar(lock) {
|
||||
if (!isSetter && contextReceiverParametersCount == 0) emptyList()
|
||||
else {
|
||||
declarationStorage.enterScope(this)
|
||||
declarationStorage.enterScope(this.symbol)
|
||||
|
||||
buildList {
|
||||
declarationStorage.addContextReceiverParametersTo(
|
||||
@@ -103,7 +103,7 @@ class Fir2IrLazyPropertyAccessor(
|
||||
)
|
||||
}
|
||||
}.apply {
|
||||
declarationStorage.leaveScope(this@Fir2IrLazyPropertyAccessor)
|
||||
declarationStorage.leaveScope(this@Fir2IrLazyPropertyAccessor.symbol)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ class Fir2IrLazySimpleFunction(
|
||||
override var contextReceiverParametersCount: Int = fir.contextReceiversForFunctionOrContainingProperty().size
|
||||
|
||||
override var valueParameters: List<IrValueParameter> by lazyVar(lock) {
|
||||
declarationStorage.enterScope(this)
|
||||
declarationStorage.enterScope(this.symbol)
|
||||
|
||||
buildList {
|
||||
declarationStorage.addContextReceiverParametersTo(
|
||||
@@ -83,7 +83,7 @@ class Fir2IrLazySimpleFunction(
|
||||
}
|
||||
}
|
||||
}.apply {
|
||||
declarationStorage.leaveScope(this@Fir2IrLazySimpleFunction)
|
||||
declarationStorage.leaveScope(this@Fir2IrLazySimpleFunction.symbol)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user