Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rustc dev guide subtree update #137642

Merged
merged 23 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b479199
Run CI multiple times a day
marxin Feb 6, 2025
28dfcd0
document bootstrap logging
jyn514 Feb 13, 2025
2d2849d
Merge pull request #2250 from jyn514/logging
jieyouxu Feb 13, 2025
7d999a5
add notes for perf issue
chenyukang Feb 14, 2025
a21ffd8
Fix borked link
marxin Feb 14, 2025
6714f1d
Start using latest release where -f checks all local links
marxin Feb 14, 2025
f8cc5d7
Merge pull request #2253 from marxin/fix-link2
JohnTitor Feb 14, 2025
27566ab
Merge pull request #2252 from chenyukang/fix-perf
jieyouxu Feb 14, 2025
dce2652
Fix examples to work with nightly-2025-02-13
torfsen Feb 15, 2025
fcfabc1
Fix CI schedule
marxin Feb 15, 2025
ba340ec
Merge pull request #2254 from marxin/start-using-latest-linkcheck2
camelid Feb 15, 2025
34db7ba
Merge pull request #2246 from marxin/CI-more-ofter
camelid Feb 15, 2025
089af67
Bump mdbook-linkcheck2 dependency version
marxin Feb 16, 2025
56f6538
Merge pull request #2257 from marxin/start-using-latest-linkcheck2-v2
tshepang Feb 16, 2025
342ced9
Merge pull request #2256 from torfsen/fix-examples-for-nightly-2025-0…
jieyouxu Feb 19, 2025
39667c5
document how to setup RA for nvim automatically
jyn514 Feb 24, 2025
25eac11
use lua locals
jyn514 Feb 24, 2025
ed2ccea
Merge pull request #2259 from jyn514/nvim-config
DianQK Feb 24, 2025
9423634
Fix posting message to Zulip
Kobzol Feb 25, 2025
5d65732
Merge pull request #2262 from Kobzol/rustc-pull-ci-fix
Kobzol Feb 25, 2025
46392d1
Preparing for merge from rustc
BoxyUwU Feb 25, 2025
d9683df
Merge from rustc
BoxyUwU Feb 25, 2025
69369a7
Merge pull request #2263 from BoxyUwU/rustc-pull2
BoxyUwU Feb 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/doc/rustc-dev-guide/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ on:
- master
pull_request:
schedule:
# Run at 18:00 UTC every day
- cron: '0 18 * * *'
# Run multiple times a day as the successfull cached links are not checked every time.
- cron: '0 */8 * * *'

jobs:
ci:
if: github.repository == 'rust-lang/rustc-dev-guide'
runs-on: ubuntu-latest
env:
MDBOOK_VERSION: 0.4.21
MDBOOK_LINKCHECK2_VERSION: 0.8.1
MDBOOK_LINKCHECK2_VERSION: 0.9.1
MDBOOK_MERMAID_VERSION: 0.12.6
MDBOOK_TOC_VERSION: 0.11.2
DEPLOY_DIR: book/html
Expand Down
2 changes: 1 addition & 1 deletion src/doc/rustc-dev-guide/.github/workflows/rustc-pull.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,4 @@ jobs:
to: 196385
type: "stream"
topic: "Subtree sync automation"
content: ${{ steps.message.outputs.message }}
content: ${{ steps.create-message.outputs.message }}
5 changes: 4 additions & 1 deletion src/doc/rustc-dev-guide/examples/README
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ For each example to compile, you will need to first run the following:

To create an executable:

rustc rustc-driver-example.rs
rustup run nightly rustc rustc-driver-example.rs

You might need to be more specific about the exact nightly version. See the comments at the top of
the examples for the version they were written for.

To run an executable:

Expand Down
14 changes: 12 additions & 2 deletions src/doc/rustc-dev-guide/examples/rustc-driver-example.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Tested with nightly-2025-02-13

#![feature(rustc_private)]

extern crate rustc_ast;
Expand Down Expand Up @@ -73,7 +75,7 @@ impl rustc_driver::Callbacks for MyCallbacks {
let hir = tcx.hir();
let item = hir.item(id);
match item.kind {
rustc_hir::ItemKind::Static(_, _, _) | rustc_hir::ItemKind::Fn(_, _, _) => {
rustc_hir::ItemKind::Static(_, _, _) | rustc_hir::ItemKind::Fn { .. } => {
let name = item.ident;
let ty = tcx.type_of(item.hir_id().owner.def_id);
println!("{name:?}:\t{ty:?}")
Expand All @@ -87,5 +89,13 @@ impl rustc_driver::Callbacks for MyCallbacks {
}

fn main() {
run_compiler(&["main.rs".to_string()], &mut MyCallbacks);
run_compiler(
&[
// The first argument, which in practice contains the name of the binary being executed
// (i.e. "rustc") is ignored by rustc.
"ignored".to_string(),
"main.rs".to_string(),
],
&mut MyCallbacks,
);
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Tested with nightly-2025-02-13

#![feature(rustc_private)]

extern crate rustc_ast;
Expand All @@ -18,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;

Expand Down Expand Up @@ -74,8 +76,8 @@ impl rustc_driver::Callbacks for MyCallbacks {
for id in hir_krate.items() {
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;
if let rustc_hir::ItemKind::Fn { body, .. } = item.kind {
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 {
Expand All @@ -94,5 +96,13 @@ impl rustc_driver::Callbacks for MyCallbacks {
}

fn main() {
run_compiler(&["main.rs".to_string()], &mut MyCallbacks);
run_compiler(
&[
// The first argument, which in practice contains the name of the binary being executed
// (i.e. "rustc") is ignored by rustc.
"ignored".to_string(),
"main.rs".to_string(),
],
&mut MyCallbacks,
);
}
8 changes: 4 additions & 4 deletions src/doc/rustc-dev-guide/examples/rustc-interface-example.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Tested with nightly-2025-02-13

#![feature(rustc_private)]

extern crate rustc_driver;
Expand All @@ -9,8 +11,6 @@ extern crate rustc_interface;
extern crate rustc_session;
extern crate rustc_span;

use std::sync::Arc;

use rustc_errors::registry;
use rustc_hash::FxHashMap;
use rustc_session::config;
Expand Down Expand Up @@ -56,7 +56,7 @@ fn main() {
expanded_args: Vec::new(),
ice_file: None,
hash_untracked_state: None,
using_internal_features: Arc::default(),
using_internal_features: &rustc_driver::USING_INTERNAL_FEATURES,
};
rustc_interface::run_compiler(config, |compiler| {
// Parse the program and print the syntax tree.
Expand All @@ -68,7 +68,7 @@ fn main() {
let hir = tcx.hir();
let item = hir.item(id);
match item.kind {
rustc_hir::ItemKind::Static(_, _, _) | rustc_hir::ItemKind::Fn(_, _, _) => {
rustc_hir::ItemKind::Static(_, _, _) | rustc_hir::ItemKind::Fn { .. } => {
let name = item.ident;
let ty = tcx.type_of(item.hir_id().owner.def_id);
println!("{name:?}:\t{ty:?}")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Tested with nightly-2025-02-13

#![feature(rustc_private)]

extern crate rustc_data_structures;
Expand All @@ -15,7 +17,7 @@ use std::sync::{Arc, Mutex};
use rustc_errors::emitter::Emitter;
use rustc_errors::registry::{self, Registry};
use rustc_errors::translation::Translate;
use rustc_errors::{DiagCtxt, DiagInner, FluentBundle};
use rustc_errors::{DiagInner, FluentBundle};
use rustc_session::config;
use rustc_span::source_map::SourceMap;

Expand Down Expand Up @@ -79,7 +81,7 @@ fn main() {
expanded_args: Vec::new(),
ice_file: None,
hash_untracked_state: None,
using_internal_features: Arc::default(),
using_internal_features: &rustc_driver::USING_INTERNAL_FEATURES,
};
rustc_interface::run_compiler(config, |compiler| {
let krate = rustc_interface::passes::parse(&compiler.sess);
Expand Down
2 changes: 1 addition & 1 deletion src/doc/rustc-dev-guide/rust-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
124cc92199ffa924f6b4c7cc819a85b65e0c3984
4ecd70ddd1039a3954056c1071e40278048476fa
Original file line number Diff line number Diff line change
@@ -1,7 +1,46 @@
# Debugging bootstrap

There are two main ways to debug bootstrap itself. The first is through println logging, and the second is through the `tracing` feature.

> FIXME: this section should be expanded

## `println` logging

Bootstrap has extensive unstructured logging. Most of it is gated behind the `--verbose` flag (pass `-vv` for even more detail).

If you want to know which `Step` ran a command, you could invoke bootstrap like so:

```
$ ./x dist rustc --dry-run -vv
learning about cargo
running: RUSTC_BOOTSTRAP="1" "/home/jyn/src/rust2/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "metadata" "--format-version" "1" "--no-deps" "--manifest-path" "/home/jyn/src/rust2/Cargo.toml" (failure_mode=Exit) (created at src/bootstrap/src/core/metadata.rs:81:25, executed at src/bootstrap/src/core/metadata.rs:92:50)
running: RUSTC_BOOTSTRAP="1" "/home/jyn/src/rust2/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "metadata" "--format-version" "1" "--no-deps" "--manifest-path" "/home/jyn/src/rust2/library/Cargo.toml" (failure_mode=Exit) (created at src/bootstrap/src/core/metadata.rs:81:25, executed at src/bootstrap/src/core/metadata.rs:92:50)
> Assemble { target_compiler: Compiler { stage: 1, host: x86_64-unknown-linux-gnu } }
> Libdir { compiler: Compiler { stage: 1, host: x86_64-unknown-linux-gnu }, target: x86_64-unknown-linux-gnu }
> Sysroot { compiler: Compiler { stage: 1, host: x86_64-unknown-linux-gnu }, force_recompile: false }
Removing sysroot /home/jyn/src/rust2/build/tmp-dry-run/x86_64-unknown-linux-gnu/stage1 to avoid caching bugs
< Sysroot { compiler: Compiler { stage: 1, host: x86_64-unknown-linux-gnu }, force_recompile: false }
< Libdir { compiler: Compiler { stage: 1, host: x86_64-unknown-linux-gnu }, target: x86_64-unknown-linux-gnu }
...
```

This will go through all the recursive dependency calculations, where `Step`s internally call `builder.ensure()`, without actually running cargo or the compiler.

In some cases, even this may not be enough logging (if so, please add more!). In that case, you can omit `--dry-run`, which will show the normal output inline with the debug logging:

```
c Sysroot { compiler: Compiler { stage: 0, host: x86_64-unknown-linux-gnu }, force_recompile: false }
using sysroot /home/jyn/src/rust2/build/x86_64-unknown-linux-gnu/stage0-sysroot
Building stage0 library artifacts (x86_64-unknown-linux-gnu)
running: cd "/home/jyn/src/rust2" && env ... RUSTC_VERBOSE="2" RUSTC_WRAPPER="/home/jyn/src/rust2/build/bootstrap/debug/rustc" "/home/jyn/src/rust2/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "build" "--target" "x86_64-unknown-linux-gnu" "-Zbinary-dep-depinfo" "-Zroot-dir=/home/jyn/src/rust2" "-v" "-v" "--manifest-path" "/home/jyn/src/rust2/library/sysroot/Cargo.toml" "--message-format" "json-render-diagnostics"
0.293440230s INFO prepare_target{force=false package_id=sysroot v0.0.0 (/home/jyn/src/rust2/library/sysroot) target="sysroot"}: cargo::core::compiler::fingerprint: fingerprint error for sysroot v0.0.0 (/home/jyn/src/rust2/library/sysroot)/Build/TargetInner { name_inferred: true, ..: lib_target("sysroot", ["lib"], "/home/jyn/src/rust2/library/sysroot/src/lib.rs", Edition2021) }
...
```

In most cases this should not be necessary.

TODO: we should convert all this to structured logging so it's easier to control precisely.

## `tracing` in bootstrap

Bootstrap has conditional [`tracing`][tracing] setup to provide structured logging.
Expand Down Expand Up @@ -53,11 +92,11 @@ Checking stage0 bootstrap artifacts (x86_64-unknown-linux-gnu)
Build completed successfully in 0:00:08
```

#### Controlling log output
#### Controlling tracing output

The env var `BOOTSTRAP_TRACING` accepts a [`tracing` env-filter][tracing-env-filter].

There are two orthogonal ways to control which kind of logs you want:
There are two orthogonal ways to control which kind of tracing logs you want:

1. You can specify the log **level**, e.g. `DEBUG` or `TRACE`.
2. You can also control the log **target**, e.g. `bootstrap` or `bootstrap::core::config` vs custom targets like `CONFIG_HANDLING`.
Expand Down
33 changes: 29 additions & 4 deletions src/doc/rustc-dev-guide/src/building/suggested.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,35 @@ create a `.vim/coc-settings.json`. The settings can be edited with
[`src/etc/rust_analyzer_settings.json`].

Another way is without a plugin, and creating your own logic in your
configuration. To do this you must translate the JSON to Lua yourself. The
translation is 1:1 and fairly straight-forward. It must be put in the
`["rust-analyzer"]` key of the setup table, which is [shown
here](https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#rust_analyzer).
configuration. The following code will work for any checkout of rust-lang/rust (newer than Febuary 2025):

```lua
lspconfig.rust_analyzer.setup {
root_dir = function()
local default = lspconfig.rust_analyzer.config_def.default_config.root_dir()
-- the default root detection uses the cargo workspace root.
-- but for rust-lang/rust, the standard library is in its own workspace.
-- use the git root instead.
local compiler_config = vim.fs.joinpath(default, "../src/bootstrap/defaults/config.compiler.toml")
if vim.fs.basename(default) == "library" and vim.uv.fs_stat(compiler_config) then
return vim.fs.dirname(default)
end
return default
end,
on_init = function(client)
local path = client.workspace_folders[1].name
local config = vim.fs.joinpath(path, "src/etc/rust_analyzer_zed.json")
if vim.uv.fs_stat(config) then
-- load rust-lang/rust settings
local file = io.open(config)
local json = vim.json.decode(file:read("*a"))
client.config.settings["rust-analyzer"] = json.lsp["rust-analyzer"].initialization_options
client.notify("workspace/didChangeConfiguration", { settings = client.config.settings })
end
return true
end
}
```

If you would like to use the build task that is described above, you may either
make your own command in your config, or you can install a plugin such as
Expand Down
2 changes: 1 addition & 1 deletion src/doc/rustc-dev-guide/src/compiler-debugging.md
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ error: layout_of(&'a u32) = Layout {
error: aborting due to previous error
```

[`Layout`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_target/abi/struct.Layout.html
[`Layout`]: https://doc.rust-lang.org/nightly/nightly-rustc/stable_mir/abi/struct.Layout.html


## Configuring CodeLLDB for debugging `rustc`
Expand Down
7 changes: 7 additions & 0 deletions src/doc/rustc-dev-guide/src/profiling/with_perf.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ you made in the beginning. But there are some things to be aware of:
- You probably don't want incremental messing about with your
profile. So something like `CARGO_INCREMENTAL=0` can be helpful.

In case to avoid the issue of `addr2line xxx/elf: could not read first record` when reading
collected data from `cargo`, you may need use the latest version of `addr2line`:

```bash
cargo install addr2line --features="bin"
```

### Gathering a perf profile from a `perf.rust-lang.org` test

Often we want to analyze a specific test from `perf.rust-lang.org`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ otherwise be printed to stderr.
To get diagnostics from the compiler,
configure [`rustc_interface::Config`] to output diagnostic to a buffer,
and run [`TyCtxt.analysis`].
The following was tested with <!-- date-check: september 2024 --> `nightly-2024-09-16`:

```rust
{{#include ../../examples/rustc-interface-getting-diagnostics.rs}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
## Getting the type of an expression

To get the type of an expression, use the [`after_analysis`] callback to get a [`TyCtxt`].
The following was tested with <!-- date-check: december 2024 --> `nightly-2024-12-15`:

```rust
{{#include ../../examples/rustc-driver-interacting-with-the-ast.rs}}
Expand Down
Loading