Skip to content

Commit

Permalink
Rollup merge of #78144 - bugadani:elements-nodrop, r=oli-obk
Browse files Browse the repository at this point in the history
Don't update `entries` in `TypedArena` if T does not need drop

As far as I can tell, `entries` is only used when dropping `TypedArenaChunk`s and their contents. It is already ignored there, if T is not `mem::needs_drop`, this PR just skips updating it's value.

You can see `TypedArenaChunk` ignoring the entry count in L71. The reasoning is similar to what you can find in `DroplessArena`.

r? @oli-obk
  • Loading branch information
GuillaumeGomez committed Oct 20, 2020
2 parents a8a424f + 2705cae commit ad218f9
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions compiler/rustc_arena/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,12 @@ impl<T> TypedArena<T> {
let mut chunks = self.chunks.borrow_mut();
let mut new_cap;
if let Some(last_chunk) = chunks.last_mut() {
let used_bytes = self.ptr.get() as usize - last_chunk.start() as usize;
last_chunk.entries = used_bytes / mem::size_of::<T>();
// If a type is `!needs_drop`, we don't need to keep track of how many elements
// the chunk stores - the field will be ignored anyway.
if mem::needs_drop::<T>() {
let used_bytes = self.ptr.get() as usize - last_chunk.start() as usize;
last_chunk.entries = used_bytes / mem::size_of::<T>();
}

// If the previous chunk's len is less than HUGE_PAGE
// bytes, then this chunk will be least double the previous
Expand Down

0 comments on commit ad218f9

Please sign in to comment.