Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output column number info when panicking #42938

Merged
merged 5 commits into from
Jul 2, 2017
Merged

Conversation

est31
Copy link
Member

@est31 est31 commented Jun 27, 2017

Outputs the column number when panicking. Useful when you e.g. have code like foo[i] = bar[k] + bar[l] and you get a panic with index out of bounds, or when you have an expression like a = b + c + d + e and the addition overflows. Now you know which operation to blame!

The format is file:line:column, just like for compiler errors. Example output with the patch:

thread 'main' panicked at 'index out of bounds: the len is 5 but the index is 8', src/main.rs:3:8

As some of the API between the compiler and the library landscape gets broken, this is a bit hackier than I'd originally wanted it to be.

  • panic and panic_bounds_check lang items got an additional column param, on stage0 I still have to use the previous version. After a SNAP this should be resolved.
  • For #[derive(RustcDeserialze)], stage0 requires a fixed signature for std::rt::begin_panic, so we can't change it right away. What we need to do instead is to keep the signature, and add a begin_panic_new function that we use in later stages instead. After a SNAP we can change the begin_panic function and rely on it instead of begin_panic_new, and one SNAP later we can remove begin_panic_new.
  • Fortunately I didn't have to break anything about the panic hook API, I could easily extend it.

Note that debuginfo remains unchanged, so RUST_BACKTRACE output won't contain any column info. See issue #42921 for discussion on including the column in debuginfo.

@rust-highfive
Copy link
Collaborator

r? @brson

(rust_highfive has picked a reviewer for you, use r? to override)

@eddyb
Copy link
Member

eddyb commented Jun 27, 2017

cc @rust-lang/libs About the addition of panicking::Location::column. r=me otherwise.

@arielb1 arielb1 added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jun 27, 2017
@est31
Copy link
Member Author

est31 commented Jun 28, 2017

I've renamed the commit (without any code changes) and added a second one with a small refactor, a comment for the stage0 updater, and (hopefully) a fix for the test failure.

@sfackler
Copy link
Member

👍

@est31 est31 changed the title [WIP] Output column number info when panicking Output column number info when panicking Jun 28, 2017
@est31
Copy link
Member Author

est31 commented Jun 28, 2017

ready. r? @eddyb

@rust-highfive rust-highfive assigned eddyb and unassigned brson Jun 28, 2017
@est31
Copy link
Member Author

est31 commented Jun 29, 2017

cc @alexcrichton

@aidanhs aidanhs added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 30, 2017
Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok looks pretty good to me, thanks @est31! Mind doing some size analysis to ensure this doesn't increase the size of anything too much?

#[allow(improper_ctypes)]
extern {
#[lang = "panic_fmt"]
#[unwind]
fn panic_impl(fmt: fmt::Arguments, file: &'static str, line: u32) -> !;
fn panic_impl(fmt: fmt::Arguments, file: &'static str, line: u32, col :u32) -> !;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/col :u32/col: u32/

@est31
Copy link
Member Author

est31 commented Jul 2, 2017

Mind doing some size analysis to ensure this doesn't increase the size of anything too much?

I've compiled rustc with the patch and with the commit this PR bases on, and these are the results:


Without patch:
120136	build/x86_64-unknown-linux-gnu/stage1-rustc
93752	build/x86_64-unknown-linux-gnu/stage1-std

With patch:
120148	build/x86_64-unknown-linux-gnu/stage1-rustc
93772	build/x86_64-unknown-linux-gnu/stage1-std

Numbers come from du output, and are therefore in kb. I've rm -r'd both directories beforehand, so artifacts of other builds don't overlap.

So almost no noticeable change, its in the sub-0.1% range for both std and rustc.

@eddyb
Copy link
Member

eddyb commented Jul 2, 2017

@bors r+

@bors
Copy link
Contributor

bors commented Jul 2, 2017

📌 Commit 376c6e7 has been approved by eddyb

@bors
Copy link
Contributor

bors commented Jul 2, 2017

⌛ Testing commit 376c6e71b0aa8bc62d5ff4a469d35a6feb063c0c with merge 018afe2f0682464086a7ebae11637bf160a4a711...

@bors
Copy link
Contributor

bors commented Jul 2, 2017

💔 Test failed - status-travis

@est31
Copy link
Member Author

est31 commented Jul 2, 2017

The failure looks legit, I'll investigate.

@est31
Copy link
Member Author

est31 commented Jul 2, 2017

The error is inside cargo's testsuite:

(expand)

[01:11:06] thread 'cargo_bench_failing_test' panicked at '
[01:11:06] Expected: execs
[01:11:06]     but: expected to find:
[01:11:06] [..]src[/]foo.rs:14
[01:11:06] 
[01:11:06] did not find in output:
[01:11:06]    Compiling foo v0.5.0 (file:///checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/cit/t11/foo)
[01:11:06]     Finished release [optimized] target(s) in 0.67 secs
[01:11:06]      Running target/release/deps/foo-b865dce48c3e4e89
[01:11:06] thread 'main' panicked at 'assertion failed: `(left == right)`
[01:11:06]   left: `"hello"`,
[01:11:06]  right: `"nope"`', src/foo.rs:14:16
[01:11:06] note: Run with `RUST_BACKTRACE=1` for a backtrace.
[01:11:06] error: bench failed
[01:11:06] ', /cargo/registry/src/github.com-1ecc6299db9ec823/hamcrest-0.1.1/src/core.rs:31:12

est31 added a commit to est31/cargo that referenced this pull request Jul 2, 2017
bors added a commit to rust-lang/cargo that referenced this pull request Jul 2, 2017
Let the cargo_bench_failing_test tolerate col info

Needed by rust-lang/rust#42938
@est31
Copy link
Member Author

est31 commented Jul 2, 2017

@Mark-Simulacrum are you sure that an update to Cargo.toml/Cargo.lock is needed? E.g. look at git commit 77931c2, it has no update.

About the other cargo failures... I'll try to fix them as well. Right now my hardware is a bit limited so I can't really run the testsuite sadly...

@Mark-Simulacrum
Copy link
Member

Cargo.lock was updated though: 77931c2#diff-5d9bf57935c52008319cccc88d4d737dR160.

est31 added a commit to est31/cargo that referenced this pull request Jul 2, 2017
Needed by rust-lang/rust#42938

I've now ripgrepped for "panicked at" and found no further
test that hardcodes the "filename:line$" format.
bors added a commit to rust-lang/cargo that referenced this pull request Jul 2, 2017
Let two further tests tolerate col info in panics

Needed by rust-lang/rust#42938

I've now ripgrepped for "panicked at" and found no further
test that hardcodes the "filename:line$" format.
@eddyb
Copy link
Member

eddyb commented Jul 2, 2017

@bors r+

@bors
Copy link
Contributor

bors commented Jul 2, 2017

📌 Commit 3b91f94 has been approved by eddyb

@bors
Copy link
Contributor

bors commented Jul 2, 2017

⌛ Testing commit 3b91f94 with merge 0679711...

bors added a commit that referenced this pull request Jul 2, 2017
Output column number info when panicking

Outputs the column number when panicking. Useful when you e.g. have code like `foo[i] = bar[k] + bar[l]` and you get a panic with index out of bounds, or when you have an expression like `a = b + c + d + e` and the addition overflows. Now you know which operation to blame!

The format is `file:line:column`, just like for compiler errors. Example output with the patch:

```
thread 'main' panicked at 'index out of bounds: the len is 5 but the index is 8', src/main.rs:3:8
```

As some of the API between the compiler and the library landscape gets broken, this is a bit hackier than I'd originally wanted it to be.

* `panic` and `panic_bounds_check` lang items got an additional column param, on stage0 I still have to use the previous version. After a SNAP this should be resolved.
* For `#[derive(RustcDeserialze)]`, stage0 requires a fixed signature for `std::rt::begin_panic`, so we can't change it right away. What we need to do instead is to keep the signature, and add a `begin_panic_new` function that we use in later stages instead. After a SNAP we can change the `begin_panic` function and rely on it instead of `begin_panic_new`, and one SNAP later we can remove `begin_panic_new`.
* Fortunately I didn't have to break anything about the panic hook API, I could easily extend it.

Note that debuginfo remains unchanged, so RUST_BACKTRACE output won't contain any column info. See issue #42921 for discussion on including the column in debuginfo.
@bors
Copy link
Contributor

bors commented Jul 2, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: eddyb
Pushing 0679711 to master...

@bors bors merged commit 3b91f94 into rust-lang:master Jul 2, 2017
alexcrichton pushed a commit to alexcrichton/cargo that referenced this pull request Jul 13, 2017
Needed by rust-lang/rust#42938

I've now ripgrepped for "panicked at" and found no further
test that hardcodes the "filename:line$" format.
est31 added a commit to est31/rust that referenced this pull request Jul 25, 2017
In rust-lang#42938 we made the compiler
emit a call to begin_panic_new in order to pass column info to it. Now
with stage0 updated (rust-lang#43320),
we can safely change begin_panic and start emitting calls for it again.
bors added a commit that referenced this pull request Jul 27, 2017
Switch to begin_panic again

In #42938 we made the compiler
emit a call to begin_panic_new in order to pass column info to it. Now
with stage0 updated (#43320),
we can safely change begin_panic and start emitting calls for it again.
est31 added a commit to est31/rust that referenced this pull request Jan 10, 2018
I've added the panic_col feature in PR rust-lang#42938.
Now it's time to stabilize it!
Closes rust-lang#42939.
frewsxcv added a commit to frewsxcv/rust that referenced this pull request Jan 10, 2018
Stabilize the panic_col feature

I've added the panic_col feature in PR rust-lang#42938.
Now it's time to stabilize it!
Closes rust-lang#42939.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants