Repository navigation
refactor: simplify OnceCell insertion and owned waits in Latch and AutoResetEvent - #498
Open
nanami-0713 wants to merge 2 commits into
Open
nanami-0713 wants to merge 2 commits into
nanami-0713 wants to merge 2 commits into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
OnceCell::{try_insert, set}directly over the initialized-state fast path andacquire_init, instead of routing an already-built value throughget_or_initand anasyncclosure that hands it over through a sideOption. Signatures, wake-ups on publication, and cancellation behavior are unchanged.AutoResetEvent::waitandLatch::waitfutures generic overBorrow<T>, sowait_ownedawaits the same future that holds theArcinstead of awaiting a borrowedwait()from a second state machine. This matches whatManualResetEventalready does and also shrinksShutdownGuard::shutdown_requested_ownedandShutdownWatch::shutdown_requested_owned, which build onLatch::wait_owned.#[allow(dead_code)]onOnceCell::initialized, whichsetnow calls.try_insert/setand for cancellingLatch::wait_owned.No public API or observable behavior changes, so
CHANGELOG.mdis untouched andcargo x semverwas not run.Validation
Local validation on macOS (
aarch64-apple-darwin, stablerustc 1.99.1, nightly1.102.0-nightlyfrom 2026-11-08):cargo x checkcargo x test— 786 tests passed, including 177 doc testscargo x lint— clippy, taplo, typos, hawkeye, and the docsrs rustdoc check pass. The rustfmt step stops on two doc-comment diffs inasyncband/src/mpsc/bounded/receiver.rs, which is unchanged here and shows the same diffs onmain(b6b8adf) with this nightly; the files touched by this PR are rustfmt-clean.cargo x miri— 572 tests passed; 14 existing tests are ignored under MiriFuture sizes measured with
std::mem::size_of_valin the test profile immediately before (b6b8adf) and after this change on the same toolchain. Borrowedwaitfutures are unchanged.OnceCell<u64>::try_insertOnceCell<u64>::setOnceCell<String>::try_insertOnceCell<String>::setOnceCell<[u8; 64]>::try_insertOnceCell<[u8; 64]>::setAutoResetEvent::wait_ownedLatch::wait_ownedShutdownGuard::shutdown_requested_ownedShutdownWatch::shutdown_requested_ownedThese are layout numbers for this target and toolchain only. No benchmark was run because the change is a simplification rather than a speed optimization.