Skip to content

Commit

Permalink
Inline dump_file_basename into dump_path
Browse files Browse the repository at this point in the history
  • Loading branch information
Zalathar committed Jan 17, 2024
1 parent b82d1d3 commit 1ec567b
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions compiler/rustc_middle/src/mir/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,17 @@ fn dump_matched_mir_node<'tcx, F>(
}
}

/// Returns the file basename portion (without extension) of a filename path
/// where we should dump a MIR representation output files.
fn dump_file_basename<'tcx>(
/// Returns the path to the filename where we should dump a given MIR.
/// Also used by other bits of code (e.g., NLL inference) that dump
/// graphviz data or other things.
fn dump_path<'tcx>(
tcx: TyCtxt<'tcx>,
extension: &str,
pass_num: bool,
pass_name: &str,
disambiguator: &dyn Display,
body: &Body<'tcx>,
) -> String {
) -> PathBuf {
let source = body.source;
let promotion_id = match source.promoted {
Some(id) => format!("-{id:?}"),
Expand Down Expand Up @@ -186,19 +188,12 @@ fn dump_file_basename<'tcx>(
_ => String::new(),
};

format!(
"{crate_name}.{item_name}{shim_disambiguator}{promotion_id}{pass_num}.{pass_name}.{disambiguator}",
)
}

/// Returns the path to the filename where we should dump a given MIR.
/// Also used by other bits of code (e.g., NLL inference) that dump
/// graphviz data or other things.
fn dump_path(tcx: TyCtxt<'_>, basename: &str, extension: &str) -> PathBuf {
let mut file_path = PathBuf::new();
file_path.push(Path::new(&tcx.sess.opts.unstable_opts.dump_mir_dir));

let file_name = format!("{basename}.{extension}",);
let file_name = format!(
"{crate_name}.{item_name}{shim_disambiguator}{promotion_id}{pass_num}.{pass_name}.{disambiguator}.{extension}",
);

file_path.push(&file_name);

Expand All @@ -217,11 +212,7 @@ pub fn create_dump_file<'tcx>(
disambiguator: &dyn Display,
body: &Body<'tcx>,
) -> io::Result<io::BufWriter<fs::File>> {
let file_path = dump_path(
tcx,
&dump_file_basename(tcx, pass_num, pass_name, disambiguator, body),
extension,
);
let file_path = dump_path(tcx, extension, pass_num, pass_name, disambiguator, body);
if let Some(parent) = file_path.parent() {
fs::create_dir_all(parent).map_err(|e| {
io::Error::new(
Expand Down

0 comments on commit 1ec567b

Please sign in to comment.