Skip to content

Commit 2358712

Browse files
committed
AST/Sema: Remove DeclAttr::isUnavailable().
Update callers to use `Decl::isUnavailable()` instead.
1 parent 1dc7aa5 commit 2358712

16 files changed

+48
-67
lines changed

include/swift/AST/Attr.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2931,10 +2931,6 @@ class DeclAttributes {
29312931
return UnaryOperatorKind::None;
29322932
}
29332933

2934-
bool isUnavailable(const ASTContext &ctx) const {
2935-
return getUnavailable(ctx) != nullptr;
2936-
}
2937-
29382934
bool isDeprecated(const ASTContext &ctx) const {
29392935
return getDeprecated(ctx) != nullptr;
29402936
}

lib/AST/ASTPrinter.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2153,7 +2153,7 @@ bool isNonSendableExtension(const Decl *D) {
21532153
ASTContext &ctx = D->getASTContext();
21542154

21552155
const ExtensionDecl *ED = dyn_cast<ExtensionDecl>(D);
2156-
if (!ED || !ED->getAttrs().isUnavailable(ctx))
2156+
if (!ED || !ED->isUnavailable())
21572157
return false;
21582158

21592159
auto nonSendable =
@@ -2193,8 +2193,7 @@ bool ShouldPrintChecker::shouldPrint(const Decl *D,
21932193
return false;
21942194
}
21952195

2196-
if (Options.SkipUnavailable &&
2197-
D->getAttrs().isUnavailable(D->getASTContext()))
2196+
if (Options.SkipUnavailable && D->isUnavailable())
21982197
return false;
21992198
}
22002199

lib/AST/ASTVerifier.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2931,7 +2931,7 @@ class Verifier : public ASTWalker {
29312931

29322932
if (auto req = dyn_cast<ValueDecl>(member)) {
29332933
if (!normal->hasWitness(req)) {
2934-
if ((req->getAttrs().isUnavailable(Ctx) ||
2934+
if ((req->isUnavailable() ||
29352935
req->getAttrs().hasAttribute<OptionalAttr>()) &&
29362936
proto->isObjC()) {
29372937
continue;

lib/AST/NameLookup.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,8 @@ enum class ConstructorComparison {
364364
static ConstructorComparison compareConstructors(ConstructorDecl *ctor1,
365365
ConstructorDecl *ctor2,
366366
const swift::ASTContext &ctx) {
367-
bool available1 = !ctor1->getAttrs().isUnavailable(ctx);
368-
bool available2 = !ctor2->getAttrs().isUnavailable(ctx);
367+
bool available1 = !ctor1->isUnavailable();
368+
bool available2 = !ctor2->isUnavailable();
369369

370370
// An unavailable initializer is always worse than an available initializer.
371371
if (available1 < available2)
@@ -560,15 +560,14 @@ static void recordShadowedDeclsAfterTypeMatch(
560560

561561
// If one declaration is available and the other is not, prefer the
562562
// available one.
563-
if (firstDecl->getAttrs().isUnavailable(ctx) !=
564-
secondDecl->getAttrs().isUnavailable(ctx)) {
565-
if (firstDecl->getAttrs().isUnavailable(ctx)) {
566-
shadowed.insert(firstDecl);
567-
break;
568-
} else {
569-
shadowed.insert(secondDecl);
570-
continue;
571-
}
563+
if (firstDecl->isUnavailable() != secondDecl->isUnavailable()) {
564+
if (firstDecl->isUnavailable()) {
565+
shadowed.insert(firstDecl);
566+
break;
567+
} else {
568+
shadowed.insert(secondDecl);
569+
continue;
570+
}
572571
}
573572

574573
// Don't apply module-shadowing rules to members of protocol types.

lib/AST/ProtocolConformance.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -731,12 +731,11 @@ void NormalProtocolConformance::setWitness(ValueDecl *requirement,
731731
// funcs; there seems to be a problem that we mark completed, but
732732
// afterwards will record the thunk witness;
733733
(dyn_cast<FuncDecl>(requirement)
734-
? (dyn_cast<FuncDecl>(requirement)->isDistributed() ||
735-
dyn_cast<FuncDecl>(requirement)->isDistributedThunk())
736-
: false) ||
734+
? (dyn_cast<FuncDecl>(requirement)->isDistributed() ||
735+
dyn_cast<FuncDecl>(requirement)->isDistributedThunk())
736+
: false) ||
737737
requirement->getAttrs().hasAttribute<OptionalAttr>() ||
738-
requirement->getAttrs().isUnavailable(
739-
requirement->getASTContext())) &&
738+
requirement->isUnavailable()) &&
740739
"Conformance already complete?");
741740
Mapping[requirement] = witness;
742741
}

lib/ClangImporter/ImportDecl.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3219,7 +3219,7 @@ namespace {
32193219
// Don't import unavailable fields that have no associated storage.
32203220
// TODO: is there any way we could bail here before we allocate/construct
32213221
// the VarDecl?
3222-
if (result->getAttrs().isUnavailable(Impl.SwiftContext))
3222+
if (result->isUnavailable())
32233223
return nullptr;
32243224

32253225
return result;
@@ -6296,7 +6296,7 @@ Decl *SwiftDeclConverter::importEnumCase(const clang::EnumConstantDecl *decl,
62966296

62976297
// If the correct declaration was unavailable, don't map to it.
62986298
// FIXME: This eliminates spurious errors, but affects QoI.
6299-
if (correctCase->getAttrs().isUnavailable(Impl.SwiftContext))
6299+
if (correctCase->isUnavailable())
63006300
return nullptr;
63016301

63026302
auto compatibilityCase =
@@ -6358,7 +6358,7 @@ SwiftDeclConverter::importOptionConstant(const clang::EnumConstantDecl *decl,
63586358
// not operate as a set-like member. Mark them unavailable with a message
63596359
// that says that they should be used as [].
63606360
if (decl->getInitVal() == 0 && !nameInfo.hasCustomName() &&
6361-
!CD->getAttrs().isUnavailable(Impl.SwiftContext)) {
6361+
!CD->isUnavailable()) {
63626362
/// Create an AvailableAttr that indicates specific availability
63636363
/// for all platforms.
63646364
auto attr = AvailableAttr::createPlatformAgnostic(
@@ -6835,8 +6835,7 @@ bool SwiftDeclConverter::existingConstructorIsWorse(
68356835

68366836
// If one constructor is unavailable in Swift and the other is
68376837
// not, keep the available one.
6838-
bool existingIsUnavailable =
6839-
existingCtor->getAttrs().isUnavailable(Impl.SwiftContext);
6838+
bool existingIsUnavailable = existingCtor->isUnavailable();
68406839
bool newIsUnavailable = Impl.isUnavailableInSwift(objcMethod);
68416840
if (existingIsUnavailable != newIsUnavailable)
68426841
return existingIsUnavailable;
@@ -6951,9 +6950,7 @@ ConstructorDecl *SwiftDeclConverter::importConstructor(
69516950
ctors = found->second;
69526951

69536952
for (auto ctor : ctors) {
6954-
if (ctor->isInvalid() ||
6955-
ctor->getAttrs().isUnavailable(Impl.SwiftContext) ||
6956-
!ctor->getClangDecl())
6953+
if (ctor->isInvalid() || ctor->isUnavailable() || !ctor->getClangDecl())
69576954
continue;
69586955

69596956
// If the types don't match, this is a different constructor with
@@ -7358,7 +7355,7 @@ SwiftDeclConverter::importSubscript(Decl *decl,
73587355

73597356
// Local function to mark the setter unavailable.
73607357
auto makeSetterUnavailable = [&] {
7361-
if (setter && !setter->getAttrs().isUnavailable(Impl.SwiftContext))
7358+
if (setter && !setter->isUnavailable())
73627359
Impl.markUnavailable(setter, "use subscripting");
73637360
};
73647361

@@ -7503,7 +7500,7 @@ SwiftDeclConverter::importSubscript(Decl *decl,
75037500
Impl.Subscripts[{getter, nullptr}] = subscript;
75047501

75057502
// Make the getter/setter methods unavailable.
7506-
if (!getter->getAttrs().isUnavailable(Impl.SwiftContext))
7503+
if (!getter->isUnavailable())
75077504
Impl.markUnavailable(getter, "use subscripting");
75087505
makeSetterUnavailable();
75097506

@@ -8571,7 +8568,7 @@ void ClangImporter::Implementation::importAttributes(
85718568

85728569
// Scan through Clang attributes and map them onto Swift
85738570
// equivalents.
8574-
bool AnyUnavailable = MappedDecl->getAttrs().isUnavailable(C);
8571+
bool AnyUnavailable = MappedDecl->isUnavailable();
85758572
for (clang::NamedDecl::attr_iterator AI = ClangDecl->attr_begin(),
85768573
AE = ClangDecl->attr_end(); AI != AE; ++AI) {
85778574
//

lib/ClangImporter/ImportType.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,7 @@ namespace {
907907
#endif
908908

909909
// If the imported typealias is unavailable, return the underlying type.
910-
if (decl->getAttrs().isUnavailable(Impl.SwiftContext))
910+
if (decl->isUnavailable())
911911
return underlyingResult;
912912

913913
return { mappedType, underlyingResult.Hint };

lib/Sema/CSDiagnostics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4246,7 +4246,7 @@ findImportedCaseWithMatchingSuffix(Type instanceTy, DeclNameRef name) {
42464246
ASTContext &ctx = a->getASTContext();
42474247

42484248
// Is one more available than the other?
4249-
WORSE(->getAttrs().isUnavailable(ctx));
4249+
WORSE(->isUnavailable());
42504250
WORSE(->getAttrs().isDeprecated(ctx));
42514251

42524252
// Does one have a shorter name (so the non-matching prefix is shorter)?

lib/Sema/DerivedConformanceCodable.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,7 @@ deriveBodyEncodable_enum_encode(AbstractFunctionDecl *encodeDecl, void *) {
11101110
-> std::tuple<EnumElementDecl *, BraceStmt *> {
11111111
SmallVector<ASTNode, 3> caseStatements;
11121112

1113-
if (elt->getAttrs().isUnavailable(C)) {
1113+
if (elt->isUnavailable()) {
11141114
// This case is not encodable because it is unavailable and therefore
11151115
// should not be instantiable at runtime. Skipping this case will
11161116
// result in the SIL pipeline giving the switch a default case for
@@ -1713,7 +1713,7 @@ deriveBodyDecodable_enum_init(AbstractFunctionDecl *initDecl, void *) {
17131713
if (!codingKeyCase)
17141714
return std::make_tuple(nullptr, nullptr);
17151715

1716-
if (elt->getAttrs().isUnavailable(C)) {
1716+
if (elt->isUnavailable()) {
17171717
// generate:
17181718
// throw DecodingError.dataCorrupted(
17191719
// DecodingError.Context(

lib/Sema/DerivedConformanceCodingKey.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ deriveBodyCodingKey_init_stringValue(AbstractFunctionDecl *initDecl, void *) {
275275
for (auto *elt : elements) {
276276
// Skip the cases that would return unavailable elements since those can't
277277
// be instantiated at runtime.
278-
if (elt->getAttrs().isUnavailable(C))
278+
if (elt->isUnavailable())
279279
continue;
280280

281281
auto *litExpr = new (C) StringLiteralExpr(elt->getNameStr(), SourceRange(),

0 commit comments

Comments
 (0)