Rollup merge of #85408 - RalfJung:alloc-size, r=oli-obk
remove size field from Allocation This is a part of https://github.com/rust-lang/rust/pull/85376 that can be easily split out. r? ``@oli-obk``
This commit is contained in:
commit
af1ac55cbf
23 changed files with 62 additions and 63 deletions
|
@ -244,7 +244,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
|
|||
let new_ptr = self.allocate(new_size, new_align, kind);
|
||||
let old_size = match old_size_and_align {
|
||||
Some((size, _align)) => size,
|
||||
None => self.get_raw(ptr.alloc_id)?.size,
|
||||
None => self.get_raw(ptr.alloc_id)?.size(),
|
||||
};
|
||||
self.copy(ptr, new_ptr, old_size.min(new_size), /*nonoverlapping*/ true)?;
|
||||
self.deallocate(ptr, old_size_and_align, kind)?;
|
||||
|
@ -306,11 +306,11 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
|
|||
);
|
||||
}
|
||||
if let Some((size, align)) = old_size_and_align {
|
||||
if size != alloc.size || align != alloc.align {
|
||||
if size != alloc.size() || align != alloc.align {
|
||||
throw_ub_format!(
|
||||
"incorrect layout on deallocation: {} has size {} and alignment {}, but gave size {} and alignment {}",
|
||||
ptr.alloc_id,
|
||||
alloc.size.bytes(),
|
||||
alloc.size().bytes(),
|
||||
alloc.align.bytes(),
|
||||
size.bytes(),
|
||||
align.bytes(),
|
||||
|
@ -319,11 +319,11 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
|
|||
}
|
||||
|
||||
// Let the machine take some extra action
|
||||
let size = alloc.size;
|
||||
let size = alloc.size();
|
||||
AllocationExtra::memory_deallocated(&mut alloc, ptr, size)?;
|
||||
|
||||
// Don't forget to remember size and align of this now-dead allocation
|
||||
let old = self.dead_alloc_map.insert(ptr.alloc_id, (alloc.size, alloc.align));
|
||||
let old = self.dead_alloc_map.insert(ptr.alloc_id, (alloc.size(), alloc.align));
|
||||
if old.is_some() {
|
||||
bug!("Nothing can be deallocated twice");
|
||||
}
|
||||
|
@ -586,7 +586,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
|
|||
// a) cause cycles in case `id` refers to a static
|
||||
// b) duplicate a global's allocation in miri
|
||||
if let Some((_, alloc)) = self.alloc_map.get(id) {
|
||||
return Ok((alloc.size, alloc.align));
|
||||
return Ok((alloc.size(), alloc.align));
|
||||
}
|
||||
|
||||
// # Function pointers
|
||||
|
@ -614,7 +614,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
|
|||
Some(GlobalAlloc::Memory(alloc)) => {
|
||||
// Need to duplicate the logic here, because the global allocations have
|
||||
// different associated types than the interpreter-local ones.
|
||||
Ok((alloc.size, alloc.align))
|
||||
Ok((alloc.size(), alloc.align))
|
||||
}
|
||||
Some(GlobalAlloc::Function(_)) => bug!("We already checked function pointers above"),
|
||||
// The rest must be dead.
|
||||
|
|
|
@ -776,8 +776,8 @@ pub struct RenderAllocation<'a, 'tcx, Tag, Extra> {
|
|||
impl<Tag: Copy + Debug, Extra> std::fmt::Display for RenderAllocation<'a, 'tcx, Tag, Extra> {
|
||||
fn fmt(&self, w: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let RenderAllocation { tcx, alloc } = *self;
|
||||
write!(w, "size: {}, align: {})", alloc.size.bytes(), alloc.align.bytes())?;
|
||||
if alloc.size == Size::ZERO {
|
||||
write!(w, "size: {}, align: {})", alloc.size().bytes(), alloc.align.bytes())?;
|
||||
if alloc.size() == Size::ZERO {
|
||||
// We are done.
|
||||
return write!(w, " {{}}");
|
||||
}
|
||||
|
@ -822,9 +822,9 @@ fn write_allocation_bytes<Tag: Copy + Debug, Extra>(
|
|||
w: &mut dyn std::fmt::Write,
|
||||
prefix: &str,
|
||||
) -> std::fmt::Result {
|
||||
let num_lines = alloc.size.bytes_usize().saturating_sub(BYTES_PER_LINE);
|
||||
let num_lines = alloc.size().bytes_usize().saturating_sub(BYTES_PER_LINE);
|
||||
// Number of chars needed to represent all line numbers.
|
||||
let pos_width = format!("{:x}", alloc.size.bytes()).len();
|
||||
let pos_width = format!("{:x}", alloc.size().bytes()).len();
|
||||
|
||||
if num_lines > 0 {
|
||||
write!(w, "{}0x{:02$x} │ ", prefix, 0, pos_width)?;
|
||||
|
@ -845,7 +845,7 @@ fn write_allocation_bytes<Tag: Copy + Debug, Extra>(
|
|||
}
|
||||
};
|
||||
|
||||
while i < alloc.size {
|
||||
while i < alloc.size() {
|
||||
// The line start already has a space. While we could remove that space from the line start
|
||||
// printing and unconditionally print a space here, that would cause the single-line case
|
||||
// to have a single space before it, which looks weird.
|
||||
|
@ -929,7 +929,7 @@ fn write_allocation_bytes<Tag: Copy + Debug, Extra>(
|
|||
i += Size::from_bytes(1);
|
||||
}
|
||||
// Print a new line header if the next line still has some bytes to print.
|
||||
if i == line_start + Size::from_bytes(BYTES_PER_LINE) && i != alloc.size {
|
||||
if i == line_start + Size::from_bytes(BYTES_PER_LINE) && i != alloc.size() {
|
||||
line_start = write_allocation_newline(w, line_start, &ascii, pos_width, prefix)?;
|
||||
ascii.clear();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue