@@ -169,7 +169,7 @@ ExportContext ExportContext::forDeclSignature(Decl *D) {
169169 auto *DC = D->getInnermostDeclContext ();
170170 auto fragileKind = DC->getFragileFunctionKind ();
171171 auto loc = D->getLoc ();
172- auto availabilityContext = TypeChecker::availabilityAtLocation (loc, DC);
172+ auto availabilityContext = AvailabilityContext::forLocation (loc, DC);
173173 bool spi = Ctx.LangOpts .LibraryLevel == LibraryLevel::SPI;
174174 bool implicit = false ;
175175 computeExportContextBits (Ctx, D, &spi, &implicit);
@@ -187,7 +187,7 @@ ExportContext ExportContext::forFunctionBody(DeclContext *DC, SourceLoc loc) {
187187 auto &Ctx = DC->getASTContext ();
188188
189189 auto fragileKind = DC->getFragileFunctionKind ();
190- auto availabilityContext = TypeChecker::availabilityAtLocation (loc, DC);
190+ auto availabilityContext = AvailabilityContext::forLocation (loc, DC);
191191 bool spi = Ctx.LangOpts .LibraryLevel == LibraryLevel::SPI;
192192 bool implicit = false ;
193193 forEachOuterDecl (
@@ -288,75 +288,11 @@ static bool shouldTreatDeclContextAsAsyncForDiagnostics(const DeclContext *DC) {
288288 return DC->isAsyncContext ();
289289}
290290
291- AvailabilityContext
292- TypeChecker::availabilityAtLocation (SourceLoc loc, const DeclContext *DC,
293- const AvailabilityScope **MostRefined) {
294- SourceFile *SF;
295- if (loc.isValid ())
296- SF = DC->getParentModule ()->getSourceFileContainingLocation (loc);
297- else
298- SF = DC->getParentSourceFile ();
299- auto &Context = DC->getASTContext ();
300-
301- // If our source location is invalid (this may be synthesized code), climb
302- // the decl context hierarchy until we find a location that is valid,
303- // collecting availability ranges on the way up.
304- // We will combine the version ranges from these annotations
305- // with the scope for the valid location to overapproximate the running
306- // OS versions at the original source location.
307- // Because we are climbing DeclContexts we will miss availability scopes in
308- // synthesized code that are introduced by AST elements that are themselves
309- // not DeclContexts, such as #available(..) and property declarations.
310- // That is, a reference with an invalid location that is contained
311- // inside a #available() and with no intermediate DeclContext will not be
312- // refined. For now, this is fine -- but if we ever synthesize #available(),
313- // this will be a real problem.
314-
315- // We can assume we are running on at least the minimum inlining target.
316- auto baseAvailability = AvailabilityContext::forInliningTarget (Context);
317- auto isInvalidLoc = [SF](SourceLoc loc) {
318- return SF ? loc.isInvalid () : true ;
319- };
320- while (DC && isInvalidLoc (loc)) {
321- const Decl *D = DC->getInnermostDeclarationDeclContext ();
322- if (!D)
323- break ;
324-
325- baseAvailability.constrainWithDecl (D);
326- loc = D->getLoc ();
327- DC = D->getDeclContext ();
328- }
329-
330- if (!SF || loc.isInvalid ())
331- return baseAvailability;
332-
333- auto *rootScope = AvailabilityScope::getOrBuildForSourceFile (*SF);
334- if (!rootScope)
335- return baseAvailability;
336-
337- AvailabilityScope *scope = rootScope->findMostRefinedSubContext (loc, Context);
338- if (!scope)
339- return baseAvailability;
340-
341- if (MostRefined) {
342- *MostRefined = scope;
343- }
344-
345- auto availability = scope->getAvailabilityContext ();
346- availability.constrainWithContext (baseAvailability, Context);
347- return availability;
348- }
349-
350- AvailabilityContext
351- TypeChecker::availabilityForDeclSignature (const Decl *decl) {
352- return TypeChecker::availabilityAtLocation (decl->getLoc (),
353- decl->getInnermostDeclContext ());
354- }
355-
356291AvailabilityRange TypeChecker::overApproximateAvailabilityAtLocation (
357292 SourceLoc loc, const DeclContext *DC,
358293 const AvailabilityScope **MostRefined) {
359- return availabilityAtLocation (loc, DC, MostRefined).getPlatformRange ();
294+ return AvailabilityContext::forLocation (loc, DC, MostRefined)
295+ .getPlatformRange ();
360296}
361297
362298// / A class that walks the AST to find the innermost (i.e., deepest) node that
@@ -1831,8 +1767,7 @@ swift::getUnsatisfiedAvailabilityConstraint(const Decl *decl,
18311767 const DeclContext *referenceDC,
18321768 SourceLoc referenceLoc) {
18331769 return getAvailabilityConstraintsForDecl (
1834- decl,
1835- TypeChecker::availabilityAtLocation (referenceLoc, referenceDC))
1770+ decl, AvailabilityContext::forLocation (referenceLoc, referenceDC))
18361771 .getPrimaryConstraint ();
18371772}
18381773
0 commit comments