Skip to content

Commit 4d91f79

Browse files
authored
Merge pull request swiftlang#37462 from DougGregor/remove-actor-independent
2 parents de221dd + d6e8fd8 commit 4d91f79

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
@@ -4489,23 +4489,12 @@ ERROR(concurrent_value_inherit,none,
44894489
"%select{| other than 'NSObject'}0",
44904490
(bool, DeclName))
44914491

4492-
ERROR(actorindependent_let,none,
4493-
"'@actorIndependent' is meaningless on 'let' declarations because "
4494-
"they are immutable",
4495-
())
4496-
ERROR(actorindependent_mutable_storage,none,
4497-
"'@actorIndependent' can not be applied to stored properties",
4498-
())
4499-
ERROR(actorindependent_local_var,none,
4500-
"'@actorIndependent' can not be applied to local variables",
4501-
())
4502-
45034492
ERROR(nonisolated_let,none,
45044493
"'nonisolated' is meaningless on 'let' declarations because "
45054494
"they are immutable",
45064495
())
45074496
ERROR(nonisolated_mutable_storage,none,
4508-
"nonisolated' can not be applied to stored properties",
4497+
"'nonisolated' can not be applied to stored properties",
45094498
())
45104499
ERROR(nonisolated_local_var,none,
45114500
"'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);
@@ -5399,48 +5398,6 @@ void AttributeChecker::visitActorAttr(ActorAttr *attr) {
53995398
(void)classDecl->isActor();
54005399
}
54015400

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

5461-
// @actorIndependent can not be applied to local properties.
5418+
// nonisolated can not be applied to local properties.
54625419
if (dc->isLocalContext()) {
54635420
diagnoseAndRemoveAttr(attr, diag::nonisolated_local_var);
54645421
return;
@@ -5611,10 +5568,6 @@ class ClosureAttributeChecker
56115568
// Nothing else to check.
56125569
}
56135570

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

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2116,9 +2116,6 @@ namespace {
21162116
AbstractClosureExpr *closure) {
21172117
// If the closure specifies a global actor, use it.
21182118
if (auto explicitClosure = dyn_cast<ClosureExpr>(closure)) {
2119-
if (explicitClosure->getAttrs().hasAttribute<ActorIndependentAttr>())
2120-
return ClosureActorIsolation::forIndependent();
2121-
21222119
if (Type globalActorType = resolveGlobalActorType(explicitClosure))
21232120
return ClosureActorIsolation::forGlobalActor(globalActorType);
21242121

@@ -2250,23 +2247,19 @@ static Optional<ActorIsolation> getIsolationFromAttributes(
22502247
const Decl *decl, bool shouldDiagnose = true, bool onlyExplicit = false) {
22512248
// Look up attributes on the declaration that can affect its actor isolation.
22522249
// If any of them are present, use that attribute.
2253-
auto independentAttr = decl->getAttrs().getAttribute<ActorIndependentAttr>();
22542250
auto nonisolatedAttr = decl->getAttrs().getAttribute<NonisolatedAttr>();
22552251
auto globalActorAttr = decl->getGlobalActorAttr();
22562252

22572253
// Remove implicit attributes if we only care about explicit ones.
22582254
if (onlyExplicit) {
2259-
if (independentAttr && independentAttr->isImplicit())
2260-
independentAttr = nullptr;
22612255
if (nonisolatedAttr && nonisolatedAttr->isImplicit())
22622256
nonisolatedAttr = nullptr;
22632257
if (globalActorAttr && globalActorAttr->first->isImplicit())
22642258
globalActorAttr = None;
22652259
}
22662260

22672261
unsigned numIsolationAttrs =
2268-
(nonisolatedAttr ? 1 : 0) + (independentAttr ? 1 : 0) +
2269-
(globalActorAttr ? 1 : 0);
2262+
(nonisolatedAttr ? 1 : 0) + (globalActorAttr ? 1 : 0);
22702263
if (numIsolationAttrs == 0)
22712264
return None;
22722265

@@ -2282,22 +2275,12 @@ static Optional<ActorIsolation> getIsolationFromAttributes(
22822275
}
22832276

22842277
if (globalActorAttr) {
2285-
StringRef nonisolatedAttrName;
2286-
SourceRange nonisolatedRange;
2287-
if (independentAttr) {
2288-
nonisolatedAttrName = independentAttr->getAttrName();
2289-
nonisolatedRange = independentAttr->getRangeWithAt();
2290-
} else {
2291-
nonisolatedAttrName = nonisolatedAttr->getAttrName();
2292-
nonisolatedRange = nonisolatedAttr->getRangeWithAt();
2293-
}
2294-
22952278
if (shouldDiagnose) {
22962279
decl->diagnose(
22972280
diag::actor_isolation_multiple_attr, decl->getDescriptiveKind(),
2298-
name, nonisolatedAttrName,
2281+
name, nonisolatedAttr->getAttrName(),
22992282
globalActorAttr->second->getName().str())
2300-
.highlight(nonisolatedRange)
2283+
.highlight(nonisolatedAttr->getRangeWithAt())
23012284
.highlight(globalActorAttr->first->getRangeWithAt());
23022285
}
23032286
}
@@ -2309,12 +2292,6 @@ static Optional<ActorIsolation> getIsolationFromAttributes(
23092292
return ActorIsolation::forIndependent();
23102293
}
23112294

2312-
// If the declaration is explicitly marked @actorIndependent, report it as
2313-
// independent.
2314-
if (independentAttr) {
2315-
return ActorIsolation::forIndependent();
2316-
}
2317-
23182295
// If the declaration is marked with a global actor, report it as being
23192296
// part of that global actor.
23202297
if (globalActorAttr) {
@@ -2404,7 +2381,7 @@ static Optional<ActorIsolation> getIsolationFromWitnessedRequirements(
24042381
llvm_unreachable("protocol requirements cannot be actor instances");
24052382

24062383
case ActorIsolation::Independent:
2407-
// We only need one @actorIndependent.
2384+
// We only need one nonisolated.
24082385
if (sawActorIndependent)
24092386
return true;
24102387

@@ -2617,8 +2594,7 @@ ActorIsolation ActorIsolationRequest::evaluate(
26172594
if (onlyGlobal)
26182595
return ActorIsolation::forUnspecified();
26192596

2620-
value->getAttrs().add(new (ctx) ActorIndependentAttr(
2621-
ActorIndependentKind::Safe, /*IsImplicit=*/true));
2597+
value->getAttrs().add(new (ctx) NonisolatedAttr(/*IsImplicit=*/true));
26222598
break;
26232599

26242600
case ActorIsolation::GlobalActorUnsafe:
@@ -2867,12 +2843,9 @@ void swift::checkOverrideActorIsolation(ValueDecl *value) {
28672843
bool swift::contextUsesConcurrencyFeatures(const DeclContext *dc) {
28682844
while (!dc->isModuleScopeContext()) {
28692845
if (auto closure = dyn_cast<AbstractClosureExpr>(dc)) {
2870-
// A closure with an explicit global actor or @actorIndependent
2846+
// A closure with an explicit global actor or nonindependent
28712847
// uses concurrency features.
28722848
if (auto explicitClosure = dyn_cast<ClosureExpr>(closure)) {
2873-
if (explicitClosure->getAttrs().hasAttribute<ActorIndependentAttr>())
2874-
return true;
2875-
28762849
if (getExplicitGlobalActor(const_cast<ClosureExpr *>(explicitClosure)))
28772850
return true;
28782851
}

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)

lib/Serialization/Deserialization.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4284,14 +4284,6 @@ llvm::Error DeclDeserializer::deserializeDeclCommon() {
42844284
break;
42854285
}
42864286

4287-
case decls_block::ActorIndependent_DECL_ATTR: {
4288-
unsigned kind;
4289-
serialization::decls_block::ActorIndependentDeclAttrLayout::readRecord(
4290-
scratch, kind);
4291-
Attr = new (ctx) ActorIndependentAttr((ActorIndependentKind)kind);
4292-
break;
4293-
}
4294-
42954287
case decls_block::Optimize_DECL_ATTR: {
42964288
unsigned kind;
42974289
serialization::decls_block::OptimizeDeclAttrLayout::readRecord(

0 commit comments

Comments
 (0)