]> git.lizzy.rs Git - rust.git/commitdiff
Make allocation relocation field private
authorAndreas Molzer <andreas.molzer@gmx.de>
Thu, 29 Aug 2019 16:02:51 +0000 (18:02 +0200)
committerAndreas Molzer <andreas.molzer@gmx.de>
Thu, 29 Aug 2019 18:02:21 +0000 (20:02 +0200)
src/librustc/mir/interpret/allocation.rs
src/librustc_mir/interpret/intern.rs
src/librustc_mir/interpret/memory.rs
src/librustc_mir/monomorphize/collector.rs
src/librustc_typeck/check/mod.rs

index dcfa2e5cb469142c389dffa4bfaaa8513ed3751f..75319a6783167d3e3e44ef4fc7d2978841450bc6 100644 (file)
@@ -35,7 +35,7 @@ pub struct Allocation<Tag=(),Extra=()> {
     /// Only the first byte of a pointer is inserted into the map; i.e.,
     /// every entry in this map applies to `pointer_size` consecutive bytes starting
     /// at the given offset.
-    pub relocations: Relocations<Tag>,
+    relocations: Relocations<Tag>,
     /// Denotes which part of this allocation is initialized.
     undef_mask: UndefMask,
     /// The size of the allocation. Currently, must always equal `bytes.len()`.
@@ -148,6 +148,11 @@ pub fn inspect_with_undef_and_ptr_outside_interpreter(&self, range: Range<usize>
     pub fn undef_mask(&self) -> &UndefMask {
         &self.undef_mask
     }
+
+    /// Returns the relocation list.
+    pub fn relocations(&self) -> &Relocations<Tag> {
+        &self.relocations
+    }
 }
 
 impl<'tcx> rustc_serialize::UseSpecializedDecodable for &'tcx Allocation {}
@@ -459,7 +464,7 @@ pub fn write_ptr_sized(
 /// Relocations
 impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> {
     /// Returns all relocations overlapping with the given ptr-offset pair.
-    pub fn relocations(
+    pub fn get_relocations(
         &self,
         cx: &impl HasDataLayout,
         ptr: Pointer<Tag>,
@@ -480,7 +485,7 @@ fn check_relocations(
         ptr: Pointer<Tag>,
         size: Size,
     ) -> InterpResult<'tcx> {
-        if self.relocations(cx, ptr, size).is_empty() {
+        if self.get_relocations(cx, ptr, size).is_empty() {
             Ok(())
         } else {
             throw_unsup!(ReadPointerAsBytes)
@@ -502,7 +507,7 @@ fn clear_relocations(
         // Find the start and end of the given range and its outermost relocations.
         let (first, last) = {
             // Find all relocations overlapping the given range.
-            let relocations = self.relocations(cx, ptr, size);
+            let relocations = self.get_relocations(cx, ptr, size);
             if relocations.is_empty() {
                 return Ok(());
             }
index 32ba70a81c99792cedd200c305dff2d8623e42ec..4cbbc0ffe17cc4262462a27d977307710f0b64a1 100644 (file)
@@ -94,7 +94,7 @@ fn intern_shallow(
         alloc.mutability = mutability;
         // link the alloc id to the actual allocation
         let alloc = tcx.intern_const_alloc(alloc);
-        self.leftover_relocations.extend(alloc.relocations.iter().map(|&(_, ((), reloc))| reloc));
+        self.leftover_relocations.extend(alloc.relocations().iter().map(|&(_, ((), reloc))| reloc));
         tcx.alloc_map.lock().set_alloc_id_memory(ptr.alloc_id, alloc);
         Ok(None)
     }
@@ -316,7 +316,7 @@ pub fn intern_const_alloc_recursive(
             // So we hand-roll the interning logic here again
             let alloc = tcx.intern_const_alloc(alloc);
             tcx.alloc_map.lock().set_alloc_id_memory(alloc_id, alloc);
-            for &(_, ((), reloc)) in alloc.relocations.iter() {
+            for &(_, ((), reloc)) in alloc.relocations().iter() {
                 if leftover_relocations.insert(reloc) {
                     todo.push(reloc);
                 }
index 7f7729ae5e0f49f7be44ae8722d9713f948d3e5a..26b3f0be8c2b82f9effdaae6bf61dc258197a0be 100644 (file)
@@ -647,7 +647,7 @@ fn dump_alloc_helper<Tag, Extra>(
 
         for i in 0..alloc.size.bytes() {
             let i = Size::from_bytes(i);
-            if let Some(&(_, target_id)) = alloc.relocations.get(&i) {
+            if let Some(&(_, target_id)) = alloc.relocations().get(&i) {
                 if allocs_seen.insert(target_id) {
                     allocs_to_print.push_back(target_id);
                 }
@@ -809,7 +809,7 @@ pub fn copy_repeatedly(
         // (`get_bytes_with_undef_and_ptr` below checks that there are no
         // relocations overlapping the edges; those would not be handled correctly).
         let relocations = {
-            let relocations = self.get(src.alloc_id)?.relocations(self, src, size);
+            let relocations = self.get(src.alloc_id)?.get_relocations(self, src, size);
             if relocations.is_empty() {
                 // nothing to copy, ignore even the `length` loop
                 Vec::new()
index 12d763bb7910af96d5f694a604aeb314274eb3f5..a9403502f64d3c32e8c643e160bfacf8b61b70ef 100644 (file)
@@ -1202,7 +1202,7 @@ fn collect_miri<'tcx>(tcx: TyCtxt<'tcx>, alloc_id: AllocId, output: &mut Vec<Mon
         }
         Some(GlobalAlloc::Memory(alloc)) => {
             trace!("collecting {:?} with {:#?}", alloc_id, alloc);
-            for &((), inner) in alloc.relocations.values() {
+            for &((), inner) in alloc.relocations().values() {
                 collect_miri(tcx, inner, output);
             }
         },
@@ -1268,7 +1268,7 @@ fn collect_const<'tcx>(
             collect_miri(tcx, ptr.alloc_id, output),
         ConstValue::Slice { data: alloc, start: _, end: _ } |
         ConstValue::ByRef { alloc, .. } => {
-            for &((), id) in alloc.relocations.values() {
+            for &((), id) in alloc.relocations().values() {
                 collect_miri(tcx, id, output);
             }
         }
index 14fc0d6347e4bd8bfbf907ff820c9c8029da870a..e68104c6df8082c06612828ef5dcb98254e42e4c 100644 (file)
@@ -1570,7 +1570,7 @@ fn maybe_check_static_with_link_section(tcx: TyCtxt<'_>, id: DefId, span: Span)
         } else {
             bug!("Matching on non-ByRef static")
         };
-        if alloc.relocations.len() != 0 {
+        if alloc.relocations().len() != 0 {
             let msg = "statics with a custom `#[link_section]` must be a \
                        simple list of bytes on the wasm target with no \
                        extra levels of indirection such as references";