Skip to content

Commit af7ce9e

Browse files
committed
[Macros] Remove the @declaration attribute.
We have @freestanding working appropriately now.
1 parent c188ab4 commit af7ce9e

19 files changed

+26
-224
lines changed

include/swift/AST/Attr.h

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2307,40 +2307,6 @@ class ObjCImplementationAttr final : public DeclAttribute {
23072307
}
23082308
};
23092309

2310-
class DeclarationAttr final
2311-
: public DeclAttribute,
2312-
private llvm::TrailingObjects<DeclarationAttr, MacroIntroducedDeclName> {
2313-
friend TrailingObjects;
2314-
2315-
MacroRole role;
2316-
unsigned numPeerNames, numMemberNames;
2317-
2318-
DeclarationAttr(SourceLoc atLoc, SourceRange range, MacroRole role,
2319-
ArrayRef<MacroIntroducedDeclName> peerNames,
2320-
ArrayRef<MacroIntroducedDeclName> memberNames,
2321-
bool implicit);
2322-
2323-
public:
2324-
static DeclarationAttr *create(ASTContext &ctx, SourceLoc atLoc,
2325-
SourceRange range, MacroRole role,
2326-
ArrayRef<MacroIntroducedDeclName> peerNames,
2327-
ArrayRef<MacroIntroducedDeclName> memberNames,
2328-
bool implicit);
2329-
2330-
size_t numTrailingObjects(OverloadToken<MacroIntroducedDeclName>) const {
2331-
return numPeerNames + numMemberNames;
2332-
}
2333-
2334-
MacroRole getMacroRole() const { return role; }
2335-
ArrayRef<MacroIntroducedDeclName> getPeerAndMemberNames() const;
2336-
ArrayRef<MacroIntroducedDeclName> getPeerNames() const;
2337-
ArrayRef<MacroIntroducedDeclName> getMemberNames() const;
2338-
2339-
static bool classof(const DeclAttribute *DA) {
2340-
return DA->getKind() == DAK_Declaration;
2341-
}
2342-
};
2343-
23442310
/// A macro role attribute, spelled with either @attached or @freestanding,
23452311
/// which declares one of the roles that a given macro can inhabit.
23462312
class MacroRoleAttr final

include/swift/AST/MacroDeclaration.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ enum class MacroRole: uint32_t {
3939
/// in the source code.
4040
Expression = 0x01,
4141
/// A freestanding declaration macro.
42-
FreestandingDeclaration = 0x02,
42+
Declaration = 0x02,
4343
/// An attached macro that declares accessors for a variable or subscript
4444
/// declaration.
4545
Accessor = 0x04,

include/swift/Parse/Parser.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,10 +1101,6 @@ class Parser {
11011101
bool parseDocumentationAttributeArgument(Optional<StringRef> &Metadata,
11021102
Optional<AccessLevel> &Visibility);
11031103

1104-
/// Parse the @declaration attribute.
1105-
ParserResult<DeclarationAttr> parseDeclarationAttribute(SourceLoc AtLoc,
1106-
SourceLoc Loc);
1107-
11081104
/// Parse the @attached or @freestanding attribute that specifies a macro
11091105
/// role.
11101106
ParserResult<MacroRoleAttr> parseMacroRoleAttribute(

lib/AST/ASTScopeCreation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ ASTSourceFileScope::ASTSourceFileScope(SourceFile *SF,
255255
// Determine the parent source location based on the macro role.
256256
switch (*macroRole) {
257257
case MacroRole::Expression:
258-
case MacroRole::FreestandingDeclaration:
258+
case MacroRole::Declaration:
259259
case MacroRole::Accessor:
260260
case MacroRole::MemberAttribute:
261261
parentLoc = expansion.getStartLoc();

lib/AST/Attr.cpp

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,15 +1311,6 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options,
13111311
break;
13121312
}
13131313

1314-
case DAK_Declaration: {
1315-
Printer.printAttrName("@declaration");
1316-
Printer << "(";
1317-
auto Attr = cast<DeclarationAttr>(this);
1318-
Printer << getMacroRoleString(Attr->getMacroRole());
1319-
Printer << ")";
1320-
break;
1321-
}
1322-
13231314
case DAK_MacroRole: {
13241315
auto Attr = cast<MacroRoleAttr>(this);
13251316
switch (Attr->getMacroSyntax()) {
@@ -1526,8 +1517,6 @@ StringRef DeclAttribute::getAttrName() const {
15261517
return "_expose";
15271518
case DAK_Documentation:
15281519
return "_documentation";
1529-
case DAK_Declaration:
1530-
return "declaration";
15311520
case DAK_MacroRole:
15321521
switch (cast<MacroRoleAttr>(this)->getMacroSyntax()) {
15331522
case MacroSyntax::Freestanding:
@@ -2373,52 +2362,6 @@ bool CustomAttr::isAttachedMacro(const Decl *decl) const {
23732362
return macroDecl != nullptr;
23742363
}
23752364

2376-
DeclarationAttr::DeclarationAttr(SourceLoc atLoc, SourceRange range,
2377-
MacroRole role,
2378-
ArrayRef<MacroIntroducedDeclName> peerNames,
2379-
ArrayRef<MacroIntroducedDeclName> memberNames,
2380-
bool implicit)
2381-
: DeclAttribute(DAK_Declaration, atLoc, range, implicit),
2382-
role(role), numPeerNames(peerNames.size()),
2383-
numMemberNames(memberNames.size()) {
2384-
auto *trailingNamesBuffer = getTrailingObjects<MacroIntroducedDeclName>();
2385-
std::uninitialized_copy(peerNames.begin(), peerNames.end(),
2386-
trailingNamesBuffer);
2387-
std::uninitialized_copy(memberNames.begin(), memberNames.end(),
2388-
trailingNamesBuffer + peerNames.size());
2389-
}
2390-
2391-
DeclarationAttr *
2392-
DeclarationAttr::create(ASTContext &ctx, SourceLoc atLoc, SourceRange range,
2393-
MacroRole role,
2394-
ArrayRef<MacroIntroducedDeclName> peerNames,
2395-
ArrayRef<MacroIntroducedDeclName> memberNames,
2396-
bool implicit) {
2397-
unsigned size = totalSizeToAlloc<MacroIntroducedDeclName>(
2398-
peerNames.size() + memberNames.size());
2399-
auto *mem = ctx.Allocate(size, alignof(DeclarationAttr));
2400-
return new (mem) DeclarationAttr(atLoc, range, role, peerNames,
2401-
memberNames, implicit);
2402-
}
2403-
2404-
ArrayRef<MacroIntroducedDeclName> DeclarationAttr::getPeerAndMemberNames() const {
2405-
return {
2406-
getTrailingObjects<MacroIntroducedDeclName>(),
2407-
numPeerNames + numMemberNames
2408-
};
2409-
}
2410-
2411-
ArrayRef<MacroIntroducedDeclName> DeclarationAttr::getPeerNames() const {
2412-
return {getTrailingObjects<MacroIntroducedDeclName>(), numPeerNames};
2413-
}
2414-
2415-
ArrayRef<MacroIntroducedDeclName> DeclarationAttr::getMemberNames() const {
2416-
return {
2417-
getTrailingObjects<MacroIntroducedDeclName>() + numPeerNames,
2418-
numMemberNames
2419-
};
2420-
}
2421-
24222365
MacroRoleAttr::MacroRoleAttr(SourceLoc atLoc, SourceRange range,
24232366
MacroSyntax syntax, MacroRole role,
24242367
ArrayRef<MacroIntroducedDeclName> names,

lib/AST/Decl.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9717,7 +9717,7 @@ StringRef swift::getMacroRoleString(MacroRole role) {
97179717
case MacroRole::Expression:
97189718
return "expression";
97199719

9720-
case MacroRole::FreestandingDeclaration:
9720+
case MacroRole::Declaration:
97219721
return "freestanding";
97229722

97239723
case MacroRole::Accessor:
@@ -9769,7 +9769,7 @@ StringRef swift::getMacroIntroducedDeclNameString(
97699769
static MacroRoles freestandingMacroRoles =
97709770
(MacroRoles() |
97719771
MacroRole::Expression |
9772-
MacroRole::FreestandingDeclaration);
9772+
MacroRole::Declaration);
97739773
static MacroRoles attachedMacroRoles = (MacroRoles() |
97749774
MacroRole::Accessor |
97759775
MacroRole::MemberAttribute |
@@ -9825,8 +9825,6 @@ SourceRange MacroDecl::getSourceRange() const {
98259825

98269826
MacroRoles MacroDecl::getMacroRoles() const {
98279827
MacroRoles contexts = None;
9828-
for (auto attr : getAttrs().getAttributes<DeclarationAttr>())
9829-
contexts |= attr->getMacroRole();
98309828
for (auto attr : getAttrs().getAttributes<MacroRoleAttr>())
98319829
contexts |= attr->getMacroRole();
98329830
return contexts;

lib/AST/Module.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,7 @@ Optional<MacroRole> SourceFile::getFulfilledMacroRole() const {
907907
return MacroRole::Expression;
908908

909909
case GeneratedSourceInfo::FreestandingDeclMacroExpansion:
910-
return MacroRole::FreestandingDeclaration;
910+
return MacroRole::Declaration;
911911

912912
case GeneratedSourceInfo::AccessorMacroExpansion:
913913
return MacroRole::Accessor;

lib/Parse/ParseDecl.cpp

Lines changed: 5 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2145,39 +2145,6 @@ Parser::parseDocumentationAttribute(SourceLoc AtLoc, SourceLoc Loc) {
21452145
return makeParserResult(new (Context) DocumentationAttr(Loc, range, FinalMetadata, Visibility, false));
21462146
}
21472147

2148-
ParserResult<DeclarationAttr>
2149-
Parser::parseDeclarationAttribute(SourceLoc AtLoc, SourceLoc Loc) {
2150-
StringRef attrName = "declaration";
2151-
bool isDeclModifier = DeclAttribute::isDeclModifier(DAK_Declaration);
2152-
if (!consumeIf(tok::l_paren)) {
2153-
diagnose(Tok, diag::attr_expected_lparen, attrName, isDeclModifier);
2154-
return makeParserError();
2155-
}
2156-
if (Tok.isNot(tok::identifier)) {
2157-
diagnose(Tok, diag::declaration_attr_expected_kind);
2158-
errorAndSkipUntilConsumeRightParen(*this, attrName);
2159-
return makeParserError();
2160-
}
2161-
auto kind = llvm::StringSwitch<Optional<MacroRole>>(Tok.getText())
2162-
.Case("freestanding", MacroRole::FreestandingDeclaration)
2163-
.Default(None);
2164-
if (!kind) {
2165-
diagnose(Tok, diag::declaration_attr_expected_kind);
2166-
errorAndSkipUntilConsumeRightParen(*this, attrName);
2167-
return makeParserError();
2168-
}
2169-
consumeToken(tok::identifier);
2170-
// TODO: Parse peer and member names.
2171-
SourceLoc rParenLoc;
2172-
if (!consumeIf(tok::r_paren, rParenLoc)) {
2173-
diagnose(Tok, diag::attr_expected_rparen, attrName, isDeclModifier);
2174-
return makeParserError();
2175-
}
2176-
SourceRange range(Loc, rParenLoc);
2177-
return makeParserResult(DeclarationAttr::create(
2178-
Context, AtLoc, range, *kind, {}, {}, /*isImplicit*/ false));
2179-
}
2180-
21812148
/// If the given argument is effectively a bare identifier, extract that
21822149
/// identifier.
21832150
static Optional<Identifier> getIdentifierFromArgument(Argument argument) {
@@ -2222,6 +2189,7 @@ static Optional<MacroRole> getMacroRole(
22222189

22232190
// Match the role string to the known set of roles.
22242191
auto role = llvm::StringSwitch<Optional<MacroRole>>(roleName->str())
2192+
.Case("declaration", MacroRole::Declaration)
22252193
.Case("expression", MacroRole::Expression)
22262194
.Case("accessor", MacroRole::Accessor)
22272195
.Case("memberAttributes", MacroRole::MemberAttribute)
@@ -3413,14 +3381,6 @@ bool Parser::parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc,
34133381
return false;
34143382
break;
34153383
}
3416-
case DAK_Declaration: {
3417-
auto Attr = parseDeclarationAttribute(AtLoc, Loc);
3418-
if (Attr.isNonNull())
3419-
Attributes.add(Attr.get());
3420-
else
3421-
return false;
3422-
break;
3423-
}
34243384
case DAK_MacroRole: {
34253385
auto syntax = (AttrName == "freestanding" ? MacroSyntax::Freestanding
34263386
: MacroSyntax::Attached);
@@ -3784,10 +3744,12 @@ ParserStatus Parser::parseDeclAttribute(
37843744
SourceLoc attrLoc = consumeToken();
37853745
diagnose(attrLoc, diag::macro_expression_attribute_removed)
37863746
.fixItReplace(SourceRange(AtLoc, attrLoc), "@freestanding(expression)");
3787-
return makeParserResult(MacroRoleAttr::create(
3747+
auto attr = MacroRoleAttr::create(
37883748
Context, AtLoc, SourceRange(AtLoc, attrLoc),
37893749
MacroSyntax::Freestanding, MacroRole::Expression, { },
3790-
/*isImplicit*/ false));
3750+
/*isImplicit*/ false);
3751+
Attributes.add(attr);
3752+
return makeParserSuccess();
37913753
}
37923754

37933755
if (DK != DAK_Count && !DeclAttribute::shouldBeRejectedByParser(DK)) {

lib/Sema/TypeCheckAttr.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ class AttributeChecker : public AttributeVisitor<AttributeChecker> {
160160
IGNORED_ATTR(Preconcurrency)
161161
IGNORED_ATTR(BackDeploy)
162162
IGNORED_ATTR(Documentation)
163-
IGNORED_ATTR(Declaration)
164163
IGNORED_ATTR(MacroRole)
165164
#undef IGNORED_ATTR
166165

lib/Sema/TypeCheckDeclOverride.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1626,7 +1626,6 @@ namespace {
16261626

16271627
UNINTERESTING_ATTR(RuntimeMetadata)
16281628

1629-
UNINTERESTING_ATTR(Declaration)
16301629
UNINTERESTING_ATTR(MacroRole)
16311630
#undef UNINTERESTING_ATTR
16321631

0 commit comments

Comments
 (0)