Skip to content

Add caching layer to bootstrap #142816

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

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

Shourya742
Copy link
Contributor

This PR adds a caching layer to the bootstrap command execution context. It is still a work in progress but introduces the initial infrastructure for it.

r? @Kobzol

@rustbot rustbot added the T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) label Jun 21, 2025
Copy link
Contributor

@Kobzol Kobzol left a comment

Choose a reason for hiding this comment

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

Awesome! I haven't checked the code yet, but once you get it working, it would be great to see some benchmarks. Ideally of "no-op" commands, like running x check rustc after no change has been made to the compiler.

@rust-log-analyzer

This comment has been minimized.

@Shourya742 Shourya742 requested a review from Kobzol June 24, 2025 05:43
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 24, 2025
Copy link
Contributor

@Kobzol Kobzol left a comment

Choose a reason for hiding this comment

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

It seems like you misunderstood what I meant and went in a different direction, sorry :) I tried to clarify in comments.

@Shourya742 Shourya742 force-pushed the 2025-06-21-add-caching-layer-to-bootstrap branch from cf6a2c5 to cd9224f Compare June 24, 2025 11:57
Copy link
Contributor

@Kobzol Kobzol left a comment

Choose a reason for hiding this comment

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

I forgot that std::process::Command now provides a way to return all the inner state regarding arguments, env. variables, program and workdir. In that case, we don't need to store the cache key at all, and we can just reconstruct it from the inner std Command right before executing the bootstrap command.

@Shourya742 Shourya742 force-pushed the 2025-06-21-add-caching-layer-to-bootstrap branch from 0f9af82 to 043d094 Compare June 24, 2025 15:47
@Shourya742 Shourya742 marked this pull request as ready for review June 24, 2025 15:54
@rust-log-analyzer

This comment has been minimized.

@Shourya742 Shourya742 force-pushed the 2025-06-21-add-caching-layer-to-bootstrap branch from 043d094 to 821d695 Compare June 24, 2025 16:18
@Shourya742 Shourya742 requested a review from Kobzol June 24, 2025 16:20
@rust-log-analyzer

This comment has been minimized.

@Shourya742 Shourya742 force-pushed the 2025-06-21-add-caching-layer-to-bootstrap branch from 821d695 to f40c002 Compare June 24, 2025 16:46
@rust-log-analyzer

This comment has been minimized.

@Kobzol
Copy link
Contributor

Kobzol commented Jun 24, 2025

Seems like some cache hits are being encountered, that's good. Later it would be nice to also record the durations of individual commands and then print some statistics at the end, which commands took the longest to execute, how many cache hits/misses they had etc.

@Shourya742 Shourya742 force-pushed the 2025-06-21-add-caching-layer-to-bootstrap branch from f40c002 to 5735674 Compare June 24, 2025 17:14
@Kobzol
Copy link
Contributor

Kobzol commented Jun 24, 2025

Code looks good now, but before we merge it, I think that we should go through existing commands and make sure that it won't be problematic to cache them. I'll go through bootstrap tomorrow and check.

It would also be useful to add a comment on top of BootstrapCommand that explains that by default, command executions are cached if they have the same workdir/program/args/envs.

@Shourya742
Copy link
Contributor Author

Shourya742 commented Jun 24, 2025

Code looks good now, but before we merge it, I think that we should go through existing commands and make sure that it won't be problematic to cache them. I'll go through bootstrap tomorrow and check.

It would also be useful to add a comment on top of BootstrapCommand that explains that by default, command executions are cached if they have the same workdir/program/args/envs.

I will add that.. added here: a5df236

@rust-log-analyzer

This comment has been minimized.

@Shourya742 Shourya742 force-pushed the 2025-06-21-add-caching-layer-to-bootstrap branch from a5df236 to bebe11d Compare June 24, 2025 17:58
@Shourya742 Shourya742 requested a review from Kobzol June 24, 2025 19:23
@Kobzol Kobzol mentioned this pull request Jun 25, 2025
@Kobzol
Copy link
Contributor

Kobzol commented Jun 25, 2025

Just to be sure, use do_not_cache on the command created in the bare_cargo function, to make sure that we don't ever cache cargo.

Also, it's a big edge case, but calling as_command_mut in ExecutionContext::start disables the caching of the command. Since our API allows executing the same command twice (although we don't currently do it anywhere, AFAIK), it could be cached in the first execution, and then not cached in the other executions, which is confusing. So it would be better if the execution context didn't call the function and just accessed the inner command directly. At the same time, I noticed that we have both exec.rs and execution_context.rs, which is a bit duplicated, both the command and the execution context belong together. So I would suggest moving the execution context to the exec.rs file (and remove execution_context.rs), which will also allow the context to access the inner std command without going through the as_command_mut function.

@Shourya742
Copy link
Contributor Author

Shourya742 commented Jun 25, 2025

Oops

@rustbot
Copy link
Collaborator

rustbot commented Jun 25, 2025

This PR modifies src/bootstrap/src/core/config.

If appropriate, please update CONFIG_CHANGE_HISTORY in src/bootstrap/src/utils/change_tracker.rs.

@Kobzol
Copy link
Contributor

Kobzol commented Jun 25, 2025

Thank you! Please squash the commits and I'll approve the PR. We'll see how it works in practice.

@Shourya742 Shourya742 force-pushed the 2025-06-21-add-caching-layer-to-bootstrap branch from ede9cb4 to b7ad1eb Compare June 25, 2025 15:52
@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) A-rustdoc-json Area: Rustdoc JSON backend A-rustdoc-search Area: Rustdoc's search feature A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. labels Jun 25, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jun 25, 2025

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri

Some changes occurred in compiler/rustc_passes/src/check_attr.rs

cc @jdonszelmann

rustc_errors::translation was changed

cc @davidtwco, @compiler-errors, @TaKO8Ki

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann

rustc_error_messages was changed

cc @davidtwco, @compiler-errors, @TaKO8Ki

Some changes occurred in compiler/rustc_codegen_ssa

cc @WaffleLapkin

rustdoc-json-types is a public (although nightly-only) API. If possible, consider changing src/librustdoc/json/conversions.rs; otherwise, make sure you bump the FORMAT_VERSION constant.

cc @CraftSpider, @aDotInTheVoid, @Enselic, @obi1kenobi

Some changes occurred in src/tools/rustfmt

cc @rust-lang/rustfmt

Some changes occurred in compiler/rustc_attr_data_structures

cc @jdonszelmann

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

Some changes occurred in compiler/rustc_codegen_ssa/src/codegen_attrs.rs

cc @jdonszelmann

Some changes occurred in HTML/CSS/JS.

cc @GuillaumeGomez, @jsha, @lolbinarycat

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

@Shourya742 Shourya742 force-pushed the 2025-06-21-add-caching-layer-to-bootstrap branch from b7ad1eb to ec765c3 Compare June 25, 2025 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-rustdoc-json Area: Rustdoc JSON backend A-rustdoc-search Area: Rustdoc's search feature A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants