Skip to content

Commit d6e8fd8

Browse files
committed
Remove @actorIndependent attribute.
`@actorIndependent` has been superseded by `nonisolated`. Remove the old spelling entirely.
1 parent 0e2e11d commit d6e8fd8

25 files changed

+81
-374
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
);
@@ -1220,25 +1216,6 @@ class ReferenceOwnershipAttr : public DeclAttribute {
12201216
}
12211217
};
12221218

1223-
/// Represents an actorIndependent/actorIndependent(unsafe) decl attribute.
1224-
class ActorIndependentAttr : public DeclAttribute {
1225-
public:
1226-
ActorIndependentAttr(SourceLoc atLoc, SourceRange range, ActorIndependentKind kind)
1227-
: DeclAttribute(DAK_ActorIndependent, atLoc, range, /*Implicit=*/false) {
1228-
Bits.ActorIndependentAttr.kind = unsigned(kind);
1229-
}
1230-
1231-
ActorIndependentAttr(ActorIndependentKind kind, bool IsImplicit=false)
1232-
: ActorIndependentAttr(SourceLoc(), SourceRange(), kind) {
1233-
setImplicit(IsImplicit);
1234-
}
1235-
1236-
ActorIndependentKind getKind() const { return ActorIndependentKind(Bits.ActorIndependentAttr.kind); }
1237-
static bool classof(const DeclAttribute *DA) {
1238-
return DA->getKind() == DAK_ActorIndependent;
1239-
}
1240-
};
1241-
12421219
/// Defines the attribute that we use to model documentation comments.
12431220
class RawDocCommentAttr : public DeclAttribute {
12441221
/// 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
@@ -4485,23 +4485,12 @@ ERROR(concurrent_value_inherit,none,
44854485
"%select{| other than 'NSObject'}0",
44864486
(bool, DeclName))
44874487

4488-
ERROR(actorindependent_let,none,
4489-
"'@actorIndependent' is meaningless on 'let' declarations because "
4490-
"they are immutable",
4491-
())
4492-
ERROR(actorindependent_mutable_storage,none,
4493-
"'@actorIndependent' can not be applied to stored properties",
4494-
())
4495-
ERROR(actorindependent_local_var,none,
4496-
"'@actorIndependent' can not be applied to local variables",
4497-
())
4498-
44994488
ERROR(nonisolated_let,none,
45004489
"'nonisolated' is meaningless on 'let' declarations because "
45014490
"they are immutable",
45024491
())
45034492
ERROR(nonisolated_mutable_storage,none,
4504-
"nonisolated' can not be applied to stored properties",
4493+
"'nonisolated' can not be applied to stored properties",
45054494
())
45064495
ERROR(nonisolated_local_var,none,
45074496
"'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
@@ -8672,6 +8672,14 @@ void ClangImporter::Implementation::importAttributes(
86728672
continue;
86738673
}
86748674

8675+
// Hard-code @actorIndependent, until Objective-C clients start
8676+
// using nonisolated.
8677+
if (swiftAttr->getAttribute() == "@actorIndependent") {
8678+
auto attr = new (SwiftContext) NonisolatedAttr(/*isImplicit=*/true);
8679+
MappedDecl->getAttrs().add(attr);
8680+
continue;
8681+
}
8682+
86758683
// Dig out a buffer with the attribute text.
86768684
unsigned bufferID = getClangSwiftAttrSourceBuffer(
86778685
swiftAttr->getAttribute());
@@ -9596,9 +9604,8 @@ ClangImporter::Implementation::createConstant(Identifier name, DeclContext *dc,
95969604

95979605
// Mark the function transparent so that we inline it away completely.
95989606
func->getAttrs().add(new (C) TransparentAttr(/*implicit*/ true));
9599-
auto actorIndependentAttr = new (C) ActorIndependentAttr(
9600-
ActorIndependentKind::Unsafe, /*IsImplicit=*/true);
9601-
var->getAttrs().add(actorIndependentAttr);
9607+
auto nonisolatedAttr = new (C) NonisolatedAttr(/*IsImplicit=*/true);
9608+
var->getAttrs().add(nonisolatedAttr);
96029609

96039610
// Set the function up as the getter.
96049611
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 & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,6 @@ class AttributeChecker : public AttributeVisitor<AttributeChecker> {
280280
void visitTransposeAttr(TransposeAttr *attr);
281281

282282
void visitActorAttr(ActorAttr *attr);
283-
void visitActorIndependentAttr(ActorIndependentAttr *attr);
284283
void visitGlobalActorAttr(GlobalActorAttr *attr);
285284
void visitAsyncAttr(AsyncAttr *attr);
286285
void visitSpawnAttr(SpawnAttr *attr);
@@ -5398,48 +5397,6 @@ void AttributeChecker::visitActorAttr(ActorAttr *attr) {
53985397
(void)classDecl->isActor();
53995398
}
54005399

5401-
void AttributeChecker::visitActorIndependentAttr(ActorIndependentAttr *attr) {
5402-
// @actorIndependent can be applied to global and static/class variables
5403-
// that do not have storage.
5404-
auto dc = D->getDeclContext();
5405-
if (auto var = dyn_cast<VarDecl>(D)) {
5406-
// @actorIndependent is meaningless on a `let`.
5407-
if (var->isLet()) {
5408-
diagnoseAndRemoveAttr(attr, diag::actorindependent_let);
5409-
return;
5410-
}
5411-
5412-
// @actorIndependent can not be applied to stored properties, unless if
5413-
// the 'unsafe' option was specified
5414-
if (var->hasStorage()) {
5415-
switch (attr->getKind()) {
5416-
case ActorIndependentKind::Safe:
5417-
diagnoseAndRemoveAttr(attr, diag::actorindependent_mutable_storage);
5418-
return;
5419-
5420-
case ActorIndependentKind::Unsafe:
5421-
break;
5422-
}
5423-
}
5424-
5425-
// @actorIndependent can not be applied to local properties.
5426-
if (dc->isLocalContext()) {
5427-
diagnoseAndRemoveAttr(attr, diag::actorindependent_local_var);
5428-
return;
5429-
}
5430-
5431-
// If this is a static or global variable, we're all set.
5432-
if (dc->isModuleScopeContext() ||
5433-
(dc->isTypeContext() && var->isStatic())) {
5434-
return;
5435-
}
5436-
}
5437-
5438-
if (auto VD = dyn_cast<ValueDecl>(D)) {
5439-
(void)getActorIsolation(VD);
5440-
}
5441-
}
5442-
54435400
void AttributeChecker::visitNonisolatedAttr(NonisolatedAttr *attr) {
54445401
// 'nonisolated' can be applied to global and static/class variables
54455402
// that do not have storage.
@@ -5457,7 +5414,7 @@ void AttributeChecker::visitNonisolatedAttr(NonisolatedAttr *attr) {
54575414
return;
54585415
}
54595416

5460-
// @actorIndependent can not be applied to local properties.
5417+
// nonisolated can not be applied to local properties.
54615418
if (dc->isLocalContext()) {
54625419
diagnoseAndRemoveAttr(attr, diag::nonisolated_local_var);
54635420
return;
@@ -5610,10 +5567,6 @@ class ClosureAttributeChecker
56105567
// Nothing else to check.
56115568
}
56125569

5613-
void visitActorIndependentAttr(ActorIndependentAttr *attr) {
5614-
// Nothing else to check.
5615-
}
5616-
56175570
void visitCustomAttr(CustomAttr *attr) {
56185571
// Check whether this custom attribute is the global actor attribute.
56195572
auto globalActorAttr = evaluateOrDefault(

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2111,9 +2111,6 @@ namespace {
21112111
AbstractClosureExpr *closure) {
21122112
// If the closure specifies a global actor, use it.
21132113
if (auto explicitClosure = dyn_cast<ClosureExpr>(closure)) {
2114-
if (explicitClosure->getAttrs().hasAttribute<ActorIndependentAttr>())
2115-
return ClosureActorIsolation::forIndependent();
2116-
21172114
if (Type globalActorType = resolveGlobalActorType(explicitClosure))
21182115
return ClosureActorIsolation::forGlobalActor(globalActorType);
21192116

@@ -2245,23 +2242,19 @@ static Optional<ActorIsolation> getIsolationFromAttributes(
22452242
const Decl *decl, bool shouldDiagnose = true, bool onlyExplicit = false) {
22462243
// Look up attributes on the declaration that can affect its actor isolation.
22472244
// If any of them are present, use that attribute.
2248-
auto independentAttr = decl->getAttrs().getAttribute<ActorIndependentAttr>();
22492245
auto nonisolatedAttr = decl->getAttrs().getAttribute<NonisolatedAttr>();
22502246
auto globalActorAttr = decl->getGlobalActorAttr();
22512247

22522248
// Remove implicit attributes if we only care about explicit ones.
22532249
if (onlyExplicit) {
2254-
if (independentAttr && independentAttr->isImplicit())
2255-
independentAttr = nullptr;
22562250
if (nonisolatedAttr && nonisolatedAttr->isImplicit())
22572251
nonisolatedAttr = nullptr;
22582252
if (globalActorAttr && globalActorAttr->first->isImplicit())
22592253
globalActorAttr = None;
22602254
}
22612255

22622256
unsigned numIsolationAttrs =
2263-
(nonisolatedAttr ? 1 : 0) + (independentAttr ? 1 : 0) +
2264-
(globalActorAttr ? 1 : 0);
2257+
(nonisolatedAttr ? 1 : 0) + (globalActorAttr ? 1 : 0);
22652258
if (numIsolationAttrs == 0)
22662259
return None;
22672260

@@ -2277,22 +2270,12 @@ static Optional<ActorIsolation> getIsolationFromAttributes(
22772270
}
22782271

22792272
if (globalActorAttr) {
2280-
StringRef nonisolatedAttrName;
2281-
SourceRange nonisolatedRange;
2282-
if (independentAttr) {
2283-
nonisolatedAttrName = independentAttr->getAttrName();
2284-
nonisolatedRange = independentAttr->getRangeWithAt();
2285-
} else {
2286-
nonisolatedAttrName = nonisolatedAttr->getAttrName();
2287-
nonisolatedRange = nonisolatedAttr->getRangeWithAt();
2288-
}
2289-
22902273
if (shouldDiagnose) {
22912274
decl->diagnose(
22922275
diag::actor_isolation_multiple_attr, decl->getDescriptiveKind(),
2293-
name, nonisolatedAttrName,
2276+
name, nonisolatedAttr->getAttrName(),
22942277
globalActorAttr->second->getName().str())
2295-
.highlight(nonisolatedRange)
2278+
.highlight(nonisolatedAttr->getRangeWithAt())
22962279
.highlight(globalActorAttr->first->getRangeWithAt());
22972280
}
22982281
}
@@ -2304,12 +2287,6 @@ static Optional<ActorIsolation> getIsolationFromAttributes(
23042287
return ActorIsolation::forIndependent();
23052288
}
23062289

2307-
// If the declaration is explicitly marked @actorIndependent, report it as
2308-
// independent.
2309-
if (independentAttr) {
2310-
return ActorIsolation::forIndependent();
2311-
}
2312-
23132290
// If the declaration is marked with a global actor, report it as being
23142291
// part of that global actor.
23152292
if (globalActorAttr) {
@@ -2399,7 +2376,7 @@ static Optional<ActorIsolation> getIsolationFromWitnessedRequirements(
23992376
llvm_unreachable("protocol requirements cannot be actor instances");
24002377

24012378
case ActorIsolation::Independent:
2402-
// We only need one @actorIndependent.
2379+
// We only need one nonisolated.
24032380
if (sawActorIndependent)
24042381
return true;
24052382

@@ -2612,8 +2589,7 @@ ActorIsolation ActorIsolationRequest::evaluate(
26122589
if (onlyGlobal)
26132590
return ActorIsolation::forUnspecified();
26142591

2615-
value->getAttrs().add(new (ctx) ActorIndependentAttr(
2616-
ActorIndependentKind::Safe, /*IsImplicit=*/true));
2592+
value->getAttrs().add(new (ctx) NonisolatedAttr(/*IsImplicit=*/true));
26172593
break;
26182594

26192595
case ActorIsolation::GlobalActorUnsafe:
@@ -2862,12 +2838,9 @@ void swift::checkOverrideActorIsolation(ValueDecl *value) {
28622838
bool swift::contextUsesConcurrencyFeatures(const DeclContext *dc) {
28632839
while (!dc->isModuleScopeContext()) {
28642840
if (auto closure = dyn_cast<AbstractClosureExpr>(dc)) {
2865-
// A closure with an explicit global actor or @actorIndependent
2841+
// A closure with an explicit global actor or nonindependent
28662842
// uses concurrency features.
28672843
if (auto explicitClosure = dyn_cast<ClosureExpr>(closure)) {
2868-
if (explicitClosure->getAttrs().hasAttribute<ActorIndependentAttr>())
2869-
return true;
2870-
28712844
if (getExplicitGlobalActor(const_cast<ClosureExpr *>(explicitClosure)))
28722845
return true;
28732846
}

lib/Sema/TypeCheckDeclOverride.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1533,7 +1533,6 @@ namespace {
15331533
UNINTERESTING_ATTR(ProjectedValueProperty)
15341534
UNINTERESTING_ATTR(OriginallyDefinedIn)
15351535
UNINTERESTING_ATTR(Actor)
1536-
UNINTERESTING_ATTR(ActorIndependent)
15371536
UNINTERESTING_ATTR(GlobalActor)
15381537
UNINTERESTING_ATTR(Async)
15391538
UNINTERESTING_ATTR(Spawn)

0 commit comments

Comments
 (0)