]> git.lizzy.rs Git - rust.git/commitdiff
Estimate size of InstanceDef::DropGlue more accurately
authorvarkor <github@varkor.com>
Fri, 19 Jan 2018 11:51:48 +0000 (11:51 +0000)
committervarkor <github@varkor.com>
Fri, 19 Jan 2018 11:51:48 +0000 (11:51 +0000)
Also a little bit of clean up.

src/librustc/mir/mono.rs
src/librustc/ty/mod.rs

index 2af2219d26785054bb68393908e14b02b5de621b..49e5c0dc21f9ead7954c506cc9db63a6d32f9ef2 100644 (file)
@@ -157,8 +157,7 @@ pub fn estimate_size<'a>(&mut self, tcx: &TyCtxt<'a, 'tcx, '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 @@ fn hash_stable<W: StableHasherResult>(&self,
         let CodegenUnit {
             ref items,
             name,
-            ..
+            // The size estimate is not relevant to the hash
+            size_estimate: _,
         } = *self;
 
         name.hash_stable(hcx, hasher);
index 1d64e7bae913c21b5528ae0d0b2469bc4a483047..332afe36010bdba11a0c4e040ad7aab128aabc83 100644 (file)
@@ -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
     }
 }