Skip to content

[WIP] Add an Inside Rust blog post for stage 0 std redesign #1582

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

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions content/inside-rust/stage0-redesign/index.md
Copy link
Member Author

Choose a reason for hiding this comment

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

TODO: having someone on t-libs and someone on t-compiler skim it and sign off that it makes sense

Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
+++
path = "inside-rust/9999/12/31/redesigning-stage-0-std"
title = "Redesigning stage 0 std"
authors = ["Jieyou Xu"]

[extra]
team = "Bootstrap"
team_url = "https://www.rust-lang.org/governance/teams/infra#team-bootstrap"
+++

# Redesigning stage 0 std
Copy link
Member

Choose a reason for hiding this comment

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

I would maybe change the title to be something like "Redesigning stage 0 during compiler bootstrapping" (i.e. give a little bit more of a hint at who will be affected, for those not familiar with what "stage 0" is)

Copy link
Member Author

@jieyouxu jieyouxu Apr 29, 2025

Choose a reason for hiding this comment

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

I might rename this to sth like "Redesigning the stage 0 compiler bootstrap sequence", not sure if that makes more sense?

Copy link
Contributor

Choose a reason for hiding this comment

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

Btw the heading should be removed, the title attribute in the frontmatter is authoritative. Otherwise it creates this:
image

Copy link
Contributor

Choose a reason for hiding this comment

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

I might rename this to sth like "Redesigning the stage 0 compiler bootstrap sequence", not sure if that makes more sense?

I agree to find a less dense title. Another (more verbose) proposal:

Redesigning rustc initial bootstrap stage to compile the standard library

or something like that. Titles are hard 😅


## Summary

We are reworking how the stage 0 bootstrap sequence works (the sequence used to build a stage 1 compiler).
Copy link
Member

Choose a reason for hiding this comment

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

Similarly, I would put a little bit of a lead up here on why this change is desired (which I think will naturally require a little bit of background to flow well).

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, previously the motivation was up front, I'll need to balance it a bit.


- Before: a stage 0 (beta by default) compiler is used to build the in-tree std, which in turn is used to build the stage 1 compiler.
Copy link
Member

@BoxyUwU BoxyUwU Apr 29, 2025

Choose a reason for hiding this comment

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

I also think that having to clarify that stage0 is "technically not always the beta compiler" makes things a bit harder to understand 🤔 Almost every contributor is going to have stage0 being the beta compiler so even if its not necessarily true I do wonder if it would make sense to lie a bit with a footnote the first time and then just ignore it from then on:

Suggested change
- Before: a stage 0 (beta by default) compiler is used to build the in-tree std, which in turn is used to build the stage 1 compiler.
- Before: the beta compiler[^1] is used to build the in-tree std, which in turn is used to build the stage 1 compiler.
[^1]: In practice, rarely, the stage0 compiler can be something other than the beta compiler. This doesn't matter too much for the purpose of this change though, so we've taken the liberty of conflating the two to make it easier to explain the change to bootstrapping.

Although maybe this actually doesn't matter too much if you have a motivation section upfront discussing mental models so that there's already a nice intuition built for "stage0 == beta mostly sort of"

- After: a stage 0 (beta by default) compiler and a precompiled stage 0 std is instead used to build the stage 1 compiler.

Comment on lines +17 to +19
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if this could do with a short summary with less of the... I hesitate to say jargon, but something like:

Suggested change
- Before: a stage 0 (beta by default) compiler is used to build the in-tree std, which in turn is used to build the stage 1 compiler.
- After: a stage 0 (beta by default) compiler and a precompiled stage 0 std is instead used to build the stage 1 compiler.
- Before: a stage 0 (beta by default) compiler is used to build the in-tree std, which in turn is used to build the stage 1 compiler.
- After: a stage 0 (beta by default) compiler and a precompiled stage 0 std is instead used to build the stage 1 compiler.
In other words, in the typical workflow, the stage1 compiler now depends on beta std instead of the in-tree std (built by the beta compiler).

Generally I find the current "before/after" description to be a little bit hard to parse 🤔

![Difference in stage 0 bootstrap sequence](stage0-redesign-diff.svg)

Notably, this means that after [redesign stage 0 std #119899](https://github.com/rust-lang/rust/pull/119899) PR lands:

- `./x {build,test,check} library --stage 0` becomes no-op, as stage 0 std is no longer the built in-tree std, and the minimum supported stage to build std is now `1`.
- Consequently, default (test, check, bench) stage values in the library profile are no longer `0`, but instead defaults to `1`.

Choose a reason for hiding this comment

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

Suggested change
- Consequently, default (test, check, bench) stage values in the library profile are no longer `0`, but instead defaults to `1`.
- Consequently, default (test, check, bench) stage values in the library profile are no longer `0`, but instead default to `1`.

- Some additional `cfg(bootstrap)` usages may be needed in the compiler sources for dogfooding unstable library features.
Comment on lines +22 to +26
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure how you'd fit in but I wonder if it'd be helpful to say something like "stage0 now always refers to things from the beta toolchain (unless otherwise customized)".

Copy link
Contributor

Choose a reason for hiding this comment

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

"If unstable library features are being dogfooded"

dogfooding = technical lingo, which might be ok if we assume a specific target audience. Could it be reworded to be less technical?

Copy link
Member Author

Choose a reason for hiding this comment

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

I can use "experimenting with unstable library features", sure.

This internal blog post is targeted towards people (compiler/library contributors) who'd already be exposed to terms like "dogfooding", but "experimenting" is less opaque, so sure.


If you have questions, or run into bugs/issues related to the stage 0 std redesign, please discuss them in the [stage 0 std redesign support thread][support-thread] or open a new issue.

[support-thread]: https://rust-lang.zulipchat.com/#narrow/channel/326414-t-infra.2Fbootstrap/topic/Stage.200.20std.20redesign.20support.20thread/with/515096924

## Comparison of common invocations

For `profile = "library"`:

| Invocation | Before stage 0 std redesign | After stage 0 std redesign |
|--------------------------------------------|-------------------------------------------------------------|----------------------------------------------------------|
| `./x {check,build,test} library` | Checks/builds/tests in-tree library | Check/build/tests stage 1 library |
| `./x {check,build,test} library --stage 0` | Checks/builds/tests in-tree library | No-op in case of build, checks/tests precompiled library |
| `./x {check,build,test} library --stage 1` | Builds in-tree library, checks/builds/tests stage 1 library | Check/build/tests stage 1 library |

For `profile = "compiler"`:

| Invocation | Before stage 0 std redesign | After stage 0 std redesign |
|--------------------------------------------|-------------------------------------------------------------|----------------------------------------------------------|
| `./x check library` | Checks in-tree library | Check/build/tests stage 1 library |
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
| `./x check library` | Checks in-tree library | Check/build/tests stage 1 library |
| `./x check library` | Checks in-tree library | Check stage 1 library |

or does x check library actually build and test it?

Copy link
Member Author

@jieyouxu jieyouxu Apr 29, 2025

Choose a reason for hiding this comment

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

No, that's a mistake from moving things around, good catch

| `./x {build,test} library` | Builds in-tree library, builds/tests stage 1 library | Check/build/tests stage 1 library |
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
| `./x {build,test} library` | Builds in-tree library, builds/tests stage 1 library | Check/build/tests stage 1 library |
| `./x {build,test} library` | Builds in-tree library, builds/tests stage 1 library | build/tests stage 1 library |

| `./x {check,build,test} library --stage 0` | Checks/builds/tests in-tree library | No-op in case of build, checks/tests precompiled library |

Choose a reason for hiding this comment

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

What does it mean to check the precompiled library?

Copy link
Member Author

@jieyouxu jieyouxu Apr 30, 2025

Choose a reason for hiding this comment

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

It's a no-op (arguably not exactly that, it's "does nothing"/"unsupported"?), I'll reword that

| `./x {check,build,test} library --stage 1` | Builds in-tree library, checks/builds/tests stage 1 library | Check/build/tests stage 1 library |

For `profile = "tools"`, by default not affected if `download-rustc` is enabled.

## What does this mean for a typical library workflow?

- Crucially, `./x {build,test,check} library --stage 0` becomes no-op and are no longer supported. Building the in-tree std now requires a stage 1 compiler.
- Consequently, library contributors are *strongly* encouraged to enable `rust.download-rustc = "if-unchanged"` to avoid having to build a stage 1 compiler. Note that this is the default for `profile = "library"`, but you may need to specify it manually if you don't use a `profile`.
- `cfg(bootstrap)` should no longer be needed for library sources.

## What does this mean for a typical compiler workflow?

- If unstable library features are being dogfooded, some additional `cfg(bootstrap)` usages may now be needed in compiler sources.
Copy link
Member

Choose a reason for hiding this comment

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

I think this would really benefit from some example(s). For example, what would this look like for e.g. a new trait solving feature that requires some core lang items?

(Aside, not the right place for this, but this effectively means that such features actually will need to a stage 2 compiler to be built to properly test them, right?)


## Why are we making this change?

The previous stage 0 bootstrapping sequence was a source of endless confusion for compiler, library and bootstrap contributors alike, because std had to support being built by *both* a previous beta rustc and in-tree rustc, with `cfg(bootstrap)` in std sources necessary to distinguish between them. By adjusting the stage 0 bootstrap sequence to instead use a precompiled stage 0 std instead of building the in-tree std, we hope to:
Copy link
Member

Choose a reason for hiding this comment

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

Said above, a very brief summary of this could be put at the beginning.

Copy link
Member

Choose a reason for hiding this comment

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

I have an alternative description of the motivation that I think more accurately captures the effect on combined compiler/library changes. Feel free to merge and integrate or so whatever with it that you want:

The compiler and standard library are tightly coupled. Intrinsics and lang items form a broad interface between the two, and whenever it is changed, both sides need to adjust. But the standard library supports being compiled with two different compilers, the in-tree compiler and the stage0 (beta) compiler. This means that all such changes require cfg(bootstrap) to support both compilers, which results in a lot of churn of anyone wanting to improve things that touch this area.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I think that's a way better motivation summary. I'll need to think about how to reword this section.


1. Simplify library development workflow to no longer need `cfg(bootstrap)`, and
Copy link
Member

Choose a reason for hiding this comment

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

Also an aside and shouldn't really be discussed here, but I personally think cfg(bootstrap) in library code is likely easier to maintain and reason about than cfg(bootstrap) in compiler code.

Though, perhaps I'm wrong, in which case I think this blog post can do better at convincing me this isn't the case.

Copy link
Member

Choose a reason for hiding this comment

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

It may be easier, but it's much more common. Instances of cfg(bootstrap) should be really rare, while in the library it's incredibly common, especially for larger refactors that were simply not done previously because it's so bad

2. Enable simplifying some bootstrap logic related to building in-tree std in stage 0.

This was [originally proposed by @jyn514 in the MCP rust-lang/compiler-team#619](https://github.com/rust-lang/compiler-team/issues/619).
Loading