Skip to content

Commit bed754f

Browse files
author
The rustc-josh-sync Cronjob Bot
committed
Merge ref 'caccb4d0368b' from rust-lang/rust
Pull recent changes from https://github.com/rust-lang/rust via Josh. Upstream ref: caccb4d0368bd918ef6668af8e13834d07040417 Filtered ref: 0f345ed05d559bbfb754f1403b16199366cda2e0 Upstream diff: rust-lang/rust@21a19c2...caccb4d This merge was created using https://github.com/rust-lang/josh-sync.
2 parents 815222c + c957826 commit bed754f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+857
-443
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
if: github.repository == 'rust-lang/rustc-dev-guide'
1515
runs-on: ubuntu-latest
1616
env:
17-
MDBOOK_VERSION: 0.4.48
17+
MDBOOK_VERSION: 0.4.52
1818
MDBOOK_LINKCHECK2_VERSION: 0.9.1
1919
MDBOOK_MERMAID_VERSION: 0.12.6
2020
MDBOOK_OUTPUT__LINKCHECK__FOLLOW_WEB_LINKS: ${{ github.event_name != 'pull_request' }}

.github/workflows/rustc-pull.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ name: rustc-pull
33
on:
44
workflow_dispatch:
55
schedule:
6-
# Run at 04:00 UTC every Monday and Thursday
7-
- cron: '0 4 * * 1,4'
6+
# Run at 04:00 UTC every Monday
7+
- cron: '0 4 * * 1'
88

99
jobs:
1010
pull:

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6bcdcc73bd11568fd85f5a38b58e1eda054ad1cd
1+
9f32ccf35fb877270bc44a86a126440f04d676d0

src/SUMMARY.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,12 @@
103103
- [The `rustdoc-json` test suite](./rustdoc-internals/rustdoc-json-test-suite.md)
104104
- [GPU offload internals](./offload/internals.md)
105105
- [Installation](./offload/installation.md)
106+
- [Usage](./offload/usage.md)
106107
- [Autodiff internals](./autodiff/internals.md)
107108
- [Installation](./autodiff/installation.md)
108109
- [How to debug](./autodiff/debugging.md)
109110
- [Autodiff flags](./autodiff/flags.md)
110-
- [Current limitations](./autodiff/limitations.md)
111+
- [Type Trees](./autodiff/type-trees.md)
111112

112113
# Source Code Representation
113114

src/about-this-guide.md

Lines changed: 5 additions & 6 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,
@@ -73,8 +73,7 @@ You might also find the following sites useful:
7373
- [compiler-team] -- the home-base for the Rust compiler team, with description
7474
of the team procedures, active working groups, and the team calendar.
7575
- [std-dev-guide] -- a similar guide for developing the standard library.
76-
- [The t-compiler zulip][z]
77-
- `#contribute` and `#wg-rustup` on [Discord](https://discord.gg/rust-lang).
76+
- [The t-compiler Zulip][z]
7877
- The [Rust Internals forum][rif], a place to ask questions and
7978
discuss Rust's internals
8079
- The [Rust reference][rr], even though it doesn't specifically talk about
@@ -106,7 +105,7 @@ You might also find the following sites useful:
106105
[cheatsheet]: https://bors.rust-lang.org/
107106
[Miri]: https://github.com/rust-lang/miri
108107
[@bors]: https://github.com/bors
109-
[GitHub repository]: https://github.com/rust-lang/rustc-dev-guide/
108+
[a GitHub repository]: https://github.com/rust-lang/rustc-dev-guide/
110109
[rustc API docs]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle
111110
[Forge]: https://forge.rust-lang.org/
112111
[compiler-team]: https://github.com/rust-lang/compiler-team/

src/appendix/code-index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Item | Kind | Short description | Chapter |
1313
`DefId` | struct | One of four types of HIR node identifiers | [Identifiers in the HIR] | [compiler/rustc_hir/src/def_id.rs](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/def_id/struct.DefId.html)
1414
`Diag` | struct | A struct for a compiler diagnostic, such as an error or lint | [Emitting Diagnostics] | [compiler/rustc_errors/src/diagnostic.rs](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_errors/struct.Diag.html)
1515
`DocContext` | struct | A state container used by rustdoc when crawling through a crate to gather its documentation | [Rustdoc] | [src/librustdoc/core.rs](https://github.com/rust-lang/rust/blob/master/src/librustdoc/core.rs)
16-
`HirId` | struct | One of four types of HIR node identifiers | [Identifiers in the HIR] | [compiler/rustc_hir/src/hir_id.rs](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/hir_id/struct.HirId.html)
16+
`HirId` | struct | One of four types of HIR node identifiers | [Identifiers in the HIR] | [compiler/rustc_hir_id/src/lib.rs](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/struct.HirId.html)
1717
`Lexer` | struct | This is the lexer used during parsing. It consumes characters from the raw source code being compiled and produces a series of tokens for use by the rest of the parser | [The parser] | [compiler/rustc_parse/src/lexer/mod.rs](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_parse/lexer/struct.Lexer.html)
1818
`NodeId` | struct | One of four types of HIR node identifiers. Being phased out | [Identifiers in the HIR] | [compiler/rustc_ast/src/ast.rs](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast/node_id/struct.NodeId.html)
1919
`P` | struct | An owned immutable smart pointer. By contrast, `&T` is not owned, and `Box<T>` is not immutable. | None | [compiler/rustc_ast/src/ptr.rs](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast/ptr/struct.P.html)

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.

src/autodiff/internals.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn main() {
1717

1818
The detailed documentation for the `std::autodiff` module is available at [std::autodiff](https://doc.rust-lang.org/std/autodiff/index.html).
1919

20-
Differentiable programing is used in various fields like numerical computing, [solid mechanics][ratel], [computational chemistry][molpipx], [fluid dynamics][waterlily] or for Neural Network training via Backpropagation, [ODE solver][diffsol], [differentiable rendering][libigl], [quantum computing][catalyst], and climate simulations.
20+
Differentiable programming is used in various fields like numerical computing, [solid mechanics][ratel], [computational chemistry][molpipx], [fluid dynamics][waterlily] or for Neural Network training via Backpropagation, [ODE solver][diffsol], [differentiable rendering][libigl], [quantum computing][catalyst], and climate simulations.
2121

2222
[ratel]: https://gitlab.com/micromorph/ratel
2323
[molpipx]: https://arxiv.org/abs/2411.17011v

src/autodiff/limitations.md

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/autodiff/type-trees.md

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}`

0 commit comments

Comments
 (0)