Skip to content

Enforce Task sendability conditions (§14.7, §14.22) #480

Closed

Description

@ehartford

Summary

Enforce the full §14.7 / §14.22 sendability rule for Task[T]: a task is Send only if it is non-ephemeral, T: Send, and every captured environment value is Send. The compiler tracks ephemeral tasks today, but the captured-environment Send condition is not enforced, so tasks can be moved through channels or thread boundaries even when their closure state should forbid it.

Spec

§14.7 says task sendability is inferred from captures and return type. §14.22 says Task[T] is Send only if all captured values are Send and the task is not ephemeral.

let local = Rc.new(1)
let t = async: local.get()
send_to_worker(move t)   // error: task captures non-Send value

Current state

Sema records task and scoped-task identities (src/Sema.w:1425) and tracks ephemeral task bindings (src/SemaCheck.w:4513, src/SemaCheck.w:4521). It rejects some ephemeral task escapes (src/SemaCheck.w:2545, src/SemaCheck.w:2553), but there is no captured-environment Send summary attached to a Task[T].

Closure capture summaries already exist for effects (src/Sema.w:2774, src/SemaCheck.w:7728). Async blocks and async functions need an analogous capture-send summary. Channel and thread boundaries currently have only placeholder Send checks until #473 lands.

Implementation plan

  1. Add task metadata recording captured symbols/types and whether each capture is Send. Reuse closure capture collection where async blocks share closure rules.
  2. Extend task type/value metadata so Task[T] values carry both ephemerality and capture-send status through bindings, returns, struct storage, channels, and function arguments.
  3. Implement type_is_send(Task[T]) in Send/Sync enforcement substance (§14.16) #473 terms: non-ephemeral, T: Send, and captured environment Send.
  4. Wire task sendability checks into channel send (Bug: channel send does not consume; non-integer element types mistyped (§14.15) #419), OS-thread spawn, std.thread APIs, and any future work-stealing cross-thread queues (Work-stealing multi-OS-thread fiber scheduler (§14.18, §14.7) #455).
  5. Produce diagnostics that name the captured non-Send binding: Task captures non-Send value 'x'.
  6. Ensure same-thread storage of non-Send non-ephemeral tasks remains allowed if §14.7 permits it; Send should be required only at thread/channel crossing boundaries.

Test plan

Add tests after #470 provides Rc:

  • err_task_capture_non_send_channel.w;
  • err_task_capture_non_send_spawn_os.w;
  • positive same-thread storage of non-Send task if allowed;
  • positive task capturing Arc[T] where T: Send + Sync;
  • negative Task[NonSend] return type even with Send captures.

Extend test/spec/spec_ss14_7_ephemeral_task_cancellation.w or add a new §14.22 spec file for non-ephemeral but non-Send tasks.

Acceptance criteria

  • Task values carry captured-environment Send metadata.
  • Cross-thread/task-channel movement rejects non-Send captures or non-Send T.
  • Ephemeral task restrictions remain independent and still enforced.
  • Diagnostics point to the capture or return type that made the task non-Send.
  • with build && with build :fixpoint && with build :test pass.

Dependencies

Depends on #473 and likely #470 for concrete non-Send witnesses. Interacts with #419 and #455.

Traceability

From the requirements campaign (docs/requirements.md, spec v7.1). Affected requirement IDs: 14.7.1.7.

Activity

  1. ehartford commented on Jun 16, 2026

    @ehartford
    ContributorAuthor

    Implemented in c309735. Task sendability now preserves the existing non-Send task provenance checks while reporting the captured non-Send binding at channel-send boundaries. Added coverage for named non-Send captures, non-Send Task result types rejected as channel elements, and same-thread storage of non-Send non-ephemeral tasks. Verification passed with project seed/release commands: build, fixpoint, full test suite, and explicit test-green.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions