diff --git a/src/base.rs b/src/base.rs index 441d875ef21d4..243852f1d2bef 100644 --- a/src/base.rs +++ b/src/base.rs @@ -74,20 +74,22 @@ pub fn trans_fn<'clif, 'tcx, B: Backend + 'static>( context.func = func; cx.module.define_function(func_id, context).unwrap(); - let value_ranges = context - .build_value_labels_ranges(cx.module.isa()) - .expect("value location ranges"); - // Write optimized function to file for debugging #[cfg(debug_assertions)] - crate::pretty_clif::write_clif_file( - cx.tcx, - "opt", - instance, - &context.func, - &clif_comments, - Some(&value_ranges), - ); + { + let value_ranges = context + .build_value_labels_ranges(cx.module.isa()) + .expect("value location ranges"); + + crate::pretty_clif::write_clif_file( + cx.tcx, + "opt", + instance, + &context.func, + &clif_comments, + Some(&value_ranges), + ); + } // Define debuginfo for function let isa = cx.module.isa(); diff --git a/src/pretty_clif.rs b/src/pretty_clif.rs index f595d384f4f2c..64359f3899f53 100644 --- a/src/pretty_clif.rs +++ b/src/pretty_clif.rs @@ -74,8 +74,8 @@ pub struct CommentWriter { impl CommentWriter { pub fn new<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> Self { - CommentWriter { - global_comments: vec![ + let mut global_comments = if cfg!(debug_assertions) { + vec![ format!("symbol {}", tcx.symbol_name(instance).name.as_str()), format!("instance {:?}", instance), format!( @@ -86,7 +86,13 @@ impl CommentWriter { ) ), String::new(), - ], + ] + } else { + vec![] + }; + + CommentWriter { + global_comments, entity_comments: HashMap::new(), inst_comments: HashMap::new(), }