Skip to content

Commit 6f3dac1

Browse files
committed
[TaskLocals] remove TaskLocalInheritance, we'll introduce when needed
1 parent a70cd95 commit 6f3dac1

File tree

10 files changed

+14
-204
lines changed

10 files changed

+14
-204
lines changed

include/swift/ABI/Task.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,8 @@ class AsyncTask : public Job {
248248
Local.pushValue(this, key, value, valueType);
249249
}
250250

251-
OpaqueValue* localValueGet(const HeapObject *key,
252-
TaskLocal::TaskLocalInheritance inherit) {
253-
return Local.getValue(this, key, inherit);
251+
OpaqueValue* localValueGet(const HeapObject *key) {
252+
return Local.getValue(this, key);
254253
}
255254

256255
void localValuePop() {

include/swift/ABI/TaskLocal.h

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -46,28 +46,6 @@ class TaskLocal {
4646
IsParent = 0b01,
4747
};
4848

49-
/// Values must match `TaskLocalInheritance` declared in `TaskLocal.swift`.
50-
enum class TaskLocalInheritance : uint8_t {
51-
/// Default task local value behavior
52-
///
53-
/// Values declared with a default-inherited key are accessible from:
54-
/// - the current task that has bound the value,
55-
/// - any child task of the current task (e.g. created by async let or groups)
56-
///
57-
/// Such values are *not* carried through detached tasks.
58-
Default = 0,
59-
60-
/// Special semantics which confine a task's local value to *only* the current
61-
/// task. In other words, they ave never inherited by any child task created
62-
/// by the current task.
63-
///
64-
/// Values declared with a never-inherited key only accessible:
65-
/// - specifically from the current task itself
66-
///
67-
/// Such values are *not* accessible from child tasks or detached tasks.
68-
Never = 1
69-
};
70-
7149
class Item {
7250
private:
7351
/// Mask used for the low status bits in a task local chain item.
@@ -204,9 +182,7 @@ class TaskLocal {
204182
const HeapObject *key,
205183
/* +1 */ OpaqueValue *value, const Metadata *valueType);
206184

207-
OpaqueValue* getValue(AsyncTask *task,
208-
const HeapObject *key,
209-
TaskLocalInheritance inheritance);
185+
OpaqueValue* getValue(AsyncTask *task, const HeapObject *key);
210186

211187
void popValue(AsyncTask *task);
212188

include/swift/Runtime/Concurrency.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -430,15 +430,12 @@ void swift_task_reportIllegalTaskLocalBindingWithinWithTaskGroup(
430430
/// \code
431431
/// func _taskLocalValueGet<Key>(
432432
/// _ task: Builtin.NativeObject,
433-
/// keyType: Any.Type /*Key.Type*/,
434-
/// inheritance: UInt8/*TaskLocalInheritance*/
433+
/// keyType: Any.Type /*Key.Type*/
435434
/// ) -> UnsafeMutableRawPointer? where Key: TaskLocalKey
436435
/// \endcode
437436
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
438437
OpaqueValue*
439-
swift_task_localValueGet(AsyncTask* task,
440-
const HeapObject *key,
441-
TaskLocal::TaskLocalInheritance inheritance);
438+
swift_task_localValueGet(AsyncTask* task, const HeapObject *key);
442439

443440
/// Add a task local value to the passed in task.
444441
///

stdlib/public/CompatibilityOverride/CompatibilityOverrideConcurrency.def

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,8 @@ OVERRIDE_TASK_LOCAL(task_localValuePush, void,
235235
OVERRIDE_TASK_LOCAL(task_localValueGet, OpaqueValue *,
236236
SWIFT_EXPORT_FROM(swift_Concurrency), SWIFT_CC(swift),
237237
swift::,
238-
(AsyncTask *task, const HeapObject *key,
239-
TaskLocal::TaskLocalInheritance inheritance),
240-
(task, key, inheritance))
238+
(AsyncTask *task, const HeapObject *key),
239+
(task, key))
241240

242241
OVERRIDE_TASK_LOCAL(task_localValuePop, void,
243242
SWIFT_EXPORT_FROM(swift_Concurrency), SWIFT_CC(swift),

stdlib/public/Concurrency/Task.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
using namespace swift;
3636
using FutureFragment = AsyncTask::FutureFragment;
3737
using TaskGroup = swift::TaskGroup;
38-
using TaskLocalInheritance = TaskLocal::TaskLocalInheritance;
3938

4039
void FutureFragment::destroy() {
4140
auto queueHead = waitQueue.load(std::memory_order_acquire);

stdlib/public/Concurrency/TaskLocal.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ static void swift_task_localValuePushImpl(AsyncTask *task,
4141

4242
SWIFT_CC(swift)
4343
static OpaqueValue* swift_task_localValueGetImpl(AsyncTask *task,
44-
const HeapObject *key,
45-
TaskLocal::TaskLocalInheritance inheritance) {
46-
return task->localValueGet(key, inheritance);
44+
const HeapObject *key) {
45+
return task->localValueGet(key);
4746
}
4847

4948
SWIFT_CC(swift)
@@ -249,8 +248,7 @@ void TaskLocal::Storage::popValue(AsyncTask *task) {
249248
}
250249

251250
OpaqueValue* TaskLocal::Storage::getValue(AsyncTask *task,
252-
const HeapObject *key,
253-
const TaskLocalInheritance inherit) {
251+
const HeapObject *key) {
254252
assert(key && "TaskLocal key must not be null.");
255253

256254
auto item = head;
@@ -259,12 +257,6 @@ OpaqueValue* TaskLocal::Storage::getValue(AsyncTask *task,
259257
return item->getStoragePtr();
260258
}
261259

262-
// if the key is an `inherit = .never` type, we stop our search the first
263-
// time we would be jumping to a parent task to continue the search.
264-
if (item->getNextLinkType() == NextLinkType::IsParent &&
265-
inherit == TaskLocalInheritance::Never)
266-
return nullptr;
267-
268260
item = item->getNext();
269261
}
270262

stdlib/public/Concurrency/TaskLocal.swift

Lines changed: 3 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,10 @@ import Swift
1919
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
2020
public final class TaskLocal<Value>: CustomStringConvertible {
2121
var defaultValue: Value
22-
var inherit: TaskLocalInheritance
2322

2423
// Note: could overload with additional parameters to support other features
2524
public init(wrappedValue: Value) {
2625
self.defaultValue = wrappedValue
27-
self.inherit = .default
28-
}
29-
30-
public init(wrappedValue: Value, inherit: TaskLocalInheritance) {
31-
self.defaultValue = wrappedValue
32-
self.inherit = inherit
3326
}
3427

3528
public var wrappedValue: Value {
@@ -40,7 +33,7 @@ public final class TaskLocal<Value>: CustomStringConvertible {
4033
}
4134

4235
let value = _taskLocalValueGet(
43-
task._task, key: unsafeBitCast(self, to: Builtin.RawPointer.self), inheritance: inherit.rawValue)
36+
task._task, key: unsafeBitCast(self, to: Builtin.RawPointer.self))
4437

4538
guard let rawValue = value else {
4639
return self.defaultValue
@@ -63,6 +56,7 @@ public final class TaskLocal<Value>: CustomStringConvertible {
6356
self
6457
}
6558

59+
/// Execute the `body` closure
6660
@discardableResult
6761
public func withValue<R>(_ valueDuringBody: Value, do body: () async throws -> R,
6862
file: String = #file, line: UInt = #line) async rethrows -> R {
@@ -87,55 +81,6 @@ public final class TaskLocal<Value>: CustomStringConvertible {
8781

8882
}
8983

90-
/// A `TaskLocalKey` is used to identify, bind and get a task local value from
91-
/// a `Task` in which a function is currently executing.
92-
///
93-
/// - SeeAlso: `Task.withLocal(_:boundTo:operation:)`
94-
/// - SeeAlso: `TaskLocal(_:)`
95-
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
96-
public protocol TaskLocalKey {
97-
/// The type of `Value` uniquely identified by this key.
98-
associatedtype Value
99-
100-
/// If a task local value is not present in a given context, its `defaultValue`
101-
/// will be returned instead.
102-
///
103-
/// A common pattern is to use an `Optional<T>` type and use `nil` as default value,
104-
/// if the type itself does not have a good "undefined" or "zero" value that could
105-
/// be used here.
106-
static var defaultValue: Value { get }
107-
108-
/// Allows configuring specialized inheritance strategies for task local values.
109-
///
110-
/// By default, task local values are accessible by the current or any of its
111-
/// child tasks (with this rule applying recursively).
112-
///
113-
/// Some, rare yet important, use-cases may require specialized inheritance
114-
/// strategies, and this property allows them to configure these for their keys.
115-
static var inherit: TaskLocalInheritance { get }
116-
}
117-
118-
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
119-
extension TaskLocalKey {
120-
public static var inherit: TaskLocalInheritance { .default }
121-
}
122-
123-
/// Determines task local value behavior in child tasks.
124-
// TODO: should likely remain extensible
125-
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
126-
public enum TaskLocalInheritance: UInt8, Equatable {
127-
/// The default inheritance strategy.
128-
///
129-
/// Task local values whose keys are `default` inherited are available to the
130-
/// task which declared them, as well as recursively by any child tasks
131-
case `default` = 0
132-
133-
/// Causes task local values to never be inherited.
134-
/// If the parent task has a value bound using this key, and a child task
135-
/// attempts to look up a value of that key, it will return `defaultValue`.
136-
case never = 1
137-
}
138-
13984
// ==== ------------------------------------------------------------------------
14085

14186
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
@@ -156,8 +101,7 @@ public func _taskLocalValuePop(
156101
@_silgen_name("swift_task_localValueGet")
157102
public func _taskLocalValueGet(
158103
_ task: Builtin.NativeObject,
159-
key: Builtin.RawPointer/*Key*/,
160-
inheritance: UInt8/*TaskLocalInheritance*/
104+
key: Builtin.RawPointer/*Key*/
161105
) -> UnsafeMutableRawPointer? // where Key: TaskLocal
162106

163107
// ==== Checks -----------------------------------------------------------------

test/Concurrency/Runtime/async_task_locals_inherit_never.swift

Lines changed: 0 additions & 91 deletions
This file was deleted.

test/Concurrency/Runtime/async_task_locals_wrapper.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ enum TL {
1313
@TaskLocal
1414
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
1515
static var number: Int = 0
16-
17-
@TaskLocal(inherit: .never)
18-
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
19-
static var string: String = "<unknown>"
2016
}
2117

2218
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)

unittests/runtime/CompatibilityOverrideConcurrency.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,7 @@ TEST_F(CompatibilityOverrideConcurrencyTest, test_swift_task_localValuePush) {
229229
}
230230

231231
TEST_F(CompatibilityOverrideConcurrencyTest, test_swift_task_localValueGet) {
232-
swift_task_localValueGet(nullptr, nullptr,
233-
swift::TaskLocal::TaskLocalInheritance());
232+
swift_task_localValueGet(nullptr, nullptr);
234233
}
235234

236235
TEST_F(CompatibilityOverrideConcurrencyTest, test_swift_task_localValuePop) {

0 commit comments

Comments
 (0)