Skip to content

Commit bf603ea

Browse files
committed
Introduce a feature for @_inheritActorContext
Add a feature for this new attribute, and make sure we use the feature guard for functions that use it, e.g., the new `async`. Finishes rdar://76927008. (cherry picked from commit cdd6ad8)
1 parent 86e8859 commit bf603ea

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

include/swift/Basic/Features.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,6 @@ LANGUAGE_FEATURE(BuiltinJob, 0, "Builtin.Job type", true)
4545
LANGUAGE_FEATURE(Sendable, 0, "Sendable and @Sendable", true)
4646
LANGUAGE_FEATURE(BuiltinContinuation, 0, "Continuation builtins", true)
4747
LANGUAGE_FEATURE(BuiltinTaskGroup, 0, "TaskGroup builtins", true)
48+
LANGUAGE_FEATURE(InheritActorContext, 0, "@_inheritActorContext attribute", true)
4849

4950
#undef LANGUAGE_FEATURE

lib/AST/ASTPrinter.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2753,6 +2753,17 @@ static bool usesFeatureBuiltinTaskGroup(Decl *decl) {
27532753
return false;
27542754
}
27552755

2756+
static bool usesFeatureInheritActorContext(Decl *decl) {
2757+
if (auto func = dyn_cast<AbstractFunctionDecl>(decl)) {
2758+
for (auto param : *func->getParameters()) {
2759+
if (param->getAttrs().hasAttribute<InheritActorContextAttr>())
2760+
return true;
2761+
}
2762+
}
2763+
2764+
return false;
2765+
}
2766+
27562767
/// Determine the set of "new" features used on a given declaration.
27572768
///
27582769
/// Note: right now, all features we check for are "new". At some point, we'll

test/ModuleInterface/features.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ public func runSomethingConcurrently(body: @Sendable () -> Void) { }
143143
// CHECK-NEXT: #endif
144144
public func stage(with actor: MyActor) { }
145145

146+
// CHECK: #if compiler(>=5.3) && $AsyncAwait && $Sendable && $InheritActorContext
147+
// CHECK-NEXT: func asyncIsh
148+
// CHECK-NEXT: #endif
149+
public func asyncIsh(@_inheritActorContext operation: @Sendable @escaping () async -> Void) { }
150+
146151
// CHECK-NOT: extension MyActor : Swift.Sendable
147152

148153
// CHECK: #if compiler(>=5.3) && $MarkerProtocol

0 commit comments

Comments
 (0)