Skip to content

Commit aeb475b

Browse files
authored
Merge pull request #77950 from tshortli/remove-semantic-available-range-attr
AST: Remove `Decl::getSemanticAvailableRangeAttr()`
2 parents 7284676 + 4da7f83 commit aeb475b

File tree

5 files changed

+15
-53
lines changed

5 files changed

+15
-53
lines changed

include/swift/AST/Decl.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,15 +1433,6 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl>, public Swi
14331433
const AvailableAttr *
14341434
getUnavailableAttr(bool ignoreAppExtensions = false) const;
14351435

1436-
/// Retrieve the @available attribute that provides the OS version range that
1437-
/// this declaration is available in.
1438-
///
1439-
/// This attribute may come from an enclosing decl since availability is
1440-
/// inherited. The second member of the returned pair is the decl that owns
1441-
/// the attribute.
1442-
std::optional<std::pair<const AvailableAttr *, const Decl *>>
1443-
getSemanticAvailableRangeAttr() const;
1444-
14451436
/// Returns true if the decl is effectively always unavailable in the current
14461437
/// compilation context. This query differs from \c isUnavailable() because it
14471438
/// takes the availability of parent declarations into account.

include/swift/AST/TypeCheckRequests.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4103,25 +4103,6 @@ class RenamedDeclRequest
41034103
void cacheResult(ValueDecl *value) const;
41044104
};
41054105

4106-
using AvailableAttrDeclPair = std::pair<const AvailableAttr *, const Decl *>;
4107-
4108-
class SemanticAvailableRangeAttrRequest
4109-
: public SimpleRequest<SemanticAvailableRangeAttrRequest,
4110-
std::optional<AvailableAttrDeclPair>(const Decl *),
4111-
RequestFlags::Cached> {
4112-
public:
4113-
using SimpleRequest::SimpleRequest;
4114-
4115-
private:
4116-
friend SimpleRequest;
4117-
4118-
std::optional<AvailableAttrDeclPair> evaluate(Evaluator &evaluator,
4119-
const Decl *decl) const;
4120-
4121-
public:
4122-
bool isCached() const { return true; }
4123-
};
4124-
41254106
enum class SemanticDeclAvailability : uint8_t {
41264107
/// The decl is potentially available in some contexts and/or under certain
41274108
/// deployment conditions.

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -469,9 +469,6 @@ SWIFT_REQUEST(TypeChecker, ImplicitKnownProtocolConformanceRequest,
469469
SWIFT_REQUEST(TypeChecker, RenamedDeclRequest,
470470
ValueDecl *(const ValueDecl *, const AvailableAttr *),
471471
Cached, NoLocationInfo)
472-
SWIFT_REQUEST(TypeChecker, SemanticAvailableRangeAttrRequest,
473-
Optional<AvailableAttrDeclPair>(const Decl *),
474-
Cached, NoLocationInfo)
475472
SWIFT_REQUEST(TypeChecker, SemanticDeclAvailabilityRequest,
476473
SemanticDeclAvailability(const Decl *),
477474
Cached, NoLocationInfo)

lib/AST/Availability.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -453,26 +453,6 @@ AvailabilityInference::attrForAnnotatedAvailableRange(const Decl *D) {
453453
return bestAvailAttr;
454454
}
455455

456-
std::optional<AvailableAttrDeclPair>
457-
SemanticAvailableRangeAttrRequest::evaluate(Evaluator &evaluator,
458-
const Decl *decl) const {
459-
if (auto attr = AvailabilityInference::attrForAnnotatedAvailableRange(decl))
460-
return std::make_pair(attr, decl);
461-
462-
if (auto *parent =
463-
AvailabilityInference::parentDeclForInferredAvailability(decl))
464-
return parent->getSemanticAvailableRangeAttr();
465-
466-
return std::nullopt;
467-
}
468-
469-
std::optional<AvailableAttrDeclPair>
470-
Decl::getSemanticAvailableRangeAttr() const {
471-
auto &eval = getASTContext().evaluator;
472-
return evaluateOrDefault(eval, SemanticAvailableRangeAttrRequest{this},
473-
std::nullopt);
474-
}
475-
476456
std::optional<AvailabilityRange>
477457
AvailabilityInference::annotatedAvailableRange(const Decl *D) {
478458
auto bestAvailAttr = attrForAnnotatedAvailableRange(D);

lib/Sema/TypeCheckAttr.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2109,6 +2109,18 @@ static Decl *getEnclosingDeclForDecl(Decl *D) {
21092109
return D->getDeclContext()->getInnermostDeclarationDeclContext();
21102110
}
21112111

2112+
static std::optional<std::pair<const AvailableAttr *, const Decl *>>
2113+
getSemanticAvailableRangeDeclAndAttr(const Decl *decl) {
2114+
if (auto attr = AvailabilityInference::attrForAnnotatedAvailableRange(decl))
2115+
return std::make_pair(attr, decl);
2116+
2117+
if (auto *parent =
2118+
AvailabilityInference::parentDeclForInferredAvailability(decl))
2119+
return getSemanticAvailableRangeDeclAndAttr(parent);
2120+
2121+
return std::nullopt;
2122+
}
2123+
21122124
void AttributeChecker::visitAvailableAttr(AvailableAttr *attr) {
21132125
if (Ctx.LangOpts.DisableAvailabilityChecking)
21142126
return;
@@ -2214,7 +2226,7 @@ void AttributeChecker::visitAvailableAttr(AvailableAttr *attr) {
22142226

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

0 commit comments

Comments
 (0)