Skip to content

Commit c188ab4

Browse files
committed
Remove the "@expression" attribute now that it has a better spelling
1 parent 5a9a654 commit c188ab4

File tree

7 files changed

+15
-11
lines changed

7 files changed

+15
-11
lines changed

include/swift/AST/DiagnosticsParse.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2043,6 +2043,8 @@ ERROR(macro_attribute_introduced_name_requires_argument,PointsToFirstBadToken,
20432043
"introduced name kind %0 requires a single argument '(name)'", (Identifier))
20442044
ERROR(macro_attribute_introduced_name_requires_no_argument,PointsToFirstBadToken,
20452045
"introduced name kind %0 must not have an argument", (Identifier))
2046+
WARNING(macro_expression_attribute_removed,PointsToFirstBadToken,
2047+
"@expression has been removed in favor of @freestanding(expression)", ())
20462048

20472049
ERROR(unexpected_attribute_expansion,PointsToFirstBadToken,
20482050
"unexpected token '%0' in expanded attribute list'",

lib/AST/Decl.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9825,8 +9825,6 @@ SourceRange MacroDecl::getSourceRange() const {
98259825

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

lib/Parse/ParseDecl.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3779,6 +3779,17 @@ ParserStatus Parser::parseDeclAttribute(
37793779
return makeParserSuccess();
37803780
}
37813781

3782+
// Old spelling for @freestanding(expression).
3783+
if (DK == DAK_Count && Tok.getText() == "expression") {
3784+
SourceLoc attrLoc = consumeToken();
3785+
diagnose(attrLoc, diag::macro_expression_attribute_removed)
3786+
.fixItReplace(SourceRange(AtLoc, attrLoc), "@freestanding(expression)");
3787+
return makeParserResult(MacroRoleAttr::create(
3788+
Context, AtLoc, SourceRange(AtLoc, attrLoc),
3789+
MacroSyntax::Freestanding, MacroRole::Expression, { },
3790+
/*isImplicit*/ false));
3791+
}
3792+
37823793
if (DK != DAK_Count && !DeclAttribute::shouldBeRejectedByParser(DK)) {
37833794
parseNewDeclAttribute(Attributes, AtLoc, DK, isFromClangAttribute);
37843795
return makeParserSuccess();

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(Expression)
164163
IGNORED_ATTR(Declaration)
165164
IGNORED_ATTR(MacroRole)
166165
#undef IGNORED_ATTR

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(Expression)
16301629
UNINTERESTING_ATTR(Declaration)
16311630
UNINTERESTING_ATTR(MacroRole)
16321631
#undef UNINTERESTING_ATTR

test/Macros/macros_diagnostics.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// RUN: %target-typecheck-verify-swift -enable-experimental-feature Macros -module-name MacrosTest
22

3-
@freestanding(expression) macro stringify<T>(_ value: T) -> (T, String) = #externalMacro(module: "MacroDefinition", type: "StringifyMacro")
3+
@expression macro stringify<T>(_ value: T) -> (T, String) = #externalMacro(module: "MacroDefinition", type: "StringifyMacro")
44
// expected-note@-1 2{{'stringify' declared here}}
55
// expected-warning@-2{{external macro implementation type}}
6+
// expected-warning@-3{{@expression has been removed in favor of @freestanding(expression)}}{{1-12=@freestanding(expression)}}
67
@freestanding(expression) macro missingMacro1(_: Any) = MissingModule.MissingType // expected-note{{'missingMacro1' declared here}}
78
// expected-warning@-1{{external macro definitions are now written using #externalMacro}}{{57-82=#externalMacro(module: "MissingModule", type: "MissingType")}}
89
// expected-warning@-2{{external macro implementation type}}

utils/gyb_syntax_support/AttributeKinds.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -903,12 +903,6 @@ def __init__(self, name, swift_name=None):
903903
ABIBreakingToAdd, ABIBreakingToRemove,
904904
APIBreakingToAdd, APIBreakingToRemove,
905905
code=130),
906-
907-
SimpleDeclAttribute('expression', 'Expression',
908-
OnMacro,
909-
ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIBreakingToRemove, # noqa: E501
910-
code=140),
911-
912906
DeclAttribute('declaration', 'Declaration',
913907
OnMacro, AllowMultipleAttributes,
914908
ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIBreakingToRemove, # noqa: E501

0 commit comments

Comments
 (0)