Skip to content

Commit e10df96

Browse files
committed
Sema: Fold TypeChecker::isDeclAvailable() into its callers
1 parent f48aa51 commit e10df96

File tree

3 files changed

+19
-46
lines changed

3 files changed

+19
-46
lines changed

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -712,29 +712,6 @@ TypeChecker::overApproximateAvailabilityAtLocation(SourceLoc loc,
712712
return OverApproximateContext;
713713
}
714714

715-
bool TypeChecker::isDeclAvailable(const Decl *D, SourceLoc referenceLoc,
716-
const DeclContext *referenceDC,
717-
AvailabilityContext &OutAvailableInfo) {
718-
ASTContext &Context = referenceDC->getASTContext();
719-
720-
AvailabilityContext safeRangeUnderApprox{
721-
AvailabilityInference::availableRange(D, Context)};
722-
AvailabilityContext runningOSOverApprox =
723-
overApproximateAvailabilityAtLocation(referenceLoc, referenceDC);
724-
725-
// The reference is safe if an over-approximation of the running OS
726-
// versions is fully contained within an under-approximation
727-
// of the versions on which the declaration is available. If this
728-
// containment cannot be guaranteed, we say the reference is
729-
// not available.
730-
if (!(runningOSOverApprox.isContainedIn(safeRangeUnderApprox))) {
731-
OutAvailableInfo = safeRangeUnderApprox;
732-
return false;
733-
}
734-
735-
return true;
736-
}
737-
738715
Optional<UnavailabilityReason>
739716
TypeChecker::checkDeclarationAvailability(const Decl *D, SourceLoc referenceLoc,
740717
const DeclContext *referenceDC) {
@@ -749,12 +726,20 @@ TypeChecker::checkDeclarationAvailability(const Decl *D, SourceLoc referenceLoc,
749726
return None;
750727
}
751728

752-
auto safeRangeUnderApprox = AvailabilityContext::neverAvailable();
753-
if (isDeclAvailable(D, referenceLoc, referenceDC, safeRangeUnderApprox)) {
729+
AvailabilityContext runningOSOverApprox =
730+
overApproximateAvailabilityAtLocation(referenceLoc, referenceDC);
731+
732+
AvailabilityContext safeRangeUnderApprox{
733+
AvailabilityInference::availableRange(D, Context)};
734+
735+
// The reference is safe if an over-approximation of the running OS
736+
// versions is fully contained within an under-approximation
737+
// of the versions on which the declaration is available. If this
738+
// containment cannot be guaranteed, we say the reference is
739+
// not available.
740+
if (runningOSOverApprox.isContainedIn(safeRangeUnderApprox))
754741
return None;
755-
}
756742

757-
// safeRangeUnderApprox now holds the safe range.
758743
VersionRange version = safeRangeUnderApprox.getOSVersion();
759744
return UnavailabilityReason::requiresVersionRange(version);
760745
}

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5455,14 +5455,13 @@ static void inferStaticInitializeObjCMetadata(ClassDecl *classDecl) {
54555455
// only statically initialize the Objective-C metadata when running on
54565456
// a new-enough OS.
54575457
if (auto sourceFile = classDecl->getParentSourceFile()) {
5458-
AvailabilityContext availableInfo = AvailabilityContext::alwaysAvailable();
5459-
for (Decl *enclosingDecl = classDecl; enclosingDecl;
5460-
enclosingDecl = enclosingDecl->getDeclContext()
5461-
->getInnermostDeclarationDeclContext()) {
5462-
if (!TypeChecker::isDeclAvailable(enclosingDecl, SourceLoc(), sourceFile,
5463-
availableInfo))
5464-
return;
5465-
}
5458+
AvailabilityContext safeRangeUnderApprox{
5459+
AvailabilityInference::availableRange(classDecl, ctx)};
5460+
AvailabilityContext runningOSOverApprox =
5461+
AvailabilityContext::forDeploymentTarget(ctx);
5462+
5463+
if (!runningOSOverApprox.isContainedIn(safeRangeUnderApprox))
5464+
return;
54665465
}
54675466

54685467
// Infer @_staticInitializeObjCMetadata.

lib/Sema/TypeChecker.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,17 +1011,6 @@ TypeRefinementContext *getOrBuildTypeRefinementContext(SourceFile *SF);
10111011
Optional<Diag<>>
10121012
diagnosticIfDeclCannotBePotentiallyUnavailable(const Decl *D);
10131013

1014-
/// Checks whether a declaration is available when referred to at the given
1015-
/// location (this reference location must be in the passed-in
1016-
/// reference DeclContext).
1017-
/// If the declaration is available, return true.
1018-
/// If the declaration is not available, return false and write the
1019-
/// declaration's availability info to the out parameter
1020-
/// \p OutAvailableRange.
1021-
bool isDeclAvailable(const Decl *D, SourceLoc referenceLoc,
1022-
const DeclContext *referenceDC,
1023-
AvailabilityContext &OutAvailableRange);
1024-
10251014
/// Checks whether a declaration should be considered unavailable when
10261015
/// referred to at the given location and, if so, returns the reason why the
10271016
/// declaration is unavailable. Returns None is the declaration is

0 commit comments

Comments
 (0)