Skip to content

Commit b2cc10c

Browse files
committed
AST: Introduce Decl::isSemanticallyUnavailable().
Adopt it in a few places as a replacement for `Decl::getSemanticUnavailableAttr()`.
1 parent 0ff25ca commit b2cc10c

File tree

6 files changed

+18
-5
lines changed

6 files changed

+18
-5
lines changed

include/swift/AST/Decl.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1455,9 +1455,15 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl>, public Swi
14551455
std::optional<std::pair<const AvailableAttr *, const Decl *>>
14561456
getSemanticUnavailableAttr(bool ignoreAppExtensions = false) const;
14571457

1458+
/// Returns true if the decl is effectively always unavailable in the current
1459+
/// compilation context. This query differs from \c isUnavailable() because it
1460+
/// takes the availability of parent declarations into account.
1461+
bool isSemanticallyUnavailable() const;
1462+
14581463
/// Returns true if code associated with this declaration should be considerd
14591464
/// unreachable at runtime because the declaration is unavailable in all
1460-
/// execution contexts in which the code may run.
1465+
/// execution contexts in which the code may run. This result takes the
1466+
/// availability of parent declarations into account.
14611467
bool isUnreachableAtRuntime() const;
14621468

14631469
/// Returns true if this declaration should be considered available during

lib/AST/Availability.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,13 @@ SemanticDeclAvailabilityRequest::evaluate(Evaluator &evaluator,
763763
return SemanticDeclAvailability::PotentiallyAvailable;
764764
}
765765

766+
bool Decl::isSemanticallyUnavailable() const {
767+
auto availability = evaluateOrDefault(
768+
getASTContext().evaluator, SemanticDeclAvailabilityRequest{this},
769+
SemanticDeclAvailability::PotentiallyAvailable);
770+
return availability != SemanticDeclAvailability::PotentiallyAvailable;
771+
}
772+
766773
bool Decl::isUnreachableAtRuntime() const {
767774
auto availability = evaluateOrDefault(
768775
getASTContext().evaluator, SemanticDeclAvailabilityRequest{this},

lib/SIL/IR/SILProfiler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ static bool shouldProfile(SILDeclRef Constant) {
117117

118118
if (auto *D = DC->getInnermostDeclarationDeclContext()) {
119119
// Do not profile AST nodes in unavailable contexts.
120-
if (D->getSemanticUnavailableAttr()) {
120+
if (D->isSemanticallyUnavailable()) {
121121
LLVM_DEBUG(llvm::dbgs() << "Skipping ASTNode: unavailable context\n");
122122
return false;
123123
}

lib/Sema/TypeCheckAttr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5007,7 +5007,7 @@ TypeChecker::diagnosticIfDeclCannotBeUnavailable(const Decl *D) {
50075007
auto parentIsUnavailable = [](const Decl *D) -> bool {
50085008
if (auto *parent =
50095009
AvailabilityInference::parentDeclForInferredAvailability(D)) {
5010-
return parent->getSemanticUnavailableAttr() != std::nullopt;
5010+
return parent->isSemanticallyUnavailable();
50115011
}
50125012
return false;
50135013
};

lib/Sema/TypeCheckDeclOverride.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1924,7 +1924,7 @@ checkOverrideUnavailability(ValueDecl *override, ValueDecl *base) {
19241924
if (auto *overrideParent = override->getDeclContext()->getAsDecl()) {
19251925
// If the parent of the override is unavailable, then the unavailability of
19261926
// the override decl is irrelevant.
1927-
if (overrideParent->getSemanticUnavailableAttr())
1927+
if (overrideParent->isSemanticallyUnavailable())
19281928
return {OverrideUnavailabilityStatus::Ignored, nullptr};
19291929
}
19301930

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1881,7 +1881,7 @@ RequirementCheck WitnessChecker::checkWitness(ValueDecl *requirement,
18811881
}
18821882

18831883
if (auto adoptingNominal = DC->getSelfNominalTypeDecl()) {
1884-
if (adoptingNominal->getSemanticUnavailableAttr())
1884+
if (adoptingNominal->isSemanticallyUnavailable())
18851885
return true;
18861886
}
18871887

0 commit comments

Comments
 (0)