-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Shorten backtraces for queries in ICEs #108938
Shorten backtraces for queries in ICEs #108938
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please add a test case that this works? You can force a panic with -Z treat-err-as-bug
.
This touches the query system by adding a call to it, so |
⌛ Trying commit 1e80402 with merge 8a09f0bf71c4a2e3329eda090794d214addf3b2b... |
This comment has been minimized.
This comment has been minimized.
This should not use |
@Zoxc What do you mean by "proper backtraces"? Why not do this by default? The only time I can imagine the query internals being useful is for people working on the query system itself, which is a very small minority of the people working on the compiler. |
It can sometimes be useful to see where a query was exactly called from. While the query backtrace does contain the calling query name, it doesn't contain more precise information about the location of the call to the query. |
I meant backtraces generated with RUST_BACKTRACE=1. The query internals isn't that useful for people not working on the query system, but the actual backtrace still is useful to see why a specific query was called. |
Ideally we'd hide all the query internals from |
That's exactly what this PR is trying to do. @chenyukang can you post an example of the shortened backtrace for the new test you added? I think having a concrete example will make it more clear what this does. |
Your example doesn't really exercise the query system, can you show an example of something deep within it instead? Like a trait bound error |
I just run the wrong command, re-uploaded new log files. |
@chenyukang I think you're missing a call to |
@jyn514 yes, we should only exclude the frames of queries. |
0fe96d3
to
0186284
Compare
hmm, interesting, I read the code and try some sample code, Actually rust/library/std/src/panicking.rs Line 579 in 39f2657
then rust/library/std/src/sys_common/backtrace.rs Lines 72 to 93 in f37f854
this means we can not use these two functions to remove a middle part of backtrace frames, instead, we can only set the starting point. I used this sample program to verify it: #[inline(never)]
fn __rust_begin_short_backtrace<T, F: FnOnce() -> T>(f: F) -> T {
let result = f();
// prevent this frame from being tail-call optimised away
std::hint::black_box(result)
}
#[inline(never)]
fn __rust_end_short_backtrace<T, F: FnOnce() -> T>(f: F) -> T {
let result = f();
// prevent this frame from being tail-call optimised away
std::hint::black_box(result)
}
fn first() {
println!("first ...");
second();
}
fn second() {
println!("second ..");
third();
}
fn third() {
println!("third ...");
__rust_end_short_backtrace(|| fourth());
}
fn fourth() {
println!("fourth ..");
fifth();
}
fn fifth() {
println!("fifth ...");
__rust_begin_short_backtrace(|| sixth());
}
fn sixth() {
println!("sixth ..");
seven();
}
fn seven() {
println!("seven");
panic!("debug now");
}
fn main() {
first();
} |
ah, that's unfortunate. can we modify that logic to support our use case without breaking existing backtraces? maybe by setting |
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
e268193
to
6c73d4e
Compare
@bors r+ |
@@ -0,0 +1,36 @@ | |||
#!/bin/sh | |||
|
|||
RUST_BACKTRACE=1 $RUSTC src/lib.rs -Z treat-err-as-bug=1 1>$TMPDIR/rust-test-1.log 2>&1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fails on the SGX platform with:
/home/jenkins/workspace/rust-sgx-ci/rust/build/x86_64-unknown-linux-gnu/stage1/bin/rustc: error while loading shared libraries: librustc_driver-b910c833a504f4dd.so: cannot open shared object file: No such file or directory
I'm confused why we get that error. You can ignore the SGX platform for this test as well.
1: short_ice_remove_middle_frames::seven | ||
2: short_ice_remove_middle_frames::sixth | ||
3: short_ice_remove_middle_frames::fifth::{{closure}} | ||
4: short_ice_remove_middle_frames::second |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please emit some kind of marker to indicate that frames have been omitted? This is just plain confusing. For example
4: short_ice_remove_middle_frames::second | |
[some frames omitted] | |
4: short_ice_remove_middle_frames::second |
or
4: short_ice_remove_middle_frames::second | |
[2 frames omitted] | |
4: short_ice_remove_middle_frames::second |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a change: ddacb2d
Found out we need to update https://github.com/rust-lang/backtrace-rs.git to add an API to emit the message.
Maybe we can enhance it in another PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you open an issue for adding the "N frame omitted" line, please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I will create an issue, then make a PR for backtrace-rs first, then another follow-up PR for it.
☔ The latest upstream changes (presumably #108062) made this pull request unmergeable. Please resolve the merge conflicts. |
d8f91e8
to
c3394b3
Compare
@rustbot ready |
@bors r=cjgillot rollup=iffy |
☀️ Test successful - checks-actions |
Finished benchmarking commit (77c836e): comparison URL. Overall result: ❌✅ regressions and improvements - ACTION NEEDEDNext Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 642.167s -> 641.625s (-0.08%) |
The perf regression was expected and deemed acceptable: #108938 (review) |
Remove `QueryEngine` trait This removes the `QueryEngine` trait and `Queries` from `rustc_query_impl` and replaced them with function pointers and fields in `QuerySystem`. As a side effect `OnDiskCache` is moved back into `rustc_middle` and the `OnDiskCache` trait is also removed. This has a couple of benefits. - `TyCtxt` is used in the query system instead of the removed `QueryCtxt` which is larger. - Function pointers are more flexible to work with. A variant of rust-lang/rust#107802 is included which avoids the double indirection. For rust-lang/rust#108938 we can name entry point `__rust_end_short_backtrace` to avoid some overhead. For rust-lang/rust#108062 it avoids the duplicate `QueryEngine` structs. - `QueryContext` now implements `DepContext` which avoids many `dep_context()` calls in `rustc_query_system`. - The `rustc_driver` size is reduced by 0.33%, hopefully that means some bootstrap improvements. - This avoids the unsafe code around the `QueryEngine` trait. r? `@cjgillot`
Remove `QueryEngine` trait This removes the `QueryEngine` trait and `Queries` from `rustc_query_impl` and replaced them with function pointers and fields in `QuerySystem`. As a side effect `OnDiskCache` is moved back into `rustc_middle` and the `OnDiskCache` trait is also removed. This has a couple of benefits. - `TyCtxt` is used in the query system instead of the removed `QueryCtxt` which is larger. - Function pointers are more flexible to work with. A variant of rust-lang/rust#107802 is included which avoids the double indirection. For rust-lang/rust#108938 we can name entry point `__rust_end_short_backtrace` to avoid some overhead. For rust-lang/rust#108062 it avoids the duplicate `QueryEngine` structs. - `QueryContext` now implements `DepContext` which avoids many `dep_context()` calls in `rustc_query_system`. - The `rustc_driver` size is reduced by 0.33%, hopefully that means some bootstrap improvements. - This avoids the unsafe code around the `QueryEngine` trait. r? `@cjgillot`
r? @jyn514
Fixes #107910