Description
Rust has the standard multi-stage structure that all bootstrapping compilers have.
A newcomer who knows about compiler stages will be confident with this, until they run a command like ./x.py build --stage 1
and get output like this:
Building stage0 std artifacts
...
Copying stage0 std from stage0
Building stage0 test artifacts
...
Copying stage0 test from stage0
Building stage0 compiler artifacts
...
Copying stage0 rustc from stage0
Building stage0 codegen artifacts
...
Assembling stage1 compiler
Building stage1 std artifacts
...
Copying stage1 std from stage1
Building stage1 test artifacts
...
Copying stage1 test from stage1
Building stage1 compiler artifacts
...
Copying stage1 rustc from stage1
Building stage1 codegen artifacts
...
Building rustdoc for stage1
...
For a newcomer, this is completely bizarre.
- Why is it building stage 0? Isn't stage 0 the compiler you download?
- How does it assemble the stage 1 compiler before building the stage 1 artifacts?
- Why is it building two stages? Shouldn't it only build one stage?
The key to understanding this is that x.py
uses a surprising naming convention:
- A "stage N artifact" is an artifact that is produced by the stage N compiler.
- The "stage (N+1) compiler" is assembled from "stage N artifacts".
- A
--stage N
flag means build with stage N.
Somebody had to explain this to me when I started working on Rust. I have since had to explain it to multiple newcomers. Even though I understand it now, I still find it very confusing, and I have to think carefully about it all.
Here's a naming convention that makes more sense to me:
- A "stage N artifact" is an artifact that is produced by the stage (N-1) compiler.
- The "stage N compiler" is assembled from "stage N artifacts".
- A
--stage N
flag means build stage N, using stage (N-1).
That way, a command like ./x.py build --stage 1
would produce output like this:
Building stage1 std artifacts
...
Copying stage1 std from stage1
Building stage1 test artifacts
...
Copying stage1 test from stage1
Building stage1 compiler artifacts
...
Copying stage1 rustc from stage1
Building stage1 codegen artifacts
...
Assembling stage1 compiler
Is there any appetite for this change? I realize it would be invasive and people would have to update their aliases, build scripts, etc. But it might be worthwhile to avoid the ongoing confusion to both newcomers and experienced contributors. Deprecating the word "stage" in favour of "phase" could help with the transition.