Skip to content

Commit 02dbb96

Browse files
committed
AST: Rename AvailabilityContext to AvailabilityRange.
The generality of the `AvailabilityContext` name made it seem like it encapsulates more than it does. Really it just augments `VersionRange` with additional set algebra operations that are useful for availability computations. The `AvailabilityContext` name should be reserved for something pulls together more than just a single version.
1 parent 732de44 commit 02dbb96

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+362
-387
lines changed

include/swift/AST/ASTContext.h

+25-25
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ namespace swift {
6969
class AbstractFunctionDecl;
7070
class ASTContext;
7171
enum class Associativity : unsigned char;
72-
class AvailabilityContext;
72+
class AvailabilityRange;
7373
class BoundGenericType;
7474
class BuiltinTupleDecl;
7575
class ClangModuleLoader;
@@ -870,25 +870,25 @@ class ASTContext final {
870870

871871
/// Get the availability of features introduced in the specified version
872872
/// of the Swift compiler for the target platform.
873-
AvailabilityContext getSwiftAvailability(unsigned major, unsigned minor) const;
873+
AvailabilityRange getSwiftAvailability(unsigned major, unsigned minor) const;
874874

875875
// For each feature defined in FeatureAvailability, define two functions;
876876
// the latter, with the suffix RuntimeAvailabilty, is for use with
877-
// AvailabilityContext::forRuntimeTarget(), and only looks at the Swift
877+
// AvailabilityRange::forRuntimeTarget(), and only looks at the Swift
878878
// runtime version.
879-
#define FEATURE(N, V) \
880-
inline AvailabilityContext get##N##Availability() const { \
881-
return getSwiftAvailability V; \
882-
} \
883-
inline AvailabilityContext get##N##RuntimeAvailability() const { \
884-
return AvailabilityContext(VersionRange::allGTE(llvm::VersionTuple V)); \
879+
#define FEATURE(N, V) \
880+
inline AvailabilityRange get##N##Availability() const { \
881+
return getSwiftAvailability V; \
882+
} \
883+
inline AvailabilityRange get##N##RuntimeAvailability() const { \
884+
return AvailabilityRange(VersionRange::allGTE(llvm::VersionTuple V)); \
885885
}
886886

887-
#include "swift/AST/FeatureAvailability.def"
887+
#include "swift/AST/FeatureAvailability.def"
888888

889889
/// Get the runtime availability of features that have been introduced in the
890890
/// Swift compiler for future versions of the target platform.
891-
AvailabilityContext getSwiftFutureAvailability() const;
891+
AvailabilityRange getSwiftFutureAvailability() const;
892892

893893
/// Returns `true` if versioned availability annotations are supported for the
894894
/// target triple.
@@ -903,86 +903,86 @@ class ASTContext final {
903903

904904
/// Get the runtime availability of features introduced in the Swift 5.0
905905
/// compiler for the target platform.
906-
inline AvailabilityContext getSwift50Availability() const {
906+
inline AvailabilityRange getSwift50Availability() const {
907907
return getSwiftAvailability(5, 0);
908908
}
909909

910910
/// Get the runtime availability of features introduced in the Swift 5.1
911911
/// compiler for the target platform.
912-
inline AvailabilityContext getSwift51Availability() const {
912+
inline AvailabilityRange getSwift51Availability() const {
913913
return getSwiftAvailability(5, 1);
914914
}
915915

916916
/// Get the runtime availability of features introduced in the Swift 5.2
917917
/// compiler for the target platform.
918-
inline AvailabilityContext getSwift52Availability() const {
918+
inline AvailabilityRange getSwift52Availability() const {
919919
return getSwiftAvailability(5, 2);
920920
}
921921

922922
/// Get the runtime availability of features introduced in the Swift 5.3
923923
/// compiler for the target platform.
924-
inline AvailabilityContext getSwift53Availability() const {
924+
inline AvailabilityRange getSwift53Availability() const {
925925
return getSwiftAvailability(5, 3);
926926
}
927927

928928
/// Get the runtime availability of features introduced in the Swift 5.4
929929
/// compiler for the target platform.
930-
inline AvailabilityContext getSwift54Availability() const {
930+
inline AvailabilityRange getSwift54Availability() const {
931931
return getSwiftAvailability(5, 4);
932932
}
933933

934934
/// Get the runtime availability of features introduced in the Swift 5.5
935935
/// compiler for the target platform.
936-
inline AvailabilityContext getSwift55Availability() const {
936+
inline AvailabilityRange getSwift55Availability() const {
937937
return getSwiftAvailability(5, 5);
938938
}
939939

940940
/// Get the runtime availability of features introduced in the Swift 5.6
941941
/// compiler for the target platform.
942-
inline AvailabilityContext getSwift56Availability() const {
942+
inline AvailabilityRange getSwift56Availability() const {
943943
return getSwiftAvailability(5, 6);
944944
}
945945

946946
/// Get the runtime availability of features introduced in the Swift 5.7
947947
/// compiler for the target platform.
948-
inline AvailabilityContext getSwift57Availability() const {
948+
inline AvailabilityRange getSwift57Availability() const {
949949
return getSwiftAvailability(5, 7);
950950
}
951951

952952
/// Get the runtime availability of features introduced in the Swift 5.8
953953
/// compiler for the target platform.
954-
inline AvailabilityContext getSwift58Availability() const {
954+
inline AvailabilityRange getSwift58Availability() const {
955955
return getSwiftAvailability(5, 8);
956956
}
957957

958958
/// Get the runtime availability of features introduced in the Swift 5.9
959959
/// compiler for the target platform.
960-
inline AvailabilityContext getSwift59Availability() const {
960+
inline AvailabilityRange getSwift59Availability() const {
961961
return getSwiftAvailability(5, 9);
962962
}
963963

964964
/// Get the runtime availability of features introduced in the Swift 5.10
965965
/// compiler for the target platform.
966-
inline AvailabilityContext getSwift510Availability() const {
966+
inline AvailabilityRange getSwift510Availability() const {
967967
return getSwiftAvailability(5, 10);
968968
}
969969

970970
/// Get the runtime availability of features introduced in the Swift 6.0
971971
/// compiler for the target platform.
972-
inline AvailabilityContext getSwift60Availability() const {
972+
inline AvailabilityRange getSwift60Availability() const {
973973
return getSwiftAvailability(6, 0);
974974
}
975975

976976
/// Get the runtime availability for a particular version of Swift (5.0+).
977-
inline AvailabilityContext
977+
inline AvailabilityRange
978978
getSwift5PlusAvailability(llvm::VersionTuple swiftVersion) const {
979979
return getSwiftAvailability(swiftVersion.getMajor(),
980980
*swiftVersion.getMinor());
981981
}
982982

983983
/// Get the runtime availability of getters and setters of multi payload enum
984984
/// tag single payloads.
985-
inline AvailabilityContext getMultiPayloadEnumTagSinglePayload() const {
985+
inline AvailabilityRange getMultiPayloadEnumTagSinglePayload() const {
986986
// This didn't fit the pattern, so needed renaming
987987
return getMultiPayloadEnumTagSinglePayloadAvailability();
988988
}

include/swift/AST/Availability.h

+24-24
Original file line numberDiff line numberDiff line change
@@ -196,45 +196,45 @@ class VersionRange {
196196

197197
/// Represents a version range in which something is available.
198198
///
199-
/// The AvailabilityContext structure forms a [lattice][], which allows it to
199+
/// The AvailabilityRange structure forms a [lattice][], which allows it to
200200
/// have meaningful union and intersection operations ("join" and "meet"),
201201
/// which use conservative approximations to prevent availability violations.
202202
/// See #unionWith, #intersectWith, and #constrainWith.
203203
///
204204
/// [lattice]: http://mathworld.wolfram.com/Lattice.html
205205
///
206206
/// NOTE: Generally you should use the utilities on \c AvailabilityInference
207-
/// to create an \c AvailabilityContext, rather than creating one directly.
208-
class AvailabilityContext {
207+
/// to create an \c AvailabilityRange, rather than creating one directly.
208+
class AvailabilityRange {
209209
VersionRange Range;
210210

211211
public:
212-
explicit AvailabilityContext(VersionRange Range) : Range(Range) {}
212+
explicit AvailabilityRange(VersionRange Range) : Range(Range) {}
213213

214214
/// Creates a context that imposes the constraints of the ASTContext's
215215
/// deployment target.
216-
static AvailabilityContext forDeploymentTarget(const ASTContext &Ctx);
216+
static AvailabilityRange forDeploymentTarget(const ASTContext &Ctx);
217217

218218
/// Creates a context that imposes the constraints of the ASTContext's
219219
/// inlining target (i.e. minimum inlining version).
220-
static AvailabilityContext forInliningTarget(const ASTContext &Ctx);
220+
static AvailabilityRange forInliningTarget(const ASTContext &Ctx);
221221

222222
/// Creates a context that imposes the constraints of the ASTContext's
223223
/// minimum runtime version.
224-
static AvailabilityContext forRuntimeTarget(const ASTContext &Ctx);
224+
static AvailabilityRange forRuntimeTarget(const ASTContext &Ctx);
225225

226226
/// Creates a context that imposes no constraints.
227227
///
228228
/// \see isAlwaysAvailable
229-
static AvailabilityContext alwaysAvailable() {
230-
return AvailabilityContext(VersionRange::all());
229+
static AvailabilityRange alwaysAvailable() {
230+
return AvailabilityRange(VersionRange::all());
231231
}
232232

233233
/// Creates a context that can never actually occur.
234234
///
235235
/// \see isKnownUnreachable
236-
static AvailabilityContext neverAvailable() {
237-
return AvailabilityContext(VersionRange::empty());
236+
static AvailabilityRange neverAvailable() {
237+
return AvailabilityRange(VersionRange::empty());
238238
}
239239

240240
/// Returns the range of possible versions required by this context.
@@ -245,7 +245,7 @@ class AvailabilityContext {
245245

246246
/// Returns the minimum version required by this context. This convenience
247247
/// is meant for debugging, diagnostics, serialization, etc. Use of the set
248-
/// algebra operations on `AvailabilityContext` should be preferred over
248+
/// algebra operations on `AvailabilityRange` should be preferred over
249249
/// direct comparison of raw versions.
250250
///
251251
/// Only call when `hasMinimumVersion()` returns true.
@@ -256,14 +256,14 @@ class AvailabilityContext {
256256
/// Returns true if \p other makes stronger guarantees than this context.
257257
///
258258
/// That is, `a.isContainedIn(b)` implies `a.union(b) == b`.
259-
bool isContainedIn(const AvailabilityContext &other) const {
259+
bool isContainedIn(const AvailabilityRange &other) const {
260260
return Range.isContainedIn(other.Range);
261261
}
262262

263263
/// Returns true if \p other is a strict subset of this context.
264264
///
265265
/// That is, `a.isSupersetOf(b)` implies `a != b` and `a.union(b) == a`.
266-
bool isSupersetOf(const AvailabilityContext &other) const {
266+
bool isSupersetOf(const AvailabilityRange &other) const {
267267
return Range.isSupersetOf(other.Range);
268268
}
269269

@@ -291,7 +291,7 @@ class AvailabilityContext {
291291
///
292292
/// As an example, this is used when figuring out the required availability
293293
/// for a type that references multiple nominal decls.
294-
void intersectWith(const AvailabilityContext &other) {
294+
void intersectWith(const AvailabilityRange &other) {
295295
Range.intersectWith(other.Range);
296296
}
297297

@@ -302,7 +302,7 @@ class AvailabilityContext {
302302
/// treating some invalid deployment environments as available.
303303
///
304304
/// As an example, this is used for the true branch of `#available`.
305-
void constrainWith(const AvailabilityContext &other) {
305+
void constrainWith(const AvailabilityRange &other) {
306306
Range.constrainWith(other.Range);
307307
}
308308

@@ -314,13 +314,13 @@ class AvailabilityContext {
314314
///
315315
/// As an example, this is used for the else branch of a conditional with
316316
/// multiple `#available` checks.
317-
void unionWith(const AvailabilityContext &other) {
317+
void unionWith(const AvailabilityRange &other) {
318318
Range.unionWith(other.Range);
319319
}
320320

321321
/// Returns a representation of this range as a string for debugging purposes.
322322
std::string getAsString() const {
323-
return "AvailabilityContext(" + getVersionString() + ")";
323+
return "AvailabilityRange(" + getVersionString() + ")";
324324
}
325325

326326
/// Returns a representation of the raw version range as a string for
@@ -345,11 +345,11 @@ class AvailabilityInference {
345345
ArrayRef<const Decl *> InferredFromDecls,
346346
ASTContext &Context);
347347

348-
static AvailabilityContext inferForType(Type t);
348+
static AvailabilityRange inferForType(Type t);
349349

350350
/// Returns the context where a declaration is available
351351
/// We assume a declaration without an annotation is always available.
352-
static AvailabilityContext availableRange(const Decl *D, ASTContext &C);
352+
static AvailabilityRange availableRange(const Decl *D, ASTContext &C);
353353

354354
/// Returns true is the declaration is `@_spi_available`.
355355
static bool isAvailableAsSPI(const Decl *D, ASTContext &C);
@@ -358,8 +358,8 @@ class AvailabilityInference {
358358
/// @available attribute.
359359
///
360360
/// NOTE: The attribute must be active on the current platform.
361-
static AvailabilityContext availableRange(const AvailableAttr *attr,
362-
ASTContext &C);
361+
static AvailabilityRange availableRange(const AvailableAttr *attr,
362+
ASTContext &C);
363363

364364
/// Returns the attribute that should be used to determine the availability
365365
/// range of the given declaration, or nullptr if there is none.
@@ -369,10 +369,10 @@ class AvailabilityInference {
369369
/// Returns the context for which the declaration
370370
/// is annotated as available, or None if the declaration
371371
/// has no availability annotation.
372-
static std::optional<AvailabilityContext>
372+
static std::optional<AvailabilityRange>
373373
annotatedAvailableRange(const Decl *D, ASTContext &C);
374374

375-
static AvailabilityContext
375+
static AvailabilityRange
376376
annotatedAvailableRangeForAttr(const SpecializeAttr *attr, ASTContext &ctx);
377377

378378
/// For the attribute's introduction version, update the platform and version

include/swift/AST/Decl.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ namespace swift {
6464
enum class AccessSemantics : unsigned char;
6565
class AccessorDecl;
6666
class ApplyExpr;
67-
class AvailabilityContext;
67+
class AvailabilityRange;
6868
class GenericEnvironment;
6969
class ArchetypeType;
7070
class ASTContext;
@@ -1326,7 +1326,7 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
13261326
return getAttrs().hasAttribute<NoImplicitCopyAttr>();
13271327
}
13281328

1329-
AvailabilityContext getAvailabilityForLinkage() const;
1329+
AvailabilityRange getAvailabilityForLinkage() const;
13301330

13311331
/// Whether this declaration or one of its outer contexts has the
13321332
/// @_weakLinked attribute.

include/swift/AST/RequirementMatch.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -255,19 +255,19 @@ struct RequirementCheck {
255255

256256
/// The required availability, if the check failed due to the
257257
/// witness being less available than the requirement.
258-
AvailabilityContext RequiredAvailability;
258+
AvailabilityRange RequiredAvailability;
259259

260260
RequirementCheck(CheckKind kind)
261-
: Kind(kind), RequiredAccessScope(AccessScope::getPublic()),
262-
RequiredAvailability(AvailabilityContext::alwaysAvailable()) { }
261+
: Kind(kind), RequiredAccessScope(AccessScope::getPublic()),
262+
RequiredAvailability(AvailabilityRange::alwaysAvailable()) {}
263263

264264
RequirementCheck(CheckKind kind, AccessScope requiredAccessScope)
265-
: Kind(kind), RequiredAccessScope(requiredAccessScope),
266-
RequiredAvailability(AvailabilityContext::alwaysAvailable()) { }
265+
: Kind(kind), RequiredAccessScope(requiredAccessScope),
266+
RequiredAvailability(AvailabilityRange::alwaysAvailable()) {}
267267

268-
RequirementCheck(CheckKind kind, AvailabilityContext requiredAvailability)
269-
: Kind(kind), RequiredAccessScope(AccessScope::getPublic()),
270-
RequiredAvailability(requiredAvailability) { }
268+
RequirementCheck(CheckKind kind, AvailabilityRange requiredAvailability)
269+
: Kind(kind), RequiredAccessScope(AccessScope::getPublic()),
270+
RequiredAvailability(requiredAvailability) {}
271271
};
272272

273273

0 commit comments

Comments
 (0)