GeezerVison is showing github.com — Replace `std::sync::LazyLock` with `common::lock::LazyLock` by youknowone · Pull Request #7079 · 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.
lock.rs now exports both LazyCell and LazyLock:
- threading: re-exports from std::sync / core::cell
- non-threading:
LazyCell from core::cell, LazyLock as LazyCell wrapper with Sync (safe without threading)
Summary by CodeRabbit
- Refactor
- Updated internal lazy initialization mechanisms to use an optimized local implementation instead of standard library dependencies, improving code consistency across the project.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
lock.rs now exports both `LazyCell` and `LazyLock`:
- threading: re-exports from std::sync / core::cell
- non-threading: `LazyCell` from core::cell, `LazyLock` as
LazyCell wrapper with Sync (safe without threading)
coderabbitai
Bot
commented
Feb 11, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
📝 Walkthrough
Walkthrough
This change removes the Lazy alias and exposes LazyLock and LazyCell directly in the lock module, adds a LazyLock<T, F> wrapper with a Sync impl and helpers for non-threading builds, and updates many import sites to use rustpython_common::lock::LazyLock (or crate::common::lock::LazyLock).
Changes
| Cohort / File(s) |
Summary |
Lock Module Core crates/common/src/lock.rs |
Removed Lazy alias; re-exported LazyLock and LazyCell explicitly. Added public LazyLock<T, F> wrapper around core::cell::LazyCell with unsafe impl Sync, const fn new, force(&Self) -> &T, and Deref impl. |
Stdlib imports crates/stdlib/src/contextvars.rs, crates/stdlib/src/csv.rs, crates/stdlib/src/mmap.rs, crates/stdlib/src/openssl.rs, crates/stdlib/src/ssl/oid.rs, crates/stdlib/src/typing.rs |
Replaced imports of std::sync::LazyLock with rustpython_common::lock::LazyLock and updated call sites (e.g., LazyLock::force). |
VM builtins imports crates/vm/src/builtins/... bytes.rs, dict.rs, genericalias.rs, mappingproxy.rs, memory.rs, range.rs, set.rs, str.rs, template.rs, tuple.rs, union.rs, weakproxy.rs |
Replaced std::sync::LazyLock imports with crate::common::lock::LazyLock across builtins. |
VM stdlib & types imports crates/vm/src/stdlib/ctypes/array.rs, crates/vm/src/stdlib/ctypes/pointer.rs, crates/vm/src/stdlib/sre.rs, crates/vm/src/types/structseq.rs |
Replaced std::sync::LazyLock with crate::common::lock::LazyLock for static initializers and mapping/sequence helpers. |
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs
Suggested reviewers
- ShaharNaveh
- coolreader18
- fanninpm
Poem
🐰 I nudged the locks to show their name,
No alias hiding, no secret game.
A wrapper snug for single-threaded cheer,
Imports changed — the path now clear.
Hooray, my code hops forward, bright and tame!
🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
| Check name |
Status |
Explanation |
Resolution |
| Docstring Coverage |
⚠️ Warning |
Docstring coverage is 11.11% 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 pull request title accurately and concisely summarizes the main change: replacing std::sync::LazyLock with common::lock::LazyLock across multiple files, including the new LazyLock implementation in lock.rs. |
✏️ 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/stdlib/src/ssl/oid.rs (1)
135-136: Consider importing LazyLock instead of using a fully qualified path.
Other files in this PR import LazyLock with a use statement, but here it's used fully qualified. For consistency:
♻️ Suggested refactor
Add at the top of the file:
use rustpython_common::lock::LazyLock;
Then simplify the declaration:
-static OID_TABLE: rustpython_common::lock::LazyLock<OidTable> =
- rustpython_common::lock::LazyLock::new(OidTable::build);
+static OID_TABLE: LazyLock<OidTable> = LazyLock::new(OidTable::build);
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:
|
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.
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.
|