Skip to content

Commit 5cc00c2

Browse files
committed
Remove the @_unsafeSendable/@_unsafeMainActor attributes.
These have been subsumed by @_predatesConcurrency. Leave in minimal parser support that warns about the removal, so we don't fully break existing source code.
1 parent 089cc4f commit 5cc00c2

File tree

8 files changed

+28
-69
lines changed

8 files changed

+28
-69
lines changed

include/swift/AST/Attr.def

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -635,15 +635,8 @@ CONTEXTUAL_SIMPLE_DECL_ATTR(nonisolated, Nonisolated,
635635
APIBreakingToAdd | APIStableToRemove,
636636
112)
637637

638-
CONTEXTUAL_SIMPLE_DECL_ATTR(_unsafeSendable, UnsafeSendable,
639-
OnParam | UserInaccessible |
640-
ABIStableToAdd | ABIStableToRemove | APIBreakingToAdd | APIStableToRemove,
641-
113)
642-
643-
CONTEXTUAL_SIMPLE_DECL_ATTR(_unsafeMainActor, UnsafeMainActor,
644-
OnParam | UserInaccessible |
645-
ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIBreakingToRemove,
646-
114)
638+
// 113 was experimental _unsafeSendable and is now unused
639+
// 114 was experimental _unsafeMainActor and is now unused
647640

648641
SIMPLE_DECL_ATTR(_implicitSelfCapture, ImplicitSelfCapture,
649642
OnParam | UserInaccessible |

include/swift/AST/DiagnosticsParse.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1719,6 +1719,10 @@ ERROR(sil_inst_autodiff_invalid_witness_generic_signature,PointsToFirstBadToken,
17191719
"parameters as original function generic signature '%1'",
17201720
(StringRef, StringRef))
17211721

1722+
WARNING(warn_attr_unsafe_removed,none,
1723+
"'%0' attribute has been removed in favor of @_predatesConcurrency",
1724+
(StringRef))
1725+
17221726
//------------------------------------------------------------------------------
17231727
// MARK: Generics parsing diagnostics
17241728
//------------------------------------------------------------------------------

lib/Parse/ParseDecl.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3080,6 +3080,17 @@ ParserStatus Parser::parseDeclAttribute(
30803080
return makeParserSuccess();
30813081
}
30823082

3083+
// @_unsafeSendable and @_unsafeMainActor have been removed; warn about them.
3084+
if (DK == DAK_Count &&
3085+
(Tok.getText() == "_unsafeSendable" ||
3086+
Tok.getText() == "_unsafeMainActor")) {
3087+
StringRef attrName = Tok.getText();
3088+
SourceLoc attrLoc = consumeToken();
3089+
diagnose(AtLoc, diag::warn_attr_unsafe_removed, attrName)
3090+
.fixItRemove(SourceRange(AtLoc, attrLoc));
3091+
return makeParserSuccess();
3092+
}
3093+
30833094
if (DK != DAK_Count && !DeclAttribute::shouldBeRejectedByParser(DK)) {
30843095
parseNewDeclAttribute(Attributes, AtLoc, DK, isFromClangAttribute);
30853096
return makeParserSuccess();

lib/Sema/TypeCheckAttr.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,6 @@ class AttributeChecker : public AttributeVisitor<AttributeChecker> {
114114
IGNORED_ATTR(NonSendable)
115115
IGNORED_ATTR(AtRethrows)
116116
IGNORED_ATTR(AtReasync)
117-
IGNORED_ATTR(UnsafeSendable)
118-
IGNORED_ATTR(UnsafeMainActor)
119117
IGNORED_ATTR(ImplicitSelfCapture)
120118
IGNORED_ATTR(InheritActorContext)
121119
IGNORED_ATTR(Isolated)

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4129,13 +4129,9 @@ static AnyFunctionType *applyUnsafeConcurrencyToFunctionType(
41294129
// @MainActor. @Sendable occurs only in concurrency contents, while
41304130
// @MainActor occurs in concurrency contexts or those where we have an
41314131
// application.
4132-
bool addSendable =
4133-
(paramDecl->getAttrs().hasAttribute<UnsafeSendableAttr>() ||
4134-
knownUnsafeParams) &&
4135-
inConcurrencyContext;
4132+
bool addSendable = knownUnsafeParams && inConcurrencyContext;
41364133
bool addMainActor =
4137-
(paramDecl->getAttrs().hasAttribute<UnsafeMainActorAttr>() ||
4138-
(isMainDispatchQueue && knownUnsafeParams)) &&
4134+
(isMainDispatchQueue && knownUnsafeParams) &&
41394135
(inConcurrencyContext || numApplies >= 1);
41404136
Type newParamType = param.getPlainType();
41414137
if (addSendable || addMainActor) {

lib/Sema/TypeCheckDeclOverride.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,8 +1555,6 @@ namespace {
15551555

15561556
UNINTERESTING_ATTR(AtReasync)
15571557
UNINTERESTING_ATTR(Nonisolated)
1558-
UNINTERESTING_ATTR(UnsafeSendable)
1559-
UNINTERESTING_ATTR(UnsafeMainActor)
15601558
UNINTERESTING_ATTR(ImplicitSelfCapture)
15611559
UNINTERESTING_ATTR(InheritActorContext)
15621560
UNINTERESTING_ATTR(Isolated)

test/Concurrency/predates_concurrency.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,12 @@ struct S2: Q {
9595
struct S3: Q, Sendable {
9696
var ns: NS // expected-error{{stored property 'ns' of 'Sendable'-conforming struct 'S3' has non-sendable type 'NS'}}
9797
}
98+
99+
// ---------------------------------------------------------------------------
100+
// Historical attribute names do nothing (but are permitted)
101+
// ---------------------------------------------------------------------------
102+
func aFailedExperiment(@_unsafeSendable _ body: @escaping () -> Void) { }
103+
// expected-warning@-1{{'_unsafeSendable' attribute has been removed in favor of @_predatesConcurrency}}
104+
105+
func anothingFailedExperiment(@_unsafeMainActor _ body: @escaping () -> Void) { }
106+
// expected-warning@-1{{'_unsafeMainActor' attribute has been removed in favor of @_predatesConcurrency}}

test/Concurrency/unsafe_param_annotations.swift

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)