Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork318
Comments
Conversation
coderabbitaibot commentedFeb 18, 2026 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
📝 WalkthroughWalkthroughThis 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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for usingCodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
codecovbot commentedFeb 18, 2026 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Codecov Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
There was a problem hiding this 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.In
lang_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_injetablesis 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 a
debug_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().
OnceLockcan 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.Uh oh!
There was an error while loading.Please reload this page.
9dd8b43 to2ccf176Compare
Uh oh!
There was an error while loading.Please reload this page.
I have noticed that
addr_of_mutcan be replaced byOnceLockin order to removeunsafe.In fact, the mutation is made only once during project setup if i'm not wrong.
Summary by CodeRabbit