Skip to content

Commit 2e63e00

Browse files
author
The Miri Cronjob Bot
committed
Merge from rustc
2 parents c070440 + cda721a commit 2e63e00

28 files changed

+341
-243
lines changed

.mailmap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ Jynn Nelson <[email protected]> <[email protected]>
33
44
55
Jynn Nelson <[email protected]>
6+

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
e42bbfe1f7c26f8760a99c4b1f27d33aba1040bb
1+
99e7c15e81385b38a8186b51edc4577d5d7b5bdd

src/appendix/compiler-lecture.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,4 @@ These are videos where various experts explain different parts of the compiler:
4646

4747
## Code Generation
4848
- [January 2019: Cranelift](https://www.youtube.com/watch?v=9OIA7DTFQWU)
49+
- [December 2024: LLVM Developers' Meeting - Rust ❤️ LLVM](https://www.youtube.com/watch?v=Kqz-umsAnk8)

src/borrow_check/two_phase_borrows.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ borrow.
7676
[`AutoBorrow`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/adjustment/enum.AutoBorrow.html
7777
[converted]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir_build/thir/cx/expr/trait.ToBorrowKind.html#method.to_borrow_kind
7878
[`BorrowKind`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/enum.BorrowKind.html
79-
[`GatherBorrows`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/visit/trait.Visitor.html#method.visit_local
79+
[`GatherBorrows`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_borrowck/borrow_set/struct.GatherBorrows.html
8080
[`BorrowData`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_borrowck/borrow_set/struct.BorrowData.html
8181

8282
## Checking two-phase borrows

src/building/bootstrapping/what-bootstrapping-does.md

Lines changed: 35 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ compiler.
4545

4646
```mermaid
4747
graph TD
48-
s0c["stage0 compiler (1.63)"]:::downloaded -->|A| s0l("stage0 std (1.64)"):::with-s0c;
48+
s0c["stage0 compiler (1.86.0-beta.1)"]:::downloaded -->|A| s0l("stage0 std (1.86.0-beta.1)"):::downloaded;
4949
s0c & s0l --- stepb[ ]:::empty;
50-
stepb -->|B| s0ca["stage0 compiler artifacts (1.64)"]:::with-s0c;
51-
s0ca -->|copy| s1c["stage1 compiler (1.64)"]:::with-s0c;
52-
s1c -->|C| s1l("stage1 std (1.64)"):::with-s1c;
50+
stepb -->|B| s0ca["stage0 compiler artifacts (1.87.0-dev)"]:::with-s0c;
51+
s0ca -->|copy| s1c["stage1 compiler (1.87.0-dev)"]:::with-s0c;
52+
s1c -->|C| s1l("stage1 std (1.87.0-dev)"):::with-s1c;
5353
s1c & s1l --- stepd[ ]:::empty;
54-
stepd -->|D| s1ca["stage1 compiler artifacts (1.64)"]:::with-s1c;
54+
stepd -->|D| s1ca["stage1 compiler artifacts (1.87.0-dev)"]:::with-s1c;
5555
s1ca -->|copy| s2c["stage2 compiler"]:::with-s1c;
5656
5757
classDef empty width:0px,height:0px;
@@ -62,19 +62,21 @@ graph TD
6262

6363
### Stage 0: the pre-compiled compiler
6464

65-
The stage0 compiler is usually the current _beta_ `rustc` compiler and its
65+
The stage0 compiler is by default the very recent _beta_ `rustc` compiler and its
6666
associated dynamic libraries, which `./x.py` will download for you. (You can
67-
also configure `./x.py` to use something else.)
67+
also configure `./x.py` to change stage0 to something else.)
6868

69-
The stage0 compiler is then used only to compile [`src/bootstrap`],
70-
[`library/std`], and [`compiler/rustc`]. When assembling the libraries and
71-
binaries that will become the stage1 `rustc` compiler, the freshly compiled
72-
`std` and `rustc` are used. There are two concepts at play here: a compiler
73-
(with its set of dependencies) and its 'target' or 'object' libraries (`std` and
74-
`rustc`). Both are staged, but in a staggered manner.
69+
The precompiled stage0 compiler is then used only to compile [`src/bootstrap`] and [`compiler/rustc`]
70+
with precompiled stage0 std.
71+
72+
Note that to build the stage1 compiler we use the precompiled stage0 compiler and std.
73+
Therefore, to use a compiler with a std that is freshly built from the tree, you need to
74+
build the stage2 compiler.
75+
76+
There are two concepts at play here: a compiler (with its set of dependencies) and its
77+
'target' or 'object' libraries (`std` and `rustc`). Both are staged, but in a staggered manner.
7578

7679
[`compiler/rustc`]: https://github.com/rust-lang/rust/tree/master/compiler/rustc
77-
[`library/std`]: https://github.com/rust-lang/rust/tree/master/library/std
7880
[`src/bootstrap`]: https://github.com/rust-lang/rust/tree/master/src/bootstrap
7981

8082
### Stage 1: from current code, by an earlier compiler
@@ -84,26 +86,25 @@ The rustc source code is then compiled with the `stage0` compiler to produce the
8486

8587
### Stage 2: the truly current compiler
8688

87-
We then rebuild our `stage1` compiler with itself to produce the `stage2`
89+
We then rebuild the compiler using `stage1` compiler with in-tree std to produce the `stage2`
8890
compiler.
8991

90-
In theory, the `stage1` compiler is functionally identical to the `stage2`
91-
compiler, but in practice there are subtle differences. In particular, the
92-
`stage1` compiler itself was built by `stage0` and hence not by the source in
93-
your working directory. This means that the ABI generated by the `stage0`
94-
compiler may not match the ABI that would have been made by the `stage1`
95-
compiler, which can cause problems for dynamic libraries, tests, and tools using
96-
`rustc_private`.
92+
The `stage1` compiler itself was built by precompiled `stage0` compiler and std
93+
and hence not by the source in your working directory. This means that the ABI
94+
generated by the `stage0` compiler may not match the ABI that would have been made
95+
by the `stage1` compiler, which can cause problems for dynamic libraries, tests
96+
and tools using `rustc_private`.
9797

9898
Note that the `proc_macro` crate avoids this issue with a `C` FFI layer called
9999
`proc_macro::bridge`, allowing it to be used with `stage1`.
100100

101101
The `stage2` compiler is the one distributed with `rustup` and all other install
102102
methods. However, it takes a very long time to build because one must first
103103
build the new compiler with an older compiler and then use that to build the new
104-
compiler with itself. For development, you usually only want the `stage1`
105-
compiler, which you can build with `./x build library`. See [Building the
106-
compiler](../how-to-build-and-run.html#building-the-compiler).
104+
compiler with itself.
105+
106+
For development, you usually only want to use `--stage 1` flag to build things.
107+
See [Building the compiler](../how-to-build-and-run.html#building-the-compiler).
107108

108109
### Stage 3: the same-result test
109110

@@ -114,10 +115,11 @@ something has broken.
114115
### Building the stages
115116

116117
The script [`./x`] tries to be helpful and pick the stage you most likely meant
117-
for each subcommand. These defaults are as follows:
118+
for each subcommand. Here are some `x` commands with their default stages:
118119

119-
- `check`: `--stage 0`
120-
- `doc`: `--stage 0`
120+
- `check`: `--stage 1`
121+
- `clippy`: `--stage 1`
122+
- `doc`: `--stage 1`
121123
- `build`: `--stage 1`
122124
- `test`: `--stage 1`
123125
- `dist`: `--stage 2`
@@ -191,8 +193,8 @@ include, but are not limited to:
191193
without building `rustc` from source ('build with `stage0`, then test the
192194
artifacts'). If you're working on the standard library, this is normally the
193195
test command you want.
194-
- `./x build --stage 0` means to build with the beta `rustc`.
195-
- `./x doc --stage 0` means to document using the beta `rustdoc`.
196+
- `./x build --stage 0` means to build with the stage0 `rustc`.
197+
- `./x doc --stage 0` means to document using the stage0 `rustdoc`.
196198

197199
#### Examples of what *not* to do
198200

@@ -208,9 +210,6 @@ include, but are not limited to:
208210

209211
### Building vs. running
210212

211-
Note that `build --stage N compiler/rustc` **does not** build the stage N
212-
compiler: instead it builds the stage N+1 compiler _using_ the stage N compiler.
213-
214213
In short, _stage 0 uses the `stage0` compiler to create `stage0` artifacts which
215214
will later be uplifted to be the stage1 compiler_.
216215

@@ -268,23 +267,6 @@ However, when cross-compiling, `stage1` `std` will only run on the host. So the
268267

269268
(See in the table how `stage2` only builds non-host `std` targets).
270269

271-
### Why does only libstd use `cfg(bootstrap)`?
272-
273-
For docs on `cfg(bootstrap)` itself, see [Complications of
274-
Bootstrapping](#complications-of-bootstrapping).
275-
276-
The `rustc` generated by the `stage0` compiler is linked to the freshly-built
277-
`std`, which means that for the most part only `std` needs to be `cfg`-gated, so
278-
that `rustc` can use features added to `std` immediately after their addition,
279-
without need for them to get into the downloaded `beta` compiler.
280-
281-
Note this is different from any other Rust program: `stage1` `rustc` is built by
282-
the _beta_ compiler, but using the _master_ version of `libstd`!
283-
284-
The only time `rustc` uses `cfg(bootstrap)` is when it adds internal lints that
285-
use diagnostic items, or when it uses unstable library features that were
286-
recently changed.
287-
288270
### What is a 'sysroot'?
289271

290272
When you build a project with `cargo`, the build artifacts for dependencies are
@@ -459,7 +441,6 @@ compiler itself uses to run. These aren't actually used by artifacts the new
459441
compiler generates. This step also copies the `rustc` and `rustdoc` binaries we
460442
generated into `build/$HOST/stage/bin`.
461443

462-
The `stage1/bin/rustc` is a fully functional compiler, but it doesn't yet have
463-
any libraries to link built binaries or libraries to. The next 3 steps will
464-
provide those libraries for it; they are mostly equivalent to constructing the
465-
`stage1/bin` compiler so we don't go through them individually here.
444+
The `stage1/bin/rustc` is a fully functional compiler built with stage0 (precompiled) compiler and std.
445+
To use a compiler built entirely from source with the in-tree compiler and std, you need to build the
446+
stage2 compiler, which is compiled using the stage1 (in-tree) compiler and std.

src/building/how-to-build-and-run.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ probably the best "go to" command for building a local compiler:
217217
This may *look* like it only builds the standard library, but that is not the case.
218218
What this command does is the following:
219219

220-
- Build `std` using the stage0 compiler
221220
- Build `rustc` using the stage0 compiler
222221
- This produces the stage1 compiler
223222
- Build `std` using the stage1 compiler
@@ -241,23 +240,22 @@ build. The **full** `rustc` build (what you get with `./x build
241240
--stage 2 compiler/rustc`) has quite a few more steps:
242241

243242
- Build `rustc` with the stage1 compiler.
244-
- The resulting compiler here is called the "stage2" compiler.
245-
- Build `std` with stage2 compiler.
243+
- The resulting compiler here is called the "stage2" compiler, which uses stage1 std from the previous command.
246244
- Build `librustdoc` and a bunch of other things with the stage2 compiler.
247245

248246
You almost never need to do this.
249247

250248
### Build specific components
251249

252250
If you are working on the standard library, you probably don't need to build
253-
the compiler unless you are planning to use a recently added nightly feature.
254-
Instead, you can just build using the bootstrap compiler.
251+
every other default component. Instead, you can build a specific component by
252+
providing its name, like this:
255253

256254
```bash
257-
./x build --stage 0 library
255+
./x build --stage 1 library
258256
```
259257

260-
If you choose the `library` profile when running `x setup`, you can omit `--stage 0` (it's the
258+
If you choose the `library` profile when running `x setup`, you can omit `--stage 1` (it's the
261259
default).
262260

263261
## Creating a rustup toolchain
@@ -271,7 +269,6 @@ you will likely need to build at some point; for example, if you want
271269
to run the entire test suite).
272270

273271
```bash
274-
rustup toolchain link stage0 build/host/stage0-sysroot # beta compiler + stage0 std
275272
rustup toolchain link stage1 build/host/stage1
276273
rustup toolchain link stage2 build/host/stage2
277274
```

src/building/new-target.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ Look for existing targets to use as examples.
8585
After adding your target to the `rustc_target` crate you may want to add
8686
`core`, `std`, ... with support for your new target. In that case you will
8787
probably need access to some `target_*` cfg. Unfortunately when building with
88-
stage0 (the beta compiler), you'll get an error that the target cfg is
88+
stage0 (a precompiled compiler), you'll get an error that the target cfg is
8989
unexpected because stage0 doesn't know about the new target specification and
9090
we pass `--check-cfg` in order to tell it to check.
9191

src/building/suggested.md

Lines changed: 19 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ always overrides the inner ones.
5959

6060
## Configuring `rust-analyzer` for `rustc`
6161

62+
### Checking the "library" tree
63+
64+
Checking the "library" tree requires a stage1 compiler, which can be a heavy process on some computers.
65+
For this reason, bootstrap has a flag called `--skip-std-check-if-no-download-rustc` that skips checking the
66+
"library" tree if `rust.download-rustc` isn't available. If you want to avoid putting a heavy load on your computer
67+
with `rust-analyzer`, you can add the `--skip-std-check-if-no-download-rustc` flag to your `./x check` command in
68+
the `rust-analyzer` configuration.
69+
6270
### Project-local rust-analyzer setup
6371

6472
`rust-analyzer` can help you check and format your code whenever you save a
@@ -91,7 +99,7 @@ for two reasons:
9199
additional rebuilds in some cases.
92100

93101
To avoid these problems:
94-
- Add `--build-dir=build-rust-analyzer` to all of the custom `x` commands in
102+
- Add `--build-dir=build/rust-analyzer` to all of the custom `x` commands in
95103
your editor's rust-analyzer configuration.
96104
(Feel free to choose a different directory name if desired.)
97105
- Modify the `rust-analyzer.rustfmt.overrideCommand` setting so that it points
@@ -100,10 +108,7 @@ To avoid these problems:
100108
copy of `rust-analyzer-proc-macro-srv` in that other build directory.
101109

102110
Using separate build directories for command-line builds and rust-analyzer
103-
requires extra disk space, and also means that running `./x clean` on the
104-
command-line will not clean out the separate build directory. To clean the
105-
separate build directory, run `./x clean --build-dir=build-rust-analyzer`
106-
instead.
111+
requires extra disk space.
107112

108113
### Visual Studio Code
109114

@@ -137,7 +142,7 @@ Task] instead:
137142

138143
### Neovim
139144

140-
For Neovim users there are several options for configuring for rustc. The
145+
For Neovim users, there are a few options. The
141146
easiest way is by using [neoconf.nvim](https://github.com/folke/neoconf.nvim/),
142147
which allows for project-local configuration files with the native LSP. The
143148
steps for how to use it are below. Note that they require rust-analyzer to
@@ -310,51 +315,15 @@ lets you use `cargo fmt`.
310315
[the section on vscode]: suggested.md#configuring-rust-analyzer-for-rustc
311316
[the section on rustup]: how-to-build-and-run.md?highlight=rustup#creating-a-rustup-toolchain
312317

313-
## Faster builds with `--keep-stage`.
314-
315-
Sometimes just checking whether the compiler builds is not enough. A common
316-
example is that you need to add a `debug!` statement to inspect the value of
317-
some state or better understand the problem. In that case, you don't really need
318-
a full build. By bypassing bootstrap's cache invalidation, you can often get
319-
these builds to complete very fast (e.g., around 30 seconds). The only catch is
320-
this requires a bit of fudging and may produce compilers that don't work (but
321-
that is easily detected and fixed).
322-
323-
The sequence of commands you want is as follows:
324-
325-
- Initial build: `./x build library`
326-
- As [documented previously], this will build a functional stage1 compiler as
327-
part of running all stage0 commands (which include building a `std`
328-
compatible with the stage1 compiler) as well as the first few steps of the
329-
"stage 1 actions" up to "stage1 (sysroot stage1) builds std".
330-
- Subsequent builds: `./x build library --keep-stage 1`
331-
- Note that we added the `--keep-stage 1` flag here
332-
333-
[documented previously]: ./how-to-build-and-run.md#building-the-compiler
334-
335-
As mentioned, the effect of `--keep-stage 1` is that we just _assume_ that the
336-
old standard library can be re-used. If you are editing the compiler, this is
337-
almost always true: you haven't changed the standard library, after all. But
338-
sometimes, it's not true: for example, if you are editing the "metadata" part of
339-
the compiler, which controls how the compiler encodes types and other states
340-
into the `rlib` files, or if you are editing things that wind up in the metadata
341-
(such as the definition of the MIR).
342-
343-
**The TL;DR is that you might get weird behavior from a compile when using
344-
`--keep-stage 1`** -- for example, strange [ICEs](../appendix/glossary.html#ice)
345-
or other panics. In that case, you should simply remove the `--keep-stage 1`
346-
from the command and rebuild. That ought to fix the problem.
347-
348-
You can also use `--keep-stage 1` when running tests. Something like this:
349-
350-
- Initial test run: `./x test tests/ui`
351-
- Subsequent test run: `./x test tests/ui --keep-stage 1`
352-
353-
### Iterating the standard library with `--keep-stage`
318+
## Faster Builds with CI-rustc
354319

355-
If you are making changes to the standard library, you can use `./x build
356-
--keep-stage 0 library` to iteratively rebuild the standard library without
357-
rebuilding the compiler.
320+
If you are not working on the compiler, you often don't need to build the compiler tree.
321+
For example, you can skip building the compiler and only build the `library` tree or the
322+
tools under `src/tools`. To achieve that, you have to enable this by setting the `download-rustc`
323+
option in your configuration. This tells bootstrap to use the latest nightly compiler for `stage > 0`
324+
steps, meaning it will have two precompiled compilers: stage0 compiler and `download-rustc` compiler
325+
for `stage > 0` steps. This way, it will never need to build the in-tree compiler. As a result, your
326+
build time will be significantly reduced by not building the in-tree compiler.
358327

359328
## Using incremental compilation
360329

0 commit comments

Comments
 (0)