Repository navigation
Description
Summary
Fix channel typing and ownership so Sender[T].send moves a T, Receiver[T].recv returns that same T, and queued non-Copy values are dropped correctly when a channel is destroyed. The runtime and codegen are already mostly element-size generic; the remaining blockers are stale sema restrictions, missing consume effects, and missing drop/close ownership semantics.
Spec
§14.15 says channels transfer ownership: sending moves the value. §14.16 requires values crossing concurrency boundaries to satisfy Send. §16.3d provides the explicit consume effect model for intrinsic-backed declarations where there is no body to infer from.
let (tx, rx) = chan[Vec[i32]](1)
let v = Vec[i32].new()
tx.send(move v)
v.len() // error: use after move
let got = rx.recv() // Vec[i32]
Current state
The low-level channel runtime is already element-size generic. The channel layout stores elem_size (rt/channel_runtime.w:18, rt/channel_runtime.w:29), grow/send/recv copy elem_size bytes (rt/channel_runtime.w:65, rt/channel_runtime.w:137, rt/channel_runtime.w:159), and create stores the provided element size (rt/channel_runtime.w:95, rt/channel_runtime.w:109).
LLVM codegen also passes typed sizes/slots: CHAN_SEND allocates a stack slot of the sent value type (src/CodegenDispatch.w:7514, src/CodegenDispatch.w:7522), CHAN_CREATE computes abi_size_of(elem) from Channel[T] (src/CodegenDispatch.w:7540, src/CodegenDispatch.w:7556), and CHAN_RECV allocates/loads the destination type (src/CodegenDispatch.w:7578, src/CodegenDispatch.w:7584).
The main type blocker is sema. Receiver return types are generic-aware in builtin_intrinsic_method_return_type (src/SemaCheck.w:9861), and send expected-arg type uses Sender[T] (src/SemaCheck.w:9967), but the low-level send intrinsic path still rejects non-integer payloads (src/SemaCheck.w:11240, src/SemaCheck.w:11242). Sender.send is not wired into the call-site consume-effect enforcement used for declared effects (src/SemaCheck.w:8177). The runtime destroy path only frees the buffer and channel object (rt/channel_runtime.w:186), so queued non-Copy elements with Drop are leaked logically.
Implementation plan
- Replace the stale
payload_kind != TY_INTguard insrc/SemaCheck.w:11240with a check that the payload type is compatible with the channel element type. Keep the existing Send/ephemeral rejection, but base it on realT: Sendonce Send/Sync enforcement substance (§14.16) #473 is available. - Treat
Sender[T].sendas consuming argument 0. Either attach a compiler-knownEFF_CONSUMEto the intrinsic method or route it through the same effect table used by@[effect]soSemaCheck.w:8177marks the argument moved and requiresmove/copyfor non-Copy values. - Ensure method-call sema and the low-level intrinsic path agree:
Sender[T].send(value)should typecheck only forvalue: T, andReceiver[T].recv()should returnTwithout falling back toi32. - Add drop glue for queued non-Copy elements. Extend
with_channel_createto accept an optional drop-function pointer plus element alignment if needed, store it in the channel layout, and havewith_channel_destroyiterate live elements and call the drop function before freeing the buffer. - Add Sender/Receiver close-on-drop semantics: dropping the final sender or receiver should close the channel or decrement endpoint counts, so blocked peers wake and observe closure. This may require endpoint reference counts in the runtime layout.
- Add channel send/recv to Implement compiler-visible current-fiber suspension model #354's current-fiber suspension set because bounded send and empty recv can yield (
rt/channel_runtime.w:121,rt/channel_runtime.w:148). - Runtime layout changes in
rt/channel_runtime.ware bootstrap-sensitive. Do not combine Link/runtime-object changes with unrelated compiler changes; follow AGENTS.md runtime migration rules if object layout or exported symbols change.
Test plan
Add test/spec/spec_ss14_15_channel_generic_payloads.w with chan[Vec[i32]], chan[str], and a small struct payload round trip.
Add test/compile_errors/err_channel_send_consumes_value.w proving a non-Copy value cannot be used after tx.send(move v) and that tx.send(v) reports the consume-effect diagnostic.
Add test/compile_errors/err_channel_send_wrong_type.w for Sender[i32].send("x").
Add test/compile_errors/err_channel_send_requires_send.w or extend test/spec/spec_ss14_15_channel_send_requires_send.w once #473 provides a concrete non-Send witness.
Add a behavior test with a Drop-counted payload queued in a channel that is destroyed without recv, proving queued drops run exactly once.
Acceptance criteria
chan[T]send/recv preserveTfor non-integer payloads.- Sending a non-Copy value consumes it and later use is rejected.
- Send rejects non-
Sendpayloads once non-Send witnesses exist. - Destroying or closing channels drops queued non-Copy elements exactly once.
- Bounded send/empty recv are represented as
may_suspendprimitives. with build && with build :fixpoint && with build :testpass.
Dependencies
Depends on #473 for substantive Send checks and overlaps #354 for suspension classification. Drop glue for generic non-Copy payloads may depend on #391 if type-specific drop function identity is blocked by generic erasure.
Traceability
From the requirements campaign (docs/requirements.md, spec v7.1). Affected requirement IDs: 14.15.1.1.
Activity
Requirements triage campaign: checkbox, verdict, and issue-link every…
ehartford commentedon Jun 17, 2026
Implemented in 013c4ff. Channel endpoints are now non-Copy ownership values,
Sender[T].sendconsumes the payload, generic channel endpoint layout/codegen handles non-integer payloads, queued payloads run drop callbacks when the channel is released, and sender/receiver endpoint drops release runtime references. Added positive tests forstr, struct,Vec[i32], and queued payload drops; added negative tests for use-after-send and wrong payload type. Verification passed with project seed/release commands:build,build :fixpoint,build :test, andbuild :test-green.