Skip to content

Commit 49ff258

Browse files
authored
Merge pull request #2263 from BoxyUwU/rustc-pull2
Rustc pull
2 parents 5ec3c62 + 3a4c5b0 commit 49ff258

10 files changed

+64
-13
lines changed

Diff for: examples/rustc-driver-interacting-with-the-ast.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use std::path::Path;
2020
use std::sync::Arc;
2121

2222
use rustc_ast_pretty::pprust::item_to_string;
23-
use rustc_driver::{Compilation, run_compiler};
23+
use rustc_driver::{run_compiler, Compilation};
2424
use rustc_interface::interface::{Compiler, Config};
2525
use rustc_middle::ty::TyCtxt;
2626

@@ -77,7 +77,7 @@ impl rustc_driver::Callbacks for MyCallbacks {
7777
let item = hir_krate.item(id);
7878
// Use pattern-matching to find a specific node inside the main function.
7979
if let rustc_hir::ItemKind::Fn { body, .. } = item.kind {
80-
let expr = &tcx.hir().body(body).value;
80+
let expr = &tcx.hir_body(body).value;
8181
if let rustc_hir::ExprKind::Block(block, _) = expr.kind {
8282
if let rustc_hir::StmtKind::Let(let_stmt) = block.stmts[0].kind {
8383
if let Some(expr) = let_stmt.init {

Diff for: rust-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
124cc92199ffa924f6b4c7cc819a85b65e0c3984
1+
4ecd70ddd1039a3954056c1071e40278048476fa

Diff for: src/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
- [Prologue](./building/bootstrapping/intro.md)
7676
- [What Bootstrapping does](./building/bootstrapping/what-bootstrapping-does.md)
7777
- [How Bootstrap does it](./building/bootstrapping/how-bootstrap-does-it.md)
78+
- [Writing tools in Bootstrap](./building/bootstrapping/writing-tools-in-bootstrap.md)
7879
- [Debugging bootstrap](./building/bootstrapping/debugging-bootstrap.md)
7980

8081
# High-level Compiler Architecture

Diff for: src/building/bootstrapping/debugging-bootstrap.md

+16
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,14 @@ $ BOOTSTRAP_TRACING=CONFIG_HANDLING=TRACE ./x build library --stage 1
115115

116116
[tracing-env-filter]: https://docs.rs/tracing-subscriber/0.3.19/tracing_subscriber/filter/struct.EnvFilter.html
117117

118+
##### FIXME(#96176): specific tracing for `compiler()` vs `compiler_for()`
119+
120+
The additional targets `COMPILER` and `COMPILER_FOR` are used to help trace what
121+
`builder.compiler()` and `builder.compiler_for()` does. They should be removed
122+
if [#96176][cleanup-compiler-for] is resolved.
123+
124+
[cleanup-compiler-for]: https://github.com/rust-lang/rust/issues/96176
125+
118126
### Using `tracing` in bootstrap
119127

120128
Both `tracing::*` macros and the `tracing::instrument` proc-macro attribute need to be gated behind `tracing` feature. Examples:
@@ -160,6 +168,14 @@ For `#[instrument]`, it's recommended to:
160168
- Explicitly pick an instrumentation name via `name = ".."` to distinguish between e.g. `run` of different steps.
161169
- Take care to not cause diverging behavior via tracing, e.g. building extra things only when tracing infra is enabled.
162170

171+
### Profiling bootstrap
172+
173+
You can use the `COMMAND` tracing target to trace execution of most commands spawned by bootstrap. If you also use the `BOOTSTRAP_PROFILE=1` environment variable, bootstrap will generate a Chrome JSON trace file, which can be visualized in Chrome's `chrome://tracing` page or on https://ui.perfetto.dev.
174+
175+
```bash
176+
$ BOOTSTRAP_TRACING=COMMAND=trace BOOTSTRAP_PROFILE=1 ./x build library
177+
```
178+
163179
### rust-analyzer integration?
164180

165181
Unfortunately, because bootstrap is a `rust-analyzer.linkedProjects`, you can't ask r-a to check/build bootstrap itself with `tracing` feature enabled to get relevant completions, due to lack of support as described in <https://github.com/rust-lang/rust-analyzer/issues/8521>.
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Writing tools in Bootstrap
2+
3+
There are three types of tools you can write in bootstrap:
4+
5+
- **`Mode::ToolBootstrap`**
6+
Use this for tools that don’t need anything from the in-tree compiler and can run with the stage0 `rustc`.
7+
The output is placed in the "stage0-bootstrap-tools" directory. This mode is for general-purpose tools built
8+
entirely with the stage0 compiler, including target libraries and only works for stage 0.
9+
10+
- **`Mode::ToolStd`**
11+
Use this for tools that rely on the locally built std. The output goes into the "stageN-tools" directory.
12+
This mode is rarely used, mainly for `compiletest` which requires `libtest`.
13+
14+
- **`Mode::ToolRustc`**
15+
Use this for tools that depend on both the locally built `rustc` and the target `std`. This is more complex than
16+
the other modes because the tool must be built with the same compiler used for `rustc` and placed in the "stageN-tools"
17+
directory. When you choose `Mode::ToolRustc`, `ToolBuild` implementation takes care of this automatically.
18+
If you need to use the builder’s compiler for something specific, you can get it from `ToolBuildResult`, which is
19+
returned by the tool's [`Step`].
20+
21+
Regardless of the tool type you must return `ToolBuildResult` from the tool’s [`Step`] implementation and use `ToolBuild` inside it.
22+
23+
[`Step`]: https://doc.rust-lang.org/nightly/nightly-rustc/bootstrap/core/builder/trait.Step.html

Diff for: src/building/suggested.md

+11
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,16 @@ You can run `./x setup editor` and select `helix`, which will prompt you to
179179
create `languages.toml` with the recommended configuration for Helix. The
180180
recommended settings live at [`src/etc/rust_analyzer_helix.toml`].
181181

182+
### Zed
183+
184+
Zed comes with built-in LSP and rust-analyzer support.
185+
It can be configured through `.zed/settings.json`, as described
186+
[here](https://zed.dev/docs/configuring-languages). Selecting `zed`
187+
in `./x setup editor` will prompt you to create a `.zed/settings.json`
188+
file which will configure Zed with the recommended configuration. The
189+
recommended `rust-analyzer` settings live
190+
at [`src/etc/rust_analyzer_zed.json`].
191+
182192
## Check, check, and check again
183193

184194
When doing simple refactoring, it can be useful to run `./x check`
@@ -406,4 +416,5 @@ load this completion.
406416
[`src/etc/rust_analyzer_settings.json`]: https://github.com/rust-lang/rust/blob/master/src/etc/rust_analyzer_settings.json
407417
[`src/etc/rust_analyzer_eglot.el`]: https://github.com/rust-lang/rust/blob/master/src/etc/rust_analyzer_eglot.el
408418
[`src/etc/rust_analyzer_helix.toml`]: https://github.com/rust-lang/rust/blob/master/src/etc/rust_analyzer_helix.toml
419+
[`src/etc/rust_analyzer_zed.json`]: https://github.com/rust-lang/rust/blob/master/src/etc/rust_analyzer_zed.json
409420
[`src/etc/pre-push.sh`]: https://github.com/rust-lang/rust/blob/master/src/etc/pre-push.sh

Diff for: src/implementing_new_features.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ smoothly.
99
**NOTE: this section is for *language* features, not *library* features,
1010
which use [a different process].**
1111

12+
See also [the Rust Language Design Team's procedures][lang-propose] for
13+
proposing changes to the language.
14+
1215
[a different process]: ./stability.md
16+
[lang-propose]: https://lang-team.rust-lang.org/how_to/propose.html
1317

1418
## The @rfcbot FCP process
1519

@@ -163,9 +167,7 @@ a new unstable feature:
163167

164168
1. Prevent usage of the new feature unless the feature gate is set.
165169
You can check it in most places in the compiler using the
166-
expression `tcx.features().$feature_name` (or
167-
`sess.features_untracked().$feature_name` if the
168-
tcx is unavailable)
170+
expression `tcx.features().$feature_name()`
169171

170172
If the feature gate is not set, you should either maintain
171173
the pre-feature behavior or raise an error, depending on

Diff for: src/mir/index.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,9 @@ The most important rule for
304304
this representation is that every value must be uniquely represented. In other
305305
words: a specific value must only be representable in one specific way. For example: there is only
306306
one way to represent an array of two integers as a `ValTree`:
307-
`ValTree::Branch(&[ValTree::Leaf(first_int), ValTree::Leaf(second_int)])`.
307+
`Branch([Leaf(first_int), Leaf(second_int)])`.
308308
Even though theoretically a `[u32; 2]` could be encoded in a `u64` and thus just be a
309-
`ValTree::Leaf(bits_of_two_u32)`, that is not a legal construction of `ValTree`
309+
`Leaf(bits_of_two_u32)`, that is not a legal construction of `ValTree`
310310
(and is very complex to do, so it is unlikely anyone is tempted to do so).
311311

312312
These rules also mean that some values are not representable. There can be no `union`s in type

Diff for: src/parallel-rustc.md

-5
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ are implemented differently depending on whether `parallel-compiler` is true.
4646

4747
| data structure | parallel | non-parallel |
4848
| -------------------------------- | --------------------------------------------------- | ------------ |
49-
| Weak | std::sync::Weak | std::rc::Weak |
50-
| Atomic{Bool}/{Usize}/{U32}/{U64} | std::sync::atomic::Atomic{Bool}/{Usize}/{U32}/{U64} | (std::cell::Cell<bool/usize/u32/u64>) |
5149
| OnceCell | std::sync::OnceLock | std::cell::OnceCell |
5250
| Lock\<T> | (parking_lot::Mutex\<T>) | (std::cell::RefCell) |
5351
| RwLock\<T> | (parking_lot::RwLock\<T>) | (std::cell::RefCell) |
@@ -58,7 +56,6 @@ are implemented differently depending on whether `parallel-compiler` is true.
5856
| WriteGuard | parking_lot::RwLockWriteGuard | std::cell::RefMut |
5957
| MappedWriteGuard | parking_lot::MappedRwLockWriteGuard | std::cell::RefMut |
6058
| LockGuard | parking_lot::MutexGuard | std::cell::RefMut |
61-
| MappedLockGuard | parking_lot::MappedMutexGuard | std::cell::RefMut |
6259

6360
- These thread-safe data structures are interspersed during compilation which
6461
can cause lock contention resulting in degraded performance as the number of
@@ -173,12 +170,10 @@ Here are some resources that can be used to learn more:
173170
- [This list of interior mutability in the compiler by nikomatsakis][imlist]
174171

175172
[`rayon`]: https://crates.io/crates/rayon
176-
[Arc]: https://doc.rust-lang.org/std/sync/struct.Arc.html
177173
[imlist]: https://github.com/nikomatsakis/rustc-parallelization/blob/master/interior-mutability-list.md
178174
[irlo0]: https://internals.rust-lang.org/t/parallelizing-rustc-using-rayon/6606
179175
[irlo1]: https://internals.rust-lang.org/t/help-test-parallel-rustc/11503
180176
[monomorphization]: backend/monomorph.md
181177
[parallel-rustdoc]: https://github.com/rust-lang/rust/issues/82741
182-
[Rc]: https://doc.rust-lang.org/std/rc/struct.Rc.html
183178
[rustc-rayon]: https://github.com/rust-lang/rustc-rayon
184179
[tracking]: https://github.com/rust-lang/rust/issues/48685

Diff for: src/tests/directives.md

+3
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ Some examples of `X` in `ignore-X` or `only-X`:
154154
`ignore-coverage-map`, `ignore-coverage-run`
155155
- When testing a dist toolchain: `dist`
156156
- This needs to be enabled with `COMPILETEST_ENABLE_DIST_TESTS=1`
157+
- The `rustc_abi` of the target: e.g. `rustc_abi-x86_64-sse2`
157158

158159
The following directives will check rustc build settings and target
159160
settings:
@@ -192,6 +193,8 @@ settings:
192193
specified atomic widths, e.g. the test with `//@ needs-target-has-atomic: 8,
193194
16, ptr` will only run if it supports the comma-separated list of atomic
194195
widths.
196+
- `needs-dynamic-linking` - ignores if target does not support dynamic linking
197+
(which is orthogonal to it being unable to create `dylib` and `cdylib` crate types)
195198

196199
The following directives will check LLVM support:
197200

0 commit comments

Comments
 (0)