Rollup merge of #95196 - RalfJung:unalloc-not-uninit, r=oli-obk

rename LocalState::Uninitialized to Unallocated

This is to avoid confusion with `Uninit` as in `ScalarMaybeUninit`, which is very different.

r? `@oli-obk`
This commit is contained in:
Dylan DPC 2022-03-22 19:07:34 +01:00 committed by GitHub
commit 0e59ad4ce3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 16 deletions

View file

@ -177,11 +177,10 @@ pub struct LocalState<'tcx, Tag: Provenance = AllocId> {
pub enum LocalValue<Tag: Provenance = AllocId> { pub enum LocalValue<Tag: Provenance = 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,
/// This local is alive but not yet initialized. It can be written to /// This local is alive but not yet allocated. It cannot be read from or have its address taken,
/// but not read from or its address taken. Locals get initialized on /// and will be allocated on the first write. This is to support unsized locals, where we cannot
/// first write because for unsized locals, we do not know their size /// know their size in advance.
/// before that. Unallocated,
Uninitialized,
/// A normal, live local. /// A normal, live local.
/// Mostly for convenience, we re-use the `Operand` type here. /// Mostly for convenience, we re-use the `Operand` type here.
/// This is an optimization over just always having a pointer here; /// This is an optimization over just always having a pointer here;
@ -198,7 +197,7 @@ impl<'tcx, Tag: Provenance + 'static> LocalState<'tcx, Tag> {
pub fn access(&self) -> InterpResult<'tcx, Operand<Tag>> { pub fn access(&self) -> InterpResult<'tcx, Operand<Tag>> {
match self.value { match self.value {
LocalValue::Dead => throw_ub!(DeadLocal), LocalValue::Dead => throw_ub!(DeadLocal),
LocalValue::Uninitialized => { LocalValue::Unallocated => {
bug!("The type checker should prevent reading from a never-written local") bug!("The type checker should prevent reading from a never-written local")
} }
LocalValue::Live(val) => Ok(val), LocalValue::Live(val) => Ok(val),
@ -216,8 +215,7 @@ impl<'tcx, Tag: Provenance + 'static> LocalState<'tcx, Tag> {
match self.value { match self.value {
LocalValue::Dead => throw_ub!(DeadLocal), LocalValue::Dead => throw_ub!(DeadLocal),
LocalValue::Live(Operand::Indirect(mplace)) => Ok(Err(mplace)), LocalValue::Live(Operand::Indirect(mplace)) => Ok(Err(mplace)),
ref mut ref mut local @ (LocalValue::Live(Operand::Immediate(_)) | LocalValue::Unallocated) => {
local @ (LocalValue::Live(Operand::Immediate(_)) | LocalValue::Uninitialized) => {
Ok(Ok(local)) Ok(Ok(local))
} }
} }
@ -752,8 +750,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
})?; })?;
} }
// Locals are initially uninitialized. // Locals are initially unallocated.
let dummy = LocalState { value: LocalValue::Uninitialized, layout: Cell::new(None) }; let dummy = LocalState { value: LocalValue::Unallocated, layout: Cell::new(None) };
let mut locals = IndexVec::from_elem(dummy, &body.local_decls); let mut locals = IndexVec::from_elem(dummy, &body.local_decls);
// Now mark those locals as dead that we do not want to initialize // Now mark those locals as dead that we do not want to initialize
@ -921,7 +919,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
assert!(local != mir::RETURN_PLACE, "Cannot make return place live"); assert!(local != mir::RETURN_PLACE, "Cannot make return place live");
trace!("{:?} is now live", local); trace!("{:?} is now live", local);
let local_val = LocalValue::Uninitialized; let local_val = LocalValue::Unallocated;
// StorageLive expects the local to be dead, and marks it live. // StorageLive expects the local to be dead, and marks it live.
let old = mem::replace(&mut self.frame_mut().locals[local].value, local_val); let old = mem::replace(&mut self.frame_mut().locals[local].value, local_val);
if !matches!(old, LocalValue::Dead) { if !matches!(old, LocalValue::Dead) {
@ -1025,7 +1023,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> std::fmt::Debug
match self.ecx.stack()[frame].locals[local].value { match self.ecx.stack()[frame].locals[local].value {
LocalValue::Dead => write!(fmt, " is dead")?, LocalValue::Dead => write!(fmt, " is dead")?,
LocalValue::Uninitialized => write!(fmt, " is uninitialized")?, LocalValue::Unallocated => write!(fmt, " is unallocated")?,
LocalValue::Live(Operand::Indirect(mplace)) => { LocalValue::Live(Operand::Indirect(mplace)) => {
write!( write!(
fmt, fmt,

View file

@ -244,8 +244,8 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine<'mir, 'tcx>
) -> InterpResult<'tcx, InterpOperand<Self::PointerTag>> { ) -> InterpResult<'tcx, InterpOperand<Self::PointerTag>> {
let l = &frame.locals[local]; let l = &frame.locals[local];
if l.value == LocalValue::Uninitialized { if l.value == LocalValue::Unallocated {
throw_machine_stop_str!("tried to access an uninitialized local") throw_machine_stop_str!("tried to access an unallocated local")
} }
l.access() l.access()
@ -442,7 +442,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
/// but not reading from them anymore. /// but not reading from them anymore.
fn remove_const(ecx: &mut InterpCx<'mir, 'tcx, ConstPropMachine<'mir, 'tcx>>, local: Local) { fn remove_const(ecx: &mut InterpCx<'mir, 'tcx, ConstPropMachine<'mir, 'tcx>>, local: Local) {
ecx.frame_mut().locals[local] = ecx.frame_mut().locals[local] =
LocalState { value: LocalValue::Uninitialized, layout: Cell::new(None) }; LocalState { value: LocalValue::Unallocated, layout: Cell::new(None) };
} }
fn lint_root(&self, source_info: SourceInfo) -> Option<HirId> { fn lint_root(&self, source_info: SourceInfo) -> Option<HirId> {
@ -1147,7 +1147,7 @@ impl<'tcx> MutVisitor<'tcx> for ConstPropagator<'_, 'tcx> {
let frame = self.ecx.frame_mut(); let frame = self.ecx.frame_mut();
frame.locals[local].value = frame.locals[local].value =
if let StatementKind::StorageLive(_) = statement.kind { if let StatementKind::StorageLive(_) = statement.kind {
LocalValue::Uninitialized LocalValue::Unallocated
} else { } else {
LocalValue::Dead LocalValue::Dead
}; };