Skip to content

Commit 7ffa095

Browse files
committed
AST: Introduce AvailabilityContext::forDeploymentTarget()
1 parent b52472b commit 7ffa095

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

include/swift/AST/Availability.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,10 @@ class AvailabilityContext {
240240
/// Creates a context that requires certain versions of the target OS.
241241
explicit AvailabilityContext(VersionRange OSVersion) : OSVersion(OSVersion) {}
242242

243+
/// Creates a context that imposes the constraints of the ASTContext's
244+
/// deployment target.
245+
static AvailabilityContext forDeploymentTarget(ASTContext &Ctx);
246+
243247
/// Creates a context that imposes no constraints.
244248
///
245249
/// \see isAlwaysAvailable

lib/AST/Availability.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
//
1515
//===----------------------------------------------------------------------===//
1616

17+
#include "swift/AST/ASTContext.h"
1718
#include "swift/AST/Attr.h"
1819
#include "swift/AST/Decl.h"
1920
#include "swift/AST/Types.h"
@@ -24,6 +25,11 @@
2425

2526
using namespace swift;
2627

28+
AvailabilityContext AvailabilityContext::forDeploymentTarget(ASTContext &Ctx) {
29+
return AvailabilityContext(
30+
VersionRange::allGTE(Ctx.LangOpts.getMinPlatformVersion()));
31+
}
32+
2733
namespace {
2834

2935
/// The inferred availability required to access a group of declarations

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -592,8 +592,7 @@ void TypeChecker::buildTypeRefinementContextHierarchy(SourceFile &SF,
592592
// The root type refinement context reflects the fact that all parts of
593593
// the source file are guaranteed to be executing on at least the minimum
594594
// platform version.
595-
AvailabilityContext MinPlatformReq{
596-
VersionRange::allGTE(AC.LangOpts.getMinPlatformVersion())};
595+
auto MinPlatformReq = AvailabilityContext::forDeploymentTarget(AC);
597596
RootTRC = TypeRefinementContext::createRoot(&SF, MinPlatformReq);
598597
SF.setTypeRefinementContext(RootTRC);
599598
}
@@ -638,8 +637,8 @@ TypeChecker::overApproximateAvailabilityAtLocation(SourceLoc loc,
638637
// this will be a real problem.
639638

640639
// We can assume we are running on at least the minimum deployment target.
641-
AvailabilityContext OverApproximateContext{
642-
VersionRange::allGTE(getLangOpts().getMinPlatformVersion())};
640+
auto OverApproximateContext =
641+
AvailabilityContext::forDeploymentTarget(Context);
643642

644643
while (DC && loc.isInvalid()) {
645644
const Decl *D = DC->getInnermostDeclarationDeclContext();

0 commit comments

Comments
 (0)