Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move lock into CodeStats #66276

Merged
merged 1 commit into from
Nov 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/librustc/session/code_stats.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -44,13 +45,13 @@ pub struct TypeSizeInfo {
pub variants: Vec<VariantInfo>,
}

#[derive(PartialEq, Eq, Debug, Default)]
#[derive(Default)]
pub struct CodeStats {
type_sizes: FxHashSet<TypeSizeInfo>,
type_sizes: Lock<FxHashSet<TypeSizeInfo>>,
}

impl CodeStats {
pub fn record_type_size<S: ToString>(&mut self,
pub fn record_type_size<S: ToString>(&self,
kind: DataTypeKind,
type_desc: S,
align: Align,
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ pub struct Session {
pub perf_stats: PerfStats,

/// Data about code being compiled, gathered during compilation.
pub code_stats: Lock<CodeStats>,
pub code_stats: CodeStats,

/// If `-zfuel=crate=n` is specified, `Some(crate)`.
optimization_fuel_crate: Option<String>,
Expand Down
14 changes: 7 additions & 7 deletions src/librustc/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?;
Expand Down