Skip to content

Commit b12ab0b

Browse files
authored
Merge pull request swiftlang#37773 from DougGregor/remove-actorindependent-less
2 parents 5f41f94 + b4fa392 commit b12ab0b

26 files changed

+96
-389
lines changed

include/swift/AST/Attr.def

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -574,12 +574,7 @@ CONTEXTUAL_SIMPLE_DECL_ATTR(actor, Actor,
574574
APIBreakingToAdd | APIBreakingToRemove,
575575
102)
576576

577-
DECL_ATTR(actorIndependent, ActorIndependent,
578-
OnClass | OnStruct | OnEnum | OnExtension | OnFunc | OnConstructor |
579-
OnVar | OnSubscript | ConcurrencyOnly |
580-
ABIBreakingToAdd | ABIBreakingToRemove |
581-
APIBreakingToAdd | APIBreakingToRemove,
582-
103)
577+
// Unused attribute 103
583578

584579
SIMPLE_DECL_ATTR(globalActor, GlobalActor,
585580
OnClass | OnStruct | OnEnum | ConcurrencyOnly |

include/swift/AST/Attr.h

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,6 @@ class DeclAttribute : public AttributeBase {
162162
kind : NumInlineKindBits
163163
);
164164

165-
SWIFT_INLINE_BITFIELD(ActorIndependentAttr, DeclAttribute, NumActorIndependentKindBits,
166-
kind : NumActorIndependentKindBits
167-
);
168-
169165
SWIFT_INLINE_BITFIELD(OptimizeAttr, DeclAttribute, NumOptimizationModeBits,
170166
mode : NumOptimizationModeBits
171167
);
@@ -1223,25 +1219,6 @@ class ReferenceOwnershipAttr : public DeclAttribute {
12231219
}
12241220
};
12251221

1226-
/// Represents an actorIndependent/actorIndependent(unsafe) decl attribute.
1227-
class ActorIndependentAttr : public DeclAttribute {
1228-
public:
1229-
ActorIndependentAttr(SourceLoc atLoc, SourceRange range, ActorIndependentKind kind)
1230-
: DeclAttribute(DAK_ActorIndependent, atLoc, range, /*Implicit=*/false) {
1231-
Bits.ActorIndependentAttr.kind = unsigned(kind);
1232-
}
1233-
1234-
ActorIndependentAttr(ActorIndependentKind kind, bool IsImplicit=false)
1235-
: ActorIndependentAttr(SourceLoc(), SourceRange(), kind) {
1236-
setImplicit(IsImplicit);
1237-
}
1238-
1239-
ActorIndependentKind getKind() const { return ActorIndependentKind(Bits.ActorIndependentAttr.kind); }
1240-
static bool classof(const DeclAttribute *DA) {
1241-
return DA->getKind() == DAK_ActorIndependent;
1242-
}
1243-
};
1244-
12451222
/// Defines the attribute that we use to model documentation comments.
12461223
class RawDocCommentAttr : public DeclAttribute {
12471224
/// Source range of the attached comment. This comment is located before

include/swift/AST/AttrKind.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,6 @@ enum : unsigned { NumInlineKindBits =
8080
countBitsUsed(static_cast<unsigned>(InlineKind::Last_InlineKind)) };
8181

8282

83-
/// Indicates whether an actorIndependent decl is unsafe or not
84-
enum class ActorIndependentKind : uint8_t {
85-
Safe = 0,
86-
Unsafe = 1,
87-
Last_InlineKind = Unsafe
88-
};
89-
90-
enum : unsigned { NumActorIndependentKindBits =
91-
countBitsUsed(static_cast<unsigned>(ActorIndependentKind::Last_InlineKind)) };
92-
9383
/// This enum represents the possible values of the @_effects attribute.
9484
/// These values are ordered from the strongest guarantee to the weakest,
9585
/// so please do not reorder existing values.

include/swift/AST/DiagnosticsParse.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,6 +1428,8 @@ ERROR(attr_renamed, none,
14281428
"'@%0' has been renamed to '@%1'", (StringRef, StringRef))
14291429
WARNING(attr_renamed_warning, none,
14301430
"'@%0' has been renamed to '@%1'", (StringRef, StringRef))
1431+
WARNING(attr_renamed_to_modifier_warning, none,
1432+
"'@%0' has been renamed to '%1'", (StringRef, StringRef))
14311433
ERROR(attr_name_close_match, none,
14321434
"no attribute named '@%0'; did you mean '@%1'?", (StringRef, StringRef))
14331435
ERROR(attr_unsupported_on_target, none,

include/swift/AST/DiagnosticsSema.def

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4520,23 +4520,12 @@ ERROR(concurrent_value_inherit,none,
45204520
"%select{| other than 'NSObject'}0",
45214521
(bool, DeclName))
45224522

4523-
ERROR(actorindependent_let,none,
4524-
"'@actorIndependent' is meaningless on 'let' declarations because "
4525-
"they are immutable",
4526-
())
4527-
ERROR(actorindependent_mutable_storage,none,
4528-
"'@actorIndependent' can not be applied to stored properties",
4529-
())
4530-
ERROR(actorindependent_local_var,none,
4531-
"'@actorIndependent' can not be applied to local variables",
4532-
())
4533-
45344523
ERROR(nonisolated_let,none,
45354524
"'nonisolated' is meaningless on 'let' declarations because "
45364525
"they are immutable",
45374526
())
45384527
ERROR(nonisolated_mutable_storage,none,
4539-
"nonisolated' can not be applied to stored properties",
4528+
"'nonisolated' can not be applied to stored properties",
45404529
())
45414530
ERROR(nonisolated_local_var,none,
45424531
"'nonisolated' can not be applied to local variables",

lib/AST/Attr.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,6 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options,
790790
case DAK_ReferenceOwnership:
791791
case DAK_Effects:
792792
case DAK_Optimize:
793-
case DAK_ActorIndependent:
794793
if (DeclAttribute::isDeclModifier(getKind())) {
795794
Printer.printKeyword(getAttrName(), Options);
796795
} else if (Options.IsForSwiftInterface && getKind() == DAK_ResultBuilder) {
@@ -1178,15 +1177,6 @@ StringRef DeclAttribute::getAttrName() const {
11781177
}
11791178
llvm_unreachable("Invalid inline kind");
11801179
}
1181-
case DAK_ActorIndependent: {
1182-
switch (cast<ActorIndependentAttr>(this)->getKind()) {
1183-
case ActorIndependentKind::Safe:
1184-
return "actorIndependent";
1185-
case ActorIndependentKind::Unsafe:
1186-
return "actorIndependent(unsafe)";
1187-
}
1188-
llvm_unreachable("Invalid actorIndependent kind");
1189-
}
11901180
case DAK_Optimize: {
11911181
switch (cast<OptimizeAttr>(this)->getMode()) {
11921182
case OptimizationMode::NoOptimization:

lib/ClangImporter/ImportDecl.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8706,6 +8706,14 @@ void ClangImporter::Implementation::importAttributes(
87068706
continue;
87078707
}
87088708

8709+
// Hard-code @actorIndependent, until Objective-C clients start
8710+
// using nonisolated.
8711+
if (swiftAttr->getAttribute() == "@actorIndependent") {
8712+
auto attr = new (SwiftContext) NonisolatedAttr(/*isImplicit=*/true);
8713+
MappedDecl->getAttrs().add(attr);
8714+
continue;
8715+
}
8716+
87098717
// Dig out a buffer with the attribute text.
87108718
unsigned bufferID = getClangSwiftAttrSourceBuffer(
87118719
swiftAttr->getAttribute());
@@ -9630,9 +9638,8 @@ ClangImporter::Implementation::createConstant(Identifier name, DeclContext *dc,
96309638

96319639
// Mark the function transparent so that we inline it away completely.
96329640
func->getAttrs().add(new (C) TransparentAttr(/*implicit*/ true));
9633-
auto actorIndependentAttr = new (C) ActorIndependentAttr(
9634-
ActorIndependentKind::Unsafe, /*IsImplicit=*/true);
9635-
var->getAttrs().add(actorIndependentAttr);
9641+
auto nonisolatedAttr = new (C) NonisolatedAttr(/*IsImplicit=*/true);
9642+
var->getAttrs().add(nonisolatedAttr);
96369643

96379644
// Set the function up as the getter.
96389645
makeComputed(var, func, nullptr);

lib/Parse/ParseDecl.cpp

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1784,45 +1784,6 @@ bool Parser::parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc,
17841784
break;
17851785
}
17861786

1787-
case DAK_ActorIndependent: {
1788-
// if no option is provided, then it's the 'safe' version.
1789-
if (!consumeIf(tok::l_paren)) {
1790-
if (!DiscardAttribute) {
1791-
AttrRange = SourceRange(Loc, Tok.getRange().getStart());
1792-
Attributes.add(new (Context) ActorIndependentAttr(AtLoc, AttrRange,
1793-
ActorIndependentKind::Safe));
1794-
}
1795-
break;
1796-
}
1797-
1798-
// otherwise, make sure it looks like an identifier.
1799-
if (Tok.isNot(tok::identifier)) {
1800-
diagnose(Loc, diag::attr_expected_option_such_as, AttrName, "unsafe");
1801-
return false;
1802-
}
1803-
1804-
// make sure the identifier is 'unsafe'
1805-
if (Tok.getText() != "unsafe") {
1806-
diagnose(Loc, diag::attr_unknown_option, Tok.getText(), AttrName);
1807-
return false;
1808-
}
1809-
1810-
consumeToken(tok::identifier);
1811-
AttrRange = SourceRange(Loc, Tok.getRange().getStart());
1812-
1813-
if (!consumeIf(tok::r_paren)) {
1814-
diagnose(Loc, diag::attr_expected_rparen, AttrName,
1815-
DeclAttribute::isDeclModifier(DK));
1816-
return false;
1817-
}
1818-
1819-
if (!DiscardAttribute)
1820-
Attributes.add(new (Context) ActorIndependentAttr(AtLoc, AttrRange,
1821-
ActorIndependentKind::Unsafe));
1822-
1823-
break;
1824-
}
1825-
18261787
case DAK_Optimize: {
18271788
if (!consumeIf(tok::l_paren)) {
18281789
diagnose(Loc, diag::attr_expected_lparen, AttrName,
@@ -2745,7 +2706,7 @@ bool Parser::parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc,
27452706
.highlight(DuplicateAttribute->getRange());
27462707
}
27472708

2748-
// If this is a decl modifier spelled with an @, emit an error and remove it
2709+
// If this is a decl modifier spelled with an @, emit an error and remove it
27492710
// with a fixit.
27502711
if (AtLoc.isValid() && DeclAttribute::isDeclModifier(DK))
27512712
diagnose(AtLoc, diag::cskeyword_not_attribute, AttrName).fixItRemove(AtLoc);
@@ -3028,6 +2989,16 @@ ParserStatus Parser::parseDeclAttribute(
30282989
checkInvalidAttrName(
30292990
"concurrent", "Sendable", DAK_Sendable, diag::attr_renamed_warning);
30302991

2992+
// Historical name for 'nonisolated'.
2993+
if (DK == DAK_Count && Tok.getText() == "actorIndependent") {
2994+
diagnose(
2995+
Tok, diag::attr_renamed_to_modifier_warning, "actorIndependent",
2996+
"nonisolated")
2997+
.fixItReplace(SourceRange(AtLoc, Tok.getLoc()), "nonisolated");
2998+
DK = DAK_Nonisolated;
2999+
AtLoc = SourceLoc();
3000+
}
3001+
30313002
if (DK == DAK_Count && Tok.getText() == "warn_unused_result") {
30323003
// The behavior created by @warn_unused_result is now the default. Emit a
30333004
// Fix-It to remove.

lib/Sema/TypeCheckAttr.cpp

Lines changed: 3 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,6 @@ class AttributeChecker : public AttributeVisitor<AttributeChecker> {
252252

253253
void visitActorAttr(ActorAttr *attr);
254254
void visitDistributedActorAttr(DistributedActorAttr *attr);
255-
void visitActorIndependentAttr(ActorIndependentAttr *attr);
256255
void visitDistributedActorIndependentAttr(DistributedActorIndependentAttr *attr);
257256
void visitGlobalActorAttr(GlobalActorAttr *attr);
258257
void visitAsyncAttr(AsyncAttr *attr);
@@ -5391,7 +5390,6 @@ void AttributeChecker::visitActorAttr(ActorAttr *attr) {
53915390
(void)classDecl->isActor();
53925391
}
53935392

5394-
53955393
void AttributeChecker::visitDistributedActorAttr(DistributedActorAttr *attr) {
53965394
auto dc = D->getDeclContext();
53975395

@@ -5441,66 +5439,18 @@ void AttributeChecker::visitDistributedActorAttr(DistributedActorAttr *attr) {
54415439
}
54425440
}
54435441

5444-
void AttributeChecker::visitActorIndependentAttr(ActorIndependentAttr *attr) {
5445-
// @actorIndependent can be applied to global and static/class variables
5446-
// that do not have storage.
5447-
auto dc = D->getDeclContext();
5448-
if (auto var = dyn_cast<VarDecl>(D)) {
5449-
// @actorIndependent is meaningless on a `let`.
5450-
if (var->isLet()) {
5451-
diagnoseAndRemoveAttr(attr, diag::actorindependent_let);
5452-
return;
5453-
}
5454-
5455-
// @actorIndependent can not be applied to stored properties, unless if
5456-
// the 'unsafe' option was specified
5457-
if (var->hasStorage()) {
5458-
switch (attr->getKind()) {
5459-
case ActorIndependentKind::Safe:
5460-
diagnoseAndRemoveAttr(attr, diag::actorindependent_mutable_storage);
5461-
return;
5462-
5463-
case ActorIndependentKind::Unsafe:
5464-
break;
5465-
}
5466-
}
5467-
5468-
// @actorIndependent can not be applied to local properties.
5469-
if (dc->isLocalContext()) {
5470-
diagnoseAndRemoveAttr(attr, diag::actorindependent_local_var);
5471-
return;
5472-
}
5473-
5474-
// If this is a static or global variable, we're all set.
5475-
if (dc->isModuleScopeContext() ||
5476-
(dc->isTypeContext() && var->isStatic())) {
5477-
return;
5478-
}
5479-
}
5480-
5481-
if (auto VD = dyn_cast<ValueDecl>(D)) {
5482-
(void)getActorIsolation(VD);
5483-
}
5484-
}
5485-
54865442
void AttributeChecker::visitNonisolatedAttr(NonisolatedAttr *attr) {
54875443
// 'nonisolated' can be applied to global and static/class variables
54885444
// that do not have storage.
54895445
auto dc = D->getDeclContext();
54905446
if (auto var = dyn_cast<VarDecl>(D)) {
5491-
// 'nonisolated' is meaningless on a `let`.
5492-
if (var->isLet()) {
5493-
diagnoseAndRemoveAttr(attr, diag::nonisolated_let);
5494-
return;
5495-
}
5496-
5497-
// 'nonisolated' can not be applied to stored properties.
5498-
if (var->hasStorage()) {
5447+
// 'nonisolated' can not be applied to mutable stored properties.
5448+
if (var->hasStorage() && var->supportsMutation()) {
54995449
diagnoseAndRemoveAttr(attr, diag::nonisolated_mutable_storage);
55005450
return;
55015451
}
55025452

5503-
// @actorIndependent can not be applied to local properties.
5453+
// nonisolated can not be applied to local properties.
55045454
if (dc->isLocalContext()) {
55055455
diagnoseAndRemoveAttr(attr, diag::nonisolated_local_var);
55065456
return;
@@ -5663,10 +5613,6 @@ class ClosureAttributeChecker
56635613
// Nothing else to check.
56645614
}
56655615

5666-
void visitActorIndependentAttr(ActorIndependentAttr *attr) {
5667-
// Nothing else to check.
5668-
}
5669-
56705616
void visitCustomAttr(CustomAttr *attr) {
56715617
// Check whether this custom attribute is the global actor attribute.
56725618
auto globalActorAttr = evaluateOrDefault(

0 commit comments

Comments
 (0)