Skip to content

Commit

Permalink
Add -Zerror-metrics=PATH to save diagnostic metadata to disk
Browse files Browse the repository at this point in the history
  • Loading branch information
yaahc committed Aug 5, 2024
1 parent 2b78d92 commit 5383592
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Session.vim
*.iml
.vscode
.project
.vim/
.favorites.json
.settings/
.vs/
Expand Down
19 changes: 12 additions & 7 deletions compiler/rustc_driver_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ use rustc_metadata::creader::MetadataLoader;
use rustc_metadata::locator;
use rustc_parse::{new_parser_from_file, new_parser_from_source_str, unwrap_or_emit_fatal};
use rustc_session::config::{
nightly_options, ErrorOutputType, Input, OutFileName, OutputType, CG_OPTIONS, Z_OPTIONS,
nightly_options, ErrorOutputType, Input, OutFileName, OutputType, UnstableOptions, CG_OPTIONS,
Z_OPTIONS,
};
use rustc_session::getopts::{self, Matches};
use rustc_session::lint::{Lint, LintId};
Expand Down Expand Up @@ -301,6 +302,8 @@ fn run_compiler(
let Some(matches) = handle_options(&default_early_dcx, &args) else { return Ok(()) };

let sopts = config::build_session_options(&mut default_early_dcx, &matches);
// fully initialize ice path static once unstable options are available as context
let _ = ice_path_with_config(Some(&sopts.unstable_opts));

if let Some(ref code) = matches.opt_str("explain") {
handle_explain(&default_early_dcx, diagnostics_registry(), code, sopts.color);
Expand Down Expand Up @@ -1307,15 +1310,14 @@ pub fn catch_with_exit_code(f: impl FnOnce() -> interface::Result<()>) -> i32 {
static ICE_PATH: OnceLock<Option<PathBuf>> = OnceLock::new();

fn ice_path() -> &'static Option<PathBuf> {
ice_path_with_config(None)
}

fn ice_path_with_config(config: Option<&UnstableOptions>) -> &'static Option<PathBuf> {
ICE_PATH.get_or_init(|| {
if !rustc_feature::UnstableFeatures::from_environment(None).is_nightly_build() {
return None;
}
if let Some(s) = std::env::var_os("RUST_BACKTRACE")
&& s == "0"
{
return None;
}
let mut path = match std::env::var_os("RUSTC_ICE") {
Some(s) => {
if s == "0" {
Expand All @@ -1324,7 +1326,10 @@ fn ice_path() -> &'static Option<PathBuf> {
}
PathBuf::from(s)
}
None => std::env::current_dir().unwrap_or_default(),
None => config
.and_then(|unstable_opts| unstable_opts.error_metrics.to_owned())
.or_else(|| std::env::current_dir().ok())
.unwrap_or_default(),
};
let now: OffsetDateTime = SystemTime::now().into();
let file_now = now
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1714,6 +1714,8 @@ options! {
"emit the bc module with thin LTO info (default: yes)"),
enforce_type_length_limit: bool = (false, parse_bool, [TRACKED],
"enforce the type length limit when monomorphizing instances in codegen"),
error_metrics: Option<PathBuf> = (None, parse_opt_pathbuf, [UNTRACKED],
"stores metrics about the errors being emitted by rustc to disk"),
export_executable_symbols: bool = (false, parse_bool, [TRACKED],
"export symbols from executables, as if they were dynamic libraries"),
external_clangrt: bool = (false, parse_bool, [UNTRACKED],
Expand Down

0 comments on commit 5383592

Please sign in to comment.