diff --git a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/FirJavaElementFinder.kt b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/FirJavaElementFinder.kt index 936f3da43db..9494ed105d9 100644 --- a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/FirJavaElementFinder.kt +++ b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/FirJavaElementFinder.kt @@ -96,7 +96,7 @@ class FirJavaElementFinder( ) val superTypeRefs = when { - firClass.resolvePhase > FirResolvePhase.SUPER_TYPES -> firClass.superTypeRefs + firClass.superTypeRefs.all { it is FirResolvedTypeRef } -> firClass.superTypeRefs else -> firClass.resolveSupertypesInTheAir(session) } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/FirDataFlowAnalyzer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/FirDataFlowAnalyzer.kt index f5cc0760ea6..98c7243c938 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/FirDataFlowAnalyzer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/FirDataFlowAnalyzer.kt @@ -13,6 +13,7 @@ import org.jetbrains.kotlin.fir.contracts.description.ConeConditionalEffectDecla import org.jetbrains.kotlin.fir.contracts.description.ConeConstantReference import org.jetbrains.kotlin.fir.contracts.description.ConeReturnsEffectDeclaration import org.jetbrains.kotlin.fir.declarations.* +import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyAccessor import org.jetbrains.kotlin.fir.declarations.utils.isLocal import org.jetbrains.kotlin.fir.expressions.* import org.jetbrains.kotlin.fir.references.FirControlFlowGraphReference @@ -214,6 +215,7 @@ abstract class FirDataFlowAnalyzer( // ----------------------------------- Named function ----------------------------------- fun enterFunction(function: FirFunction) { + if (function is FirDefaultPropertyAccessor) return if (function is FirAnonymousFunction) { enterAnonymousFunction(function) return @@ -226,7 +228,8 @@ abstract class FirDataFlowAnalyzer( functionEnterNode.mergeIncomingFlow(shouldForkFlow = previousNode != null) } - fun exitFunction(function: FirFunction): FirControlFlowGraphReference { + fun exitFunction(function: FirFunction): FirControlFlowGraphReference? { + if (function is FirDefaultPropertyAccessor) return null if (function is FirAnonymousFunction) { return exitAnonymousFunction(function) } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirStatusResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirStatusResolveTransformer.kt index 9cfb5c8264e..e4e859ac37a 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirStatusResolveTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirStatusResolveTransformer.kt @@ -407,8 +407,7 @@ abstract class AbstractFirStatusResolveTransformer( forceResolveStatusesOfSupertypes(regularClass) return } - if (regularClass.resolvePhase > FirResolvePhase.STATUS) return - val firProvider = session.firProvider + if (regularClass.origin != FirDeclarationOrigin.Source) return val statusComputationStatus = statusComputationSession[regularClass] if (!statusComputationStatus.requiresComputation) return @@ -425,6 +424,7 @@ abstract class AbstractFirStatusResolveTransformer( } reverse() } else buildList { + val firProvider = regularClass.moduleData.session.firProvider val outerClasses = generateSequence(symbol.classId) { classId -> classId.outerClassId }.mapTo(mutableListOf()) { firProvider.getFirClassifierByFqName(it) } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirSupertypesResolution.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirSupertypesResolution.kt index 36a164d19f5..7c5db72dbb9 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirSupertypesResolution.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirSupertypesResolution.kt @@ -436,14 +436,14 @@ class SupertypeComputationSession { val supertypesSupplier: SupertypeSupplier = object : SupertypeSupplier() { override fun forClass(firClass: FirClass, useSiteSession: FirSession): List { - if (firClass.resolvePhase > FirResolvePhase.SUPER_TYPES) return firClass.superConeTypes + if (firClass.superTypeRefs.all { it is FirResolvedTypeRef }) return firClass.superConeTypes return (getSupertypesComputationStatus(firClass) as? SupertypeComputationStatus.Computed)?.supertypeRefs?.mapNotNull { it.coneTypeSafe() }.orEmpty() } override fun expansionForTypeAlias(typeAlias: FirTypeAlias, useSiteSession: FirSession): ConeClassLikeType? { - if (typeAlias.resolvePhase > FirResolvePhase.SUPER_TYPES) return typeAlias.expandedConeType + if (typeAlias.expandedTypeRef is FirResolvedTypeRef) return typeAlias.expandedConeType return (getSupertypesComputationStatus(typeAlias) as? SupertypeComputationStatus.Computed) ?.supertypeRefs ?.getOrNull(0)?.coneTypeSafe() diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt index 5e790cf7a0b..7f69eac9c67 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt @@ -107,7 +107,7 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor } override fun transformEnumEntry(enumEntry: FirEnumEntry, data: ResolutionMode): FirEnumEntry { - if (enumEntry.resolvePhase == transformerPhase) return enumEntry + if (implicitTypeOnly || enumEntry.initializerResolved) return enumEntry transformer.replaceDeclarationResolvePhaseIfNeeded(enumEntry, transformerPhase) return context.forEnumEntry { (enumEntry.transformChildren(this, data) as FirEnumEntry) @@ -126,11 +126,8 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor } val returnTypeRef = property.returnTypeRef + if (property.initializerAndAccessorsAreResolved) return property if (returnTypeRef !is FirImplicitTypeRef && implicitTypeOnly) return property - if (property.resolvePhase == transformerPhase) return property - if (property.resolvePhase == FirResolvePhase.BODY_RESOLVE || property.resolvePhase == transformerPhase) { - return property - } property.transformReceiverTypeRef(transformer, ResolutionMode.ContextIndependent) dataFlowAnalyzer.enterProperty(property) @@ -158,6 +155,7 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor dataFlowAnalyzer.exitProperty(property)?.let { property.replaceControlFlowGraphReference(FirControlFlowGraphReferenceImpl(it)) } + property.replaceInitializerAndAccessorsAreResolved(true) property } } @@ -165,9 +163,8 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor override fun transformField(field: FirField, data: ResolutionMode): FirField { val returnTypeRef = field.returnTypeRef if (implicitTypeOnly) return field - if (field.resolvePhase == FirResolvePhase.BODY_RESOLVE || field.resolvePhase == transformerPhase) { - return field - } + if (field.initializerResolved) return field + dataFlowAnalyzer.enterField(field) return withFullBodyResolve { context.withField(field) { @@ -394,23 +391,17 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor regularClass: FirRegularClass, data: ResolutionMode ): FirRegularClass { - val notAnalyzed = regularClass.resolvePhase < transformerPhase - - if (notAnalyzed) { - dataFlowAnalyzer.enterClass() - } + dataFlowAnalyzer.enterClass() val result = context.withRegularClass(regularClass, components) { transformDeclarationContent(regularClass, data) as FirRegularClass } - if (notAnalyzed) { - if (!implicitTypeOnly) { - val controlFlowGraph = dataFlowAnalyzer.exitRegularClass(result) - result.replaceControlFlowGraphReference(FirControlFlowGraphReferenceImpl(controlFlowGraph)) - } else { - dataFlowAnalyzer.exitClass() - } + if (!implicitTypeOnly) { + val controlFlowGraph = dataFlowAnalyzer.exitRegularClass(result) + result.replaceControlFlowGraphReference(FirControlFlowGraphReferenceImpl(controlFlowGraph)) + } else { + dataFlowAnalyzer.exitClass() } return result @@ -476,7 +467,7 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor simpleFunction: FirSimpleFunction, data: ResolutionMode ): FirSimpleFunction { - if (simpleFunction.resolvePhase == FirResolvePhase.BODY_RESOLVE || simpleFunction.resolvePhase == transformerPhase) { + if (simpleFunction.bodyResolved) { return simpleFunction } val returnTypeRef = simpleFunction.returnTypeRef @@ -540,7 +531,7 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor function: FirFunction, data: ResolutionMode ): FirStatement { - val functionIsNotAnalyzed = transformerPhase != function.resolvePhase + val functionIsNotAnalyzed = !function.bodyResolved if (functionIsNotAnalyzed) { dataFlowAnalyzer.enterFunction(function) } @@ -892,4 +883,10 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor return valueParameter } } + + private val FirVariable.initializerResolved: Boolean + get() = initializer?.typeRef is FirResolvedTypeRef + + private val FirFunction.bodyResolved: Boolean + get() = body?.typeRef is FirResolvedTypeRef } diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/FirProperty.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/FirProperty.kt index 1522e6a4ee1..1928be19d64 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/FirProperty.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/FirProperty.kt @@ -49,6 +49,7 @@ abstract class FirProperty : FirVariable(), FirTypeParametersOwner, FirControlFl abstract val backingFieldSymbol: FirBackingFieldSymbol abstract val delegateFieldSymbol: FirDelegateFieldSymbol? abstract val isLocal: Boolean + abstract val initializerAndAccessorsAreResolved: Boolean abstract override val typeParameters: List override fun accept(visitor: FirVisitor, data: D): R = visitor.visitProperty(this, data) @@ -67,6 +68,8 @@ abstract class FirProperty : FirVariable(), FirTypeParametersOwner, FirControlFl abstract override fun replaceControlFlowGraphReference(newControlFlowGraphReference: FirControlFlowGraphReference?) + abstract fun replaceInitializerAndAccessorsAreResolved(newInitializerAndAccessorsAreResolved: Boolean) + abstract override fun transformReturnTypeRef(transformer: FirTransformer, data: D): FirProperty abstract override fun transformReceiverTypeRef(transformer: FirTransformer, data: D): FirProperty diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/builder/FirPropertyBuilder.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/builder/FirPropertyBuilder.kt index 999ad0877ce..30b5d2e5c33 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/builder/FirPropertyBuilder.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/builder/FirPropertyBuilder.kt @@ -59,6 +59,7 @@ class FirPropertyBuilder : FirDeclarationBuilder, FirTypeParametersOwnerBuilder, lateinit var symbol: FirPropertySymbol var delegateFieldSymbol: FirDelegateFieldSymbol? = null var isLocal: Boolean by kotlin.properties.Delegates.notNull() + var initializerAndAccessorsAreResolved: Boolean = false override val typeParameters: MutableList = mutableListOf() override fun build(): FirProperty { @@ -83,6 +84,7 @@ class FirPropertyBuilder : FirDeclarationBuilder, FirTypeParametersOwnerBuilder, symbol, delegateFieldSymbol, isLocal, + initializerAndAccessorsAreResolved, typeParameters, ) } @@ -123,6 +125,7 @@ inline fun buildPropertyCopy(original: FirProperty, init: FirPropertyBuilder.() copyBuilder.symbol = original.symbol copyBuilder.delegateFieldSymbol = original.delegateFieldSymbol copyBuilder.isLocal = original.isLocal + copyBuilder.initializerAndAccessorsAreResolved = original.initializerAndAccessorsAreResolved copyBuilder.typeParameters.addAll(original.typeParameters) return copyBuilder.apply(init).build() } diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirPropertyImpl.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirPropertyImpl.kt index 0375a3c7a65..439f25d85d1 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirPropertyImpl.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirPropertyImpl.kt @@ -52,6 +52,7 @@ internal class FirPropertyImpl( override val symbol: FirPropertySymbol, override val delegateFieldSymbol: FirDelegateFieldSymbol?, override val isLocal: Boolean, + override var initializerAndAccessorsAreResolved: Boolean, override val typeParameters: MutableList, ) : FirProperty() { override val isVal: Boolean get() = !isVar @@ -160,4 +161,8 @@ internal class FirPropertyImpl( override fun replaceControlFlowGraphReference(newControlFlowGraphReference: FirControlFlowGraphReference?) { controlFlowGraphReference = newControlFlowGraphReference } + + override fun replaceInitializerAndAccessorsAreResolved(newInitializerAndAccessorsAreResolved: Boolean) { + initializerAndAccessorsAreResolved = newInitializerAndAccessorsAreResolved + } } diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirDefaultPropertyAccessor.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirDefaultPropertyAccessor.kt index 6033ccd0f37..3f0b0ea58b3 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirDefaultPropertyAccessor.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/impl/FirDefaultPropertyAccessor.kt @@ -17,11 +17,8 @@ import org.jetbrains.kotlin.fir.declarations.builder.buildDefaultSetterValuePara import org.jetbrains.kotlin.fir.expressions.FirBlock import org.jetbrains.kotlin.fir.symbols.impl.FirPropertyAccessorSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirValueParameterSymbol -import org.jetbrains.kotlin.fir.symbols.impl.FirVariableSymbol import org.jetbrains.kotlin.fir.types.FirTypeRef import org.jetbrains.kotlin.fir.types.impl.FirImplicitUnitTypeRef -import org.jetbrains.kotlin.name.CallableId -import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name @OptIn(FirImplementationDetail::class) diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/synthetic/FirSyntheticProperty.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/synthetic/FirSyntheticProperty.kt index 5520b3e7f1d..82ced502d3f 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/synthetic/FirSyntheticProperty.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/synthetic/FirSyntheticProperty.kt @@ -81,6 +81,9 @@ class FirSyntheticProperty( // ??? override val backingFieldSymbol: FirBackingFieldSymbol = FirBackingFieldSymbol(symbol.callableId) + override val initializerAndAccessorsAreResolved: Boolean + get() = true + override fun acceptChildren(visitor: FirVisitor, data: D) { returnTypeRef.accept(visitor, data) status.accept(visitor, data) @@ -149,4 +152,8 @@ class FirSyntheticProperty( override fun replaceInitializer(newInitializer: FirExpression?) { throw AssertionError("Mutation of synthetic property isn't supported") } + + override fun replaceInitializerAndAccessorsAreResolved(newInitializerAndAccessorsAreResolved: Boolean) { + throw AssertionError("Mutation of synthetic property isn't supported") + } } diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/utils/FirStatusUtils.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/utils/FirStatusUtils.kt index dd47842966c..d72a49b360a 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/utils/FirStatusUtils.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/utils/FirStatusUtils.kt @@ -8,7 +8,10 @@ package org.jetbrains.kotlin.fir.declarations.utils import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.fir.FirRenderer import org.jetbrains.kotlin.fir.declarations.* +import org.jetbrains.kotlin.fir.declarations.impl.FirResolvedDeclarationStatusImpl import org.jetbrains.kotlin.fir.render +import kotlin.contracts.ExperimentalContracts +import kotlin.contracts.contract inline val FirMemberDeclaration.modality: Modality? get() = status.modality inline val FirMemberDeclaration.isAbstract: Boolean get() = status.modality == Modality.ABSTRACT diff --git a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/BuilderConfigurator.kt b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/BuilderConfigurator.kt index 712efb08de8..e008fa04e8f 100644 --- a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/BuilderConfigurator.kt +++ b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/BuilderConfigurator.kt @@ -202,6 +202,7 @@ object BuilderConfigurator : AbstractBuilderConfigurator(FirTree parents += typeParametersOwnerBuilder defaultNull("getter", "setter", "containerSource", "delegateFieldSymbol") default("resolvePhase", "FirResolvePhase.RAW_FIR") + defaultFalse("initializerAndAccessorsAreResolved") withCopy() } diff --git a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt index a2fa0c79dc1..e50d639f6f0 100644 --- a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt +++ b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt @@ -311,6 +311,7 @@ object NodeConfigurator : AbstractFieldConfigurator(FirTreeBuild +field("backingFieldSymbol", backingFieldSymbolType) +field("delegateFieldSymbol", delegateFieldSymbolType, nullable = true) +booleanField("isLocal") + +booleanField("initializerAndAccessorsAreResolved", withReplace = true) +typeParameters } diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/api/DeclarationCopyBuilder.kt b/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/api/DeclarationCopyBuilder.kt index 5d13422e4fb..132921fb1aa 100644 --- a/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/api/DeclarationCopyBuilder.kt +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/api/DeclarationCopyBuilder.kt @@ -59,6 +59,10 @@ internal object DeclarationCopyBuilder { getter = propertyWithBody.getter setter = copySetter + if (propertyResolvePhase < FirResolvePhase.IMPLICIT_TYPES_BODY_RESOLVE) { + initializerAndAccessorsAreResolved = false + } + initDeclaration(this@withBodyFrom, propertyWithBody) resolvePhase = propertyResolvePhase }