◐ Shell
clean mode source ↗

Replace `std::sync::LazyLock` with `common::lock::LazyLock` by youknowone · Pull Request #7079 · RustPython/RustPython

📝 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 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/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.