Skip to content

Commit ef27110

Browse files
committed
[TaskLocals] Avoid use of defer in back deployed functions in the standard library.
Older versions of the 5.8 compiler have a bug when generating SIL for functions with `@_backDeploy` containing defer blocks (#62444) and for now we need the standard library interface to be compatible with those older compilers. Resolves rdar://104045168
1 parent 24fe6ae commit ef27110

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

stdlib/public/BackDeployConcurrency/TaskCancellation.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,10 @@ public func withTaskCancellationHandler<T>(
4646
// unconditionally add the cancellation record to the task.
4747
// if the task was already cancelled, it will be executed right away.
4848
let record = _taskAddCancellationHandler(handler: handler)
49-
defer { _taskRemoveCancellationHandler(record: record) }
49+
let result = try await operation()
50+
_taskRemoveCancellationHandler(record: record)
5051

51-
return try await operation()
52+
return result
5253
}
5354

5455
@available(SwiftStdlib 5.1, *)

stdlib/public/BackDeployConcurrency/TaskLocal.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,10 @@ public final class TaskLocal<Value: Sendable>: Sendable, CustomStringConvertible
145145
_checkIllegalTaskLocalBindingWithinWithTaskGroup(file: file, line: line)
146146

147147
_taskLocalValuePush(key: key, value: valueDuringOperation)
148-
defer { _taskLocalValuePop() }
148+
let result = try await operation()
149+
_taskLocalValuePop()
149150

150-
return try await operation()
151+
return result
151152
}
152153

153154
/// Binds the task-local to the specific value for the duration of the

stdlib/public/Concurrency/TaskCancellation.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,10 @@ public func withTaskCancellationHandler<T>(
4646
// unconditionally add the cancellation record to the task.
4747
// if the task was already cancelled, it will be executed right away.
4848
let record = _taskAddCancellationHandler(handler: handler)
49-
defer { _taskRemoveCancellationHandler(record: record) }
49+
let result = try await operation()
50+
_taskRemoveCancellationHandler(record: record)
5051

51-
return try await operation()
52+
return result
5253
}
5354

5455
@available(SwiftStdlib 5.1, *)

stdlib/public/Concurrency/TaskLocal.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,10 @@ public final class TaskLocal<Value: Sendable>: Sendable, CustomStringConvertible
145145
_checkIllegalTaskLocalBindingWithinWithTaskGroup(file: file, line: line)
146146

147147
_taskLocalValuePush(key: key, value: valueDuringOperation)
148-
defer { _taskLocalValuePop() }
148+
let result = try await operation()
149+
_taskLocalValuePop()
149150

150-
return try await operation()
151+
return result
151152
}
152153

153154
/// Binds the task-local to the specific value for the duration of the

0 commit comments

Comments
 (0)