@@ -169,7 +169,7 @@ ExportContext ExportContext::forDeclSignature(Decl *D) {
169
169
auto *DC = D->getInnermostDeclContext();
170
170
auto fragileKind = DC->getFragileFunctionKind();
171
171
auto loc = D->getLoc();
172
- auto availabilityContext = TypeChecker::availabilityAtLocation (loc, DC);
172
+ auto availabilityContext = AvailabilityContext::forLocation (loc, DC);
173
173
bool spi = Ctx.LangOpts.LibraryLevel == LibraryLevel::SPI;
174
174
bool implicit = false;
175
175
computeExportContextBits(Ctx, D, &spi, &implicit);
@@ -187,7 +187,7 @@ ExportContext ExportContext::forFunctionBody(DeclContext *DC, SourceLoc loc) {
187
187
auto &Ctx = DC->getASTContext();
188
188
189
189
auto fragileKind = DC->getFragileFunctionKind();
190
- auto availabilityContext = TypeChecker::availabilityAtLocation (loc, DC);
190
+ auto availabilityContext = AvailabilityContext::forLocation (loc, DC);
191
191
bool spi = Ctx.LangOpts.LibraryLevel == LibraryLevel::SPI;
192
192
bool implicit = false;
193
193
forEachOuterDecl(
@@ -288,75 +288,11 @@ static bool shouldTreatDeclContextAsAsyncForDiagnostics(const DeclContext *DC) {
288
288
return DC->isAsyncContext();
289
289
}
290
290
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
-
356
291
AvailabilityRange TypeChecker::overApproximateAvailabilityAtLocation(
357
292
SourceLoc loc, const DeclContext *DC,
358
293
const AvailabilityScope **MostRefined) {
359
- return availabilityAtLocation (loc, DC, MostRefined).getPlatformRange ();
294
+ return AvailabilityContext::forLocation(loc, DC, MostRefined)
295
+ .getPlatformRange();
360
296
}
361
297
362
298
/// A class that walks the AST to find the innermost (i.e., deepest) node that
@@ -1831,8 +1767,7 @@ swift::getUnsatisfiedAvailabilityConstraint(const Decl *decl,
1831
1767
const DeclContext *referenceDC,
1832
1768
SourceLoc referenceLoc) {
1833
1769
return getAvailabilityConstraintsForDecl(
1834
- decl,
1835
- TypeChecker::availabilityAtLocation (referenceLoc, referenceDC))
1770
+ decl, AvailabilityContext::forLocation(referenceLoc, referenceDC))
1836
1771
.getPrimaryConstraint();
1837
1772
}
1838
1773
0 commit comments