@@ -37,14 +37,27 @@ static bool constrainRange(AvailabilityRange &existing,
3737 return true ;
3838}
3939
40+ static bool constrainUnavailableDomain (
41+ std::optional<AvailabilityDomain> &domain,
42+ const std::optional<AvailabilityDomain> &otherDomain) {
43+ // If the other domain is absent or is the same domain, it's a noop.
44+ if (!otherDomain || domain == otherDomain)
45+ return false ;
46+
47+ // Check if the other domain is a superset and constrain to it if it is.
48+ if (!domain || otherDomain->contains (*domain)) {
49+ domain = otherDomain;
50+ return true ;
51+ }
52+
53+ return false ;
54+ }
55+
4056bool AvailabilityContext::Info::constrainWith (const Info &other) {
4157 bool isConstrained = false ;
4258 isConstrained |= constrainRange (Range, other.Range );
43- if (other.IsUnavailable ) {
44- isConstrained |= constrainUnavailability (other.UnavailablePlatform );
45- isConstrained |=
46- CONSTRAIN_BOOL (IsUnavailableInEmbedded, other.IsUnavailableInEmbedded );
47- }
59+ if (other.UnavailableDomain )
60+ isConstrained |= constrainUnavailability (other.UnavailableDomain );
4861 isConstrained |= CONSTRAIN_BOOL (IsDeprecated, other.IsDeprecated );
4962
5063 return isConstrained;
@@ -56,77 +69,44 @@ bool AvailabilityContext::Info::constrainWith(const Decl *decl) {
5669 if (auto range = AvailabilityInference::annotatedAvailableRange (decl))
5770 isConstrained |= constrainRange (Range, *range);
5871
59- if (auto attr = decl->getUnavailableAttr ()) {
60- isConstrained |= constrainUnavailability (attr->getPlatform ());
61- isConstrained |=
62- CONSTRAIN_BOOL (IsUnavailableInEmbedded, attr->isEmbeddedSpecific ());
63- }
72+ if (auto attr = decl->getUnavailableAttr ())
73+ isConstrained |= constrainUnavailability (attr->getDomain ());
6474
6575 isConstrained |= CONSTRAIN_BOOL (IsDeprecated, decl->isDeprecated ());
6676
6777 return isConstrained;
6878}
6979
7080bool AvailabilityContext::Info::constrainUnavailability (
71- std::optional<PlatformKind> unavailablePlatform) {
72- if (!unavailablePlatform)
73- return false ;
74-
75- if (IsUnavailable) {
76- // Universal unavailability cannot be refined.
77- if (UnavailablePlatform == PlatformKind::none)
78- return false ;
79-
80- // There's nothing to do if the platforms already match.
81- if (UnavailablePlatform == *unavailablePlatform)
82- return false ;
83-
84- // The new platform must be more restrictive.
85- if (*unavailablePlatform != PlatformKind::none &&
86- inheritsAvailabilityFromPlatform (*unavailablePlatform,
87- UnavailablePlatform))
88- return false ;
89- }
90-
91- IsUnavailable = true ;
92- UnavailablePlatform = *unavailablePlatform;
93- return true ;
81+ std::optional<AvailabilityDomain> domain) {
82+ return constrainUnavailableDomain (UnavailableDomain, domain);
9483}
9584
9685bool AvailabilityContext::Info::isContainedIn (const Info &other) const {
86+ // The available versions range be the same or smaller.
9787 if (!Range.isContainedIn (other.Range ))
9888 return false ;
9989
100- if (!IsUnavailable && other.IsUnavailable )
101- return false ;
102-
103- if (IsUnavailable && other.IsUnavailable ) {
104- if (UnavailablePlatform != other.UnavailablePlatform &&
105- UnavailablePlatform != PlatformKind::none &&
106- inheritsAvailabilityFromPlatform (UnavailablePlatform,
107- other.UnavailablePlatform ))
90+ // The set of unavailable domains should be the same or larger.
91+ if (auto otherUnavailableDomain = other.UnavailableDomain ) {
92+ if (!UnavailableDomain)
10893 return false ;
10994
110- if (IsUnavailableInEmbedded && !other. IsUnavailableInEmbedded )
95+ if (!UnavailableDomain-> contains (otherUnavailableDomain. value ()) )
11196 return false ;
11297 }
11398
99+ // The set of deprecated domains should be the same or larger.
114100 if (!IsDeprecated && other.IsDeprecated )
115101 return false ;
116102
117103 return true ;
118104}
119105
120- void AvailabilityContext::Storage::Profile (llvm::FoldingSetNodeID &id) const {
121- info.Profile (id);
122- }
123-
124106AvailabilityContext
125107AvailabilityContext::forPlatformRange (const AvailabilityRange &range,
126108 ASTContext &ctx) {
127- Info info{range, PlatformKind::none,
128- /* IsUnavailable*/ false ,
129- /* IsUnavailableInEmbedded*/ false ,
109+ Info info{range, /* UnavailableDomain*/ std::nullopt ,
130110 /* IsDeprecated*/ false };
131111 return AvailabilityContext (Storage::get (info, ctx));
132112}
@@ -143,29 +123,19 @@ AvailabilityContext AvailabilityContext::forDeploymentTarget(ASTContext &ctx) {
143123
144124AvailabilityContext
145125AvailabilityContext::get (const AvailabilityRange &platformAvailability,
146- std::optional<PlatformKind> unavailablePlatform ,
126+ std::optional<AvailabilityDomain> unavailableDomain ,
147127 bool deprecated, ASTContext &ctx) {
148- Info info{platformAvailability,
149- unavailablePlatform.has_value () ? *unavailablePlatform
150- : PlatformKind::none,
151- unavailablePlatform.has_value (),
152- /* IsUnavailableInEmbedded*/ false , deprecated};
128+ Info info{platformAvailability, unavailableDomain, deprecated};
153129 return AvailabilityContext (Storage::get (info, ctx));
154130}
155131
156132AvailabilityRange AvailabilityContext::getPlatformRange () const {
157133 return storage->info .Range ;
158134}
159135
160- std::optional<PlatformKind>
161- AvailabilityContext::getUnavailablePlatformKind () const {
162- if (storage->info .IsUnavailable )
163- return storage->info .UnavailablePlatform ;
164- return std::nullopt ;
165- }
166-
167- bool AvailabilityContext::isUnavailableInEmbedded () const {
168- return storage->info .IsUnavailableInEmbedded ;
136+ std::optional<AvailabilityDomain>
137+ AvailabilityContext::getUnavailableDomain () const {
138+ return storage->info .UnavailableDomain ;
169139}
170140
171141bool AvailabilityContext::isDeprecated () const {
@@ -233,8 +203,8 @@ stringForAvailability(const AvailabilityRange &availability) {
233203void AvailabilityContext::print (llvm::raw_ostream &os) const {
234204 os << " version=" << stringForAvailability (getPlatformRange ());
235205
236- if (auto unavailablePlatform = getUnavailablePlatformKind ())
237- os << " unavailable=" << platformString (*unavailablePlatform );
206+ if (auto unavailableDomain = getUnavailableDomain ())
207+ os << " unavailable=" << unavailableDomain-> getNameForAttributePrinting ( );
238208
239209 if (isDeprecated ())
240210 os << " deprecated" ;
0 commit comments