GeezerVison is showing github.com — Replace `once_cell` with `std::sync::OnceLock`/`core::cell::OnceCell` by youknowone · Pull Request #7077 · RustPython/RustPython
Conversation
youknowone
commented
Feb 11, 2026
•
edited by coderabbitai
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
- Replace
once_cell::sync::{Lazy, OnceCell} with std::sync::{LazyLock, OnceLock}
- Replace
once_cell::unsync::{Lazy, OnceCell} with core::cell::{LazyCell, OnceCell}
- Inline
get_or_try_init at call sites (unstable in std as of 1.93)
- Replace
OnceCell::with_value() with OnceCell::from() in codecs.rs
- Remove
once_cell direct dependency from common and vm crates
Summary by CodeRabbit
- Chores
- Removed an external dependency and refactored internal lazy initialization patterns throughout the codebase.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
- Replace `once_cell::sync::{Lazy, OnceCell}` with
`std::sync::{LazyLock, OnceLock}`
- Replace `once_cell::unsync::{Lazy, OnceCell}` with
`core::cell::{LazyCell, OnceCell}`
- Inline `get_or_try_init` at call sites (unstable in std as of 1.93)
- Replace `OnceCell::with_value()` with `OnceCell::from()` in codecs.rs
- Remove `once_cell` direct dependency from common and vm crates
coderabbitai
Bot
commented
Feb 11, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
📝 Walkthrough
Walkthrough
The PR removes the once_cell crate dependency from the project by migrating to standard library equivalents: std::sync::LazyLock/OnceLock for threading contexts and core::cell::LazyCell/OnceCell for non-threaded contexts. Implementation details across multiple VM and common modules are updated to use explicit lazy initialization patterns.
Changes
| Cohort / File(s) |
Summary |
Dependency Removals Cargo.toml, crates/common/Cargo.toml, crates/vm/Cargo.toml |
Removed once_cell dependencies from workspace and crate manifests. |
Lock Module Reexports crates/common/src/lock.rs |
Updated public re-exports to alias stdlib types: LazyLock as Lazy and OnceLock as OnceCell (threaded), or LazyCell as Lazy and OnceCell (non-threaded), replacing once_cell crate references. |
Static Cell Implementation crates/common/src/static_cell.rs |
Replaced get_or_try_init delegation with explicit initialization: check for existing value via get(), compute if absent, store via set(), and return reference. |
VM Lazy Initialization crates/vm/src/builtins/function.rs, crates/vm/src/builtins/memory.rs, crates/vm/src/codecs.rs, crates/vm/src/stdlib/os.rs |
Replaced get_or_try_init closures with explicit check-compute-cache patterns using get() and set() calls. Updated initialization of exception cells to use From-based construction instead of with_value. |
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs
Poem
🐰 The once\_cell is gone, hooray, hooray!
We've swapped the crate for stdlib's way
LazyLock and OnceLock now take the stage
Explicit get and set fill every page
Built-in types, no external cage! ✨
🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
| Check name |
Status |
Explanation |
Resolution |
| Docstring Coverage |
⚠️ Warning |
Docstring coverage is 45.45% which is insufficient. The required threshold is 80.00%. |
Write docstrings for the functions missing them to satisfy the coverage threshold. |
✅ Passed checks (2 passed)
| Check name |
Status |
Explanation |
| Description Check |
✅ Passed |
Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check |
✅ Passed |
The title accurately summarizes the main change: replacing the once_cell crate with standard library equivalents (std::sync::OnceLock and core::cell::OnceCell). |
✏️ Tip: You can configure your own custom pre-merge checks in the settings.
✨ Finishing touches
🧪 Generate unit tests (beta)
- Create PR with unit tests
- Post copyable unit tests in a comment
No actionable comments were generated in the recent review. 🎉
🧹 Recent nitpick comments
crates/common/src/static_cell.rs (1)
30-40: Threading variant: f() may be invoked concurrently by multiple threads.
Unlike OnceLock::get_or_try_init (which blocks competing callers), this manual get/set pattern allows multiple threads to evaluate f() simultaneously, discarding all but the winner's result. This is functionally safe but differs from the previous once_cell behavior which serialized initialization. If f() is expensive or has side effects, callers should be aware.
Given this is an accepted trade-off for avoiding unstable APIs, just flagging for awareness.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share
Comment @coderabbitai help to get the list of available commands and usage tips.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Code has been automatically formatted
The code in this PR has been formatted using:
cargo fmt --all
Please pull the latest changes before pushing again:
git pull origin once-cell
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
youknowone
added a commit
to youknowone/RustPython
that referenced
this pull request
Mar 22, 2026
…RustPython#7077)
* Replace `once_cell` with `std::sync::OnceLock`/`core::cell::OnceCell`
- Replace `once_cell::sync::{Lazy, OnceCell}` with
`std::sync::{LazyLock, OnceLock}`
- Replace `once_cell::unsync::{Lazy, OnceCell}` with
`core::cell::{LazyCell, OnceCell}`
- Inline `get_or_try_init` at call sites (unstable in std as of 1.93)
- Replace `OnceCell::with_value()` with `OnceCell::from()` in codecs.rs
- Remove `once_cell` direct dependency from common and vm crates
* Auto-format: cargo fmt --all
---------
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
youknowone
added a commit
that referenced
this pull request
Sep 16, 2026
…#7077)
* Replace `once_cell` with `std::sync::OnceLock`/`core::cell::OnceCell`
- Replace `once_cell::sync::{Lazy, OnceCell}` with
`std::sync::{LazyLock, OnceLock}`
- Replace `once_cell::unsync::{Lazy, OnceCell}` with
`core::cell::{LazyCell, OnceCell}`
- Inline `get_or_try_init` at call sites (unstable in std as of 1.93)
- Replace `OnceCell::with_value()` with `OnceCell::from()` in codecs.rs
- Remove `once_cell` direct dependency from common and vm crates
* Auto-format: cargo fmt --all
---------
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|