Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Comments

refactor: addr_of_mut to OnceLock#2486

Open
Dsaquel wants to merge 2 commits intoast-grep:mainfrom
Dsaquel:refactor/addr_of_mut-to-OnceLock
Open

refactor: addr_of_mut to OnceLock#2486
Dsaquel wants to merge 2 commits intoast-grep:mainfrom
Dsaquel:refactor/addr_of_mut-to-OnceLock

Conversation

@Dsaquel
Copy link
Contributor

@DsaquelDsaquel commentedFeb 18, 2026
edited by coderabbitaibot
Loading

I have noticed thataddr_of_mut can be replaced byOnceLock in order to removeunsafe.
In fact, the mutation is made only once during project setup if i'm not wrong.

Summary by CodeRabbit

  • Refactor
    • Enhanced thread safety of internal language registration and injection mechanisms through improved global state management patterns.
    • Simplified function safety semantics across language management modules by removing unsafe code patterns and consolidating error handling.
    • Updated internal systems to support better concurrency handling without affecting external API behavior.

HerringtonDarkholme reacted with thumbs up emoji
@coderabbitai
Copy link
Contributor

coderabbitaibot commentedFeb 18, 2026
edited
Loading

Caution

Review failed

The head commit changed during the review from9dd8b43 to2ccf176.

📝 Walkthrough

Walkthrough

This pull request converts unsafe global mutable statics to thread-safe OnceLock-based lazy initialization patterns across the CLI and dynamic language modules. The changes remove unsafe blocks and make registration functions safe by eliminating mutable static state.

Changes

Cohort / File(s)Summary
Global State Safety Migration
crates/cli/src/lang/injection.rs,crates/cli/src/lang/lang_globs.rs,crates/dynamic/src/lib.rs
Replaced unsafe mutable global statics (LANG_INJECTIONS, LANG_GLOBS, DYNAMIC_LANG, LANG_INDEX) with thread-safe OnceLock equivalents. Updated registration functions frompub unsafe fn topub fn and replaced unsafe dereferencing with safe.get() access patterns.
Call Site Updates
crates/cli/src/lang/mod.rs,crates/dynamic/src/custom_lang.rs
Removed unsafe blocks wrapping registration function calls (lang_globs::register, injection::register_injetables, DynamicLang::register) and simplified error propagation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • HerringtonDarkholme

Poem

🐰Unsafe statics vanished in the night,
OnceLock brought thread-safe delight,
No more pointer dances, no more dread,
Safe state awaits us all ahead!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check nameStatusExplanationResolution
Docstring Coverage⚠️ WarningDocstring coverage is 31.82% 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 nameStatusExplanation
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
Title check✅ PassedThe title 'refactor: addr_of_mut to OnceLock' clearly and accurately summarizes the main change: replacing unsafe addr_of_mut patterns with thread-safe OnceLock throughout multiple files.

✏️ 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

Thanks for usingCodeRabbit! 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.

@codecov
Copy link

codecovbot commentedFeb 18, 2026
edited
Loading

Codecov Report

❌ Patch coverage is85.71429% with5 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.15%. Comparing base (3ae01ae) to head (2ccf176).

Files with missing linesPatch %Lines
crates/cli/src/lang/injection.rs80.00%3 Missing⚠️
crates/cli/src/lang/mod.rs50.00%1 Missing⚠️
crates/dynamic/src/custom_lang.rs0.00%1 Missing⚠️
Additional details and impacted files
@@           Coverage Diff           @@##             main    #2486   +/-   ##=======================================  Coverage   88.14%   88.15%           =======================================  Files         108      108             Lines       17876    17874    -2     =======================================- Hits        15757    15756    -1+ Misses       2119     2118    -1

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report?Share it here.

🚀 New features to boost your workflow:
  • ❄️Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@coderabbitaicoderabbitaibot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
crates/cli/src/lang/injection.rs (1)

54-75:Missingdebug_assert! for double-registration, unlikelang_globs.rs.

Inlang_globs.rs (line 17–20), there is adebug_assert!(LANG_GLOBS.get().is_none(), "language globs already registered") to catch accidental double-registration in debug builds. This file lacks a similar guard. Ifregister_injetables is called twice,.set().ok() silently discards the new data, and line 61's.get().expect(...) would read thestale first registration — a subtle data-loss scenario.

Consider adding adebug_assert! for consistency:

Proposed fix
 pub fn register_injetables(injections: Vec<SerializableInjection>) -> Result<()> {+  debug_assert!(+    LANG_INJECTIONS.get().is_none(),+    "language injections already registered"+  );   let mut injectable = HashMap::new();
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.In `@crates/cli/src/lang/injection.rs` around lines 54 - 75, Add a debug-onlyassertion at the start of register_injetables to ensure we aren'tdouble-registering: call debug_assert!(LANG_INJECTIONS.get().is_none(),"language injections already registered") (and optionally do the same forINJECTABLE_LANGS if you want both guards) before building and setting the mapsso a debug build will catch accidental second registrations instead of silentlydropping the new data.
crates/cli/src/lang/lang_globs.rs (1)

153-165:Test uses the globalOnceLock — may conflict with other tests callingregister().

OnceLock can only be set once per process. Since Rust's test harness runs tests as threads in a single process, if any other test in this crate (or integration tests) also callsregister(), thedebug_assert! will fire or data will be silently dropped. This is a pre-existing test-isolation concern with global state, not introduced by this PR — just worth noting as a known limitation.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.In `@crates/cli/src/lang/lang_globs.rs` around lines 153 - 165, The test uses theglobal OnceLock LANG_GLOBS via register(), which can only be set once perprocess and will conflict with other tests; modify the test or code so testsdon't rely on global state: either add a cfg(test)-only helper to reset orinitialize LANG_GLOBS (exposing a test_reset or test_set function) and call thatfrom test_merge_with_globs, or refactor register()/LANG_GLOBS to allow injectionof a local globs instance (e.g., accept a Globs param or provide a non-globalmerge_globs_in_place) so the test can operate on a per-test Globs instanceinstead of calling the global register(); update test_merge_with_globs to usethe new helper/injectable API and reference the existing register(), LANG_GLOBS,and merge_globs symbols when making the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.Inline comments:In `@crates/dynamic/src/lib.rs`:- Around line 157-159: Remove the incorrect "/// # Safety" doc heading above thenon-unsafe function register and instead document the one-time-call requirementas a normal doc comment; update the comment block for pub fn register(regs:Vec<Registration>) -> Result<(), DynamicLangError> so the note "The registerfunction should be called exactly once before use." appears as a regulardocumentation line (not under a Safety section) immediately above the functionsignature.---Nitpick comments:In `@crates/cli/src/lang/injection.rs`:- Around line 54-75: Add a debug-only assertion at the start ofregister_injetables to ensure we aren't double-registering: calldebug_assert!(LANG_INJECTIONS.get().is_none(), "language injections alreadyregistered") (and optionally do the same for INJECTABLE_LANGS if you want bothguards) before building and setting the maps so a debug build will catchaccidental second registrations instead of silently dropping the new data.In `@crates/cli/src/lang/lang_globs.rs`:- Around line 153-165: The test uses the global OnceLock LANG_GLOBS viaregister(), which can only be set once per process and will conflict with othertests; modify the test or code so tests don't rely on global state: either add acfg(test)-only helper to reset or initialize LANG_GLOBS (exposing a test_resetor test_set function) and call that from test_merge_with_globs, or refactorregister()/LANG_GLOBS to allow injection of a local globs instance (e.g., accepta Globs param or provide a non-global merge_globs_in_place) so the test canoperate on a per-test Globs instance instead of calling the global register();update test_merge_with_globs to use the new helper/injectable API and referencethe existing register(), LANG_GLOBS, and merge_globs symbols when making thechange.

@DsaquelDsaquelforce-pushed therefactor/addr_of_mut-to-OnceLock branch from9dd8b43 to2ccf176CompareFebruary 18, 2026 12:12
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@coderabbitaicoderabbitai[bot]coderabbitai[bot] left review comments

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

1 participant

@Dsaquel

[8]ページ先頭

©2009-2026 Movatter.jp