Skip to content

Commit b918a99

Browse files
stepanchegfacebook-github-bot
authored andcommitted
Fix test_allocated_summary
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
1 parent 8926457 commit b918a99

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

starlark/src/values/layout/heap/arena.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,11 @@ impl<'c> Iterator for ChunkIter<'c> {
140140
}
141141

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

@@ -510,6 +514,7 @@ mod tests {
510514
assert_eq!(res.len(), 1);
511515
let entry = res.values().next().unwrap();
512516
assert_eq!(entry.count, 2);
513-
assert_eq!(entry.bytes, arena.allocated_bytes());
517+
// Because `arena.allocated_bytes` over-approximates.
518+
assert!(entry.bytes <= arena.allocated_bytes());
514519
}
515520
}

0 commit comments

Comments
 (0)