Skip to content

Commit

Permalink
Fix test_allocated_summary
Browse files Browse the repository at this point in the history
Summary:
Also explain why `Arena::allocated_bytes` returns incorrect result.

Test broke when `bumpalo` updated on crates.

Reviewed By: bobyangyf

Differential Revision: D38816393

fbshipit-source-id: 57119e122e7c8bf06dc724d8dcc63c22d267fc3c
  • Loading branch information
stepancheg authored and facebook-github-bot committed Aug 18, 2022
1 parent 8926457 commit b918a99
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion starlark/src/values/layout/heap/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,11 @@ impl<'c> Iterator for ChunkIter<'c> {
}

impl Arena {
/// Number of allocated bytes plus padding size.
pub fn allocated_bytes(&self) -> usize {
// This overestimates the allocates size, see `Bump::allocated_bytes()`:
// "those padding bytes will add to this method’s resulting sum".
// https://docs.rs/bumpalo/3.11.0/bumpalo/struct.Bump.html#method.allocated_bytes
self.drop.allocated_bytes() + self.non_drop.allocated_bytes()
}

Expand Down Expand Up @@ -510,6 +514,7 @@ mod tests {
assert_eq!(res.len(), 1);
let entry = res.values().next().unwrap();
assert_eq!(entry.count, 2);
assert_eq!(entry.bytes, arena.allocated_bytes());
// Because `arena.allocated_bytes` over-approximates.
assert!(entry.bytes <= arena.allocated_bytes());
}
}

0 comments on commit b918a99

Please sign in to comment.