[AA FIR] KT-58503 Use resolvedStatus to access modality only in case of Status Transformers present
ATM unconditional `resolvedStatus` call in `modality` causes a performance degradation in our completion tests Since `resolvedStatus` is called to make sure that all the status-transforming compiler plugins had finished their job, it doesn't make sense to call `resolvedStatus` if there are no such compiler plugins registered N.B. After KT-56551 is fixed, this optimization might become obsolete and can be removed if proved so
This commit is contained in:
+21
-1
@@ -20,7 +20,10 @@ import org.jetbrains.kotlin.analysis.api.symbols.markers.KtSymbolKind
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.descriptors.Visibility
|
||||
import org.jetbrains.kotlin.fir.declarations.FirDeclarationStatus
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.*
|
||||
import org.jetbrains.kotlin.fir.extensions.extensionService
|
||||
import org.jetbrains.kotlin.fir.extensions.statusTransformerExtensions
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
@@ -39,7 +42,7 @@ internal class KtFirNamedClassOrObjectSymbol(
|
||||
|
||||
override val modality: Modality
|
||||
get() = withValidityAssertion {
|
||||
firSymbol.modality
|
||||
firSymbol.optionallyResolvedStatus.modality
|
||||
?: when (classKind) { // default modality
|
||||
KtClassKind.INTERFACE -> Modality.ABSTRACT
|
||||
else -> Modality.FINAL
|
||||
@@ -88,4 +91,21 @@ internal class KtFirNamedClassOrObjectSymbol(
|
||||
}
|
||||
|
||||
override val symbolKind: KtSymbolKind get() = withValidityAssertion { getSymbolKind() }
|
||||
|
||||
/**
|
||||
* We can use [FirRegularClassSymbol.rawStatus] to avoid unnecessary resolve unless there are status transformers present.
|
||||
* If they are present, we have to resort to [FirRegularClassSymbol.resolvedStatus] instead - otherwise we can observe incorrect status
|
||||
* properties.
|
||||
*
|
||||
* TODO This optimization should become obsolete after KT-56551 is fixed.
|
||||
*/
|
||||
private val FirRegularClassSymbol.optionallyResolvedStatus: FirDeclarationStatus
|
||||
get() = if (statusTransformersPresent) {
|
||||
resolvedStatus
|
||||
} else {
|
||||
rawStatus
|
||||
}
|
||||
|
||||
private val statusTransformersPresent: Boolean
|
||||
get() = analysisSession.useSiteSession.extensionService.statusTransformerExtensions.isNotEmpty()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user