From 98cda6cb07f09a910c493d6c16d8cb47234bf39a Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Tue, 7 Feb 2017 20:28:54 +0100 Subject: [PATCH] freeze -> static --- src/error.rs | 4 ++-- src/eval_context.rs | 10 ++++------ src/memory.rs | 6 +++--- tests/compile-fail/modifying_constants.rs | 2 +- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/error.rs b/src/error.rs index 30bd5beba2..f806110190 100644 --- a/src/error.rs +++ b/src/error.rs @@ -119,9 +119,9 @@ impl<'tcx> Error for EvalError<'tcx> { EvalError::TypeNotPrimitive(_) => "expected primitive type, got nonprimitive", EvalError::ReallocatedStaticMemory => - "tried to reallocate frozen memory", + "tried to reallocate static memory", EvalError::DeallocatedStaticMemory => - "tried to deallocate frozen memory", + "tried to deallocate static memory", EvalError::Layout(_) => "rustc layout computation failed", EvalError::UnterminatedCString(_) => diff --git a/src/eval_context.rs b/src/eval_context.rs index ac6fffd1e0..1996bbf9dc 100644 --- a/src/eval_context.rs +++ b/src/eval_context.rs @@ -314,7 +314,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { match frame.return_to_block { StackPopCleanup::MarkStatic(mutable) => if let Lvalue::Global(id) = frame.return_lvalue { let global_value = self.globals.get_mut(&id) - .expect("global should have been cached (freeze/static)"); + .expect("global should have been cached (static)"); match global_value.value { Value::ByRef(ptr) => self.memory.mark_static(ptr.alloc_id, mutable)?, Value::ByVal(val) => if let PrimVal::Ptr(ptr) = val { @@ -332,7 +332,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { assert!(global_value.mutable); global_value.mutable = mutable; } else { - bug!("StackPopCleanup::Freeze on: {:?}", frame.return_lvalue); + bug!("StackPopCleanup::MarkStatic on: {:?}", frame.return_lvalue); }, StackPopCleanup::Goto(target) => self.goto_block(target), StackPopCleanup::None => {}, @@ -343,10 +343,8 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { trace!("deallocating local"); self.memory.dump_alloc(ptr.alloc_id); match self.memory.deallocate(ptr) { - // Any frozen memory means that it belongs to a constant or something referenced - // by a constant. We could alternatively check whether the alloc_id is frozen - // before calling deallocate, but this is much simpler and is probably the - // rare case. + // We could alternatively check whether the alloc_id is static before calling + // deallocate, but this is much simpler and is probably the rare case. Ok(()) | Err(EvalError::DeallocatedStaticMemory) => {}, other => return other, } diff --git a/src/memory.rs b/src/memory.rs index 8c22232153..0b5f90f3fc 100644 --- a/src/memory.rs +++ b/src/memory.rs @@ -39,7 +39,7 @@ pub struct Allocation { pub align: u64, /// Whether the allocation may be modified. /// Use the `mark_static` method of `Memory` to ensure that an error occurs, if the memory of this - /// allocation is modified in the future. + /// allocation is modified or deallocated in the future. pub static_kind: StaticKind, } @@ -626,7 +626,7 @@ impl<'a, 'tcx> Memory<'a, 'tcx> { impl<'a, 'tcx> Memory<'a, 'tcx> { /// mark an allocation as static, either mutable or not pub fn mark_static(&mut self, alloc_id: AllocId, mutable: bool) -> EvalResult<'tcx> { - // do not use `self.get_mut(alloc_id)` here, because we might have already frozen a + // do not use `self.get_mut(alloc_id)` here, because we might have already marked a // sub-element or have circular pointers (e.g. `Rc`-cycles) let relocations = match self.alloc_map.get_mut(&alloc_id) { Some(&mut Allocation { ref mut relocations, static_kind: ref mut kind @ StaticKind::NotStatic, .. }) => { @@ -636,7 +636,7 @@ impl<'a, 'tcx> Memory<'a, 'tcx> { StaticKind::Immutable }; // take out the relocations vector to free the borrow on self, so we can call - // freeze recursively + // mark recursively mem::replace(relocations, Default::default()) }, None if alloc_id == NEVER_ALLOC_ID || alloc_id == ZST_ALLOC_ID => return Ok(()), diff --git a/tests/compile-fail/modifying_constants.rs b/tests/compile-fail/modifying_constants.rs index 5a8fd189aa..cb2e7217d5 100644 --- a/tests/compile-fail/modifying_constants.rs +++ b/tests/compile-fail/modifying_constants.rs @@ -1,5 +1,5 @@ fn main() { - let x = &1; // the `&1` is promoted to a constant, but it used to be that only the pointer is frozen, not the pointee + let x = &1; // the `&1` is promoted to a constant, but it used to be that only the pointer is marked static, not the pointee let y = unsafe { &mut *(x as *const i32 as *mut i32) }; *y = 42; //~ ERROR tried to modify constant memory assert_eq!(*x, 42);