[Concurrency] Introduce Task.id#89237
Conversation
This ID is stable and can be used to quickly identify tasks. It is implemented as a growing counter though we don't promise it'll stay this way. Align with proposal update the symbols
| /// | ||
| /// Available: Swift 6.5 | ||
| SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift) | ||
| uint64_t swift_task_getCurrentTaskId(void); |
There was a problem hiding this comment.
This is more efficient than getting the task builtin into swift and then call swift_task_getJobTaskId on it; because getting it into swift caused an ARC operation on the task handle.
| // ever surfacing the task reference to Swift, so there's no ARC dance. | ||
| // The runtime returns 0 when there is no current task; task IDs are | ||
| // guaranteed to be non-zero. | ||
| let id = _getCurrentTaskId() |
There was a problem hiding this comment.
Backdeployment note: We could backdeploy this more if we do the "get task -> get id from job" and use the more efficient version in 6.5+
There was a problem hiding this comment.
I think that would be a desirable idea.
|
@swift-ci please smoke test |
|
@swift-ci please smoke test |
| /// - SeeAlso: ``UnsafeCurrentTask/id`` | ||
| @available(StdlibDeploymentTarget 6.5, *) | ||
| @frozen | ||
| public struct TaskID: Sendable, Hashable { |
There was a problem hiding this comment.
Sorry for asking, but why do we want to have this as a separate type? Isn't this just a single UInt64? Not that I'm against using newtypes.
There was a problem hiding this comment.
You can see rationale in the draft proposal:
There was a problem hiding this comment.
Thanks for the info! I agree using a newtype is more idiomatic.
| /// scoped to the current process and are not suitable for cross-process | ||
| /// correlation. | ||
| /// | ||
| /// Reading the ID of the currently-executing task is fast. |
There was a problem hiding this comment.
I think we should expand this part. I will come up with a suggestion if you haven't already.
This ID is stable and can be used to quickly identify tasks.
Pitch thread: https://forums.swift.org/t/pitch-cheap-task-identity-for-high-performance-instrumentation/86666/23