Skip to content

Rust: Make crate fallback logic more conservative in path resolution library - #22495

Open
hvitved wants to merge 3 commits into
github:mainfrom
hvitved:rust/path-resolution-crate-fallback-uniqueness
Open

Rust: Make crate fallback logic more conservative in path resolution library#22495
hvitved wants to merge 3 commits into
github:mainfrom
hvitved:rust/path-resolution-crate-fallback-uniqueness

Conversation

@hvitved

@hvitved hvitved commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

When doing a QA run for #21795, I noticed that our fallback logic for crate dependencies can sometimes lead to combinatorial explosions. This PR alleviates this by only applying the fallback logic to crates that have a unique latest version. DCA confirms that this PR resolves the performance issue, most notably on the reflaxe-rust project, where the hxrt crate exists in many test copies (e.g. https://github.com/fullofcaffeine/reflaxe.rust/blob/main/test/snapshot/abstracts_conversions/intended/hxrt/Cargo.toml).

@github-actions github-actions Bot added the Rust Pull requests that update Rust code label Sep 2, 2026
@hvitved
hvitved force-pushed the rust/path-resolution-crate-fallback-uniqueness branch from e35d861 to 1925c20 Compare September 3, 2026 07:06
@hvitved hvitved added the no-change-note-required This PR does not need a change note label Sep 3, 2026
@hvitved
hvitved marked this pull request as ready for review September 3, 2026 10:49
@hvitved
hvitved requested a review from a team as a code owner September 3, 2026 10:49
@hvitved
hvitved requested review from paldepind and a balanced review from Copilot September 3, 2026 10:49

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.

Copilot review overview

🟡 Changes recommended

Raw string ordering can select the wrong semantic version, and the uniqueness behavior lacks regression coverage.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review tier: Balanced
Findings: 1 Medium severity · 1 Low severity

New issues introduced by this change (2)
Severity Finding
Medium severity rust/​ql/​lib/​codeql/​rust/​internal/​PathResolution.qllver is a raw Cargo version string, so this ordering is lexicographic rather than semantic: for…
Low severity rust/​ql/​lib/​codeql/​rust/​internal/​PathResolution.qll — The existing path-resolution fixture does not contain multiple extracted crate entities sharing the…
What changed in this PR

Restricts Rust crate dependency fallback to a uniquely identified latest crate version, reducing path-resolution explosions.

Changes:

  • Selects the latest crate version for fallback resolution.
  • Adds debugging support for crate dependency edges.
File Description
rust/​ql/​lib/​codeql/​rust/​internal/​PathResolution.qll Narrows crate fallback resolution and adds debugging support.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread rust/ql/lib/codeql/rust/internal/PathResolution.qll
Comment thread rust/ql/lib/codeql/rust/internal/PathResolution.qll
@hvitved
hvitved requested review from a team as code owners September 3, 2026 11:06
@hvitved
hvitved force-pushed the rust/path-resolution-crate-fallback-uniqueness branch from d432cd5 to 52e2c72 Compare September 3, 2026 11:08
Comment thread shared/util/codeql/util/SemVer.qll Fixed

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

Looks good to me. Two small comments.

Huge speedup on reflaxe-rust. Some of the metrics that we usually like going up are going down. That's to be expected, but I wonder if, for the non-unique crates, it could make sense to pick one of them based on some arbitrary but stable thing (that's not the version)?

Comment thread shared/util/codeql/util/SemVer.qll Outdated
* Pre-release information and build metadata is not yet supported.
*/
bindingset[orig]
string normalizeSemVer(string orig) {

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.

The name "normalize" made me initially think this was something about turning 1.023.0 into 1.23.0. But it's not really about normalizing, it's about padding to make make lexicographic order coincide with semver order. What about calling it padSemVer?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I just kept the name as-is from Go/JS (except I changed casing).

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.

Yes, but we can still change it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

OK, I'll change it ;-)

@hvitved hvitved Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. I also realized that Ruby had its own (more tolerant) implementation, which is now in the shared library.

Comment thread shared/util/codeql/util/SemVer.qll Outdated
module;

bindingset[str]
private string leftPad(string str) { result = ("000" + str).suffix(str.length()) }

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.

I've seen quite a few version components in Rust at tripple digits. Maybe throw in one more 0 for good measure?

@hvitved

hvitved commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

That's to be expected, but I wonder if, for the non-unique crates, it could make sense to pick one of them based on some arbitrary but stable thing (that's not the version)

It might make sense to do something based on the folder structure, but I'd prefer to get this in now, and then we can do it later if needed.

@hvitved
hvitved force-pushed the rust/path-resolution-crate-fallback-uniqueness branch from 52e2c72 to 9207c4b Compare September 3, 2026 12:46
@hvitved
hvitved requested a review from paldepind September 3, 2026 12:46
Comment thread shared/util/codeql/util/SemVer.qll Fixed
@hvitved
hvitved requested a review from a team as a code owner September 3, 2026 13:41
@github-actions github-actions Bot added the Ruby label Sep 3, 2026
module;

bindingset[str]
private string leftPad(string str) { result = ("0000" + str).suffix(str.length()) }
paldepind
paldepind previously approved these changes Sep 3, 2026

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

Nice to get the Ruby version de-duplicated as well 😎

@hvitved
hvitved force-pushed the rust/path-resolution-crate-fallback-uniqueness branch from f645ecc to df7d49d Compare September 3, 2026 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Go JS no-change-note-required This PR does not need a change note Ruby Rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants