Skip to content

Commit 03f55d7

Browse files
committed
Revert "Revert "Remove @actorIndependent attribute.""
This reverts commit 7c0b50e.
1 parent 509e026 commit 03f55d7

25 files changed

+81
-380
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/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: 0 additions & 39 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,

lib/Sema/TypeCheckAttr.cpp

Lines changed: 1 addition & 49 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,48 +5439,6 @@ 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.
@@ -5500,7 +5456,7 @@ void AttributeChecker::visitNonisolatedAttr(NonisolatedAttr *attr) {
55005456
return;
55015457
}
55025458

5503-
// @actorIndependent can not be applied to local properties.
5459+
// nonisolated can not be applied to local properties.
55045460
if (dc->isLocalContext()) {
55055461
diagnoseAndRemoveAttr(attr, diag::nonisolated_local_var);
55065462
return;
@@ -5663,10 +5619,6 @@ class ClosureAttributeChecker
56635619
// Nothing else to check.
56645620
}
56655621

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

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2278,9 +2278,6 @@ namespace {
22782278
AbstractClosureExpr *closure) {
22792279
// If the closure specifies a global actor, use it.
22802280
if (auto explicitClosure = dyn_cast<ClosureExpr>(closure)) {
2281-
if (explicitClosure->getAttrs().hasAttribute<ActorIndependentAttr>())
2282-
return ClosureActorIsolation::forIndependent();
2283-
22842281
if (Type globalActorType = resolveGlobalActorType(explicitClosure))
22852282
return ClosureActorIsolation::forGlobalActor(globalActorType);
22862283

@@ -2504,23 +2501,19 @@ static Optional<ActorIsolation> getIsolationFromAttributes(
25042501
const Decl *decl, bool shouldDiagnose = true, bool onlyExplicit = false) {
25052502
// Look up attributes on the declaration that can affect its actor isolation.
25062503
// If any of them are present, use that attribute.
2507-
auto independentAttr = decl->getAttrs().getAttribute<ActorIndependentAttr>();
25082504
auto nonisolatedAttr = decl->getAttrs().getAttribute<NonisolatedAttr>();
25092505
auto globalActorAttr = decl->getGlobalActorAttr();
25102506

25112507
// Remove implicit attributes if we only care about explicit ones.
25122508
if (onlyExplicit) {
2513-
if (independentAttr && independentAttr->isImplicit())
2514-
independentAttr = nullptr;
25152509
if (nonisolatedAttr && nonisolatedAttr->isImplicit())
25162510
nonisolatedAttr = nullptr;
25172511
if (globalActorAttr && globalActorAttr->first->isImplicit())
25182512
globalActorAttr = None;
25192513
}
25202514

25212515
unsigned numIsolationAttrs =
2522-
(nonisolatedAttr ? 1 : 0) + (independentAttr ? 1 : 0) +
2523-
(globalActorAttr ? 1 : 0);
2516+
(nonisolatedAttr ? 1 : 0) + (globalActorAttr ? 1 : 0);
25242517
if (numIsolationAttrs == 0)
25252518
return None;
25262519

@@ -2536,22 +2529,12 @@ static Optional<ActorIsolation> getIsolationFromAttributes(
25362529
}
25372530

25382531
if (globalActorAttr) {
2539-
StringRef nonisolatedAttrName;
2540-
SourceRange nonisolatedRange;
2541-
if (independentAttr) {
2542-
nonisolatedAttrName = independentAttr->getAttrName();
2543-
nonisolatedRange = independentAttr->getRangeWithAt();
2544-
} else {
2545-
nonisolatedAttrName = nonisolatedAttr->getAttrName();
2546-
nonisolatedRange = nonisolatedAttr->getRangeWithAt();
2547-
}
2548-
25492532
if (shouldDiagnose) {
25502533
decl->diagnose(
25512534
diag::actor_isolation_multiple_attr, decl->getDescriptiveKind(),
2552-
name, nonisolatedAttrName,
2535+
name, nonisolatedAttr->getAttrName(),
25532536
globalActorAttr->second->getName().str())
2554-
.highlight(nonisolatedRange)
2537+
.highlight(nonisolatedAttr->getRangeWithAt())
25552538
.highlight(globalActorAttr->first->getRangeWithAt());
25562539
}
25572540
}
@@ -2563,12 +2546,6 @@ static Optional<ActorIsolation> getIsolationFromAttributes(
25632546
return ActorIsolation::forIndependent();
25642547
}
25652548

2566-
// If the declaration is explicitly marked @actorIndependent, report it as
2567-
// independent.
2568-
if (independentAttr) {
2569-
return ActorIsolation::forIndependent();
2570-
}
2571-
25722549
// If the declaration is marked with a global actor, report it as being
25732550
// part of that global actor.
25742551
if (globalActorAttr) {
@@ -2660,7 +2637,7 @@ static Optional<ActorIsolation> getIsolationFromWitnessedRequirements(
26602637
llvm_unreachable("protocol requirements cannot be actor instances");
26612638

26622639
case ActorIsolation::Independent:
2663-
// We only need one @actorIndependent.
2640+
// We only need one nonisolated.
26642641
if (sawActorIndependent)
26652642
return true;
26662643

@@ -2880,13 +2857,7 @@ ActorIsolation ActorIsolationRequest::evaluate(
28802857
if (onlyGlobal)
28812858
return ActorIsolation::forUnspecified();
28822859

2883-
if (auto varDecl = dyn_cast<VarDecl>(value)) {
2884-
// only set the @actorIndependent on values where it is legal to do so
2885-
if (!varDecl->isLet()) {
2886-
value->getAttrs().add(new (ctx) ActorIndependentAttr(
2887-
ActorIndependentKind::Safe, /*IsImplicit=*/true));
2888-
}
2889-
}
2860+
value->getAttrs().add(new (ctx) NonisolatedAttr(/*IsImplicit=*/true));
28902861
break;
28912862

28922863
case ActorIsolation::GlobalActorUnsafe:
@@ -3144,12 +3115,9 @@ void swift::checkOverrideActorIsolation(ValueDecl *value) {
31443115
bool swift::contextUsesConcurrencyFeatures(const DeclContext *dc) {
31453116
while (!dc->isModuleScopeContext()) {
31463117
if (auto closure = dyn_cast<AbstractClosureExpr>(dc)) {
3147-
// A closure with an explicit global actor or @actorIndependent
3118+
// A closure with an explicit global actor or nonindependent
31483119
// uses concurrency features.
31493120
if (auto explicitClosure = dyn_cast<ClosureExpr>(closure)) {
3150-
if (explicitClosure->getAttrs().hasAttribute<ActorIndependentAttr>())
3151-
return true;
3152-
31533121
if (getExplicitGlobalActor(const_cast<ClosureExpr *>(explicitClosure)))
31543122
return true;
31553123
}

lib/Sema/TypeCheckDeclOverride.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1534,7 +1534,6 @@ namespace {
15341534
UNINTERESTING_ATTR(OriginallyDefinedIn)
15351535
UNINTERESTING_ATTR(Actor)
15361536
UNINTERESTING_ATTR(DistributedActor)
1537-
UNINTERESTING_ATTR(ActorIndependent)
15381537
UNINTERESTING_ATTR(DistributedActorIndependent)
15391538
UNINTERESTING_ATTR(GlobalActor)
15401539
UNINTERESTING_ATTR(Async)

0 commit comments

Comments
 (0)