Skip to content

Commit 8057e62

Browse files
committed
Add support for SpanTrace capture in ICE reports
let me push damnit! we meet again rustfmt enable trace by default checkpoint while figuring out this damn rebase reduce log level to avoid bugs in logging remove accidentally readded fn remove unused deps bless these initially, deal with actual output next add example with spantrace output try to hack around the issue to get nice output with proper spantrace output add helper message for spantrace
1 parent 1203e08 commit 8057e62

File tree

19 files changed

+90
-23
lines changed

19 files changed

+90
-23
lines changed

Cargo.lock

+29-11
Original file line numberDiff line numberDiff line change
@@ -3323,6 +3323,16 @@ version = "0.3.0"
33233323
source = "registry+https://github.com/rust-lang/crates.io-index"
33243324
checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be"
33253325

3326+
[[package]]
3327+
name = "nu-ansi-term"
3328+
version = "0.46.0"
3329+
source = "registry+https://github.com/rust-lang/crates.io-index"
3330+
checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84"
3331+
dependencies = [
3332+
"overload",
3333+
"winapi",
3334+
]
3335+
33263336
[[package]]
33273337
name = "num-integer"
33283338
version = "0.1.43"
@@ -3500,6 +3510,12 @@ dependencies = [
35003510
"winapi",
35013511
]
35023512

3513+
[[package]]
3514+
name = "overload"
3515+
version = "0.1.1"
3516+
source = "registry+https://github.com/rust-lang/crates.io-index"
3517+
checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"
3518+
35033519
[[package]]
35043520
name = "owo-colors"
35053521
version = "3.5.0"
@@ -4588,6 +4604,7 @@ dependencies = [
45884604
"rustc_ty_utils",
45894605
"serde_json",
45904606
"tracing",
4607+
"tracing-error",
45914608
"winapi",
45924609
]
45934610

@@ -4919,6 +4936,7 @@ dependencies = [
49194936
"rustc_span",
49204937
"tracing",
49214938
"tracing-core",
4939+
"tracing-error",
49224940
"tracing-subscriber",
49234941
"tracing-tree",
49244942
]
@@ -5742,9 +5760,9 @@ dependencies = [
57425760

57435761
[[package]]
57445762
name = "sharded-slab"
5745-
version = "0.1.1"
5763+
version = "0.1.4"
57465764
source = "registry+https://github.com/rust-lang/crates.io-index"
5747-
checksum = "79c719719ee05df97490f80a45acfc99e5a30ce98a1e4fb67aee422745ae14e3"
5765+
checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31"
57485766
dependencies = [
57495767
"lazy_static",
57505768
]
@@ -6387,9 +6405,9 @@ dependencies = [
63876405

63886406
[[package]]
63896407
name = "tracing-core"
6390-
version = "0.1.28"
6408+
version = "0.1.30"
63916409
source = "registry+https://github.com/rust-lang/crates.io-index"
6392-
checksum = "7b7358be39f2f274f322d2aaed611acc57f382e8eb1e5b48cb9ae30933495ce7"
6410+
checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a"
63936411
dependencies = [
63946412
"once_cell",
63956413
"valuable",
@@ -6407,9 +6425,9 @@ dependencies = [
64076425

64086426
[[package]]
64096427
name = "tracing-log"
6410-
version = "0.1.2"
6428+
version = "0.1.3"
64116429
source = "registry+https://github.com/rust-lang/crates.io-index"
6412-
checksum = "a6923477a48e41c1951f1999ef8bb5a3023eb723ceadafe78ffb65dc366761e3"
6430+
checksum = "78ddad33d2d10b1ed7eb9d1f518a5674713876e97e5bb9b7345a7984fbb4f922"
64136431
dependencies = [
64146432
"lazy_static",
64156433
"log",
@@ -6418,14 +6436,14 @@ dependencies = [
64186436

64196437
[[package]]
64206438
name = "tracing-subscriber"
6421-
version = "0.3.3"
6439+
version = "0.3.16"
64226440
source = "registry+https://github.com/rust-lang/crates.io-index"
6423-
checksum = "245da694cc7fc4729f3f418b304cb57789f1bed2a78c575407ab8a23f53cb4d3"
6441+
checksum = "a6176eae26dd70d0c919749377897b54a9276bd7061339665dd68777926b5a70"
64246442
dependencies = [
6425-
"ansi_term",
6426-
"lazy_static",
64276443
"matchers",
6428-
"parking_lot 0.11.2",
6444+
"nu-ansi-term",
6445+
"once_cell",
6446+
"parking_lot 0.12.1",
64296447
"regex",
64306448
"sharded-slab",
64316449
"smallvec",

compiler/rustc_driver_impl/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ rustc_interface = { path = "../rustc_interface" }
5050
rustc_ast = { path = "../rustc_ast" }
5151
rustc_span = { path = "../rustc_span" }
5252
rustc_hir_analysis = { path = "../rustc_hir_analysis" }
53+
tracing-error = "0.2.0"
5354

5455
[target.'cfg(unix)'.dependencies]
5556
libc = "0.2"
@@ -60,5 +61,4 @@ winapi = { version = "0.3", features = ["consoleapi", "debugapi", "processenv"]
6061
[features]
6162
llvm = ['rustc_interface/llvm']
6263
max_level_info = ['rustc_log/max_level_info']
63-
rustc_use_parallel_compiler = ['rustc_data_structures/rustc_use_parallel_compiler', 'rustc_interface/rustc_use_parallel_compiler',
64-
'rustc_middle/rustc_use_parallel_compiler']
64+
rustc_use_parallel_compiler = ['rustc_data_structures/rustc_use_parallel_compiler', 'rustc_interface/rustc_use_parallel_compiler', 'rustc_middle/rustc_use_parallel_compiler']

compiler/rustc_driver_impl/src/lib.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -1245,6 +1245,15 @@ pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
12451245

12461246
interface::try_print_query_stack(&handler, num_frames);
12471247

1248+
let spantrace = tracing_error::SpanTrace::capture().to_string();
1249+
if !spantrace.is_empty() {
1250+
eprintln!("SpanTrace:\n{}", spantrace);
1251+
} else {
1252+
eprintln!(
1253+
"note: run with `RUSTC_ICE_LOG=trace` environment variable to display a SpanTrace"
1254+
);
1255+
}
1256+
12481257
#[cfg(windows)]
12491258
unsafe {
12501259
if env::var("RUSTC_BREAK_ON_ICE").is_ok() {
@@ -1273,14 +1282,14 @@ pub fn install_ice_hook() {
12731282
/// This allows tools to enable rust logging without having to magically match rustc's
12741283
/// tracing crate version.
12751284
pub fn init_rustc_env_logger() {
1276-
init_env_logger("RUSTC_LOG");
1285+
init_env_logger("RUSTC_LOG", "RUSTC_ICE_LOG");
12771286
}
12781287

12791288
/// This allows tools to enable rust logging without having to magically match rustc's
12801289
/// tracing crate version. In contrast to `init_rustc_env_logger` it allows you to choose an env var
12811290
/// other than `RUSTC_LOG`.
1282-
pub fn init_env_logger(env: &str) {
1283-
if let Err(error) = rustc_log::init_env_logger(env) {
1291+
pub fn init_env_logger(env: &str, ice_env: &str) {
1292+
if let Err(error) = rustc_log::init_env_logger(env, ice_env) {
12841293
early_error(ErrorOutputType::default(), &error.to_string());
12851294
}
12861295
}

compiler/rustc_log/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ edition = "2021"
55

66
[dependencies]
77
tracing = "0.1.28"
8-
tracing-subscriber = { version = "0.3.3", default-features = false, features = ["fmt", "env-filter", "smallvec", "parking_lot", "ansi"] }
8+
tracing-subscriber = { version = "0.3.16", default-features = false, features = ["registry", "fmt", "env-filter", "smallvec", "parking_lot", "ansi"] }
99
tracing-tree = "0.2.0"
1010
tracing-core = "0.1.28"
11+
tracing-error = "0.2.0"
1112

1213
[dev-dependencies]
1314
rustc_span = { path = "../rustc_span" }

compiler/rustc_log/src/lib.rs

+20-5
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,32 @@
4545
use std::env::{self, VarError};
4646
use std::fmt::{self, Display};
4747
use std::io::{self, IsTerminal};
48+
use std::str::FromStr;
4849
use tracing_core::{Event, Subscriber};
4950
use tracing_subscriber::filter::{Directive, EnvFilter, LevelFilter};
5051
use tracing_subscriber::fmt::{
5152
format::{self, FormatEvent, FormatFields},
5253
FmtContext,
5354
};
5455
use tracing_subscriber::layer::SubscriberExt;
56+
use tracing_subscriber::Layer;
5557

56-
pub fn init_env_logger(env: &str) -> Result<(), Error> {
57-
let filter = match env::var(env) {
58+
/// In contrast to `init_rustc_env_logger` this allows you to choose an env var
59+
/// other than `RUSTC_LOG`.
60+
pub fn init_env_logger(env: &str, ice_env: &str) -> Result<(), Error> {
61+
let log_filter = match env::var(env) {
5862
Ok(env) => EnvFilter::new(env),
5963
_ => EnvFilter::default().add_directive(Directive::from(LevelFilter::WARN)),
6064
};
6165

66+
let error_filter = match env::var(ice_env) {
67+
Ok(env) => tracing::Level::from_str(&env).unwrap(),
68+
_ => tracing::Level::WARN,
69+
};
70+
let error_filter = tracing_subscriber::filter::filter_fn(move |metadata| {
71+
metadata.is_span() && metadata.level() <= &error_filter
72+
});
73+
6274
let color_logs = match env::var(String::from(env) + "_COLOR") {
6375
Ok(value) => match value.as_ref() {
6476
"always" => true,
@@ -75,7 +87,7 @@ pub fn init_env_logger(env: &str) -> Result<(), Error> {
7587
Some(v) => &v != "0",
7688
};
7789

78-
let layer = tracing_tree::HierarchicalLayer::default()
90+
let log_layer = tracing_tree::HierarchicalLayer::default()
7991
.with_writer(io::stderr)
8092
.with_indent_lines(true)
8193
.with_ansi(color_logs)
@@ -84,9 +96,12 @@ pub fn init_env_logger(env: &str) -> Result<(), Error> {
8496
.with_verbose_entry(verbose_entry_exit)
8597
.with_indent_amount(2);
8698
#[cfg(parallel_compiler)]
87-
let layer = layer.with_thread_ids(true).with_thread_names(true);
99+
let log_layer = log_layer.with_thread_ids(true).with_thread_names(true);
100+
let error_layer = tracing_error::ErrorLayer::default();
101+
let subscriber = tracing_subscriber::Registry::default()
102+
.with(error_layer.with_filter(error_filter))
103+
.with(log_layer.with_filter(log_filter));
88104

89-
let subscriber = tracing_subscriber::Registry::default().with(filter).with(layer);
90105
match env::var(format!("{env}_BACKTRACE")) {
91106
Ok(str) => {
92107
let fmt_layer = tracing_subscriber::fmt::layer()

compiler/rustc_session/src/session.rs

+1
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,7 @@ impl Session {
677677
|| self.opts.unstable_opts.unpretty.is_some()
678678
|| self.opts.output_types.contains_key(&OutputType::Mir)
679679
|| std::env::var_os("RUSTC_LOG").is_some()
680+
|| std::env::var_os("RUSTC_ICE_LOG").is_some()
680681
{
681682
return;
682683
}

src/librustdoc/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ pub fn main() {
167167
// `debug_logging = true` is because all rustc logging goes to its version of tracing (the one
168168
// in the sysroot), and all of rustdoc's logging goes to its version (the one in Cargo.toml).
169169
init_logging();
170-
rustc_driver::init_env_logger("RUSTDOC_LOG");
170+
rustc_driver::init_env_logger("RUSTDOC_LOG", "RUSTDOC_ICE_LOG");
171171

172172
let exit_code = rustc_driver::catch_with_exit_code(|| match get_args() {
173173
Some(args) => main_args(&args),

src/tools/tidy/src/deps.rs

+11
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,12 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[
167167
"memmap2",
168168
"memoffset",
169169
"miniz_oxide",
170+
"nu-ansi-term",
170171
"num_cpus",
171172
"object",
172173
"odht",
173174
"once_cell",
175+
"overload",
174176
"parking_lot",
175177
"parking_lot_core",
176178
"pathdiff",
@@ -237,6 +239,7 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[
237239
"tracing-log",
238240
"tracing-subscriber",
239241
"tracing-tree",
242+
"tracing-error",
240243
"twox-hash",
241244
"type-map",
242245
"typenum",
@@ -264,6 +267,14 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[
264267
"winapi-i686-pc-windows-gnu",
265268
"winapi-util",
266269
"winapi-x86_64-pc-windows-gnu",
270+
"windows-sys",
271+
"windows_aarch64_msvc",
272+
"windows_aarch64_gnullvm",
273+
"windows_i686_gnu",
274+
"windows_i686_msvc",
275+
"windows_x86_64_gnu",
276+
"windows_x86_64_gnullvm",
277+
"windows_x86_64_msvc",
267278
"writeable",
268279
// this is a false-positive: it's only used by rustfmt, but because it's enabled through a
269280
// feature, tidy thinks it's used by rustc as well.

tests/ui/associated-inherent-types/bugs/ice-substitution.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ query stack during panic:
44
#0 [typeck] type-checking `weird`
55
#1 [typeck_item_bodies] type-checking all item bodies
66
end of query stack
7+
note: run with `RUSTC_ICE_LOG=trace` environment variable to display a SpanTrace

tests/ui/chalkify/bugs/async.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// edition:2021
22
// known-bug: unknown
33
// unset-rustc-env:RUST_BACKTRACE
4+
// rustc-env:RUSTC_ICE_LOG=trace
45
// compile-flags:-Z trait-solver=chalk
56
// error-pattern:internal compiler error
67
// failure-status:101

tests/ui/chalkify/bugs/async.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ LL | async fn foo(x: u32) -> u32 {
2323
#8 [check_mod_item_types] checking item types in top-level module
2424
#9 [analysis] running analysis passes on this crate
2525
end of query stack
26+
SpanTrace:
27+
2628
error: aborting due to 2 previous errors
2729

2830
For more information about this error, try `rustc --explain E0277`.

tests/ui/consts/const-eval/const-eval-query-stack.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ query stack during panic:
1111
#3 [lint_mod] linting top-level module
1212
#4 [analysis] running analysis passes on this crate
1313
end of query stack
14+
note: run with `RUSTC_ICE_LOG=trace` environment variable to display a SpanTrace

tests/ui/impl-trait/issues/issue-86800.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ query stack during panic:
2222
#1 [check_mod_item_types] checking item types in top-level module
2323
#2 [analysis] running analysis passes on this crate
2424
end of query stack
25+

tests/ui/impl-trait/normalize-tait-in-const.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ query stack during panic:
44
#0 [eval_to_allocation_raw] const-evaluating + checking `BAR`
55
#1 [eval_to_const_value_raw] simplifying constant for the type system `BAR`
66
end of query stack
7+
note: run with `RUSTC_ICE_LOG=trace` environment variable to display a SpanTrace
78
error: aborting due to previous error
89

tests/ui/layout/valid_range_oob.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ query stack during panic:
44
#0 [layout_of] computing layout of `Foo`
55
#1 [eval_to_allocation_raw] const-evaluating + checking `FOO`
66
end of query stack
7+
note: run with `RUSTC_ICE_LOG=trace` environment variable to display a SpanTrace

tests/ui/mir/validate/storage-live.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ query stack during panic:
1111
#0 [mir_const] preparing `multiple_storage` for borrow checking
1212
#1 [mir_promoted] processing MIR for `multiple_storage`
1313
end of query stack
14+
note: run with `RUSTC_ICE_LOG=trace` environment variable to display a SpanTrace

tests/ui/panics/default-backtrace-ice.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ error: the compiler unexpectedly panicked. this is a bug.
1515
query stack during panic:
1616
#0 [resolver_for_lowering] getting the resolver for lowering
1717
end of query stack
18+

tests/ui/treat-err-as-bug/delay_span_bug.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ error: the compiler unexpectedly panicked. this is a bug.
99
query stack during panic:
1010
#0 [trigger_delay_span_bug] triggering a delay span bug
1111
end of query stack
12+
note: run with `RUSTC_ICE_LOG=trace` environment variable to display a SpanTrace

tests/ui/treat-err-as-bug/err.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ query stack during panic:
1010
#0 [eval_to_allocation_raw] const-evaluating + checking `C`
1111
#1 [eval_to_allocation_raw] const-evaluating + checking `C`
1212
end of query stack
13+
note: run with `RUSTC_ICE_LOG=trace` environment variable to display a SpanTrace

0 commit comments

Comments
 (0)