Skip to content

Commit 45d4d97

Browse files
committed
Deprecate @_unsafeInheritExecutor and remove it from Swift 6
1 parent c5457ab commit 45d4d97

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
@@ -4000,6 +4000,9 @@ ERROR(inherits_executor_without_async,none,
40004000
ERROR(isolation_in_inherits_executor,none,
40014001
"#isolation%select{| (introduced by a default argument)}0 cannot be used "
40024002
"within an '@_unsafeInheritExecutor' function", (bool))
4003+
ERROR(unsafe_inherits_executor_deprecated,none,
4004+
"@_unsafeInheritExecutor attribute is deprecated; consider an "
4005+
"'isolated' parameter defaulted to '#isolation' instead", ())
40034006

40044007
ERROR(lifetime_invalid_global_scope,none, "%0 is only valid on methods",
40054008
(DeclAttribute))

lib/Sema/TypeCheckAttr.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7279,6 +7279,13 @@ void AttributeChecker::visitUnsafeInheritExecutorAttr(
72797279
auto fn = cast<FuncDecl>(D);
72807280
if (!fn->isAsyncContext()) {
72817281
diagnose(attr->getLocation(), diag::inherits_executor_without_async);
7282+
} else {
7283+
bool inConcurrencyModule = D->getDeclContext()->getParentModule()->getName()
7284+
.str().equals("_Concurrency");
7285+
auto diag = fn->diagnose(diag::unsafe_inherits_executor_deprecated);
7286+
diag.warnUntilSwiftVersion(6);
7287+
diag.limitBehaviorIf(inConcurrencyModule, DiagnosticBehavior::Warning);
7288+
replaceUnsafeInheritExecutorWithDefaultedIsolationParam(fn, diag);
72827289
}
72837290
}
72847291

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2054,9 +2054,7 @@ static std::pair<SourceLoc, bool> adjustPoundIsolationDiagLoc(
20542054
};
20552055
}
20562056

2057-
/// Replace the @_unsafeInheritExecutor with a defaulted isolation
2058-
/// parameter.
2059-
static void replaceUnsafeInheritExecutorWithDefaultedIsolationParam(
2057+
void swift::replaceUnsafeInheritExecutorWithDefaultedIsolationParam(
20602058
AbstractFunctionDecl *func, InFlightDiagnostic &diag) {
20612059
auto attr = func->getAttrs().getAttribute<UnsafeInheritExecutorAttr>();
20622060
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)