From 62703cfd26592be8ea641912aa61ecf5d1cbe64f Mon Sep 17 00:00:00 2001 From: varkor Date: Fri, 19 Jan 2018 11:51:48 +0000 Subject: [PATCH] Estimate size of InstanceDef::DropGlue more accurately Also a little bit of clean up. --- src/librustc/mir/mono.rs | 6 +++--- src/librustc/ty/mod.rs | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/librustc/mir/mono.rs b/src/librustc/mir/mono.rs index 2af2219d2678..49e5c0dc21f9 100644 --- a/src/librustc/mir/mono.rs +++ b/src/librustc/mir/mono.rs @@ -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) { @@ -176,7 +175,8 @@ impl<'tcx> HashStable> 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); diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 1d64e7bae913..332afe36010b 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -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 } }