Skip to content

rustc: avoid path dependent queries in source presence checks - #165837

Closed
yawnbo wants to merge 2 commits into
rust-lang:mainfrom
yawnbo:main
Closed

yawnbo wants to merge 2 commits into
rust-lang:mainfrom
yawnbo:main

Conversation

@yawnbo

@yawnbo yawnbo commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

debugger visualizer lookups executed a query to used_crate_source as an rlib or rmeta spot check, creating a path dependent fingerprint that would invalidate CGUs if the artifacts were moved to different canonical paths. (frequently occurring during sandboxed build runs)

Instead, we return bitflags describing the presence of source fields from a CrateSource and update other relevant callers of used_crate_source to instead consume CrateSourceFlags.

LLM disclosure: I used an LLM to find the cause of this bug while debugging sandboxed builds. Commits are handwritten and LLM reviewed.

@rustbot rustbot added A-run-make Area: port run-make Makefiles to rmake.rs S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 12, 2026
@rustbot

rustbot commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust Project has assigned @petrochenkov (or someone else) to review your changes, you should hear from them (or someone else) within the next two weeks.

Please see the contribution instructions and our LLM policy for more information.

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 79 candidates
  • Random selection from 20 candidates

@Kobzol

Kobzol commented Nov 12, 2026

Copy link
Copy Markdown
Member

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Nov 12, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Nov 12, 2026
codegen: avoid CGU invalidation in path dependent debugger visualizer lookup
@rust-bors

rust-bors Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 1fe7323 (1fe73232b210bf52f3bcbbd9c6a46682c4980b3f)
Base parent: 6b05f82 (6b05f82b4f2d1309cdbddece388c9e4d26f481fc)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown

Finished benchmarking commit (1fe7323): comparison URL.

Overall result: ❌ regressions - no action needed

Benchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up.

@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.2% [0.2%, 0.2%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (primary -2.5%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-2.5% [-2.6%, -2.4%] 2
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -2.5% [-2.6%, -2.4%] 2

Cycles

This perf run didn't have relevant results for this metric.

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 484.187s -> 483.785s (-0.08%)
Artifact size: 406.04 MiB -> 406.07 MiB (0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Nov 12, 2026
@petrochenkov

Copy link
Copy Markdown
Contributor

It would generally more useful to add a structure like

struct CrateSourceFlags {
    dylib: bool,
    rlib: bool,
    rmeta: bool,
    sdylib_interface: bool,
}

and a query that returns it.
(Alternatively, bitflags! could be used instead of a structure.)

Then most uses of query used_crate_source could be replaces with this new query.

The query or the struct also need to have a comment explaining that it is used to avoid introducing dependency on specific absolute paths.
@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 12, 2026
@rustbot

rustbot commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@yawnbo

yawnbo commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for reviewing, i'll add comments in the test file and throughout the broader impl. However, I'm also curious about the proposed impl, would directly returning this query have some edge cases on invalidation? I would assume that cases where this actually happens would be very rare, but maybe some combination of --emit=metadata,link and future --emit=obj?

i'll start work on this tomorrow, but i'll probably look more into going down the route of querying with the desired bitflags and keeping the returned value a single bool. Thoughts on going this way?

@petrochenkov

Copy link
Copy Markdown
Contributor

I suggest not to over-complicate things, the scenario that the change intends to address is avoiding rebuilds when moving the project between directories, not avoiding rebuilds after some exceedingly rare changes in compiler flags.

@rustbot

rustbot commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator

These commits modify the Cargo.lock file. Unintentional changes to Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

@yawnbo yawnbo changed the title codegen: avoid CGU invalidation in path dependent debugger visualizer lookup rustc: avoid path dependent queries in source presense checks Nov 13, 2026
@yawnbo yawnbo changed the title rustc: avoid path dependent queries in source presense checks rustc: avoid path dependent queries in source presence checks Nov 13, 2026
@yawnbo

yawnbo commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

I think all relevant callers of used_crate_source have been replaced with the proposed bitflags.

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 13, 2026
@petrochenkov

Copy link
Copy Markdown
Contributor

r=me after addressing #165837 (comment) and squashing commits.
@rustbot author

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 16, 2026
@rustbot rustbot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Nov 16, 2026
bors and others added 2 commits November 16, 2026 11:25
…nathanBrouwer

Rollup of 6 pull requests

Successful merges:

 - rust-lang#165805 (Replace `match_span_kind` macro with `SpanKind`)
 - rust-lang#165746 (std: don't overflow when rounding up huge thread stack sizes on unix)
 - rust-lang#165807 (Fix 'simga' typo in char.to_lowercase documentation)
 - rust-lang#165809 (Update to ar_archive_writer 0.5.5)
 - rust-lang#165812 (Remove `-Z stack-protector=basic`)
 - rust-lang#165815 (Adjust `unsized.rs` debuginfo test expected output for cdb `10.0.28000.2957`)

codegen: avoid CGU invalidation in path dependent debugger visualizer lookup
@yawnbo yawnbo closed this Nov 16, 2026
@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-run-make Area: port run-make Makefiles to rmake.rs T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants