Skip to content

Enforce in bootstrap that check must have stage at least 1 #143048

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 16 commits into from
Jul 7, 2025

Conversation

Kobzol
Copy link
Member

@Kobzol Kobzol commented Jun 26, 2025

This PR is another step towards https://rust-lang.zulipchat.com/#narrow/channel/326414-t-infra.2Fbootstrap/topic/Proposal.20to.20cleanup.20stages.20and.20steps.20after.20the.20redesign/with/523586917, this time dealing with x check.

It enforces the invariant that:

  • We check std stage N with rustc stage N
  • We check everything else stage N with rustc stage N - 1

It creates a single function that prepares a proper build compiler for checking something, and also adds snapshot tests for various common check steps. Some obsolete code was also removed.

The default check stage also becomes 1, for all profiles. I tested manually that x check std with download-ci-rustc still works and doesn't build rustc locally.

Closes: #139170

r? @ghost

@rustbot rustbot added A-testsuite Area: The testsuite used to check the correctness of rustc T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue. labels Jun 26, 2025
@Kobzol Kobzol force-pushed the bootstrap-check-stage-1 branch from f06e41e to aed5f23 Compare June 26, 2025 08:03
@Kobzol
Copy link
Member Author

Kobzol commented Jun 26, 2025

CC @jieyouxu (one of many heaps of bootstrap fixup commits I have in store 😆)

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented Jun 26, 2025

☔ The latest upstream changes (presumably #141899) made this pull request unmergeable. Please resolve the merge conflicts.

@bors bors added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jun 26, 2025
@Kobzol Kobzol force-pushed the bootstrap-check-stage-1 branch from aed5f23 to a36ee24 Compare June 26, 2025 14:29
@Kobzol
Copy link
Member Author

Kobzol commented Jun 26, 2025

Cross-compilation checks are now doing too much work, I need to take a look at how we can reduce that, because x check --stage1 with cross-compilation is no longer a thing.

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented Jul 1, 2025

☔ The latest upstream changes (presumably #143254) made this pull request unmergeable. Please resolve the merge conflicts.

@Kobzol Kobzol force-pushed the bootstrap-check-stage-1 branch from a36ee24 to 22fb548 Compare July 1, 2025 15:43
@Kobzol Kobzol marked this pull request as ready for review July 1, 2025 15:44
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 1, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jul 1, 2025

This PR modifies src/bootstrap/defaults.

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

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
Member Author

Kobzol commented Jul 1, 2025

r? @jieyouxu

@rustbot
Copy link
Collaborator

rustbot commented Jul 1, 2025

jieyouxu is not on the review rotation at the moment.
They may take a while to respond.

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented Jul 1, 2025

☔ The latest upstream changes (presumably #143287) made this pull request unmergeable. Please resolve the merge conflicts.

@jieyouxu jieyouxu removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 2, 2025
Copy link
Member

@jieyouxu jieyouxu left a comment

Choose a reason for hiding this comment

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

I like this a lot in general, it does feel much more self-consistent and coherent.

I left some questions/discussions for things that I wanted to double-check, but overall looks good!

Comment on lines 183 to 191
self.stage.or(self
.built_by
.map(|compiler| if self.name == "std" { compiler.stage } else { compiler.stage + 1 }))
Copy link
Member

@jieyouxu jieyouxu Jul 2, 2025

Choose a reason for hiding this comment

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

Discussion: this makes me feel a bit uneasy, but I guess the logic here is: anything that's not the standard library should be considered a non-library artifact, and should be considered a product of the stage n (compiler, standard library) pair (and so gets numbered as the next stage)? I.e. reading back https://hackmd.io/QXj6LqntQTKPgm3uBuE-aA again, the core model is

stage corresponds to what gets built, not what is used to build it

(The following is me trying to make sure I understand this)


Let's call the (compiler, library) pair12

$$\mathbf{CLP}_{\mathrm{stage}} := \left\langle \text{compiler}_{\mathrm{stage}}, \text{library}_{\mathrm{stage}} \right\rangle$$

where the separation between stages is delineated by which $\mathrm{compiler}$ gets built. Then, by design, because the standard library is "special" and tightly coupled with the compiler, we fix the immediate standard library built by $\mathrm{compiler}_{\mathrm{stage}}$ to be of the same $\mathrm{stage}$, i.e. $\mathrm{library}_{\mathrm{stage}}$.

With the stage 0 redesign, we now have a nice straightforward "derivation chain" ($\longrightarrow$; artifacts can be used to build new artifacts) property where

$$\left\langle \text{compiler}_{\mathrm{stage}}, \text{library}_{\mathrm{stage}} \right\rangle \longrightarrow \left\langle \text{compiler}_{\mathrm{stage + 1}}, \text{library}_{\mathrm{stage + 1}} \right\rangle$$

actually holds even for $\mathrm{stage} = 0$.

However, for:

  • bootstrap tools
    Tools that are unconditionally built by the stage 0 $\mathbf{CLP}$, i.e. always depends on $\mathbf{CLP}_{0}$. Their stage numbering will be called $\mathrm{BootstrapTool}_{1}$, at least in the short-term.
  • host rustc tools
    Tools that depend on rustc_private and so on $\mathrm{compiler}_{\mathrm{stage}}$. This means that they will be numbered as $\mathrm{HostRustcTool}_{\mathrm{stage} + 1}$.
  • std tools
    Tools that depend on the whole $\mathbf{CLP}_{\mathrm{stage}}$, i.e. both $\mathrm{compiler}_{\mathrm{stage}}$, and $\mathrm{library}_{\mathrm{stage}}$. Similiarly, this means that they will be numbered as $\mathrm{StdTool}_{\mathrm{stage} + 1}$.

They then follow the general "what gets built" model (?).

mental-model

Footnotes

  1. I can't come up with a better name, it's not exactly a toolchain, neither is it a "complete" sysroot I think

  2. Not to be confused with the Chilean Peso.

Comment on lines 255 to 256
builder.std(build_compiler, host);
builder.std(build_compiler, target);
builder.ensure(Std::new(build_compiler, target));
Copy link
Member

@jieyouxu jieyouxu Jul 2, 2025

Choose a reason for hiding this comment

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

Question: wait, why is this different? For $\mathrm{stage} \ge 1$, isn't this equivalent? I.e.

if compiler.stage == 0 {
if target != compiler.host {
panic!(
r"It is not possible to build the standard library for `{target}` using the stage0 compiler.
You have to build a stage1 compiler for `{}` first, and then use it to build a standard library for `{target}`.
",
compiler.host
)
}
// We still need to link the prebuilt standard library into the ephemeral stage0 sysroot
self.ensure(StdLink::from_std(Std::new(compiler, target), compiler));
} else {
// This step both compiles the std and links it into the compiler's sysroot.
// Yes, it's quite magical and side-effecty.. would be nice to refactor later.
self.ensure(Std::new(compiler, target));
}

At this point, wouldn't we have already rejected invoking ./x check flow with $\mathrm{stage} = 0$?

Copy link
Member Author

@Kobzol Kobzol Jul 3, 2025

Choose a reason for hiding this comment

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

Equivalent to what? :) I changed it just to this:

let build_compiler = builder.compiler(builder.top_stage, host);
builder.ensure(Std::new(build_compiler, target));
build_compiler

because I remembered that stdlib's proc macros and build scripts are always compiled using the stage0 libstd. We only need the host stdlib when compiling host code of other modes (yeah, I know..).

Copy link
Member Author

Choose a reason for hiding this comment

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

Except! We actually need the host stdlib when checking the tool itself (not stdlib). Aaaaargh.

Copy link
Member

@jieyouxu jieyouxu Jul 4, 2025

Choose a reason for hiding this comment

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

Equivalent to what?

NGL, I don't know what I meant by this myself -- when I click at this comment, it's outdated against something, and I can't tell what it was...

@@ -48,7 +48,7 @@ ENV SCRIPT \
python3 ../x.py build src/tools/build-manifest && \
python3 ../x.py test --stage 0 src/tools/compiletest && \
python3 ../x.py check compiletest --set build.compiletest-use-stage0-libtest=true && \
python3 ../x.py check --stage 1 --target=i686-pc-windows-gnu --host=i686-pc-windows-gnu && \
python3 ../x.py check --stage 2 --target=i686-pc-windows-gnu --host=i686-pc-windows-gnu && \
Copy link
Member

Choose a reason for hiding this comment

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

Suggestion: actually, can you add a comment for this specifically that we're exercising cross-compile here, so --stage 1 isn't sufficient?

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 3, 2025
…eyouxu

Add bootstrap check snapshot tests

Split off from rust-lang#143048, so that we get a baseline of how check behaved before we make changes to it. Note that the output of the check snapshot tests is suboptimal in many places, as we're missing information about stages and the build compiler. That will be changed in rust-lang#143048.

r? `@jieyouxu`
rust-timer added a commit that referenced this pull request Jul 3, 2025
Rollup merge of #143316 - Kobzol:bootstrap-check-tests, r=jieyouxu

Add bootstrap check snapshot tests

Split off from #143048, so that we get a baseline of how check behaved before we make changes to it. Note that the output of the check snapshot tests is suboptimal in many places, as we're missing information about stages and the build compiler. That will be changed in #143048.

r? `@jieyouxu`
@Kobzol Kobzol force-pushed the bootstrap-check-stage-1 branch from 22fb548 to fae5ba2 Compare July 3, 2025 15:59
@rust-log-analyzer

This comment has been minimized.

@Kobzol Kobzol force-pushed the bootstrap-check-stage-1 branch from fae5ba2 to 996cd08 Compare July 5, 2025 08:02
@Kobzol Kobzol force-pushed the bootstrap-check-stage-1 branch from 6fbfbd1 to 5dc77ba Compare July 6, 2025 15:25
@Kobzol
Copy link
Member Author

Kobzol commented Jul 6, 2025

My rebases lost author information of Zalathar from the code I reused from #139170, reinstated that. Rebased and updated the change tracker.

@jieyouxu
Copy link
Member

jieyouxu commented Jul 6, 2025

Cool, feel free to r=me after PR CI is green.

@Kobzol
Copy link
Member Author

Kobzol commented Jul 6, 2025

@bors r=jieyouxu rollup=never

@bors
Copy link
Collaborator

bors commented Jul 6, 2025

📌 Commit 5dc77ba has been approved by jieyouxu

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 6, 2025
@bors
Copy link
Collaborator

bors commented Jul 7, 2025

⌛ Testing commit 5dc77ba with merge c720f49...

@bors
Copy link
Collaborator

bors commented Jul 7, 2025

☀️ Test successful - checks-actions
Approved by: jieyouxu
Pushing c720f49 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jul 7, 2025
@bors bors merged commit c720f49 into rust-lang:master Jul 7, 2025
12 checks passed
@rustbot rustbot added this to the 1.90.0 milestone Jul 7, 2025
Copy link
Contributor

github-actions bot commented Jul 7, 2025

What is this? This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.

Comparing 0d11be5 (parent) -> c720f49 (this PR)

Test differences

Show 2 test diffs

2 doctest diffs were found. These are ignored, as they are noisy.

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard c720f49c46ec3e70bbc2bbb3e0dd1fe7fc0a47f2 --output-dir test-dashboard

And then open test-dashboard/index.html in your browser to see an overview of all executed tests.

Job duration changes

  1. x86_64-apple-2: 5793.7s -> 4023.2s (-30.6%)
  2. pr-check-2: 2000.5s -> 2519.6s (25.9%)
  3. x86_64-apple-1: 7001.1s -> 5443.5s (-22.2%)
  4. dist-apple-various: 6512.0s -> 7780.2s (19.5%)
  5. dist-s390x-linux: 5462.3s -> 4419.7s (-19.1%)
  6. x86_64-rust-for-linux: 2951.2s -> 2463.0s (-16.5%)
  7. dist-aarch64-apple: 5438.4s -> 4743.0s (-12.8%)
  8. i686-gnu-2: 6299.0s -> 5497.5s (-12.7%)
  9. i686-gnu-1: 8243.7s -> 7263.5s (-11.9%)
  10. x86_64-gnu-tools: 3694.2s -> 3273.4s (-11.4%)
How to interpret the job duration changes?

Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.

@Kobzol Kobzol deleted the bootstrap-check-stage-1 branch July 7, 2025 08:19
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (c720f49): comparison URL.

Overall result: ❌✅ regressions and improvements - no action needed

@rustbot label: -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.0% [0.0%, 0.0%] 1
Improvements ✅
(primary)
-1.4% [-1.4%, -1.4%] 1
Improvements ✅
(secondary)
-0.8% [-1.4%, -0.3%] 2
All ❌✅ (primary) -1.4% [-1.4%, -1.4%] 1

Max RSS (memory usage)

Results (secondary 2.0%)

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)
2.0% [1.7%, 2.4%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Cycles

Results (secondary 2.4%)

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)
2.4% [2.4%, 2.4%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 462.394s -> 464.259s (0.40%)
Artifact size: 372.15 MiB -> 372.10 MiB (-0.02%)

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Jul 7, 2025

How can I do just a check build now?

I had

# The default stage to use for the `check` subcommand
check-stage = 0

# The default stage to use for the `doc` subcommand
doc-stage = 0

# The default stage to use for the `build` subcommand
build-stage = 1

# The default stage to use for the `test` subcommand
test-stage = 1

# The default stage to use for the `dist` subcommand
dist-stage = 2

# The default stage to use for the `install` subcommand
install-stage = 2

# The default stage to use for the `bench` subcommand
bench-stage = 2

which no longer works now:

Building bootstrap
    Finished `dev` profile [unoptimized] target(s) in 0.05s
WARNING: cannot check anything on stage 0. Use at least stage 1.
Build completed unsuccessfully in 0:00:00

so I set

# The default stage to use for the `check` subcommand
check-stage = 1

# The default stage to use for the `doc` subcommand
doc-stage = 1
...

which now does a check build but also a full stage0 -> stage1 bootstrap right after?? 🤔

./x.py check
Building bootstrap
    Finished `dev` profile [unoptimized] target(s) in 0.04s
Checking stage1 compiler artifacts {rustc-main, rustc_abi, rustc_arena, rustc_ast, rustc_ast_ir, rustc_ast_lowering, rustc_ast_passes, rustc_ast_pretty, rustc_attr_data_structures, rustc_attr_parsing, rustc_baked_icu_data, rustc_borrowck, rustc_builtin_macros, rustc_codegen_llvm, rustc_codegen_ssa, rustc_const_eval, rustc_data_structures, rustc_driver, rustc_driver_impl, rustc_error_codes, rustc_error_messages, rustc_errors, rustc_expand, rustc_feature, rustc_fluent_macro, rustc_fs_util, rustc_graphviz, rustc_hashes, rustc_hir, rustc_hir_analysis, rustc_hir_pretty, rustc_hir_typeck, rustc_incremental, rustc_index, rustc_index_macros, rustc_infer, rustc_interface, rustc_lexer, rustc_lint, rustc_lint_defs, rustc_llvm, rustc_log, rustc_macros, rustc_metadata, rustc_middle, rustc_mir_build, rustc_mir_dataflow, rustc_mir_transform, rustc_monomorphize, rustc_next_trait_solver, rustc_parse, rustc_parse_format, rustc_passes, rustc_pattern_analysis, rustc_privacy, rustc_proc_macro, rustc_query_impl, rustc_query_system, rustc_resolve, rustc_sanitizers, rustc_serialize, rustc_session, rustc_smir, rustc_span, rustc_symbol_mangling, rustc_target, rustc_thread_pool, rustc_trait_selection, rustc_traits, rustc_transmute, rustc_ty_utils, rustc_type_ir, rustc_type_ir_macros, stable_mir} (x86_64-unknown-linux-gnu)
    Finished `release` profile [optimized + debuginfo] target(s) in 0.29s
Checking tool rustdoc (stage0 -> stage1, x86_64-unknown-linux-gnu)
    Finished `release` profile [optimized + debuginfo] target(s) in 0.15s
Checking stage1 rustc_codegen_cranelift (x86_64-unknown-linux-gnu)
    Finished `release` profile [optimized + debuginfo] target(s) in 0.05s
Checking stage1 rustc_codegen_gcc (x86_64-unknown-linux-gnu)
    Finished `release` profile [optimized + debuginfo] target(s) in 0.03s
Checking tool clippy (stage0 -> stage1, x86_64-unknown-linux-gnu)
    Finished `release` profile [optimized + debuginfo] target(s) in 0.20s
Checking tool miri (stage0 -> stage1, x86_64-unknown-linux-gnu)
    Finished `release` profile [optimized + debuginfo] target(s) in 0.18s
Checking tool cargo-miri (stage0 -> stage1, x86_64-unknown-linux-gnu)
    Finished `release` profile [optimized + debuginfo] target(s) in 0.14s
Checking stage1 tool miropt-test-tools (x86_64-unknown-linux-gnu)
    Finished `release` profile [optimized + debuginfo] target(s) in 0.11s
Checking tool rustfmt (stage0 -> stage1, x86_64-unknown-linux-gnu)
    Finished `release` profile [optimized + debuginfo] target(s) in 0.17s
Checking stage1 rust-analyzer artifacts (x86_64-unknown-linux-gnu)
    Finished `release` profile [optimized + debuginfo] target(s) in 0.30s
/home/matthias/vcs/github/rust/build/x86_64-unknown-linux-gnu/ci-llvm/bin/llvm-strip does not exist; skipping copy
Building compiler artifacts (stage0 -> stage1, x86_64-unknown-linux-gnu)
   Compiling rustc_llvm v0.0.0 (/home/matthias/vcs/github/rust/compiler/rustc_llvm)
   Compiling rustc_parse v0.0.0 (/home/matthias/vcs/github/rust/compiler/rustc_parse)
   Compiling rustc_middle v0.0.0 (/home/matthias/vcs/github/rust/compiler/rustc_middle)
   Compiling rustc_ast_passes v0.0.0 (/home/matthias/vcs/github/rust/compiler/rustc_ast_passes)
   Compiling rustc_expand v0.0.0 (/home/matthias/vcs/github/rust/compiler/rustc_expand)
   Compiling rustc_builtin_macros v0.0.0 (/home/matthias/vcs/github/rust/compiler/rustc_builtin_macros)
   Compiling rustc_infer v0.0.0 (/home/matthias/vcs/github/rust/compiler/rustc_infer)
   Compiling rustc_transmute v0.0.0 (/home/matthias/vcs/github/rust/compiler/rustc_transmute)
   Compiling rustc_incremental v0.0.0 (/home/matthias/vcs/github/rust/compiler/rustc_incremental)
   Compiling rustc_symbol_mangling v0.0.0 (/home/matthias/vcs/github/rust/compiler/rustc_symbol_mangling)
   Compiling rustc_mir_dataflow v0.0.0 (/home/matthias/vcs/github/rust/compiler/rustc_mir_dataflow)
   Compiling rustc_pattern_analysis v0.0.0 (/home/matthias/vcs/github/rust/compiler/rustc_pattern_analysis)
   Compiling rustc_ast_lowering v0.0.0 (/home/matthias/vcs/github/rust/compiler/rustc_ast_lowering)
   Compiling rustc_query_impl v0.0.0 (/home/matthias/vcs/github/rust/compiler/rustc_query_impl)
   Compiling rustc_smir v0.0.0 (/home/matthias/vcs/github/rust/compiler/rustc_smir)
   Compiling stable_mir v0.1.0-preview (/home/matthias/vcs/github/rust/compiler/stable_mir)
   Compiling rustc_monomorphize v0.0.0 (/home/matthias/vcs/github/rust/compiler/rustc_monomorphize)
   Compiling rustc_metadata v0.0.0 (/home/matthias/vcs/github/rust/compiler/rustc_metadata)
   Compiling rustc_trait_selection v0.0.0 (/home/matthias/vcs/github/rust/compiler/rustc_trait_selection)

edit: I also have
download-rustc = false

@Kobzol
Copy link
Member Author

Kobzol commented Jul 7, 2025

x check checks both rustc and std, amongst other things. For checking std, you need to build a stage 1 rustc after the stage0 redesign, there's no way around that (other than download-ci-rustc).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-testsuite Area: The testsuite used to check the correctness of rustc merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants