Skip to content

Commit 8b3a36d

Browse files
committed
Deprecate @_unsafeInheritExecutor and remove it from Swift 6
1 parent 4c593d5 commit 8b3a36d

File tree

5 files changed

+31
-6
lines changed

5 files changed

+31
-6
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3980,6 +3980,9 @@ ERROR(inherits_executor_without_async,none,
39803980
ERROR(isolation_in_inherits_executor,none,
39813981
"#isolation%select{| (introduced by a default argument)}0 cannot be used "
39823982
"within an '@_unsafeInheritExecutor' function", (bool))
3983+
ERROR(unsafe_inherits_executor_deprecated,none,
3984+
"@_unsafeInheritExecutor attribute is deprecated; consider an "
3985+
"'isolated' parameter defaulted to '#isolation' instead", ())
39833986

39843987
ERROR(lifetime_invalid_global_scope,none, "%0 is only valid on methods",
39853988
(DeclAttribute))

lib/Sema/TypeCheckAttr.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7201,6 +7201,13 @@ void AttributeChecker::visitUnsafeInheritExecutorAttr(
72017201
auto fn = cast<FuncDecl>(D);
72027202
if (!fn->isAsyncContext()) {
72037203
diagnose(attr->getLocation(), diag::inherits_executor_without_async);
7204+
} else {
7205+
bool inConcurrencyModule = D->getDeclContext()->getParentModule()->getName()
7206+
.str().equals("_Concurrency");
7207+
auto diag = fn->diagnose(diag::unsafe_inherits_executor_deprecated);
7208+
diag.warnUntilSwiftVersion(6);
7209+
diag.limitBehaviorIf(inConcurrencyModule, DiagnosticBehavior::Warning);
7210+
replaceUnsafeInheritExecutorWithDefaultedIsolationParam(fn, diag);
72047211
}
72057212
}
72067213

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2058,9 +2058,7 @@ static std::pair<SourceLoc, bool> adjustPoundIsolationDiagLoc(
20582058
};
20592059
}
20602060

2061-
/// Replace the @_unsafeInheritExecutor with a defaulted isolation
2062-
/// parameter.
2063-
static void replaceUnsafeInheritExecutorWithDefaultedIsolationParam(
2061+
void swift::replaceUnsafeInheritExecutorWithDefaultedIsolationParam(
20642062
AbstractFunctionDecl *func, InFlightDiagnostic &diag) {
20652063
auto attr = func->getAttrs().getAttribute<UnsafeInheritExecutorAttr>();
20662064
assert(attr && "Caller didn't validate the presence of the attribute");

lib/Sema/TypeCheckConcurrency.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,11 @@ bool diagnoseApplyArgSendability(
651651
/// If the enclosing function has @_unsafeInheritExecutorAttr, return it.
652652
AbstractFunctionDecl *enclosingUnsafeInheritsExecutor(const DeclContext *dc);
653653

654+
/// Add Fix-Its to the given function to replace the @_unsafeInheritExecutor
655+
/// attribute with a defaulted isolation parameter.
656+
void replaceUnsafeInheritExecutorWithDefaultedIsolationParam(
657+
AbstractFunctionDecl *func, InFlightDiagnostic &diag);
658+
654659
} // end namespace swift
655660

656661
namespace llvm {

test/Concurrency/unsafe_inherit_executor.swift

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ func testNonAsync() {}
1111

1212
@_unsafeInheritExecutor
1313
func testAsync() async {}
14+
// expected-warning@-1{{@_unsafeInheritExecutor attribute is deprecated; consider an 'isolated' parameter defaulted to '#isolation' instead}}
1415

1516
struct A {
1617
// expected-error @+1 {{@_unsafeInheritExecutor may only be used on 'func' declarations}}
@@ -23,6 +24,7 @@ struct A {
2324

2425
@_unsafeInheritExecutor
2526
func testAsync() async {}
27+
// expected-warning@-1{{@_unsafeInheritExecutor attribute is deprecated; consider an 'isolated' parameter defaulted to '#isolation' instead}}
2628
}
2729

2830

@@ -32,6 +34,7 @@ class NonSendableObject {
3234

3335
@_unsafeInheritExecutor
3436
func useNonSendable(object: NonSendableObject) async {}
37+
// expected-warning@-1{{@_unsafeInheritExecutor attribute is deprecated; consider an 'isolated' parameter defaulted to '#isolation' instead; this is an error in the Swift 6 language mode}}{{35:1-24=}}{{36:46-46=, isolation: isolated (any Actor)? = #isolation}}
3538

3639
actor MyActor {
3740
var object = NonSendableObject()
@@ -46,23 +49,32 @@ func inheritsIsolationProperly(isolation: isolated (any Actor)? = #isolation) as
4649
// @_unsafeInheritExecutor does not work with #isolation
4750
@_unsafeInheritExecutor
4851
func unsafeCallerA(x: Int) async {
52+
// expected-warning@-1{{@_unsafeInheritExecutor attribute is deprecated; consider an 'isolated' parameter defaulted to '#isolation' instead}}
53+
4954
await inheritsIsolationProperly()
50-
// expected-error@-1{{#isolation (introduced by a default argument) cannot be used within an '@_unsafeInheritExecutor' function}}{{47:1-24=}}{{48:26-26=, isolation: isolated (any Actor)? = #isolation}}
55+
// expected-error@-1{{#isolation (introduced by a default argument) cannot be used within an '@_unsafeInheritExecutor' function}}{{50:1-24=}}{{51:26-26=, isolation: isolated (any Actor)? = #isolation}}
56+
t 6)
5157
}
5258

5359
@_unsafeInheritExecutor
5460
func unsafeCallerB() async {
61+
// expected-warning@-1{{@_unsafeInheritExecutor attribute is deprecated; consider an 'isolated' parameter defaulted to '#isolation' instead}}
62+
5563
await inheritsIsolationProperly(isolation: #isolation)
56-
// expected-error@-1{{#isolation cannot be used within an '@_unsafeInheritExecutor' function}}{{53:1-24=}}{{54:20-20=isolation: isolated (any Actor)? = #isolation}}
64+
// expected-error@-1{{#isolation cannot be used within an '@_unsafeInheritExecutor' function}}{{58:1-24=}}{{59:20-20=isolation: isolated (any Actor)? = #isolation}}
5765
}
5866

5967
@_unsafeInheritExecutor
6068
func unsafeCallerC(x: Int, fn: () -> Void, fn2: () -> Void) async {
69+
// expected-warning@-1{{@_unsafeInheritExecutor attribute is deprecated; consider an 'isolated' parameter defaulted to '#isolation' instead}}
70+
6171
await inheritsIsolationProperly()
62-
// expected-error@-1{{#isolation (introduced by a default argument) cannot be used within an '@_unsafeInheritExecutor' function}}{{59:1-24=}}{{60:28-28=, isolation: isolated (any Actor)? = #isolation, }}
72+
// expected-error@-1{{#isolation (introduced by a default argument) cannot be used within an '@_unsafeInheritExecutor' function}}{{66:1-24=}}{{67:28-28=, isolation: isolated (any Actor)? = #isolation, }}
6373
}
6474

6575
@_unsafeInheritExecutor
6676
func unsafeCallerAvoidsNewLoop(x: some AsyncSequence<Int, Never>) async throws {
77+
// expected-warning@-1{{@_unsafeInheritExecutor attribute is deprecated; consider an 'isolated' parameter defaulted to '#isolation' instead}}
78+
6779
for try await _ in x { }
6880
}

0 commit comments

Comments
 (0)