Rollup merge of #120038 - Zalathar:dump-path, r=WaffleLapkin
Don't create a separate "basename" when naming and opening a MIR dump file These functions were split up by #77080, in order to support passing the dump file's “basename” (filename without extension) to the implementation of `-Zdump-mir-spanview`, so that it could be used as a page title. That flag has since been removed (#119566), so now there's no particular reason for this code to handle the basename separately from the filename or full path. This PR therefore restores things to (roughly) how they were before #77080.
This commit is contained in:
commit
c526cce281
@ -142,15 +142,17 @@ fn dump_matched_mir_node<'tcx, F>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the file basename portion (without extension) of a filename path
|
/// Returns the path to the filename where we should dump a given MIR.
|
||||||
/// where we should dump a MIR representation output files.
|
/// Also used by other bits of code (e.g., NLL inference) that dump
|
||||||
fn dump_file_basename<'tcx>(
|
/// graphviz data or other things.
|
||||||
|
fn dump_path<'tcx>(
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
|
extension: &str,
|
||||||
pass_num: bool,
|
pass_num: bool,
|
||||||
pass_name: &str,
|
pass_name: &str,
|
||||||
disambiguator: &dyn Display,
|
disambiguator: &dyn Display,
|
||||||
body: &Body<'tcx>,
|
body: &Body<'tcx>,
|
||||||
) -> String {
|
) -> PathBuf {
|
||||||
let source = body.source;
|
let source = body.source;
|
||||||
let promotion_id = match source.promoted {
|
let promotion_id = match source.promoted {
|
||||||
Some(id) => format!("-{id:?}"),
|
Some(id) => format!("-{id:?}"),
|
||||||
@ -186,45 +188,18 @@ fn dump_file_basename<'tcx>(
|
|||||||
_ => String::new(),
|
_ => 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();
|
let mut file_path = PathBuf::new();
|
||||||
file_path.push(Path::new(&tcx.sess.opts.unstable_opts.dump_mir_dir));
|
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);
|
file_path.push(&file_name);
|
||||||
|
|
||||||
file_path
|
file_path
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Attempts to open the MIR dump file with the given name and extension.
|
|
||||||
fn create_dump_file_with_basename(
|
|
||||||
tcx: TyCtxt<'_>,
|
|
||||||
file_basename: &str,
|
|
||||||
extension: &str,
|
|
||||||
) -> io::Result<io::BufWriter<fs::File>> {
|
|
||||||
let file_path = dump_path(tcx, file_basename, extension);
|
|
||||||
if let Some(parent) = file_path.parent() {
|
|
||||||
fs::create_dir_all(parent).map_err(|e| {
|
|
||||||
io::Error::new(
|
|
||||||
e.kind(),
|
|
||||||
format!("IO error creating MIR dump directory: {parent:?}; {e}"),
|
|
||||||
)
|
|
||||||
})?;
|
|
||||||
}
|
|
||||||
Ok(io::BufWriter::new(fs::File::create(&file_path).map_err(|e| {
|
|
||||||
io::Error::new(e.kind(), format!("IO error creating MIR dump file: {file_path:?}; {e}"))
|
|
||||||
})?))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Attempts to open a file where we should dump a given MIR or other
|
/// Attempts to open a file where we should dump a given MIR or other
|
||||||
/// bit of MIR-related data. Used by `mir-dump`, but also by other
|
/// bit of MIR-related data. Used by `mir-dump`, but also by other
|
||||||
/// bits of code (e.g., NLL inference) that dump graphviz data or
|
/// bits of code (e.g., NLL inference) that dump graphviz data or
|
||||||
@ -237,11 +212,18 @@ pub fn create_dump_file<'tcx>(
|
|||||||
disambiguator: &dyn Display,
|
disambiguator: &dyn Display,
|
||||||
body: &Body<'tcx>,
|
body: &Body<'tcx>,
|
||||||
) -> io::Result<io::BufWriter<fs::File>> {
|
) -> io::Result<io::BufWriter<fs::File>> {
|
||||||
create_dump_file_with_basename(
|
let file_path = dump_path(tcx, extension, pass_num, pass_name, disambiguator, body);
|
||||||
tcx,
|
if let Some(parent) = file_path.parent() {
|
||||||
&dump_file_basename(tcx, pass_num, pass_name, disambiguator, body),
|
fs::create_dir_all(parent).map_err(|e| {
|
||||||
extension,
|
io::Error::new(
|
||||||
)
|
e.kind(),
|
||||||
|
format!("IO error creating MIR dump directory: {parent:?}; {e}"),
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
}
|
||||||
|
Ok(io::BufWriter::new(fs::File::create(&file_path).map_err(|e| {
|
||||||
|
io::Error::new(e.kind(), format!("IO error creating MIR dump file: {file_path:?}; {e}"))
|
||||||
|
})?))
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
Loading…
x
Reference in New Issue
Block a user