Replace once_cell with std::sync::LazyLock and OnceLock#881
Open
Richardmsbr wants to merge 1 commit into
Open
Conversation
Closes cloudflare#721 The once_cell crate's Lazy and OnceCell primitives are now available in the standard library as LazyLock (stable since 1.80) and OnceLock (stable since 1.70). This removes an external dependency and aligns with the standard library going forward. Notes: - Bumped workspace MSRV to 1.80 (required by LazyLock). - OnceCell::try_insert has no stable std equivalent yet (rust-lang/rust#116693). Replaced with set() + get().unwrap() pattern in pingora-runtime::NoStealRuntime::get_pools(), preserving the race-safe semantics. - Documentation example in docs/user_guide/rate_limiter.md and doc-comment in pingora-prometheus were updated to match.
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
Removes the external
once_celldependency in favor of the now-stablestandard library equivalents:
once_cell::sync::Lazy→std::sync::LazyLock(stable since Rust 1.80)once_cell::sync::OnceCell→std::sync::OnceLock(stable since Rust 1.70)Closes #721.
Changes
once_cell = "1"from the workspace and from every membercrate that depended on it (
pingora,pingora-cache,pingora-core,pingora-memory-cache,pingora-proxy,pingora-runtime,pingora-timeout).docs/user_guide/rate_limiter.mdand the doc-comment inpingora-prometheusto match the new API.rust-versionto1.80(required byLazyLock).The one non-trivial change:
try_insertOnceLockinstddoes not yet expose atry_insertequivalent(see rust-lang/rust#116693).
The single occurrence in
pingora-runtime::NoStealRuntime::get_pools()was replaced with the
set()+get().unwrap()pattern suggested inthe issue, preserving the existing race-safe initialization semantics:
The semantics are equivalent: when
setsucceeds, we know the valuewe just inserted is the one stored, so
get().unwrap()is sound. Whensetfails, another thread won the race andget()will return itsvalue.
Validation
Locally (Linux, Rust 1.95.0):
cargo check --workspace— cleancargo fmt --all -- --check— cleancargo test --workspace --lib— 706 passed, 0 failed, 2 ignored(matches main exactly: I ran the same suite on
mainafterstashing this diff and got identical counts per crate)
cargo clippy --workspace --all-targets— same output asmain(the two pre-existing
iter::for_each+unreachable!warnings inpingora-http/src/lib.rsare present onmaintoo)Integration tests that depend on the openresty mock origin were
not exercised in this environment.
Notes
If preserving a lower MSRV is important, an alternative is to keep
once_cellas an optionalstdshim, but the simpler approach isto bump the MSRV as the issue requested.