Skip to content

Commit 62703cf

Browse files
committed
Estimate size of InstanceDef::DropGlue more accurately
Also a little bit of clean up.
1 parent 5c9a8b5 commit 62703cf

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/librustc/mir/mono.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,7 @@ impl<'tcx> CodegenUnit<'tcx> {
157157

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

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

182182
name.hash_stable(hcx, hasher);

src/librustc/ty/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -2673,11 +2673,12 @@ fn instance_def_size_estimate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
26732673
instance_def: InstanceDef<'tcx>)
26742674
-> usize {
26752675
match instance_def {
2676-
InstanceDef::Item(def_id) => {
2677-
let mir = tcx.optimized_mir(def_id);
2676+
InstanceDef::Item(..) |
2677+
InstanceDef::DropGlue(..) => {
2678+
let mir = tcx.instance_mir(instance_def);
26782679
mir.basic_blocks().iter().map(|bb| bb.statements.len()).sum()
26792680
},
2680-
// Estimate the size of compiler-generated shims to be 1.
2681+
// Estimate the size of other compiler-generated shims to be 1.
26812682
_ => 1
26822683
}
26832684
}

0 commit comments

Comments
 (0)