Skip to content

Commit 44ab007

Browse files
committed
Sema: Retire TypeChecker::overApproximateAvailabilityAtLocation().
It has been superseded by `AvailabilityContext::forLocation()`.
1 parent da31340 commit 44ab007

6 files changed

+20
-35
lines changed

lib/Sema/TypeCheckAvailability.cpp

+10-16
Original file line numberDiff line numberDiff line change
@@ -288,13 +288,6 @@ static bool shouldTreatDeclContextAsAsyncForDiagnostics(const DeclContext *DC) {
288288
return DC->isAsyncContext();
289289
}
290290

291-
AvailabilityRange TypeChecker::overApproximateAvailabilityAtLocation(
292-
SourceLoc loc, const DeclContext *DC,
293-
const AvailabilityScope **MostRefined) {
294-
return AvailabilityContext::forLocation(loc, DC, MostRefined)
295-
.getPlatformRange();
296-
}
297-
298291
/// A class that walks the AST to find the innermost (i.e., deepest) node that
299292
/// contains a target SourceRange and matches a particular criterion.
300293
/// This class finds the innermost nodes of interest by walking
@@ -689,8 +682,8 @@ static bool fixAvailabilityByNarrowingNearbyVersionCheck(
689682
return false;
690683

691684
const AvailabilityScope *scope = nullptr;
692-
(void)TypeChecker::overApproximateAvailabilityAtLocation(ReferenceRange.Start,
693-
ReferenceDC, &scope);
685+
(void)AvailabilityContext::forLocation(ReferenceRange.Start, ReferenceDC,
686+
&scope);
694687
if (!scope)
695688
return false;
696689

@@ -866,7 +859,7 @@ static void diagnosePotentialUnavailability(
866859
// FIXME: [availability] Should this take an AvailabilityContext instead of
867860
// AvailabilityRange?
868861
bool TypeChecker::checkAvailability(SourceRange ReferenceRange,
869-
AvailabilityRange RequiredAvailability,
862+
AvailabilityRange PlatformRange,
870863
const DeclContext *ReferenceDC,
871864
llvm::function_ref<InFlightDiagnostic(
872865
AvailabilityDomain, AvailabilityRange)>
@@ -880,24 +873,25 @@ bool TypeChecker::checkAvailability(SourceRange ReferenceRange,
880873
return false;
881874

882875
auto availabilityAtLocation =
883-
TypeChecker::overApproximateAvailabilityAtLocation(ReferenceRange.Start,
884-
ReferenceDC);
885-
if (!availabilityAtLocation.isContainedIn(RequiredAvailability)) {
876+
AvailabilityContext::forLocation(ReferenceRange.Start, ReferenceDC)
877+
.getPlatformRange();
878+
879+
if (!availabilityAtLocation.isContainedIn(PlatformRange)) {
886880
diagnosePotentialUnavailability(ReferenceRange, Diagnose, ReferenceDC,
887-
domain, RequiredAvailability);
881+
domain, PlatformRange);
888882
return true;
889883
}
890884

891885
return false;
892886
}
893887

894888
bool TypeChecker::checkAvailability(
895-
SourceRange ReferenceRange, AvailabilityRange RequiredAvailability,
889+
SourceRange ReferenceRange, AvailabilityRange PlatformRange,
896890
Diag<AvailabilityDomain, AvailabilityRange> Diag,
897891
const DeclContext *ReferenceDC) {
898892
auto &Diags = ReferenceDC->getASTContext().Diags;
899893
return TypeChecker::checkAvailability(
900-
ReferenceRange, RequiredAvailability, ReferenceDC,
894+
ReferenceRange, PlatformRange, ReferenceDC,
901895
[&](AvailabilityDomain domain, AvailabilityRange range) {
902896
return Diags.diagnose(ReferenceRange.Start, Diag, domain, range);
903897
});

lib/Sema/TypeCheckConcurrency.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,8 @@ bool IsDefaultActorRequest::evaluate(
220220
auto customExecutorAvailability =
221221
ctx.getConcurrencyDistributedActorWithCustomExecutorAvailability();
222222

223-
auto actorAvailability = TypeChecker::overApproximateAvailabilityAtLocation(
224-
classDecl->getStartLoc(),
225-
classDecl);
223+
auto actorAvailability =
224+
AvailabilityContext::forDeclSignature(classDecl).getPlatformRange();
226225

227226
if (!actorAvailability.isContainedIn(customExecutorAvailability)) {
228227
// Any 'distributed actor' declared with availability lower than the
@@ -1510,8 +1509,7 @@ void swift::tryDiagnoseExecutorConformance(ASTContext &C,
15101509
AvailabilityRange requirementInfo =
15111510
AvailabilityInference::availableRange(moveOnlyEnqueueRequirement);
15121511
AvailabilityRange declInfo =
1513-
TypeChecker::overApproximateAvailabilityAtLocation(
1514-
nominal->getLoc(), dyn_cast<DeclContext>(nominal));
1512+
AvailabilityContext::forDeclSignature(nominal).getPlatformRange();
15151513
canRemoveOldDecls = declInfo.isContainedIn(requirementInfo);
15161514
}
15171515

lib/Sema/TypeCheckDecl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1732,7 +1732,7 @@ bool TypeChecker::isAvailabilitySafeForConformance(
17321732
requirementInfo.constrainWith(infoForConformingDecl);
17331733

17341734
AvailabilityRange infoForProtocolDecl =
1735-
overApproximateAvailabilityAtLocation(proto->getLoc(), proto);
1735+
AvailabilityContext::forDeclSignature(proto).getPlatformRange();
17361736

17371737
witnessInfo.constrainWith(infoForProtocolDecl);
17381738
requirementInfo.constrainWith(infoForProtocolDecl);

lib/Sema/TypeCheckProtocol.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -5210,8 +5210,8 @@ static void ensureRequirementsAreSatisfied(ASTContext &ctx,
52105210
if (auto depMemberType = depTy->getAs<DependentMemberType>()) {
52115211
auto assocType = depMemberType->getAssocType();
52125212
availability.intersectWith(
5213-
TypeChecker::overApproximateAvailabilityAtLocation(
5214-
assocType->getLoc(), assocType->getDeclContext()));
5213+
AvailabilityContext::forDeclSignature(assocType)
5214+
.getPlatformRange());
52155215
}
52165216

52175217
diagnoseConformanceAvailability(

lib/Sema/TypeCheckStmt.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -3299,7 +3299,8 @@ FuncDecl *TypeChecker::getForEachIteratorNextFunction(
32993299

33003300
// We can only call next(isolation:) if we are in an availability context
33013301
// that supports typed throws.
3302-
auto availability = overApproximateAvailabilityAtLocation(loc, dc);
3302+
auto availability =
3303+
AvailabilityContext::forLocation(loc, dc).getPlatformRange();
33033304
if (availability.isContainedIn(ctx.getTypedThrowsAvailability()))
33043305
return nextElement;
33053306

lib/Sema/TypeChecker.h

+2-10
Original file line numberDiff line numberDiff line change
@@ -1031,14 +1031,6 @@ bool isAvailabilitySafeForConformance(
10311031
const ValueDecl *witness, const DeclContext *dc,
10321032
AvailabilityRange &requiredAvailability);
10331033

1034-
/// Returns an over-approximation of the range of operating system versions
1035-
/// that could the passed-in location could be executing upon for
1036-
/// the target platform. If MostRefined != nullptr, set to the most-refined
1037-
/// scope found while approximating.
1038-
AvailabilityRange overApproximateAvailabilityAtLocation(
1039-
SourceLoc loc, const DeclContext *DC,
1040-
const AvailabilityScope **MostRefined = nullptr);
1041-
10421034
/// Returns a diagnostic indicating why the declaration cannot be annotated
10431035
/// with an @available() attribute indicating it is potentially unavailable
10441036
/// or None if this is allowed.
@@ -1055,7 +1047,7 @@ diagnosticIfDeclCannotBeUnavailable(const Decl *D, SemanticAvailableAttr attr);
10551047
/// platform are available at the given `SourceRange`. If not, `Diagnose` is
10561048
/// invoked.
10571049
bool checkAvailability(SourceRange ReferenceRange,
1058-
AvailabilityRange RequiredAvailability,
1050+
AvailabilityRange PlatformRange,
10591051
const DeclContext *ReferenceDC,
10601052
llvm::function_ref<InFlightDiagnostic(AvailabilityDomain,
10611053
AvailabilityRange)>
@@ -1065,7 +1057,7 @@ bool checkAvailability(SourceRange ReferenceRange,
10651057
/// platform are available at the given `SourceRange`. If not, `Diag` is
10661058
/// emitted.
10671059
bool checkAvailability(SourceRange ReferenceRange,
1068-
AvailabilityRange RequiredAvailability,
1060+
AvailabilityRange PlatformRange,
10691061
Diag<AvailabilityDomain, AvailabilityRange> Diag,
10701062
const DeclContext *ReferenceDC);
10711063

0 commit comments

Comments
 (0)