@@ -936,37 +936,51 @@ TypeChecker::overApproximateAvailabilityAtLocation(SourceLoc loc,
936
936
return OverApproximateContext;
937
937
}
938
938
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) {
943
942
ASTContext &Context = referenceDC->getASTContext ();
944
943
if (Context.LangOpts .DisableAvailabilityChecking ) {
945
- return None ;
944
+ return false ;
946
945
}
947
946
948
947
if (!referenceDC->getParentSourceFile ()) {
949
948
// We only check availability if this reference is in a source file; we do
950
949
// not check in other kinds of FileUnits.
951
- return None ;
950
+ return false ;
952
951
}
953
952
954
- AvailabilityContext runningOSOverApprox =
955
- where.getAvailabilityContext ();
956
-
957
953
AvailabilityContext safeRangeUnderApprox{
958
954
AvailabilityInference::availableRange (D, Context)};
959
955
956
+ if (safeRangeUnderApprox.isAlwaysAvailable ())
957
+ return false ;
958
+
959
+ AvailabilityContext runningOSOverApprox = getAvailabilityContext ();
960
+
960
961
// The reference is safe if an over-approximation of the running OS
961
962
// versions is fully contained within an under-approximation
962
963
// of the versions on which the declaration is available. If this
963
964
// containment cannot be guaranteed, we say the reference is
964
965
// not available.
965
- if ( runningOSOverApprox.isContainedIn (safeRangeUnderApprox))
966
- return None;
966
+ return ! runningOSOverApprox.isContainedIn (safeRangeUnderApprox);
967
+ }
967
968
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;
970
984
}
971
985
972
986
Optional<UnavailabilityReason>
0 commit comments