Merge from rustc
This commit is contained in:
commit
3a4c5b0447
|
|
@ -20,7 +20,7 @@ use std::path::Path;
|
|||
use std::sync::Arc;
|
||||
|
||||
use rustc_ast_pretty::pprust::item_to_string;
|
||||
use rustc_driver::{Compilation, run_compiler};
|
||||
use rustc_driver::{run_compiler, Compilation};
|
||||
use rustc_interface::interface::{Compiler, Config};
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
|
||||
|
|
@ -77,7 +77,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, .. } = item.kind {
|
||||
let expr = &tcx.hir().body(body).value;
|
||||
let expr = &tcx.hir_body(body).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 {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -115,6 +115,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:
|
||||
|
|
@ -160,6 +168,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 <https://github.com/rust-lang/rust-analyzer/issues/8521>.
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -179,6 +179,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`
|
||||
|
|
@ -406,4 +416,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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
@ -163,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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -46,8 +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<bool/usize/u32/u64>) |
|
||||
| OnceCell | std::sync::OnceLock | std::cell::OnceCell |
|
||||
| Lock\<T> | (parking_lot::Mutex\<T>) | (std::cell::RefCell) |
|
||||
| RwLock\<T> | (parking_lot::RwLock\<T>) | (std::cell::RefCell) |
|
||||
|
|
@ -58,7 +56,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
|
||||
|
|
@ -173,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
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
@ -192,6 +193,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:
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue