Skip to content

Commit d976ea6

Browse files
authored
Merge pull request #69578 from tshortli/module-interface-lazy-typecheck-print-semantic-attrs
AST: Print semantic attributes
2 parents 68910da + f4ed269 commit d976ea6

File tree

8 files changed

+16
-15
lines changed

8 files changed

+16
-15
lines changed

include/swift/AST/Decl.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -924,11 +924,10 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
924924
/// expansions.
925925
OrigDeclAttributes getOriginalAttrs() const;
926926

927-
/// Returns the semantic CustomAttrs attached to this declaration,
927+
/// Returns the attributes attached to this declaration,
928928
/// including attributes that are generated as the result of member
929929
/// attribute macro expansion.
930-
DeclAttributes::AttributeKindRange<CustomAttr, false>
931-
getSemanticCustomAttrs() const;
930+
DeclAttributes getExpandedAttrs() const;
932931

933932
/// Returns all semantic attributes attached to this declaration,
934933
/// including attributes that are generated as the result of member

lib/AST/ASTPrinter.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,6 +1150,8 @@ void PrintAST::printAttributes(const Decl *D) {
11501150
if (Options.SkipAttributes)
11511151
return;
11521152

1153+
auto attrs = D->getSemanticAttrs();
1154+
11531155
// Save the current number of exclude attrs to restore once we're done.
11541156
unsigned originalExcludeAttrCount = Options.ExcludeAttrList.size();
11551157

@@ -1205,7 +1207,7 @@ void PrintAST::printAttributes(const Decl *D) {
12051207
// If the declaration is implicitly @objc, print the attribute now.
12061208
if (auto VD = dyn_cast<ValueDecl>(D)) {
12071209
if (VD->isObjC() && !isa<EnumElementDecl>(VD) &&
1208-
!VD->getAttrs().hasAttribute<ObjCAttr>()) {
1210+
!attrs.hasAttribute<ObjCAttr>()) {
12091211
Printer.printAttrName("@objc");
12101212
Printer << " ";
12111213
}
@@ -1235,13 +1237,13 @@ void PrintAST::printAttributes(const Decl *D) {
12351237
Options.ExcludeAttrList.push_back(DAK_Borrowing);
12361238
}
12371239

1238-
D->getAttrs().print(Printer, Options, D);
1240+
attrs.print(Printer, Options, D);
12391241

12401242
// Print the implicit 'final' attribute.
12411243
if (auto VD = dyn_cast<ValueDecl>(D)) {
12421244
auto VarD = dyn_cast<VarDecl>(D);
12431245
if (VD->isFinal() &&
1244-
!VD->getAttrs().hasAttribute<FinalAttr>() &&
1246+
!attrs.hasAttribute<FinalAttr>() &&
12451247
// Don't print a redundant 'final' if printing a 'let' or 'static' decl.
12461248
!(VarD && VarD->isLet()) &&
12471249
getCorrectStaticSpelling(D) != StaticSpellingKind::KeywordStatic &&

lib/AST/Decl.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -375,13 +375,12 @@ OrigDeclAttributes Decl::getOriginalAttrs() const {
375375
return OrigDeclAttributes(getAttrs(), this);
376376
}
377377

378-
DeclAttributes::AttributeKindRange<CustomAttr, false>
379-
Decl::getSemanticCustomAttrs() const {
378+
DeclAttributes Decl::getExpandedAttrs() const {
380379
auto mutableThis = const_cast<Decl *>(this);
381380
(void)evaluateOrDefault(getASTContext().evaluator,
382381
ExpandMemberAttributeMacros{mutableThis}, {});
383382

384-
return getAttrs().getAttributes<CustomAttr>();
383+
return getAttrs();
385384
}
386385

387386
DeclAttributes Decl::getSemanticAttrs() const {
@@ -447,7 +446,7 @@ void Decl::visitAuxiliaryDecls(
447446

448447
void Decl::forEachAttachedMacro(MacroRole role,
449448
MacroCallback macroCallback) const {
450-
for (auto customAttrConst : getSemanticCustomAttrs()) {
449+
for (auto customAttrConst : getExpandedAttrs().getAttributes<CustomAttr>()) {
451450
auto customAttr = const_cast<CustomAttr *>(customAttrConst);
452451
auto *macroDecl = getResolvedMacro(customAttr);
453452

lib/AST/NameLookup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1725,7 +1725,7 @@ void namelookup::forEachPotentialAttachedMacro(
17251725
// We intentionally avoid calling `forEachAttachedMacro` in order to avoid
17261726
// a request cycle.
17271727
auto moduleScopeCtx = decl->getDeclContext()->getModuleScopeContext();
1728-
for (auto attrConst : decl->getSemanticCustomAttrs()) {
1728+
for (auto attrConst : decl->getExpandedAttrs().getAttributes<CustomAttr>()) {
17291729
auto *attr = const_cast<CustomAttr *>(attrConst);
17301730
UnresolvedMacroReference macroRef(attr);
17311731
auto macroName = macroRef.getMacroName();

lib/Sema/TypeCheckAccess.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1281,7 +1281,7 @@ class AccessControlChecker : public AccessControlCheckerBase,
12811281
}
12821282

12831283
void checkAttachedMacrosAccess(const Decl *D) {
1284-
for (auto customAttrC : D->getSemanticCustomAttrs()) {
1284+
for (auto customAttrC : D->getExpandedAttrs().getAttributes<CustomAttr>()) {
12851285
auto customAttr = const_cast<CustomAttr *>(customAttrC);
12861286
auto *macroDecl = D->getResolvedMacro(customAttr);
12871287
if (macroDecl) {

lib/Sema/TypeCheckAttr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1579,7 +1579,7 @@ void TypeChecker::checkDeclAttributes(Decl *D) {
15791579
llvm::SmallVector<AvailableAttr *, 4> availableAttrs;
15801580
llvm::SmallVector<BackDeployedAttr *, 4> backDeployedAttrs;
15811581
llvm::SmallVector<OriginallyDefinedInAttr*, 4> ODIAttrs;
1582-
for (auto attr : D->getSemanticAttrs()) {
1582+
for (auto attr : D->getExpandedAttrs()) {
15831583
if (!attr->isValid()) continue;
15841584

15851585
// If Attr.def says that the attribute cannot appear on this kind of

lib/Sema/TypeCheckMacros.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1664,7 +1664,8 @@ ArrayRef<unsigned>
16641664
ExpandExtensionMacros::evaluate(Evaluator &evaluator,
16651665
NominalTypeDecl *nominal) const {
16661666
SmallVector<unsigned, 2> bufferIDs;
1667-
for (auto customAttrConst : nominal->getSemanticCustomAttrs()) {
1667+
for (auto customAttrConst :
1668+
nominal->getExpandedAttrs().getAttributes<CustomAttr>()) {
16681669
auto customAttr = const_cast<CustomAttr *>(customAttrConst);
16691670
auto *macro = nominal->getResolvedMacro(customAttr);
16701671

lib/Sema/TypeCheckPropertyWrapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ AttachedPropertyWrappersRequest::evaluate(Evaluator &evaluator,
438438
auto dc = var->getDeclContext();
439439
llvm::TinyPtrVector<CustomAttr *> result;
440440

441-
for (auto attr : var->getSemanticCustomAttrs()) {
441+
for (auto attr : var->getExpandedAttrs().getAttributes<CustomAttr>()) {
442442
auto mutableAttr = const_cast<CustomAttr *>(attr);
443443
// Figure out which nominal declaration this custom attribute refers to.
444444
auto *nominal = evaluateOrDefault(

0 commit comments

Comments
 (0)