Skip to content

Rust: Reduce semantic queries during extraction - #23323

Open
redsun82 wants to merge 2 commits into
mainfrom
redsun82-supreme-invention
Open

redsun82 wants to merge 2 commits into
mainfrom
redsun82-supreme-invention

Conversation

@redsun82

@redsun82 redsun82 commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: fe2a07d1ae04455df440ff9b6bfa4d05d4b62d19

Dimension Assessment Rationale
Change confidence 8.5/10 ↑ All 177 extractor tests plus path-resolution, variables, diagnostics, unusedentities, CWE-696 and web_frameworks tests pass locally.
↑ Mutation checks: dropping in_expansion breaks macro-expansion/macro-in-library; an outer-attributes-only guard breaks the new inner-attribute test.
↑ 8/8 fact-parity queries identical on a ripgrep DB.
↓ PR CI not yet observed.
↓ Future expansion call sites rely on documentation, not a lint.

First layer of an extractor performance stack. Cuts rust-analyzer semantic queries in translate/base.rs:

  • Nodes outside macro expansions use their syntax range directly; Semantics::original_range is only used inside in_expansion (include, nested, attribute and built-in derive mapping unchanged).
  • Items without any (outer or inner) attribute skip the costly attribute-macro check.
  • item_post_emit reuses the decision made in item_pre_emit instead of querying again.

Also adds a Copilot instruction for the in_expansion invariant and a test for an attribute macro used as an inner attribute.

On a noisy local ripgrep DB create (8 threads, 2 runs each) this layer took ~98s vs ~101–109s on main.

Paolo Tranquilli and others added 2 commits December 2, 2026 09:34
Use a node's own text range outside macro expansions, skip the attribute
macro check for items without attributes, and reuse the pre-emit decision
in `item_post_emit`.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b98227f5d3a24d73abe15df037acd68e
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b98227f5d3a24d73abe15df037acd68e
Copilot AI adaptive review requested due to automatic review settings December 2, 2026 11:12
@redsun82
redsun82 requested review from a team as code owners December 2, 2026 11:12

Copilot AI 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.

🔵 Needs a closer look

The source-location fast path changes extractor-wide provenance invariants across nested macro, include, attribute, and derive expansions, requiring human review of their interactions.

No open issues 🎉

What changed in this PR

Reduces rust-analyzer semantic queries in the Rust extractor while preserving macro-expansion location handling.

Changes:

  • Uses syntax ranges outside expansions and avoids redundant attribute-macro checks.
  • Adds regression coverage for inner-attribute macros.
  • Documents the expansion-emission invariant.
File Description
rust/​ql/​test/​extractor-tests/​macro-expansion-inner-attribute/​test.ql Queries attribute-macro expansion results.
rust/​ql/​test/​extractor-tests/​macro-expansion-inner-attribute/​test.expected Records expected expansion results and locations.
rust/​ql/​test/​extractor-tests/​macro-expansion-inner-attribute/​proc_macro.rs Defines the test attribute macro.
rust/​ql/​test/​extractor-tests/​macro-expansion-inner-attribute/​options.yml Disables Cargo checking for the nightly-only syntax.
rust/​ql/​test/​extractor-tests/​macro-expansion-inner-attribute/​inner.rs Exercises an inner-attribute macro.
rust/​ql/​test/​extractor-tests/​macro-expansion-inner-attribute/​Cargo.lock Locks test dependencies.
rust/​extractor/​src/​translate/​base.rs Tracks expansion context and reuses attribute-macro decisions.
.github/​instructions/​rust-extractor.instructions.md Documents safe emission of expanded syntax.

Review effort: Balanced (adaptive)

@github-actions github-actions Bot added the Rust Pull requests that update Rust code label Dec 2, 2026
@redsun82
redsun82 added this pull request to stack #23336 December 2, 2026 16:58

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants