Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 9, 2025

Conversation

hvitved
Copy link
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 Copilot AI review requested due to automatic review settings April 9, 2025 18:38
Copy link
Contributor

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

2 participants