Skip to content

Commit 1dc7aa5

Browse files
committed
AST: Introduce Decl::isUnavailable().
Replace calls to `AvailableAttr::isUnavailable()` with `Decl::isUnavailable()`.
1 parent 94f4b05 commit 1dc7aa5

19 files changed

+41
-26
lines changed

include/swift/AST/Decl.h

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,16 +1378,29 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl>, public Swi
13781378
/// @_originalDefinedIn attribute, this function returns this module name.
13791379
StringRef getAlternateModuleName() const;
13801380

1381-
// Is this Decl an SPI? It can be directly marked with @_spi or is defined in
1382-
// an @_spi context.
1381+
/// Is this Decl an SPI? It can be directly marked with @_spi or is defined in
1382+
/// an @_spi context.
13831383
bool isSPI() const;
13841384

1385+
/// Returns true if the attribute providing the platform availability
1386+
/// introduction for this decl is an `@_spi_available` attribute.
13851387
bool isAvailableAsSPI() const;
13861388

13871389
/// Determine whether this Decl has either Private or FilePrivate access,
13881390
/// and its DeclContext does not.
13891391
bool isOutermostPrivateOrFilePrivateScope() const;
13901392

1393+
/// Returns true if the decl is always unavailable in this compilation
1394+
/// context. For example, the decl could be marked explicitly unavailable on
1395+
/// either the current platform or in the current language mode. Returns false
1396+
/// for declarations that are only _potentially_ unavailable because of a
1397+
/// condition that could be satisfied at runtime (like requiring an operating
1398+
/// system version that is higher than the current deployment target).
1399+
///
1400+
/// Note that this query only considers the attributes that are attached
1401+
/// directly to this decl (or the extension it is declared in, if applicable).
1402+
bool isUnavailable() const;
1403+
13911404
/// Retrieve the @available attribute that provides the OS version range that
13921405
/// this declaration is available in.
13931406
///
@@ -1406,7 +1419,7 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl>, public Swi
14061419
/// the attribute.
14071420
///
14081421
/// Note that this notion of unavailability is broader than that which is
1409-
/// checked by \c AvailableAttr::isUnavailable.
1422+
/// checked by \c isUnavailable().
14101423
std::optional<std::pair<const AvailableAttr *, const Decl *>>
14111424
getSemanticUnavailableAttr(bool ignoreAppExtensions = false) const;
14121425

lib/APIDigester/ModuleAnalyzerNodes.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1767,8 +1767,8 @@ SDKContext::shouldIgnore(Decl *D, const Decl* Parent) const {
17671767
if (D->isPrivateSystemDecl(false))
17681768
return true;
17691769
}
1770-
if (AvailableAttr::isUnavailable(D))
1771-
return true;
1770+
if (D->isUnavailable())
1771+
return true;
17721772
if (auto VD = dyn_cast<ValueDecl>(D)) {
17731773
switch (getAccessLevel(VD)) {
17741774
case AccessLevel::Internal:

lib/AST/Availability.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,8 @@ bool Decl::isAvailableAsSPI() const {
486486
return AvailabilityInference::isAvailableAsSPI(this);
487487
}
488488

489+
bool Decl::isUnavailable() const { return AvailableAttr::isUnavailable(this); }
490+
489491
std::optional<AvailableAttrDeclPair>
490492
SemanticUnavailableAttrRequest::evaluate(Evaluator &evaluator, const Decl *decl,
491493
bool ignoreAppExtensions) const {

lib/AST/Decl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4377,7 +4377,7 @@ bool ValueDecl::shouldHideFromEditor() const {
43774377
getAttrs().hasAttribute<ShowInInterfaceAttr>())
43784378
return true;
43794379

4380-
if (AvailableAttr::isUnavailable(this))
4380+
if (isUnavailable())
43814381
return true;
43824382

43834383
// Hide 'swift_private' clang decls. They are imported with '__' prefix.

lib/AST/DeclContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1534,7 +1534,7 @@ bool DeclContext::isAlwaysAvailableConformanceContext() const {
15341534
if (ext == nullptr)
15351535
return true;
15361536

1537-
if (AvailableAttr::isUnavailable(ext))
1537+
if (ext->isUnavailable())
15381538
return false;
15391539

15401540
auto &ctx = getASTContext();

lib/AST/ProtocolConformanceRef.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ bool ProtocolConformanceRef::hasUnavailableConformance() const {
335335
auto concrete = getConcrete();
336336
auto *dc = concrete->getRootConformance()->getDeclContext();
337337
auto ext = dyn_cast<ExtensionDecl>(dc);
338-
if (ext && AvailableAttr::isUnavailable(ext))
338+
if (ext && ext->isUnavailable())
339339
return true;
340340

341341
// Check the conformances in the substitution map.

lib/Index/Index.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
617617

618618
bool walkToDeclPre(Decl *D, CharSourceRange Range) override {
619619
// Do not handle unavailable decls from other modules.
620-
if (IsModuleFile && AvailableAttr::isUnavailable(D))
620+
if (IsModuleFile && D->isUnavailable())
621621
return false;
622622

623623
if (!handleCustomAttrInitRefs(D))

lib/Sema/CodeSynthesis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1177,7 +1177,7 @@ static void collectNonOveriddenSuperclassInits(
11771177
continue;
11781178

11791179
// Skip unavailable superclass initializers.
1180-
if (AvailableAttr::isUnavailable(superclassCtor))
1180+
if (superclassCtor->isUnavailable())
11811181
continue;
11821182

11831183
if (!overriddenInits.count(superclassCtor))

lib/Sema/LookupVisibleDecls.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -987,13 +987,13 @@ class OverrideFilteringConsumer : public VisibleDeclConsumer {
987987
/*skipProtocolExtensionCheck*/true)) {
988988
FoundConflicting = true;
989989

990-
if (!AvailableAttr::isUnavailable(VD)) {
990+
if (!VD->isUnavailable()) {
991991
bool preferVD = (
992992
// Prefer derived requirements over their witnesses.
993993
Reason == DeclVisibilityKind::
994994
MemberOfProtocolDerivedByCurrentNominal ||
995995
// Prefer available one.
996-
AvailableAttr::isUnavailable(OtherVD) ||
996+
OtherVD->isUnavailable() ||
997997
// Prefer more accessible one.
998998
VD->getFormalAccess() > OtherVD->getFormalAccess());
999999
if (preferVD) {

lib/Sema/TypeCheckAttr.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3076,7 +3076,7 @@ SynthesizeMainFunctionRequest::evaluate(Evaluator &evaluator,
30763076

30773077
if (mainFunction->hasAsync() &&
30783078
context.LangOpts.isConcurrencyModelTaskToThread() &&
3079-
!AvailableAttr::isUnavailable(mainFunction)) {
3079+
!mainFunction->isUnavailable()) {
30803080
mainFunction->diagnose(diag::concurrency_task_to_thread_model_async_main,
30813081
"task-to-thread concurrency model");
30823082
return nullptr;
@@ -4221,7 +4221,7 @@ void AttributeChecker::visitCustomAttr(CustomAttr *attr) {
42214221
}
42224222

42234223
if (nominal->isMainActor() && Ctx.LangOpts.isConcurrencyModelTaskToThread() &&
4224-
!AvailableAttr::isUnavailable(D)) {
4224+
!D->isUnavailable()) {
42254225
SourceLoc loc;
42264226
if (attr->isImplicit()) {
42274227
loc = D->getStartLoc();
@@ -7337,7 +7337,7 @@ void AttributeChecker::visitGlobalActorAttr(GlobalActorAttr *attr) {
73377337

73387338
auto &context = nominal->getASTContext();
73397339
if (context.LangOpts.isConcurrencyModelTaskToThread() &&
7340-
!AvailableAttr::isUnavailable(nominal)) {
7340+
!nominal->isUnavailable()) {
73417341
context.Diags.diagnose(attr->getLocation(),
73427342
diag::concurrency_task_to_thread_model_global_actor,
73437343
"task-to-thread concurrency model");

0 commit comments

Comments
 (0)