[FIR] optimize deprecation calculation for symbols
All symbols except member callables can be deprecated if they have non-empty annotation list ^KT-56800 fixed
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
// FIR_DISABLE_LAZY_RESOLVE_CHECKS
|
||||
// ISSUE: KT-55286
|
||||
|
||||
annotation class Deprecated<T>
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
package org.jetbrains.kotlin.fir.symbols.impl
|
||||
|
||||
import org.jetbrains.kotlin.config.ApiVersion
|
||||
import org.jetbrains.kotlin.fir.FirAnnotationContainer
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.lazyResolveToPhase
|
||||
@@ -67,10 +66,17 @@ abstract class FirCallableSymbol<D : FirCallableDeclaration> : FirBasedSymbol<D>
|
||||
get() = callableId.callableName
|
||||
|
||||
fun getDeprecation(apiVersion: ApiVersion): DeprecationsPerUseSite? {
|
||||
if (!canBeDeprecated()) return null
|
||||
lazyResolveToPhase(FirResolvePhase.STATUS)
|
||||
return fir.deprecationsProvider.getDeprecationsInfo(apiVersion)
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if symbol can be deprecated by syntax
|
||||
* @return `true` if symbol might have some deprecation status, or `false` if it's definitely not deprecated
|
||||
*/
|
||||
internal open fun canBeDeprecated(): Boolean = true
|
||||
|
||||
private fun ensureType(typeRef: FirTypeRef?) {
|
||||
when (typeRef) {
|
||||
null, is FirResolvedTypeRef -> {}
|
||||
|
||||
@@ -26,7 +26,8 @@ sealed class FirClassLikeSymbol<D : FirClassLikeDeclaration>(
|
||||
|
||||
val name get() = classId.shortClassName
|
||||
|
||||
fun getDeprecation(apiVersion: ApiVersion): DeprecationsPerUseSite? {
|
||||
fun getDeprecation(apiVersion: ApiVersion): DeprecationsPerUseSite? {
|
||||
if (annotations.isEmpty()) return null
|
||||
lazyResolveToPhase(FirResolvePhase.COMPILER_REQUIRED_ANNOTATIONS)
|
||||
return fir.deprecationsProvider.getDeprecationsInfo(apiVersion)
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.fir.symbols.impl
|
||||
import org.jetbrains.kotlin.fir.FirLabel
|
||||
import org.jetbrains.kotlin.fir.contracts.FirResolvedContractDescription
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isLocal
|
||||
import org.jetbrains.kotlin.fir.expressions.FirDelegatedConstructorCall
|
||||
import org.jetbrains.kotlin.fir.references.FirControlFlowGraphReference
|
||||
import org.jetbrains.kotlin.fir.references.toResolvedConstructorSymbol
|
||||
@@ -41,7 +42,12 @@ sealed class FirFunctionSymbol<D : FirFunction>(
|
||||
|
||||
open class FirNamedFunctionSymbol(
|
||||
callableId: CallableId,
|
||||
) : FirFunctionSymbol<FirSimpleFunction>(callableId)
|
||||
) : FirFunctionSymbol<FirSimpleFunction>(callableId) {
|
||||
override fun canBeDeprecated(): Boolean {
|
||||
if (isLocal || callableId.className == null) return annotations.isNotEmpty()
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
interface FirIntersectionCallableSymbol {
|
||||
val intersections: Collection<FirCallableSymbol<*>>
|
||||
@@ -75,6 +81,10 @@ class FirConstructorSymbol(
|
||||
|
||||
val delegatedConstructorCallIsSuper: Boolean
|
||||
get() = fir.delegatedConstructor?.isSuper ?: false
|
||||
|
||||
override fun canBeDeprecated(): Boolean {
|
||||
return annotations.isNotEmpty()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -99,12 +109,20 @@ sealed class FirFunctionWithoutNameSymbol<F : FirFunction>(
|
||||
|
||||
class FirAnonymousFunctionSymbol : FirFunctionWithoutNameSymbol<FirAnonymousFunction>(Name.identifier("anonymous")) {
|
||||
val label: FirLabel? get() = fir.label
|
||||
|
||||
override fun canBeDeprecated(): Boolean {
|
||||
return annotations.isNotEmpty()
|
||||
}
|
||||
}
|
||||
|
||||
class FirPropertyAccessorSymbol : FirFunctionWithoutNameSymbol<FirPropertyAccessor>(Name.identifier("accessor")) {
|
||||
val isGetter: Boolean get() = fir.isGetter
|
||||
val isSetter: Boolean get() = fir.isSetter
|
||||
val propertySymbol get() = fir.propertySymbol
|
||||
|
||||
override fun canBeDeprecated(): Boolean {
|
||||
return propertySymbol.canBeDeprecated()
|
||||
}
|
||||
}
|
||||
|
||||
class FirErrorFunctionSymbol : FirFunctionWithoutNameSymbol<FirErrorFunction>(Name.identifier("error"))
|
||||
|
||||
@@ -61,6 +61,15 @@ open class FirPropertySymbol(
|
||||
|
||||
val isVar: Boolean
|
||||
get() = fir.isVar
|
||||
|
||||
override fun canBeDeprecated(): Boolean {
|
||||
if (isLocal || callableId.className == null) {
|
||||
return annotations.isNotEmpty()
|
||||
|| getterSymbol?.annotations?.isNotEmpty() == true
|
||||
|| setterSymbol?.annotations?.isNotEmpty() == true
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
class FirIntersectionOverridePropertySymbol(
|
||||
@@ -116,6 +125,9 @@ class FirValueParameterSymbol(name: Name) : FirVariableSymbol<FirValueParameter>
|
||||
val containingFunctionSymbol: FirFunctionSymbol<*>
|
||||
get() = fir.containingFunctionSymbol
|
||||
|
||||
override fun canBeDeprecated(): Boolean {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
class FirErrorPropertySymbol(
|
||||
|
||||
Reference in New Issue
Block a user