@@ -936,37 +936,51 @@ TypeChecker::overApproximateAvailabilityAtLocation(SourceLoc loc,
936936 return OverApproximateContext;
937937}
938938
939- Optional<UnavailabilityReason>
940- TypeChecker::checkDeclarationAvailability (const Decl *D,
941- const ExportContext &where) {
942- auto *referenceDC = where.getDeclContext ();
939+ bool TypeChecker::isDeclarationUnavailable (
940+ const Decl *D, const DeclContext *referenceDC,
941+ llvm::function_ref<AvailabilityContext()> getAvailabilityContext) {
943942 ASTContext &Context = referenceDC->getASTContext ();
944943 if (Context.LangOpts .DisableAvailabilityChecking ) {
945- return None ;
944+ return false ;
946945 }
947946
948947 if (!referenceDC->getParentSourceFile ()) {
949948 // We only check availability if this reference is in a source file; we do
950949 // not check in other kinds of FileUnits.
951- return None ;
950+ return false ;
952951 }
953952
954- AvailabilityContext runningOSOverApprox =
955- where.getAvailabilityContext ();
956-
957953 AvailabilityContext safeRangeUnderApprox{
958954 AvailabilityInference::availableRange (D, Context)};
959955
956+ if (safeRangeUnderApprox.isAlwaysAvailable ())
957+ return false ;
958+
959+ AvailabilityContext runningOSOverApprox = getAvailabilityContext ();
960+
960961 // The reference is safe if an over-approximation of the running OS
961962 // versions is fully contained within an under-approximation
962963 // of the versions on which the declaration is available. If this
963964 // containment cannot be guaranteed, we say the reference is
964965 // not available.
965- if ( runningOSOverApprox.isContainedIn (safeRangeUnderApprox))
966- return None;
966+ return ! runningOSOverApprox.isContainedIn (safeRangeUnderApprox);
967+ }
967968
968- VersionRange version = safeRangeUnderApprox.getOSVersion ();
969- return UnavailabilityReason::requiresVersionRange (version);
969+ Optional<UnavailabilityReason>
970+ TypeChecker::checkDeclarationAvailability (const Decl *D,
971+ const ExportContext &Where) {
972+ if (isDeclarationUnavailable (D, Where.getDeclContext (), [&Where] {
973+ return Where.getAvailabilityContext ();
974+ })) {
975+ auto &Context = Where.getDeclContext ()->getASTContext ();
976+ AvailabilityContext safeRangeUnderApprox{
977+ AvailabilityInference::availableRange (D, Context)};
978+
979+ VersionRange version = safeRangeUnderApprox.getOSVersion ();
980+ return UnavailabilityReason::requiresVersionRange (version);
981+ }
982+
983+ return None;
970984}
971985
972986Optional<UnavailabilityReason>
0 commit comments