Repository navigation
perf(classify): skip macro-item parse when the exact answer is known (#9217) - #12033
Conversation
…9217) Return false from macro_may_define_item_named without MacroSites::scan when the source has no `!`, or when the callee name is absent and the file has no macro_rules!. Unparsed files that hold macro_rules! stay undecided. Retarget the #9086 SCAN_COUNT pin onto a source that contains `!` so it still measures scan-once-per-distinct-query after the skip. Co-authored-by: Steven Zimmerman, CPA <EffortlessSteven@users.noreply.github.com>
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
Warning Review limit reachedEnable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing. Next included review available in 58 minutes. View limit details
|
EffortlessSteven
left a comment
There was a problem hiding this comment.
review-pr (author self-review COMMENT)
GitHub cannot request-changes from the author. This is not an approval.
reviewed_head_sha: ccd20e0655dfadae757a7e4dc9d30ef205c10346
integration_basis: origin/main a69bf0214f7bd7e0537a1cdd07e95608e5a366e8
claim_boundary: exact-answer prefilter in macro_may_define_item_named (#9217 item 1); helper_transfer.rs test-module fixture retarget only; no helper-hop memoization; no reveal.rs edits
changed_surfaces_and_semantic_owners_inspected: analysis/classify/macro_item_names.rs (owner of MacroSites::scan / may_define); consumers file_imports_foreign_callee_name (reveal.rs:4638) and helper-hop callers via that gate; FileUseStatements still scans directly (ProbeContext memo path unchanged); helper_transfer.rs mod tests only; changelog.d fragment
blocking_findings: none on this head
non_blocking_suggestions: unparsed control uses SCAN_COUNT >= 1 rather than == 1; raw source.contains("macro_rules!") is a conservative extra scan vs the masked Unparsed path (answers stay exact)
refuted_or_stale_findings: gemini-code-assist and coderabbit comments are quota/rate-limit, not source findings (missing provider review, not a clean bot pass)
proof_and_ci_observed: local macro_item_names::tests 14/14 (two skip tests failed before the prefilter); scoped_import_answer_scans_once_per_distinct_query pass after fixture bang; other SCAN_COUNT pins pass; cargo clippy -p ripr --all-targets -- -D warnings pass; cargo xtask check-pr-shape pass on published body; cargo xtask precommit fail on inherited check-process-policy orphan for run_chain.rs grouped import (#12027), not this diff; goldens skipped
proof_or_review_missing: hosted Ripr Rust Small Result (not requested until Ready + merge-ready); ub-review / coderabbit / gemini quota; full workspace test matrix
affected_currentness_dimensions: production implementation, test stimulus, test oracle, public claim (changelog); integration basis unchanged; no goldens/conflicts
residual_assumptions_and_non_claims: skip is exact for parsed routes because every may_define path needs the name in text; Unparsed+macro_rules! remains undecided by not skipping when macro_rules! is present. Does not claim a measured wall-clock win, helper-hop site memoization, or runtime mutation outcomes.
disposition: REVIEW_INCOMPLETE for missing hosted qualification; no blocking source/oracle defect on this head. Eligible to leave Draft, mark Ready, and request merge-ready. Not REVIEW_READY for merge.
Authority
macro_may_define_item_named remains the helper-hop authority. ProbeContext still uses FileUseStatements::macro_sites → MacroSites::scan directly, so the skip does not change the memoized per-file path. Callers in reveal.rs / helper_transfer.rs production code are unchanged.
Oracle challenge
A name-only skip would still scan the bang-less entry fixture; a bang-only skip would still scan emit!(other) for entry. Both fail before the prefilter (SCAN_COUNT 1 and 2) and pass after (0). Positive emit!(entry) still scans once and answers true. Unparsed fn { macro_rules! ... with an absent name still answers true, so a wrong "name absent → false" skip is rejected. Existing #8467 controls unchanged.
Fixture retarget
#9086 scoped_import_answer_scans_once_per_distinct_query must keep measuring scan-once-per-distinct-query. The old bang-less source would now skip. Unused macro_rules! unused supplies ! without rebinding parse/other. Test-module only.
Zero inline threads. Quota bot comments are missing provider evidence.
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
merge-ready requested on frozen head Ready is review state; the No merge from this session. |
There was a problem hiding this comment.
Independent review (fresh-context reviewer, head ccd20e0): REVIEW_INCOMPLETE
First independent review on this PR. It is bound to the head below and rests on the source at that head and on the hosted checks at that head.
Inspected:
- Head
ccd20e0655dfadae757a7e4dc9d30ef205c10346; not draft;mergeable: MERGEABLE,mergeStateStatus: BLOCKED; no labels; title "perf(classify): skip macro-item parse when the exact answer is known (#9217)". Governed by issue #9217. - The candidate's whole change against the current main tip
a69bf0214f7bd7e0537a1cdd07e95608e5a366e8, which is also this branch's base, is 3 paths, +72/-1:changelog.d/9217-macro-item-name-prefilter.md(+5/-0, new),crates/ripr/src/analysis/classify/helper_transfer.rs(+9/-1) andcrates/ripr/src/analysis/classify/macro_item_names.rs(+58/-0). The change is confined to one function and its tests. - What the change does.
macro_may_define_item_named(source, name)gains three cheap checks before it reachesMacroSites::scan(source):if !source.contains('!') { return false; }; the queried name has itsr#prefix stripped and an empty name returnsfalse; andif !contains_as_whole_word(source, name) && !source.contains("macro_rules!") { return false; }. Everything else falls through to the originalMacroSites::scan(source).may_define(name). - I checked the shortcut for soundness rather than assuming it.
MacroSites::scan(crates/ripr/src/analysis/classify/macro_item_names.rs) parses the source withparse_clean_source_file; on a parse failure it returnsSelf::Unparsed { has_macro_rules: mask_comments_and_strings(source).contains("macro_rules!") }, andmay_defineon that variant returns*has_macro_rules— the undecided answer istrueexactly when the file is unparsable and holdsmacro_rules!. The prefilter's escape hatch is keyed on the same condition, so the undecided case still reaches the scan. The three checks are each sound for the same reason: a macro invocation requires a!in the text;may_define's argument-based paths (mentions_name,bare_item_argument,declares_in_arguments) all look for the name inside the invocation's arguments, which are part of the source, and the local-macro_rules!path can only make the answer true when the name appears in the definition's expansion text, which is also part of the source — so a name absent from the source text cannot makemay_definetrue. Ther#strip mirrors the one insidemay_define, so the two agree on raw identifiers. - One asymmetry worth recording, and it is in the safe direction:
scancomputeshas_macro_rulesover the comment-and-string-masked source, while the prefilter tests the raw source. A file whose onlymacro_rules!is inside a comment or a string therefore takes the slow path even though the masked answer isfalse. That is conservative — it costs a parse it could have skipped, and it cannot change an answer. - The oracle. Four new tests use a
#[cfg(test)]SCAN_COUNTthread-local thatMacroSites::scanincrements, and they pin the mechanism rather than a wall clock:a_source_without_bang_never_scans(a source with the name present but no!, so a name-only prefilter would still scan) asserts zero scans;an_absent_name_without_macro_rules_never_scans(a source with!but nomacro_rules!) asserts zero scans for bothentryandr#entry;a_present_name_still_scans_and_may_defineasserts one scan and atrueanswer;an_unparsed_macro_rules_file_still_scans_when_the_name_is_absentasserts the unparsablemacro_rules!case still scans. Observing the count of avoided parses is the right shape of proof for a performance change, and it discriminates — each test is constructed so that a weaker prefilter would still scan. - The delta also repairs an existing test whose premise the change silently broke.
helper_transfer.rs'sscoped_import_answer_scans_once_per_distinct_queryused a source with no!, so after the change it would have taken the fast path and no longer measured scan-once-per-distinct-query. The author added amacro_rules! unused { () => {}; }line to keep the bang and documented why, including the claim that the unused macro "does not rebindparseorother" — which holds, becausemay_define's local-definition branch is keyed on the invoked macro's name andunusedis never invoked. - The PR body's acceptance delta matches the implementation sentence for sentence: "
macro_may_define_item_namedreturns false without scanning when the source has no!, or when the callee name (withr#stripped) is absent as a whole word and the source has nomacro_rules!, while unparsedmacro_rules!files stay undecided and existing #8467 answers stay unchanged." - Hosted evidence at this head (54 contexts): the check rollup is PENDING — 14 SUCCESS, 33 SKIPPED, 1 NEUTRAL, and 6 still running (
ub-review,paste-macos-latestand four others). The required status checkRipr Rust Small Resultis absent, and every Rust lane isSKIPPED. The PR body records the same thing from its side: localcargo xtask precommitfails on an inheritedcheck-process-policyorphan inpolicy/process_allowlist.d/11720-first-pr-run-chain.txt, which the body attributes to #12021 / open #12027 and names as not-this-diff.
Blocking:
- None found. The shortcut is sound on all three of its branches, the oracle discriminates, the acceptance matches the implementation, and the one existing test whose premise the change invalidated was repaired with its reason recorded.
Non-blocking:
- The structural fix is available and this PR deliberately does not take it — and it says so, which is what makes this a note rather than a criticism.
crates/ripr/src/analysis/classify/reveal.rs:4696already reaches the same parse through a memo:.get_or_build(&file, || super::macro_item_names::MacroSites::scan(source)). The helper-hop path this PR optimizes reaches the sameMacroSites::scanthroughcrates/ripr/src/analysis/classify/context.rs:184(memo.macro_may_define_callee_name(file, source, callee)), which is where the repeated parse lives. So the repository already contains the structure that removes the parse once per file rather than once per query, in the same module family. The PR body says "Per-source memoization of sites on the helper-hop path is not in this PR", which is exactly the disclosure that makes this acceptable: the author has identified the follow-up, named it, and left it out of a change whose acceptance is a behavioural skip. Recording it because the next reader of this code will meet the same repetition and should know the memo shape exists. - The prefilter's own cost is O(source length) per query, and it is paid once per (file, callee) pair. Three substring scans over the source replace one parse, which is a large constant-factor win, but the scans are repeated for each queried callee name on the same file — so a file with many callee names pays many scans and, when any name is present, still pays a parse per query. Both costs are bounded and strictly smaller than what they replace, so this is a net win by construction; it is only a note that "skip the parse" and "do the parse once" are different improvements, and only the first is in this PR.
- No measurement is published, and for this acceptance that is defensible. The change's acceptance is behavioural — the scan must not happen when the answer is known — and the oracle proves it by counting scans, which is stronger evidence than a timing delta. What is missing is the size of the prize: no figure says how many parses a real classification run performs, or what fraction this removes. A one-line note in the changelog fragment or the body ("the helper-hop path re-parses per callee name; on the corpus this removed N parses of M") would tell a reader whether the change matters in practice without needing a benchmark. The fragment currently states the mechanism only.
- Efficiency — the change removes the most expensive operation it can.
MacroSites::scancallsparse_clean_source_file, a full parse of the file; the prefilter replaces it with substring searches that cannot exceed the parse by more than a constant factor. There is no new I/O, no process spawn, no cache with an invalidation obligation, no unbounded collection, and no allocation added on the analysis path — the scan counter is#[cfg(test)]gated insidescanitself, so the release binary pays nothing for the instrumentation. The changelog fragment and the code agree that the answers do not change, and the unparsed-macro_rules!carve-out is the one place where they could have, so it is worth noting that the carve-out is exactly where the code and the fragment both say so. - The
has_macro_rulesasymmetry costs a parse in a rare case. A file whose onlymacro_rules!sits inside a comment or a string takes the slow path even though the masked answer isfalse. Matching the prefilter toscanhere — masking the source once and reusing it for both checks — would recover that parse, at the cost of one masked copy per query. At the rarity of the case, I would not make that change; recording it so the asymmetry is not mistaken for an oversight if someone reads the twomacro_rules!tests side by side.
Not run:
- The Rust toolchain on this host is not on
PATH, so there was no local build, nocargo xtask precommit, no local test run, and no way to execute the new tests here. Every Rust-level statement above comes from the hosted check list at this exact head or from reading source at this exact SHA. - The hosted Rust phase is unobserved at this head, not green: every Rust lane is
SKIPPED, the required checkRipr Rust Small Resultis absent, and six contexts were still running when I read them. This review does not rest on the Rust phase and does not claim it passed. - The new scan-counting tests have not executed at this head. My reading that the shortcut is sound and that each test discriminates is from the source and from the tests' own assertions, not from an observed run; in particular, the claim that the shortcut cannot change an answer rests on the relationship between
may_define's argument-based paths and the presence of the name in the source text, which I derived by reading rather than by executing both sides. - I did not reproduce the parse-count reduction on a real corpus; I did not run any classification.
Reviewed by an independent Mavis review agent on behalf of the maintainer; bound to head ccd20e0655dfadae757a7e4dc9d30ef205c10346. Not an approval.
|
ccd20e0 hosted reds were inherited, not this unique delta.
GitHub merged Waiting for |
EffortlessSteven
left a comment
There was a problem hiding this comment.
review-pr (author self-review COMMENT) — integration-basis refresh only
GitHub cannot request-changes from the author. This is not an approval.
reviewed_head_sha: 8c9710c1a7905fe775962e1be640577757d96cd8
integration_basis: origin/main 99b2e4d08e5dbed103d661e89cf1c6fabb6a7b62 (#11995)
claim_boundary: exact-answer prefilter in macro_may_define_item_named (#9217 item 1); helper_transfer.rs test-module fixture retarget only; no helper-hop memoization; no reveal.rs edits
changed_surfaces_and_semantic_owners_inspected: unique delta vs new main is the same 3 paths as ccd20e0655 (+72/-1): macro_item_names.rs, helper_transfer.rs tests only, changelog fragment. Production/test/oracle/public-claim dimensions unchanged from the ccd20e0655 source review.
blocking_findings: none on this head
non_blocking_suggestions: unchanged from ccd20e0655 review (conservative raw contains("macro_rules!"); SCAN_COUNT >= 1 on unparsed control)
refuted_or_stale_findings: ccd20e0655 hosted reds classified inherited (process-policy orphan landed via #11995; LSP/selector/worktree tests were main-red shards). Quota bot comments remain missing provider review, not a clean bot pass. Zero inline threads.
proof_and_ci_observed: unique files identical to the reviewed ccd20e0655 unique delta. merge-ready request in flight for this exact head (actions/runs/41269301992); Ripr Rust Small on GitHub Hosted / Rust gates in_progress; Ripr Rust Small Result not yet terminal.
proof_or_review_missing: hosted Ripr Rust Small Result on 8c9710c1; ub-review / coderabbit / gemini quota
affected_currentness_dimensions: integration basis only (GitHub merged main #11995). Production implementation, test stimulus, test oracle, public claim, generated relationships unchanged. No conflict resolution in the unique delta.
residual_assumptions_and_non_claims: same as ccd20e0655: skip is exact for parsed routes; Unparsed+macro_rules! remains undecided. Does not claim a measured wall-clock win, helper-hop site memoization, or runtime mutation outcomes.
disposition: REVIEW_INCOMPLETE for missing hosted qualification on this exact head; no blocking source/oracle defect. Not REVIEW_READY for merge. Do not re-apply merge-ready while the current-subject run is in flight. No merge from this session.
Independent review 5726184907 remains valid for the unique source/oracle at ccd20e0655; this head only adds the GitHub merge of main. Refresh is integration-basis only.
There was a problem hiding this comment.
Verification questions
- Confirm the cheap prefilter preserves the parsed-answer route: no bang returns false, an empty raw identifier returns false, and absent names still scan when macro_rules! is present.
- Confirm focused behavioral coverage exists for both skip paths and both scan paths, including raw identifiers and unparsable macro_rules! input.
- Confirm the two new skip tests are red/green-sensitive to the production prefilter, but no broad differential test proves prefilter equivalence to the parsed classifier across varied Rust syntax.
- Confirm the runtime-helper scan did not establish absence of every equivalent macro-item textual prefilter elsewhere, so repository-wide call-site coverage remains needed.
- Confirm the helper_transfer change is test-only and preserves the scan-once-per-distinct-query pin by adding a bang and unused macro_rules! without changing production routing.
Refuted
- No worker, async, GC, detach, or transfer boundary is touched by the diff.
Evidence gaps
- Broader public route coverage remains incomplete because the ripr sensor failed and cargo-test receipt is absent; this lane cannot independently validate all affected callers.
- The absent cargo-test receipt leaves runtime validation of the new prefilter pins unresolved.
- The late cargo-test receipt remains absent, so the advertised Rust behavior proof is not independently completed in this review packet.
- The source-UB sensor did not complete successfully, so the added behavioral tests have not been confirmed by the supplied sensor packet.
- Model proof intent was rejected by deterministic validation.
- Full semantic equivalence is not independently proven because cargo-test evidence was absent and ripr exited with code 2.
|
Qualification on frozen head
Unique delta vs main is still the three files. In-place |
|
Re-requested qualification on frozen head |
|
Review of record, head Inspected: full diff (3 files), semantic owner Findings: none. Generated by Claude Code |
Summary
Skip
MacroSites::scan/parse_clean_source_fileinmacro_may_define_item_namedwhen the exact answer is already known from cheap text checks. Classification answers stay the same; helper-hop callers keep using this function. Per-source memoization of sites on the helper-hop path is not in this PR.Advances #9217
Swarm / Source Boundary
This PR targets
EffortlessMetrics/ripr-swarm, the normal development trunk fortrusted same-repo
riprwork. Confirm the change belongs here:dependency, or repo-ops development for
ripr-swarmsurface
If this PR moves crates.io publishing, VS Marketplace publishing, Open VSX
publishing, GitHub Release assets, signing, release environments, or release
secrets, close or retarget it. Those surfaces belong in
EffortlessMetrics/riprunless a dedicated release-boundary change has already been approved.
Source-of-truth Links
Proposal: none
Spec: none (perf skip of an existing exact answer; #8467 controls stay)
ADR: none
Plan item: none
Governing issue or accepted claim: #9217
Acceptance delta (one sentence):
macro_may_define_item_namedreturns false without scanning when the source has no!, or when the callee name (withr#stripped) is absent as a whole word and the source has nomacro_rules!, while unparsedmacro_rules!files stay undecided and existing #8467 answers stay unchanged.Candidate Relationships
Candidate branch (GitHub PR head is authoritative after publication):
cursor/9217-macro-item-name-prefilter-67b5Stack parent or prerequisite PR (if any): none for this delta. GitHub merged
origin/main99b2e4d08e(#11995) into this PR; that landing removed the inheritedcheck-process-policyorphan that had failed local precommit and hosted Rust gates onccd20e0655. Unique delta vs current main is unchanged (three files).Proposed replacement of PR (if any; not yet accepted): none
Acceptance retained from a replaced candidate (if any): none
Accepted winner and losing candidate disposition (when decided): none; needs no reconciliation
Name a stack or proposed replacement explicitly. A proposed replacement does
not make its predecessor superseded. Shared files or a shared parent issue
alone do not establish duplication. If the relationship is unknown, record it
as needing reconciliation before disposing of either PR.
Scope
Exact-answer prefilter in
macro_may_define_item_named, plus a test-only retarget of the #9086 SCAN_COUNT pin so it still measures scan-once-per-distinct-query after the skip.Scope Classification
This PR is scoped by:
Production delta:
macro_may_define_item_namedreturnsfalsewithoutMacroSites::scanwhensourcecontains no!.r#, an empty name returnsfalsewithout scanning (same asmay_define).sourceandsourcehas nomacro_rules!, returnfalsewithout scanning.may_defineas before. An unparsable file that holdsmacro_rules!still answers true (undecided).Evidence/support delta:
!but nomacro_rules!; one scan and true whenemit!(entry)names the callee; unparsedmacro_rules!still scans and stays undecided.fn namein arguments, passthrough macros and some use forms #8467 controls unchanged.helper_transfer.rstest module only:scoped_import_answer_scans_once_per_distinct_querypreviously used a bang-less source, so the new no-!skip madeSCAN_COUNTstay 0 and broke the work-unit pin. The fixture now includes an unusedmacro_rules! unused { () => {}; }so the pin still measures scan-once-per-distinct-query (1 then 1 then 2 then 3). Boolean import answers are unchanged; the unused macro does not rebindparseorother. No production edits tohelper_transfer.rs.Single acceptance criterion:
!.Non-goals:
MacroSiteson the helper-hop path (file_imports_foreign_callee_name/reveal.rs).reveal.rsorhelper_transfer.rs.Support-tier Impact
docs/status/SUPPORT_TIERS.mdClaim/proof notes:
Changedperformance note.Policy Impact
Ledger or exception notes:
check-process-policyfailure was inherited (fix(policy): drop orphaned run_chain import entry (#12021) #12027) and is no longer in the unique delta after GitHub merged main fix: repair main after #11950 (verdict-corpus expected rows) #11995.Proof
Result, failures, or skipped proof:
macro_item_names::tests: 14 passed (including four new perf(reveal): macro_may_define_item_named parses the test source per (probe, test, callee) with no prefilter; about 16% of classification worker time #9217 pins and existing macro_item_names: macro-defined owner name still missed forfn namein arguments, passthrough macros and some use forms #8467 controls). Before the prefilter, the two skip tests failed with SCAN_COUNT 1 and 2.scoped_import_answer_scans_once_per_distinct_query: pass after fixture retarget.-p ripr --all-targets -- -D warnings: pass.cargo xtask precommit: fail on inheritedcheck-process-policyorphaned allowlist entry forcrates/ripr/src/output/first_pr/run_chain.rs/use std::process::Command(file uses a grouped import). Not in this diff. That orphan landed on main via fix: repair main after #11950 (verdict-corpus expected rows) #11995; hosted qualification is the merge-ready request on8c9710c1. Policy/fmt/changelog-fragments and the rest of the run that executed before that gate passed. Clippy was skipped by precommit because policy failed first; ran separately as above.Ripr Rust Small Result, or helper-hop memoization.Claim Boundary
What may be claimed after this PR? What must not be claimed yet?
macro_may_define_item_namedskips the parse when the exact answer is already false; SCAN_COUNT pins that skip; perf: ripr check takes 400s+ on a 165-line diff (petgraph); pair of files 37s while each alone is <0.3s #9086 still pins one scan per distinct query on a source that contains!.ripr check; that hosted qualification already passed; thatkilled/survivedmutation results follow from this skip.Rollback
How can this PR be reverted safely?
Revert the commit. Answers return to always-scan; the #9086 fixture bang is only needed while the skip exists.
Spec-Test-Code Traceability
fn namein arguments, passthrough macros and some use forms #8467 controls remain the semantic regression setmacro_item_names::tests::{a_source_without_bang_never_scans, an_absent_name_without_macro_rules_never_scans, a_present_name_still_scans_and_may_define, an_unparsed_macro_rules_file_still_scans_when_the_name_is_absent};helper_transfer::tests::scoped_import_answer_scans_once_per_distinct_querymacro_may_define_item_namedincrates/ripr/src/analysis/classify/macro_item_names.rsStatic Language Check
killed,survived,untested,proven, andadequate.CI Economics
Engineering Check
panic,unwrap,expect,todo, orunimplementedin production code.panic,unwrap,expect,todo, orunimplementedin tests.Gates
Local: fmt (via precommit), package Clippy, focused tests as above. Full workspace test/clippy/doc/package not rerun locally. Hosted
Ripr Rust Small Resultis the qualification request after Ready +merge-ready. Current-subject run is in flight on adopted head8c9710c1; do not re-applymerge-ready.Exact candidate SHA at publication:
ccd20e0655dfadae757a7e4dc9d30ef205c10346Adopted exact head after GitHub merge of main:
8c9710c1a7905fe775962e1be640577757d96cd8