@@ -37,14 +37,27 @@ static bool constrainRange(AvailabilityRange &existing,
37
37
return true ;
38
38
}
39
39
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
+
40
56
bool AvailabilityContext::Info::constrainWith (const Info &other) {
41
57
bool isConstrained = false ;
42
58
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 );
48
61
isConstrained |= CONSTRAIN_BOOL (IsDeprecated, other.IsDeprecated );
49
62
50
63
return isConstrained;
@@ -56,77 +69,44 @@ bool AvailabilityContext::Info::constrainWith(const Decl *decl) {
56
69
if (auto range = AvailabilityInference::annotatedAvailableRange (decl))
57
70
isConstrained |= constrainRange (Range, *range);
58
71
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 ());
64
74
65
75
isConstrained |= CONSTRAIN_BOOL (IsDeprecated, decl->isDeprecated ());
66
76
67
77
return isConstrained;
68
78
}
69
79
70
80
bool 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);
94
83
}
95
84
96
85
bool AvailabilityContext::Info::isContainedIn (const Info &other) const {
86
+ // The available versions range be the same or smaller.
97
87
if (!Range.isContainedIn (other.Range ))
98
88
return false ;
99
89
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)
108
93
return false ;
109
94
110
- if (IsUnavailableInEmbedded && !other. IsUnavailableInEmbedded )
95
+ if (!UnavailableDomain-> contains (otherUnavailableDomain. value ()) )
111
96
return false ;
112
97
}
113
98
99
+ // The set of deprecated domains should be the same or larger.
114
100
if (!IsDeprecated && other.IsDeprecated )
115
101
return false ;
116
102
117
103
return true ;
118
104
}
119
105
120
- void AvailabilityContext::Storage::Profile (llvm::FoldingSetNodeID &id) const {
121
- info.Profile (id);
122
- }
123
-
124
106
AvailabilityContext
125
107
AvailabilityContext::forPlatformRange (const AvailabilityRange &range,
126
108
ASTContext &ctx) {
127
- Info info{range, PlatformKind::none,
128
- /* IsUnavailable*/ false ,
129
- /* IsUnavailableInEmbedded*/ false ,
109
+ Info info{range, /* UnavailableDomain*/ std::nullopt ,
130
110
/* IsDeprecated*/ false };
131
111
return AvailabilityContext (Storage::get (info, ctx));
132
112
}
@@ -143,29 +123,19 @@ AvailabilityContext AvailabilityContext::forDeploymentTarget(ASTContext &ctx) {
143
123
144
124
AvailabilityContext
145
125
AvailabilityContext::get (const AvailabilityRange &platformAvailability,
146
- std::optional<PlatformKind> unavailablePlatform ,
126
+ std::optional<AvailabilityDomain> unavailableDomain ,
147
127
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};
153
129
return AvailabilityContext (Storage::get (info, ctx));
154
130
}
155
131
156
132
AvailabilityRange AvailabilityContext::getPlatformRange () const {
157
133
return storage->info .Range ;
158
134
}
159
135
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 ;
169
139
}
170
140
171
141
bool AvailabilityContext::isDeprecated () const {
@@ -233,8 +203,8 @@ stringForAvailability(const AvailabilityRange &availability) {
233
203
void AvailabilityContext::print (llvm::raw_ostream &os) const {
234
204
os << " version=" << stringForAvailability (getPlatformRange ());
235
205
236
- if (auto unavailablePlatform = getUnavailablePlatformKind ())
237
- os << " unavailable=" << platformString (*unavailablePlatform );
206
+ if (auto unavailableDomain = getUnavailableDomain ())
207
+ os << " unavailable=" << unavailableDomain-> getNameForAttributePrinting ( );
238
208
239
209
if (isDeprecated ())
240
210
os << " deprecated" ;
0 commit comments