Skip to content

Commit 698a975

Browse files
authored
Merge pull request swiftlang#36586 from jckarter/owned-task-spawn-closures
Allow closures to be `__owned` or `__shared`, and make task spawning closures `__owned`
2 parents 3df5ca6 + c6691f3 commit 698a975

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

lib/Sema/TypeCheckType.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3481,8 +3481,9 @@ TypeResolver::resolveSpecifierTypeRepr(SpecifierTypeRepr *repr,
34813481
return ErrorType::get(getASTContext());
34823482
}
34833483

3484-
if (!isa<ImplicitlyUnwrappedOptionalTypeRepr>(repr->getBase())) {
3485-
// Anything within the inout isn't a parameter anymore.
3484+
if (isa<InOutTypeRepr>(repr)
3485+
&& !isa<ImplicitlyUnwrappedOptionalTypeRepr>(repr->getBase())) {
3486+
// Anything within an inout isn't a parameter anymore.
34863487
options.setContext(None);
34873488
}
34883489

stdlib/public/Concurrency/Task.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ extension Task {
377377
@discardableResult
378378
public static func runDetached<T>(
379379
priority: Priority = .default,
380-
operation: @Sendable @escaping () async -> T
380+
operation: __owned @Sendable @escaping () async -> T
381381
// TODO: Allow inheriting task-locals?
382382
) -> Handle<T, Never> {
383383
// Set up the job flags for a new task.
@@ -430,7 +430,7 @@ extension Task {
430430
@discardableResult
431431
public static func runDetached<T, Failure>(
432432
priority: Priority = .default,
433-
operation: @Sendable @escaping () async throws -> T
433+
operation: __owned @Sendable @escaping () async throws -> T
434434
) -> Handle<T, Failure> {
435435
// Set up the job flags for a new task.
436436
var flags = JobFlags()

stdlib/public/Concurrency/TaskGroup.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ extension Task {
124124
@discardableResult
125125
public mutating func add(
126126
overridingPriority priorityOverride: Priority? = nil,
127-
operation: @Sendable @escaping () async throws -> TaskResult
127+
operation: __owned @Sendable @escaping () async throws -> TaskResult
128128
) async -> Bool {
129129
let canAdd = _taskGroupAddPendingTask(group: _group)
130130

0 commit comments

Comments
 (0)