Skip to content

Commit 8964436

Browse files
committed
Add _unsafeInheritExecutor_ version of TaskLocal.withValue
1 parent a2038f9 commit 8964436

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

stdlib/public/Concurrency/TaskLocal.swift

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,14 +215,21 @@ public final class TaskLocal<Value: Sendable>: Sendable, CustomStringConvertible
215215
file: file, line: line)
216216
}
217217

218-
@usableFromInline
218+
// Note: hack to stage out @_unsafeInheritExecutor forms of various functions
219+
// in favor of #isolation. The _unsafeInheritExecutor_ prefix is meaningful
220+
// to the type checker.
221+
//
222+
// This function also doubles as an ABI-compatibility shim predating the
223+
// introduction of #isolation.
219224
@discardableResult
220225
@_unsafeInheritExecutor // ABI compatibility with Swift 5.1
221226
@available(SwiftStdlib 5.1, *)
222227
@_silgen_name("$ss9TaskLocalC9withValue_9operation4file4lineqd__x_qd__yYaKXESSSutYaKlF")
223-
internal func __abi_withValue<R>(_ valueDuringOperation: Value,
224-
operation: () async throws -> R,
225-
file: String = #fileID, line: UInt = #line) async rethrows -> R {
228+
public func _unsafeInheritExecutor_withValue<R>(
229+
_ valueDuringOperation: Value,
230+
operation: () async throws -> R,
231+
file: String = #fileID, line: UInt = #line
232+
) async rethrows -> R {
226233
return try await withValueImpl(valueDuringOperation, operation: operation, file: file, line: line)
227234
}
228235

test/Concurrency/unsafe_inherit_executor.swift

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// RUN: %target-swift-frontend -emit-sil -o /dev/null -verify -disable-availability-checking %s
2-
// RUN: %target-swift-frontend -emit-sil -o /dev/null -verify -disable-availability-checking %s -strict-concurrency=targeted
3-
// RUN: %target-swift-frontend -emit-sil -o /dev/null -verify -disable-availability-checking %s -strict-concurrency=complete
4-
// RUN: %target-swift-frontend -emit-sil -o /dev/null -verify -disable-availability-checking %s -strict-concurrency=complete -enable-upcoming-feature RegionBasedIsolation
1+
// RUN: %target-swift-frontend -plugin-path %swift-plugin-dir -emit-sil -o /dev/null -verify -disable-availability-checking %s
2+
// RUN: %target-swift-frontend -plugin-path %swift-plugin-dir -emit-sil -o /dev/null -verify -disable-availability-checking %s -strict-concurrency=targeted
3+
// RUN: %target-swift-frontend -plugin-path %swift-plugin-dir -emit-sil -o /dev/null -verify -disable-availability-checking %s -strict-concurrency=complete
4+
// RUN: %target-swift-frontend -plugin-path %swift-plugin-dir -emit-sil -o /dev/null -verify -disable-availability-checking %s -strict-concurrency=complete -enable-upcoming-feature RegionBasedIsolation
55

66
// REQUIRES: asserts
77

@@ -83,6 +83,11 @@ func unsafeCallerAvoidsNewLoop(x: some AsyncSequence<Int, Never>) async throws {
8383
// some concurrency library functions.
8484
// -------------------------------------------------------------------------
8585

86+
enum TL {
87+
@TaskLocal
88+
static var string: String = "<undefined>"
89+
}
90+
8691
@_unsafeInheritExecutor
8792
func unsafeCallerAvoidsNewLoop() async throws {
8893
// expected-warning@-1{{@_unsafeInheritExecutor attribute is deprecated; consider an 'isolated' parameter defaulted to '#isolation' instead}}
@@ -107,4 +112,8 @@ func unsafeCallerAvoidsNewLoop() async throws {
107112
5
108113
} onCancel: {
109114
}
115+
116+
TL.$string.withValue("hello") {
117+
print(TL.string)
118+
}
110119
}

0 commit comments

Comments
 (0)