Skip to content

Commit bee2fd5

Browse files
authored
Add mdbook-toc, markers, and documentation (#1028)
* Add mdbook-toc to travis, book.toml and documentation * Add toc markers * Whitespace cleanup and some punctuation * Addressed comments
1 parent bd8e94a commit bee2fd5

Some content is hidden

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

53 files changed

+177
-76
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ install:
1313
- source ~/.cargo/env || true
1414
- cargo install mdbook --version '^0.4.5'
1515
- cargo install mdbook-linkcheck --version '^0.7.2'
16+
- cargo install mdbook-toc --version '^0.6.1'
1617
script:
1718
- git checkout -b ci
1819
- git rebase origin/master

README.md

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

4242
```
43-
> cargo install mdbook mdbook-linkcheck
43+
> cargo install mdbook mdbook-linkcheck mdbook-toc
4444
```
4545

4646
and execute the following command in the root of the repository:
@@ -56,6 +56,11 @@ The build files are found in the `book` directory.
5656
We use `mdbook-linkcheck` to validate URLs included in our documentation.
5757
`linkcheck` will be run automatically when you build with the instructions in the section above.
5858

59+
### Table of Contents
60+
61+
We use `mdbook-toc` to auto-generate TOCs for long sections. You can invoke the preprocessor by
62+
including the `<!-- toc -->` marker at the place where you want the TOC.
63+
5964
### Pre-commit script
6065

6166
We also test that line lengths are less than 100 columns. To test this locally,
@@ -95,7 +100,7 @@ but we leave these instructions for when we do it again in the future.
95100

96101
7. Click on the log and Ctrl-f to get a search box in the log
97102

98-
8. Search for rustc-dev-guide. This gets you to the place where the links are checked. It is usually ~11K lines into the log
103+
8. Search for rustc-dev-guide. This gets you to the place where the links are checked. It is usually ~11K lines into the log.
99104

100105
9. Look at the links in the log near that point in the log
101106

book.toml

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ description = "A guide to developing rustc"
66
[build]
77
create-missing = false
88

9+
[preprocessor.toc]
10+
command = "mdbook-toc"
11+
renderer = ["html"]
12+
913
[output.html]
1014
git-repository-url = "https://github.com/rust-lang/rustc-dev-guide"
1115

src/about-this-guide.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ a correction!
4747
If you do contribute to the guide, please see the corresponding
4848
[subsection on writing documentation in this guide].
4949

50-
[subsection on writing documentation in this guide]: contributing.md#contributing-to-rustc-dev-guide.
50+
[subsection on writing documentation in this guide]: contributing.md#contributing-to-rustc-dev-guide
5151

5252
> “‘All conditioned things are impermanent’ — when one sees this with wisdom, one turns away from
5353
> suffering.” _The Dhammapada, verse 277_

src/backend/backend-agnostic.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Backend Agnostic Codegen
22

3+
<!-- toc -->
4+
35
As of January 2021, `rustc_codegen_ssa` provides an abstract interface for all backends to
46
implement, to allow other codegen backends (e.g. [Cranelift]).
57

src/backend/implicit-caller-location.md

+24-22
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# Implicit Caller Location
22

3+
<!-- toc -->
4+
35
Approved in [RFC 2091], this feature enables the accurate reporting of caller location during panics
4-
initiated from functions like `Option::unwrap`, `Result::expect`, and `Index::index`. This feature
5-
adds the [`#[track_caller]`][attr-reference] attribute for functions, the
6-
[`caller_location`][intrinsic] intrinsic, and the stabilization-friendly
6+
initiated from functions like `Option::unwrap`, `Result::expect`, and `Index::index`. This feature
7+
adds the [`#[track_caller]`][attr-reference] attribute for functions, the
8+
[`caller_location`][intrinsic] intrinsic, and the stabilization-friendly
79
[`core::panic::Location::caller`][wrapper] wrapper.
810

911
## Motivating Example
@@ -28,25 +30,25 @@ note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
2830
As of 1.42, we get a much more helpful message:
2931

3032
```
31-
$ rustc +1.42.0 example.rs; example.exe
33+
$ rustc +1.42.0 example.rs; example.exe
3234
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', example.rs:3:5
3335
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
3436
```
3537

3638
These error messages are achieved through a combination of changes to `panic!` internals to make use
37-
of `core::panic::Location::caller` and a number of `#[track_caller]` annotations in the standard
39+
of `core::panic::Location::caller` and a number of `#[track_caller]` annotations in the standard
3840
library which propagate caller information.
3941

4042
## Reading Caller Location
4143

4244
Previously, `panic!` made use of the `file!()`, `line!()`, and `column!()` macros to construct a
4345
[`Location`] pointing to where the panic occurred. These macros couldn't be given an overridden
44-
location, so functions which intentionally invoked `panic!` couldn't provide their own location,
46+
location, so functions which intentionally invoked `panic!` couldn't provide their own location,
4547
hiding the actual source of error.
4648

47-
Internally, `panic!()` now calls [`core::panic::Location::caller()`][wrapper] to find out where it
48-
was expanded. This function is itself annotated with `#[track_caller]` and wraps the
49-
[`caller_location`][intrinsic] compiler intrinsic implemented by rustc. This intrinsic is easiest
49+
Internally, `panic!()` now calls [`core::panic::Location::caller()`][wrapper] to find out where it
50+
was expanded. This function is itself annotated with `#[track_caller]` and wraps the
51+
[`caller_location`][intrinsic] compiler intrinsic implemented by rustc. This intrinsic is easiest
5052
explained in terms of how it works in a `const` context.
5153

5254
## Caller Location in `const`
@@ -56,20 +58,20 @@ to find the right location and allocating a const value to return.
5658

5759
### Finding the right `Location`
5860

59-
In a const context we "walk up the stack" from where the intrinsic is invoked, stopping when we
61+
In a const context we "walk up the stack" from where the intrinsic is invoked, stopping when we
6062
reach the first function call in the stack which does *not* have the attribute. This walk is in
6163
[`InterpCx::find_closest_untracked_caller_location()`][const-find-closest].
6264

63-
Starting at the bottom, we iterate up over stack [`Frame`][const-frame]s in the
65+
Starting at the bottom, we iterate up over stack [`Frame`][const-frame]s in the
6466
[`InterpCx::stack`][const-stack], calling
65-
[`InstanceDef::requires_caller_location`][requires-location] on the
67+
[`InstanceDef::requires_caller_location`][requires-location] on the
6668
[`Instance`s from each `Frame`][frame-instance]. We stop once we find one that returns `false` and
6769
return the span of the *previous* frame which was the "topmost" tracked function.
6870

6971
### Allocating a static `Location`
7072

71-
Once we have a `Span`, we need to allocate static memory for the `Location`, which is performed by
72-
the [`TyCtxt::const_caller_location()`][const-location-query] query. Internally this calls
73+
Once we have a `Span`, we need to allocate static memory for the `Location`, which is performed by
74+
the [`TyCtxt::const_caller_location()`][const-location-query] query. Internally this calls
7375
[`InterpCx::alloc_caller_location()`][alloc-location] and results in a unique
7476
[memory kind][location-memory-kind] (`MemoryKind::CallerLocation`). The SSA codegen backend is able
7577
to emit code for these same values, and we use this code there as well.
@@ -78,14 +80,14 @@ Once our `Location` has been allocated in static memory, our intrinsic returns a
7880

7981
## Generating code for `#[track_caller]` callees
8082

81-
To generate efficient code for a tracked function and its callers, we need to provide the same
83+
To generate efficient code for a tracked function and its callers, we need to provide the same
8284
behavior from the intrinsic's point of view without having a stack to walk up at runtime. We invert
8385
the approach: as we grow the stack down we pass an additional argument to calls of tracked functions
8486
rather than walking up the stack when the intrinsic is called. That additional argument can be
8587
returned wherever the caller location is queried.
8688

8789
The argument we append is of type `&'static core::panic::Location<'static>`. A reference was chosen
88-
to avoid unnecessary copying because a pointer is a third the size of
90+
to avoid unnecessary copying because a pointer is a third the size of
8991
`std::mem::size_of::<core::panic::Location>() == 24` at time of writing.
9092

9193
When generating a call to a function which is tracked, we pass the location argument the value of
@@ -151,12 +153,12 @@ probably the best we can do without modifying fully-stabilized type signatures.
151153

152154
> *Note:* We always emit a [`ReifyShim`] when taking a pointer to a tracked function. While the
153155
> constraint here is imposed by codegen contexts, we don't know during MIR construction of the shim
154-
> whether we'll be called in a const context (safe to ignore shim) or in a codegen context (unsafe
156+
> whether we'll be called in a const context (safe to ignore shim) or in a codegen context (unsafe
155157
> to ignore shim). Even if we did know, the results from const and codegen contexts must agree.
156158
157159
## The Attribute
158160

159-
The `#[track_caller]` attribute is checked alongside other codegen attributes to ensure the
161+
The `#[track_caller]` attribute is checked alongside other codegen attributes to ensure the
160162
function:
161163

162164
* has the `"Rust"` ABI (as opposed to e.g., `"C"`)
@@ -171,7 +173,7 @@ used in both const and codegen contexts to ensure correct propagation.
171173

172174
When applied to trait method implementations, the attribute works as it does for regular functions.
173175

174-
When applied to a trait method prototype, the attribute applies to all implementations of the
176+
When applied to a trait method prototype, the attribute applies to all implementations of the
175177
method. When applied to a default trait method implementation, the attribute takes effect on
176178
that implementation *and* any overrides.
177179

@@ -203,14 +205,14 @@ trait TrackedFourWays {
203205
assert_tracked!();
204206
}
205207

206-
/// Overrides of this implementation are tracked (it is too).
208+
/// Overrides of this implementation are tracked (it is too).
207209
#[track_caller]
208210
fn default_tracked_to_override() {
209211
assert_tracked!();
210212
}
211213
}
212214

213-
/// This impl uses the default impl for `default_tracked` and provides its own for
215+
/// This impl uses the default impl for `default_tracked` and provides its own for
214216
/// `default_tracked_to_override`.
215217
impl TrackedFourWays for () {
216218
fn blanket_tracked() {
@@ -253,7 +255,7 @@ up on the tracking issue. During the course of implementing that, it was also di
253255
implementation was possible without modifying the number of arguments in a function's MIR, which
254256
would simplify later stages and unlock use in traits.
255257

256-
Because the RFC's implementation strategy could not readily support traits, the semantics were not
258+
Because the RFC's implementation strategy could not readily support traits, the semantics were not
257259
originally specified. They have since been implemented following the path which seemed most correct
258260
to the author and reviewers.
259261

src/backend/monomorph.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Monomorphization
22

3+
<!-- toc -->
4+
35
As you probably know, rust has a very expressive type system that has extensive
46
support for generic types. But of course, assembly is not generic, so we need
57
to figure out the concrete types of all the generics before the code can
@@ -57,12 +59,12 @@ units](../appendix/glossary.md#codegen-unit).
5759

5860
## Codegen Unit (CGU) partitioning
5961

60-
For better incremental build times, the CGU partitioner creates two CGU for each source level
61-
modules. One is for "stable" i.e. non-generic code and the other is more volatile code i.e.
62+
For better incremental build times, the CGU partitioner creates two CGU for each source level
63+
modules. One is for "stable" i.e. non-generic code and the other is more volatile code i.e.
6264
monoporphized/specialized instances.
6365

6466
For depenencies, consider Crate A and Crate B, such that Crate B depends on Crate A.
65-
The following table lists different scenarios for a function in Crate A that might be used by one
67+
The following table lists different scenarios for a function in Crate A that might be used by one
6668
or more modules in Crate B.
6769

6870
| Crate A function | Behavior |

src/backend/updating-llvm.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Updating LLVM
22

3+
<!-- toc -->
4+
35
The Rust compiler uses LLVM as its primary codegen backend today, and naturally
46
we want to at least occasionally update this dependency! Currently we do not
57
have a strict policy about when to update LLVM or what it can be updated to, but

src/borrow_check/moves_and_initialization/move_paths.md

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
# Move paths
22

3+
<!-- toc -->
4+
35
In reality, it's not enough to track initialization at the granularity
46
of local variables. Rust also allows us to do moves and initialization
57
at the field granularity:
68

79
```rust,ignore
810
fn foo() {
911
let a: (Vec<u32>, Vec<u32>) = (vec![22], vec![44]);
10-
12+
1113
// a.0 and a.1 are both initialized
12-
14+
1315
let b = a.0; // moves a.0
14-
16+
1517
// a.0 is not initialized, but a.1 still is
1618
1719
let c = a.0; // ERROR
@@ -73,7 +75,7 @@ there is no need for a [`MovePathIndex`]. Some examples:
7375
there would be no move-path for `foo[1]`.
7476
- You cannot move from inside of a borrowed reference, so if we have e.g. `foo: &String`,
7577
there would be no move-path for `*foo`.
76-
78+
7779
These rules are enforced by the [`move_path_for`] function, which
7880
converts a [`Place`] into a [`MovePathIndex`] -- in error cases like
7981
those just discussed, the function returns an `Err`. This in turn
@@ -102,7 +104,7 @@ of [`MoveData`]. There are two different methods:
102104
[`LookupResult`] indicating the closest path it was able to find
103105
that exists (e.g., for `foo[1]`, it might return just the path for
104106
`foo`).
105-
107+
106108
[`find`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/dataflow/move_paths/struct.MovePathLookup.html#method.find
107109
[`find_local`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/dataflow/move_paths/struct.MovePathLookup.html#method.find_local
108110
[`mir::Local`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/struct.Local.html
@@ -120,7 +122,7 @@ just over the paths that are **actually referenced** in the source,
120122
not all **possible** paths that could have been referenced). These
121123
references are used for example in the
122124
[`find_in_move_path_or_its_descendants`] function, which determines
123-
whether a move-path (e.g., `a.b`) or any child of that move-path
125+
whether a move-path (e.g., `a.b`) or any child of that move-path
124126
(e.g.,`a.b.c`) matches a given predicate.
125127

126128
[`Place`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/struct.Place.html

src/borrow_check/region_inference.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Region inference (NLL)
22

3+
<!-- toc -->
4+
35
The MIR-based region checking code is located in [the `rustc_mir::borrow_check`
46
module][nll].
57

src/borrow_check/region_inference/constraint_propagation.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Constraint propagation
22

3+
<!-- toc -->
4+
35
The main work of the region inference is **constraint propagation**,
46
which is done in the [`propagate_constraints`] function. There are
57
three sorts of constraints that are used in NLL, and we'll explain how

src/borrow_check/region_inference/lifetime_parameters.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Universal regions
22

3+
<!-- toc -->
4+
35
"Universal regions" is the name that the code uses to refer to "named
46
lifetimes" -- e.g., lifetime parameters and `'static`. The name
57
derives from the fact that such lifetimes are "universally quantified"

src/borrow_check/region_inference/member_constraints.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Member constraints
22

3+
<!-- toc -->
4+
35
A member constraint `'m member of ['c_1..'c_N]` expresses that the
46
region `'m` must be *equal* to some **choice regions** `'c_i` (for
57
some `i`). These constraints cannot be expressed by users, but they

src/borrow_check/region_inference/placeholders_and_universes.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Placeholders and universes
22

3+
<!-- toc -->
4+
35
From time to time we have to reason about regions that we can't
46
concretely know. For example, consider this program:
57

src/bug-fix-procedure.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# Rustc Bug Fix Procedure
2+
3+
<!-- toc -->
4+
25
This page defines the best practices procedure for making bug fixes or soundness
36
corrections in the compiler that can cause existing code to stop compiling. This
47
text is based on

src/building/bootstrapping.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Bootstrapping the Compiler
22

3+
<!-- toc -->
4+
35
This subchapter is about the bootstrapping process.
46

57
## What is bootstrapping? How does it work?

src/compiler-debugging.md

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Debugging the compiler
22
[debugging]: #debugging
33

4+
<!-- toc -->
5+
46
This chapter contains a few tips to debug the compiler. These tips aim to be
57
useful no matter what you are working on. Some of the other chapters have
68
advice about specific parts of the compiler (e.g. the [Queries Debugging and
@@ -9,14 +11,14 @@ chapter](./backend/debugging.md)).
911

1012
## Configuring the compiler
1113

12-
By default, rustc is built without most debug information. To enable debug info,
13-
set `debug = true` in your config.toml.
14+
By default, rustc is built without most debug information. To enable debug info,
15+
set `debug = true` in your config.toml.
1416

15-
Setting `debug = true` turns on many different debug options (e.g., `debug-assertions`,
16-
`debug-logging`, etc.) which can be individually tweaked if you want to, but many people
17+
Setting `debug = true` turns on many different debug options (e.g., `debug-assertions`,
18+
`debug-logging`, etc.) which can be individually tweaked if you want to, but many people
1719
simply set `debug = true`. Check out the comments in config.toml.example for more info.
1820

19-
You will need to rebuild the compiler once you've changed any configuration options.
21+
You will need to rebuild the compiler once you've changed any configuration options.
2022

2123
## `-Z` flags
2224

@@ -36,7 +38,7 @@ normal Rust programs. IIRC backtraces **don't work** on MinGW,
3638
sorry. If you have trouble or the backtraces are full of `unknown`,
3739
you might want to find some way to use Linux, Mac, or MSVC on Windows.
3840

39-
In the default configuration (without `debug` set to `true`), you don't have line numbers
41+
In the default configuration (without `debug` set to `true`), you don't have line numbers
4042
enabled, so the backtrace looks like this:
4143

4244
```text
@@ -56,7 +58,7 @@ stack backtrace:
5658
37: rustc_driver::run_compiler
5759
```
5860

59-
If you set `debug = true`, you will get line numbers for the stack trace.
61+
If you set `debug = true`, you will get line numbers for the stack trace.
6062
Then the backtrace will look like this:
6163

6264
```text

0 commit comments

Comments
 (0)