Skip to content

refactor: deslopify the crate inside and out - #345

Merged
tisonkun merged 24 commits into
mainfrom
tison/deslopify
Oct 3, 2026
Merged

tisonkun merged 24 commits into
mainfrom
tison/deslopify

Conversation

@tisonkun

@tisonkun tisonkun commented Oct 3, 2026

Copy link
Copy Markdown
Member

Summary

A deslopify sweep of the crate: one commit per finding, each commit message explains why the removed or rewritten piece was slop. Net -84 lines, no behavior change.

  • internal: delete the dead Arena::values and the unused Default for Arena, gate Arena::len to tests, and align test_support visibility with the module-boundary convention.
  • mutex/rwlock: drop comments that restate declarations ("ownership certificate", DerefMut narration), state the real invariant at every Arc extraction site, make the write-guard fields private, and explain the default reader cap accurately.
  • broadcast: collapse the no-op-arm match in the sender Drop impls into a conditional, fix the reclaim_vacated growth-point reference, and drop field docs duplicating Inner's own doc.
  • spmc: remove the Send::drop waiter handoff that is unreachable in a single-producer queue, and say "an internal mutex" (there is exactly one).
  • once-cell: correct the stale "initialized at most once" contract (take() re-initializes), say "task" not "thread", and remove the vestigial let _permit = permit; rebind.
  • latch: implement wait_owned by awaiting wait(), deleting the field-for-field duplicated OwnedLatchWait (the pattern both event primitives already use).
  • pool: remove the dead default type parameter on private UnreadyObject and narrow ObjectStatus mutation methods to pub(super).
  • tooling/manifests: describe cargo x test as running workspace tests, remove the unused cargo-release metadata, make the packaged MIGRATE.md changelog links absolute, and drop redundant default-features = false on workspace-inherited deps.

Considered and left alone:

  • AutoResetEvent::poll_wait hand-rolls register_waker: adopting the shared helper requires reshaping the Waiter enum (the helper wants an Option<Waker> slot); state-machine churn for three lines, fine as a follow-up if wanted.
  • oneshot::Receiver's explicit impl Unpin: redundant with the auto impl today, but it matches the mpsc::UnboundedReceiver convention guarding the auto-trait contract.
  • benchmarks TaskBatch duplication between mpmc and spmc: deduplicating means restructuring the fixture generics (the Clone sender bound), a design change rather than slop removal.

Validation: cargo x lint, cargo x test, cargo x check (feature matrix), and cargo x miri all pass.

No caller exists in any feature combination: the method was added for a
broadcast consumer that has since been removed, and the module-level
#[allow(dead_code)] on the arena module hid that. Iteration over occupied
values is covered by take_all and into_iter.
Nothing constructs an Arena through Default: every mem::take site in the
crate takes a WakerSet, which has its own Default impl built on
WakerSet::new. WaitList already sets the precedent of a const fn new
without a Default impl, so new_without_default stays quiet.
Its only callers are WaitList::occupied_len, which is itself #[cfg(test)],
and the arena unit tests. Production code observes occupancy through
is_empty, which stays available in all builds.
The module itself is a private mod declaration, so crate visibility is
already restricted at the module boundary. Repository style keeps
restricted visibility on the boundary and plain pub on the module's
items, the same pattern the internal module follows.
These comments narrate the very line they precede instead of explaining
a rationale: field docs that paraphrase the field's type ("Container
storing the protected data" on UnsafeCell<T>, "Non-null pointer to the
mapped data" on NonNull<T>), the "ownership certificate" voice-over on
Arc lock fields, "Release the lock by calling release on the semaphore"
above s.release(1), and the "Use DerefMut ..." meta commentary. The
broadcast Shared::inner field doc additionally duplicated the Inner
type's own documentation. Comments carrying real invariants (variance,
non-zero max_readers) are kept.
"We safely extract the Arc from the ManuallyDrop guard" just asserts
safety in the imperative mood without giving a reason, and
OwnedMutexGuard::map had no comment at all while its siblings did. Every
extraction site now states the actual invariant, matching the wording
the rwlock write guards already used: the source guard is ManuallyDrop
and will not be dropped, so moving the Arc out transfers lock ownership
instead of releasing it.
Every access to RwLockWriteGuard and OwnedRwLockWriteGuard fields happens
inside the file that defines the guard, so the pub(super) widens
visibility without a consumer. The read guard fields keep theirs:
downgrade constructs read guards from the write guard modules.
"large enough while not touch the edge" was ungrammatical and named no
constraint: the cap exists to keep semaphore permit arithmetic away from
usize::MAX while remaining unreachable in practice.
…itional

The Drop impls matched on the fetch_sub result with a no-op fallback arm
whose only content was a comment saying there is nothing to do. An
equality check expresses the last-sender test directly, the same shape
the mpsc sender and waitgroup disconnect paths already use. The bounded
sender keeps its comment explaining why only receivers need waking.
The reclaim_vacated comment claimed the buffer grows only in
Backlog::publish, but the growth is the push_back in publish_retained,
which the bounded channel calls directly, bypassing publish entirely.
The accounting argument only holds if the reference names the actual
growth point.
The queue is single-producer: send borrows the sender exclusively, so at
most one Send future exists and send_waiters can hold only its own node.
Once Drop removes that node, notify_one always finds an empty list and
the "another blocked sender" scenario the field comment describes cannot
occur. The mpmc queue keeps its handoff because multiple producers make
it live; the receiver-side handoff here stays for the same reason. The
removed branch could only fire for a mem::forget-leaked send future,
where waking the stale waker is a pointless poll.
Both constructors claimed operations acquire "internal mutexes", but the
queue state lives behind one Mutex, and the unbounded paragraph even
contradicted itself two sentences later. The mpmc and mpsc modules
already say "an internal mutex".
The struct summary promised std-style "initialized at most once"
semantics, but take() deliberately moves the cell back to an
uninitialized state so it can be initialized again; the module-level
docs already describe the actual contract. The set() docs also said
"thread" where every sibling method says "task".
let _permit = permit extended nothing: a by-value parameter already
lives until the end of the function. It is scaffolding from the
pre-ValueCell implementation, when the body held the permit across
several statements; naming the parameter _permit expresses the
held-but-unused intent directly and the SAFETY comment already documents
the permit invariant.
OwnedLatchWait duplicated LatchWait field-for-field and poll-for-poll,
differing only in holding Arc<Latch> instead of &Latch, and the
intern_poll helper existed only to be shared by the two. Both event
primitives already implement the identical method as self.wait().await:
the Arc lives inside the async block while wait() borrows from it, and
cancel-safety is unchanged because the same LatchWait future drives the
wait. With a single caller left, intern_poll is inlined back into
LatchWait::poll.
Every other future type in the crate uses the message with `.await` in
backticks; this one diverged by the missing markup alone.
…ject

The struct is private and constructed exactly once, inside
Pool<T, M>::get where M is inferred from the pool; neither impl block
relies on the default. It was copied from the public Object<T, M =
NeverManageObject<T>> signature, where the default backs the Pool<T>
convenience API, and the bounded pool's UnreadyObject never had one.
Both call sites live in the pool subtree (bounded.rs, unbounded.rs), so
crate-wide visibility overshoots the consumers. pub would leak the
methods into the public API because ObjectStatus is re-exported, and
pub(super) is the idiom sibling modules already use for exactly this
case, e.g. watch's SendError::new.
The subcommand invokes cargo test --workspace, which runs unit tests,
the tests-integration suites, and doc tests; "Run unit tests"
under-reports the workflow that AGENTS.md designates as the source of
truth. The sibling entries already say "workspace" explicitly.
The table is read only by cargo-release, which this repository does not
use: the release skill publishes with cargo publish through ATR and
Trusted Publishing, and nothing in the repo consumes the key. The
package is already unpublished via publish = false, which is what the
other private workspace members rely on.
The asyncband/ copy of MIGRATE.md ships inside the published crate and
is also what the GitHub directory view renders, but its relative
CHANGELOG.md and CHANGELOG-OLD.md links resolve against asyncband/,
where no changelogs exist, and 404 there as well as in the packaged
crate. Absolute links work in every context; the two copies stay
byte-identical.
The workspace declarations for hashbrown and ureq already set
default-features = false, so repeating it in the member manifests is a
no-op; cargo tree confirms the resolved feature sets are unchanged.
@tisonkun
tisonkun enabled auto-merge (squash) October 3, 2026 08:13
@tisonkun
tisonkun merged commit f998f35 into main Oct 3, 2026
9 checks passed
@tisonkun
tisonkun deleted the tison/deslopify branch October 3, 2026 08:16
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