You can find it in SwiftUI's .swiftinterface file (aka the "header file" for Swift modules).
The module interface is located at:
[Path to Xcode.app]/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/SwiftUI.framework/Modules/SwiftUI.swiftmodule
Inside, you'll find this declaration for .task, including the @_inheritActorContext attribute:
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
extension SwiftUI.View {
#if compiler(>=5.3) && $AsyncAwait && $Sendable && $InheritActorContext
@inlinable public func task(priority: _Concurrency.TaskPriority = .userInitiated, @_inheritActorContext _ action: @escaping @Sendable () async -> Swift.Void) -> some SwiftUI.View {
modifier(_TaskModifier(priority: priority, action: action))
}
#endif
…
}
And you'll find that View.body has the @MainActor(unsafe) attribute:
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
@_typeEraser(AnyView) public protocol View {
…
@SwiftUI.ViewBuilder @_Concurrency.MainActor(unsafe) var body: Self.Body { get }
}
The fact that View.body is @MainActor is significant because that's where .task inherits its actor context from.
At least if you use .task inside the body property, that is. If you place the .task modifier inside a helper property that isn't annotated with @MainActor, you'll see an error:
import SwiftUI
@MainActor
func foo() {
print("Hey!")
}
struct ContentView: View {
// is explicitly @MainActor via the View protocol
var body: some View {
helper
}
// is not @MainActor
var helper: some View {
Text("Hello, world!")
.task {
// Error: Expression is 'async' but is not marked with 'await'
foo()
}
}
}