Skip to content

Commit f51dda0

Browse files
committed
move back to Task.ID
1 parent ccb71da commit f51dda0

7 files changed

Lines changed: 106 additions & 106 deletions

File tree

benchmark/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ set(SWIFT_BENCH_MODULES
211211
single-source/Suffix
212212
single-source/SuperChars
213213
single-source/TaskGroups
214-
single-source/TaskIdentifier
214+
single-source/TaskID
215215
single-source/TaskLocalGet
216216
single-source/ToddCoxeter
217217
single-source/TwoSum

benchmark/single-source/TaskIdentifier.swift renamed to benchmark/single-source/TaskID.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===--- TaskIdentifier.swift ---------------------------------------------===//
1+
//===--- TaskID.swift -----------------------------------------------------===//
22
//
33
// This source file is part of the Swift.org open source project
44
//
@@ -10,7 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
// Measures the cost of reading the current Task's identity.
13+
// Measures the cost of reading the current Task's ID.
1414

1515
import TestsUtils
1616

@@ -20,40 +20,40 @@ public var benchmarks: [BenchmarkInfo] {
2020
}
2121
return [
2222
BenchmarkInfo(
23-
name: "TaskIdentifier.currentIdentifier",
24-
runFunction: run_TaskIdentifier_currentIdentifier,
23+
name: "TaskID.currentID",
24+
runFunction: run_TaskID_currentID,
2525
tags: [.concurrency]
2626
),
2727
BenchmarkInfo(
28-
name: "TaskIdentifier.withUnsafeCurrentTask.identifier",
29-
runFunction: run_TaskIdentifier_withUnsafeCurrentTask,
28+
name: "TaskID.withUnsafeCurrentTask.id",
29+
runFunction: run_TaskID_withUnsafeCurrentTask,
3030
tags: [.concurrency]
3131
),
3232
BenchmarkInfo(
33-
name: "TaskIdentifier.directBuiltins",
34-
runFunction: run_TaskIdentifier_directBuiltins,
33+
name: "TaskID.directBuiltins",
34+
runFunction: run_TaskID_directBuiltins,
3535
tags: [.concurrency]
3636
),
3737
]
3838
}
3939

4040
// Direct accessor: single runtime call, no closure, no ARC on the task.
4141
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
42-
private func run_TaskIdentifier_currentIdentifier(_ n: Int) async {
42+
private func run_TaskID_currentID(_ n: Int) async {
4343
for _ in 0..<n {
4444
for _ in 0..<10_000 {
45-
blackHole(Task.currentIdentifier)
45+
blackHole(Task.currentID)
4646
}
4747
}
4848
}
4949

5050
// Equivalent shape built on withUnsafeCurrentTask.
5151
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
52-
private func run_TaskIdentifier_withUnsafeCurrentTask(_ n: Int) async {
52+
private func run_TaskID_withUnsafeCurrentTask(_ n: Int) async {
5353
for _ in 0..<n {
5454
for _ in 0..<10_000 {
5555
withUnsafeCurrentTask { task in
56-
blackHole(task?.identifier)
56+
blackHole(task?.id)
5757
}
5858
}
5959
}
@@ -75,7 +75,7 @@ private let _bench_swift_task_getJobTaskId: _GetJobTaskIdFn = unsafeBitCast(
7575
)
7676

7777
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
78-
private func run_TaskIdentifier_directBuiltins(_ n: Int) async {
78+
private func run_TaskID_directBuiltins(_ n: Int) async {
7979
for _ in 0..<n {
8080
for _ in 0..<10_000 {
8181
if let task = _bench_swift_task_getCurrent() {
@@ -88,5 +88,5 @@ private func run_TaskIdentifier_directBuiltins(_ n: Int) async {
8888
}
8989
#else
9090
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
91-
private func run_TaskIdentifier_directBuiltins(_ n: Int) async {}
91+
private func run_TaskID_directBuiltins(_ n: Int) async {}
9292
#endif

benchmark/utils/main.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ import SubstringTest
216216
import Suffix
217217
import SuperChars
218218
import TaskGroups
219-
import TaskIdentifier
219+
import TaskID
220220
import TaskLocalGet
221221
import ToddCoxeter
222222
import TwoSum
@@ -434,7 +434,7 @@ register(SubstringTest.benchmarks)
434434
register(Suffix.benchmarks)
435435
register(SuperChars.benchmarks)
436436
register(TaskGroups.benchmarks)
437-
register(TaskIdentifier.benchmarks)
437+
register(TaskID.benchmarks)
438438
register(TaskLocalGet.benchmarks)
439439
register(ToddCoxeter.benchmarks)
440440
register(TwoSum.benchmarks)

stdlib/public/Concurrency/Task.swift

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -291,23 +291,23 @@ extension Task: Equatable {
291291
}
292292

293293
// ==== -----------------------------------------------------------------------
294-
// MARK: Task Identifier
294+
// MARK: Task ID
295295

296296
/// An opaque, process-unique identifier for a Swift ``Task``.
297297
///
298-
/// A `TaskIdentifier` is assigned at task creation, never changes for the
299-
/// lifetime of the task, and is never reused once a task has completed.
300-
/// Identifiers are scoped to the current process and are not suitable for
301-
/// cross-process correlation.
298+
/// A `TaskID` is assigned at task creation, never changes for the lifetime
299+
/// of the task, and is never reused once a task has completed. IDs are
300+
/// scoped to the current process and are not suitable for cross-process
301+
/// correlation.
302302
///
303-
/// Reading the identifier of the currently-executing task is fast.
303+
/// Reading the ID of the currently-executing task is fast.
304304
///
305-
/// - See: ``Task/currentIdentifier``
306-
/// - See: ``Task/identifier``
307-
/// - See: ``UnsafeCurrentTask/identifier``
305+
/// - See: ``Task/currentID``
306+
/// - See: ``Task/id``
307+
/// - See: ``UnsafeCurrentTask/id``
308308
@available(StdlibDeploymentTarget 6.5, *)
309309
@frozen
310-
public struct TaskIdentifier: Sendable, Hashable {
310+
public struct TaskID: Sendable, Hashable {
311311
@usableFromInline
312312
internal var _rawValue: UInt64
313313

@@ -316,21 +316,21 @@ public struct TaskIdentifier: Sendable, Hashable {
316316
self._rawValue = _rawValue
317317
}
318318

319-
/// The raw 64-bit value of this identifier.
319+
/// The raw 64-bit value of this ID.
320320
///
321321
/// This is the only escape hatch from the opaque type and is intended for
322322
/// serialization, logging, or interop with tools that expect a numeric
323323
/// task ID. The numeric value carries no semantic meaning beyond the
324-
/// guarantees on `TaskIdentifier` itself.
324+
/// guarantees on `TaskID` itself.
325325
@_alwaysEmitIntoClient
326326
public var rawValue: UInt64 { _rawValue }
327327
}
328328

329329
@available(StdlibDeploymentTarget 6.5, *)
330330
extension Task {
331-
/// A type alias for ``TaskIdentifier``, providing the spelling
332-
/// `Task.Identifier` at the use site.
333-
public typealias Identifier = TaskIdentifier
331+
/// A type alias for ``TaskID``, providing the spelling
332+
/// `Task.ID` at the use site.
333+
public typealias ID = TaskID
334334
}
335335

336336
// ==== Task Priority ----------------------------------------------------------
@@ -482,27 +482,27 @@ extension Task where Success == Never, Failure == Never {
482482
}
483483
}
484484

485-
/// The stable identifier of the currently-executing task.
485+
/// The stable ID of the currently-executing task.
486486
///
487487
/// If you access this static property outside the execution context of a
488488
/// task, it will return `nil`.
489489
///
490-
/// This identifier is quick to obtain and can be used to reliably identify
491-
/// a task, instead of its memory address which may be reused once the task
490+
/// This ID is quick to obtain and can be used to reliably identify a
491+
/// task, instead of its memory address which may be reused once the task
492492
/// has been destroyed. No guarantees are made about its exact numeric
493493
/// value.
494494
///
495-
/// - SeeAlso: ``Task/identifier``
496-
/// - SeeAlso: ``UnsafeCurrentTask/identifier``
495+
/// - SeeAlso: ``Task/id``
496+
/// - SeeAlso: ``UnsafeCurrentTask/id``
497497
@available(StdlibDeploymentTarget 6.5, *)
498498
@_alwaysEmitIntoClient
499-
public static var currentIdentifier: Task.Identifier? {
499+
public static var currentID: Task.ID? {
500500
// Direct runtime call: reads the id on the current AsyncTask without
501501
// ever surfacing the task reference to Swift, so there's no ARC dance.
502502
// The runtime returns 0 when there is no current task; task IDs are
503503
// guaranteed to be non-zero.
504504
let id = _getCurrentTaskId()
505-
return id == 0 ? nil : TaskIdentifier(_rawValue: id)
505+
return id == 0 ? nil : TaskID(_rawValue: id)
506506
}
507507

508508
}
@@ -710,22 +710,22 @@ extension Task {
710710
}
711711
}
712712

713-
/// A stable identifier for this task.
713+
/// A stable ID for this task.
714714
///
715-
/// This identifier is quick to obtain and can be used to reliably identify
716-
/// a task, instead of its memory address which may be reused once the task
715+
/// This ID is quick to obtain and can be used to reliably identify a
716+
/// task, instead of its memory address which may be reused once the task
717717
/// has been destroyed. No guarantees are made about its exact numeric
718718
/// value.
719719
///
720-
/// The same identifier is visible in tools such as `swift-inspect` and
720+
/// The same ID is visible in tools such as `swift-inspect` and
721721
/// Instruments, which makes it a convenient correlation key for tracing
722722
/// and logging.
723723
///
724-
/// - SeeAlso: ``Task/currentIdentifier``
725-
/// - SeeAlso: ``UnsafeCurrentTask/identifier``
724+
/// - SeeAlso: ``Task/currentID``
725+
/// - SeeAlso: ``UnsafeCurrentTask/id``
726726
@available(StdlibDeploymentTarget 6.5, *)
727727
@_alwaysEmitIntoClient
728-
public var identifier: Identifier {
728+
public var id: ID {
729729
unsafe .init(
730730
_rawValue: _getJobTaskId(unsafeBitCast(_task, to: UnownedJob.self)))
731731
}
@@ -987,21 +987,21 @@ public struct UnsafeCurrentTask {
987987
}
988988
}
989989

990-
/// A stable identifier for the current task.
990+
/// A stable ID for the current task.
991991
///
992-
/// This identifier is quick to obtain and can be used to reliably identify
993-
/// a task, instead of its memory address which may be reused once the task
992+
/// This ID is quick to obtain and can be used to reliably identify a
993+
/// task, instead of its memory address which may be reused once the task
994994
/// has been destroyed. No guarantees are made about its exact numeric
995995
/// value.
996996
///
997-
/// Returns the same value as ``Task/identifier`` read on the owning task.
997+
/// Returns the same value as ``Task/id`` read on the owning task.
998998
///
999-
/// - SeeAlso: ``Task/identifier``
1000-
/// - SeeAlso: ``Task/currentIdentifier``
999+
/// - SeeAlso: ``Task/id``
1000+
/// - SeeAlso: ``Task/currentID``
10011001
@available(StdlibDeploymentTarget 6.5, *)
10021002
@_alwaysEmitIntoClient
1003-
public var identifier: Task.Identifier {
1004-
unsafe TaskIdentifier(
1003+
public var id: Task.ID {
1004+
unsafe TaskID(
10051005
_rawValue: _getJobTaskId(unsafeBitCast(_task, to: UnownedJob.self)))
10061006
}
10071007
}

test/Concurrency/Runtime/async_task_identifier.swift renamed to test/Concurrency/Runtime/async_task_id.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,33 @@
99
@available(SwiftStdlib 6.5, *)
1010
@main struct Main {
1111
static func main() async {
12-
// Task.currentIdentifier is non-nil inside a task
13-
let current = Task.currentIdentifier
12+
// Task.currentID is non-nil inside a task
13+
let current = Task.currentID
1414
print("current id is some: \(current != nil)")
1515
// CHECK: current id is some: true
1616

17-
// identifier is stable: reading twice yields the same value
18-
let first = Task.currentIdentifier
19-
let second = Task.currentIdentifier
17+
// id is stable: reading twice yields the same value
18+
let first = Task.currentID
19+
let second = Task.currentID
2020
print("stable: \(first == second)")
2121
// CHECK: stable: true
2222

23-
// UnsafeCurrentTask.identifier agrees with Task.currentIdentifier
23+
// UnsafeCurrentTask.id agrees with Task.currentID
2424
let matchesUnsafe: Bool = withUnsafeCurrentTask { task in
2525
guard let task else { return false }
26-
return task.identifier == Task.currentIdentifier
26+
return task.id == Task.currentID
2727
}
2828
print("unsafe matches: \(matchesUnsafe)")
2929
// CHECK: unsafe matches: true
3030

31-
// Task.Identifier exposes the raw 64-bit value
32-
let raw = Task.currentIdentifier?.rawValue ?? 0
31+
// Task.ID exposes the raw 64-bit value
32+
let raw = Task.currentID?.rawValue ?? 0
3333
print("raw is non-zero: \(raw != 0)")
3434
// CHECK: raw is non-zero: true
3535

36-
// Different child tasks have different identifiers
37-
let t1 = Task { Task.currentIdentifier }
38-
let t2 = Task { Task.currentIdentifier }
36+
// Different child tasks have different IDs
37+
let t1 = Task { Task.currentID }
38+
let t2 = Task { Task.currentID }
3939
let id1 = await t1.value
4040
let id2 = await t2.value
4141
print("both non-nil: \(id1 != nil && id2 != nil)")

test/abi/macOS/arm64/concurrency.swift

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -443,24 +443,24 @@ Added: _$sScT2ids6UInt64VvpMV
443443
Added: _$sSct2ids6UInt64VvpMV
444444
Added: _$sScTss5NeverORszABRs_rlE9currentIDs6UInt64VSgvpZMV
445445

446-
// Task.identifier / UnsafeCurrentTask.identifier / Task.currentIdentifier
446+
// Task.id / UnsafeCurrentTask.id / Task.currentID
447447
Added: _swift_task_getCurrentTaskId
448-
Added: _$sScT10identifiers14TaskIdentifierVvpMV
449-
Added: _$sSct10identifiers14TaskIdentifierVvpMV
450-
Added: _$sScTss5NeverORszABRs_rlE17currentIdentifiers04TaskC0VSgvpZMV
451-
452-
// TaskIdentifier struct (Sendable, Hashable)
453-
Added: _$ss14TaskIdentifierVMa
454-
Added: _$ss14TaskIdentifierVMn
455-
Added: _$ss14TaskIdentifierVN
456-
Added: _$ss14TaskIdentifierVSHsMc
457-
Added: _$ss14TaskIdentifierVSQsMc
458-
Added: _$ss14TaskIdentifierV2eeoiySbAB_ABtFZ
459-
Added: _$ss14TaskIdentifierV4hash4intoys6HasherVz_tF
460-
Added: _$ss14TaskIdentifierV8rawValues6UInt64VvpMV
461-
Added: _$ss14TaskIdentifierV9hashValueSivg
462-
Added: _$ss14TaskIdentifierV9hashValueSivpMV
463-
Added: _$ss14TaskIdentifierV9_rawValues6UInt64Vvg
464-
Added: _$ss14TaskIdentifierV9_rawValues6UInt64VvM
465-
Added: _$ss14TaskIdentifierV9_rawValues6UInt64VvpMV
466-
Added: _$ss14TaskIdentifierV9_rawValues6UInt64Vvs
448+
Added: _$sScT2ids6TaskIDVvpMV
449+
Added: _$sSct2ids6TaskIDVvpMV
450+
Added: _$sScTss5NeverORszABRs_rlE9currentIDs6TaskIDVSgvpZMV
451+
452+
// TaskID struct (Sendable, Hashable)
453+
Added: _$ss6TaskIDVMa
454+
Added: _$ss6TaskIDVMn
455+
Added: _$ss6TaskIDVN
456+
Added: _$ss6TaskIDVSHsMc
457+
Added: _$ss6TaskIDVSQsMc
458+
Added: _$ss6TaskIDV2eeoiySbAB_ABtFZ
459+
Added: _$ss6TaskIDV4hash4intoys6HasherVz_tF
460+
Added: _$ss6TaskIDV8rawValues6UInt64VvpMV
461+
Added: _$ss6TaskIDV9hashValueSivg
462+
Added: _$ss6TaskIDV9hashValueSivpMV
463+
Added: _$ss6TaskIDV9_rawValues6UInt64Vvg
464+
Added: _$ss6TaskIDV9_rawValues6UInt64VvM
465+
Added: _$ss6TaskIDV9_rawValues6UInt64VvpMV
466+
Added: _$ss6TaskIDV9_rawValues6UInt64Vvs

0 commit comments

Comments
 (0)