Skip to content

Commit b98da0d

Browse files
committed
Merge from rustc
2 parents b06461f + e0f0073 commit b98da0d

File tree

8 files changed

+105
-55
lines changed

8 files changed

+105
-55
lines changed

Diff for: examples/rustc-driver-example.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ use std::path::Path;
1818

1919
use rustc_ast_pretty::pprust::item_to_string;
2020
use rustc_data_structures::sync::Lrc;
21-
use rustc_driver::{Compilation, RunCompiler};
22-
use rustc_interface::interface::Compiler;
21+
use rustc_driver::{Compilation, run_compiler};
22+
use rustc_interface::interface::{Compiler, Config};
2323
use rustc_middle::ty::TyCtxt;
2424

2525
struct MyFileLoader;
@@ -51,6 +51,10 @@ fn main() {
5151
struct MyCallbacks;
5252

5353
impl rustc_driver::Callbacks for MyCallbacks {
54+
fn config(&mut self, config: &mut Config) {
55+
config.file_loader = Some(Box::new(MyFileLoader));
56+
}
57+
5458
fn after_crate_root_parsing(
5559
&mut self,
5660
_compiler: &Compiler,
@@ -83,10 +87,5 @@ impl rustc_driver::Callbacks for MyCallbacks {
8387
}
8488

8589
fn main() {
86-
match RunCompiler::new(&["main.rs".to_string()], &mut MyCallbacks) {
87-
mut compiler => {
88-
compiler.set_file_loader(Some(Box::new(MyFileLoader)));
89-
compiler.run();
90-
}
91-
}
90+
run_compiler(&["main.rs".to_string()], &mut MyCallbacks);
9291
}

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

+7-8
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ use std::path::Path;
1818

1919
use rustc_ast_pretty::pprust::item_to_string;
2020
use rustc_data_structures::sync::Lrc;
21-
use rustc_driver::{Compilation, RunCompiler};
22-
use rustc_interface::interface::Compiler;
21+
use rustc_driver::{Compilation, run_compiler};
22+
use rustc_interface::interface::{Compiler, Config};
2323
use rustc_middle::ty::TyCtxt;
2424

2525
struct MyFileLoader;
@@ -51,6 +51,10 @@ fn main() {
5151
struct MyCallbacks;
5252

5353
impl rustc_driver::Callbacks for MyCallbacks {
54+
fn config(&mut self, config: &mut Config) {
55+
config.file_loader = Some(Box::new(MyFileLoader));
56+
}
57+
5458
fn after_crate_root_parsing(
5559
&mut self,
5660
_compiler: &Compiler,
@@ -90,10 +94,5 @@ impl rustc_driver::Callbacks for MyCallbacks {
9094
}
9195

9296
fn main() {
93-
match RunCompiler::new(&["main.rs".to_string()], &mut MyCallbacks) {
94-
mut compiler => {
95-
compiler.set_file_loader(Some(Box::new(MyFileLoader)));
96-
compiler.run();
97-
}
98-
}
97+
run_compiler(&["main.rs".to_string()], &mut MyCallbacks);
9998
}

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

+58-32
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Debugging bootstrap
22

3-
> FIXME: this page could be expanded
3+
> FIXME: this section should be expanded
44
55
## `tracing` in bootstrap
66

@@ -10,21 +10,69 @@ Bootstrap has conditional [`tracing`][tracing] setup to provide structured loggi
1010

1111
### Enabling `tracing` output
1212

13-
Bootstrap will conditionally enable `tracing` output if the `BOOTSTRAP_TRACING` env var is set.
13+
Bootstrap will conditionally build `tracing` support and enable `tracing` output if the `BOOTSTRAP_TRACING` env var is set.
1414

15-
Example usage:
15+
#### Basic usage
16+
17+
Example basic usage[^just-trace]:
18+
19+
[^just-trace]: It is not recommend to use *just* `BOOTSTRAP_TRACING=TRACE` because that will dump *everything* at `TRACE` level, including logs intentionally gated behind custom targets as they are too verbose even for `TRACE` level by default.
1620

1721
```bash
18-
$ BOOTSTRAP_TRACING=TRACE ./x build library --stage 1
22+
$ BOOTSTRAP_TRACING=bootstrap=TRACE ./x build library --stage 1
23+
```
24+
25+
Example output[^unstable]:
26+
27+
```
28+
$ BOOTSTRAP_TRACING=bootstrap=TRACE ./x check src/bootstrap/
29+
Building bootstrap
30+
Compiling bootstrap v0.0.0 (/home/joe/repos/rust/src/bootstrap)
31+
Finished `dev` profile [unoptimized] target(s) in 2.74s
32+
DEBUG bootstrap parsing flags
33+
bootstrap::core::config::flags::Flags::parse args=["check", "src/bootstrap/"]
34+
DEBUG bootstrap parsing config based on flags
35+
DEBUG bootstrap creating new build based on config
36+
bootstrap::Build::build
37+
TRACE bootstrap setting up job management
38+
TRACE bootstrap downloading rustfmt early
39+
bootstrap::handling hardcoded subcommands (Format, Suggest, Perf)
40+
DEBUG bootstrap not a hardcoded subcommand; returning to normal handling, cmd=Check { all_targets: false }
41+
DEBUG bootstrap handling subcommand normally
42+
bootstrap::executing real run
43+
bootstrap::(1) executing dry-run sanity-check
44+
bootstrap::(2) executing actual run
45+
Checking stage0 library artifacts (x86_64-unknown-linux-gnu)
46+
Finished `release` profile [optimized + debuginfo] target(s) in 0.04s
47+
Checking stage0 compiler artifacts {rustc-main, rustc_abi, rustc_arena, rustc_ast, rustc_ast_ir, rustc_ast_lowering, rustc_ast_passes, rustc_ast_pretty, rustc_attr_data_structures, rustc_attr_parsing, rustc_baked_icu_data, rustc_borrowck, rustc_builtin_macros, rustc_codegen_llvm, rustc_codegen_ssa, rustc_const_eval, rustc_data_structures, rustc_driver, rustc_driver_impl, rustc_error_codes, rustc_error_messages, rustc_errors, rustc_expand, rustc_feature, rustc_fluent_macro, rustc_fs_util, rustc_graphviz, rustc_hir, rustc_hir_analysis, rustc_hir_pretty, rustc_hir_typeck, rustc_incremental, rustc_index, rustc_index_macros, rustc_infer, rustc_interface, rustc_lexer, rustc_lint, rustc_lint_defs, rustc_llvm, rustc_log, rustc_macros, rustc_metadata, rustc_middle, rustc_mir_build, rustc_mir_dataflow, rustc_mir_transform, rustc_monomorphize, rustc_next_trait_solver, rustc_parse, rustc_parse_format, rustc_passes, rustc_pattern_analysis, rustc_privacy, rustc_query_impl, rustc_query_system, rustc_resolve, rustc_sanitizers, rustc_serialize, rustc_session, rustc_smir, rustc_span, rustc_symbol_mangling, rustc_target, rustc_trait_selection, rustc_traits, rustc_transmute, rustc_ty_utils, rustc_type_ir, rustc_type_ir_macros, stable_mir} (x86_64-unknown-linux-gnu)
48+
Finished `release` profile [optimized + debuginfo] target(s) in 0.23s
49+
Checking stage0 bootstrap artifacts (x86_64-unknown-linux-gnu)
50+
Checking bootstrap v0.0.0 (/home/joe/repos/rust/src/bootstrap)
51+
Finished `release` profile [optimized + debuginfo] target(s) in 0.64s
52+
DEBUG bootstrap checking for postponed test failures from `test --no-fail-fast`
53+
Build completed successfully in 0:00:08
1954
```
2055

21-
Example output[^experimental]:
56+
#### Controlling log output
57+
58+
The env var `BOOTSTRAP_TRACING` accepts a [`tracing` env-filter][tracing-env-filter].
59+
60+
There are two orthogonal ways to control which kind of logs you want:
2261

23-
![Example bootstrap tracing output](./debugging-bootstrap/tracing-output-example.png)
62+
1. You can specify the log **level**, e.g. `DEBUG` or `TRACE`.
63+
2. You can also control the log **target**, e.g. `bootstrap` or `bootstrap::core::config` vs custom targets like `CONFIG_HANDLING`.
64+
- Custom targets are used to limit what is output when `BOOTSTRAP_TRACING=bootstrap=TRACE` is used, as they can be too verbose even for `TRACE` level by default. Currently used custom targets:
65+
- `CONFIG_HANDLING`
2466

25-
[^experimental]: This shows what's *possible* with the infra in an experimental implementation.
67+
The `TRACE` filter will enable *all* `trace` level or less verbose level tracing output.
2668

27-
The env var `BOOTSTRAP_TRACING` accepts a [`tracing` env-filter][tracing-env-filter]. The `TRACE` filter will enable *all* `trace` level or less verbose level tracing output.
69+
You can of course combine them (custom target logs are typically gated behind `TRACE` log level additionally):
70+
71+
```bash
72+
$ BOOTSTRAP_TRACING=CONFIG_HANDLING=TRACE ./x build library --stage 1
73+
```
74+
75+
[^unstable]: This output is always subject to further changes.
2876

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

@@ -73,28 +121,6 @@ For `#[instrument]`, it's recommended to:
73121
- Explicitly pick an instrumentation name via `name = ".."` to distinguish between e.g. `run` of different steps.
74122
- Take care to not cause diverging behavior via tracing, e.g. building extra things only when tracing infra is enabled.
75123

76-
### Enabling `tracing` bootstrap feature in rust-analyzer
124+
### rust-analyzer integration?
77125

78-
You can adjust your `settings.json`'s `rust-analyzer.check.overrideCommand` and `rust-analyzer.cargo.buildScripts.overrideCommand` if you want to also enable `logging` cargo feature by default in your editor. This is mostly useful if you want proper r-a completions and such when working on bootstrap itself.
79-
80-
```json
81-
"rust-analyzer.check.overrideCommand": [
82-
"BOOTSTRAP_TRACING=1", // <- BOOTSTRAP_TRACING=1 won't enable tracing filter, but it will activate bootstrap's `tracing` feature
83-
"python3",
84-
"x.py",
85-
"check",
86-
"--json-output",
87-
"--build-dir=build-rust-analyzer"
88-
],
89-
```
90-
91-
```json
92-
"rust-analyzer.cargo.buildScripts.overrideCommand": [
93-
"BOOTSTRAP_TRACING=1", // <- note this
94-
"python3",
95-
"x.py",
96-
"check",
97-
"--json-output",
98-
"--build-dir=build-rust-analyzer"
99-
],
100-
```
126+
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>.
Binary file not shown.

Diff for: src/conventions.md

+25-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
This file offers some tips on the coding conventions for rustc. This
1+
This file offers some tips on the coding conventions for rustc. This
22
chapter covers [formatting](#formatting), [coding for correctness](#cc),
33
[using crates from crates.io](#cio), and some tips on
44
[structuring your PR for easy review](#er).
@@ -25,6 +25,7 @@ pass the <!-- date-check: nov 2022 --> `--edition=2021` argument yourself when c
2525
`rustfmt` directly.
2626

2727
[fmt]: https://github.com/rust-dev-tools/fmt-rfcs
28+
2829
[`rustfmt`]:https://github.com/rust-lang/rustfmt
2930

3031
## Formatting C++ code
@@ -40,6 +41,26 @@ When modifying that code, use this command to format it:
4041
This uses a pinned version of `clang-format`, to avoid relying on the local
4142
environment.
4243

44+
## Formatting and linting Python code
45+
46+
The Rust repository contains quite a lof of Python code. We try to keep
47+
it both linted and formatted by the [ruff][ruff] tool.
48+
49+
When modifying Python code, use this command to format it:
50+
```sh
51+
./x test tidy --extra-checks=py:fmt --bless
52+
```
53+
54+
and the following command to run lints:
55+
```sh
56+
./x test tidy --extra-checks=py:lint
57+
```
58+
59+
This uses a pinned version of `ruff`, to avoid relying on the local
60+
environment.
61+
62+
[ruff]: https://github.com/astral-sh/ruff
63+
4364
<a id="copyright"></a>
4465

4566
<!-- REUSE-IgnoreStart -->
@@ -84,7 +105,7 @@ Using `_` in a match is convenient, but it means that when new
84105
variants are added to the enum, they may not get handled correctly.
85106
Ask yourself: if a new variant were added to this enum, what's the
86107
chance that it would want to use the `_` code, versus having some
87-
other treatment? Unless the answer is "low", then prefer an
108+
other treatment? Unless the answer is "low", then prefer an
88109
exhaustive match. (The same advice applies to `if let` and `while
89110
let`, which are effectively tests for a single variant.)
90111

@@ -124,7 +145,7 @@ See the [crates.io dependencies][crates] section.
124145
# How to structure your PR
125146

126147
How you prepare the commits in your PR can make a big difference for the
127-
reviewer. Here are some tips.
148+
reviewer. Here are some tips.
128149

129150
**Isolate "pure refactorings" into their own commit.** For example, if
130151
you rename a method, then put that rename into its own commit, along
@@ -165,4 +186,5 @@ to the compiler.
165186
crate-related, often the spelling is changed to `krate`.
166187

167188
[tcx]: ./ty.md
189+
168190
[crates]: ./crates-io.md

Diff for: src/rustc-driver/intro.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The [`rustc_driver`] is essentially `rustc`'s `main` function.
66
It acts as the glue for running the various phases of the compiler in the correct order,
77
using the interface defined in the [`rustc_interface`] crate. Where possible, using [`rustc_driver`] rather than [`rustc_interface`] is recommended.
88

9-
The main entry point of [`rustc_driver`] is [`rustc_driver::RunCompiler`][rd_rc].
9+
The main entry point of [`rustc_driver`] is [`rustc_driver::run_compiler`][rd_rc].
1010
This builder accepts the same command-line args as rustc as well as an implementation of [`Callbacks`][cb] and a couple of other optional options.
1111
[`Callbacks`][cb] is a `trait` that allows for custom compiler configuration,
1212
as well as allowing custom code to run after different phases of the compilation.
@@ -40,7 +40,7 @@ specifically [`rustc_driver_impl::run_compiler`][rdi_rc]
4040
[cb]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_driver/trait.Callbacks.html
4141
[example]: https://github.com/rust-lang/rustc-dev-guide/blob/master/examples/rustc-interface-example.rs
4242
[i_rc]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_interface/interface/fn.run_compiler.html
43-
[rd_rc]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_driver/struct.RunCompiler.html
43+
[rd_rc]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_driver/fn.run_compiler.html
4444
[rdi_rc]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_driver_impl/fn.run_compiler.html
4545
[stupid-stats]: https://github.com/nrc/stupid-stats
4646
[`nightly-rustc`]: https://doc.rust-lang.org/nightly/nightly-rustc/

Diff for: src/stability.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ Previously, due to a [rustc bug], stable items inside unstable modules were
3434
available to stable code in that location.
3535
As of <!-- date-check --> September 2024, items with [accidentally stabilized
3636
paths] are marked with the `#[rustc_allowed_through_unstable_modules]` attribute
37-
to prevent code dependent on those paths from breaking.
37+
to prevent code dependent on those paths from breaking. Do *not* add this attribute
38+
to any more items unless that is needed to avoid breaking changes.
3839

3940
The `unstable` attribute may also have the `soft` value, which makes it a
4041
future-incompatible deny-by-default lint instead of a hard error. This is used

Diff for: src/tests/directives.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ for more details.
9494
| Directive | Explanation | Supported test suites | Possible values |
9595
|-----------------------------------|--------------------------------------------------------------------------------------------------------------------------|----------------------------------------------|-----------------------------------------------------------------------------------------|
9696
| `check-run-results` | Check run test binary `run-{pass,fail}` output snapshot | `ui`, `crashes`, `incremental` if `run-pass` | N/A |
97-
| `error-pattern` | Check that output contains a specific string | `ui`, `crashes`, `incremental` if `run-pass` | String |
97+
| `error-pattern` | Check that output contains a specific string | `ui`, `crashes`, `incremental` if `run-pass` | String |
9898
| `regex-error-pattern` | Check that output contains a regex pattern | `ui`, `crashes`, `incremental` if `run-pass` | Regex |
9999
| `check-stdout` | Check `stdout` against `error-pattern`s from running test binary[^check_stdout] | `ui`, `crashes`, `incremental` | N/A |
100100
| `normalize-stderr-32bit` | Normalize actual stderr (for 32-bit platforms) with a rule `"<raw>" -> "<normalized>"` before comparing against snapshot | `ui`, `incremental` | `"<RAW>" -> "<NORMALIZED>"`, `<RAW>`/`<NORMALIZED>` is regex capture and replace syntax |
@@ -152,6 +152,8 @@ Some examples of `X` in `ignore-X` or `only-X`:
152152
`compare-mode-split-dwarf`, `compare-mode-split-dwarf-single`
153153
- The two different test modes used by coverage tests:
154154
`ignore-coverage-map`, `ignore-coverage-run`
155+
- When testing a dist toolchain: `dist`
156+
- This needs to be enabled with `COMPILETEST_ENABLE_DIST_TESTS=1`
155157

156158
The following directives will check rustc build settings and target
157159
settings:
@@ -174,6 +176,7 @@ settings:
174176
- `needs-rust-lld` — ignores if the rust lld support is not enabled (`rust.lld =
175177
true` in `config.toml`)
176178
- `needs-threads` — ignores if the target does not have threading support
179+
- `needs-subprocess` — ignores if the target does not have subprocess support
177180
- `needs-symlink` — ignores if the target does not support symlinks. This can be
178181
the case on Windows if the developer did not enable privileged symlink
179182
permissions.

0 commit comments

Comments
 (0)