Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
0dc233f
point to Compiler team docs on Forge
tshepang Sep 6, 2025
1806a82
remove confusing parts of sentence
tshepang Sep 8, 2025
755db7f
sembr
tshepang Sep 8, 2025
cb0e26f
fix markup
tshepang Sep 8, 2025
94da520
readability
tshepang Sep 8, 2025
8c324de
Merge pull request #2585 from rust-lang/tshepang/sembr
tshepang Sep 8, 2025
a5575f8
Fix broken Microsoft URL missing slash
ali90h Sep 8, 2025
808595e
Merge pull request #2586 from ali90h/fix-microsoft-link-broken-url
Noratrieb Sep 8, 2025
096ae06
glossary: add entry for rustbuild
lolbinarycat Jul 22, 2025
196b49a
glossary(rustbuild): reword according to code review
lolbinarycat Sep 10, 2025
82ff002
Add missing documentation for running tests with GCC backend
GuillaumeGomez Sep 10, 2025
76c4d68
Merge pull request #2516 from lolbinarycat/patch-4
tshepang Sep 10, 2025
d8f0842
docs: typetree in autodiff
KMJ-007 May 13, 2025
ff59107
Merge pull request #2385 from KMJ-007/master
ZuseZ4 Sep 11, 2025
d588c11
Restructure the docs
Kobzol Sep 11, 2025
7a4b728
Rename "crashes tests" to "crash tests"
fmease Sep 12, 2025
ddfd47a
Merge pull request #2588 from fmease/to-crash-tests
fmease Sep 12, 2025
ee63b07
Merge pull request #2584 from rust-lang/tshepang-patch-5
Noratrieb Sep 12, 2025
7b0b0bb
Clarify that backtick escaping doesn't work for `@bors try jobs`
Kobzol Sep 15, 2025
001f8e3
Update src/tests/ci.md
Kobzol Sep 15, 2025
3a14fb7
Merge pull request #2589 from Kobzol/ci-bors-backticks
Kobzol Sep 15, 2025
ee496f2
a valid state is achieved by passing the test suite
tshepang Sep 17, 2025
cea82e3
Merge pull request #2591 from rust-lang/tshepang-patch-5
Noratrieb Sep 17, 2025
b17213a
about-this-guide.md: improve a bit
tshepang Sep 17, 2025
66a84ef
Merge pull request #2592 from rust-lang/tshepang-patch-5
tshepang Sep 17, 2025
9819cea
Merge pull request #2587 from GuillaumeGomez/gcc-backend-missing-docs
GuillaumeGomez Sep 18, 2025
72b0291
Merge pull request #2580 from rust-lang/tshepang-patch-2
jieyouxu Sep 19, 2025
d887c57
Correct a misspelling of RUSTC_LOG
cammeresi Sep 21, 2025
a11333a
Merge pull request #2594 from cammeresi/spelling-20250921
tshepang Sep 21, 2025
5658b39
Prepare for merging from rust-lang/rust
invalid-email-address Sep 22, 2025
c3d3074
Merge ref '9f32ccf35fb8' from rust-lang/rust
invalid-email-address Sep 22, 2025
391a2ea
Merge pull request #2595 from rust-lang/rustc-pull
tshepang Sep 22, 2025
62b2bd5
reduce overlong lines
tshepang Sep 22, 2025
45f891d
Merge pull request #2596 from rust-lang/tshepang/sembr
tshepang Sep 22, 2025
1e2594f
various improvements resulting from reading Testing with CI
tshepang Sep 22, 2025
70f3768
Merge pull request #2593 from rust-lang/tshepang/testing-with-ci
tshepang Sep 22, 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
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 @@
2f3f27bf79ec147fec9d2e7980605307a74067f4
9f32ccf35fb877270bc44a86a126440f04d676d0
1 change: 1 addition & 0 deletions src/doc/rustc-dev-guide/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
- [Installation](./autodiff/installation.md)
- [How to debug](./autodiff/debugging.md)
- [Autodiff flags](./autodiff/flags.md)
- [Type Trees](./autodiff/type-trees.md)

# Source Code Representation

Expand Down
8 changes: 4 additions & 4 deletions src/doc/rustc-dev-guide/src/about-this-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ In addition, many of the ideas discussed throughout this guide are idealized des
that are not fully realized yet.
All this makes keeping this guide completely up to date on everything very hard!

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

If you do contribute to the guide,
Expand Down Expand Up @@ -105,7 +105,7 @@ You might also find the following sites useful:
[cheatsheet]: https://bors.rust-lang.org/
[Miri]: https://github.com/rust-lang/miri
[@bors]: https://github.com/bors
[GitHub repository]: https://github.com/rust-lang/rustc-dev-guide/
[a GitHub repository]: https://github.com/rust-lang/rustc-dev-guide/
[rustc API docs]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle
[Forge]: https://forge.rust-lang.org/
[compiler-team]: https://github.com/rust-lang/compiler-team/
Expand Down
1 change: 1 addition & 0 deletions src/doc/rustc-dev-guide/src/appendix/glossary.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Term | Meaning
<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))
<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)).
<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))
<span id="rustbuild">rustbuild</span> | A deprecated term for the part of bootstrap that is written in Rust
<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.
<span id="sess">`sess`</span> | The compiler _session_, which stores global data used throughout compilation
<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.
Expand Down
193 changes: 193 additions & 0 deletions src/doc/rustc-dev-guide/src/autodiff/type-trees.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
# TypeTrees for Autodiff

## What are TypeTrees?
Memory layout descriptors for Enzyme. Tell Enzyme exactly how types are structured in memory so it can compute derivatives efficiently.

## Structure
```rust
TypeTree(Vec<Type>)

Type {
offset: isize, // byte offset (-1 = everywhere)
size: usize, // size in bytes
kind: Kind, // Float, Integer, Pointer, etc.
child: TypeTree // nested structure
}
```

## Example: `fn compute(x: &f32, data: &[f32]) -> f32`

**Input 0: `x: &f32`**
```rust
TypeTree(vec![Type {
offset: -1, size: 8, kind: Pointer,
child: TypeTree(vec![Type {
offset: 0, size: 4, kind: Float, // Single value: use offset 0
child: TypeTree::new()
}])
}])
```

**Input 1: `data: &[f32]`**
```rust
TypeTree(vec![Type {
offset: -1, size: 8, kind: Pointer,
child: TypeTree(vec![Type {
offset: -1, size: 4, kind: Float, // -1 = all elements
child: TypeTree::new()
}])
}])
```

**Output: `f32`**
```rust
TypeTree(vec![Type {
offset: 0, size: 4, kind: Float, // Single scalar: use offset 0
child: TypeTree::new()
}])
```

## Why Needed?
- Enzyme can't deduce complex type layouts from LLVM IR
- Prevents slow memory pattern analysis
- Enables correct derivative computation for nested structures
- Tells Enzyme which bytes are differentiable vs metadata

## What Enzyme Does With This Information:

Without TypeTrees:
```llvm
; Enzyme sees generic LLVM IR:
define float @distance(ptr %p1, ptr %p2) {
; Has to guess what these pointers point to
; Slow analysis of all memory operations
; May miss optimization opportunities
}
```

With TypeTrees:
```llvm
define "enzyme_type"="{[-1]:Float@float}" float @distance(
ptr "enzyme_type"="{[-1]:Pointer, [-1,0]:Float@float}" %p1,
ptr "enzyme_type"="{[-1]:Pointer, [-1,0]:Float@float}" %p2
) {
; Enzyme knows exact type layout
; Can generate efficient derivative code directly
}
```

# TypeTrees - Offset and -1 Explained

## Type Structure

```rust
Type {
offset: isize, // WHERE this type starts
size: usize, // HOW BIG this type is
kind: Kind, // WHAT KIND of data (Float, Int, Pointer)
child: TypeTree // WHAT'S INSIDE (for pointers/containers)
}
```

## Offset Values

### Regular Offset (0, 4, 8, etc.)
**Specific byte position within a structure**

```rust
struct Point {
x: f32, // offset 0, size 4
y: f32, // offset 4, size 4
id: i32, // offset 8, size 4
}
```

TypeTree for `&Point` (internal representation):
```rust
TypeTree(vec![
Type { offset: 0, size: 4, kind: Float }, // x at byte 0
Type { offset: 4, size: 4, kind: Float }, // y at byte 4
Type { offset: 8, size: 4, kind: Integer } // id at byte 8
])
```

Generates LLVM
```llvm
"enzyme_type"="{[-1]:Pointer, [-1,0]:Float@float, [-1,4]:Float@float, [-1,8]:Integer, [-1,9]:Integer, [-1,10]:Integer, [-1,11]:Integer}"
```

### Offset -1 (Special: "Everywhere")
**Means "this pattern repeats for ALL elements"**

#### Example 1: Direct Array `[f32; 100]` (no pointer indirection)
```rust
TypeTree(vec![Type {
offset: -1, // ALL positions
size: 4, // each f32 is 4 bytes
kind: Float, // every element is float
}])
```

Generates LLVM: `"enzyme_type"="{[-1]:Float@float}"`

#### Example 1b: Array Reference `&[f32; 100]` (with pointer indirection)
```rust
TypeTree(vec![Type {
offset: -1, size: 8, kind: Pointer,
child: TypeTree(vec![Type {
offset: -1, // ALL array elements
size: 4, // each f32 is 4 bytes
kind: Float, // every element is float
}])
}])
```

Generates LLVM: `"enzyme_type"="{[-1]:Pointer, [-1,-1]:Float@float}"`

Instead of listing 100 separate Types with offsets `0,4,8,12...396`

#### Example 2: Slice `&[i32]`
```rust
// Pointer to slice data
TypeTree(vec![Type {
offset: -1, size: 8, kind: Pointer,
child: TypeTree(vec![Type {
offset: -1, // ALL slice elements
size: 4, // each i32 is 4 bytes
kind: Integer
}])
}])
```

Generates LLVM: `"enzyme_type"="{[-1]:Pointer, [-1,-1]:Integer}"`

#### Example 3: Mixed Structure
```rust
struct Container {
header: i64, // offset 0
data: [f32; 1000], // offset 8, but elements use -1
}
```

```rust
TypeTree(vec![
Type { offset: 0, size: 8, kind: Integer }, // header
Type { offset: 8, size: 4000, kind: Pointer,
child: TypeTree(vec![Type {
offset: -1, size: 4, kind: Float // ALL array elements
}])
}
])
```

## Key Distinction: Single Values vs Arrays

**Single Values** use offset `0` for precision:
- `&f32` has exactly one f32 value at offset 0
- More precise than using -1 ("everywhere")
- Generates: `{[-1]:Pointer, [-1,0]:Float@float}`

**Arrays** use offset `-1` for efficiency:
- `&[f32; 100]` has the same pattern repeated 100 times
- Using -1 avoids listing 100 separate offsets
- Generates: `{[-1]:Pointer, [-1,-1]:Float@float}`
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,32 @@
There are three types of tools you can write in bootstrap:

- **`Mode::ToolBootstrap`**

Use this for tools that don’t need anything from the in-tree compiler and can run with the stage0 `rustc`.
The output is placed in the "bootstrap-tools" directory. This mode is for general-purpose tools built
entirely with the stage0 compiler, including target libraries and only works for stage 0.
The output is placed in the "bootstrap-tools" directory.
This mode is for general-purpose tools built entirely with the stage0 compiler,
including target libraries, and it only works for stage 0.

- **`Mode::ToolStd`**
Use this for tools that rely on the locally built std. The output goes into the "stageN-tools" directory.

Use this for tools that rely on the locally built std.
The output goes into the "stageN-tools" directory.
This mode is rarely used, mainly for `compiletest` which requires `libtest`.

- **`Mode::ToolRustcPrivate`**
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
returned by the tool's [`Step`].

Regardless of the tool type you must return `ToolBuildResult` from the tool’s [`Step`] implementation and use `ToolBuild` inside it.
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 returned by the tool's [`Step`].

Regardless of the tool type,
you must return `ToolBuildResult` from the tool’s [`Step`] implementation,
and use `ToolBuild` inside it.

[`Step`]: https://doc.rust-lang.org/nightly/nightly-rustc/bootstrap/core/builder/trait.Step.html
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ On Windows, the Powershell commands may give you an error that looks like this:
```
PS C:\Users\vboxuser\rust> ./x
./x : File C:\Users\vboxuser\rust\x.ps1 cannot be loaded because running scripts is disabled on this system. For more
information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
information, see about_Execution_Policies at https://go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ ./x
+ ~~~
Expand Down
4 changes: 4 additions & 0 deletions src/doc/rustc-dev-guide/src/compiler-team.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# About the compiler team

> NOTE:
> There exists much detail about the team [on Forge], making most of the following obsolete.

rustc is maintained by the [Rust compiler team][team]. The people who belong to
this team collectively work to track regressions and implement new features.
Members of the Rust compiler team are people who have made significant
contributions to rustc and its design.

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

## Discussion
Expand Down
7 changes: 4 additions & 3 deletions src/doc/rustc-dev-guide/src/fuzzing.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,15 @@ Here are a few things you can do to help the Rust project after filing an ICE.
triggering the ICE, such as syntax errors or borrow-checking errors
- Minimize the test case (see below). If successful, you can label the
issue with `S-has-mcve`. Otherwise, you can apply `E-needs-mcve`.
- Add the minimal test case to the rust-lang/rust repo as a [crashes test].
- Add the minimal test case to the rust-lang/rust repo as a [crash test].
While you're at it, consider including other "untracked" crashes in your PR.
Please don't forget to mark your issue with `S-bug-has-test` afterwards.
Please don't forget to mark all relevant issues with `S-bug-has-test` once
your PR is merged.

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

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

## Minimization
Expand Down
3 changes: 1 addition & 2 deletions src/doc/rustc-dev-guide/src/profiling/with_perf.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ This is a guide for how to profile rustc with [perf](https://perf.wiki.kernel.or

## Initial steps

- Get a clean checkout of rust-lang/master, or whatever it is you want
to profile.
- Get a clean checkout of rust-lang/rust
- Set the following settings in your `bootstrap.toml`:
- `rust.debuginfo-level = 1` - enables line debuginfo
- `rust.jemalloc = false` - lets you do memory use profiling with valgrind
Expand Down
4 changes: 2 additions & 2 deletions src/doc/rustc-dev-guide/src/tests/best-practices.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ related tests.
> //! Regression test for <https://github.com/rust-lang/rust/issues/123456>.
> ```
>
> One exception to this rule is [crashes tests]: there it is canonical that
> One exception to this rule is [crash tests]: there it is canonical that
> tests are named only after issue numbers because its purpose is to track
> snippets from which issues no longer ICE/crash, and they would either be
> removed or converted into proper ui/other tests in the fix PRs.
Expand Down Expand Up @@ -199,4 +199,4 @@ See [LLVM FileCheck guide][FileCheck] for details.
[compiletest directives]: ./directives.md
[`run-make`]: ./compiletest.md#run-make-tests
[FileCheck]: https://llvm.org/docs/CommandGuide/FileCheck.html
[crashes tests]: ./compiletest.md#crashes-tests
[crash tests]: ./compiletest.md#crash-tests
Loading
Loading