Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit b477a54

Browse files
committed
Avoid file name formatting when debug file writing is disabled
1 parent 56bf873 commit b477a54

File tree

2 files changed

+26
-22
lines changed

2 files changed

+26
-22
lines changed

src/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ pub(crate) fn codegen_fn<'tcx>(
147147
if let Some(disasm) = &context.mach_compile_result.as_ref().unwrap().disasm {
148148
crate::pretty_clif::write_ir_file(
149149
tcx,
150-
&format!("{}.vcode", tcx.symbol_name(instance).name),
150+
|| format!("{}.vcode", tcx.symbol_name(instance).name),
151151
|file| file.write_all(disasm.as_bytes()),
152152
)
153153
}

src/pretty_clif.rs

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ pub(crate) fn should_write_ir(tcx: TyCtxt<'_>) -> bool {
207207

208208
pub(crate) fn write_ir_file(
209209
tcx: TyCtxt<'_>,
210-
name: &str,
210+
name: impl FnOnce() -> String,
211211
write: impl FnOnce(&mut dyn Write) -> std::io::Result<()>,
212212
) {
213213
if !should_write_ir(tcx) {
@@ -222,7 +222,7 @@ pub(crate) fn write_ir_file(
222222
res @ Err(_) => res.unwrap(),
223223
}
224224

225-
let clif_file_name = clif_output_dir.join(name);
225+
let clif_file_name = clif_output_dir.join(name());
226226

227227
let res = std::fs::File::create(clif_file_name).and_then(|mut file| write(&mut file));
228228
if let Err(err) = res {
@@ -238,27 +238,31 @@ pub(crate) fn write_clif_file<'tcx>(
238238
context: &cranelift_codegen::Context,
239239
mut clif_comments: &CommentWriter,
240240
) {
241-
write_ir_file(tcx, &format!("{}.{}.clif", tcx.symbol_name(instance).name, postfix), |file| {
242-
let value_ranges =
243-
isa.map(|isa| context.build_value_labels_ranges(isa).expect("value location ranges"));
241+
write_ir_file(
242+
tcx,
243+
|| format!("{}.{}.clif", tcx.symbol_name(instance).name, postfix),
244+
|file| {
245+
let value_ranges = isa
246+
.map(|isa| context.build_value_labels_ranges(isa).expect("value location ranges"));
244247

245-
let mut clif = String::new();
246-
cranelift_codegen::write::decorate_function(
247-
&mut clif_comments,
248-
&mut clif,
249-
&context.func,
250-
&DisplayFunctionAnnotations { isa, value_ranges: value_ranges.as_ref() },
251-
)
252-
.unwrap();
248+
let mut clif = String::new();
249+
cranelift_codegen::write::decorate_function(
250+
&mut clif_comments,
251+
&mut clif,
252+
&context.func,
253+
&DisplayFunctionAnnotations { isa, value_ranges: value_ranges.as_ref() },
254+
)
255+
.unwrap();
253256

254-
writeln!(file, "test compile")?;
255-
writeln!(file, "set is_pic")?;
256-
writeln!(file, "set enable_simd")?;
257-
writeln!(file, "target {} haswell", crate::target_triple(tcx.sess))?;
258-
writeln!(file)?;
259-
file.write_all(clif.as_bytes())?;
260-
Ok(())
261-
});
257+
writeln!(file, "test compile")?;
258+
writeln!(file, "set is_pic")?;
259+
writeln!(file, "set enable_simd")?;
260+
writeln!(file, "target {} haswell", crate::target_triple(tcx.sess))?;
261+
writeln!(file)?;
262+
file.write_all(clif.as_bytes())?;
263+
Ok(())
264+
},
265+
);
262266
}
263267

264268
impl fmt::Debug for FunctionCx<'_, '_, '_> {

0 commit comments

Comments
 (0)