Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 266bab2

Browse files
committed
make get_relocations private
This limits access to the relocations data a bit (instead of increasing it just for the purposes of interning).
1 parent 97a0b2e commit 266bab2

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

compiler/rustc_const_eval/src/interpret/memory.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ impl<'tcx, 'a, Tag: Provenance, Extra> AllocRef<'a, 'tcx, Tag, Extra> {
945945

946946
/// Returns whether the allocation has relocations for the entire range of the `AllocRef`.
947947
pub(crate) fn has_relocations(&self) -> bool {
948-
!self.alloc.get_relocations(&self.tcx, self.range).is_empty()
948+
self.alloc.has_relocations(&self.tcx, self.range)
949949
}
950950
}
951951

compiler/rustc_middle/src/mir/interpret/allocation.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -537,21 +537,26 @@ impl<Tag: Provenance, Extra> Allocation<Tag, Extra> {
537537
/// Relocations.
538538
impl<Tag: Copy, Extra> Allocation<Tag, Extra> {
539539
/// Returns all relocations overlapping with the given pointer-offset pair.
540-
pub fn get_relocations(&self, cx: &impl HasDataLayout, range: AllocRange) -> &[(Size, Tag)] {
540+
fn get_relocations(&self, cx: &impl HasDataLayout, range: AllocRange) -> &[(Size, Tag)] {
541541
// We have to go back `pointer_size - 1` bytes, as that one would still overlap with
542542
// the beginning of this range.
543543
let start = range.start.bytes().saturating_sub(cx.data_layout().pointer_size.bytes() - 1);
544544
self.relocations.range(Size::from_bytes(start)..range.end())
545545
}
546546

547+
/// Returns whether this allocation has relocations overlapping with the given range.
548+
///
549+
/// Note: this function exists to allow `get_relocations` to be private, in order to somewhat
550+
/// limit access to relocations outside of the `Allocation` abstraction.
551+
///
552+
pub fn has_relocations(&self, cx: &impl HasDataLayout, range: AllocRange) -> bool {
553+
!self.get_relocations(cx, range).is_empty()
554+
}
555+
547556
/// Checks that there are no relocations overlapping with the given range.
548557
#[inline(always)]
549558
fn check_relocations(&self, cx: &impl HasDataLayout, range: AllocRange) -> AllocResult {
550-
if self.get_relocations(cx, range).is_empty() {
551-
Ok(())
552-
} else {
553-
Err(AllocError::ReadPointerAsBytes)
554-
}
559+
if self.has_relocations(cx, range) { Err(AllocError::ReadPointerAsBytes) } else { Ok(()) }
555560
}
556561

557562
/// Removes all relocations inside the given range.

0 commit comments

Comments
 (0)