From fc82914207747b076e941e9d4065a546d045ddda Mon Sep 17 00:00:00 2001 From: Aman Arora Date: Sun, 11 Jul 2021 13:54:34 -0400 Subject: [PATCH 1/2] Crater: closure size profile build --- compiler/rustc_mir/src/monomorphize/util.rs | 26 ++++++--------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/compiler/rustc_mir/src/monomorphize/util.rs b/compiler/rustc_mir/src/monomorphize/util.rs index 799b4e18c240f..3e1321046ad3a 100644 --- a/compiler/rustc_mir/src/monomorphize/util.rs +++ b/compiler/rustc_mir/src/monomorphize/util.rs @@ -1,6 +1,5 @@ +use rustc_hir::def_id::LOCAL_CRATE; use rustc_middle::ty::{self, ClosureSizeProfileData, Instance, TyCtxt}; -use std::fs::OpenOptions; -use std::io::prelude::*; /// For a given closure, writes out the data for the profiling the impact of RFC 2229 on /// closure size into a CSV. @@ -8,20 +7,11 @@ use std::io::prelude::*; /// During the same compile all closures dump the information in the same file /// "closure_profile_XXXXX.csv", which is created in the directory where the compiler is invoked. crate fn dump_closure_profile(tcx: TyCtxt<'tcx>, closure_instance: Instance<'tcx>) { - let mut file = if let Ok(file) = OpenOptions::new() - .create(true) - .append(true) - .open(&format!("closure_profile_{}.csv", std::process::id())) - { - file - } else { - eprintln!("Cound't open file for writing closure profile"); - return; - }; - let closure_def_id = closure_instance.def_id(); let typeck_results = tcx.typeck(closure_def_id.expect_local()); + let crate_name = tcx.crate_name(LOCAL_CRATE); + if typeck_results.closure_size_eval.contains_key(&closure_def_id) { let param_env = ty::ParamEnv::reveal_all(); @@ -59,15 +49,13 @@ crate fn dump_closure_profile(tcx: TyCtxt<'tcx>, closure_instance: Instance<'tcx .map(|l| format!("{:?} {:?}", l.lines.first(), l.lines.last())) .unwrap_or_else(|e| format!("{:?}", e)); - if let Err(e) = writeln!( - file, - "{}, {}, {}, {:?}", + eprintln!( + "SG_CRATER_E239478slkdjf: {}, {}, {}, {}, {:?}", + crate_name, old_size, new_size, src_file.prefer_local(), line_nos - ) { - eprintln!("Error writting to file {}", e.to_string()) - } + ); } } From e6793beed8566ef87d733a1fb5f90d65bdf8a4bd Mon Sep 17 00:00:00 2001 From: Aman Arora Date: Mon, 19 Jul 2021 13:12:43 -0400 Subject: [PATCH 2/2] Print hash of instance instead of span --- compiler/rustc_mir/src/monomorphize/util.rs | 24 ++++++--------------- 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/compiler/rustc_mir/src/monomorphize/util.rs b/compiler/rustc_mir/src/monomorphize/util.rs index 3e1321046ad3a..3e5c7ef233d84 100644 --- a/compiler/rustc_mir/src/monomorphize/util.rs +++ b/compiler/rustc_mir/src/monomorphize/util.rs @@ -1,3 +1,4 @@ +use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_hir::def_id::LOCAL_CRATE; use rustc_middle::ty::{self, ClosureSizeProfileData, Instance, TyCtxt}; @@ -39,23 +40,10 @@ crate fn dump_closure_profile(tcx: TyCtxt<'tcx>, closure_instance: Instance<'tcx .map(|l| format!("{:?}", l.size.bytes())) .unwrap_or_else(|e| format!("Failed {:?}", e)); - let closure_hir_id = tcx.hir().local_def_id_to_hir_id(closure_def_id.expect_local()); - let closure_span = tcx.hir().span(closure_hir_id); - let src_file = tcx.sess.source_map().span_to_filename(closure_span); - let line_nos = tcx - .sess - .source_map() - .span_to_lines(closure_span) - .map(|l| format!("{:?} {:?}", l.lines.first(), l.lines.last())) - .unwrap_or_else(|e| format!("{:?}", e)); - - eprintln!( - "SG_CRATER_E239478slkdjf: {}, {}, {}, {}, {:?}", - crate_name, - old_size, - new_size, - src_file.prefer_local(), - line_nos - ); + let mut hasher = StableHasher::new(); + closure_instance.hash_stable(&mut tcx.create_stable_hashing_context(), &mut hasher); + let hash = hasher.finalize(); + + eprintln!("SG_CR_Eslkdjf: {}, {:x?}, {}, {}", crate_name, hash, old_size, new_size); } }