Skip to content

Commit f89d26b

Browse files
authored
Rollup merge of rust-lang#146896 - tshepang:rdg-sync, r=tshepang
rustc-dev-guide subtree update Subtree update of `rustc-dev-guide` to rust-lang/rustc-dev-guide@d76c84c. Created using https://github.com/rust-lang/josh-sync. r? `````@ghost`````
2 parents c2e11d7 + 70f3768 commit f89d26b

File tree

16 files changed

+360
-93
lines changed

16 files changed

+360
-93
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2f3f27bf79ec147fec9d2e7980605307a74067f4
1+
9f32ccf35fb877270bc44a86a126440f04d676d0

src/doc/rustc-dev-guide/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
- [Installation](./autodiff/installation.md)
109109
- [How to debug](./autodiff/debugging.md)
110110
- [Autodiff flags](./autodiff/flags.md)
111+
- [Type Trees](./autodiff/type-trees.md)
111112

112113
# Source Code Representation
113114

src/doc/rustc-dev-guide/src/about-this-guide.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ In addition, many of the ideas discussed throughout this guide are idealized des
4848
that are not fully realized yet.
4949
All this makes keeping this guide completely up to date on everything very hard!
5050

51-
The Guide itself is of course open-source as well,
52-
and the sources can be found at the [GitHub repository].
53-
If you find any mistakes in the guide, please file an issue about it.
51+
The guide itself is of course open source as well,
52+
and the sources are hosted on [a GitHub repository].
53+
If you find any mistakes in the guide, please file an issue.
5454
Even better, open a PR with a correction!
5555

5656
If you do contribute to the guide,
@@ -105,7 +105,7 @@ You might also find the following sites useful:
105105
[cheatsheet]: https://bors.rust-lang.org/
106106
[Miri]: https://github.com/rust-lang/miri
107107
[@bors]: https://github.com/bors
108-
[GitHub repository]: https://github.com/rust-lang/rustc-dev-guide/
108+
[a GitHub repository]: https://github.com/rust-lang/rustc-dev-guide/
109109
[rustc API docs]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle
110110
[Forge]: https://forge.rust-lang.org/
111111
[compiler-team]: https://github.com/rust-lang/compiler-team/

src/doc/rustc-dev-guide/src/appendix/glossary.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ Term | Meaning
6868
<span id="rib">rib</span> | A data structure in the name resolver that keeps track of a single scope for names. ([see more](../name-resolution.md))
6969
<span id="rpit">RPIT</span> | A return-position `impl Trait`. ([see the reference](https://doc.rust-lang.org/reference/types/impl-trait.html#abstract-return-types)).
7070
<span id="rpitit">RPITIT</span> | A return-position `impl Trait` in trait. Unlike RPIT, this is desugared to a generic associated type (GAT). Introduced in [RFC 3425](https://rust-lang.github.io/rfcs/3425-return-position-impl-trait-in-traits.html). ([see more](../return-position-impl-trait-in-trait.md))
71+
<span id="rustbuild">rustbuild</span> | A deprecated term for the part of bootstrap that is written in Rust
7172
<span id="scrutinee">scrutinee</span> | A scrutinee is the expression that is matched on in `match` expressions and similar pattern matching constructs. For example, in `match x { A => 1, B => 2 }`, the expression `x` is the scrutinee.
7273
<span id="sess">`sess`</span> | The compiler _session_, which stores global data used throughout compilation
7374
<span id="side-tables">side tables</span> | Because the [AST](#ast) and HIR are immutable once created, we often carry extra information about them in the form of hashtables, indexed by the id of a particular node.
Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
# TypeTrees for Autodiff
2+
3+
## What are TypeTrees?
4+
Memory layout descriptors for Enzyme. Tell Enzyme exactly how types are structured in memory so it can compute derivatives efficiently.
5+
6+
## Structure
7+
```rust
8+
TypeTree(Vec<Type>)
9+
10+
Type {
11+
offset: isize, // byte offset (-1 = everywhere)
12+
size: usize, // size in bytes
13+
kind: Kind, // Float, Integer, Pointer, etc.
14+
child: TypeTree // nested structure
15+
}
16+
```
17+
18+
## Example: `fn compute(x: &f32, data: &[f32]) -> f32`
19+
20+
**Input 0: `x: &f32`**
21+
```rust
22+
TypeTree(vec![Type {
23+
offset: -1, size: 8, kind: Pointer,
24+
child: TypeTree(vec![Type {
25+
offset: 0, size: 4, kind: Float, // Single value: use offset 0
26+
child: TypeTree::new()
27+
}])
28+
}])
29+
```
30+
31+
**Input 1: `data: &[f32]`**
32+
```rust
33+
TypeTree(vec![Type {
34+
offset: -1, size: 8, kind: Pointer,
35+
child: TypeTree(vec![Type {
36+
offset: -1, size: 4, kind: Float, // -1 = all elements
37+
child: TypeTree::new()
38+
}])
39+
}])
40+
```
41+
42+
**Output: `f32`**
43+
```rust
44+
TypeTree(vec![Type {
45+
offset: 0, size: 4, kind: Float, // Single scalar: use offset 0
46+
child: TypeTree::new()
47+
}])
48+
```
49+
50+
## Why Needed?
51+
- Enzyme can't deduce complex type layouts from LLVM IR
52+
- Prevents slow memory pattern analysis
53+
- Enables correct derivative computation for nested structures
54+
- Tells Enzyme which bytes are differentiable vs metadata
55+
56+
## What Enzyme Does With This Information:
57+
58+
Without TypeTrees:
59+
```llvm
60+
; Enzyme sees generic LLVM IR:
61+
define float @distance(ptr %p1, ptr %p2) {
62+
; Has to guess what these pointers point to
63+
; Slow analysis of all memory operations
64+
; May miss optimization opportunities
65+
}
66+
```
67+
68+
With TypeTrees:
69+
```llvm
70+
define "enzyme_type"="{[-1]:Float@float}" float @distance(
71+
ptr "enzyme_type"="{[-1]:Pointer, [-1,0]:Float@float}" %p1,
72+
ptr "enzyme_type"="{[-1]:Pointer, [-1,0]:Float@float}" %p2
73+
) {
74+
; Enzyme knows exact type layout
75+
; Can generate efficient derivative code directly
76+
}
77+
```
78+
79+
# TypeTrees - Offset and -1 Explained
80+
81+
## Type Structure
82+
83+
```rust
84+
Type {
85+
offset: isize, // WHERE this type starts
86+
size: usize, // HOW BIG this type is
87+
kind: Kind, // WHAT KIND of data (Float, Int, Pointer)
88+
child: TypeTree // WHAT'S INSIDE (for pointers/containers)
89+
}
90+
```
91+
92+
## Offset Values
93+
94+
### Regular Offset (0, 4, 8, etc.)
95+
**Specific byte position within a structure**
96+
97+
```rust
98+
struct Point {
99+
x: f32, // offset 0, size 4
100+
y: f32, // offset 4, size 4
101+
id: i32, // offset 8, size 4
102+
}
103+
```
104+
105+
TypeTree for `&Point` (internal representation):
106+
```rust
107+
TypeTree(vec![
108+
Type { offset: 0, size: 4, kind: Float }, // x at byte 0
109+
Type { offset: 4, size: 4, kind: Float }, // y at byte 4
110+
Type { offset: 8, size: 4, kind: Integer } // id at byte 8
111+
])
112+
```
113+
114+
Generates LLVM
115+
```llvm
116+
"enzyme_type"="{[-1]:Pointer, [-1,0]:Float@float, [-1,4]:Float@float, [-1,8]:Integer, [-1,9]:Integer, [-1,10]:Integer, [-1,11]:Integer}"
117+
```
118+
119+
### Offset -1 (Special: "Everywhere")
120+
**Means "this pattern repeats for ALL elements"**
121+
122+
#### Example 1: Direct Array `[f32; 100]` (no pointer indirection)
123+
```rust
124+
TypeTree(vec![Type {
125+
offset: -1, // ALL positions
126+
size: 4, // each f32 is 4 bytes
127+
kind: Float, // every element is float
128+
}])
129+
```
130+
131+
Generates LLVM: `"enzyme_type"="{[-1]:Float@float}"`
132+
133+
#### Example 1b: Array Reference `&[f32; 100]` (with pointer indirection)
134+
```rust
135+
TypeTree(vec![Type {
136+
offset: -1, size: 8, kind: Pointer,
137+
child: TypeTree(vec![Type {
138+
offset: -1, // ALL array elements
139+
size: 4, // each f32 is 4 bytes
140+
kind: Float, // every element is float
141+
}])
142+
}])
143+
```
144+
145+
Generates LLVM: `"enzyme_type"="{[-1]:Pointer, [-1,-1]:Float@float}"`
146+
147+
Instead of listing 100 separate Types with offsets `0,4,8,12...396`
148+
149+
#### Example 2: Slice `&[i32]`
150+
```rust
151+
// Pointer to slice data
152+
TypeTree(vec![Type {
153+
offset: -1, size: 8, kind: Pointer,
154+
child: TypeTree(vec![Type {
155+
offset: -1, // ALL slice elements
156+
size: 4, // each i32 is 4 bytes
157+
kind: Integer
158+
}])
159+
}])
160+
```
161+
162+
Generates LLVM: `"enzyme_type"="{[-1]:Pointer, [-1,-1]:Integer}"`
163+
164+
#### Example 3: Mixed Structure
165+
```rust
166+
struct Container {
167+
header: i64, // offset 0
168+
data: [f32; 1000], // offset 8, but elements use -1
169+
}
170+
```
171+
172+
```rust
173+
TypeTree(vec![
174+
Type { offset: 0, size: 8, kind: Integer }, // header
175+
Type { offset: 8, size: 4000, kind: Pointer,
176+
child: TypeTree(vec![Type {
177+
offset: -1, size: 4, kind: Float // ALL array elements
178+
}])
179+
}
180+
])
181+
```
182+
183+
## Key Distinction: Single Values vs Arrays
184+
185+
**Single Values** use offset `0` for precision:
186+
- `&f32` has exactly one f32 value at offset 0
187+
- More precise than using -1 ("everywhere")
188+
- Generates: `{[-1]:Pointer, [-1,0]:Float@float}`
189+
190+
**Arrays** use offset `-1` for efficiency:
191+
- `&[f32; 100]` has the same pattern repeated 100 times
192+
- Using -1 avoids listing 100 separate offsets
193+
- Generates: `{[-1]:Pointer, [-1,-1]:Float@float}`

src/doc/rustc-dev-guide/src/building/bootstrapping/writing-tools-in-bootstrap.md

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,32 @@
33
There are three types of tools you can write in bootstrap:
44

55
- **`Mode::ToolBootstrap`**
6+
67
Use this for tools that don’t need anything from the in-tree compiler and can run with the stage0 `rustc`.
7-
The output is placed in the "bootstrap-tools" directory. This mode is for general-purpose tools built
8-
entirely with the stage0 compiler, including target libraries and only works for stage 0.
8+
The output is placed in the "bootstrap-tools" directory.
9+
This mode is for general-purpose tools built entirely with the stage0 compiler,
10+
including target libraries, and it only works for stage 0.
911

1012
- **`Mode::ToolStd`**
11-
Use this for tools that rely on the locally built std. The output goes into the "stageN-tools" directory.
13+
14+
Use this for tools that rely on the locally built std.
15+
The output goes into the "stageN-tools" directory.
1216
This mode is rarely used, mainly for `compiletest` which requires `libtest`.
1317

1418
- **`Mode::ToolRustcPrivate`**
15-
Use this for tools that use the `rustc_private` mechanism, and thus depend on the locally built `rustc` and its rlib artifacts. 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::ToolRustcPrivate`, `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
16-
returned by the tool's [`Step`].
1719

18-
Regardless of the tool type you must return `ToolBuildResult` from the tool’s [`Step`] implementation and use `ToolBuild` inside it.
20+
Use this for tools that use the `rustc_private` mechanism,
21+
and thus depend on the locally built `rustc` and its rlib artifacts.
22+
This is more complex than the other modes,
23+
because the tool must be built with the same compiler used for `rustc`,
24+
and placed in the "stageN-tools" directory.
25+
When you choose `Mode::ToolRustcPrivate`,
26+
`ToolBuild` implementation takes care of this automatically.
27+
If you need to use the builder’s compiler for something specific,
28+
you can get it from `ToolBuildResult`, which is returned by the tool's [`Step`].
29+
30+
Regardless of the tool type,
31+
you must return `ToolBuildResult` from the tool’s [`Step`] implementation,
32+
and use `ToolBuild` inside it.
1933

2034
[`Step`]: https://doc.rust-lang.org/nightly/nightly-rustc/bootstrap/core/builder/trait.Step.html

src/doc/rustc-dev-guide/src/building/how-to-build-and-run.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ On Windows, the Powershell commands may give you an error that looks like this:
149149
```
150150
PS C:\Users\vboxuser\rust> ./x
151151
./x : File C:\Users\vboxuser\rust\x.ps1 cannot be loaded because running scripts is disabled on this system. For more
152-
information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
152+
information, see about_Execution_Policies at https://go.microsoft.com/fwlink/?LinkID=135170.
153153
At line:1 char:1
154154
+ ./x
155155
+ ~~~

src/doc/rustc-dev-guide/src/compiler-team.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
# About the compiler team
22

3+
> NOTE:
4+
> There exists much detail about the team [on Forge], making most of the following obsolete.
5+
36
rustc is maintained by the [Rust compiler team][team]. The people who belong to
47
this team collectively work to track regressions and implement new features.
58
Members of the Rust compiler team are people who have made significant
69
contributions to rustc and its design.
710

11+
[on Forge]: https://forge.rust-lang.org/compiler
812
[team]: https://www.rust-lang.org/governance/teams/compiler
913

1014
## Discussion

src/doc/rustc-dev-guide/src/fuzzing.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,15 @@ Here are a few things you can do to help the Rust project after filing an ICE.
9090
triggering the ICE, such as syntax errors or borrow-checking errors
9191
- Minimize the test case (see below). If successful, you can label the
9292
issue with `S-has-mcve`. Otherwise, you can apply `E-needs-mcve`.
93-
- Add the minimal test case to the rust-lang/rust repo as a [crashes test].
93+
- Add the minimal test case to the rust-lang/rust repo as a [crash test].
9494
While you're at it, consider including other "untracked" crashes in your PR.
95-
Please don't forget to mark your issue with `S-bug-has-test` afterwards.
95+
Please don't forget to mark all relevant issues with `S-bug-has-test` once
96+
your PR is merged.
9697

9798
See also [applying and removing labels][labeling].
9899

99100
[bisect]: https://rust-lang.github.io/cargo-bisect-rustc/
100-
[crashes test]: tests/compiletest.html#crashes-tests
101+
[crash test]: tests/compiletest.html#crash-tests
101102
[labeling]: https://forge.rust-lang.org/release/issue-triaging.html#applying-and-removing-labels
102103

103104
## Minimization

src/doc/rustc-dev-guide/src/profiling/with_perf.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ This is a guide for how to profile rustc with [perf](https://perf.wiki.kernel.or
44

55
## Initial steps
66

7-
- Get a clean checkout of rust-lang/master, or whatever it is you want
8-
to profile.
7+
- Get a clean checkout of rust-lang/rust
98
- Set the following settings in your `bootstrap.toml`:
109
- `rust.debuginfo-level = 1` - enables line debuginfo
1110
- `rust.jemalloc = false` - lets you do memory use profiling with valgrind

0 commit comments

Comments
 (0)