Skip to content

Commit 8052e3f

Browse files
committed
AST: Remove 'OS' from AvailabilityContext member names.
An `AvailabilityContext` represents an abstract version range in which something is available. In the future, these version ranges may not necessarily always correspond to operating system version ranges. NFC.
1 parent 018234f commit 8052e3f

File tree

11 files changed

+47
-47
lines changed

11 files changed

+47
-47
lines changed

include/swift/AST/Availability.h

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,7 @@ class UnavailabilityReason {
216216
bool requiresDeploymentTargetOrEarlier(ASTContext &Ctx) const;
217217
};
218218

219-
/// Represents everything that a particular chunk of code may assume about its
220-
/// runtime environment.
219+
/// Represents a version range in which something is available.
221220
///
222221
/// The AvailabilityContext structure forms a [lattice][], which allows it to
223222
/// have meaningful union and intersection operations ("join" and "meet"),
@@ -229,11 +228,10 @@ class UnavailabilityReason {
229228
/// NOTE: Generally you should use the utilities on \c AvailabilityInference
230229
/// to create an \c AvailabilityContext, rather than creating one directly.
231230
class AvailabilityContext {
232-
VersionRange OSVersion;
231+
VersionRange Range;
233232

234233
public:
235-
/// Creates a context that requires certain versions of the target OS.
236-
explicit AvailabilityContext(VersionRange OSVersion) : OSVersion(OSVersion) {}
234+
explicit AvailabilityContext(VersionRange Range) : Range(Range) {}
237235

238236
/// Creates a context that imposes the constraints of the ASTContext's
239237
/// deployment target.
@@ -261,21 +259,21 @@ class AvailabilityContext {
261259
return AvailabilityContext(VersionRange::empty());
262260
}
263261

264-
/// Returns the range of possible OS versions required by this context.
265-
VersionRange getOSVersion() const { return OSVersion; }
262+
/// Returns the range of possible versions required by this context.
263+
VersionRange getVersionRange() const { return Range; }
266264

267265
/// Returns true if \p other makes stronger guarantees than this context.
268266
///
269267
/// That is, `a.isContainedIn(b)` implies `a.union(b) == b`.
270268
bool isContainedIn(const AvailabilityContext &other) const {
271-
return OSVersion.isContainedIn(other.OSVersion);
269+
return Range.isContainedIn(other.Range);
272270
}
273271

274272
/// Returns true if \p other is a strict subset of this context.
275273
///
276274
/// That is, `a.isSupersetOf(b)` implies `a != b` and `a.union(b) == a`.
277275
bool isSupersetOf(const AvailabilityContext &other) const {
278-
return OSVersion.isSupersetOf(other.OSVersion);
276+
return Range.isSupersetOf(other.Range);
279277
}
280278

281279
/// Returns true if this context has constraints that make it impossible to
@@ -284,13 +282,13 @@ class AvailabilityContext {
284282
/// For example, the else branch of a `#available` check for iOS 8.0 when the
285283
/// containing function already requires iOS 9.
286284
bool isKnownUnreachable() const {
287-
return OSVersion.isEmpty();
285+
return Range.isEmpty();
288286
}
289287

290288
/// Returns true if there are no constraints on this context; that is,
291289
/// nothing can be assumed.
292290
bool isAlwaysAvailable() const {
293-
return OSVersion.isAll();
291+
return Range.isAll();
294292
}
295293

296294
/// Produces an under-approximation of the intersection of the two
@@ -303,7 +301,7 @@ class AvailabilityContext {
303301
/// As an example, this is used when figuring out the required availability
304302
/// for a type that references multiple nominal decls.
305303
void intersectWith(const AvailabilityContext &other) {
306-
OSVersion.intersectWith(other.getOSVersion());
304+
Range.intersectWith(other.Range);
307305
}
308306

309307
/// Produces an over-approximation of the intersection of the two
@@ -314,7 +312,7 @@ class AvailabilityContext {
314312
///
315313
/// As an example, this is used for the true branch of `#available`.
316314
void constrainWith(const AvailabilityContext &other) {
317-
OSVersion.constrainWith(other.getOSVersion());
315+
Range.constrainWith(other.Range);
318316
}
319317

320318
/// Produces an over-approximation of the union of two availability contexts.
@@ -326,12 +324,12 @@ class AvailabilityContext {
326324
/// As an example, this is used for the else branch of a conditional with
327325
/// multiple `#available` checks.
328326
void unionWith(const AvailabilityContext &other) {
329-
OSVersion.unionWith(other.getOSVersion());
327+
Range.unionWith(other.Range);
330328
}
331329

332330
/// Returns a representation of this range as a string for debugging purposes.
333331
std::string getAsString() const {
334-
return "AvailabilityContext(" + OSVersion.getAsString() + ")";
332+
return "AvailabilityContext(" + Range.getAsString() + ")";
335333
}
336334
};
337335

lib/AST/Availability.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ bool UnavailabilityReason::requiresDeploymentTargetOrEarlier(
521521
ASTContext &Ctx) const {
522522
return RequiredDeploymentRange.getLowerEndpoint() <=
523523
AvailabilityContext::forDeploymentTarget(Ctx)
524-
.getOSVersion()
524+
.getVersionRange()
525525
.getLowerEndpoint();
526526
}
527527

lib/AST/TypeRefinementContext.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ void TypeRefinementContext::print(raw_ostream &OS, SourceManager &SrcMgr,
365365
OS.indent(Indent);
366366
OS << "(" << getReasonName(getReason());
367367

368-
OS << " versions=" << AvailabilityInfo.getOSVersion().getAsString();
368+
OS << " versions=" << AvailabilityInfo.getVersionRange().getAsString();
369369

370370
if (getReason() == Reason::Decl || getReason() == Reason::DeclImplicit) {
371371
Decl *D = Node.getAsDecl();
@@ -391,7 +391,7 @@ void TypeRefinementContext::print(raw_ostream &OS, SourceManager &SrcMgr,
391391

392392
if (!ExplicitAvailabilityInfo.isAlwaysAvailable())
393393
OS << " explicit_versions="
394-
<< ExplicitAvailabilityInfo.getOSVersion().getAsString();
394+
<< ExplicitAvailabilityInfo.getVersionRange().getAsString();
395395

396396
for (TypeRefinementContext *Child : Children) {
397397
OS << '\n';

lib/ClangImporter/ImportDecl.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ static void applyAvailableAttribute(Decl *decl, AvailabilityContext &info,
541541
/*Message=*/StringRef(),
542542
/*Rename=*/StringRef(),
543543
/*RenameDecl=*/nullptr,
544-
info.getOSVersion().getLowerEndpoint(),
544+
info.getVersionRange().getLowerEndpoint(),
545545
/*IntroducedRange*/SourceRange(),
546546
/*Deprecated=*/noVersion,
547547
/*DeprecatedRange*/SourceRange(),
@@ -2800,11 +2800,11 @@ namespace {
28002800

28012801
auto ctx = Impl.SwiftContext.getSwift58Availability();
28022802
if (!ctx.isAlwaysAvailable()) {
2803-
assert(ctx.getOSVersion().hasLowerEndpoint());
2803+
assert(ctx.getVersionRange().hasLowerEndpoint());
28042804
auto AvAttr = new (Impl.SwiftContext) AvailableAttr(
28052805
SourceLoc(), SourceRange(),
28062806
targetPlatform(Impl.SwiftContext.LangOpts), "", "",
2807-
/*RenameDecl=*/nullptr, ctx.getOSVersion().getLowerEndpoint(),
2807+
/*RenameDecl=*/nullptr, ctx.getVersionRange().getLowerEndpoint(),
28082808
/*IntroducedRange=*/SourceRange(), {},
28092809
/*DeprecatedRange=*/SourceRange(), {},
28102810
/*ObsoletedRange=*/SourceRange(),
@@ -6615,7 +6615,7 @@ bool SwiftDeclConverter::existingConstructorIsWorse(
66156615
if (!introduced.empty())
66166616
return false;
66176617
} else {
6618-
VersionRange existingIntroduced = existingAvailability.getOSVersion();
6618+
VersionRange existingIntroduced = existingAvailability.getVersionRange();
66196619
if (introduced != existingIntroduced.getLowerEndpoint()) {
66206620
return introduced < existingIntroduced.getLowerEndpoint();
66216621
}

lib/IRGen/GenMeta.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5116,8 +5116,8 @@ diagnoseUnsupportedObjCImplLayout(IRGenModule &IGM, ClassDecl *classDecl,
51165116
field.getVarDecl(),
51175117
diag::attr_objc_implementation_resilient_property_deployment_target,
51185118
prettyPlatformString(targetPlatform(ctx.LangOpts)),
5119-
currentAvailability.getOSVersion().getLowerEndpoint(),
5120-
requiredAvailability.getOSVersion().getLowerEndpoint());
5119+
currentAvailability.getVersionRange().getLowerEndpoint(),
5120+
requiredAvailability.getVersionRange().getLowerEndpoint());
51215121
else
51225122
diags.diagnose(
51235123
field.getVarDecl(),

lib/SIL/IR/SILPrinter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3438,7 +3438,7 @@ void SILFunction::print(SILPrintContext &PrintCtx) const {
34383438
OS << "[weak_imported] ";
34393439
auto availability = getAvailabilityForLinkage();
34403440
if (!availability.isAlwaysAvailable()) {
3441-
auto version = availability.getOSVersion().getLowerEndpoint();
3441+
auto version = availability.getVersionRange().getLowerEndpoint();
34423442
OS << "[available " << version.getAsString() << "] ";
34433443
}
34443444

@@ -4409,8 +4409,8 @@ void SILSpecializeAttr::print(llvm::raw_ostream &OS) const {
44094409
if (targetFunction) {
44104410
OS << "target: \"" << targetFunction->getName() << "\", ";
44114411
}
4412-
if (!availability.isAlwaysAvailable()) {
4413-
auto version = availability.getOSVersion().getLowerEndpoint();
4412+
if (!availability.isAlwaysAvailable()) {
4413+
auto version = availability.getVersionRange().getLowerEndpoint();
44144414
OS << "available: " << version.getAsString() << ", ";
44154415
}
44164416
if (!requirements.empty()) {

lib/Sema/TypeCheckAttr.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,10 +1681,11 @@ visitObjCImplementationAttr(ObjCImplementationAttr *attr) {
16811681
// supported.
16821682
auto deploymentAvailability = AvailabilityContext::forDeploymentTarget(Ctx);
16831683
if (!deploymentAvailability.isContainedIn(Ctx.getSwift50Availability())) {
1684-
auto diag = diagnose(attr->getLocation(),
1685-
diag::attr_objc_implementation_raise_minimum_deployment_target,
1686-
prettyPlatformString(targetPlatform(Ctx.LangOpts)),
1687-
Ctx.getSwift50Availability().getOSVersion().getLowerEndpoint());
1684+
auto diag = diagnose(
1685+
attr->getLocation(),
1686+
diag::attr_objc_implementation_raise_minimum_deployment_target,
1687+
prettyPlatformString(targetPlatform(Ctx.LangOpts)),
1688+
Ctx.getSwift50Availability().getVersionRange().getLowerEndpoint());
16881689
if (attr->isEarlyAdopter()) {
16891690
diag.wrapIn(diag::wrap_objc_implementation_will_become_error);
16901691
}
@@ -2209,11 +2210,11 @@ void AttributeChecker::visitAvailableAttr(AvailableAttr *attr) {
22092210
diag::availability_implicit_decl_here,
22102211
D->getDescriptiveKind(),
22112212
prettyPlatformString(targetPlatform(Ctx.LangOpts)),
2212-
AttrRange.getOSVersion().getLowerEndpoint());
2213+
AttrRange.getVersionRange().getLowerEndpoint());
22132214
diagnose(enclosingDecl->getLoc(),
22142215
diag::availability_decl_more_than_enclosing_here,
22152216
prettyPlatformString(targetPlatform(Ctx.LangOpts)),
2216-
EnclosingAnnotatedRange->getOSVersion().getLowerEndpoint());
2217+
EnclosingAnnotatedRange->getVersionRange().getLowerEndpoint());
22172218
}
22182219
}
22192220
}

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,7 +1119,7 @@ class TypeRefinementContextBuilder : private ASTWalker {
11191119
}
11201120

11211121
AvailabilityContext NewConstraint = contextForSpec(Spec, false);
1122-
Query->setAvailableRange(contextForSpec(Spec, true).getOSVersion());
1122+
Query->setAvailableRange(contextForSpec(Spec, true).getVersionRange());
11231123

11241124
// When compiling zippered for macCatalyst, we need to collect both
11251125
// a macOS version (the target version) and an iOS/macCatalyst version
@@ -1130,7 +1130,7 @@ class TypeRefinementContextBuilder : private ASTWalker {
11301130
AvailabilitySpec *VariantSpec =
11311131
bestActiveSpecForQuery(Query, /*ForTargetVariant*/ true);
11321132
VersionRange VariantRange =
1133-
contextForSpec(VariantSpec, true).getOSVersion();
1133+
contextForSpec(VariantSpec, true).getVersionRange();
11341134
Query->setVariantAvailableRange(VariantRange);
11351135
}
11361136

@@ -1474,7 +1474,7 @@ TypeChecker::checkDeclarationAvailability(const Decl *D,
14741474
AvailabilityContext safeRangeUnderApprox{
14751475
AvailabilityInference::availableRange(D, Context)};
14761476

1477-
VersionRange version = safeRangeUnderApprox.getOSVersion();
1477+
VersionRange version = safeRangeUnderApprox.getVersionRange();
14781478
return UnavailabilityReason::requiresVersionRange(version);
14791479
}
14801480

@@ -1921,7 +1921,8 @@ static bool fixAvailabilityByNarrowingNearbyVersionCheck(
19211921
ReferenceDC, &TRC);
19221922
if (!TRC)
19231923
return false;
1924-
VersionRange RunningRange = TRC->getExplicitAvailabilityInfo().getOSVersion();
1924+
VersionRange RunningRange =
1925+
TRC->getExplicitAvailabilityInfo().getVersionRange();
19251926
if (RunningRange.hasLowerEndpoint() &&
19261927
RequiredRange.hasLowerEndpoint() &&
19271928
TRC->getReason() != TypeRefinementContext::Reason::Root &&
@@ -2100,9 +2101,9 @@ bool TypeChecker::checkAvailability(SourceRange ReferenceRange,
21002101
TypeChecker::overApproximateAvailabilityAtLocation(
21012102
ReferenceRange.Start, ReferenceDC);
21022103
if (!runningOS.isContainedIn(Availability)) {
2103-
diagnosePotentialUnavailability(
2104-
ReferenceRange, Diag, ReferenceDC,
2105-
UnavailabilityReason::requiresVersionRange(Availability.getOSVersion()));
2104+
diagnosePotentialUnavailability(ReferenceRange, Diag, ReferenceDC,
2105+
UnavailabilityReason::requiresVersionRange(
2106+
Availability.getVersionRange()));
21062107
return true;
21072108
}
21082109

@@ -4634,7 +4635,7 @@ static bool declNeedsExplicitAvailability(const Decl *decl) {
46344635

46354636
// Warn on decls without an introduction version.
46364637
auto safeRangeUnderApprox = AvailabilityInference::availableRange(decl, ctx);
4637-
return !safeRangeUnderApprox.getOSVersion().hasLowerEndpoint();
4638+
return !safeRangeUnderApprox.getVersionRange().hasLowerEndpoint();
46384639
}
46394640

46404641
void swift::checkExplicitAvailability(Decl *decl) {

lib/Sema/TypeCheckDeclObjC.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,11 +521,11 @@ static bool checkObjCClassStubAvailability(ASTContext &ctx, const Decl *decl) {
521521
auto minRange = getMinOSVersionForClassStubs(ctx.LangOpts.Target);
522522

523523
auto targetRange = AvailabilityContext::forDeploymentTarget(ctx);
524-
if (targetRange.getOSVersion().isContainedIn(minRange))
524+
if (targetRange.getVersionRange().isContainedIn(minRange))
525525
return true;
526526

527527
auto declRange = AvailabilityInference::availableRange(decl, ctx);
528-
return declRange.getOSVersion().isContainedIn(minRange);
528+
return declRange.getVersionRange().isContainedIn(minRange);
529529
}
530530

531531
static const ClassDecl *getResilientAncestor(ModuleDecl *mod,

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4316,7 +4316,7 @@ ConformanceChecker::resolveWitnessViaLookup(ValueDecl *requirement) {
43164316
diagLoc, diag::availability_protocol_requires_version,
43174317
conformance->getProtocol(), witness,
43184318
prettyPlatformString(targetPlatform(ctx.LangOpts)),
4319-
check.RequiredAvailability.getOSVersion().getLowerEndpoint());
4319+
check.RequiredAvailability.getVersionRange().getLowerEndpoint());
43204320
emitDeclaredHereIfNeeded(diags, diagLoc, witness);
43214321
diags.diagnose(requirement,
43224322
diag::availability_protocol_requirement_here);
@@ -4821,7 +4821,7 @@ static bool diagnoseTypeWitnessAvailability(
48214821
if (!TypeChecker::isAvailabilitySafeForConformance(conformance->getProtocol(),
48224822
assocType, witness, dc,
48234823
requiredAvailability)) {
4824-
auto requiredRange = requiredAvailability.getOSVersion();
4824+
auto requiredRange = requiredAvailability.getVersionRange();
48254825
ctx.addDelayedConformanceDiag(
48264826
conformance, shouldError,
48274827
[witness, requiredRange](NormalProtocolConformance *conformance) {

0 commit comments

Comments
 (0)