diff options
| author | Oliver Schneider <git-no-reply-9879165716479413131@oli-obk.de> | 2018-01-26 14:28:58 +0100 |
|---|---|---|
| committer | Oliver Schneider <git-spam-no-reply9815368754983@oli-obk.de> | 2018-03-08 08:34:11 +0100 |
| commit | 8a93972ba9c29bf5c735108a8f7c316aa60fa0da (patch) | |
| tree | f3f69c8a34a36f62a50ce8f54383424480e22f76 | |
| parent | c5d2e178e75517d584808c4fbbac08b8df2287c0 (diff) | |
| download | rust-8a93972ba9c29bf5c735108a8f7c316aa60fa0da.tar.gz rust-8a93972ba9c29bf5c735108a8f7c316aa60fa0da.zip | |
Use Mutability enum instead of bool
| -rw-r--r-- | src/librustc/ich/impls_ty.rs | 7 | ||||
| -rw-r--r-- | src/librustc/mir/interpret/mod.rs | 9 | ||||
| -rw-r--r-- | src/librustc_mir/interpret/memory.rs | 4 | ||||
| -rw-r--r-- | src/librustc_trans/mir/constant.rs | 3 |
4 files changed, 16 insertions, 7 deletions
diff --git a/src/librustc/ich/impls_ty.rs b/src/librustc/ich/impls_ty.rs index 4f691c0d394..2dfb2d0bffc 100644 --- a/src/librustc/ich/impls_ty.rs +++ b/src/librustc/ich/impls_ty.rs @@ -417,10 +417,15 @@ impl<'a> HashStable<StableHashingContext<'a>> for mir::interpret::Allocation { } self.undef_mask.hash_stable(hcx, hasher); self.align.hash_stable(hcx, hasher); - self.mutable.hash_stable(hcx, hasher); + self.runtime_mutability.hash_stable(hcx, hasher); } } +impl_stable_hash_for!(enum ::syntax::ast::Mutability { + Immutable, + Mutable +}); + impl_stable_hash_for!(struct mir::interpret::Pointer{primval}); impl_stable_hash_for!(enum mir::interpret::PrimVal { diff --git a/src/librustc/mir/interpret/mod.rs b/src/librustc/mir/interpret/mod.rs index c395be549a3..b621f3f3731 100644 --- a/src/librustc/mir/interpret/mod.rs +++ b/src/librustc/mir/interpret/mod.rs @@ -19,6 +19,7 @@ use ty; use ty::layout::{self, Align, HasDataLayout}; use middle::region; use std::iter; +use syntax::ast::Mutability; #[derive(Clone, Debug, PartialEq)] pub enum Lock { @@ -169,8 +170,10 @@ pub struct Allocation { pub undef_mask: UndefMask, /// The alignment of the allocation to detect unaligned reads. pub align: Align, - /// Whether the allocation should be put into mutable memory when translating via llvm - pub mutable: bool, + /// Whether the allocation (of a static) should be put into mutable memory when translating + /// + /// Only happens for `static mut` or `static` with interior mutability + pub runtime_mutability: Mutability, } impl Allocation { @@ -182,7 +185,7 @@ impl Allocation { relocations: BTreeMap::new(), undef_mask, align: Align::from_bytes(1, 1).unwrap(), - mutable: false, + runtime_mutability: Mutability::Immutable, } } } diff --git a/src/librustc_mir/interpret/memory.rs b/src/librustc_mir/interpret/memory.rs index a22158c7334..e67c3677911 100644 --- a/src/librustc_mir/interpret/memory.rs +++ b/src/librustc_mir/interpret/memory.rs @@ -105,7 +105,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> { relocations: BTreeMap::new(), undef_mask: UndefMask::new(size), align, - mutable: false, + runtime_mutability: Mutability::Immutable, }; let id = self.tcx.interpret_interner.reserve(); M::add_lock(self, id); @@ -544,7 +544,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> { let uninit = self.uninitialized_statics.remove(&alloc_id); if let Some(mut alloc) = alloc.or(uninit) { // ensure llvm knows not to put this into immutable memroy - alloc.mutable = mutability == Mutability::Mutable; + alloc.runtime_mutability = mutability; let alloc = self.tcx.intern_const_alloc(alloc); self.tcx.interpret_interner.intern_at_reserved(alloc_id, alloc); // recurse into inner allocations diff --git a/src/librustc_trans/mir/constant.rs b/src/librustc_trans/mir/constant.rs index 1b470665cd9..c7a0724c1e7 100644 --- a/src/librustc_trans/mir/constant.rs +++ b/src/librustc_trans/mir/constant.rs @@ -24,6 +24,7 @@ use common::{C_bytes, C_struct, C_uint_big, C_undef, C_usize}; use consts; use type_of::LayoutLlvmExt; use type_::Type; +use syntax::ast::Mutability; use super::super::callee; use super::FunctionCx; @@ -57,7 +58,7 @@ pub fn primval_to_llvm(cx: &CodegenCx, } else if let Some(alloc) = cx.tcx.interpret_interner .get_alloc(ptr.alloc_id) { let init = global_initializer(cx, alloc); - if alloc.mutable { + if alloc.runtime_mutability == Mutability::Mutable { consts::addr_of_mut(cx, init, alloc.align, "byte_str") } else { consts::addr_of(cx, init, alloc.align, "byte_str") |
