diff --git a/src/librustc/session/code_stats.rs b/src/librustc/session/code_stats.rs index 0f535249b5e2a..5baf0c5948f28 100644 --- a/src/librustc/session/code_stats.rs +++ b/src/librustc/session/code_stats.rs @@ -1,6 +1,7 @@ use rustc_target::abi::{Align, Size}; use rustc_data_structures::fx::{FxHashSet}; use std::cmp::{self, Ordering}; +use rustc_data_structures::sync::Lock; #[derive(Clone, PartialEq, Eq, Hash, Debug)] pub struct VariantInfo { @@ -44,13 +45,13 @@ pub struct TypeSizeInfo { pub variants: Vec, } -#[derive(PartialEq, Eq, Debug, Default)] +#[derive(Default)] pub struct CodeStats { - type_sizes: FxHashSet, + type_sizes: Lock>, } impl CodeStats { - pub fn record_type_size(&mut self, + pub fn record_type_size(&self, kind: DataTypeKind, type_desc: S, align: Align, @@ -73,11 +74,12 @@ impl CodeStats { opt_discr_size: opt_discr_size.map(|s| s.bytes()), variants, }; - self.type_sizes.insert(info); + self.type_sizes.borrow_mut().insert(info); } pub fn print_type_sizes(&self) { - let mut sorted: Vec<_> = self.type_sizes.iter().collect(); + let type_sizes = self.type_sizes.borrow(); + let mut sorted: Vec<_> = type_sizes.iter().collect(); // Primary sort: large-to-small. // Secondary sort: description (dictionary order) diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index bab7ab89ce751..920438da0d638 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -124,7 +124,7 @@ pub struct Session { pub perf_stats: PerfStats, /// Data about code being compiled, gathered during compilation. - pub code_stats: Lock, + pub code_stats: CodeStats, /// If `-zfuel=crate=n` is specified, `Some(crate)`. optimization_fuel_crate: Option, diff --git a/src/librustc/ty/layout.rs b/src/librustc/ty/layout.rs index 4bf500555f14b..56fa2d6e89dca 100644 --- a/src/librustc/ty/layout.rs +++ b/src/librustc/ty/layout.rs @@ -1614,13 +1614,13 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { // (delay format until we actually need it) let record = |kind, packed, opt_discr_size, variants| { let type_desc = format!("{:?}", layout.ty); - self.tcx.sess.code_stats.borrow_mut().record_type_size(kind, - type_desc, - layout.align.abi, - layout.size, - packed, - opt_discr_size, - variants); + self.tcx.sess.code_stats.record_type_size(kind, + type_desc, + layout.align.abi, + layout.size, + packed, + opt_discr_size, + variants); }; let adt_def = match layout.ty.kind { diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 7973a804f1a46..294019496e1c5 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -394,7 +394,7 @@ pub fn run_compiler( mem::drop(compiler.global_ctxt()?.take()); if sess.opts.debugging_opts.print_type_sizes { - sess.code_stats.borrow().print_type_sizes(); + sess.code_stats.print_type_sizes(); } compiler.link()?;