Skip to content

Commit b7ffa50

Browse files
authored
Unrolled build for rust-lang#140044
Rollup merge of rust-lang#140044 - tshepang:rdg-push, r=jieyouxu rustc-dev-guide subtree update r? ``@ghost``
2 parents b8c54d6 + 976d13f commit b7ffa50

34 files changed

+517
-111
lines changed

Diff for: src/doc/rustc-dev-guide/README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ rustdocs][rustdocs].
4343
To build a local static HTML site, install [`mdbook`](https://github.com/rust-lang/mdBook) with:
4444

4545
```
46-
> cargo install mdbook mdbook-linkcheck2 mdbook-toc mdbook-mermaid
46+
cargo install mdbook mdbook-linkcheck2 mdbook-toc mdbook-mermaid
4747
```
4848

4949
and execute the following command in the root of the repository:
5050

5151
```
52-
> mdbook build --open
52+
mdbook build --open
5353
```
5454

5555
The build files are found in the `book/html` directory.
@@ -61,8 +61,8 @@ checking is **not** run by default locally, though it is in CI. To enable it
6161
locally, set the environment variable `ENABLE_LINKCHECK=1` like in the
6262
following example.
6363

64-
```console
65-
$ ENABLE_LINKCHECK=1 mdbook serve
64+
```
65+
ENABLE_LINKCHECK=1 mdbook serve
6666
```
6767

6868
### Table of Contents
@@ -86,14 +86,14 @@ Older versions of `josh-proxy` may not round trip commits losslessly so it is im
8686
1) Checkout a new branch that will be used to create a PR into `rust-lang/rustc-dev-guide`
8787
2) Run the pull command
8888
```
89-
$ cargo run --manifest-path josh-sync/Cargo.toml rustc-pull
89+
cargo run --manifest-path josh-sync/Cargo.toml rustc-pull
9090
```
9191
3) Push the branch to your fork and create a PR into `rustc-dev-guide`
9292
9393
### Push changes from this repository into `rust-lang/rust`
9494
1) Run the push command to create a branch named `<branch-name>` in a `rustc` fork under the `<gh-username>` account
9595
```
96-
$ cargo run --manifest-path josh-sync/Cargo.toml rustc-push <branch-name> <gh-username>
96+
cargo run --manifest-path josh-sync/Cargo.toml rustc-push <branch-name> <gh-username>
9797
```
9898
2) Create a PR from `<branch-name>` into `rust-lang/rust`
9999
@@ -106,5 +106,5 @@ You may observe "Nothing to pull" even if you *know* rustc-pull has something to
106106
To minimize the likelihood of this happening, you may wish to keep a separate *minimal* git config that *only* has `[user]` entries from global git config, then repoint system git to use the minimal git config instead. E.g.
107107
108108
```
109-
$ GIT_CONFIG_GLOBAL=/path/to/minimal/gitconfig GIT_CONFIG_SYSTEM='' cargo +stable run --manifest-path josh-sync/Cargo.toml -- rustc-pull
109+
GIT_CONFIG_GLOBAL=/path/to/minimal/gitconfig GIT_CONFIG_SYSTEM='' cargo +stable run --manifest-path josh-sync/Cargo.toml -- rustc-pull
110110
```

Diff for: src/doc/rustc-dev-guide/rust-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
25a615bf829b9f6d6f22da537e3851043f92e5f2
1+
a7c39b68616668a45f0afd62849a1da7c8ad2516

Diff for: src/doc/rustc-dev-guide/src/SUMMARY.md

+27-20
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
- [How to build and run the compiler](./building/how-to-build-and-run.md)
1111
- [Quickstart](./building/quickstart.md)
1212
- [Prerequisites](./building/prerequisites.md)
13-
- [Suggested Workflows](./building/suggested.md)
13+
- [Suggested workflows](./building/suggested.md)
1414
- [Distribution artifacts](./building/build-install-distribution-artifacts.md)
15-
- [Building Documentation](./building/compiler-documenting.md)
15+
- [Building documentation](./building/compiler-documenting.md)
1616
- [Rustdoc overview](./rustdoc.md)
1717
- [Adding a new target](./building/new-target.md)
1818
- [Optimized build](./building/optimized-build.md)
@@ -42,11 +42,11 @@
4242
- [with the linux perf tool](./profiling/with_perf.md)
4343
- [with Windows Performance Analyzer](./profiling/wpa_profiling.md)
4444
- [with the Rust benchmark suite](./profiling/with_rustc_perf.md)
45-
- [crates.io Dependencies](./crates-io.md)
45+
- [crates.io dependencies](./crates-io.md)
4646

4747
# Contributing to Rust
4848

49-
- [Contribution Procedures](./contributing.md)
49+
- [Contribution procedures](./contributing.md)
5050
- [About the compiler team](./compiler-team.md)
5151
- [Using Git](./git.md)
5252
- [Mastering @rustbot](./rustbot.md)
@@ -56,7 +56,7 @@
5656
- [Stabilizing Features](./stabilization_guide.md)
5757
- [Feature Gates](./feature-gates.md)
5858
- [Coding conventions](./conventions.md)
59-
- [Procedures for Breaking Changes](./bug-fix-procedure.md)
59+
- [Procedures for breaking changes](./bug-fix-procedure.md)
6060
- [Using external repositories](./external-repos.md)
6161
- [Fuzzing](./fuzzing.md)
6262
- [Notification groups](notification-groups/about.md)
@@ -81,36 +81,43 @@
8181
- [How Bootstrap does it](./building/bootstrapping/how-bootstrap-does-it.md)
8282
- [Writing tools in Bootstrap](./building/bootstrapping/writing-tools-in-bootstrap.md)
8383
- [Debugging bootstrap](./building/bootstrapping/debugging-bootstrap.md)
84+
- [cfg(bootstrap) in dependencies](./building/bootstrapping/bootstrap-in-dependencies.md)
8485

8586
# High-level Compiler Architecture
8687

8788
- [Prologue](./part-2-intro.md)
8889
- [Overview of the compiler](./overview.md)
8990
- [The compiler source code](./compiler-src.md)
9091
- [Queries: demand-driven compilation](./query.md)
91-
- [The Query Evaluation Model in Detail](./queries/query-evaluation-model-in-detail.md)
92+
- [The Query Evaluation Model in detail](./queries/query-evaluation-model-in-detail.md)
9293
- [Incremental compilation](./queries/incremental-compilation.md)
93-
- [Incremental compilation In Detail](./queries/incremental-compilation-in-detail.md)
94-
- [Debugging and Testing](./incrcomp-debugging.md)
94+
- [Incremental compilation in detail](./queries/incremental-compilation-in-detail.md)
95+
- [Debugging and testing](./incrcomp-debugging.md)
9596
- [Salsa](./queries/salsa.md)
96-
- [Memory Management in Rustc](./memory.md)
97-
- [Serialization in Rustc](./serialization.md)
98-
- [Parallel Compilation](./parallel-rustc.md)
97+
- [Memory management in rustc](./memory.md)
98+
- [Serialization in rustc](./serialization.md)
99+
- [Parallel compilation](./parallel-rustc.md)
99100
- [Rustdoc internals](./rustdoc-internals.md)
100101
- [Search](./rustdoc-internals/search.md)
101102
- [The `rustdoc` test suite](./rustdoc-internals/rustdoc-test-suite.md)
103+
- [Autodiff internals](./autodiff/internals.md)
104+
- [Installation](./autodiff/installation.md)
105+
- [How to debug](./autodiff/debugging.md)
106+
- [Autodiff flags](./autodiff/flags.md)
107+
- [Current limitations](./autodiff/limitations.md)
108+
102109
# Source Code Representation
103110

104111
- [Prologue](./part-3-intro.md)
105112
- [Syntax and the AST](./syntax-intro.md)
106-
- [Lexing and Parsing](./the-parser.md)
113+
- [Lexing and parsing](./the-parser.md)
107114
- [Macro expansion](./macro-expansion.md)
108115
- [Name resolution](./name-resolution.md)
109116
- [Attributes](./attributes.md)
110-
- [`#[test]` Implementation](./test-implementation.md)
111-
- [Panic Implementation](./panic-implementation.md)
112-
- [AST Validation](./ast-validation.md)
113-
- [Feature Gate Checking](./feature-gate-ck.md)
117+
- [`#[test]` implementation](./test-implementation.md)
118+
- [Panic implementation](./panic-implementation.md)
119+
- [AST validation](./ast-validation.md)
120+
- [Feature gate checking](./feature-gate-ck.md)
114121
- [Lang Items](./lang-items.md)
115122
- [The HIR (High-level IR)](./hir.md)
116123
- [Lowering AST to HIR](./ast-lowering.md)
@@ -129,7 +136,7 @@
129136
- [Example: Type checking](./rustc-driver/interacting-with-the-ast.md)
130137
- [Example: Getting diagnostics](./rustc-driver/getting-diagnostics.md)
131138
- [Remarks on perma-unstable features](./rustc-driver/remarks-on-perma-unstable-features.md)
132-
- [Errors and Lints](diagnostics.md)
139+
- [Errors and lints](diagnostics.md)
133140
- [Diagnostic and subdiagnostic structs](./diagnostics/diagnostic-structs.md)
134141
- [Translation](./diagnostics/translation.md)
135142
- [`LintStore`](./diagnostics/lintstore.md)
@@ -175,14 +182,14 @@
175182
- [Type checking](./type-checking.md)
176183
- [Method Lookup](./method-lookup.md)
177184
- [Variance](./variance.md)
178-
- [Coherence Checking](./coherence.md)
179-
- [Opaque Types](./opaque-types-type-alias-impl-trait.md)
185+
- [Coherence checking](./coherence.md)
186+
- [Opaque types](./opaque-types-type-alias-impl-trait.md)
180187
- [Inference details](./opaque-types-impl-trait-inference.md)
181188
- [Return Position Impl Trait In Trait](./return-position-impl-trait-in-trait.md)
182189
- [Region inference restrictions][opaque-infer]
183190
- [Const condition checking](./effects.md)
184191
- [Pattern and Exhaustiveness Checking](./pat-exhaustive-checking.md)
185-
- [Unsafety Checking](./unsafety-checking.md)
192+
- [Unsafety checking](./unsafety-checking.md)
186193
- [MIR dataflow](./mir/dataflow.md)
187194
- [Drop elaboration](./mir/drop-elaboration.md)
188195
- [The borrow checker](./borrow_check.md)

Diff for: src/doc/rustc-dev-guide/src/about-this-guide.md

+22-14
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,41 @@
33
This guide is meant to help document how rustc – the Rust compiler – works,
44
as well as to help new contributors get involved in rustc development.
55

6-
There are seven parts to this guide:
6+
There are several parts to this guide:
77

8-
1. [Building `rustc`][p1]:
8+
1. [Building and debugging `rustc`][p1]:
99
Contains information that should be useful no matter how you are contributing,
1010
about building, debugging, profiling, etc.
11-
2. [Contributing to `rustc`][p2]:
11+
1. [Contributing to Rust][p2]:
1212
Contains information that should be useful no matter how you are contributing,
1313
about procedures for contribution, using git and Github, stabilizing features, etc.
14-
3. [High-Level Compiler Architecture][p3]:
14+
1. [Bootstrapping][p3]:
15+
Describes how the Rust compiler builds itself using previous versions, including
16+
an introduction to the bootstrap process and debugging methods.
17+
1. [High-level Compiler Architecture][p4]:
1518
Discusses the high-level architecture of the compiler and stages of the compile process.
16-
4. [Source Code Representation][p4]:
19+
1. [Source Code Representation][p5]:
1720
Describes the process of taking raw source code from the user
1821
and transforming it into various forms that the compiler can work with easily.
19-
5. [Analysis][p5]:
20-
discusses the analyses that the compiler uses to check various properties of the code
22+
1. [Supporting Infrastructure][p6]:
23+
Covers command-line argument conventions, compiler entry points like rustc_driver and
24+
rustc_interface, and the design and implementation of errors and lints.
25+
1. [Analysis][p7]:
26+
Discusses the analyses that the compiler uses to check various properties of the code
2127
and inform later stages of the compile process (e.g., type checking).
22-
6. [From MIR to Binaries][p6]: How linked executable machine code is generated.
23-
7. [Appendices][p7] at the end with useful reference information.
28+
1. [MIR to Binaries][p8]: How linked executable machine code is generated.
29+
1. [Appendices][p9] at the end with useful reference information.
2430
There are a few of these with different information, including a glossary.
2531

2632
[p1]: ./building/how-to-build-and-run.html
2733
[p2]: ./contributing.md
28-
[p3]: ./part-2-intro.md
29-
[p4]: ./part-3-intro.md
30-
[p5]: ./part-4-intro.md
31-
[p6]: ./part-5-intro.md
32-
[p7]: ./appendix/background.md
34+
[p3]: ./building/bootstrapping/intro.md
35+
[p4]: ./part-2-intro.md
36+
[p5]: ./part-3-intro.md
37+
[p6]: ./cli.md
38+
[p7]: ./part-4-intro.md
39+
[p8]: ./part-5-intro.md
40+
[p9]: ./appendix/background.md
3341

3442
### Constant change
3543

Diff for: src/doc/rustc-dev-guide/src/ast-validation.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# AST Validation
1+
# AST validation
22

33
_AST validation_ is a separate AST pass that visits each
44
item in the tree and performs simple checks. This pass

Diff for: src/doc/rustc-dev-guide/src/autodiff/debugging.md

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# Reporting backend crashes
2+
3+
If after a compilation failure you are greeted by a large amount of llvm-ir code, then our enzyme backend likely failed to compile your code. These cases are harder to debug, so your help is highly appreciated. Please also keep in mind that release builds are usually much more likely to work at the moment.
4+
5+
The final goal here is to reproduce your bug in the enzyme [compiler explorer](https://enzyme.mit.edu/explorer/), in order to create a bug report in the [Enzyme](https://github.com/enzymead/enzyme/issues) repository.
6+
7+
We have an `autodiff` flag which you can pass to `rustflags` to help with this. it will print the whole llvm-ir module, along with some `__enzyme_fwddiff` or `__enzyme_autodiff` calls. A potential workflow on linux could look like:
8+
9+
## Controlling llvm-ir generation
10+
11+
Before generating the llvm-ir, keep in mind two techniques that can help ensure the relevant rust code is visible for debugging:
12+
13+
- **`std::hint::black_box`**: wrap rust variables or expressions in `std::hint::black_box()` to prevent rust and llvm from optimizing them away. This is useful when you need to inspect or manually manipulate specific values in the llvm-ir.
14+
- **`extern "rust"` or `extern "c"`**: if you want to see how a specific function declaration is lowered to llvm-ir, you can declare it as `extern "rust"` or `extern "c"`. You can also look for existing `__enzyme_autodiff` or similar declarations within the generated module for examples.
15+
16+
## 1) Generate an llvm-ir reproducer
17+
18+
```sh
19+
rustflags="-z autodiff=enable,printmodbefore" cargo +enzyme build --release &> out.ll
20+
```
21+
22+
This also captures a few warnings and info messages above and below your module. open out.ll and remove every line above `; moduleid = <somehash>`. Now look at the end of the file and remove everything that's not part of llvm-ir, i.e. remove errors and warnings. The last line of your llvm-ir should now start with `!<somenumber> = `, i.e. `!40831 = !{i32 0, i32 1037508, i32 1037538, i32 1037559}` or `!43760 = !dilocation(line: 297, column: 5, scope: !43746)`.
23+
24+
The actual numbers will depend on your code.
25+
26+
## 2) Check your llvm-ir reproducer
27+
28+
To confirm that your previous step worked, we will use llvm's `opt` tool. find your path to the opt binary, with a path similar to `<some_dir>/rust/build/<x86/arm/...-target-tripple>/build/bin/opt`. also find `llvmenzyme-19.<so/dll/dylib>` path, similar to `/rust/build/target-tripple/enzyme/build/enzyme/llvmenzyme-19`. Please keep in mind that llvm frequently updates it's llvm backend, so the version number might be higher (20, 21, ...). Once you have both, run the following command:
29+
30+
```sh
31+
<path/to/opt> out.ll -load-pass-plugin=/path/to/llvmenzyme-19.so -passes="enzyme" -s
32+
```
33+
34+
If the previous step succeeded, you are going to see the same error that you saw when compiling your rust code with cargo.
35+
36+
If you fail to get the same error, please open an issue in the rust repository. If you succeed, congrats! the file is still huge, so let's automatically minimize it.
37+
38+
## 3) Minimize your llvm-ir reproducer
39+
40+
First find your `llvm-extract` binary, it's in the same folder as your opt binary. then run:
41+
42+
```sh
43+
<path/to/llvm-extract> -s --func=<name> --recursive --rfunc="enzyme_autodiff*" --rfunc="enzyme_fwddiff*" --rfunc=<fnc_called_by_enzyme> out.ll -o mwe.ll
44+
```
45+
46+
This command creates `mwe.ll`, a minimal working example.
47+
48+
Please adjust the name passed with the last `--func` flag. You can either apply the `#[no_mangle]` attribute to the function you differentiate, then you can replace it with the rust name. otherwise you will need to look up the mangled function name. To do that, open `out.ll` and search for `__enzyme_fwddiff` or `__enzyme_autodiff`. the first string in that function call is the name of your function. example:
49+
50+
```llvm-ir
51+
define double @enzyme_opt_helper_0(ptr %0, i64 %1, double %2) {
52+
%4 = call double (...) @__enzyme_fwddiff(ptr @_zn2ad3_f217h3b3b1800bd39fde3e, metadata !"enzyme_const", ptr %0, metadata !"enzyme_const", i64 %1, metadata !"enzyme_dup", double %2, double %2)
53+
ret double %4
54+
}
55+
```
56+
57+
Here, `_zn2ad3_f217h3b3b1800bd39fde3e` is the correct name. make sure to not copy the leading `@`. redo step 2) by running the `opt` command again, but this time passing `mwe.ll` as the input file instead of `out.ll`. Check if this minimized example still reproduces the crash.
58+
59+
## 4) (Optional) Minimize your llvm-ir reproducer further.
60+
61+
After the previous step you should have an `mwe.ll` file with ~5k loc. let's try to get it down to 50. find your `llvm-reduce` binary next to `opt` and `llvm-extract`. Copy the first line of your error message, an example could be:
62+
63+
```sh
64+
opt: /home/manuel/prog/rust/src/llvm-project/llvm/lib/ir/instructions.cpp:686: void llvm::callinst::init(llvm::functiontype*, llvm::value*, llvm::arrayref<llvm::value*>, llvm::arrayref<llvm::operandbundledeft<llvm::value*> >, const llvm::twine&): assertion `(args.size() == fty->getnumparams() || (fty->isvararg() && args.size() > fty->getnumparams())) && "calling a function with bad signature!"' failed.
65+
```
66+
67+
If you just get a `segfault` there is no sensible error message and not much to do automatically, so continue to 5).
68+
otherwise, create a `script.sh` file containing
69+
70+
```sh
71+
#!/bin/bash
72+
<path/to/your/opt> $1 -load-pass-plugin=/path/to/llvmenzyme-19.so -passes="enzyme" \
73+
|& grep "/some/path.cpp:686: void llvm::callinst::init"
74+
```
75+
76+
Experiment a bit with which error message you pass to grep. it should be long enough to make sure that the error is unique. However, for longer errors including `(` or `)` you will need to escape them correctly which can become annoying. Run
77+
78+
```sh
79+
<path/to/llvm-reduce> --test=script.sh mwe.ll
80+
```
81+
82+
If you see `input isn't interesting! verify interesting-ness test`, you got the error message in script.sh wrong, you need to make sure that grep matches your actual error. If all works out, you will see a lot of iterations, ending with a new `reduced.ll` file. Verify with `opt` that you still get the same error.
83+
84+
### Advanced debugging: manual llvm-ir investigation
85+
86+
Once you have a minimized reproducer (`mwe.ll` or `reduced.ll`), you can delve deeper:
87+
88+
- **manual editing:** try manually rewriting the llvm-ir. for certain issues, like those involving indirect calls, you might investigate enzyme-specific intrinsics like `__enzyme_virtualreverse`. Understanding how to use these might require consulting enzyme's documentation or source code.
89+
- **enzyme test cases:** look for relevant test cases within the [enzyme repository](https://github.com/enzymead/enzyme/tree/main/enzyme/test) that might demonstrate the correct usage of features or intrinsics related to your problem.
90+
91+
## 5) Report your bug.
92+
93+
Afterwards, you should be able to copy and paste your `mwe.ll` (or `reduced.ll`) example into our [compiler explorer](https://enzyme.mit.edu/explorer/).
94+
95+
- Select `llvm ir` as language and `opt 20` as compiler.
96+
- Replace the field to the right of your compiler with `-passes="enzyme"`, if it is not already set.
97+
- Hopefully, you will see once again your now familiar error.
98+
- Please use the share button to copy links to them.
99+
- Please create an issue on [https://github.com/enzymead/enzyme/issues](https://github.com/enzymead/enzyme/issues) and share `mwe.ll` and (if you have it) `reduced.ll`, as well as links to the compiler explorer. Please feel free to also add your rust code or a link to it.
100+
101+
#### Documenting findings
102+
103+
some enzyme errors, like `"attempting to call an indirect active function whose runtime value is inactive"`, have historically caused confusion. If you investigate such an issue, even if you don't find a complete solution, please consider documenting your findings. If the insights are general to enzyme and not specific to its rust usage, contributing them to the main [enzyme documentation](https://github.com/enzymead/www) is often the best first step. You can also mention your findings in the relevant enzyme github issue or propose updates to these docs if appropriate. This helps prevent others from starting from scratch.
104+
105+
With a clear reproducer and documentation, hopefully an enzyme developer will be able to fix your bug. Once that happens, the enzyme submodule inside the rust compiler will be updated, which should allow you to differentiate your rust code. Thanks for helping us to improve rust-ad.
106+
107+
# Minimize rust code
108+
109+
Beyond having a minimal llvm-ir reproducer, it is also helpful to have a minimal rust reproducer without dependencies. This allows us to add it as a test case to ci once we fix it, which avoids regressions for the future.
110+
111+
There are a few solutions to help you with minimizing the rust reproducer. This is probably the most simple automated approach: [cargo-minimize](https://github.com/nilstrieb/cargo-minimize).
112+
113+
Otherwise we have various alternatives, including [`treereduce`](https://github.com/langston-barrett/treereduce), [`halfempty`](https://github.com/googleprojectzero/halfempty), or [`picireny`](https://github.com/renatahodovan/picireny), potentially also [`creduce`](https://github.com/csmith-project/creduce).

0 commit comments

Comments
 (0)