From 844a47ab9f6e059ffdcc5912d9eac57f9166d174 Mon Sep 17 00:00:00 2001 From: Askar Safin Date: Tue, 11 Feb 2025 08:14:00 +0300 Subject: [PATCH 01/16] compiler/rustc_data_structures/src/sync.rs: delete MappedLockGuard It seems it is left-over after some refactoring --- src/parallel-rustc.md | 1 - 1 file changed, 1 deletion(-) diff --git a/src/parallel-rustc.md b/src/parallel-rustc.md index 44c78a125..49c52976c 100644 --- a/src/parallel-rustc.md +++ b/src/parallel-rustc.md @@ -58,7 +58,6 @@ are implemented differently depending on whether `parallel-compiler` is true. | WriteGuard | parking_lot::RwLockWriteGuard | std::cell::RefMut | | MappedWriteGuard | parking_lot::MappedRwLockWriteGuard | std::cell::RefMut | | LockGuard | parking_lot::MutexGuard | std::cell::RefMut | -| MappedLockGuard | parking_lot::MappedMutexGuard | std::cell::RefMut | - These thread-safe data structures are interspersed during compilation which can cause lock contention resulting in degraded performance as the number of From efa3dae1e187bc6511da4cab196fca2ed0142970 Mon Sep 17 00:00:00 2001 From: Askar Safin Date: Tue, 11 Feb 2025 08:25:50 +0300 Subject: [PATCH 02/16] compiler/rustc_data_structures/src/sync.rs: delete Weak --- src/parallel-rustc.md | 1 - 1 file changed, 1 deletion(-) diff --git a/src/parallel-rustc.md b/src/parallel-rustc.md index 49c52976c..4fb91da68 100644 --- a/src/parallel-rustc.md +++ b/src/parallel-rustc.md @@ -46,7 +46,6 @@ are implemented differently depending on whether `parallel-compiler` is true. | data structure | parallel | non-parallel | | -------------------------------- | --------------------------------------------------- | ------------ | -| Weak | std::sync::Weak | std::rc::Weak | | Atomic{Bool}/{Usize}/{U32}/{U64} | std::sync::atomic::Atomic{Bool}/{Usize}/{U32}/{U64} | (std::cell::Cell) | | OnceCell | std::sync::OnceLock | std::cell::OnceCell | | Lock\ | (parking_lot::Mutex\) | (std::cell::RefCell) | From f0bcb7376097fc03f24fb1ae16cea190f8f3a224 Mon Sep 17 00:00:00 2001 From: Askar Safin Date: Tue, 11 Feb 2025 08:57:36 +0300 Subject: [PATCH 03/16] compiler/rustc_data_structures/src/sync.rs: remove atomics, but not AtomicU64! --- src/parallel-rustc.md | 1 - 1 file changed, 1 deletion(-) diff --git a/src/parallel-rustc.md b/src/parallel-rustc.md index 4fb91da68..deddf77e3 100644 --- a/src/parallel-rustc.md +++ b/src/parallel-rustc.md @@ -46,7 +46,6 @@ are implemented differently depending on whether `parallel-compiler` is true. | data structure | parallel | non-parallel | | -------------------------------- | --------------------------------------------------- | ------------ | -| Atomic{Bool}/{Usize}/{U32}/{U64} | std::sync::atomic::Atomic{Bool}/{Usize}/{U32}/{U64} | (std::cell::Cell) | | OnceCell | std::sync::OnceLock | std::cell::OnceCell | | Lock\ | (parking_lot::Mutex\) | (std::cell::RefCell) | | RwLock\ | (parking_lot::RwLock\) | (std::cell::RefCell) | From eeec2f4b40dff17ec92902cdd7752c6c7ffe4412 Mon Sep 17 00:00:00 2001 From: Askar Safin Date: Tue, 11 Feb 2025 09:23:54 +0300 Subject: [PATCH 04/16] src/doc/rustc-dev-guide/src/parallel-rustc.md: remove Arc and Rc (it seems they are left-over after my PR) --- src/parallel-rustc.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/parallel-rustc.md b/src/parallel-rustc.md index deddf77e3..c5b70706a 100644 --- a/src/parallel-rustc.md +++ b/src/parallel-rustc.md @@ -170,12 +170,10 @@ Here are some resources that can be used to learn more: - [This list of interior mutability in the compiler by nikomatsakis][imlist] [`rayon`]: https://crates.io/crates/rayon -[Arc]: https://doc.rust-lang.org/std/sync/struct.Arc.html [imlist]: https://github.com/nikomatsakis/rustc-parallelization/blob/master/interior-mutability-list.md [irlo0]: https://internals.rust-lang.org/t/parallelizing-rustc-using-rayon/6606 [irlo1]: https://internals.rust-lang.org/t/help-test-parallel-rustc/11503 [monomorphization]: backend/monomorph.md [parallel-rustdoc]: https://github.com/rust-lang/rust/issues/82741 -[Rc]: https://doc.rust-lang.org/std/rc/struct.Rc.html [rustc-rayon]: https://github.com/rust-lang/rustc-rayon [tracking]: https://github.com/rust-lang/rust/issues/48685 From 66e5b92c319b15b4a1e093b7c28cc5f269493268 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Tue, 11 Feb 2025 15:47:29 +0100 Subject: [PATCH 05/16] dev-guide: Link to t-lang procedures for new features --- src/implementing_new_features.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/implementing_new_features.md b/src/implementing_new_features.md index d87afeaed..5b67ccd7f 100644 --- a/src/implementing_new_features.md +++ b/src/implementing_new_features.md @@ -9,7 +9,11 @@ smoothly. **NOTE: this section is for *language* features, not *library* features, which use [a different process].** +See also [the Rust Language Design Team's procedures][lang-propose] for +proposing changes to the language. + [a different process]: ./stability.md +[lang-propose]: https://lang-team.rust-lang.org/how_to/propose.html ## The @rfcbot FCP process From 5cb9ff172f307bcaf5bdc3e8d2138fd089c51748 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Tue, 11 Feb 2025 21:21:04 +0200 Subject: [PATCH 06/16] document the directive --- src/tests/directives.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/tests/directives.md b/src/tests/directives.md index 9e0f8f9c2..b6209bcb2 100644 --- a/src/tests/directives.md +++ b/src/tests/directives.md @@ -192,6 +192,8 @@ settings: specified atomic widths, e.g. the test with `//@ needs-target-has-atomic: 8, 16, ptr` will only run if it supports the comma-separated list of atomic widths. +- `needs-dynamic-linking` - ignores if target does not support dynamic linking + (which is orthogonal to it being unable to create `dylib` and `cdylib` crate types) The following directives will check LLVM support: From db57a5f454168b86820c26cb3c6ad73a4b331e1b Mon Sep 17 00:00:00 2001 From: Lukas Markeffsky <@> Date: Fri, 7 Feb 2025 19:33:58 +0100 Subject: [PATCH 07/16] intern valtrees --- src/mir/index.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mir/index.md b/src/mir/index.md index 778c58391..f355875aa 100644 --- a/src/mir/index.md +++ b/src/mir/index.md @@ -304,9 +304,9 @@ The most important rule for this representation is that every value must be uniquely represented. In other words: a specific value must only be representable in one specific way. For example: there is only one way to represent an array of two integers as a `ValTree`: -`ValTree::Branch(&[ValTree::Leaf(first_int), ValTree::Leaf(second_int)])`. +`Branch([Leaf(first_int), Leaf(second_int)])`. Even though theoretically a `[u32; 2]` could be encoded in a `u64` and thus just be a -`ValTree::Leaf(bits_of_two_u32)`, that is not a legal construction of `ValTree` +`Leaf(bits_of_two_u32)`, that is not a legal construction of `ValTree` (and is very complex to do, so it is unlikely anyone is tempted to do so). These rules also mean that some values are not representable. There can be no `union`s in type From 470a207ef09aaa474cb61495b0f2b39477635bef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Wed, 12 Feb 2025 13:48:48 +0100 Subject: [PATCH 08/16] Document bootstrap profiling --- src/building/bootstrapping/debugging-bootstrap.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/building/bootstrapping/debugging-bootstrap.md b/src/building/bootstrapping/debugging-bootstrap.md index 3f907e85d..04fa5b204 100644 --- a/src/building/bootstrapping/debugging-bootstrap.md +++ b/src/building/bootstrapping/debugging-bootstrap.md @@ -121,6 +121,14 @@ For `#[instrument]`, it's recommended to: - Explicitly pick an instrumentation name via `name = ".."` to distinguish between e.g. `run` of different steps. - Take care to not cause diverging behavior via tracing, e.g. building extra things only when tracing infra is enabled. +### Profiling bootstrap + +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. + +```bash +$ BOOTSTRAP_TRACING=COMMAND=trace BOOTSTRAP_PROFILE=1 ./x build library +``` + ### rust-analyzer integration? 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 . From f32fc55183701d1a75a7cbd6923ad8201f14a558 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= <39484203+jieyouxu@users.noreply.github.com> Date: Sat, 15 Feb 2025 19:16:42 +0800 Subject: [PATCH 09/16] rustc-dev-guide: document `{ignore,only}-rustc_abi-x86-sse2` --- src/tests/directives.md | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tests/directives.md b/src/tests/directives.md index b6209bcb2..00bb2bc4d 100644 --- a/src/tests/directives.md +++ b/src/tests/directives.md @@ -154,6 +154,7 @@ Some examples of `X` in `ignore-X` or `only-X`: `ignore-coverage-map`, `ignore-coverage-run` - When testing a dist toolchain: `dist` - This needs to be enabled with `COMPILETEST_ENABLE_DIST_TESTS=1` +- The `rustc_abi` of the target: e.g. `rustc_abi-x86_64-sse2` The following directives will check rustc build settings and target settings: From 141a8a1962ce8b698e6437be77e054523abae7af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= <39484203+jieyouxu@users.noreply.github.com> Date: Sat, 15 Feb 2025 22:59:01 +0800 Subject: [PATCH 10/16] rustc-dev-guide: document `COMPILER` and `COMPILER_FOR` tracing targets --- src/building/bootstrapping/debugging-bootstrap.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/building/bootstrapping/debugging-bootstrap.md b/src/building/bootstrapping/debugging-bootstrap.md index 04fa5b204..04d8e91dc 100644 --- a/src/building/bootstrapping/debugging-bootstrap.md +++ b/src/building/bootstrapping/debugging-bootstrap.md @@ -76,6 +76,14 @@ $ BOOTSTRAP_TRACING=CONFIG_HANDLING=TRACE ./x build library --stage 1 [tracing-env-filter]: https://docs.rs/tracing-subscriber/0.3.19/tracing_subscriber/filter/struct.EnvFilter.html +##### FIXME(#96176): specific tracing for `compiler()` vs `compiler_for()` + +The additional targets `COMPILER` and `COMPILER_FOR` are used to help trace what +`builder.compiler()` and `builder.compiler_for()` does. They should be removed +if [#96176][cleanup-compiler-for] is resolved. + +[cleanup-compiler-for]: https://github.com/rust-lang/rust/issues/96176 + ### Using `tracing` in bootstrap Both `tracing::*` macros and the `tracing::instrument` proc-macro attribute need to be gated behind `tracing` feature. Examples: From 35c8087bff2281dc0c87ec17ca654d2fe362a388 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 3 Feb 2025 10:45:49 +1100 Subject: [PATCH 11/16] Move some `Map` methods onto `TyCtxt`. The end goal is to eliminate `Map` altogether. I added a `hir_` prefix to all of them, that seemed simplest. The exceptions are `module_items` which became `hir_module_free_items` because there was already a `hir_module_items`, and `items` which became `hir_free_items` for consistency with `hir_module_free_items`. --- examples/rustc-driver-interacting-with-the-ast.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/rustc-driver-interacting-with-the-ast.rs b/examples/rustc-driver-interacting-with-the-ast.rs index 9fcb16b0f..dc63e1aa5 100644 --- a/examples/rustc-driver-interacting-with-the-ast.rs +++ b/examples/rustc-driver-interacting-with-the-ast.rs @@ -75,7 +75,7 @@ impl rustc_driver::Callbacks for MyCallbacks { let item = hir_krate.item(id); // Use pattern-matching to find a specific node inside the main function. if let rustc_hir::ItemKind::Fn(_, _, body_id) = item.kind { - let expr = &tcx.hir().body(body_id).value; + let expr = &tcx.hir_body(body_id).value; if let rustc_hir::ExprKind::Block(block, _) = expr.kind { if let rustc_hir::StmtKind::Let(let_stmt) = block.stmts[0].kind { if let Some(expr) = let_stmt.init { From 019264fc55b88135f4d3ca75adb16d71775d56b7 Mon Sep 17 00:00:00 2001 From: "Chai T. Rex" Date: Mon, 17 Feb 2025 23:48:39 -0500 Subject: [PATCH 12/16] Add Zed to dev guide suggested workflows page --- src/building/suggested.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/building/suggested.md b/src/building/suggested.md index 2c6c3fe1d..5c041d6cb 100644 --- a/src/building/suggested.md +++ b/src/building/suggested.md @@ -154,6 +154,16 @@ You can run `./x setup editor` and select `helix`, which will prompt you to create `languages.toml` with the recommended configuration for Helix. The recommended settings live at [`src/etc/rust_analyzer_helix.toml`]. +### Zed + +Zed comes with built-in LSP and rust-analyzer support. +It can be configured through `.zed/settings.json`, as described +[here](https://zed.dev/docs/configuring-languages). Selecting `zed` +in `./x setup editor` will prompt you to create a `.zed/settings.json` +file which will configure Zed with the recommended configuration. The +recommended `rust-analyzer` settings live +at [`src/etc/rust_analyzer_zed.json`]. + ## Check, check, and check again When doing simple refactoring, it can be useful to run `./x check` @@ -381,4 +391,5 @@ load this completion. [`src/etc/rust_analyzer_settings.json`]: https://github.com/rust-lang/rust/blob/master/src/etc/rust_analyzer_settings.json [`src/etc/rust_analyzer_eglot.el`]: https://github.com/rust-lang/rust/blob/master/src/etc/rust_analyzer_eglot.el [`src/etc/rust_analyzer_helix.toml`]: https://github.com/rust-lang/rust/blob/master/src/etc/rust_analyzer_helix.toml +[`src/etc/rust_analyzer_zed.json`]: https://github.com/rust-lang/rust/blob/master/src/etc/rust_analyzer_zed.json [`src/etc/pre-push.sh`]: https://github.com/rust-lang/rust/blob/master/src/etc/pre-push.sh From 209dd46dad6a9ef6814b8d785a30ee4cc7304653 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 18 Feb 2025 10:28:36 -0600 Subject: [PATCH 13/16] docs(dev): Remove reference to features_untracked This was removed in #114723 --- src/implementing_new_features.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/implementing_new_features.md b/src/implementing_new_features.md index 5b67ccd7f..c77b872cf 100644 --- a/src/implementing_new_features.md +++ b/src/implementing_new_features.md @@ -167,9 +167,7 @@ a new unstable feature: 1. Prevent usage of the new feature unless the feature gate is set. You can check it in most places in the compiler using the - expression `tcx.features().$feature_name` (or - `sess.features_untracked().$feature_name` if the - tcx is unavailable) + expression `tcx.features().$feature_name` If the feature gate is not set, you should either maintain the pre-feature behavior or raise an error, depending on From 1520629844fc748359152008611f003e577971bd Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 18 Feb 2025 10:35:13 -0600 Subject: [PATCH 14/16] docs(dev): Access features as functions, not members This was changed in #132027 --- src/implementing_new_features.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/implementing_new_features.md b/src/implementing_new_features.md index c77b872cf..fda38ef4f 100644 --- a/src/implementing_new_features.md +++ b/src/implementing_new_features.md @@ -167,7 +167,7 @@ a new unstable feature: 1. Prevent usage of the new feature unless the feature gate is set. You can check it in most places in the compiler using the - expression `tcx.features().$feature_name` + expression `tcx.features().$feature_name()` If the feature gate is not set, you should either maintain the pre-feature behavior or raise an error, depending on From 97b80c80d12ec1241a59f202c6546208b93c2ef5 Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Wed, 19 Feb 2025 09:03:35 +0300 Subject: [PATCH 15/16] add rustc-dev doc about bootstrap tools Signed-off-by: onur-ozkan --- src/SUMMARY.md | 1 + .../writing-tools-in-bootstrap.md | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 src/building/bootstrapping/writing-tools-in-bootstrap.md diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 91c4aeacb..106db508e 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -75,6 +75,7 @@ - [Prologue](./building/bootstrapping/intro.md) - [What Bootstrapping does](./building/bootstrapping/what-bootstrapping-does.md) - [How Bootstrap does it](./building/bootstrapping/how-bootstrap-does-it.md) +- [Writing tools in Bootstrap](./building/bootstrapping/writing-tools-in-bootstrap.md) - [Debugging bootstrap](./building/bootstrapping/debugging-bootstrap.md) # High-level Compiler Architecture diff --git a/src/building/bootstrapping/writing-tools-in-bootstrap.md b/src/building/bootstrapping/writing-tools-in-bootstrap.md new file mode 100644 index 000000000..6046d5b13 --- /dev/null +++ b/src/building/bootstrapping/writing-tools-in-bootstrap.md @@ -0,0 +1,23 @@ +# Writing tools in Bootstrap + +There are three types of tools you can write in bootstrap: + +- **`Mode::ToolBootstrap`** + Use this for tools that don’t need anything from the in-tree compiler and can run with the stage0 `rustc`. + The output is placed in the "stage0-bootstrap-tools" directory. This mode is for general-purpose tools built + entirely with the stage0 compiler, including target libraries and only works for stage 0. + +- **`Mode::ToolStd`** + Use this for tools that rely on the locally built std. The output goes into the "stageN-tools" directory. + This mode is rarely used, mainly for `compiletest` which requires `libtest`. + +- **`Mode::ToolRustc`** + Use this for tools that depend on both the locally built `rustc` and the target `std`. This is more complex than + the other modes because the tool must be built with the same compiler used for `rustc` and placed in the "stageN-tools" + directory. When you choose `Mode::ToolRustc`, `ToolBuild` implementation takes care of this automatically. + If you need to use the builder’s compiler for something specific, you can get it from `ToolBuildResult`, which is + returned by the tool's [`Step`]. + +Regardless of the tool type you must return `ToolBuildResult` from the tool’s [`Step`] implementation and use `ToolBuild` inside it. + +[`Step`]: https://doc.rust-lang.org/nightly/nightly-rustc/bootstrap/core/builder/trait.Step.html From 5bda7ef853bcbca5568db450be56418a8973c640 Mon Sep 17 00:00:00 2001 From: Boxy Date: Tue, 25 Feb 2025 21:22:45 +0000 Subject: [PATCH 16/16] Preparing for merge from rustc --- rust-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-version b/rust-version index 78e9ecdf1..ce21bb8ef 100644 --- a/rust-version +++ b/rust-version @@ -1 +1 @@ -124cc92199ffa924f6b4c7cc819a85b65e0c3984 +4ecd70ddd1039a3954056c1071e40278048476fa