Simplify force_allocation_maybe_sized
This commit is contained in:
parent
b5b5258d74
commit
bb1ecee5b6
2 changed files with 4 additions and 15 deletions
|
@ -118,7 +118,7 @@ pub struct LocalState<'tcx, Tag = (), Id = AllocId> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Current value of a local variable
|
/// Current value of a local variable
|
||||||
#[derive(Clone, PartialEq, Eq, Debug, HashStable)] // Miri debug-prints these
|
#[derive(Copy, Clone, PartialEq, Eq, Debug, HashStable)] // Miri debug-prints these
|
||||||
pub enum LocalValue<Tag = (), Id = AllocId> {
|
pub enum LocalValue<Tag = (), Id = AllocId> {
|
||||||
/// This local is not currently alive, and cannot be used at all.
|
/// This local is not currently alive, and cannot be used at all.
|
||||||
Dead,
|
Dead,
|
||||||
|
|
|
@ -974,31 +974,20 @@ where
|
||||||
let (mplace, size) = match place.place {
|
let (mplace, size) = match place.place {
|
||||||
Place::Local { frame, local } => {
|
Place::Local { frame, local } => {
|
||||||
match self.stack[frame].locals[local].access_mut()? {
|
match self.stack[frame].locals[local].access_mut()? {
|
||||||
Ok(local_val) => {
|
Ok(&mut local_val) => {
|
||||||
// We need to make an allocation.
|
// We need to make an allocation.
|
||||||
// FIXME: Consider not doing anything for a ZST, and just returning
|
|
||||||
// a fake pointer? Are we even called for ZST?
|
|
||||||
|
|
||||||
// We cannot hold on to the reference `local_val` while allocating,
|
|
||||||
// but we can hold on to the value in there.
|
|
||||||
let old_val =
|
|
||||||
if let LocalValue::Live(Operand::Immediate(value)) = *local_val {
|
|
||||||
Some(value)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
|
|
||||||
// We need the layout of the local. We can NOT use the layout we got,
|
// We need the layout of the local. We can NOT use the layout we got,
|
||||||
// that might e.g., be an inner field of a struct with `Scalar` layout,
|
// that might e.g., be an inner field of a struct with `Scalar` layout,
|
||||||
// that has different alignment than the outer field.
|
// that has different alignment than the outer field.
|
||||||
// We also need to support unsized types, and hence cannot use `allocate`.
|
|
||||||
let local_layout = self.layout_of_local(&self.stack[frame], local, None)?;
|
let local_layout = self.layout_of_local(&self.stack[frame], local, None)?;
|
||||||
|
// We also need to support unsized types, and hence cannot use `allocate`.
|
||||||
let (size, align) = self
|
let (size, align) = self
|
||||||
.size_and_align_of(meta, local_layout)?
|
.size_and_align_of(meta, local_layout)?
|
||||||
.expect("Cannot allocate for non-dyn-sized type");
|
.expect("Cannot allocate for non-dyn-sized type");
|
||||||
let ptr = self.memory.allocate(size, align, MemoryKind::Stack);
|
let ptr = self.memory.allocate(size, align, MemoryKind::Stack);
|
||||||
let mplace = MemPlace { ptr: ptr.into(), align, meta };
|
let mplace = MemPlace { ptr: ptr.into(), align, meta };
|
||||||
if let Some(value) = old_val {
|
if let LocalValue::Live(Operand::Immediate(value)) = local_val {
|
||||||
// Preserve old value.
|
// Preserve old value.
|
||||||
// We don't have to validate as we can assume the local
|
// We don't have to validate as we can assume the local
|
||||||
// was already valid for its type.
|
// was already valid for its type.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue