FIR: drop some usages of ConeTypeContext
This commit is contained in:
committed by
TeamCityServer
parent
81ff9b820a
commit
d1194e5fd2
@@ -76,7 +76,7 @@ fun FirSymbolProvider.getSymbolByLookupTag(lookupTag: ConeClassLikeLookupTag): F
|
||||
return lookupTag.toSymbol(session)
|
||||
}
|
||||
|
||||
fun ConeKotlinType.withParameterNameAnnotation(valueParameter: FirValueParameter, context: ConeTypeContext): ConeKotlinType {
|
||||
fun ConeKotlinType.withParameterNameAnnotation(valueParameter: FirValueParameter): ConeKotlinType {
|
||||
if (valueParameter.name == SpecialNames.NO_NAME_PROVIDED || valueParameter.name == SpecialNames.UNDERSCORE_FOR_UNUSED_VAR) return this
|
||||
// Existing @ParameterName annotation takes precedence
|
||||
if (attributes.customAnnotations.getAnnotationsByClassId(StandardNames.FqNames.parameterNameClassId).isNotEmpty()) return this
|
||||
@@ -100,16 +100,16 @@ fun ConeKotlinType.withParameterNameAnnotation(valueParameter: FirValueParameter
|
||||
}
|
||||
val attributesWithParameterNameAnnotation =
|
||||
ConeAttributes.create(listOf(CustomAnnotationTypeAttribute(listOf(parameterNameAnnotationCall))))
|
||||
return withCombinedAttributesFrom(attributesWithParameterNameAnnotation, context)
|
||||
return withCombinedAttributesFrom(attributesWithParameterNameAnnotation)
|
||||
}
|
||||
|
||||
fun ConeKotlinType.withCombinedAttributesFrom(other: ConeKotlinType, context: ConeTypeContext): ConeKotlinType =
|
||||
withCombinedAttributesFrom(other.attributes, context)
|
||||
fun ConeKotlinType.withCombinedAttributesFrom(other: ConeKotlinType): ConeKotlinType =
|
||||
withCombinedAttributesFrom(other.attributes)
|
||||
|
||||
private fun ConeKotlinType.withCombinedAttributesFrom(other: ConeAttributes, context: ConeTypeContext): ConeKotlinType {
|
||||
private fun ConeKotlinType.withCombinedAttributesFrom(other: ConeAttributes): ConeKotlinType {
|
||||
if (other.isEmpty()) return this
|
||||
val combinedConeAttributes = attributes.add(other)
|
||||
return withAttributes(combinedConeAttributes, context)
|
||||
return withAttributes(combinedConeAttributes)
|
||||
}
|
||||
|
||||
fun ConeKotlinType.findClassRepresentation(
|
||||
|
||||
@@ -77,7 +77,7 @@ fun ConeClassLikeType.directExpansionType(
|
||||
|
||||
val resultType = expandedConeType(typeAlias)
|
||||
?.applyNullabilityFrom(useSiteSession, this)
|
||||
?.applyAttributesFrom(useSiteSession, this)
|
||||
?.applyAttributesFrom(this)
|
||||
?: return null
|
||||
|
||||
if (resultType.typeArguments.isEmpty()) return resultType
|
||||
@@ -93,11 +93,10 @@ private fun ConeClassLikeType.applyNullabilityFrom(
|
||||
}
|
||||
|
||||
private fun ConeClassLikeType.applyAttributesFrom(
|
||||
session: FirSession,
|
||||
abbreviation: ConeClassLikeType
|
||||
): ConeClassLikeType {
|
||||
val combinedAttributes = attributes.add(abbreviation.attributes)
|
||||
return withAttributes(combinedAttributes, session.typeContext)
|
||||
return withAttributes(combinedAttributes)
|
||||
}
|
||||
|
||||
private fun mapTypeAliasArguments(
|
||||
@@ -135,7 +134,7 @@ private fun mapTypeAliasArguments(
|
||||
is ConeDefinitelyNotNullType,
|
||||
is ConeTypeParameterTypeImpl,
|
||||
is ConeFlexibleType -> {
|
||||
mappedType.withAttributes(type.attributes.add(mappedType.attributes), useSiteSession.typeContext)
|
||||
mappedType.withAttributes(type.attributes.add(mappedType.attributes))
|
||||
}
|
||||
null -> return mappedProjection
|
||||
else -> mappedType
|
||||
|
||||
+4
-4
@@ -105,7 +105,7 @@ abstract class AbstractConeSubstitutor(protected val typeContext: ConeTypeContex
|
||||
private fun ConeDefinitelyNotNullType.substituteOriginal(): ConeKotlinType? {
|
||||
val substituted = substituteOrNull(original)
|
||||
?.withNullability(ConeNullability.NOT_NULL, typeContext)
|
||||
?.withAttributes(original.attributes, typeContext)
|
||||
?.withAttributes(original.attributes)
|
||||
?: return null
|
||||
return ConeDefinitelyNotNullType.create(substituted, typeContext) ?: substituted
|
||||
}
|
||||
@@ -193,7 +193,7 @@ class ConeSubstitutorByMap(
|
||||
if (type !is ConeTypeParameterType) return null
|
||||
val result =
|
||||
substitution[type.lookupTag.symbol].updateNullabilityIfNeeded(type)
|
||||
?.withCombinedAttributesFrom(type, useSiteSession.typeContext)
|
||||
?.withCombinedAttributesFrom(type)
|
||||
?: return null
|
||||
if (type.isUnsafeVarianceType(useSiteSession)) {
|
||||
return useSiteSession.typeApproximator.approximateToSuperType(
|
||||
@@ -223,7 +223,7 @@ fun createTypeSubstitutorByTypeConstructor(map: Map<TypeConstructorMarker, ConeK
|
||||
override fun substituteType(type: ConeKotlinType): ConeKotlinType? {
|
||||
if (type !is ConeLookupTagBasedType && type !is ConeStubType) return null
|
||||
val new = map[type.typeConstructor(context)] ?: return null
|
||||
return new.approximateIntegerLiteralType().updateNullabilityIfNeeded(type)?.withCombinedAttributesFrom(type, context)
|
||||
return new.approximateIntegerLiteralType().updateNullabilityIfNeeded(type)?.withCombinedAttributesFrom(type)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -235,7 +235,7 @@ internal class TypeSubstitutorByTypeConstructor(
|
||||
override fun substituteType(type: ConeKotlinType): ConeKotlinType? {
|
||||
if (type !is ConeLookupTagBasedType && type !is ConeStubType) return null
|
||||
val new = map[type.typeConstructor(typeContext)] ?: return null
|
||||
return new.approximateIntegerLiteralType().updateNullabilityIfNeeded(type)?.withCombinedAttributesFrom(type, typeContext)
|
||||
return new.approximateIntegerLiteralType().updateNullabilityIfNeeded(type)?.withCombinedAttributesFrom(type)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -274,17 +274,17 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo
|
||||
|
||||
override fun KotlinTypeMarker.removeAnnotations(): KotlinTypeMarker {
|
||||
require(this is ConeKotlinType)
|
||||
return withAttributes(ConeAttributes.Empty, this@ConeInferenceContext)
|
||||
return withAttributes(ConeAttributes.Empty)
|
||||
}
|
||||
|
||||
override fun SimpleTypeMarker.replaceArguments(newArguments: List<TypeArgumentMarker>): SimpleTypeMarker {
|
||||
require(this is ConeKotlinType)
|
||||
return this.withArguments(newArguments.cast<List<ConeTypeProjection>>().toTypedArray(), this@ConeInferenceContext)
|
||||
return this.withArguments(newArguments.cast<List<ConeTypeProjection>>().toTypedArray())
|
||||
}
|
||||
|
||||
override fun SimpleTypeMarker.replaceArguments(replacement: (TypeArgumentMarker) -> TypeArgumentMarker): SimpleTypeMarker {
|
||||
require(this is ConeKotlinType)
|
||||
return this.withArguments({ replacement(it).cast() }, this@ConeInferenceContext)
|
||||
return this.withArguments { replacement(it) as ConeTypeProjection }
|
||||
}
|
||||
|
||||
override fun KotlinTypeMarker.hasExactAnnotation(): Boolean {
|
||||
@@ -387,7 +387,7 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo
|
||||
|
||||
override fun KotlinTypeMarker.removeExactAnnotation(): KotlinTypeMarker {
|
||||
require(this is ConeKotlinType)
|
||||
return withAttributes(attributes.remove(CompilerConeAttributes.Exact), this@ConeInferenceContext)
|
||||
return withAttributes(attributes.remove(CompilerConeAttributes.Exact))
|
||||
}
|
||||
|
||||
override fun TypeConstructorMarker.toErrorType(): SimpleTypeMarker {
|
||||
@@ -415,10 +415,7 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val newCustomAttributes = (newAttributes as List<ConeAttribute<*>>).filter { it.isCustomAttribute() }
|
||||
val attributesToKeep = this.attributes.filterNot { it.isCustomAttribute() }
|
||||
return withAttributes(
|
||||
ConeAttributes.create(newCustomAttributes + attributesToKeep),
|
||||
this@ConeInferenceContext
|
||||
)
|
||||
return withAttributes(ConeAttributes.create(newCustomAttributes + attributesToKeep))
|
||||
}
|
||||
|
||||
override fun TypeConstructorMarker.getApproximatedIntegerLiteralType(): KotlinTypeMarker {
|
||||
|
||||
@@ -89,7 +89,7 @@ fun ConeKotlinType.makeConeTypeDefinitelyNotNullOrNotNull(typeContext: ConeTypeC
|
||||
return ConeDefinitelyNotNullType.create(this, typeContext) ?: this.withNullability(ConeNullability.NOT_NULL, typeContext)
|
||||
}
|
||||
|
||||
fun <T : ConeKotlinType> T.withArguments(arguments: Array<out ConeTypeProjection>, typeSystemContext: ConeTypeContext): T {
|
||||
fun <T : ConeKotlinType> T.withArguments(arguments: Array<out ConeTypeProjection>): T {
|
||||
if (this.typeArguments === arguments) {
|
||||
return this
|
||||
}
|
||||
@@ -98,15 +98,15 @@ fun <T : ConeKotlinType> T.withArguments(arguments: Array<out ConeTypeProjection
|
||||
return when (this) {
|
||||
is ConeClassErrorType -> this
|
||||
is ConeClassLikeTypeImpl -> ConeClassLikeTypeImpl(lookupTag, arguments, nullability.isNullable) as T
|
||||
is ConeDefinitelyNotNullType -> ConeDefinitelyNotNullType(original.withArguments(arguments, typeSystemContext)) as T
|
||||
is ConeDefinitelyNotNullType -> ConeDefinitelyNotNullType(original.withArguments(arguments)) as T
|
||||
else -> error("Not supported: $this: ${this.render()}")
|
||||
}
|
||||
}
|
||||
|
||||
fun <T : ConeKotlinType> T.withArguments(replacement: (ConeTypeProjection) -> ConeTypeProjection, typeSystemContext: ConeTypeContext) =
|
||||
withArguments(typeArguments.map(replacement).toTypedArray(), typeSystemContext)
|
||||
fun <T : ConeKotlinType> T.withArguments(replacement: (ConeTypeProjection) -> ConeTypeProjection) =
|
||||
withArguments(typeArguments.map(replacement).toTypedArray())
|
||||
|
||||
fun <T : ConeKotlinType> T.withAttributes(attributes: ConeAttributes, typeSystemContext: ConeTypeContext): T {
|
||||
fun <T : ConeKotlinType> T.withAttributes(attributes: ConeAttributes): T {
|
||||
if (this.attributes == attributes) {
|
||||
return this
|
||||
}
|
||||
@@ -115,16 +115,10 @@ fun <T : ConeKotlinType> T.withAttributes(attributes: ConeAttributes, typeSystem
|
||||
return when (this) {
|
||||
is ConeClassErrorType -> this
|
||||
is ConeClassLikeTypeImpl -> ConeClassLikeTypeImpl(lookupTag, typeArguments, nullability.isNullable, attributes)
|
||||
is ConeDefinitelyNotNullType -> ConeDefinitelyNotNullType(original.withAttributes(attributes, typeSystemContext))
|
||||
is ConeDefinitelyNotNullType -> ConeDefinitelyNotNullType(original.withAttributes(attributes))
|
||||
is ConeTypeParameterTypeImpl -> ConeTypeParameterTypeImpl(lookupTag, nullability.isNullable, attributes)
|
||||
is ConeRawType -> ConeRawType(
|
||||
lowerBound.withAttributes(attributes, typeSystemContext),
|
||||
upperBound.withAttributes(attributes, typeSystemContext)
|
||||
)
|
||||
is ConeFlexibleType -> ConeFlexibleType(
|
||||
lowerBound.withAttributes(attributes, typeSystemContext),
|
||||
upperBound.withAttributes(attributes, typeSystemContext)
|
||||
)
|
||||
is ConeRawType -> ConeRawType(lowerBound.withAttributes(attributes), upperBound.withAttributes(attributes))
|
||||
is ConeFlexibleType -> ConeFlexibleType(lowerBound.withAttributes(attributes), upperBound.withAttributes(attributes))
|
||||
is ConeTypeVariableType -> ConeTypeVariableType(nullability, lookupTag, attributes)
|
||||
is ConeCapturedType -> ConeCapturedType(
|
||||
captureStatus, lowerType, nullability, constructor, attributes, isProjectionNotNull,
|
||||
@@ -252,7 +246,7 @@ fun FirTypeRef.isUnsafeVarianceType(session: FirSession): Boolean {
|
||||
fun FirTypeRef.hasEnhancedNullability(): Boolean =
|
||||
coneTypeSafe<ConeKotlinType>()?.hasEnhancedNullability == true
|
||||
|
||||
fun FirTypeRef.withoutEnhancedNullability(typeSystemContext: ConeTypeContext): FirTypeRef {
|
||||
fun FirTypeRef.withoutEnhancedNullability(): FirTypeRef {
|
||||
require(this is FirResolvedTypeRef)
|
||||
if (!hasEnhancedNullability()) return this
|
||||
return buildResolvedTypeRef {
|
||||
@@ -261,7 +255,6 @@ fun FirTypeRef.withoutEnhancedNullability(typeSystemContext: ConeTypeContext): F
|
||||
ConeAttributes.create(
|
||||
this@withoutEnhancedNullability.type.attributes.filter { it != CompilerConeAttributes.EnhancedNullability }
|
||||
),
|
||||
typeSystemContext,
|
||||
)
|
||||
annotations += this@withoutEnhancedNullability.annotations
|
||||
}
|
||||
@@ -323,14 +316,13 @@ fun FirTypeRef.approximated(
|
||||
fun FirTypeRef.approximatedIfNeededOrSelf(
|
||||
approximator: ConeTypeApproximator,
|
||||
containingCallableVisibility: Visibility?,
|
||||
typeSystemContext: ConeTypeContext,
|
||||
isInlineFunction: Boolean = false,
|
||||
): FirTypeRef {
|
||||
val approximated = if (containingCallableVisibility == Visibilities.Public || containingCallableVisibility == Visibilities.Protected)
|
||||
approximatedForPublicPosition(approximator)
|
||||
else
|
||||
this
|
||||
return approximated.hideLocalTypeIfNeeded(containingCallableVisibility, isInlineFunction).withoutEnhancedNullability(typeSystemContext)
|
||||
return approximated.hideLocalTypeIfNeeded(containingCallableVisibility, isInlineFunction).withoutEnhancedNullability()
|
||||
}
|
||||
|
||||
fun FirTypeRef.approximatedForPublicPosition(approximator: ConeTypeApproximator): FirTypeRef =
|
||||
@@ -403,15 +395,15 @@ fun FirDeclaration.visibilityForApproximation(container: FirDeclaration?): Visib
|
||||
}
|
||||
|
||||
|
||||
fun ConeTypeContext.captureFromArgumentsInternal(type: ConeKotlinType, status: CaptureStatus): ConeKotlinType? {
|
||||
internal fun ConeTypeContext.captureFromArgumentsInternal(type: ConeKotlinType, status: CaptureStatus): ConeKotlinType? {
|
||||
val capturedArguments = captureArguments(type, status) ?: return null
|
||||
return if (type is ConeFlexibleType) {
|
||||
ConeFlexibleType(
|
||||
type.lowerBound.withArguments(capturedArguments, this),
|
||||
type.upperBound.withArguments(capturedArguments, this),
|
||||
type.lowerBound.withArguments(capturedArguments),
|
||||
type.upperBound.withArguments(capturedArguments),
|
||||
)
|
||||
} else {
|
||||
type.withArguments(capturedArguments, this)
|
||||
type.withArguments(capturedArguments)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -466,7 +458,7 @@ fun ConeTypeContext.captureArguments(type: ConeKotlinType, status: CaptureStatus
|
||||
return newArguments
|
||||
}
|
||||
|
||||
fun ConeTypeContext.captureFromExpressionInternal(type: ConeKotlinType): ConeKotlinType? {
|
||||
internal fun ConeTypeContext.captureFromExpressionInternal(type: ConeKotlinType): ConeKotlinType? {
|
||||
if (type !is ConeIntersectionType && type !is ConeFlexibleType) {
|
||||
return captureFromArgumentsInternal(type, CaptureStatus.FROM_EXPRESSION)
|
||||
}
|
||||
@@ -491,12 +483,12 @@ fun ConeTypeContext.captureFromExpressionInternal(type: ConeKotlinType): ConeKot
|
||||
typeToReplace.intersectedTypes.map { componentType ->
|
||||
val capturedArguments = findCorrespondingCapturedArgumentsForType(componentType)
|
||||
?: return@map componentType
|
||||
componentType.withArguments(capturedArguments, this)
|
||||
componentType.withArguments(capturedArguments)
|
||||
}
|
||||
} else {
|
||||
val capturedArguments = findCorrespondingCapturedArgumentsForType(typeToReplace)
|
||||
?: return listOf(typeToReplace)
|
||||
listOf(typeToReplace.withArguments(capturedArguments, this))
|
||||
listOf(typeToReplace.withArguments(capturedArguments))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user