@@ -345,6 +345,18 @@ class AvailabilityContext : public llvm::FoldingSetNode {
345345 // / The introduction version.
346346 AvailabilityRange Range;
347347
348+ // / When `IsUnavailable` is true, this value stores the broadest platform
349+ // / kind for which the context is unavailable.
350+ PlatformKind UnavailablePlatform;
351+
352+ // / Whether or not the context is considered unavailable on the current
353+ // / platform.
354+ unsigned IsUnavailable : 1 ;
355+
356+ // / Whether or not the context is considered deprecated on the current
357+ // / platform.
358+ unsigned IsDeprecated : 1 ;
359+
348360 // / Sets `Range` to `other` if `other` is more restrictive. Returns true if
349361 // / any property changed as a result of adding this constraint.
350362 bool constrainRange (const AvailabilityRange &other) {
@@ -360,8 +372,23 @@ class AvailabilityContext : public llvm::FoldingSetNode {
360372 // / any property changed as a result of adding this constraint.
361373 bool constrainRange (const Decl *decl);
362374
375+ // / Updates `UnavailablePlatform` and `IsUnavailable` to reflect the status
376+ // / of `decl` if its platform unavailability is more restrictive. Returns
377+ // / true if any property changed as a result of adding this constraint.
378+ bool constrainUnavailability (const Decl *decl);
379+
380+ // / If `decl` is deprecated, sets `IsDeprecated` to true. Returns true if
381+ // / any property changed as a result of adding this constraint.
382+ bool constrainDeprecated (const Decl *decl);
383+
384+ // / Returns true if `other` is as available or is more available.
385+ bool isContainedIn (const PlatformInfo &other) const ;
386+
363387 void Profile (llvm::FoldingSetNodeID &ID) const {
364388 Range.getRawVersionRange ().Profile (ID);
389+ ID.AddBoolean (IsUnavailable);
390+ ID.AddInteger (static_cast <uint8_t >(UnavailablePlatform));
391+ ID.AddBoolean (IsDeprecated);
365392 }
366393 };
367394 PlatformInfo PlatformAvailability;
@@ -381,8 +408,14 @@ class AvailabilityContext : public llvm::FoldingSetNode {
381408 // / Retrieves a uniqued `AvailabilityContext` with the given platform
382409 // / availability parameters.
383410 static const AvailabilityContext *
384- get (const AvailabilityRange &platformAvailability, ASTContext &ctx) {
385- PlatformInfo platformInfo{platformAvailability};
411+ get (const AvailabilityRange &platformAvailability,
412+ std::optional<PlatformKind> unavailablePlatform, bool deprecated,
413+ ASTContext &ctx) {
414+ PlatformInfo platformInfo{platformAvailability,
415+ unavailablePlatform.has_value ()
416+ ? *unavailablePlatform
417+ : PlatformKind::none,
418+ unavailablePlatform.has_value (), deprecated};
386419 return get (platformInfo, ctx);
387420 }
388421
@@ -392,6 +425,18 @@ class AvailabilityContext : public llvm::FoldingSetNode {
392425 return PlatformAvailability.Range ;
393426 }
394427
428+ // / When the context is unavailable on the current platform this returns the
429+ // / broadest `PlatformKind` for which the context is unavailable. Otherwise,
430+ // / returns `nullopt`.
431+ std::optional<PlatformKind> getUnavailablePlatformKind () const {
432+ if (PlatformAvailability.IsUnavailable )
433+ return PlatformAvailability.UnavailablePlatform ;
434+ return std::nullopt ;
435+ }
436+
437+ // / Returns true if this context is deprecated on the current platform.
438+ bool isDeprecated () const { return PlatformAvailability.IsDeprecated ; }
439+
395440 // / Returns the unique context that is the result of constraining the current
396441 // / context's platform availability range with `platformRange`.
397442 const AvailabilityContext *
@@ -404,6 +449,12 @@ class AvailabilityContext : public llvm::FoldingSetNode {
404449 const AvailabilityContext *constrainWithDeclAndPlatformRange (
405450 Decl *decl, const AvailabilityRange &platformRange) const ;
406451
452+ // / Returns true if `other` is as available or is more available.
453+ bool isContainedIn (const AvailabilityContext *other) const ;
454+
455+ void print (llvm::raw_ostream &os) const ;
456+ SWIFT_DEBUG_DUMP;
457+
407458 void Profile (llvm::FoldingSetNodeID &ID) const ;
408459};
409460
0 commit comments