@@ -201,9 +201,33 @@ void AvailabilityInference::applyInferredAvailableAttrs(
201
201
Decl *ToDecl, ArrayRef<const Decl *> InferredFromDecls) {
202
202
auto &Context = ToDecl->getASTContext ();
203
203
204
+ class OrderedAvailabilityDomain {
205
+ public:
206
+ AvailabilityDomain domain;
207
+
208
+ OrderedAvailabilityDomain (AvailabilityDomain domain) : domain(domain) {}
209
+
210
+ bool operator <(const OrderedAvailabilityDomain &other) const {
211
+ auto kind = domain.getKind ();
212
+ auto otherKind = other.domain .getKind ();
213
+ if (kind != otherKind)
214
+ return kind < otherKind;
215
+
216
+ switch (kind) {
217
+ case AvailabilityDomain::Kind::Universal:
218
+ case AvailabilityDomain::Kind::SwiftLanguage:
219
+ case AvailabilityDomain::Kind::PackageDescription:
220
+ case AvailabilityDomain::Kind::Embedded:
221
+ return false ;
222
+ case AvailabilityDomain::Kind::Platform:
223
+ return domain.getPlatformKind () < other.domain .getPlatformKind ();
224
+ }
225
+ }
226
+ };
227
+
204
228
// Iterate over the declarations and infer required availability on
205
229
// a per-platform basis.
206
- std::map<AvailabilityDomain , InferredAvailability> Inferred;
230
+ std::map<OrderedAvailabilityDomain , InferredAvailability> Inferred;
207
231
for (const Decl *D : InferredFromDecls) {
208
232
llvm::SmallVector<SemanticAvailableAttr, 8 > MergedAttrs;
209
233
@@ -238,7 +262,8 @@ void AvailabilityInference::applyInferredAvailableAttrs(
238
262
// Create an availability attribute for each observed platform and add
239
263
// to ToDecl.
240
264
for (auto &Pair : Inferred) {
241
- if (auto Attr = createAvailableAttr (Pair.first , Pair.second , Context))
265
+ if (auto Attr =
266
+ createAvailableAttr (Pair.first .domain , Pair.second , Context))
242
267
Attrs.add (Attr);
243
268
}
244
269
}
0 commit comments