GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Replace `once_cell` with `std::sync::OnceLock`/`core::cell::OnceCell` by youknowone · Pull Request #7077 · RustPython/RustPython

Conversation

@youknowone

@youknowone youknowone commented Feb 11, 2026 •
edited by coderabbitai Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member
  • 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.

All reactions
@youknowone
Replace once_cell with std::sync::OnceLock/core::cell::OnceCell
a5ca61b
- 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

coderabbitai Bot commented Feb 11, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor
📝 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

  • fix scandir/lstat for windows #6357: Modifies the same file (crates/vm/src/stdlib/os.rs) with related DirEntry caching and stat/lstat behavior changes.

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 docstrings
🧪 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
  • X
  • Mastodon
  • Reddit
  • LinkedIn

Comment @coderabbitai help to get the list of available commands and usage tips.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions
Auto-format: cargo fmt --all
0779e7e
@github-actions

github-actions Bot commented Feb 11, 2026

Copy link
Copy Markdown
Contributor

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
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@youknowone
youknowone marked this pull request as ready for review February 11, 2026 01:58
@youknowone
youknowone merged commit c06cf56 into RustPython:main Feb 11, 2026
13 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@youknowone
youknowone deleted the once-cell branch February 11, 2026 02:08
youknowone added a commit to youknowone/RustPython that referenced this pull request Mar 22, 2026
@youknowone @github-actions
Replace once_cell with std::sync::OnceLock/core::cell::OnceCell (…
76eb7fe
…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
@youknowone @github-actions
Replace once_cell with std::sync::OnceLock/core::cell::OnceCell (…
37fa0cb
…#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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

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.

1 participant

@youknowone
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.