Skip to content

Commit c7026f6

Browse files
committed
AST: Re-implement Decl::getUnavailableAttr() using AvailabilityConstraint.
Use the consolidated logic of `swift::getAvailabilityConstraintsForDecl()` to replace the logic of `Decl::getUnavailableAttr()`. NFC.
1 parent 3301f96 commit c7026f6

File tree

1 file changed

+6
-41
lines changed

1 file changed

+6
-41
lines changed

lib/AST/Availability.cpp

Lines changed: 6 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -573,49 +573,14 @@ bool Decl::isUnavailableInCurrentSwiftVersion() const {
573573
return false;
574574
}
575575

576-
std::optional<SemanticAvailableAttr> getDeclUnavailableAttr(const Decl *D) {
577-
auto &ctx = D->getASTContext();
578-
std::optional<SemanticAvailableAttr> result;
579-
auto bestActive = D->getActiveAvailableAttrForCurrentPlatform();
580-
581-
for (auto attr : D->getSemanticAvailableAttrs(/*includingInactive=*/false)) {
582-
// If this is a platform-specific attribute and it isn't the most
583-
// specific attribute for the current platform, we're done.
584-
if (attr.isPlatformSpecific() && (!bestActive || attr != bestActive))
585-
continue;
586-
587-
// Unconditional unavailable.
588-
if (attr.isUnconditionallyUnavailable())
589-
return attr;
590-
591-
switch (attr.getVersionAvailability(ctx)) {
592-
case AvailableVersionComparison::Available:
593-
case AvailableVersionComparison::PotentiallyUnavailable:
594-
break;
595-
596-
case AvailableVersionComparison::Obsoleted:
597-
case AvailableVersionComparison::Unavailable:
598-
result.emplace(attr);
599-
break;
600-
}
601-
}
602-
return result;
603-
}
604-
605576
std::optional<SemanticAvailableAttr> Decl::getUnavailableAttr() const {
606-
if (auto attr = getDeclUnavailableAttr(this))
607-
return attr;
577+
auto context = AvailabilityContext::forDeploymentTarget(getASTContext());
578+
auto constraints = swift::getAvailabilityConstraintsForDecl(this, context);
608579

609-
// If D is an extension member, check if the extension is unavailable.
610-
//
611-
// Skip decls imported from Clang, they could be associated to the wrong
612-
// extension and inherit undesired unavailability. The ClangImporter
613-
// associates Objective-C protocol members to the first category where the
614-
// protocol is directly or indirectly adopted, no matter its availability
615-
// and the availability of other categories. rdar://problem/53956555
616-
if (!getClangNode())
617-
if (auto ext = dyn_cast<ExtensionDecl>(getDeclContext()))
618-
return ext->getUnavailableAttr();
580+
for (auto const &constraint : constraints) {
581+
if (constraint.isUnavailable())
582+
return constraint.getAttr();
583+
}
619584

620585
return std::nullopt;
621586
}

0 commit comments

Comments
 (0)