Skip to content

Commit 242b9cc

Browse files
committed
Sema: Replace TypeChecker::checkConformanceAvailability().
Adopt `getUnmetDeclAvailabilityRequirement()` instead.
1 parent 7b5757b commit 242b9cc

File tree

2 files changed

+18
-77
lines changed

2 files changed

+18
-77
lines changed

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 18 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,61 +1465,6 @@ AvailabilityRange TypeChecker::overApproximateAvailabilityAtLocation(
14651465
return availabilityAtLocation(loc, DC, MostRefined).getPlatformRange();
14661466
}
14671467

1468-
static bool isDeclarationUnavailable(
1469-
const Decl *D, const DeclContext *referenceDC,
1470-
llvm::function_ref<AvailabilityRange()> getAvailabilityRange) {
1471-
ASTContext &Context = referenceDC->getASTContext();
1472-
if (Context.LangOpts.DisableAvailabilityChecking) {
1473-
return false;
1474-
}
1475-
1476-
if (!referenceDC->getParentSourceFile()) {
1477-
// We only check availability if this reference is in a source file; we do
1478-
// not check in other kinds of FileUnits.
1479-
return false;
1480-
}
1481-
1482-
AvailabilityRange safeRangeUnderApprox{
1483-
AvailabilityInference::availableRange(D)};
1484-
1485-
if (safeRangeUnderApprox.isAlwaysAvailable())
1486-
return false;
1487-
1488-
AvailabilityRange runningOSOverApprox = getAvailabilityRange();
1489-
1490-
// The reference is safe if an over-approximation of the running OS
1491-
// versions is fully contained within an under-approximation
1492-
// of the versions on which the declaration is available. If this
1493-
// containment cannot be guaranteed, we say the reference is
1494-
// not available.
1495-
return !runningOSOverApprox.isContainedIn(safeRangeUnderApprox);
1496-
}
1497-
1498-
static std::optional<AvailabilityRange>
1499-
checkDeclarationAvailability(const Decl *D, const ExportContext &Where) {
1500-
// Skip computing potential unavailability if the declaration is explicitly
1501-
// unavailable and the context is also unavailable.
1502-
if (const AvailableAttr *Attr = AvailableAttr::isUnavailable(D))
1503-
if (isInsideCompatibleUnavailableDeclaration(D, Where.getAvailability(),
1504-
Attr))
1505-
return std::nullopt;
1506-
1507-
if (isDeclarationUnavailable(D, Where.getDeclContext(), [&Where] {
1508-
return Where.getAvailabilityRange();
1509-
})) {
1510-
return AvailabilityInference::availableRange(D);
1511-
}
1512-
1513-
return std::nullopt;
1514-
}
1515-
1516-
std::optional<AvailabilityRange>
1517-
TypeChecker::checkConformanceAvailability(const RootProtocolConformance *conf,
1518-
const ExtensionDecl *ext,
1519-
const ExportContext &where) {
1520-
return checkDeclarationAvailability(ext, where);
1521-
}
1522-
15231468
/// A class that walks the AST to find the innermost (i.e., deepest) node that
15241469
/// contains a target SourceRange and matches a particular criterion.
15251470
/// This class finds the innermost nodes of interest by walking
@@ -4625,6 +4570,7 @@ swift::diagnoseConformanceAvailability(SourceLoc loc,
46254570
// Diagnose "missing" conformances where we needed a conformance but
46264571
// didn't have one.
46274572
auto *DC = where.getDeclContext();
4573+
auto &ctx = DC->getASTContext();
46284574
if (auto builtinConformance = dyn_cast<BuiltinProtocolConformance>(rootConf)){
46294575
if (builtinConformance->isMissing()) {
46304576
diagnoseMissingConformance(loc, builtinConformance->getType(),
@@ -4638,7 +4584,6 @@ swift::diagnoseConformanceAvailability(SourceLoc loc,
46384584

46394585
Type selfTy = rootConf->getProtocol()->getSelfInterfaceType();
46404586
if (!depTy->isEqual(selfTy)) {
4641-
auto &ctx = DC->getASTContext();
46424587
ctx.Diags.diagnose(
46434588
loc,
46444589
diag::assoc_conformance_from_implementation_only_module,
@@ -4653,20 +4598,24 @@ swift::diagnoseConformanceAvailability(SourceLoc loc,
46534598
return true;
46544599
}
46554600

4656-
if (diagnoseExplicitUnavailability(loc, rootConf, ext, where,
4657-
warnIfConformanceUnavailablePreSwift6)) {
4658-
maybeEmitAssociatedTypeNote();
4659-
return true;
4660-
}
4601+
auto unmetRequirement = getUnmetDeclAvailabilityRequirement(
4602+
ext, where.getDeclContext(), where.getAvailability());
4603+
if (unmetRequirement) {
4604+
// FIXME: diagnoseExplicitUnavailability() should take unmet requirement
4605+
if (diagnoseExplicitUnavailability(
4606+
loc, rootConf, ext, where,
4607+
warnIfConformanceUnavailablePreSwift6)) {
4608+
maybeEmitAssociatedTypeNote();
4609+
return true;
4610+
}
46614611

4662-
// Diagnose (and possibly signal) for potential unavailability
4663-
auto maybeUnavail = TypeChecker::checkConformanceAvailability(
4664-
rootConf, ext, where);
4665-
if (maybeUnavail.has_value()) {
4666-
diagnosePotentialUnavailability(rootConf, ext, loc, DC,
4667-
maybeUnavail.value());
4668-
maybeEmitAssociatedTypeNote();
4669-
return true;
4612+
// Diagnose (and possibly signal) for potential unavailability
4613+
if (auto requiredRange =
4614+
unmetRequirement->getRequiredNewerAvailabilityRange(ctx)) {
4615+
diagnosePotentialUnavailability(rootConf, ext, loc, DC, *requiredRange);
4616+
maybeEmitAssociatedTypeNote();
4617+
return true;
4618+
}
46704619
}
46714620

46724621
// Diagnose for deprecation

lib/Sema/TypeChecker.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,14 +1032,6 @@ diagnosticIfDeclCannotBePotentiallyUnavailable(const Decl *D);
10321032
/// is allowed.
10331033
std::optional<Diagnostic> diagnosticIfDeclCannotBeUnavailable(const Decl *D);
10341034

1035-
/// Checks whether a conformance should be considered unavailable when
1036-
/// referred to at the given location and, if so, returns the unmet required
1037-
/// version range. Returns None is the declaration is definitely available.
1038-
std::optional<AvailabilityRange>
1039-
checkConformanceAvailability(const RootProtocolConformance *Conf,
1040-
const ExtensionDecl *Ext,
1041-
const ExportContext &Where);
1042-
10431035
bool checkAvailability(
10441036
SourceRange ReferenceRange, AvailabilityRange RequiredAvailability,
10451037
const DeclContext *ReferenceDC,

0 commit comments

Comments
 (0)