swift
60e11059 - [WIP][Concurrency] Prototype TaskLocalContext for external propagation

Commit
25 days ago
[WIP][Concurrency] Prototype TaskLocalContext for external propagation Adds a public stdlib type `TaskLocalContext` that captures a type-erased snapshot of the currently visible task-local bindings (most-specific per key, respecting shadowing) and re-applies them onto an arbitrary execution context via `context.withValues { ... }`. This gives external libraries the same propagation that `Task.init { ... }` performs today, but without spawning a structured task. Runtime: * New `TaskLocal::Snapshot` class (heap-allocated single-buffer layout: header + Entry[count] + padded value payloads). * Five exported entrypoints: swift_task_localsCopyToSnapshot swift_task_localsSnapshotCount swift_task_localsSnapshotPush swift_task_localsSnapshotPop swift_task_localsSnapshotDestroy * Push routes through the standard swift_task_localValuePush path, so ValueInTaskGroupBody tagging and fallback-TLS selection happen for free. * Capture respects StopLookupMarker; keys are swift_retain'd; values are copied via vw_initializeWithCopy at capture and destroyed via vw_destroy at snapshot destroy. Swift API: * public struct TaskLocalContext: @unchecked Sendable * TaskLocalContext.current captures ambient bindings. * withValues { ... } sync + async overloads, symmetric with TaskLocal.withValue. Test: * test/Concurrency/Runtime/task_local_context.swift covers basic, shadowing, multi-key, async-across-await, escape, concurrent applies, empty capture, nested apply, cross task <-> plain-thread fallback, task-group body interaction, and class-value lifetime. Known status: WIP prototype. Compatibility-override table entries deliberately skipped; add before back-deploying. Availability tag is @available(SwiftStdlib 6.4, *) as a placeholder.
Author
Parents
Loading