Skip to content

Commit

Permalink
Estimate size of InstanceDef::DropGlue more accurately
Browse files Browse the repository at this point in the history
Also a little bit of clean up.
  • Loading branch information
varkor committed Jan 19, 2018
1 parent 5c9a8b5 commit 62703cf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/librustc/mir/mono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@ impl<'tcx> CodegenUnit<'tcx> {

pub fn size_estimate(&self) -> usize {
// Should only be called if `estimate_size` has previously been called.
assert!(self.size_estimate.is_some());
self.size_estimate.unwrap()
self.size_estimate.expect("estimate_size must be called before getting a size_estimate")
}

pub fn modify_size_estimate(&mut self, delta: usize) {
Expand All @@ -176,7 +175,8 @@ impl<'tcx> HashStable<StableHashingContext<'tcx>> for CodegenUnit<'tcx> {
let CodegenUnit {
ref items,
name,
..
// The size estimate is not relevant to the hash
size_estimate: _,
} = *self;

name.hash_stable(hcx, hasher);
Expand Down
7 changes: 4 additions & 3 deletions src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2673,11 +2673,12 @@ fn instance_def_size_estimate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
instance_def: InstanceDef<'tcx>)
-> usize {
match instance_def {
InstanceDef::Item(def_id) => {
let mir = tcx.optimized_mir(def_id);
InstanceDef::Item(..) |
InstanceDef::DropGlue(..) => {
let mir = tcx.instance_mir(instance_def);
mir.basic_blocks().iter().map(|bb| bb.statements.len()).sum()
},
// Estimate the size of compiler-generated shims to be 1.
// Estimate the size of other compiler-generated shims to be 1.
_ => 1
}
}
Expand Down

0 comments on commit 62703cf

Please sign in to comment.