[Frontend] Add a feature to guard use of @concurrent and nonisolated(nonsending) in swift interface files

This commit is contained in:
Pavel Yaskevich
2025-04-11 15:47:47 -07:00
parent dafc31ae08
commit e98ba2d0bc
3 changed files with 119 additions and 5 deletions

View File

@@ -6,22 +6,58 @@
// REQUIRES: concurrency
public struct Test {
// CHECK: nonisolated(nonsending) public init() async
// CHECK: #if compiler(>=5.3) && $AsyncExecutionBehaviorAttributes
// CHECK-NEXT: nonisolated(nonsending) public init() async
// CHECK-NEXT: #endif
nonisolated(nonsending)
public init() async {
}
// CHECK: @concurrent public func test() async
// CHECK: #if compiler(>=5.3) && $AsyncExecutionBehaviorAttributes
// CHECK-NEXT: @concurrent public init(something: Swift.Int) async
// CHECK-NEXT: #endif
@concurrent
public init(something: Int) async {
}
// CHECK-NOT: #if compiler(>=5.3) && $AsyncExecutionBehaviorAttributes
// CHECK: public init(noExplicit: Swift.String) async
// CHECK-NOT: #endif
public init(noExplicit: String) async {
}
// CHECK: #if compiler(>=5.3) && $AsyncExecutionBehaviorAttributes
// CHECK-NEXT: @concurrent public func test() async
// CHECK-NEXT: #endif
@concurrent
public func test() async {
}
// CHECK: public func other(_: nonisolated(nonsending) () async -> Swift.Void)
// CHECK: #if compiler(>=5.3) && $AsyncExecutionBehaviorAttributes
// CHECK-NEXT: public func other(_: nonisolated(nonsending) () async -> Swift.Void)
// CHECK-NEXT: #endif
public func other(_: nonisolated(nonsending) () async -> Void) {}
// CHECK: nonisolated(nonsending) public var testOnVar: Swift.Int {
// CHECK-NOT: #if compiler(>=5.3) && $AsyncExecutionBehaviorAttributes
// CHECK: public func concurrentResult(_: () async -> Swift.Void) -> (Swift.Int) async -> Swift.Void
// CHECK-NOT: #endif
public func concurrentResult(_: () async -> Void) -> @concurrent (Int) async -> Void {}
// CHECK: #if compiler(>=5.3) && $AsyncExecutionBehaviorAttributes
// CHECK-NEXT: public func nestedPositions1(_: Swift.Array<[Swift.String : nonisolated(nonsending) (Swift.Int) async -> Swift.Void]>)
// CHECK-NEXT: #endif
public func nestedPositions1(_: Array<[String: nonisolated(nonsending) (Int) async -> Void]>) {}
// CHECK-NOT: #if compiler(>=5.3) && $AsyncExecutionBehaviorAttributes
// CHECK: public func nestedPositions2(_: Swift.Array<[Swift.String : (Swift.Int) async -> Swift.Void]>)
// CHECK-NOT: #endif
public func nestedPositions2(_: Array<[String: @concurrent (Int) async -> Void]>) {}
// CHECK: #if compiler(>=5.3) && $AsyncExecutionBehaviorAttributes
// CHECK-NEXT: nonisolated(nonsending) public var testOnVar: Swift.Int {
// CHECK-NEXT: get async
// CHECK-NEXT: }
// CHECK-NEXT: #endif
nonisolated(nonsending)
public var testOnVar: Int {
get async {
@@ -29,14 +65,40 @@ public struct Test {
}
}
// CHECK: nonisolated(nonsending) public subscript(onSubscript _: Swift.Int) -> Swift.Bool {
// CHECK: #if compiler(>=5.3) && $AsyncExecutionBehaviorAttributes
// CHECK-NEXT: @concurrent public var testOnVarConcurrent: Swift.Int {
// CHECK-NEXT: get async
// CHECK-NEXT: }
// CHECK-NEXT: #endif
@concurrent
public var testOnVarConcurrent: Int {
get async {
42
}
}
// CHECK: #if compiler(>=5.3) && $AsyncExecutionBehaviorAttributes
// CHECK-NEXT: nonisolated(nonsending) public subscript(onSubscript _: Swift.Int) -> Swift.Bool {
// CHECK-NEXT: get async
// CHECK-NEXT: }
// CHECK-NEXT: #endif
nonisolated(nonsending)
public subscript(onSubscript _: Int) -> Bool {
get async {
false
}
}
// CHECK: #if compiler(>=5.3) && $AsyncExecutionBehaviorAttributes
// CHECK-NEXT: @concurrent public subscript(concurrentOnSubscript _: Swift.Int) -> Swift.Bool {
// CHECK-NEXT: get async
// CHECK-NEXT: }
// CHECK-NEXT: #endif
@concurrent
public subscript(concurrentOnSubscript _: Int) -> Bool {
get async {
false
}
}
}