Rollup merge of #66276 - Mark-Simulacrum:sess-code-stats, r=nikomatsakis
Move lock into CodeStats Prevent (theoretical) accidental too-long borrows by ensuring only encapsulated locking.
This commit is contained in:
commit
dfd11229b3
4 changed files with 16 additions and 14 deletions
|
@ -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<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,
|
||||
|
@ -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)
|
||||
|
|
|
@ -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>,
|
||||
|
|
|
@ -1614,7 +1614,7 @@ 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,
|
||||
self.tcx.sess.code_stats.record_type_size(kind,
|
||||
type_desc,
|
||||
layout.align.abi,
|
||||
layout.size,
|
||||
|
|
|
@ -393,7 +393,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()?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue