Skip to content

Commit e6acd30

Browse files
Alexander Regueiromark-i-m
Alexander Regueiro
authored andcommitted
Hard-wrapped lines that are too long.
1 parent ba057b3 commit e6acd30

15 files changed

+206
-161
lines changed

ci/check_line_lengths.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ for file in "$@" ; do
1414
(( inside_block = !$inside_block ))
1515
continue
1616
fi
17-
if ! (( $inside_block )) && ! [[ "$line" =~ " | "|"://"|\[\^[^\ ]+\]: ]] && (( "${#line}" > $MAX_LINE_LENGTH )) ; then
17+
if ! (( $inside_block )) && ! [[ "$line" =~ " | "|"-|-"|"://"|\[\^[^\ ]+\]: ]] && (( "${#line}" > $MAX_LINE_LENGTH )) ; then
1818
(( bad_lines++ ))
1919
echo -e "\t$line_no : $line"
2020
fi

src/SUMMARY.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
- [The compiler testing framework](./tests/intro.md)
77
- [Running tests](./tests/running.md)
88
- [Adding new tests](./tests/adding.md)
9-
- [Using `compiletest` + commands to control test execution](./compiletest.md)
9+
- [Using `compiletest` + commands to control test
10+
execution](./compiletest.md)
1011
- [Walkthrough: a typical contribution](./walkthrough.md)
1112
- [High-level overview of the compiler source](./high-level-overview.md)
1213
- [The Rustc Driver](./rustc-driver.md)

src/compiletest.md

+16-14
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# `compiletest`
22
## Introduction
3-
`compiletest` is the main test harness of the Rust test suite. It allows test authors to organize large numbers of tests (the
4-
Rust compiler has many thousands), efficient test execution (parallel execution is supported), and allows the test author to
5-
configure behavior and expected results of both individual and groups of tests.
3+
`compiletest` is the main test harness of the Rust test suite. It allows
4+
test authors to organize large numbers of tests (the Rust compiler has many
5+
thousands), efficient test execution (parallel execution is supported), and
6+
allows the test author to configure behavior and expected results of both
7+
individual and groups of tests.
68

79
`compiletest` tests may check test code for success, for failure or in some cases, even failure to compile. Tests are
810
typically organized as a Rust source file with annotations in comments before and/or within the test code, which serve to
@@ -12,17 +14,17 @@ testing framework, see [`this chapter`](./tests/intro.html) for additional backg
1214
The tests themselves are typically (but not always) organized into "suites"--for example, `run-pass`, a folder
1315
representing tests that should succeed, `run-fail`, a folder holding tests that should compile successfully, but return
1416
a failure (non-zero status), `compile-fail`, a folder holding tests that should fail to compile, and many more. The various
15-
suites are defined in [src/tools/compiletest/src/common.rs](https://github.com/rust-lang/rust/tree/master/src/tools/compiletest/src/common.rs) in the `pub struct Config` declaration. And a very good
17+
suites are defined in [src/tools/compiletest/src/common.rs](https://github.com/rust-lang/rust/tree/master/src/tools/compiletest/src/common.rs) in the `pub struct Config` declaration. And a very good
1618
introduction to the different suites of compiler tests along with details about them can be found in [`Adding new tests`](./tests/adding.html).
1719

1820
## Adding a new test file
19-
Briefly, simply create your new test in the appropriate location under [src/test](https://github.com/rust-lang/rust/tree/master/src/test). No registration of test files is necessary as
21+
Briefly, simply create your new test in the appropriate location under [src/test](https://github.com/rust-lang/rust/tree/master/src/test). No registration of test files is necessary as
2022
`compiletest` will scan the [src/test](https://github.com/rust-lang/rust/tree/master/src/test) subfolder recursively, and will execute any Rust source files it finds as tests.
21-
See [`Adding new tests`](./tests/adding.html) for a complete guide on how to adding new tests.
23+
See [`Adding new tests`](./tests/adding.html) for a complete guide on how to adding new tests.
2224

2325
## Header Commands
2426
Source file annotations which appear in comments near the top of the source file *before* any test code are known as header
25-
commands. These commands can instruct `compiletest` to ignore this test, set expectations on whether it is expected to
27+
commands. These commands can instruct `compiletest` to ignore this test, set expectations on whether it is expected to
2628
succeed at compiling, or what the test's return code is expected to be. Header commands (and their inline counterparts,
2729
Error Info commands) are described more fully [here](./tests/adding.html#header-commands-configuring-rustc).
2830

@@ -96,7 +98,7 @@ As a concrete example, here is the implementation for the `parse_failure_status(
9698
pub normalize_stderr: Vec<(String, String)>,
9799
+ pub failure_status: i32,
98100
}
99-
101+
100102
impl TestProps {
101103
@@ -260,6 +261,7 @@ impl TestProps {
102104
run_pass: false,
@@ -105,7 +107,7 @@ As a concrete example, here is the implementation for the `parse_failure_status(
105107
+ failure_status: 101,
106108
}
107109
}
108-
110+
109111
@@ -383,6 +385,10 @@ impl TestProps {
110112
if let Some(rule) = config.parse_custom_normalization(ln, "normalize-stderr") {
111113
self.normalize_stderr.push(rule);
@@ -115,12 +117,12 @@ As a concrete example, here is the implementation for the `parse_failure_status(
115117
+ self.failure_status = code;
116118
+ }
117119
});
118-
120+
119121
for key in &["RUST_TEST_NOCAPTURE", "RUST_TEST_THREADS"] {
120122
@@ -488,6 +494,13 @@ impl Config {
121123
self.parse_name_directive(line, "pretty-compare-only")
122124
}
123-
125+
124126
+ fn parse_failure_status(&self, line: &str) -> Option<i32> {
125127
+ match self.parse_name_value_directive(line, "failure-status") {
126128
+ Some(code) => code.trim().parse::<i32>().ok(),
@@ -141,7 +143,7 @@ located in [src/tools/compiletest/src/runtest.rs](https://github.com/rust-lang/r
141143
```diff
142144
@@ -295,11 +295,14 @@ impl<'test> TestCx<'test> {
143145
}
144-
146+
145147
fn check_correct_failure_status(&self, proc_res: &ProcRes) {
146148
- // The value the rust runtime returns on failure
147149
- const RUST_ERR: i32 = 101;
@@ -160,7 +162,7 @@ located in [src/tools/compiletest/src/runtest.rs](https://github.com/rust-lang/r
160162
}
161163
@@ -320,7 +323,6 @@ impl<'test> TestCx<'test> {
162164
);
163-
165+
164166
let proc_res = self.exec_compiled_test();
165167
-
166168
if !proc_res.status.success() {
@@ -172,7 +174,7 @@ located in [src/tools/compiletest/src/runtest.rs](https://github.com/rust-lang/r
172174
);
173175
- panic!();
174176
}
175-
}
177+
}
176178
```
177179
Note the use of `self.props.failure_status` to access the header command property. In tests which do not specify the failure
178180
status header command, `self.props.failure_status` will evaluate to the default value of 101 at the time of this writing.

src/high-level-overview.md

+15-14
Original file line numberDiff line numberDiff line change
@@ -94,20 +94,21 @@ order to compile a Rust crate, these are the general steps that we
9494
take:
9595

9696
1. **Parsing input**
97-
- this processes the `.rs` files and produces the AST ("abstract syntax tree")
97+
- this processes the `.rs` files and produces the AST
98+
("abstract syntax tree")
9899
- the AST is defined in `syntax/ast.rs`. It is intended to match the lexical
99100
syntax of the Rust language quite closely.
100101
2. **Name resolution, macro expansion, and configuration**
101-
- once parsing is complete, we process the AST recursively, resolving paths
102-
and expanding macros. This same process also processes `#[cfg]` nodes, and hence
103-
may strip things out of the AST as well.
102+
- once parsing is complete, we process the AST recursively, resolving
103+
paths and expanding macros. This same process also processes `#[cfg]`
104+
nodes, and hence may strip things out of the AST as well.
104105
3. **Lowering to HIR**
105106
- Once name resolution completes, we convert the AST into the HIR,
106-
or "high-level IR". The HIR is defined in `src/librustc/hir/`; that module also includes
107-
the lowering code.
108-
- The HIR is a lightly desugared variant of the AST. It is more processed than the
109-
AST and more suitable for the analyses that follow. It is **not** required to match
110-
the syntax of the Rust language.
107+
or "high-level IR". The HIR is defined in `src/librustc/hir/`;
108+
that module also includes the lowering code.
109+
- The HIR is a lightly desugared variant of the AST. It is more processed
110+
than the AST and more suitable for the analyses that follow.
111+
It is **not** required to match the syntax of the Rust language.
111112
- As a simple example, in the **AST**, we preserve the parentheses
112113
that the user wrote, so `((1 + 2) + 3)` and `1 + 2 + 3` parse
113114
into distinct trees, even though they are equivalent. In the
@@ -125,13 +126,13 @@ take:
125126
the types of expressions, the way to resolve methods, and so forth.
126127
- After type-checking, we can do other analyses, such as privacy checking.
127128
4. **Lowering to MIR and post-processing**
128-
- Once type-checking is done, we can lower the HIR into MIR ("middle IR"), which
129-
is a **very** desugared version of Rust, well suited to the borrowck but also
130-
certain high-level optimizations.
129+
- Once type-checking is done, we can lower the HIR into MIR ("middle IR"),
130+
which is a **very** desugared version of Rust, well suited to borrowck
131+
but also to certain high-level optimizations.
131132
5. **Translation to LLVM and LLVM optimizations**
132133
- From MIR, we can produce LLVM IR.
133-
- LLVM then runs its various optimizations, which produces a number of `.o` files
134-
(one for each "codegen unit").
134+
- LLVM then runs its various optimizations, which produces a number of
135+
`.o` files (one for each "codegen unit").
135136
6. **Linking**
136137
- Finally, those `.o` files are linked together.
137138

src/hir.md

+20-18
Original file line numberDiff line numberDiff line change
@@ -63,23 +63,25 @@ carry around references into the HIR, but rather to carry around
6363
*identifier numbers* (or just "ids"). Right now, you will find four
6464
sorts of identifiers in active use:
6565

66-
- `DefId` – primarily names "definitions" or top-level items.
67-
- You can think of a `DefId` as shorthand for a very explicit and complete
68-
path, like `std::collections::HashMap`. However, these paths are able to
69-
name things that are not nameable in normal Rust (e.g. `impl`s), and they
70-
also include extra information about the crate (such as its version number,
71-
since two versions of the same crate can co-exist).
72-
- A `DefId` really consists of two parts, a `CrateNum` (which identifies the
73-
crate) and a `DefIndex` (which indexes into a list of items that is
74-
maintained per crate).
75-
- `HirId` – combines the index of a particular item with an offset within
76-
that item.
77-
- The key point of an `HirId` is that it is *relative* to some item (which is
78-
named via a `DefId`).
79-
- `BodyId` – an absolute identifier that refers to a specific body (definition
80-
of a function or constant) in the crate. It is currently effectively a
81-
"newtype'd" `NodeId`.
82-
- `NodeId` – an absolute ID that identifies a single node in the HIR tree.
66+
- `DefId`, which primarily names "definitions" or top-level items.
67+
- You can think of a `DefId` as being shorthand for a very explicit
68+
and complete path, like `std::collections::HashMap`. However,
69+
these paths are able to name things that are not nameable in
70+
normal Rust (e.g. impls), and they also include extra information
71+
about the crate (such as its version number, as two versions of
72+
the same crate can co-exist).
73+
- A `DefId` really consists of two parts, a `CrateNum` (which
74+
identifies the crate) and a `DefIndex` (which indixes into a list
75+
of items that is maintained per crate).
76+
- `HirId`, which combines the index of a particular item with an
77+
offset within that item.
78+
- the key point of a `HirId` is that it is *relative* to some item
79+
(which is named via a `DefId`).
80+
- `BodyId`, this is an absolute identifier that refers to a specific
81+
body (definition of a function or constant) in the crate. It is currently
82+
effectively a "newtype'd" `NodeId`.
83+
- `NodeId`, which is an absolute id that identifies a single node in the HIR
84+
tree.
8385
- While these are still in common use, **they are being slowly phased out**.
8486
- Since they are absolute within the crate, adding a new node anywhere in the
8587
tree causes the `NodeId`s of all subsequent code in the crate to change.
@@ -119,5 +121,5 @@ of a function/closure or the definition of a constant. Bodies are
119121
associated with an **owner**, which is typically some kind of item
120122
(e.g. an `fn()` or `const`), but could also be a closure expression
121123
(e.g. `|x, y| x + y`). You can use the HIR map to find the body
122-
associated with a given `DefId` (`maybe_body_owned_by()`) or to find
124+
associated with a given def-id (`maybe_body_owned_by()`) or to find
123125
the owner of a body (`body_owner_def_id()`).

src/how-to-build-and-run.md

+20-14
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
The compiler is built using a tool called `x.py`. You will need to
44
have Python installed to run it. But before we get to that, if you're going to
5-
be hacking on rustc, you'll want to tweak the configuration of the compiler. The default
6-
configuration is oriented towards running the compiler as a user, not a developer.
5+
be hacking on rustc, you'll want to tweak the configuration of the compiler.
6+
The default configuration is oriented towards running the compiler as a user,
7+
not a developer.
78

89
### Create a config.toml
910

@@ -84,15 +85,16 @@ What this command will do is the following:
8485
- Using this stage 1 compiler, it will build the standard library.
8586
(this is what the `src/libstd`) means.
8687

87-
This is just a subset of the full rustc build. The **full** rustc build (what you
88-
get if you just say `./x.py build`) has quite a few more steps:
88+
This is just a subset of the full rustc build. The **full** rustc build
89+
(what you get if you just say `./x.py build`) has quite a few more steps:
8990

90-
- Build stage1 rustc with stage0 compiler
91-
- Build libstd with stage1 compiler (up to here is the same)
92-
- Build rustc from `src` again, this time with the stage1 compiler (this part is new)
93-
- The resulting compiler here is called the "stage2" compiler
94-
- Build libstd with stage2 compiler
95-
- Build librustdoc and a bunch of other things
91+
- Build stage1 rustc with stage0 compiler.
92+
- Build libstd with stage1 compiler (up to here is the same).
93+
- Build rustc from `src` again, this time with the stage1 compiler
94+
(this part is new).
95+
- The resulting compiler here is called the "stage2" compiler.
96+
- Build libstd with stage2 compiler.
97+
- Build librustdoc and a bunch of other things.
9698

9799
### Creating a rustup toolchain
98100

@@ -126,12 +128,16 @@ LLVM version: 4.0
126128

127129
### Other x.py commands
128130

129-
Here are a few other useful x.py commands. We'll cover some of them in detail in other sections:
131+
Here are a few other useful x.py commands. We'll cover some of them in detail
132+
in other sections:
130133

131134
- Building things:
132-
- `./x.py clean` – clean up the build directory (`rm -rf build` works too, but then you have to rebuild LLVM)
133-
- `./x.py build --stage 1` – builds everything using the stage 1 compiler, not just up to libstd
135+
- `./x.py clean` – clean up the build directory (`rm -rf build` works too,
136+
but then you have to rebuild LLVM)
137+
- `./x.py build --stage 1` – builds everything using the stage 1 compiler,
138+
not just up to libstd
134139
- `./x.py build` – builds the stage2 compiler
135-
- Running tests (see the [section on running tests](./tests/running.html) for more details):
140+
- Running tests (see the [section on running tests](./tests/running.html) for
141+
more details):
136142
- `./x.py test --stage 1 src/libstd` – runs the `#[test]` tests from libstd
137143
- `./x.py test --stage 1 src/test/run-pass` – runs the `run-pass` test suite

src/incremental-compilation.md

+21-18
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
The incremental compilation scheme is, in essence, a surprisingly
44
simple extension to the overall query system. We'll start by describing
5-
a slightly simplified variant of the real thing – the "basic algorithm" – and then describe
6-
some possible improvements.
5+
a slightly simplified variant of the real thing – the "basic algorithm" –
6+
and then describe some possible improvements.
77

88
## The basic algorithm
99

@@ -40,7 +40,7 @@ There are two key insights here:
4040
produced the same result as the previous time. **If it did,** we
4141
can still mark the query as green, and hence avoid re-executing
4242
dependent queries.
43-
43+
4444
### The try-mark-green algorithm
4545

4646
At the core of incremental compilation is an algorithm called
@@ -66,28 +66,30 @@ Try-mark-green works as follows:
6666
- For each query R in `reads(Q)`, we recursively demand the color
6767
of R using try-mark-green.
6868
- Note: it is important that we visit each node in `reads(Q)` in same order
69-
as they occurred in the original compilation. See [the section on the query DAG below](#dag).
70-
- If **any** of the nodes in `reads(Q)` wind up colored **red**, then Q is dirty.
71-
- We re-execute Q and compare the hash of its result to the hash of the result
72-
from the previous compilation.
69+
as they occurred in the original compilation. See [the section on the
70+
query DAG below](#dag).
71+
- If **any** of the nodes in `reads(Q)` wind up colored **red**, then Q is
72+
dirty.
73+
- We re-execute Q and compare the hash of its result to the hash of the
74+
result from the previous compilation.
7375
- If the hash has not changed, we can mark Q as **green** and return.
74-
- Otherwise, **all** of the nodes in `reads(Q)` must be **green**. In that case,
75-
we can color Q as **green** and return.
76+
- Otherwise, **all** of the nodes in `reads(Q)` must be **green**. In that
77+
case, we can color Q as **green** and return.
7678

7779
<a name="dag">
7880

7981
### The query DAG
8082

8183
The query DAG code is stored in
8284
[`src/librustc/dep_graph`][dep_graph]. Construction of the DAG is done
83-
by instrumenting the query execution.
85+
by instrumenting the query execution.
8486

8587
One key point is that the query DAG also tracks ordering; that is, for
8688
each query Q, we not only track the queries that Q reads, we track the
8789
**order** in which they were read. This allows try-mark-green to walk
88-
those queries back in the same order. This is important because once a subquery comes back as red,
89-
we can no longer be sure that Q will continue along the same path as before.
90-
That is, imagine a query like this:
90+
those queries back in the same order. This is important because once a
91+
subquery comes back as red, we can no longer be sure that Q will continue
92+
along the same path as before. That is, imagine a query like this:
9193

9294
```rust,ignore
9395
fn main_query(tcx) {
@@ -105,9 +107,10 @@ query `main_query` executes will be `subquery2`, and `subquery3` will
105107
not be executed at all.
106108

107109
But now imagine that in the **next** compilation, the input has
108-
changed such that `subquery1` returns **false**. In this case, `subquery2` would never
109-
execute. If try-mark-green were to visit `reads(main_query)` out of order,
110-
however, it might visit `subquery2` before `subquery1`, and hence execute it.
110+
changed such that `subquery1` returns **false**. In this case, `subquery2`
111+
would never execute. If try-mark-green were to visit `reads(main_query)` out
112+
of order, however, it might visit `subquery2` before `subquery1`, and hence
113+
execute it.
111114
This can lead to ICEs and other problems in the compiler.
112115

113116
[dep_graph]: https://github.com/rust-lang/rust/tree/master/src/librustc/dep_graph
@@ -124,8 +127,8 @@ we **also** save the results.
124127

125128
This is why the incremental algorithm separates computing the
126129
**color** of a node, which often does not require its value, from
127-
computing the **result** of a node. Computing the result is done via a simple algorithm
128-
like so:
130+
computing the **result** of a node. Computing the result is done via a simple
131+
algorithm like so:
129132

130133
- Check if a saved result for Q is available. If so, compute the color of Q.
131134
If Q is green, deserialize and return the saved result.

0 commit comments

Comments
 (0)