@@ -168,46 +168,11 @@ void AvailabilityInference::applyInferredAvailableAttrs(
168
168
Decl *ToDecl, ArrayRef<const Decl *> InferredFromDecls) {
169
169
auto &Context = ToDecl->getASTContext ();
170
170
171
- // / A wrapper for AvailabilityDomain that implements a stable, total ordering for
172
- // / domains. This is needed to ensure that the inferred attributes are added to
173
- // / the declaration in a consistent order, preserving interface printing output
174
- // / stability across compilations.
175
- class OrderedAvailabilityDomain {
176
- public:
177
- AvailabilityDomain domain;
178
-
179
- OrderedAvailabilityDomain (AvailabilityDomain domain) : domain(domain) {}
180
-
181
- bool operator <(const OrderedAvailabilityDomain &other) const {
182
- auto kind = domain.getKind ();
183
- auto otherKind = other.domain .getKind ();
184
- if (kind != otherKind)
185
- return kind < otherKind;
186
-
187
- switch (kind) {
188
- case AvailabilityDomain::Kind::Universal:
189
- case AvailabilityDomain::Kind::SwiftLanguage:
190
- case AvailabilityDomain::Kind::PackageDescription:
191
- case AvailabilityDomain::Kind::Embedded:
192
- return false ;
193
- case AvailabilityDomain::Kind::Platform:
194
- return domain.getPlatformKind () < other.domain .getPlatformKind ();
195
- case AvailabilityDomain::Kind::Custom: {
196
- auto mod = domain.getModule ();
197
- auto otherMod = other.domain .getModule ();
198
- if (mod != otherMod)
199
- return mod->getName () < otherMod->getName ();
200
-
201
- return domain.getNameForAttributePrinting () <
202
- other.domain .getNameForAttributePrinting ();
203
- }
204
- }
205
- }
206
- };
207
-
208
171
// Iterate over the declarations and infer required availability on
209
- // a per-platform basis.
210
- std::map<OrderedAvailabilityDomain, InferredAvailability> Inferred;
172
+ // a per-domain basis.
173
+ std::map<AvailabilityDomain, InferredAvailability,
174
+ StableAvailabilityDomainComparator>
175
+ Inferred;
211
176
for (const Decl *D : InferredFromDecls) {
212
177
llvm::SmallVector<SemanticAvailableAttr, 8 > MergedAttrs;
213
178
@@ -242,8 +207,7 @@ void AvailabilityInference::applyInferredAvailableAttrs(
242
207
// Create an availability attribute for each observed platform and add
243
208
// to ToDecl.
244
209
for (auto &Pair : Inferred) {
245
- if (auto Attr =
246
- createAvailableAttr (Pair.first .domain , Pair.second , Context))
210
+ if (auto Attr = createAvailableAttr (Pair.first , Pair.second , Context))
247
211
Attrs.add (Attr);
248
212
}
249
213
}
0 commit comments