Skip to main content

Module task

Module task 

Source
Expand description

pub, not private like [gc]: task’s ABI constants (PollFn, POLL_READY, STATE_SLOT_TAG, STATE_SLOT_TEMPS) are not all read by this crate’s own runtime logic – some exist purely as the documented contract codegen (Task 5’s async_lower.rs) must reproduce. A private module would make those pub items unreachable from outside the crate, which both defeats their purpose and makes rustc’s dead_code lint treat them as genuinely dead, since nothing inside this crate alone uses them. A single-threaded cooperative executor.

Single-threaded is a correctness requirement, not a simplification. The collector keeps its entire heap in a thread_local! (gc’s HEAP), so an object allocated on one thread lives in that thread’s heap map and only that thread’s collector can see or free it – gc::add_root and gc::remove_root are thread_local! for the identical reason (see their doc comments in gc.rs). A second thread running Nova code would free objects the first still holds. This executor’s own state (QUEUE, TASKS, IN_BLOCK_ON below) is therefore thread_local! too, by construction rather than by convention: there is no API here for a task to migrate between threads. See ADR 0009.

No wakers: a task that returns POLL_PENDING is re-queued for another turn unless it staged a park (see [Wait]), in which case it waits in the park set instead until a deadline or another task’s completion – the executor’s only two wake sources – moves it back. Both are scheduled by the executor itself, not registered as an arbitrary callback the awaited resource invokes, which is what “no wakers” still means once parking exists. That makes interleaving between ready tasks deterministic by construction, which is what lets nova_rt_task_block_on’s round-robin order be pinned by a test rather than merely observed.

Constants§

FUTURE_SIZE
The whole future value’s size in bytes, for the allocation that holds it.
FUTURE_SLOT_POLL
The future value’s own layout – the { poll_code, state } two-word fat pointer every nova_rt_task_spawn / nova_rt_task_block_on argument points at, the same shape MakeClosure builds for a closure. Named for the same reason STATE_SLOT_TAG and friends are: async_lower.rs (Task 5) builds this layout independently and the two ends are kept in step by nothing but these declared offsets.
FUTURE_SLOT_STATE
POLL_PENDING
A PollFn returns this when it has not yet produced a value; the executor re-queues the task for another turn.
POLL_READY
A PollFn returns this once it has written the final value to the state object’s output slot (STATE_SLOT_OUTPUT).
STATE_MIN_SIZE
The smallest state object any future may have: the tag and output slots are read and written unconditionally, for every future, including one whose async fn returns unit and has no temps at all. A state object with n MIR temps is (STATE_SLOT_TEMPS + n) * 8 bytes, which is never smaller than this.
STATE_SLOT_OUTPUT
STATE_SLOT_TAG
The state object’s layout, word-indexed: slot n is at byte offset 8 * n. async_lower.rs (Task 5) must build exactly this layout – this executor and every generated poll function address it by raw offset, with no shared Rust type to keep the two ends in sync if one of them drifts.
STATE_SLOT_TEMPS
TIMEOUT_STATUS_COMPLETED
The inner future completed before the deadline.
TIMEOUT_STATUS_ELAPSED
The deadline passed with the inner future still pending.

Functions§

nova_rt_task_block_on⚠
Drive this thread’s executor to quiescence and return future’s output. See [run_to_completion] for exactly what “quiescence” means here.
nova_rt_task_is_done⚠
Whether the task named by future’s state object has completed.
nova_rt_task_join_future⚠
A fresh Future<unit> that completes when future’s task does.
nova_rt_task_release⚠
End the executor’s claim on the task named by future’s state object. See [release_internal] for why this exists next to nova_rt_task_take_output rather than instead of it, and why calling it twice is a no-op rather than a diagnostic.
nova_rt_task_sleep_future_nanos
A fresh Future<unit> that parks for nanos nanoseconds, then completes.
nova_rt_task_spawn⚠
Queue a { poll_code, state } future as a new task and return its id.
nova_rt_task_take_output⚠
A completed task’s output slot, taken exactly once.
nova_rt_task_timeout_future
A fresh Future<Int> that polls fut until it completes or nanos nanoseconds pass, reporting which happened.
nova_rt_task_yield_future
A fresh Future<unit> that pends once and then completes – what std/task’s yield_now awaits.
output_bits
The raw bits a completed task’s output was copied out as, without taking it and without touching any GC root.

Type Aliases§

PollFn
The signature every compiled async fn’s poll function has – both the hand-written ones this module’s tests drive it with, and the ones async_lower.rs (Task 5) generates. Reads and writes state’s slots (see STATE_SLOT_TAG and friends) and reports POLL_PENDING or POLL_READY.