Skip to content

Commit c8baac5

Browse files
committed
remove remaining use of Pointer in Allocation API
1 parent 3a24abd commit c8baac5

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ impl InitMaskCompressed {
512512
/// Transferring the initialization mask to other allocations.
513513
impl<Tag, Extra> Allocation<Tag, Extra> {
514514
/// Creates a run-length encoding of the initialization mask.
515-
pub fn compress_uninit_range(&self, src: Pointer<Tag>, size: Size) -> InitMaskCompressed {
515+
pub fn compress_uninit_range(&self, range: AllocRange) -> InitMaskCompressed {
516516
// Since we are copying `size` bytes from `src` to `dest + i * size` (`for i in 0..repeat`),
517517
// a naive initialization mask copying algorithm would repeatedly have to read the initialization mask from
518518
// the source and write it to the destination. Even if we optimized the memory accesses,
@@ -526,13 +526,13 @@ impl<Tag, Extra> Allocation<Tag, Extra> {
526526
// where each element toggles the state.
527527

528528
let mut ranges = smallvec::SmallVec::<[u64; 1]>::new();
529-
let initial = self.init_mask.get(src.offset);
529+
let initial = self.init_mask.get(range.start);
530530
let mut cur_len = 1;
531531
let mut cur = initial;
532532

533-
for i in 1..size.bytes() {
533+
for i in 1..range.size.bytes() {
534534
// FIXME: optimize to bitshift the current uninitialized block's bits and read the top bit.
535-
if self.init_mask.get(src.offset + Size::from_bytes(i)) == cur {
535+
if self.init_mask.get(range.start + Size::from_bytes(i)) == cur {
536536
cur_len += 1;
537537
} else {
538538
ranges.push(cur_len);
@@ -550,24 +550,23 @@ impl<Tag, Extra> Allocation<Tag, Extra> {
550550
pub fn mark_compressed_init_range(
551551
&mut self,
552552
defined: &InitMaskCompressed,
553-
dest: Pointer<Tag>,
554-
size: Size,
553+
range: AllocRange,
555554
repeat: u64,
556555
) {
557556
// An optimization where we can just overwrite an entire range of initialization
558557
// bits if they are going to be uniformly `1` or `0`.
559558
if defined.ranges.len() <= 1 {
560559
self.init_mask.set_range_inbounds(
561-
dest.offset,
562-
dest.offset + size * repeat, // `Size` operations
560+
range.start,
561+
range.start + range.size * repeat, // `Size` operations
563562
defined.initial,
564563
);
565564
return;
566565
}
567566

568567
for mut j in 0..repeat {
569-
j *= size.bytes();
570-
j += dest.offset.bytes();
568+
j *= range.size.bytes();
569+
j += range.start.bytes();
571570
let mut cur = defined.initial;
572571
for range in &defined.ranges {
573572
let old_j = j;

compiler/rustc_mir/src/interpret/memory.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
10491049
num_copies,
10501050
);
10511051
// Prepare a copy of the initialization mask.
1052-
let compressed = src_alloc.compress_uninit_range(src, size);
1052+
let compressed = src_alloc.compress_uninit_range(alloc_range(src.offset, size));
10531053
// This checks relocation edges on the src.
10541054
let src_bytes = src_alloc
10551055
.get_bytes_with_uninit_and_ptr(&tcx, alloc_range(src.offset, size))
@@ -1110,7 +1110,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
11101110
}
11111111

11121112
// now fill in all the "init" data
1113-
dest_alloc.mark_compressed_init_range(&compressed, dest, size, num_copies);
1113+
dest_alloc.mark_compressed_init_range(&compressed, alloc_range(dest.offset, size), num_copies);
11141114
// copy the relocations to the destination
11151115
dest_alloc.mark_relocation_range(relocations);
11161116

0 commit comments

Comments
 (0)