Skip to content

refactor: pre-0.8.1 internal simplifications and Miri coverage - #461

Merged
tisonkun merged 7 commits into
mainfrom
refactor/pre-0.8.1-dislopify
Nov 23, 2026
Merged

tisonkun merged 7 commits into
mainfrom
refactor/pre-0.8.1-dislopify

Conversation

@tisonkun

@tisonkun tisonkun commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Summary

Clean up pre-0.8.1 internal redundancies, test/Miri blind spots, and release metadata on top of DESIGN.md without changing public APIs:

  1. spmc sender waiting (37b5130): Replace State::send_waiters: WaitList<RetryWaiter> with Option<Waker> and route Shared::send through reserve().await and send_reserved, matching mpsc and mpmc since BoundedSender is !Clone and holds &mut self across waiting and any returned Permit.
  2. Shared coalescing table (c62a87f): Extract internal::coalesce (Entry, EntryTable, and EntryGuard) for OnceMap and singleflight::Group, removing duplicated reference-count cleanup logic while preserving OnceMap's cached lookup fast path and skipping table-lock acquisition in EntryGuard::drop once entry.cell.initialized() is set.
  3. latch countdown state (317883b): Inline single-consumer internal::countdown directly into latch now that WaitGroup uses its own state machine.
  4. OnceState and Semaphore cleanup (702ffab): Replace the unreachable HAS_WAITERS wake branch in OnceState::complete_mut with a debug_assert_eq! and hoist waiters.is_empty() to the top of Semaphore::distribute_permits to skip WakerBatch setup on empty queues and deduplicate cancel_acquire.
  5. Miri suite and xtask runner (7c2c9e7): Convert the three synchronous pool_test cases to plain #[test], narrow tests-integration's Tokio feature set to avoid mio/kqueue FFI crashes under macOS Miri, batch Miri integration targets into one Cargo invocation (adding barrier_test, completion_test, event_test, pool_test, and traits_test), and pass --all-features directly in cargo x test.
  6. Deterministic shutdown_test and wake assertions (deae323): Drive shutdown_test with TestTask (and include it in cargo x miri), remove tests_integration::test_runtime() and move tokio to [dev-dependencies], poll the woken broadcast receiver for RecvError::Disconnected, and split wake vs drop callbacks in event_test::manual_reset.
  7. Doc version and ATR header exclusions (66e5a2c): Update the getting-started Cargo snippet in asyncband/src/lib.rs from 0.7 to 0.8 (noting it in the release skill checklist) and drop the three pool files from .asf.yaml's source_excludes_lightweight list to match licenserc.toml.

Validation

  • cargo x lint
  • cargo x check
  • cargo x test
  • cargo x miri (67 library unit tests + 17 integration test suites)
  • cargo x semver --release-version 0.8.1 (196/196 passed)
  • Paired microbenchmarks (--repeat 7..9 on Apple M4 Max):
    • spmc/bounded/tasks-1p4c-cap64-4w: 304 ms baseline vs 303 ms PR
    • primitives::once_map::lookup::compute_hit_same_key/threads=1: 130 ms baseline vs 114 ms PR

`spmc::BoundedSender<T>` is not `Clone` and both `send` and `reserve`
hold `&mut self` across waiting and any returned `Permit`, so at most one
sender waiter can ever exist for a queue. Keeping a `WaitList<RetryWaiter>`
allocated an arena on first backpressure and duplicated waiting and
cancellation glue across separate `Send` and `Reserve` futures.

Store the blocked sender waker in `Option<Waker>` and route `Shared::send`
through `reserve().await` and `send_reserved`, matching `mpsc` and `mpmc`.

Signed-off-by: tison <wander4096@gmail.com>
`OnceMap` and `singleflight::Group` maintained near-identical copies of
their `HashTable<Arc<Entry<K, V>>>` lookup, duplicate-key drop ordering,
and abandoned-entry reference-count cleanup logic. Both also dismissed
their cleanup guard only after cloning `V`, causing an unnecessary table
lock acquisition if `V::clone` panicked after publication.

Extract `internal::coalesce` (`Entry`, `EntryTable`, and `EntryGuard`)
and check `!entry.cell.initialized()` before acquiring the table lock in
`EntryGuard::drop`.

Signed-off-by: tison <wander4096@gmail.com>
Since `WaitGroup` moved onto its own state machine, `internal::countdown`
was gated behind `feature = "latch"` with `Latch` as its only caller and
a 1:1 forwarding wrapper. Inline `CountdownState` and its wait future
directly into `latch`.

Signed-off-by: tison <wander4096@gmail.com>
…batch

Every caller of `OnceState::complete_mut` holds `&mut self` across a
preceding `reset_mut`, so `HAS_WAITERS` can never be set when completing
exclusively. In `internal::semaphore`, checking `waiters.is_empty()` at
the start of `distribute_permits` avoids constructing a `WakerBatch` on
uncontended slow-path releases and collapses the duplicate branch in
`cancel_acquire`.

Signed-off-by: tison <wander4096@gmail.com>
`cargo x miri` launched a separate Cargo invocation per integration test
binary and omitted `barrier_test`, `completion_test`, `event_test`,
`pool_test` (including its `cfg!(miri)` replenish test), and `traits_test`.
`tests-integration` also enabled `tokio/full`, pulling `mio`/`kqueue` into
`#[tokio::test]` binaries and breaking Miri on macOS.

Convert the three synchronous `pool_test` cases to plain `#[test]`, narrow
`tests-integration`'s Tokio features to the runtime, sync, time, and macro
subsets it uses, batch all Miri integration targets into one invocation,
pass `--all-features` directly in `cargo x test`, and align the `semver`
subcommand name in `dislopify`.

Signed-off-by: tison <wander4096@gmail.com>
`shutdown_test` spawned detached futures onto a global multi-threaded
`test_runtime()` without ensuring they parked before `request_shutdown`,
leaving `tokio` in regular `[dependencies]` and keeping `shutdown_test`
out of Miri. Meanwhile, `broadcast_test::unbounded` dropped a woken
`recv` future without polling it for `RecvError::Disconnected`, and
`event_test::manual_reset::ReentrantWaker` called `reset()` in both
`wake` and `drop` so a missed wake callback still passed via `Drop`.

Drive `shutdown_test` deterministically with `TestTask` (and include it
in `cargo x miri`), convert the remaining `mpsc` caller to `#[tokio::test]`
so `test_runtime()` can be removed and `tokio` moved to `[dev-dependencies]`,
poll the woken broadcast receiver for disconnection, and split wake and
drop callbacks in `manual_reset`.

Signed-off-by: tison <wander4096@gmail.com>
Update the getting-started Cargo snippet in `asyncband/src/lib.rs` from
`0.7` to `0.8` (noting it in the release skill checklist) and drop the
three `pool` files from `.asf.yaml`'s `source_excludes_lightweight` list
to match `licenserc.toml` now that they carry standard ASF headers.

Signed-off-by: tison <wander4096@gmail.com>
@tisonkun
tisonkun force-pushed the refactor/pre-0.8.1-dislopify branch from 5570659 to 66e5a2c Compare November 23, 2026 02:31
@tisonkun
tisonkun merged commit c0dc25f into main Nov 23, 2026
11 checks passed
@tisonkun
tisonkun deleted the refactor/pre-0.8.1-dislopify branch November 23, 2026 02:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant