Skip to content

Rust: Allow for crate self-references in crate graph paths#19265

Merged
hvitved merged 1 commit intogithub:mainfrom
hvitved:rust/crate-graph-self-crate-ref
Apr 9, 2025
Merged

Rust: Allow for crate self-references in crate graph paths#19265
hvitved merged 1 commit intogithub:mainfrom
hvitved:rust/crate-graph-self-crate-ref

Conversation

@hvitved
Copy link
Copy Markdown
Contributor

@hvitved hvitved commented Apr 9, 2025

The extractor produces fully crate-qualified paths for entities extracted from the crate graph, which our path resolution logic handles. However, for entities where the crate-qualifier refers to the defining crate itself, the extractor should have used the special crate qualifier instead of the name of the crate.

For example, the impl<T> Option<T> block is extracted as impl<T> core::option::Option<T> instead of impl<T> crate::option::Option<T>.

This PR adjusts our path resolution logic to also handle crate self-references like above, but restricted to entities from the crate graph.

DCA shows that, while we maintain performance, we reduce the number of unresolved call targets by 16 % (down 1,699,468 from 2,012,848), all numbers computed across the entire DCA suite.

cc @aibaars

@github-actions github-actions Bot added the Rust Pull requests that update Rust code label Apr 9, 2025
@hvitved hvitved marked this pull request as ready for review April 9, 2025 18:38
Copilot AI review requested due to automatic review settings April 9, 2025 18:38
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot wasn't able to review any files in this pull request.

Files not reviewed (1)
  • rust/ql/lib/codeql/rust/internal/PathResolution.qll: Language not supported

@hvitved hvitved requested a review from aibaars April 9, 2025 18:38
Copy link
Copy Markdown
Contributor

@aibaars aibaars left a comment

Choose a reason for hiding this comment

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

Looks good to me, although I should probably improve the crate graph extractor to do the right thing at some point.

@hvitved hvitved merged commit 0e31bf1 into github:main Apr 9, 2025
16 checks passed
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.

3 participants