Skip to content

AST: Remove Decl::getSemanticAvailableRangeAttr() #77950

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1433,15 +1433,6 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl>, public Swi
const AvailableAttr *
getUnavailableAttr(bool ignoreAppExtensions = false) const;

/// Retrieve the @available attribute that provides the OS version range that
/// this declaration is available in.
///
/// This attribute may come from an enclosing decl since availability is
/// inherited. The second member of the returned pair is the decl that owns
/// the attribute.
std::optional<std::pair<const AvailableAttr *, const Decl *>>
getSemanticAvailableRangeAttr() const;

/// Returns true if the decl is effectively always unavailable in the current
/// compilation context. This query differs from \c isUnavailable() because it
/// takes the availability of parent declarations into account.
Expand Down
19 changes: 0 additions & 19 deletions include/swift/AST/TypeCheckRequests.h
Original file line number Diff line number Diff line change
Expand Up @@ -4103,25 +4103,6 @@ class RenamedDeclRequest
void cacheResult(ValueDecl *value) const;
};

using AvailableAttrDeclPair = std::pair<const AvailableAttr *, const Decl *>;

class SemanticAvailableRangeAttrRequest
: public SimpleRequest<SemanticAvailableRangeAttrRequest,
std::optional<AvailableAttrDeclPair>(const Decl *),
RequestFlags::Cached> {
public:
using SimpleRequest::SimpleRequest;

private:
friend SimpleRequest;

std::optional<AvailableAttrDeclPair> evaluate(Evaluator &evaluator,
const Decl *decl) const;

public:
bool isCached() const { return true; }
};

enum class SemanticDeclAvailability : uint8_t {
/// The decl is potentially available in some contexts and/or under certain
/// deployment conditions.
Expand Down
3 changes: 0 additions & 3 deletions include/swift/AST/TypeCheckerTypeIDZone.def
Original file line number Diff line number Diff line change
Expand Up @@ -469,9 +469,6 @@ SWIFT_REQUEST(TypeChecker, ImplicitKnownProtocolConformanceRequest,
SWIFT_REQUEST(TypeChecker, RenamedDeclRequest,
ValueDecl *(const ValueDecl *, const AvailableAttr *),
Cached, NoLocationInfo)
SWIFT_REQUEST(TypeChecker, SemanticAvailableRangeAttrRequest,
Optional<AvailableAttrDeclPair>(const Decl *),
Cached, NoLocationInfo)
SWIFT_REQUEST(TypeChecker, SemanticDeclAvailabilityRequest,
SemanticDeclAvailability(const Decl *),
Cached, NoLocationInfo)
Expand Down
20 changes: 0 additions & 20 deletions lib/AST/Availability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,26 +453,6 @@ AvailabilityInference::attrForAnnotatedAvailableRange(const Decl *D) {
return bestAvailAttr;
}

std::optional<AvailableAttrDeclPair>
SemanticAvailableRangeAttrRequest::evaluate(Evaluator &evaluator,
const Decl *decl) const {
if (auto attr = AvailabilityInference::attrForAnnotatedAvailableRange(decl))
return std::make_pair(attr, decl);

if (auto *parent =
AvailabilityInference::parentDeclForInferredAvailability(decl))
return parent->getSemanticAvailableRangeAttr();

return std::nullopt;
}

std::optional<AvailableAttrDeclPair>
Decl::getSemanticAvailableRangeAttr() const {
auto &eval = getASTContext().evaluator;
return evaluateOrDefault(eval, SemanticAvailableRangeAttrRequest{this},
std::nullopt);
}

std::optional<AvailabilityRange>
AvailabilityInference::annotatedAvailableRange(const Decl *D) {
auto bestAvailAttr = attrForAnnotatedAvailableRange(D);
Expand Down
17 changes: 15 additions & 2 deletions lib/Sema/TypeCheckAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2109,6 +2109,18 @@ static Decl *getEnclosingDeclForDecl(Decl *D) {
return D->getDeclContext()->getInnermostDeclarationDeclContext();
}

static std::optional<std::pair<const AvailableAttr *, const Decl *>>
getSemanticAvailableRangeDeclAndAttr(const Decl *decl) {
if (auto attr = AvailabilityInference::attrForAnnotatedAvailableRange(decl))
return std::make_pair(attr, decl);

if (auto *parent =
AvailabilityInference::parentDeclForInferredAvailability(decl))
return getSemanticAvailableRangeDeclAndAttr(parent);

return std::nullopt;
}

void AttributeChecker::visitAvailableAttr(AvailableAttr *attr) {
if (Ctx.LangOpts.DisableAvailabilityChecking)
return;
Expand Down Expand Up @@ -2214,7 +2226,7 @@ void AttributeChecker::visitAvailableAttr(AvailableAttr *attr) {

if (auto *parent = getEnclosingDeclForDecl(D)) {
if (auto enclosingAvailable =
parent->getSemanticAvailableRangeAttr()) {
getSemanticAvailableRangeDeclAndAttr(parent)) {
const AvailableAttr *enclosingAttr = enclosingAvailable.value().first;
const Decl *enclosingDecl = enclosingAvailable.value().second;
EnclosingAnnotatedRange.emplace(
Expand Down Expand Up @@ -4833,7 +4845,8 @@ void AttributeChecker::checkBackDeployedAttrs(
// Verify that the decl is available before the back deployment boundary.
// If it's not, the attribute doesn't make sense since the back deployment
// fallback could never be executed at runtime.
if (auto availableRangeAttrPair = VD->getSemanticAvailableRangeAttr()) {
if (auto availableRangeAttrPair =
getSemanticAvailableRangeDeclAndAttr(VD)) {
auto beforePlatformString = prettyPlatformString(Attr->Platform);
auto beforeVersion = Attr->Version;
auto availableAttr = availableRangeAttrPair.value().first;
Expand Down