@@ -109,12 +109,14 @@ namespace {
109109// / The inferred availability required to access a group of declarations
110110// / on a single platform.
111111struct InferredAvailability {
112- PlatformAgnosticAvailabilityKind PlatformAgnostic
113- = PlatformAgnosticAvailabilityKind::None;
112+ AvailableAttr::Kind Kind = AvailableAttr::Kind::Default;
114113
115114 std::optional<llvm::VersionTuple> Introduced;
116115 std::optional<llvm::VersionTuple> Deprecated;
117116 std::optional<llvm::VersionTuple> Obsoleted;
117+
118+ StringRef Message;
119+ StringRef Rename;
118120 bool IsSPI = false ;
119121};
120122
@@ -148,10 +150,9 @@ mergeIntoInferredVersion(const std::optional<llvm::VersionTuple> &Version,
148150static void mergeWithInferredAvailability (SemanticAvailableAttr Attr,
149151 InferredAvailability &Inferred) {
150152 auto *ParsedAttr = Attr.getParsedAttr ();
151- Inferred.PlatformAgnostic = static_cast <PlatformAgnosticAvailabilityKind>(
152- std::max (static_cast <unsigned >(Inferred.PlatformAgnostic ),
153- static_cast <unsigned >(
154- ParsedAttr->getPlatformAgnosticAvailability ())));
153+ Inferred.Kind = static_cast <AvailableAttr::Kind>(
154+ std::max (static_cast <unsigned >(Inferred.Kind ),
155+ static_cast <unsigned >(ParsedAttr->getKind ())));
155156
156157 // The merge of two introduction versions is the maximum of the two versions.
157158 if (mergeIntoInferredVersion (Attr.getIntroduced (), Inferred.Introduced ,
@@ -162,21 +163,24 @@ static void mergeWithInferredAvailability(SemanticAvailableAttr Attr,
162163 // The merge of deprecated and obsoleted versions takes the minimum.
163164 mergeIntoInferredVersion (Attr.getDeprecated (), Inferred.Deprecated , std::min);
164165 mergeIntoInferredVersion (Attr.getObsoleted (), Inferred.Obsoleted , std::min);
166+
167+ if (Inferred.Message .empty () && !Attr.getMessage ().empty ())
168+ Inferred.Message = Attr.getMessage ();
169+
170+ if (Inferred.Rename .empty () && !Attr.getRename ().empty ())
171+ Inferred.Rename = Attr.getRename ();
165172}
166173
167- // / Create an implicit availability attribute for the given platform
174+ // / Create an implicit availability attribute for the given domain
168175// / and with the inferred availability.
169- static AvailableAttr *createAvailableAttr (PlatformKind Platform ,
176+ static AvailableAttr *createAvailableAttr (AvailabilityDomain Domain ,
170177 const InferredAvailability &Inferred,
171- StringRef Message,
172- StringRef Rename,
173- ValueDecl *RenameDecl,
174178 ASTContext &Context) {
175179 // If there is no information that would go into the availability attribute,
176180 // don't create one.
177- if (Inferred.PlatformAgnostic == PlatformAgnosticAvailabilityKind::None &&
178- !Inferred.Introduced && !Inferred.Deprecated && ! Inferred.Obsoleted &&
179- Message. empty () && Rename.empty () && !RenameDecl )
181+ if (Inferred.Kind == AvailableAttr::Kind::Default && !Inferred. Introduced &&
182+ !Inferred.Deprecated && !Inferred.Obsoleted && Inferred.Message . empty () &&
183+ Inferred. Rename .empty ())
180184 return nullptr ;
181185
182186 llvm::VersionTuple Introduced =
@@ -186,36 +190,26 @@ static AvailableAttr *createAvailableAttr(PlatformKind Platform,
186190 llvm::VersionTuple Obsoleted =
187191 Inferred.Obsoleted .value_or (llvm::VersionTuple ());
188192
189- return new (Context)
190- AvailableAttr (SourceLoc (), SourceRange (), Platform, Message, Rename,
191- Introduced, SourceRange (), Deprecated, SourceRange (),
192- Obsoleted, SourceRange (), Inferred.PlatformAgnostic ,
193- /* Implicit=*/ true , Inferred.IsSPI );
193+ return new (Context) AvailableAttr (
194+ SourceLoc (), SourceRange (), Domain, Inferred.Kind , Inferred.Message ,
195+ Inferred.Rename , Introduced, SourceRange (), Deprecated, SourceRange (),
196+ Obsoleted, SourceRange (), /* Implicit=*/ true , Inferred.IsSPI );
194197}
195198
196199void AvailabilityInference::applyInferredAvailableAttrs (
197200 Decl *ToDecl, ArrayRef<const Decl *> InferredFromDecls) {
198201 auto &Context = ToDecl->getASTContext ();
199202
200- // Let the new AvailabilityAttr inherit the message and rename.
201- // The first encountered message / rename will win; this matches the
202- // behaviour of diagnostics for 'non-inherited' AvailabilityAttrs.
203- StringRef Message;
204- StringRef Rename;
205- ValueDecl *RenameDecl = nullptr ;
206-
207203 // Iterate over the declarations and infer required availability on
208204 // a per-platform basis.
209- // FIXME: [availability] Generalize to AvailabilityDomain.
210- std::map<PlatformKind, InferredAvailability> Inferred;
205+ std::map<AvailabilityDomain, InferredAvailability> Inferred;
211206 for (const Decl *D : InferredFromDecls) {
212207 llvm::SmallVector<SemanticAvailableAttr, 8 > MergedAttrs;
213208
214209 do {
215210 llvm::SmallVector<SemanticAvailableAttr, 8 > PendingAttrs;
216211
217- for (auto AvAttr :
218- D->getSemanticAvailableAttrs ()) {
212+ for (auto AvAttr : D->getSemanticAvailableAttrs ()) {
219213 // Skip an attribute from an outer declaration if it is for a platform
220214 // that was already handled implicitly by an attribute from an inner
221215 // declaration.
@@ -226,14 +220,8 @@ void AvailabilityInference::applyInferredAvailableAttrs(
226220 }))
227221 continue ;
228222
229- mergeWithInferredAvailability (AvAttr, Inferred[AvAttr.getPlatform ()]);
223+ mergeWithInferredAvailability (AvAttr, Inferred[AvAttr.getDomain ()]);
230224 PendingAttrs.push_back (AvAttr);
231-
232- if (Message.empty () && !AvAttr.getMessage ().empty ())
233- Message = AvAttr.getMessage ();
234-
235- if (Rename.empty () && !AvAttr.getRename ().empty ())
236- Rename = AvAttr.getRename ();
237225 }
238226
239227 MergedAttrs.append (PendingAttrs);
@@ -245,20 +233,12 @@ void AvailabilityInference::applyInferredAvailableAttrs(
245233 }
246234
247235 DeclAttributes &Attrs = ToDecl->getAttrs ();
248- auto *ToValueDecl = dyn_cast<ValueDecl>(ToDecl);
249236
250237 // Create an availability attribute for each observed platform and add
251238 // to ToDecl.
252239 for (auto &Pair : Inferred) {
253- auto *Attr = createAvailableAttr (Pair.first , Pair.second , Message,
254- Rename, RenameDecl, Context);
255-
256- if (Attr) {
257- if (RenameDecl && ToValueDecl)
258- ToValueDecl->setRenamedDecl (Attr, RenameDecl);
259-
240+ if (auto Attr = createAvailableAttr (Pair.first , Pair.second , Context))
260241 Attrs.add (Attr);
261- }
262242 }
263243}
264244
0 commit comments