[FIR] Inline FirExpression.coneTypeSafe und use resolvedType
The call-sites don't actually need to handle unresolved expressions, they only need safe-casts to ConeClassLikeType or ConeIntegerLiteralType. #KT-61367
This commit is contained in:
committed by
Space Team
parent
a4fff7c7c0
commit
0d628c9e59
+2
-4
@@ -1158,8 +1158,7 @@ internal class KtFirCallResolver(
|
||||
private fun FirArrayLiteral.toKtCallInfo(): KtCallInfo? {
|
||||
val arrayOfSymbol = with(analysisSession) {
|
||||
|
||||
@OptIn(UnresolvedExpressionTypeAccess::class)
|
||||
val type = coneTypeSafe<ConeClassLikeType>()
|
||||
val type = resolvedType as? ConeClassLikeType
|
||||
?: return run {
|
||||
val defaultArrayOfSymbol = arrayOfSymbol(arrayOf) ?: return null
|
||||
val substitutor = createSubstitutorFromTypeArguments(defaultArrayOfSymbol)
|
||||
@@ -1205,8 +1204,7 @@ internal class KtFirCallResolver(
|
||||
// No type parameter means this is an arrayOf call of primitives, in which case there is no type arguments
|
||||
val typeParameter = firSymbol.fir.typeParameters.singleOrNull() ?: return KtSubstitutor.Empty(token)
|
||||
|
||||
@OptIn(UnresolvedExpressionTypeAccess::class)
|
||||
val elementType = coneTypeSafe<ConeClassLikeType>()?.arrayElementType() ?: return KtSubstitutor.Empty(token)
|
||||
val elementType = resolvedType.arrayElementType() ?: return KtSubstitutor.Empty(token)
|
||||
val coneSubstitutor = substitutorByMap(mapOf(typeParameter.symbol to elementType), rootModuleSession)
|
||||
return firSymbolBuilder.typeBuilder.buildSubstitutor(coneSubstitutor)
|
||||
}
|
||||
|
||||
+2
-4
@@ -13,9 +13,8 @@ import org.jetbrains.kotlin.analysis.api.fir.symbols.KtFirArrayOfSymbolProvider.
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.getOrBuildFirSafe
|
||||
import org.jetbrains.kotlin.fir.expressions.FirArrayLiteral
|
||||
import org.jetbrains.kotlin.fir.expressions.UnresolvedExpressionTypeAccess
|
||||
import org.jetbrains.kotlin.fir.types.ConeClassLikeType
|
||||
import org.jetbrains.kotlin.fir.types.coneTypeSafe
|
||||
import org.jetbrains.kotlin.fir.types.resolvedType
|
||||
|
||||
import org.jetbrains.kotlin.psi.KtCollectionLiteralExpression
|
||||
|
||||
@@ -26,8 +25,7 @@ class KtFirCollectionLiteralReference(
|
||||
check(this is KtFirAnalysisSession)
|
||||
val fir = element.getOrBuildFirSafe<FirArrayLiteral>(firResolveSession) ?: return emptyList()
|
||||
|
||||
@OptIn(UnresolvedExpressionTypeAccess::class)
|
||||
val type = fir.coneTypeSafe<ConeClassLikeType>() ?: return listOfNotNull(arrayOfSymbol(arrayOf))
|
||||
val type = fir.resolvedType as? ConeClassLikeType ?: return listOfNotNull(arrayOfSymbol(arrayOf))
|
||||
val call = arrayTypeToArrayOfCall[type.lookupTag.classId] ?: arrayOf
|
||||
return listOfNotNull(arrayOfSymbol(call))
|
||||
}
|
||||
|
||||
+2
-4
@@ -62,8 +62,7 @@ class IntegerLiteralAndOperatorApproximationTransformer(
|
||||
constExpression: FirConstExpression<T>,
|
||||
data: ConeKotlinType?,
|
||||
): FirStatement {
|
||||
@OptIn(UnresolvedExpressionTypeAccess::class)
|
||||
val type = constExpression.coneTypeSafe<ConeIntegerLiteralType>() ?: return constExpression
|
||||
val type = constExpression.resolvedType as? ConeIntegerLiteralType ?: return constExpression
|
||||
val approximatedType = type.getApproximatedType(data?.fullyExpandedType(session))
|
||||
constExpression.resultType = approximatedType
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@@ -79,8 +78,7 @@ class IntegerLiteralAndOperatorApproximationTransformer(
|
||||
@Suppress("UnnecessaryVariable")
|
||||
val call = integerLiteralOperatorCall
|
||||
|
||||
@OptIn(UnresolvedExpressionTypeAccess::class)
|
||||
val operatorType = call.coneTypeSafe<ConeIntegerLiteralType>() ?: return call
|
||||
val operatorType = call.resolvedType as? ConeIntegerLiteralType ?: return call
|
||||
val approximatedType = operatorType.getApproximatedType(data?.fullyExpandedType(session))
|
||||
call.transformDispatchReceiver(this, null)
|
||||
call.transformExtensionReceiver(this, null)
|
||||
|
||||
+1
-3
@@ -37,7 +37,6 @@ import org.jetbrains.kotlin.fir.scopes.impl.isWrappedIntegerOperatorForUnsignedT
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.fir.types.builder.buildErrorTypeRef
|
||||
import org.jetbrains.kotlin.fir.types.impl.FirImplicitTypeRefImplWithoutSource
|
||||
import org.jetbrains.kotlin.fir.visitors.FirDefaultTransformer
|
||||
import org.jetbrains.kotlin.fir.visitors.FirTransformer
|
||||
import org.jetbrains.kotlin.fir.visitors.TransformData
|
||||
@@ -1291,8 +1290,7 @@ open class FirExpressionsResolveTransformer(transformer: FirAbstractBodyResolveT
|
||||
.resolveDelegatingConstructorCall(delegatedConstructorCall, constructorType, containingClass.symbol.toLookupTag())
|
||||
|
||||
if (reference is FirThisReference && reference.boundSymbol == null) {
|
||||
@OptIn(UnresolvedExpressionTypeAccess::class)
|
||||
resolvedCall.dispatchReceiver?.coneTypeSafe<ConeClassLikeType>()?.lookupTag?.toSymbol(session)?.let {
|
||||
(resolvedCall.dispatchReceiver?.resolvedType as? ConeClassLikeType)?.lookupTag?.toSymbol(session)?.let {
|
||||
reference.replaceBoundSymbol(it)
|
||||
}
|
||||
}
|
||||
|
||||
+2
-3
@@ -25,7 +25,7 @@ import org.jetbrains.kotlin.fir.resolve.toSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||
import org.jetbrains.kotlin.fir.types.ConeClassLikeType
|
||||
import org.jetbrains.kotlin.fir.types.coneTypeSafe
|
||||
import org.jetbrains.kotlin.fir.types.resolvedType
|
||||
import org.jetbrains.kotlin.fir.utils.exceptions.withFirEntry
|
||||
import org.jetbrains.kotlin.fir.utils.exceptions.withFirSymbolEntry
|
||||
import org.jetbrains.kotlin.utils.exceptions.errorWithAttachment
|
||||
@@ -180,8 +180,7 @@ class VariableStorageImpl(private val session: FirSession) : VariableStorage() {
|
||||
property.modality != Modality.FINAL -> {
|
||||
val dispatchReceiver = (originalFir.unwrapElement() as? FirQualifiedAccessExpression)?.dispatchReceiver ?: return null
|
||||
|
||||
@OptIn(UnresolvedExpressionTypeAccess::class)
|
||||
val receiverType = dispatchReceiver.coneTypeSafe<ConeClassLikeType>()?.fullyExpandedType(session) ?: return null
|
||||
val receiverType = (dispatchReceiver.resolvedType as? ConeClassLikeType)?.fullyExpandedType(session) ?: return null
|
||||
val receiverSymbol = receiverType.lookupTag.toSymbol(session) ?: return null
|
||||
when (val receiverFir = receiverSymbol.fir) {
|
||||
is FirAnonymousObject -> PropertyStability.STABLE_VALUE
|
||||
|
||||
@@ -41,9 +41,6 @@ val FirExpression.resolvedType: ConeKotlinType
|
||||
withFirEntry("expression", this@resolvedType)
|
||||
}
|
||||
|
||||
@UnresolvedExpressionTypeAccess
|
||||
inline fun <reified T : ConeKotlinType> FirExpression.coneTypeSafe(): T? = (coneTypeOrNull as? T)
|
||||
|
||||
@OptIn(UnresolvedExpressionTypeAccess::class)
|
||||
val FirExpression.isResolved: Boolean get() = coneTypeOrNull != null
|
||||
|
||||
|
||||
Reference in New Issue
Block a user