Skip to content

Commit c050e8f

Browse files
committed
[AST] Protect declarations with @_inheritActorContext(always) by a feature flag
This is going to avoid condfails when declarations are printed in the swiftinterface files.
1 parent 04d4676 commit c050e8f

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

include/swift/Basic/Features.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ LANGUAGE_FEATURE(IsolatedConformances, 407, "Global-actor isolated conformances"
259259
LANGUAGE_FEATURE(ValueGenericsNameLookup, 452, "Value generics appearing as static members for namelookup")
260260
LANGUAGE_FEATURE(GeneralizedIsSameMetaTypeBuiltin, 465, "Builtin.is_same_metatype with support for noncopyable/nonescapable types")
261261
SUPPRESSIBLE_LANGUAGE_FEATURE(ABIAttributeSE0479, 479, "@abi attribute on functions, initializers, properties, and subscripts")
262+
LANGUAGE_FEATURE(AlwaysInheritActorContext, 472, "@_inheritActorContext(always)")
262263

263264
// Swift 6
264265
UPCOMING_FEATURE(ConciseMagicFile, 274, 6)

lib/AST/FeatureSet.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,21 @@ static bool usesFeatureExtensibleAttribute(Decl *decl) {
624624
return decl->getAttrs().hasAttribute<ExtensibleAttr>();
625625
}
626626

627+
static bool usesFeatureAlwaysInheritActorContext(Decl *decl) {
628+
auto *VD = dyn_cast<ValueDecl>(decl);
629+
if (!VD)
630+
return false;
631+
632+
if (auto *PL = VD->getParameterList()) {
633+
return llvm::any_of(*PL, [&](const ParamDecl *P) {
634+
auto *attr = P->getAttrs().getAttribute<InheritActorContextAttr>();
635+
return attr && attr->isAlways();
636+
});
637+
}
638+
639+
return false;
640+
}
641+
627642
// ----------------------------------------------------------------------------
628643
// MARK: - FeatureSet
629644
// ----------------------------------------------------------------------------
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-emit-module-interface(%t/Library.swiftinterface) %s -module-name Library
3+
// RUN: %target-swift-typecheck-module-from-interface(%t/Library.swiftinterface) -module-name Library
4+
// RUN: %FileCheck %s < %t/Library.swiftinterface
5+
6+
// CHECK-NOT: #if compiler(>=5.3) && $AlwaysInheritActorContext
7+
// CHECK: public func globalTest(@_inheritActorContext _: @Sendable () async -> Swift.Void)
8+
// CHECK-NOT: #endif
9+
public func globalTest(@_inheritActorContext _: @Sendable () async -> Void) {}
10+
11+
// CHECK: #if compiler(>=5.3) && $AlwaysInheritActorContext
12+
// CHECK-NEXT: public func globalTestAlways(@_inheritActorContext(always) _: @Sendable () async -> Swift.Void)
13+
// CHECK-NEXT: #endif
14+
public func globalTestAlways(@_inheritActorContext(always) _: @Sendable () async -> Void) {}
15+
16+
public struct Test {
17+
// CHECK-NOT: #if compiler(>=5.3) && $AlwaysInheritActorContext
18+
// CHECK: public init(@_inheritActorContext x: @Sendable () async -> Swift.Int)
19+
// CHECK-NOT: #endif
20+
public init(@_inheritActorContext x: @Sendable () async -> Int) {}
21+
22+
// CHECK: #if compiler(>=5.3) && $AlwaysInheritActorContext
23+
// CHECK-NEXT: #if compiler(>=5.3) && $SendingArgsAndResults
24+
// CHECK-NEXT: public init(@_inheritActorContext(always) y: sending () async -> Swift.Void)
25+
// CHECK-NEXT: #else
26+
// CHECK-NEXT: public init(@_inheritActorContext(always) y: () async -> Swift.Void)
27+
// CHECK-NEXT: #endif
28+
// CHECK-NEXT: #endif
29+
public init(@_inheritActorContext(always) y: sending () async -> Void) {}
30+
31+
// CHECK-NOT: #if compiler(>=5.3) && $AlwaysInheritActorContext
32+
// CHECK: public subscript(@_inheritActorContext _: @Sendable () async -> Swift.Void) -> Swift.Bool {
33+
// CHECK-NEXT: get
34+
// CHECK-NEXT: }
35+
// CHECK-NOT: #endif
36+
public subscript(@_inheritActorContext _: @Sendable () async -> Void) -> Bool { false }
37+
38+
// CHECK: #if compiler(>=5.3) && $AlwaysInheritActorContext
39+
// CHECK-NEXT: public subscript(@_inheritActorContext(always) _: @Sendable (Swift.Int) async -> Swift.Void) -> Swift.Bool {
40+
// CHECK-NEXT: get
41+
// CHECK-NEXT: }
42+
public subscript(@_inheritActorContext(always) _: @Sendable (Int) async -> Void) -> Bool { false }
43+
}

0 commit comments

Comments
 (0)