Skip to content

Commit 29572cd

Browse files
cg-cnumark-i-m
authored andcommitted
refactor: fixed typos, text formatting suggested in the review
1 parent 8e02b37 commit 29572cd

File tree

2 files changed

+26
-23
lines changed

2 files changed

+26
-23
lines changed

src/SUMMARY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- [Adding new tests](./tests/adding.md)
99
- [Using `compiletest` + commands to control test
1010
execution](./compiletest.md)
11+
- [Debugging the Compiler](./compiler-debugging.md)
1112
- [Walkthrough: a typical contribution](./walkthrough.md)
1213
- [High-level overview of the compiler source](./high-level-overview.md)
1314
- [The Rustc Driver](./rustc-driver.md)
@@ -52,7 +53,6 @@
5253
- [miri const evaluator](./miri.md)
5354
- [Parameter Environments](./param_env.md)
5455
- [Generating LLVM IR](./trans.md)
55-
- [Debugging the Compiler](./compiler-debugging.md)
5656

5757
---
5858

src/compiler-debugging.md

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,30 @@ you might want to find some way to use Linux or MSVC on Windows.
2020
In the default configuration, you don't have line numbers enabled, so the
2121
backtrace looks like this:
2222

23-
```
23+
```text
2424
stack backtrace:
2525
0: std::sys::imp::backtrace::tracing::imp::unwind_backtrace
2626
1: std::sys_common::backtrace::_print
2727
2: std::panicking::default_hook::{{closure}}
2828
3: std::panicking::default_hook
2929
4: std::panicking::rust_panic_with_hook
3030
5: std::panicking::begin_panic
31-
6: rustc_typeck::check::cast::<impl rustc_typeck::check::FnCtxt<'a, 'gcx, \
32-
'tcx>>::pointer_kind
3331
(~~~~ LINES REMOVED BY ME FOR BREVITY ~~~~)
3432
32: rustc_typeck::check_crate
3533
33: <std::thread::local::LocalKey<T>>::with
3634
34: <std::thread::local::LocalKey<T>>::with
3735
35: rustc::ty::context::TyCtxt::create_and_enter
3836
36: rustc_driver::driver::compile_input
3937
37: rustc_driver::run_compiler
40-
```
38+
```
4139

4240
If you want line numbers for the stack trace, you can enable
4341
`debuginfo-lines=true` or `debuginfo=true` in your config.toml and rebuild the
4442
compiler. Then the backtrace will look like this:
4543

46-
```
44+
```text
4745
stack backtrace:
4846
(~~~~ LINES REMOVED BY ME FOR BREVITY ~~~~)
49-
6: rustc_typeck::check::cast::<impl rustc_typeck::check::FnCtxt<'a, 'gcx, \
50-
'tcx>>::pointer_kind
5147
at /home/user/rust/src/librustc_typeck/check/cast.rs:110
5248
7: rustc_typeck::check::cast::CastCheck::check
5349
at /home/user/rust/src/librustc_typeck/check/cast.rs:572
@@ -72,11 +68,15 @@ This can also help when debugging `delay_span_bug` calls - it will make
7268
the first `delay_span_bug` call panic, which will give you a useful backtrace.
7369

7470
For example:
75-
```
71+
72+
```rust
7673
$ cat error.rs
7774
fn main() {
7875
1 + ();
7976
}
77+
```
78+
79+
```bash
8080
$ ./build/x86_64-unknown-linux-gnu/stage1/bin/rustc error.rs
8181
error[E0277]: the trait bound `{integer}: std::ops::Add<()>` is not satisfied
8282
--> error.rs:2:7
@@ -137,8 +137,8 @@ $ # Cool, now I have a backtrace for the error
137137
138138
The compiler has a lot of `debug!` calls, which print out logging information
139139
at many points. These are very useful to at least narrow down the location of
140-
a bug if not to find it entirely, or just to orient yourself to why a compiler
141-
is doing a particular thing.
140+
a bug if not to find it entirely, or just to orient yourself as to why the
141+
compiler is doing a particular thing.
142142
143143
To see the logs, you need to set the `RUST_LOG` environment variable to
144144
your log filter, e.g. to get the logs for a specific module, you can run the
@@ -152,7 +152,8 @@ of output - so it's typically a good idea to pipe standard error to a file
152152
and look at the log output with a text editor.
153153
154154
So to put it together.
155-
```
155+
156+
```bash
156157
# This puts the output of all debug calls in `librustc/traits` into
157158
# standard error, which might fill your console backscroll.
158159
$ RUST_LOG=rustc::traits rustc +local my-file.rs
@@ -191,10 +192,10 @@ want to call `x.py clean` to force one.
191192
### Logging etiquette
192193
193194
Because calls to `debug!` are removed by default, in most cases, don't worry
194-
about adding "unnecessary" calls to `debug!` and leaving them in in code
195-
you commit - they won't slow
196-
down the performance of what we ship, and if they helped you pinning down
197-
a bug, they will probably help someone else with a different one.
195+
about adding "unnecessary" calls to `debug!` and leaving them in code you
196+
commit - they won't slow down the performance of what we ship, and if they
197+
helped you pinning down a bug, they will probably help someone else with a
198+
different one.
198199
199200
However, there are still a few concerns that you might care about:
200201
@@ -253,7 +254,7 @@ dumps various borrow-checker dataflow graphs.
253254
These all produce `.dot` files. To view these files, install graphviz (e.g.
254255
`apt-get install graphviz`) and then run the following commands:
255256
256-
```
257+
```bash
257258
$ dot -T pdf maybe_init_suffix.dot > maybe_init_suffix.pdf
258259
$ firefox maybe_init_suffix.pdf # Or your favorite pdf viewer
259260
```
@@ -281,12 +282,13 @@ to replicate manually and means that LLVM is called multiple times in parallel.
281282
If you can get away with it (i.e. if it doesn't make your bug disappear),
282283
passing `-C codegen-units=1` to rustc will make debugging easier.
283284
284-
If you want to play with the optimization pipeline, you can use the `opt` from
285-
there on the IR rustc emits with `--emit=llvm-ir`. Note
286-
that rustc emits different IR depending on whether `-O` is enabled, even without
287-
LLVM's optimizations, so if you want to play with the IR rustc emits,
285+
If you want to play with the optimization pipeline, you can use the opt tool
286+
from `./build/<host-triple>/llvm/bin/` with the the LLVM IR emitted by rustc.
287+
Note that rustc emits different IR depending on whether `-O` is enabled, even
288+
without LLVM's optimizations, so if you want to play with the IR rustc emits,
288289
you should:
289-
```
290+
291+
```bash
290292
$ rustc +local my-file.rs --emit=llvm-ir -O -C no-prepopulate-passes \
291293
-C codegen-units=1
292294
$ OPT=./build/$TRIPLE/llvm/bin/opt
@@ -309,7 +311,8 @@ the printouts will mix together and you won't be able to read anything.
309311
If you want just the IR for a specific function (say, you want to see
310312
why it causes an assertion or doesn't optimize correctly), you can use
311313
`llvm-extract`, e.g.
312-
```
314+
315+
```bash
313316
$ ./build/$TRIPLE/llvm/bin/llvm-extract \
314317
-func='_ZN11collections3str21_$LT$impl$u20$str$GT$7replace17hbe10ea2e7c809b0bE' \
315318
-S \

0 commit comments

Comments
 (0)