mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
- Extend `@_inheritActorContext` attribute to support optional `always` modifier. The new modifier will make closure context isolated even if the parameter is not captured by the closure. - Implementation `@_inheritActorContext` attribute validation - it could only be used on parameter that have `@Sendable` or `sending` and `@isolated(any)` or `async` function type (downgraded to a warning until future major Swift mode to avoid source compatibility issues). - Add a new language feature that guards use of `@_inheritActorContext(always)` in swift interface files - Update `getLoweredLocalCaptures` to add an entry for isolation parameter implicitly captured by `@_inheritActorContext(always)` - Update serialization code to store `always` modifier (cherry picked from commit04d46760bb) (cherry picked from commitc050e8f75a) (cherry picked from commitc0aca5384b) (cherry picked from commita4f6d710cf) (cherry picked from commit6c911f5d42) (cherry picked from commit17b8f7ef12)
39 lines
1.9 KiB
Swift
39 lines
1.9 KiB
Swift
// RUN: %target-typecheck-verify-swift
|
|
|
|
func test1(@_inheritActorContext _: @Sendable () async -> Void) {} // Ok
|
|
func test2(@_inheritActorContext(always) _: sending () async -> Void) {} // Ok
|
|
|
|
func test3(@_inheritActorContext _: () async -> Void) {}
|
|
// expected-warning@-1 {{@_inheritActorContext only applies to 'sending' parameters or parameters with '@Sendable' function types}}
|
|
func test3(@_inheritActorContext _: @Sendable () -> Void) {}
|
|
// expected-warning@-1 {{@_inheritActorContext only applies to '@isolated(any)' parameters or parameters with asynchronous function types}}
|
|
|
|
func test4(@_inheritActorContext _: Int) {}
|
|
// expected-error@-1 {{@_inheritActorContext only applies to parameters with function types (got: 'Int')}}
|
|
|
|
func test5(@_inheritActorContext _: sending Optional<() async -> Int>) {} // Ok
|
|
func test6(@_inheritActorContext _: (Optional<@Sendable () async -> Int>)?) {} // Ok
|
|
func test6(@_inheritActorContext _: (Optional<@Sendable @isolated(any) () -> Int>)?) {} // Ok
|
|
|
|
func test7(@_inheritActorContext _: Int?) {} // Ok
|
|
// expected-error@-1 {{@_inheritActorContext only applies to parameters with function types (got: 'Int?')}}
|
|
|
|
struct S {
|
|
init(@_inheritActorContext(always) _: @escaping @Sendable () async -> Void) {} // Ok
|
|
|
|
var test: @_inheritActorContext () async -> Void { // expected-error {{attribute can only be applied to declarations, not types}}
|
|
{ }
|
|
}
|
|
|
|
subscript(@_inheritActorContext _: @Sendable () async -> Void) -> Bool { false } // Ok
|
|
subscript(@_inheritActorContext(always) _: @Sendable (Int) async -> Void) -> Bool { false } // Ok
|
|
|
|
subscript(@_inheritActorContext _: sending (String) async -> Void) -> Bool { false }
|
|
subscript(x: Int, @_inheritActorContext(always) _: @Sendable (Int, Int) async -> Void) -> Bool { false }
|
|
|
|
func testClosure() {
|
|
_ = { @_inheritActorContext in // expected-error {{attribute @_inheritActorContext is not supported on a closure}}
|
|
}
|
|
}
|
|
}
|