Skip to content

Commit 6fe31fe

Browse files
committed
Make allocation relocation field private
1 parent 85d6b7b commit 6fe31fe

File tree

5 files changed

+16
-11
lines changed

5 files changed

+16
-11
lines changed

src/librustc/mir/interpret/allocation.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub struct Allocation<Tag=(),Extra=()> {
3535
/// Only the first byte of a pointer is inserted into the map; i.e.,
3636
/// every entry in this map applies to `pointer_size` consecutive bytes starting
3737
/// at the given offset.
38-
pub relocations: Relocations<Tag>,
38+
relocations: Relocations<Tag>,
3939
/// Denotes which part of this allocation is initialized.
4040
undef_mask: UndefMask,
4141
/// The size of the allocation. Currently, must always equal `bytes.len()`.
@@ -148,6 +148,11 @@ impl<Tag, Extra> Allocation<Tag, Extra> {
148148
pub fn undef_mask(&self) -> &UndefMask {
149149
&self.undef_mask
150150
}
151+
152+
/// Returns the relocation list.
153+
pub fn relocations(&self) -> &Relocations<Tag> {
154+
&self.relocations
155+
}
151156
}
152157

153158
impl<'tcx> rustc_serialize::UseSpecializedDecodable for &'tcx Allocation {}
@@ -459,7 +464,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
459464
/// Relocations
460465
impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> {
461466
/// Returns all relocations overlapping with the given ptr-offset pair.
462-
pub fn relocations(
467+
pub fn get_relocations(
463468
&self,
464469
cx: &impl HasDataLayout,
465470
ptr: Pointer<Tag>,
@@ -480,7 +485,7 @@ impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> {
480485
ptr: Pointer<Tag>,
481486
size: Size,
482487
) -> InterpResult<'tcx> {
483-
if self.relocations(cx, ptr, size).is_empty() {
488+
if self.get_relocations(cx, ptr, size).is_empty() {
484489
Ok(())
485490
} else {
486491
throw_unsup!(ReadPointerAsBytes)
@@ -502,7 +507,7 @@ impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> {
502507
// Find the start and end of the given range and its outermost relocations.
503508
let (first, last) = {
504509
// Find all relocations overlapping the given range.
505-
let relocations = self.relocations(cx, ptr, size);
510+
let relocations = self.get_relocations(cx, ptr, size);
506511
if relocations.is_empty() {
507512
return Ok(());
508513
}

src/librustc_mir/interpret/intern.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl<'rt, 'mir, 'tcx> InternVisitor<'rt, 'mir, 'tcx> {
9494
alloc.mutability = mutability;
9595
// link the alloc id to the actual allocation
9696
let alloc = tcx.intern_const_alloc(alloc);
97-
self.leftover_relocations.extend(alloc.relocations.iter().map(|&(_, ((), reloc))| reloc));
97+
self.leftover_relocations.extend(alloc.relocations().iter().map(|&(_, ((), reloc))| reloc));
9898
tcx.alloc_map.lock().set_alloc_id_memory(ptr.alloc_id, alloc);
9999
Ok(None)
100100
}
@@ -316,7 +316,7 @@ pub fn intern_const_alloc_recursive(
316316
// So we hand-roll the interning logic here again
317317
let alloc = tcx.intern_const_alloc(alloc);
318318
tcx.alloc_map.lock().set_alloc_id_memory(alloc_id, alloc);
319-
for &(_, ((), reloc)) in alloc.relocations.iter() {
319+
for &(_, ((), reloc)) in alloc.relocations().iter() {
320320
if leftover_relocations.insert(reloc) {
321321
todo.push(reloc);
322322
}

src/librustc_mir/interpret/memory.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
647647

648648
for i in 0..alloc.size.bytes() {
649649
let i = Size::from_bytes(i);
650-
if let Some(&(_, target_id)) = alloc.relocations.get(&i) {
650+
if let Some(&(_, target_id)) = alloc.relocations().get(&i) {
651651
if allocs_seen.insert(target_id) {
652652
allocs_to_print.push_back(target_id);
653653
}
@@ -809,7 +809,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
809809
// (`get_bytes_with_undef_and_ptr` below checks that there are no
810810
// relocations overlapping the edges; those would not be handled correctly).
811811
let relocations = {
812-
let relocations = self.get(src.alloc_id)?.relocations(self, src, size);
812+
let relocations = self.get(src.alloc_id)?.get_relocations(self, src, size);
813813
if relocations.is_empty() {
814814
// nothing to copy, ignore even the `length` loop
815815
Vec::new()

src/librustc_mir/monomorphize/collector.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,7 +1202,7 @@ fn collect_miri<'tcx>(tcx: TyCtxt<'tcx>, alloc_id: AllocId, output: &mut Vec<Mon
12021202
}
12031203
Some(GlobalAlloc::Memory(alloc)) => {
12041204
trace!("collecting {:?} with {:#?}", alloc_id, alloc);
1205-
for &((), inner) in alloc.relocations.values() {
1205+
for &((), inner) in alloc.relocations().values() {
12061206
collect_miri(tcx, inner, output);
12071207
}
12081208
},
@@ -1268,7 +1268,7 @@ fn collect_const<'tcx>(
12681268
collect_miri(tcx, ptr.alloc_id, output),
12691269
ConstValue::Slice { data: alloc, start: _, end: _ } |
12701270
ConstValue::ByRef { alloc, .. } => {
1271-
for &((), id) in alloc.relocations.values() {
1271+
for &((), id) in alloc.relocations().values() {
12721272
collect_miri(tcx, id, output);
12731273
}
12741274
}

src/librustc_typeck/check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1570,7 +1570,7 @@ fn maybe_check_static_with_link_section(tcx: TyCtxt<'_>, id: DefId, span: Span)
15701570
} else {
15711571
bug!("Matching on non-ByRef static")
15721572
};
1573-
if alloc.relocations.len() != 0 {
1573+
if alloc.relocations().len() != 0 {
15741574
let msg = "statics with a custom `#[link_section]` must be a \
15751575
simple list of bytes on the wasm target with no \
15761576
extra levels of indirection such as references";

0 commit comments

Comments
 (0)