Skip to content

Commit ec219dc

Browse files
authored
Merge pull request #86089 from gottesmm/release/6.3-rdar166244033
[6.3][concurrency] Hide Concurrency StackNesting builtins behind a feature flag
2 parents d1acc97 + 78548f7 commit ec219dc

File tree

5 files changed

+75
-2
lines changed

5 files changed

+75
-2
lines changed

include/swift/Basic/Features.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ LANGUAGE_FEATURE(LifetimeDependenceMutableAccessors, 0, "Support mutable accesso
277277
LANGUAGE_FEATURE(InoutLifetimeDependence, 0, "Support @_lifetime(&)")
278278
SUPPRESSIBLE_LANGUAGE_FEATURE(NonexhaustiveAttribute, 487, "Nonexhaustive Enums")
279279
LANGUAGE_FEATURE(ModuleSelector, 491, "Module selectors (`Module::name` syntax)")
280+
LANGUAGE_FEATURE(BuiltinConcurrencyStackNesting, 0, "Concurrency Stack Nesting Builtins")
280281

281282
// Swift 6
282283
UPCOMING_FEATURE(ConciseMagicFile, 274, 6)

lib/AST/FeatureSet.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,10 @@ static bool usesFeatureClosureBodyMacro(Decl *decl) {
347347
return false;
348348
}
349349

350+
static bool usesFeatureBuiltinConcurrencyStackNesting(Decl *decl) {
351+
return false;
352+
}
353+
350354
UNINTERESTING_FEATURE(StrictMemorySafety)
351355
UNINTERESTING_FEATURE(LibraryEvolution)
352356
UNINTERESTING_FEATURE(SafeInteropWrappers)

stdlib/public/Concurrency/Task+PriorityEscalation.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,30 @@ func __withTaskPriorityEscalationHandler0<T, E>(
125125
onPriorityEscalated handler0: @Sendable (UInt8, UInt8) -> Void,
126126
isolation: isolated (any Actor)? = #isolation
127127
) async throws(E) -> T {
128+
#if $BuiltinConcurrencyStackNesting
128129
let record =
129130
unsafe Builtin.taskAddPriorityEscalationHandler(handler: handler0)
130131
defer {
131132
unsafe Builtin.taskRemovePriorityEscalationHandler(record: record)
132133
}
134+
#else
135+
let record = unsafe _taskAddPriorityEscalationHandler(handler: handler0)
136+
defer { unsafe _taskRemovePriorityEscalationHandler(record: record) }
137+
#endif
133138

134139
return try await operation()
135140
}
141+
142+
@usableFromInline
143+
@available(SwiftStdlib 6.2, *)
144+
@_silgen_name("swift_task_addPriorityEscalationHandler")
145+
func _taskAddPriorityEscalationHandler(
146+
handler: (UInt8, UInt8) -> Void
147+
) -> UnsafeRawPointer /*EscalationNotificationStatusRecord*/
148+
149+
@usableFromInline
150+
@available(SwiftStdlib 6.2, *)
151+
@_silgen_name("swift_task_removePriorityEscalationHandler")
152+
func _taskRemovePriorityEscalationHandler(
153+
record: UnsafeRawPointer /*EscalationNotificationStatusRecord*/
154+
)

stdlib/public/Concurrency/TaskCancellation.swift

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,13 @@ public func withTaskCancellationHandler<T>(
8484
) async rethrows -> T {
8585
// unconditionally add the cancellation record to the task.
8686
// if the task was already cancelled, it will be executed right away.
87+
#if $BuiltinConcurrencyStackNesting
8788
let record = unsafe Builtin.taskAddCancellationHandler(handler: handler)
8889
defer { unsafe Builtin.taskRemoveCancellationHandler(record: record) }
89-
90+
#else
91+
let record = unsafe _taskAddCancellationHandler(handler: handler)
92+
defer { unsafe _taskRemoveCancellationHandler(record: record) }
93+
#endif
9094
return try await operation()
9195
}
9296

@@ -105,9 +109,13 @@ public func _unsafeInheritExecutor_withTaskCancellationHandler<T>(
105109
) async rethrows -> T {
106110
// unconditionally add the cancellation record to the task.
107111
// if the task was already cancelled, it will be executed right away.
112+
#if $BuiltinConcurrencyStackNesting
108113
let record = unsafe Builtin.taskAddCancellationHandler(handler: handler)
109114
defer { unsafe Builtin.taskRemoveCancellationHandler(record: record) }
110-
115+
#else
116+
let record = unsafe _taskAddCancellationHandler(handler: handler)
117+
defer { unsafe _taskRemoveCancellationHandler(record: record) }
118+
#endif
111119
return try await operation()
112120
}
113121

@@ -163,3 +171,16 @@ public struct CancellationError: Error {
163171
// no extra information, cancellation is intended to be light-weight
164172
public init() {}
165173
}
174+
175+
@usableFromInline
176+
@available(SwiftStdlib 5.1, *)
177+
@_silgen_name("swift_task_addCancellationHandler")
178+
func _taskAddCancellationHandler(handler: () -> Void) -> UnsafeRawPointer /*CancellationNotificationStatusRecord*/
179+
180+
@usableFromInline
181+
@available(SwiftStdlib 5.1, *)
182+
@_silgen_name("swift_task_removeCancellationHandler")
183+
func _taskRemoveCancellationHandler(
184+
record: UnsafeRawPointer /*CancellationNotificationStatusRecord*/
185+
)
186+

stdlib/public/Concurrency/TaskLocal.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,13 @@ public final class TaskLocal<Value: Sendable>: Sendable, CustomStringConvertible
259259
operation: () async throws -> R,
260260
isolation: isolated (any Actor)?,
261261
file: String = #fileID, line: UInt = #line) async rethrows -> R {
262+
#if $BuiltinConcurrencyStackNesting
262263
Builtin.taskLocalValuePush(key, consume valueDuringOperation)
263264
defer { Builtin.taskLocalValuePop() }
265+
#else
266+
_taskLocalValuePush(key: key, value: consume valueDuringOperation)
267+
defer { _taskLocalValuePop() }
268+
#endif
264269

265270
return try await operation()
266271
}
@@ -275,8 +280,13 @@ public final class TaskLocal<Value: Sendable>: Sendable, CustomStringConvertible
275280
operation: () async throws -> R,
276281
file: String = #fileID, line: UInt = #line
277282
) async rethrows -> R {
283+
#if $BuiltinConcurrencyStackNesting
278284
Builtin.taskLocalValuePush(key, consume valueDuringOperation)
279285
defer { Builtin.taskLocalValuePop() }
286+
#else
287+
_taskLocalValuePush(key: key, value: consume valueDuringOperation)
288+
defer { _taskLocalValuePop() }
289+
#endif
280290

281291
return try await operation()
282292
}
@@ -299,8 +309,13 @@ public final class TaskLocal<Value: Sendable>: Sendable, CustomStringConvertible
299309
@discardableResult
300310
public func withValue<R>(_ valueDuringOperation: Value, operation: () throws -> R,
301311
file: String = #fileID, line: UInt = #line) rethrows -> R {
312+
#if $BuiltinConcurrencyStackNesting
302313
Builtin.taskLocalValuePush(key, valueDuringOperation)
303314
defer { Builtin.taskLocalValuePop() }
315+
#else
316+
_taskLocalValuePush(key: key, value: valueDuringOperation)
317+
defer { _taskLocalValuePop() }
318+
#endif
304319

305320
return try operation()
306321
}
@@ -344,6 +359,19 @@ public final class TaskLocal<Value: Sendable>: Sendable, CustomStringConvertible
344359

345360
// ==== ------------------------------------------------------------------------
346361

362+
@available(SwiftStdlib 5.1, *)
363+
@usableFromInline
364+
@_silgen_name("swift_task_localValuePush")
365+
func _taskLocalValuePush<Value>(
366+
key: Builtin.RawPointer/*: Key*/,
367+
value: __owned Value
368+
) // where Key: TaskLocal
369+
370+
@available(SwiftStdlib 5.1, *)
371+
@usableFromInline
372+
@_silgen_name("swift_task_localValuePop")
373+
func _taskLocalValuePop()
374+
347375
@available(SwiftStdlib 5.1, *)
348376
@_silgen_name("swift_task_localValueGet")
349377
func _taskLocalValueGet(

0 commit comments

Comments
 (0)