Skip to content

Commit c526cce

Browse files
authored
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.
2 parents b185606 + 1ec567b commit c526cce

File tree

1 file changed

+20
-38
lines changed

1 file changed

+20
-38
lines changed

compiler/rustc_middle/src/mir/pretty.rs

+20-38
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,17 @@ fn dump_matched_mir_node<'tcx, F>(
142142
}
143143
}
144144

145-
/// Returns the file basename portion (without extension) of a filename path
146-
/// where we should dump a MIR representation output files.
147-
fn dump_file_basename<'tcx>(
145+
/// Returns the path to the filename where we should dump a given MIR.
146+
/// Also used by other bits of code (e.g., NLL inference) that dump
147+
/// graphviz data or other things.
148+
fn dump_path<'tcx>(
148149
tcx: TyCtxt<'tcx>,
150+
extension: &str,
149151
pass_num: bool,
150152
pass_name: &str,
151153
disambiguator: &dyn Display,
152154
body: &Body<'tcx>,
153-
) -> String {
155+
) -> PathBuf {
154156
let source = body.source;
155157
let promotion_id = match source.promoted {
156158
Some(id) => format!("-{id:?}"),
@@ -186,32 +188,31 @@ fn dump_file_basename<'tcx>(
186188
_ => String::new(),
187189
};
188190

189-
format!(
190-
"{crate_name}.{item_name}{shim_disambiguator}{promotion_id}{pass_num}.{pass_name}.{disambiguator}",
191-
)
192-
}
193-
194-
/// Returns the path to the filename where we should dump a given MIR.
195-
/// Also used by other bits of code (e.g., NLL inference) that dump
196-
/// graphviz data or other things.
197-
fn dump_path(tcx: TyCtxt<'_>, basename: &str, extension: &str) -> PathBuf {
198191
let mut file_path = PathBuf::new();
199192
file_path.push(Path::new(&tcx.sess.opts.unstable_opts.dump_mir_dir));
200193

201-
let file_name = format!("{basename}.{extension}",);
194+
let file_name = format!(
195+
"{crate_name}.{item_name}{shim_disambiguator}{promotion_id}{pass_num}.{pass_name}.{disambiguator}.{extension}",
196+
);
202197

203198
file_path.push(&file_name);
204199

205200
file_path
206201
}
207202

208-
/// Attempts to open the MIR dump file with the given name and extension.
209-
fn create_dump_file_with_basename(
210-
tcx: TyCtxt<'_>,
211-
file_basename: &str,
203+
/// Attempts to open a file where we should dump a given MIR or other
204+
/// bit of MIR-related data. Used by `mir-dump`, but also by other
205+
/// bits of code (e.g., NLL inference) that dump graphviz data or
206+
/// other things, and hence takes the extension as an argument.
207+
pub fn create_dump_file<'tcx>(
208+
tcx: TyCtxt<'tcx>,
212209
extension: &str,
210+
pass_num: bool,
211+
pass_name: &str,
212+
disambiguator: &dyn Display,
213+
body: &Body<'tcx>,
213214
) -> io::Result<io::BufWriter<fs::File>> {
214-
let file_path = dump_path(tcx, file_basename, extension);
215+
let file_path = dump_path(tcx, extension, pass_num, pass_name, disambiguator, body);
215216
if let Some(parent) = file_path.parent() {
216217
fs::create_dir_all(parent).map_err(|e| {
217218
io::Error::new(
@@ -225,25 +226,6 @@ fn create_dump_file_with_basename(
225226
})?))
226227
}
227228

228-
/// Attempts to open a file where we should dump a given MIR or other
229-
/// bit of MIR-related data. Used by `mir-dump`, but also by other
230-
/// bits of code (e.g., NLL inference) that dump graphviz data or
231-
/// other things, and hence takes the extension as an argument.
232-
pub fn create_dump_file<'tcx>(
233-
tcx: TyCtxt<'tcx>,
234-
extension: &str,
235-
pass_num: bool,
236-
pass_name: &str,
237-
disambiguator: &dyn Display,
238-
body: &Body<'tcx>,
239-
) -> io::Result<io::BufWriter<fs::File>> {
240-
create_dump_file_with_basename(
241-
tcx,
242-
&dump_file_basename(tcx, pass_num, pass_name, disambiguator, body),
243-
extension,
244-
)
245-
}
246-
247229
///////////////////////////////////////////////////////////////////////////
248230
// Whole MIR bodies
249231

0 commit comments

Comments
 (0)