Skip to content

perf(analysis): share macro scopes across MacroVisibility resolvers - #11974

Merged
EffortlessSteven merged 7 commits into
mainfrom
claude/project-thread-tsulhi-2
Nov 1, 2026
Merged

EffortlessSteven merged 7 commits into
mainfrom
claude/project-thread-tsulhi-2

Conversation

@EffortlessSteven

Copy link
Copy Markdown
Member

Governing issue or accepted claim: #11948

Acceptance delta (one sentence): The facts pass and the classifier no longer each re-parse the same source to build its macro scope, cutting about 6% from the servo cold pilot with findings unchanged.

Change

MacroVisibility resolvers memoized macro_scope per instance, so the same source was parsed up to three times per run. A pointer-keyed, weak-validated shared cache (capped at 16,384 entries) lets resolvers over one Arc<str> share a single scope. An equal-text but separately allocated source does not share, which the test pins.

Proof

  • cargo xtask precommit passes.
  • New test resolvers_over_one_source_share_its_scope.
  • Servo cold pilot receipts are in changelog.d/11948-share-macro-scopes-across-resolvers.md.

Generated by Claude Code

@gemini-code-assist

Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@coderabbitai

coderabbitai Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

  • Ask an admin to enable usage-based reviews

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Next included review available in 51 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available. Your 149 included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Essentials
  • Run ID: e632846d-fec7-477a-9388-c1127bcb9e7c
Commits

Reviewing files that changed from the base of the PR and between 99b2e4d and 326bd10.

Files selected for processing: 3
  • changelog.d/11948-share-macro-scopes-across-resolvers.md
  • crates/ripr/src/analysis/facts/macro_visibility.rs
  • crates/ripr/src/analysis/facts/macro_visibility/declaration_tests.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@EffortlessSteven
EffortlessSteven marked this pull request as ready for review October 31, 2026 23:44
@gemini-code-assist

Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@github-actions

Copy link
Copy Markdown
Contributor

merge-ready was requested, but this PR conflicts with main (head 3e550a2c), so GitHub creates no test-merge ref and no qualification run can start. Merge main into the branch and resolve the conflicts, then remove and re-apply merge-ready.

@EffortlessSteven EffortlessSteven left a comment •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Independent review (fresh-context reviewer, head 3e550a2): REVIEW_INCOMPLETE

Inspected:

  • The candidate's whole change: two files over base 56d273dc2 - crates/ripr/src/analysis/facts/macro_visibility.rs (+68/-8) and changelog.d/11948-share-macro-scopes-across-resolvers.md (+2/-0). It adds a process-global, pointer-keyed cache of derived macro scopes: static SHARED_SCOPES: Mutex<Option<HashMap<usize, (Weak<str>, Option<Arc<MacroScope>>)>>>, capped at SHARED_SCOPE_ENTRIES = 16_384, consulted by shared_scope(source) and by the resolver's per-file scope() lookup. The stated purpose is in the changelog fragment and the design comment: the facts pass and the classifier each build a MacroVisibility over the same sources, each resolver (and each clone) starts with an empty memo, so every Rust file was parsed again for each - about three parses of 1,730 files on servo.
  • The keying hazard, which is the load-bearing design question here, and it is handled correctly. The cache is keyed by the address of the Arc<str> allocation (Arc::as_ptr(source).cast::<u8>() as usize), which is the classic ABA setup: a freed allocation's address can be reused by a different one. The defense is the Weak validation on lookup - weak.upgrade().is_some_and(|live| Arc::ptr_eq(&live, source)) - and it is airtight for the reason it should be. Arc::downgrade keeps the control block alive, so a freed allocation's Weak cannot upgrade, and a reused address therefore produces None from upgrade() and misses the cache; and when the address is reused while the old control block is still alive, Arc::ptr_eq compares the new allocation against the old one and rejects it. A cache miss costs a re-parse, never a wrong scope, provided that validation holds. I checked the two places it could be bypassed and it is not: the lookup validates on every hit, and the stored Weak is always Arc::downgrade of the source it was derived from.
  • That sharing the derived scope is safe, which is the second question the change has to answer. MacroScope is pub(crate) struct MacroScope { macros: Vec<ScopedMacro>, modules: Vec<ScopedModule>, uses: Vec<ScopedUse>, export_opaque: bool, opaque: bool } in crates/ripr/src/analysis/syntax/macro_scope.rs - plain data with no interior mutability, no RefCell, Cell, Mutex or OnceCell. Two resolvers holding the same Arc<MacroScope> therefore observe the same immutable value, which is what the previous one-Arc-per-resolver behaviour produced as well. ScopedMacro is likewise plain (name, offset, text, exported). Sharing is sound.
  • That the layering is right. The per-instance memo is still consulted first - scope() checks self.scopes before falling through to the shared cache - so the shared cache is only reached on a per-instance miss. The expensive work happens outside the lock: macro_scope(source) is called before SHARED_SCOPES.lock() is taken, so concurrent resolvers do not serialize on the parse. The lock is held only for a map lookup and a map insert. Two threads that race on the same key both parse and both insert; the second insert overwrites with an equal value, which is benign.
  • That the error path is preserved and improved. The old code was for scoped in macro_scope(source).unwrap_or_default().macros; the new code is let Some(scope) = shared_scope(source) else { continue; } followed by for scoped in &scope.macros. An unparseable file previously produced an empty scope and an empty iteration; it now produces None and a skipped iteration - the same outcome. The negative result is also cached (Option<Arc<MacroScope>>), so a file that fails to parse is not re-parsed on the next resolver.
  • The oracle, and what it does and does not pin. resolvers_over_one_source_share_its_scope asserts both halves of the keying contract: two resolvers built over the same Arc<str> return scopes that are Arc::ptr_eq, and a resolver built over a separately allocated Arc::from(&*source) - same text, different allocation - returns a scope that is not ptr_eq. Both assertions are discriminating, and the second one is the one that would catch a change from pointer keying to text keying.
  • The hosted state at this head. Exactly one workflow ran: Merge-ready Conflict Notice, success. No CI run and no Merge-ready request run exist for this head, so no Rust lane ran at all - the merge-ready label was never applied. The only red context on the pull request is merge-ready conflict with state=FAILURE, which is the base-conflict re-check, matching the reported merge state DIRTY. The required Ripr Rust Small Result context is absent rather than green, and no implementation or test result exists at this head.

Blocking:

  • None found. The change is a correct, well-scoped cache, the two hazards it introduces - address reuse and shared mutable state - are both properly defended, and the negative result is cached alongside the positive one.
  • One landing-readiness item, not a candidate defect: the branch is DIRTY against its base (the merge-ready conflict check is the one red context), and the required Ripr Rust Small Result context is absent because no Rust lane ran at this head.

Non-blocking:

  • The cache's eviction is a live-set filter with a full clear, and it is O(cap) per insert once the cap is reached. When map.len() >= SHARED_SCOPE_ENTRIES, the code does map.retain(|_, (weak, _)| weak.strong_count() > 0) and, if the map is still at the cap, map.clear(). Both operations are O(cap) over 16,384 entries, and they run on every insert past the cap. On servo - 1,730 files per this pull request's own receipt - the cap is an order of magnitude away, so this path does not execute. But a repository holding more than 16,384 simultaneously-live sources would pay an O(cap) retain plus an O(cap) clear per file, i.e. O(files x cap) across the run. It remains a net win, because each avoided parse is far more expensive than 16,384 hash-map operations, but it is not amortized O(1) and it is worth knowing before the same cache shape is reused on a larger corpus. A second-chance or epoch scheme, or simply a smaller cap with an LRU discipline, would keep the insert path O(1) amortized.
  • The cap bounds entries, not bytes. Each entry holds a strong Arc<MacroScope> - the parsed macro table for one file - so 16,384 live entries is an unbounded-in-bytes amount of retained parse output, and the number was not derived from a memory budget. The retain only runs when the cap is hit, so scopes for sources that have since been dropped accumulate in between. The Weak keeps the source from being pinned, which is the right thing, but the derived scope is pinned strongly. If the intent is a memory ceiling rather than an entry ceiling, the retained value should be the one bounded.
  • A poisoned mutex silently disables the cache for the rest of the process. Both lock sites use if let Ok(guard) = SHARED_SCOPES.lock(), so if a panic ever occurs while the lock is held, the mutex is poisoned, lock() returns Err from then on, and every subsequent call takes the false branch: the scope is still derived correctly, so results stay right, but the cache is never written or read again and the optimization disappears with no signal. lock().unwrap_or_else(|poisoned| poisoned.into_inner()) would recover it. The exposure window is small - the lock is held only across a map get and a map insert, never across the parse - so poisoning is unlikely, but the failure mode is silent and permanent, and a cache that silently stops working is harder to notice than one that fails loudly.
  • The receipt's own numbers are surprising and unexplained, and that matters for how the change generalises. The changelog fragment states that the cold pilot parsed 1,730 files three times each, that the macro-scope parsing was "62% of the bytes it parsed", and that sharing cuts the cold pilot about 6% - CPU 55.6 to 51.7 s and 57.2 to 53.1 s, wall 43.5 to 40.6 s and 44.9 to 42.1 s, two paired runs on a loaded 4-core box. If two of every three parses of every file were eliminated and the parsing was 62% of the bytes read, the time saving should be considerably larger than 6%. The most likely explanation is that the removed work was not on the critical path - the bytes were read and parsed, but the parse was cheap next to the rest of the analysis - which is a perfectly good outcome and arguably the most interesting finding here, because it means the duplicate parses were mostly not what the cold pilot spent its time on. But that reasoning is not in the receipt, and it is the part that decides whether the same change pays off on other repositories. A per-phase timing breakdown rather than a whole-pilot delta would settle it, and would cost nothing beyond the runs already being made for the paired comparison. I am not asserting the numbers are wrong; I am recording that they do not obviously follow from the stated model and that the gap is the interesting part.
  • The ABA defense - the one failure mode here that would be a silent wrong answer rather than a slow path - is argued in the design comment but not pinned by a test. The test covers "same allocation shares" and "different allocation with the same text does not share"; neither forces an address to be reused, so a regression that dropped the weak.upgrade()/ptr_eq validation would keep both tests green. That regression would be fail-open: a scope derived from a different file could be returned for a reused address, which would make a macro appear invisible or mis-scoped. Address reuse is awkward to force deterministically, but the property can be pinned without it by testing the lookup helper directly - that a key whose Weak no longer upgrades yields None and does not return the stored scope - which needs no address manipulation at all.
  • One small regression inside the optimized path: generators.insert(scoped.name.clone()) replaces what was a move (generators.insert(scoped.name)) with a clone, so each matching macro now allocates a fresh String where the scope already owned one. It is immaterial next to the parse it sits behind, but it is a new allocation in the code this change exists to make cheaper, and ScopedMacro.name could be inserted by reference or the scope could hand out an owned name deliberately.
  • On efficiency, in summary: the change removes redundant work rather than adding any. Before, each source was parsed up to three times per run (the facts pass, the classifier, and each resolver clone); after, each distinct Arc<str> allocation is parsed once. The lookup is O(1) - a hash of an integer key plus a Weak::upgrade and an Arc::ptr_eq - and the parse, which is the expensive part, is outside the lock. The remaining costs I could find are the eviction path and the retained scopes described above; I found no unbounded growth, no quadratic behaviour, no new I/O, no process spawning, no cache-keying mistake and no memory growth beyond the bounded-but-not-byte-bounded entry set. On the semantic side the change is a pure cache: the derived scope is the same content either way, so a miss costs time and not correctness - with the ABA case as the one exception, and that is defended.

Not run:

  • The Rust toolchain on this host is not on PATH: I ran no test, clippy, fmt, or cargo xtask gate. I did not reproduce the cargo xtask precommit result the pull request claims, and I did not run the new test.
  • No hosted Rust lane ran at this head: the only workflow that ran was Merge-ready Conflict Notice, so the exact-head workspace result is unobserved rather than green, and the pull request's servo pilot receipts are the only performance evidence I have. I did not reproduce those runs.
  • I could not execute the new test, so my reading of the eviction and poisoning behaviour is from the source and not from an observed run; in particular the claim that the cap is never reached on servo rests on the receipt's file count, not on a measurement I made.
  • I did not run a combined-tree compile of the merged base and head.

Reviewed by an independent Mavis review agent on behalf of the maintainer; bound to head 3e550a2ca5267ce347d752e037b33c0cb66924f6. Not an approval.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SvmPmnpjseHB4bwBLfUmC5
…rom #11975 (main red)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SvmPmnpjseHB4bwBLfUmC5
…o matched

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SvmPmnpjseHB4bwBLfUmC5

Copy link
Copy Markdown
Member Author

Rust-only feature lane is red on head 8c534d3 with failures in -p ripr --lib and -p ripr --test cli_smoke. Neither touches this diff (macro_visibility only). They match the known main breaks: the cli_smoke --json spelling (#11982) and the LSP list_actionable_items group order (#11989), both open with fixes. I'm not widening this PR. Once those land I'll merge main and re-run once.


Generated by Claude Code

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Verification questions

  • Confirm the cache's cap and eviction behavior are untested, including whether a newly derived scope remains usable after another source causes eviction.
  • Confirm the new sharing test observes scope pointer identity, not that the second resolver avoided reparsing.
  • Confirm the adjusted declaration test now expects two parses, but does not identify which two sources were parsed.
  • Confirm a poisoned SHARED_SCOPES mutex permanently disables sharing, because both lookup and insertion use if let Ok(lock) and silently continue without repairing the poisoned state.
  • Confirm the process-global cache can be affected by test execution order, but existing tests only assert aggregate parse counts and pointer sharing.
  • Confirm concurrent access to the process-global cache and scope derivation is not exercised by the changed tests.
  • Confirm the global cache is process-wide and mutable, so stale, poisoned, or concurrently evicted entries require explicit isolation and stress coverage.

Evidence gaps

  • The performance claim compares cold-pilot outputs only apart from paths, hashes, and timestamps, but the changed source does not expose the referenced receipt contents or verify artifact equivalence.
  • No completed cargo-test receipt or focused concurrent/cache-pressure witness is available to validate the new global-cache behavior.
  • Full executable validation remains incomplete because cargo-test has no receipt and ripr failed with exit code 2.
  • Model proof intent was rejected by deterministic validation.
  • The changelog's 6% performance improvement is supported only by two paired runs on a loaded four-core box, while equivalence is asserted apart from paths, hashes, and timestamps.

…try guard (#11948)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SvmPmnpjseHB4bwBLfUmC5

@EffortlessSteven EffortlessSteven left a comment •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Independent review (fresh-context reviewer, head 8c534d3): REVIEW_INCOMPLETE

This is a re-bind. An independent review already exists on this PR bound to 3e550a2ca5267ce347d752e037b33c0cb66924f6, which reported REVIEW_INCOMPLETE with no blocking defect and five non-blocking findings. The head has since moved. This review covers the delta and states, per earlier finding, whether it still holds, has been repaired, or is stale. It does not supersede the earlier review; it binds to the head below.

Inspected:

  • Head 8c534d3bb9542d0755b87c5737d716f57e1a3652; not draft; mergeable: MERGEABLE, mergeStateStatus: BLOCKED; label merge-ready present; title "perf(analysis): share macro scopes across MacroVisibility resolvers".
  • The candidate's contribution against merge base ad8b265b821f2380f15cb6ea859214b46b2c9788 is now 4 paths, +76/-13: changelog.d/11948-share-macro-scopes-across-resolvers.md (+2/-0), crates/ripr/src/analysis/facts/macro_visibility.rs (+80/-13), crates/ripr/src/analysis/facts/macro_visibility/declaration_tests.rs (+6/-6, new module) and policy/process_allowlist.d/11720-first-pr-run-chain.txt (+3/-0, new file). The head-to-head delta 3e550a2ca..8c534d3bb is 947 paths, but that is main's advance; the candidate's own change since the previously reviewed head is the text-gate work in macro_visibility.rs, the new declaration_tests.rs module, and the allowlist file.
  • The change the delta makes. MacroVisibility::attributed moves from OnceLock<BTreeMap<String, BTreeSet<PathBuf>>> to SyncMemo<BTreeMap<String, Arc<Vec<PathBuf>>>> (:63, :123, :311), i.e. from one whole-workspace index built once to a per-name, lazily resolved memo. A new text gate may_declare_module_named(source, name, attributed) (:165) decides from raw text whether a file could declare mod name; at all, so a file that cannot spell the declaration is never parsed. A new attributed_elsewhere(name, file) (:646) replaces the index lookup and stops the scan at the second confirmed declarer, on the reasoning that two distinct files always include one that is not file. A test-only thread_local! counter SCOPE_PARSES (:38) counts parses so the new tests can assert the count.
  • The new oracle in crates/ripr/src/analysis/facts/macro_visibility/declaration_tests.rs: resolving_one_file_parses_only_files_that_can_declare_its_modules asserts exactly 2 scope parses for a 53-file workspace and 0 for a repeat ask; the_lookup_matches_the_whole_workspace_index is a differential test that compares attributed_elsewhere against a whole-workspace reference index over 27 contrived sources x 4 names x 3 files, including mod r#cases;, mod\u{200e}cases;, pub (in crate) mod cases;, #[doc = "a]b"] #[cfg(feature = "x")] mod cases; and #[path = "a[0]"] mod cases;; the_text_gate_never_hides_a_declaration_the_parser_lists cross-checks the gate against the parser's own module list over a name x gap x prefix grid and asserts more than 100 declarations were checked; the_attributed_lookup_stops_at_the_second_declarer pins the early stop; the_text_gate_keeps_every_contrived_attributed_declaration pins 17 contrived attributed forms.
  • crates/ripr/src/analysis/facts/macro_visibility.rs at this head: the shared cache is unchanged in its load-bearing parts — SHARED_SCOPE_ENTRIES = 16_384 (:88), SHARED_SCOPES.lock() at :93 and :104 both still if let Ok(...), the validation weak.upgrade().is_some_and(|live| Arc::ptr_eq(&live, source)) at :96-97, the stored Arc::downgrade(source) at :112, the eviction map.retain(...) / map.clear() at :106-109, and generators.insert(scoped.name.clone()) at :303.
  • Hosted evidence at this head (57 contexts): Ripr Rust Small on GitHub Hosted / Rust gates (job 124705557418) FAILURE with the gate table FORMATTING_RESULT: success, PRECOMMIT_RESULT: success, PROCESS_POLICY_RESULT: success, ALL_FEATURES_CHECK_RESULT: success, CLIPPY_RESULT: success, GOLDENS_RESULT: success, FIXTURES_RESULT: success, CAPABILITY_PRODUCERS_RESULT: success, CAPABILITY_DOCS_RESULT: success, VERDICT_CORPUS_RESULT: failure, RUST_TESTS_RESULT: skipped; Rust-only feature lane (job 124705378633) FAILURE with test result: FAILED. 12889 passed; 1 failed and a second group test result: FAILED. 619 passed; 2 failed; Ripr Rust Small Result (the required status check on main) FAILURE and present; ub-review CANCELLED.

Earlier findings, re-disposed:

  • "No blocking defect: the change is a correct, well-scoped cache, and the two hazards it introduces — address reuse and shared mutable state — are both properly defended" → STILL HOLDS for the cache half, and the delta extends the design rather than weakening it. The Weak upgrade plus Arc::ptr_eq validation is unchanged at :96-97 and the stored Weak is still Arc::downgrade of the source it was derived from at :112, so a reused address still misses rather than returning a foreign scope. The delta adds a second, orthogonal optimization — a text prefilter — and it is also fail-closed in the same direction: every case the gate cannot model (a comment, a non-ASCII byte, a keyword, an attribute it does not recognise, an unmodelled pub(..) form) returns "maybe" and forces the parse.
  • Landing-readiness — "the branch is DIRTY against its base and the required Ripr Rust Small Result context is absent because no Rust lane ran at this head" → REPAIRED. The branch is now MERGEABLE against its base and the required context is present at this head.
  • Non-blocking — "the cache's eviction is a live-set filter with a full clear, and it is O(cap) per insert once the cap is reached" → STILL HOLDS. macro_visibility.rs:106-109 is unchanged: map.retain(|_, (weak, _)| weak.strong_count() > 0) then map.clear() when still at the cap, both O(cap) over 16,384 entries, on every insert past the cap. The receipt's 1,730 files are an order of magnitude below the cap, so it does not execute there, but it is still O(files x cap) across a run on a larger corpus.
  • Non-blocking — "the cap bounds entries, not bytes; each entry holds a strong Arc<MacroScope>" → STILL HOLDS. :88 and :112 are unchanged.
  • Non-blocking — "a poisoned mutex silently disables the cache for the rest of the process" → STILL HOLDS. Both lock sites are still if let Ok(guard) = SHARED_SCOPES.lock() (:93) and if let Ok(mut guard) = SHARED_SCOPES.lock() (:104). A panic while the lock is held poisons it, every later call takes the false branch, and the scope is still derived correctly — so results stay right while the optimisation disappears with no signal. lock().unwrap_or_else(|poisoned| poisoned.into_inner()) would recover it. The exposure window is small, because the lock is only held across a map get and a map insert and never across the parse, but the failure mode is silent and permanent, and a cache that silently stops working is harder to notice than one that fails loudly.
  • Non-blocking — "the ABA defense is argued in the design comment but not pinned by a test; a regression that dropped the weak.upgrade()/ptr_eq validation would keep both tests green" → STILL HOLDS. The new declaration_tests.rs module tests the text gate, not the ABA path. The only ptr_eq assertions in the tree are still the pre-existing pair at :1331/:1335 ("same allocation shares", "different allocation with the same text does not share"), neither of which forces an address reuse or exercises a Weak that no longer upgrades. The earlier review's suggestion still stands: the property can be pinned without any address manipulation by testing the lookup helper directly — a key whose Weak no longer upgrades must yield None and must not return the stored scope. The failure mode there is a silent wrong answer rather than a slow path, which is why it deserves a test rather than an argument.
  • Non-blocking — "generators.insert(scoped.name.clone()) replaces a move with a clone, a new allocation in the code this change exists to make cheaper" → STILL HOLDS. :303 is unchanged.
  • Non-blocking — "the receipt's numbers are surprising and unexplained: eliminating two of three parses of every file when the parsing was 62% of the bytes read should have saved considerably more than 6%" → STILL HOLDS, and the delta widens the gap. The changelog fragment is unchanged at +2 lines, so it still carries only the original receipt. The delta adds a second, different optimization — the text prefilter, which avoids parses entirely for files that cannot spell a declaration — and the fragment states no receipt for it at all. The interesting question the earlier review raised (whether the duplicate parses were on the critical path) is still unanswered, and now there is a second change whose effect is unmeasured. A per-phase timing breakdown would settle both, and the paired runs this PR already makes are the natural place to take it.

Blocking:

  • None attributable to this candidate. The one gate that fails on the candidate's own lane is base-side, and I proved it with a same-base sibling rather than by argument (see below).

Non-blocking:

  • verdict-corpus check-all is red at this head, and it is base-side. The gate names exactly two cases: eq-divert-match-later-arm-old-constant and shop-tier-gold-arm-unreached, each "expected observed_verdict: \"limited\", got observed_verdict: \"gap\"". I did not take that on trust: #10240, whose head carries main's crates/ripr/src/analysis/facts/macro_visibility.rs blob 53bdc767e7434ad4054c6a1d072d672a63404ab9 — byte-identical to main's, and therefore without this candidate's macro-visibility change — and the same stale committed rows, fails the same gate with the same two cases and the same expected/got values (job 124688421807). The drift therefore reproduces without the candidate, which places its cause on main. I traced it there: commit 7972ca8f ("fix(arm-selection): ignore inline test module use super::* for binding arms (#11950)") is an ancestor of main, changed crates/ripr/src/analysis/classify/arm_selection.rs by +82/-13, and did not re-bless those two rows. The repair carrier is #11995, whose contribution re-blesses exactly these two rows from limited to gap. Two earlier independent reviews in this campaign reached the same conclusion from the other direction, so this is corroboration rather than a new claim.
  • The Rust-only feature lane fails three tests, none in this candidate's diff. lsp::backend::list_actionable_items_tests::list_actionable_items_names_gaps_the_actionable_profile_hides is the known base-side red; check_worktree_drill_in_commands_reach_the_uncommitted_finding and selector_location_misses_explain_syntax_and_preserve_retry_scope are also outside this candidate's four-path contribution. RUST_TESTS_RESULT: skipped on the Rust gates job is likewise unobserved rather than green.
  • The text gate is a correctness-bearing filter whose guarantee is empirical, not structural. may_declare_module_named decides whether a file is parsed at all for an attributed-declaration lookup. A false negative there — a real mod name; with an attribute in a file the gate rejects — would make the lookup miss a declarer, so a macro would be treated as uniquely declared when the workspace says otherwise: a wrong analysis answer, not a slow path. The design is fail-closed (the gate returns "maybe" for every case it does not model) and the differential test the_lookup_matches_the_whole_workspace_index is the right shape of oracle, because it compares the fast path against a whole-workspace reference index rather than against a restatement of itself. But the gate is a hand-written second approximation of the lexer's rules — may_follow_attribute models a bare pub, a plain pub(...), and a tolerated attribute set, and treats everything else as a maybe — so every lexer rule it does not model is a chance for a silent false negative, and the tests pin a fixed, sampled matrix (27 contrived sources, and a name x gap x prefix grid yielding more than 100 parsed declarations) rather than proving the gate cannot hide a declaration. The cheapest strengthening is to derive the gate from the same lexer macro_scope uses, or to make the differential test generate its source matrix rather than enumerate it; as it stands, the guarantee is broad but sampled.
  • Efficiency — the shape moved from "one index for all names" to "one full text scan per name". The old attributed_declarations() built a single BTreeMap<String, BTreeSet<PathBuf>> for every name in one pass over the sources. The new attributed_elsewhere(name, file) resolves one name at a time, so each distinct name asked costs a scan over every source's text — may_declare_module_named does source.match_indices(name) across the whole file — making the worst case O(names x files x source_len) against the old O(files x source_len) parse-based index. The trade is in the right currency: a text scan is far cheaper than a parse, and it buys the early stop at the second declarer, which is where the win is. Two costs are worth naming. First, the memo is per-MacroVisibility instance — Clone resets it (attributed: SyncMemo::default(), :123), so each clone re-runs the per-name scans, even though the shared SHARED_SCOPES cache added by the earlier half of this PR is process-global and would serve exactly this. Second, the scan is a full-text substring search per name, so a workspace with many module names pays many full-file scans. Lifting the per-name result into the same shared-cache shape as SHARED_SCOPES — keyed by the name and the source set — would remove both costs at once.
  • Efficiency — the new parse counter cannot see a parse on another thread. SCOPE_PARSES is a thread_local! Cell, so it observes only parses on the thread that ran the test. The tests are single-threaded so this is correct for them, but the shared cache is a process-global Mutex shared across threads, so the counter's reach is narrower than the cache's. Worth knowing before anyone uses it as a general "how many parses happened" probe.
  • Duplicate-carrier note (verified by blob, not by issue number). The delta adds policy/process_allowlist.d/11720-first-pr-run-chain.txt with blob 2402ccd29d575e911faa09697f7f303872ead9a5 — byte-identical to the copy carried by #11975, #11942 and #11995. Its subject is #11720's ripr first-pr --run-chain: both crates/ripr/src/output/first_pr/run_chain.rs and crates/ripr/tests/first_pr_run_chain.rs exist on main and both spawn processes, which is why main's check-process-policy is red. #11974 is a macro-visibility performance change with no connection to the run chain, so this file is a carried dependency, not part of this PR's claim; #11975 was already named the narrow survivor of that repair. Because the blob is identical there is no textual conflict, but the allowlist repair is now travelling inside four PRs, and the deciding criterion should be stated once rather than re-derived per PR: the entry belongs to whichever PR owns the spawning test file (#11970), with #11975 as the minimal carrier if #11970 does not take it. Nothing in this PR's own claim depends on it.

Not run:

  • The Rust toolchain on this host is not on PATH, so there was no local build, no cargo xtask precommit, no local test run, and no way to execute the new tests here. Every Rust-level statement above comes from the hosted job logs at this exact head or from reading source at this exact SHA.
  • I did not measure the new text gate's effect. The delta's own performance claim has no receipt, and I did not reproduce the fragment's paired servo runs, so I make no claim about how much the text prefilter saves relative to the shared-scope cache, nor whether it could regress any case the shared cache handled.
  • The hosted Rust phase beyond the gates I quoted is unobserved at this head: RUST_TESTS_RESULT, BASE_STILL_MERGES_RESULT, PR_EVIDENCE_RESULT and SCHEMA_SWEEP_RESULT are all skipped, and ub-review was CANCELLED at its substantive step. This review does not rest on them and does not claim they passed.
  • I did not execute the new declaration_tests.rs module, so my reading of the gate's soundness is from the source and from the test matrix, not from an observed run.

Reviewed by an independent Mavis review agent on behalf of the maintainer; bound to head 8c534d3bb9542d0755b87c5737d716f57e1a3652. Not an approval.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SvmPmnpjseHB4bwBLfUmC5

Copy link
Copy Markdown
Member Author

Rust tests shard 2 of 4 on head 326bd10 died with exit code 143 (SIGTERM, runner terminated) with no test failure in its log, and the shards verify job failed as a consequence. This is not a test result for this diff, so I re-ran the failed jobs once (run 41269810524). If shard 2 fails again with a real test failure, I'll treat it as mine.


Generated by Claude Code

Copy link
Copy Markdown
Member Author

Review of record, head 326bd10 (COMMENT; helper review-burn-down)

Evidence: the shard 2 SIGTERM failure (run 41269810524, 05:02Z) was infrastructure; the rerun on the same head completed Ripr Rust Small Result success at 06:34:50Z with all 4 shards, shards verify and Rust gates green. mergeable_state clean; no review threads. No push or comment by the author lane since 04:51Z (7 hours), so no live owner.

Angles inspected (full diff read):

  1. Semantic owner. macro_scope(source) is a pure function of the immutable Arc<str> text, so a scope derived once is valid for every resolver holding that allocation; both consumers (MacroVisibility::new generator scan and scope()) now go through shared_scope.
  2. Cache key correctness. Key is the allocation address, and a hit requires Weak::upgrade to yield Arc::ptr_eq with the caller's source, so a reused address returns nothing stale (fail-closed: miss re-derives). A Weak also pins the allocation until the entry is evicted, so reuse cannot occur while the entry lives. A different allocation with equal text derives its own scope (asserted).
  3. Bounds and locking. 16,384 entries; at the cap it drops dead entries then clears. Lock is never held across macro_scope, so there is no parse under the mutex and no deadlock; poisoning is recovered, which is safe because the data is re-derivable. Minor note: dead entries retain their Weak allocation until eviction, bounded by the cap.
  4. Tests. resolvers_over_one_source_share_its_scope asserts pointer sharing across two resolvers and non-sharing for a copy; a_stale_entry_at_a_reused_address_is_not_returned injects a dead-Weak entry at the live key and asserts the bogus scope is not returned. The declaration_tests parse count change 3 to 2 is explained (macros.rs scope already shared from the generator scan) and keeps the negative claim for filler files.
  5. Docs/changelog. Fragment 11948-share-macro-scopes-across-resolvers.md has a valid section and (#11948); no output, schema or golden change (identical repo-exposure/packet output reported).

Findings: none material. Merging on the exact head.


Generated by Claude Code

@EffortlessSteven
EffortlessSteven merged commit f317af7 into main Nov 1, 2026
102 of 108 checks passed
@EffortlessSteven
EffortlessSteven deleted the claude/project-thread-tsulhi-2 branch November 1, 2026 11:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants