Skip to content

Commit 7f7664a

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

File tree

2 files changed

+18
-29
lines changed

2 files changed

+18
-29
lines changed

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,13 +1513,6 @@ checkDeclarationAvailability(const Decl *D, const ExportContext &Where) {
15131513
return std::nullopt;
15141514
}
15151515

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-
15231516
/// A class that walks the AST to find the innermost (i.e., deepest) node that
15241517
/// contains a target SourceRange and matches a particular criterion.
15251518
/// This class finds the innermost nodes of interest by walking
@@ -4625,6 +4618,7 @@ swift::diagnoseConformanceAvailability(SourceLoc loc,
46254618
// Diagnose "missing" conformances where we needed a conformance but
46264619
// didn't have one.
46274620
auto *DC = where.getDeclContext();
4621+
auto &ctx = DC->getASTContext();
46284622
if (auto builtinConformance = dyn_cast<BuiltinProtocolConformance>(rootConf)){
46294623
if (builtinConformance->isMissing()) {
46304624
diagnoseMissingConformance(loc, builtinConformance->getType(),
@@ -4638,7 +4632,6 @@ swift::diagnoseConformanceAvailability(SourceLoc loc,
46384632

46394633
Type selfTy = rootConf->getProtocol()->getSelfInterfaceType();
46404634
if (!depTy->isEqual(selfTy)) {
4641-
auto &ctx = DC->getASTContext();
46424635
ctx.Diags.diagnose(
46434636
loc,
46444637
diag::assoc_conformance_from_implementation_only_module,
@@ -4653,20 +4646,24 @@ swift::diagnoseConformanceAvailability(SourceLoc loc,
46534646
return true;
46544647
}
46554648

4656-
if (diagnoseExplicitUnavailability(loc, rootConf, ext, where,
4657-
warnIfConformanceUnavailablePreSwift6)) {
4658-
maybeEmitAssociatedTypeNote();
4659-
return true;
4660-
}
4649+
auto unmetRequirement = getUnmetDeclAvailabilityRequirement(
4650+
ext, where.getDeclContext(), where.getAvailability());
4651+
if (unmetRequirement) {
4652+
// FIXME: diagnoseExplicitUnavailability() should take unmet requirement
4653+
if (diagnoseExplicitUnavailability(
4654+
loc, rootConf, ext, where,
4655+
warnIfConformanceUnavailablePreSwift6)) {
4656+
maybeEmitAssociatedTypeNote();
4657+
return true;
4658+
}
46614659

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;
4660+
// Diagnose (and possibly signal) for potential unavailability
4661+
if (auto requiredRange =
4662+
unmetRequirement->getRequiredNewerAvailabilityRange(ctx)) {
4663+
diagnosePotentialUnavailability(rootConf, ext, loc, DC, *requiredRange);
4664+
maybeEmitAssociatedTypeNote();
4665+
return true;
4666+
}
46704667
}
46714668

46724669
// 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)