Skip to content

Commit 320df68

Browse files
authored
rustc invocation standarized (#992)
* rustc invocation standarized * Addressed comments * Addressed comments * Addressed comments * Updated command output
1 parent a436d3a commit 320df68

17 files changed

+89
-85
lines changed

src/backend/debugging.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,27 +103,27 @@ specifically the `#t-compiler/wg-llvm` stream.
103103

104104
### Compiler options to know and love
105105

106-
The `-Chelp` and `-Zhelp` compiler switches will list out a variety
106+
The `-C help` and `-Z help` compiler switches will list out a variety
107107
of interesting options you may find useful. Here are a few of the most
108108
common that pertain to LLVM development (some of them are employed in the
109109
tutorial above):
110110

111111
- The `--emit llvm-ir` option emits a `<filename>.ll` file with LLVM IR in textual format
112112
- The `--emit llvm-bc` option emits in bytecode format (`<filename>.bc`)
113-
- Passing `-Cllvm-args=<foo>` allows passing pretty much all the
113+
- Passing `-C llvm-args=<foo>` allows passing pretty much all the
114114
options that tools like llc and opt would accept;
115-
e.g. `-Cllvm-args=-print-before-all` to print IR before every LLVM
115+
e.g. `-C llvm-args=-print-before-all` to print IR before every LLVM
116116
pass.
117-
- The `-Cno-prepopulate-passes` will avoid pre-populate the LLVM pass
117+
- The `-C no-prepopulate-passes` will avoid pre-populate the LLVM pass
118118
manager with a list of passes. This will allow you to view the LLVM
119119
IR that rustc generates, not the LLVM IR after optimizations.
120-
- The `-Cpasses=val` option allows you to supply a space separated list of extra LLVM passes to run
121-
- The `-Csave-temps` option saves all temporary output files during compilation
122-
- The `-Zprint-llvm-passes` option will print out LLVM optimization passes being run
123-
- The `-Ztime-llvm-passes` option measures the time of each LLVM pass
124-
- The `-Zverify-llvm-ir` option will verify the LLVM IR for correctness
125-
- The `-Zno-parallel-llvm` will disable parallel compilation of distinct compilation units
126-
- The `-Zllvm-time-trace` option will output a Chrome profiler compatible JSON file
120+
- The `-C passes=val` option allows you to supply a space separated list of extra LLVM passes to run
121+
- The `-C save-temps` option saves all temporary output files during compilation
122+
- The `-Z print-llvm-passes` option will print out LLVM optimization passes being run
123+
- The `-Z time-llvm-passes` option measures the time of each LLVM pass
124+
- The `-Z verify-llvm-ir` option will verify the LLVM IR for correctness
125+
- The `-Z no-parallel-llvm` will disable parallel compilation of distinct compilation units
126+
- The `-Z llvm-time-trace` option will output a Chrome profiler compatible JSON file
127127
which contains details and timings for LLVM passes.
128128

129129
### Filing LLVM bug reports

src/closure.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ fn main() {
3232
```
3333

3434
Let's say the above is the content of a file called `immut.rs`. If we compile
35-
`immut.rs` using the following command. The [`-Zdump-mir=all`][dump-mir] flag will cause
35+
`immut.rs` using the following command. The [`-Z dump-mir=all`][dump-mir] flag will cause
3636
`rustc` to generate and dump the [MIR][mir] to a directory called `mir_dump`.
3737
```console
38-
> rustc +stage1 immut.rs -Zdump-mir=all
38+
> rustc +stage1 immut.rs -Z dump-mir=all
3939
```
4040

4141
[mir]: ./mir/index.md
@@ -146,7 +146,7 @@ codebase. For closures specifically, set the `RUST_LOG` env variable as below an
146146
output in a file:
147147

148148
```console
149-
> RUST_LOG=rustc_typeck::check::upvar rustc +stage1 -Zdump-mir=all \
149+
> RUST_LOG=rustc_typeck::check::upvar rustc +stage1 -Z dump-mir=all \
150150
<.rs file to compile> 2> <file where the output will be dumped>
151151
```
152152

src/compiler-debugging.md

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -82,28 +82,31 @@ For example:
8282

8383
```bash
8484
$ cat error.rs
85+
```
86+
87+
```rust
8588
fn main() {
8689
1 + ();
8790
}
8891
```
8992

9093
```bash
91-
$ ./build/x86_64-unknown-linux-gnu/stage1/bin/rustc error.rs
92-
error[E0277]: the trait bound `{integer}: std::ops::Add<()>` is not satisfied
94+
$ rustc +stage1 error.rs
95+
error[E0277]: cannot add `()` to `{integer}`
9396
--> error.rs:2:7
9497
|
95-
2 | 1 + ();
96-
| ^ no implementation for `{integer} + ()`
98+
2 | 1 + ();
99+
| ^ no implementation for `{integer} + ()`
97100
|
98-
= help: the trait `std::ops::Add<()>` is not implemented for `{integer}`
101+
= help: the trait `Add<()>` is not implemented for `{integer}`
99102
100103
error: aborting due to previous error
104+
```
105+
106+
Now, where does the error above come from?
101107

102-
$ # Now, where does the error above come from?
103-
$ RUST_BACKTRACE=1 \
104-
./build/x86_64-unknown-linux-gnu/stage1/bin/rustc \
105-
error.rs \
106-
-Z treat-err-as-bug
108+
```bash
109+
$ RUST_BACKTRACE=1 rustc +stage1 error.rs -Z treat-err-as-bug
107110
error[E0277]: the trait bound `{integer}: std::ops::Add<()>` is not satisfied
108111
--> error.rs:2:7
109112
|
@@ -140,9 +143,10 @@ stack backtrace:
140143
(~~~ IRRELEVANT PART OF BACKTRACE REMOVED BY ME ~~~)
141144
36: rustc_driver::run_compiler
142145
at /home/user/rust/compiler/rustc_driver/src/lib.rs:253
143-
$ # Cool, now I have a backtrace for the error
144146
```
145147

148+
Cool, now I have a backtrace for the error!
149+
146150
## Getting logging output
147151
[getting-logging-output]: #getting-logging-output
148152

@@ -180,16 +184,16 @@ So to put it together.
180184
```bash
181185
# This puts the output of all debug calls in `rustc_middle/src/traits` into
182186
# standard error, which might fill your console backscroll.
183-
$ RUSTC_LOG=rustc_middle::traits rustc +local my-file.rs
187+
$ RUSTC_LOG=rustc_middle::traits rustc +stage1 my-file.rs
184188
185189
# This puts the output of all debug calls in `rustc_middle/src/traits` in
186190
# `traits-log`, so you can then see it with a text editor.
187-
$ RUSTC_LOG=rustc_middle::traits rustc +local my-file.rs 2>traits-log
191+
$ RUSTC_LOG=rustc_middle::traits rustc +stage1 my-file.rs 2>traits-log
188192
189193
# Not recommended. This will show the output of all `debug!` calls
190194
# in the Rust compiler, and there are a *lot* of them, so it will be
191195
# hard to find anything.
192-
$ RUSTC_LOG=debug rustc +local my-file.rs 2>all-log
196+
$ RUSTC_LOG=debug rustc +stage1 my-file.rs 2>all-log
193197
194198
# This will show the output of all `info!` calls in `rustc_trans`.
195199
#
@@ -198,13 +202,13 @@ $ RUSTC_LOG=debug rustc +local my-file.rs 2>all-log
198202
# which function triggers an LLVM assertion, and this is an `info!`
199203
# log rather than a `debug!` log so it will work on the official
200204
# compilers.
201-
$ RUSTC_LOG=rustc_trans=info rustc +local my-file.rs
205+
$ RUSTC_LOG=rustc_trans=info rustc +stage1 my-file.rs
202206

203207
# This will show the output of all `info!` calls made by rustdoc or any rustc library it calls.
204-
$ RUSTDOC_LOG=info rustdoc +local my-file.rs
208+
$ RUSTDOC_LOG=info rustdoc +stage1 my-file.rs
205209

206210
# This will only show `debug!` calls made by rustdoc directly, not any `rustc*` crate.
207-
$ RUSTDOC_LOG=rustdoc rustdoc +local my-file.rs
211+
$ RUSTDOC_LOG=rustdoc rustdoc +stage1 my-file.rs
208212
```
209213
210214
### How to keep or remove `debug!` and `trace!` calls from the resulting binary
@@ -271,7 +275,7 @@ In addition to [graphviz output](#formatting-graphviz-output-dot-files), MIR deb
271275
flags include an option to generate a MIR representation called `Spanview` that
272276
uses HTML to highlight code regions in the original source code and display
273277
compiler metadata associated with each region.
274-
[`-Zdump-mir-spanview`](./mir/debugging.md), for example, highlights spans
278+
[`-Z dump-mir-spanview`](./mir/debugging.md), for example, highlights spans
275279
associated with each MIR `Statement`, `Terminator`, and/or `BasicBlock`.
276280
277281
These `.html` files use CSS features to dynamically expand spans obscured by

src/diagnostics.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ There are two main ways to find where a given error is emitted:
263263
the error emitting code is removed from the code where the error is
264264
constructed behind a relatively deep call-stack. Even then, it is a good way
265265
to get your bearings.
266-
- Invoking `rustc` with the nightly-only flag `-Ztreat-err-as-bug=1`, which
266+
- Invoking `rustc` with the nightly-only flag `-Z treat-err-as-bug=1`, which
267267
will treat the first error being emitted as an Internal Compiler Error, which
268268
allows you to use the environment variable `RUST_BACKTRACE=full` to get a
269269
stack trace at the point the error has been emitted. Change the `1` to

src/hir-debugging.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# HIR Debugging
22

3-
The `-Zunpretty=hir-tree` flag will dump out the HIR.
3+
The `-Z unpretty=hir-tree` flag will dump out the HIR.
44

55
If you are trying to correlate `NodeId`s or `DefId`s with source code, the
66
`--pretty expanded,identified` flag may be useful.

src/hir.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ the HIR. This makes HIR more amenable to analysis than a normal AST.
1212
This chapter covers the main concepts of the HIR.
1313

1414
You can view the HIR representation of your code by passing the
15-
`-Zunpretty=hir-tree` flag to rustc:
15+
`-Z unpretty=hir-tree` flag to rustc:
1616

1717
```bash
18-
cargo rustc -- -Zunpretty=hir-tree
18+
cargo rustc -- -Z unpretty=hir-tree
1919
```
2020

2121
### Out-of-band storage and the `Crate` type

src/llvm-coverage-instrumentation.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ $ ./x.py test src/test/<test-type> --blessed
308308
[spanview-debugging]: compiler-debugging.md#viewing-spanview-output
309309
[`coverage-llvmir`]: https://github.com/rust-lang/rust/tree/master/src/test/run-make-fulldeps/coverage-llvmir
310310

311-
## Implementation Details of the `InstrumentCoverage` MIR Pass
311+
## Implementation Details of the `InstrumentCoverage` MIR Pass
312312

313313
The bulk of the implementation of the `InstrumentCoverage` MIR pass is performed
314314
by the [`Instrumentor`][instrumentor]. For each MIR (each non-const, non-inlined
@@ -496,8 +496,8 @@ An visual, interactive representation of the final `CoverageSpan`s can be
496496
generated with the following `rustc` flags:
497497

498498
```shell
499-
$ rustc -Zinstrument-coverage -Zdump-mir=InstrumentCoverage \
500-
-Zdump-mir-spanview some_rust_source.rs
499+
$ rustc -Z instrument-coverage -Z dump-mir=InstrumentCoverage \
500+
-Z dump-mir-spanview some_rust_source.rs
501501
```
502502

503503
These flags request Spanview output for the `InstrumentCoverage` pass, and the

src/mir/dataflow.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ for (bb, block) in body.basic_blocks().iter_enumerated() {
201201
### Graphviz Diagrams
202202

203203
When the results of a dataflow analysis are not what you expect, it often helps
204-
to visualize them. This can be done with the `-Zdump-mir` flags described in
205-
[Debugging MIR]. Start with `-Zdump-mir=F -Zdump-mir-dataflow`, where `F` is
204+
to visualize them. This can be done with the `-Z dump-mir` flags described in
205+
[Debugging MIR]. Start with `-Z dump-mir=F -Z dump-mir-dataflow`, where `F` is
206206
either "all" or the name of the MIR body you are interested in.
207207

208208
These `.dot` files will be saved in your `mir_dump` directory and will have the

src/mir/debugging.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
# MIR Debugging
22

3-
The `-Zdump-mir` flag can be used to dump a text representation of the MIR.
4-
The following optional flags, used in combination with `-Zdump-mir`, enable
3+
The `-Z dump-mir` flag can be used to dump a text representation of the MIR.
4+
The following optional flags, used in combination with `-Z dump-mir`, enable
55
additional output formats, including:
66

7-
* `-Zdump-mir-graphviz` - dumps a `.dot` file that represents MIR as a
7+
* `-Z dump-mir-graphviz` - dumps a `.dot` file that represents MIR as a
88
control-flow graph
9-
* `-Zdump-mir-dataflow` - dumps a `.dot` file showing the [dataflow state] at
9+
* `-Z dump-mir-dataflow` - dumps a `.dot` file showing the [dataflow state] at
1010
each point in the control-flow graph
11-
* `-Zdump-mir-spanview` - dumps an `.html` file that highlights the source
11+
* `-Z dump-mir-spanview` - dumps an `.html` file that highlights the source
1212
spans associated with MIR elements (including mouse-over actions to reveal
1313
elements obscured by overlaps, and tooltips to view the MIR statements).
1414
This flag takes an optional value: `statement` (the default), `terminator`, or
1515
`block`, to generate span highlights with different levels of granulatity.
1616

17-
`-Zdump-mir=F` is a handy compiler options that will let you view the MIR for
18-
each function at each stage of compilation. `-Zdump-mir` takes a **filter** `F`
17+
`-Z dump-mir=F` is a handy compiler options that will let you view the MIR for
18+
each function at each stage of compilation. `-Z dump-mir` takes a **filter** `F`
1919
which allows you to control which functions and which passes you are
2020
interesting in. For example:
2121

2222
```bash
23-
> rustc -Zdump-mir=foo ...
23+
> rustc -Z dump-mir=foo ...
2424
```
2525

2626
This will dump the MIR for any function whose name contains `foo`; it
@@ -34,7 +34,7 @@ fn main() {
3434
println!("Hello, world!");
3535
}
3636
^D
37-
> rustc -Zdump-mir=main foo.rs
37+
> rustc -Z dump-mir=main foo.rs
3838
> ls mir_dump/* | wc -l
3939
161
4040
```
@@ -56,7 +56,7 @@ will select for things that reference *both* `main` and the pass
5656
`CleanEndRegions`:
5757

5858
```bash
59-
> rustc -Zdump-mir='main & CleanEndRegions' foo.rs
59+
> rustc -Z dump-mir='main & CleanEndRegions' foo.rs
6060
> ls mir_dump
6161
rustc.main.000-000.CleanEndRegions.after.mir rustc.main.000-000.CleanEndRegions.before.mir
6262
```
@@ -67,7 +67,7 @@ NoLandingPads` will select *either* `main` and `CleanEndRegions` *or*
6767
`main` and `NoLandingPads`:
6868

6969
```bash
70-
> rustc -Zdump-mir='main & CleanEndRegions | main & NoLandingPads' foo.rs
70+
> rustc -Z dump-mir='main & CleanEndRegions | main & NoLandingPads' foo.rs
7171
> ls mir_dump
7272
rustc.main-promoted[0].002-000.NoLandingPads.after.mir
7373
rustc.main-promoted[0].002-000.NoLandingPads.before.mir

src/notification-groups/llvm.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ The ["Debugging LLVM"][d] section of the
2222
rustc-dev-guide gives a step-by-step process for how to help debug bugs
2323
caused by LLVM. In particular, it discusses how to emit LLVM IR, run
2424
the LLVM IR optimization pipelines, and so forth. You may also find
25-
it useful to look at the various codegen options listed under `-Chelp`
26-
and the internal options under `-Zhelp` -- there are a number that
25+
it useful to look at the various codegen options listed under `-C help`
26+
and the internal options under `-Z help` -- there are a number that
2727
pertain to LLVM (just search for LLVM).
2828

2929
[d]: ../backend/debugging.md

src/overview.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ we'll talk about that later.
3232
- The token stream passes through a higher-level lexer located in
3333
[`rustc_parse`] to prepare for the next stage of the compile process. The
3434
[`StringReader`] struct is used at this stage to perform a set of validations
35-
and turn strings into interned symbols (_interning_ is discussed later).
36-
[String interning] is a way of storing only one immutable
35+
and turn strings into interned symbols (_interning_ is discussed later).
36+
[String interning] is a way of storing only one immutable
3737
copy of each distinct string value.
38-
38+
3939
- The lexer has a small interface and doesn't depend directly on the
4040
diagnostic infrastructure in `rustc`. Instead it provides diagnostics as plain
4141
data which are emitted in `rustc_parse::lexer::mod` as real diagnostics.
@@ -330,7 +330,7 @@ For more details on bootstrapping, see
330330

331331
- Does LLVM ever do optimizations in debug builds?
332332
- How do I explore phases of the compile process in my own sources (lexer,
333-
parser, HIR, etc)? - e.g., `cargo rustc -- -Zunpretty=hir-tree` allows you to
333+
parser, HIR, etc)? - e.g., `cargo rustc -- -Z unpretty=hir-tree` allows you to
334334
view HIR representation
335335
- What is the main source entry point for `X`?
336336
- Where do phases diverge for cross-compilation to machine code across
@@ -363,7 +363,7 @@ For more details on bootstrapping, see
363363
- Guide: [Identifiers in the HIR](https://rustc-dev-guide.rust-lang.org/hir.html#identifiers-in-the-hir)
364364
- Guide: [The HIR Map](https://rustc-dev-guide.rust-lang.org/hir.html#the-hir-map)
365365
- Guide: [Lowering AST to HIR](https://rustc-dev-guide.rust-lang.org/lowering.html)
366-
- How to view HIR representation for your code `cargo rustc -- -Zunpretty=hir-tree`
366+
- How to view HIR representation for your code `cargo rustc -- -Z unpretty=hir-tree`
367367
- Rustc HIR definition: [`rustc_hir`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/index.html)
368368
- Main entry point: **TODO**
369369
- Late linting: **TODO**

src/profile-guided-optimization.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ coverage results for PGO has not been attempted at this time.
5454

5555
Generating a PGO-optimized program involves the following four steps:
5656

57-
1. Compile the program with instrumentation enabled (e.g. `rustc -Cprofile-generate main.rs`)
57+
1. Compile the program with instrumentation enabled (e.g. `rustc -C profile-generate main.rs`)
5858
2. Run the instrumented program (e.g. `./main`) which generates a `default-<id>.profraw` file
5959
3. Convert the `.profraw` file into a `.profdata` file using LLVM's `llvm-profdata` tool.
6060
4. Compile the program again, this time making use of the profiling data
61-
(e.g. `rustc -Cprofile-use=merged.profdata main.rs`)
61+
(e.g. `rustc -C profile-use=merged.profdata main.rs`)
6262

6363
### Compile-Time Aspects
6464

0 commit comments

Comments
 (0)