Skip to content

Commit e63a625

Browse files
committed
interpret: rename relocation → provenance
1 parent 332cc8f commit e63a625

File tree

14 files changed

+161
-164
lines changed

14 files changed

+161
-164
lines changed

compiler/rustc_codegen_cranelift/src/constant.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant
430430
let bytes = alloc.inspect_with_uninit_and_ptr_outside_interpreter(0..alloc.len()).to_vec();
431431
data_ctx.define(bytes.into_boxed_slice());
432432

433-
for &(offset, alloc_id) in alloc.relocations().iter() {
433+
for &(offset, alloc_id) in alloc.provenance().iter() {
434434
let addend = {
435435
let endianness = tcx.data_layout.endian;
436436
let offset = offset.bytes() as usize;

compiler/rustc_codegen_gcc/src/consts.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ impl<'gcc, 'tcx> StaticMethods for CodegenCx<'gcc, 'tcx> {
127127
//
128128
// We could remove this hack whenever we decide to drop macOS 10.10 support.
129129
if self.tcx.sess.target.options.is_like_osx {
130-
// The `inspect` method is okay here because we checked relocations, and
130+
// The `inspect` method is okay here because we checked for provenance, and
131131
// because we are doing this access to inspect the final interpreter state
132132
// (not as part of the interpreter execution).
133133
//
@@ -296,17 +296,17 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
296296

297297
pub fn const_alloc_to_gcc<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, alloc: ConstAllocation<'tcx>) -> RValue<'gcc> {
298298
let alloc = alloc.inner();
299-
let mut llvals = Vec::with_capacity(alloc.relocations().len() + 1);
299+
let mut llvals = Vec::with_capacity(alloc.provenance().len() + 1);
300300
let dl = cx.data_layout();
301301
let pointer_size = dl.pointer_size.bytes() as usize;
302302

303303
let mut next_offset = 0;
304-
for &(offset, alloc_id) in alloc.relocations().iter() {
304+
for &(offset, alloc_id) in alloc.provenance().iter() {
305305
let offset = offset.bytes();
306306
assert_eq!(offset as usize as u64, offset);
307307
let offset = offset as usize;
308308
if offset > next_offset {
309-
// This `inspect` is okay since we have checked that it is not within a relocation, it
309+
// This `inspect` is okay since we have checked that it is not within a pointer with provenance, it
310310
// is within the bounds of the allocation, and it doesn't affect interpreter execution
311311
// (we inspect the result after interpreter execution). Any undef byte is replaced with
312312
// some arbitrary byte value.
@@ -319,7 +319,7 @@ pub fn const_alloc_to_gcc<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, alloc: ConstAl
319319
read_target_uint( dl.endian,
320320
// This `inspect` is okay since it is within the bounds of the allocation, it doesn't
321321
// affect interpreter execution (we inspect the result after interpreter execution),
322-
// and we properly interpret the relocation as a relocation pointer offset.
322+
// and we properly interpret the provenance as a relocation pointer offset.
323323
alloc.inspect_with_uninit_and_ptr_outside_interpreter(offset..(offset + pointer_size)),
324324
)
325325
.expect("const_alloc_to_llvm: could not read relocation pointer")
@@ -336,7 +336,7 @@ pub fn const_alloc_to_gcc<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, alloc: ConstAl
336336
}
337337
if alloc.len() >= next_offset {
338338
let range = next_offset..alloc.len();
339-
// This `inspect` is okay since we have check that it is after all relocations, it is
339+
// This `inspect` is okay since we have check that it is after all provenance, it is
340340
// within the bounds of the allocation, and it doesn't affect interpreter execution (we
341341
// inspect the result after interpreter execution). Any undef byte is replaced with some
342342
// arbitrary byte value.

compiler/rustc_codegen_llvm/src/consts.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ use tracing::debug;
2727

2828
pub fn const_alloc_to_llvm<'ll>(cx: &CodegenCx<'ll, '_>, alloc: ConstAllocation<'_>) -> &'ll Value {
2929
let alloc = alloc.inner();
30-
let mut llvals = Vec::with_capacity(alloc.relocations().len() + 1);
30+
let mut llvals = Vec::with_capacity(alloc.provenance().len() + 1);
3131
let dl = cx.data_layout();
3232
let pointer_size = dl.pointer_size.bytes() as usize;
3333

34-
// Note: this function may call `inspect_with_uninit_and_ptr_outside_interpreter`,
35-
// so `range` must be within the bounds of `alloc` and not contain or overlap a relocation.
34+
// Note: this function may call `inspect_with_uninit_and_ptr_outside_interpreter`, so `range`
35+
// must be within the bounds of `alloc` and not contain or overlap a pointer provenance.
3636
fn append_chunks_of_init_and_uninit_bytes<'ll, 'a, 'b>(
3737
llvals: &mut Vec<&'ll Value>,
3838
cx: &'a CodegenCx<'ll, 'b>,
@@ -79,12 +79,12 @@ pub fn const_alloc_to_llvm<'ll>(cx: &CodegenCx<'ll, '_>, alloc: ConstAllocation<
7979
}
8080

8181
let mut next_offset = 0;
82-
for &(offset, alloc_id) in alloc.relocations().iter() {
82+
for &(offset, alloc_id) in alloc.provenance().iter() {
8383
let offset = offset.bytes();
8484
assert_eq!(offset as usize as u64, offset);
8585
let offset = offset as usize;
8686
if offset > next_offset {
87-
// This `inspect` is okay since we have checked that it is not within a relocation, it
87+
// This `inspect` is okay since we have checked that there is no provenance, it
8888
// is within the bounds of the allocation, and it doesn't affect interpreter execution
8989
// (we inspect the result after interpreter execution).
9090
append_chunks_of_init_and_uninit_bytes(&mut llvals, cx, alloc, next_offset..offset);
@@ -93,7 +93,7 @@ pub fn const_alloc_to_llvm<'ll>(cx: &CodegenCx<'ll, '_>, alloc: ConstAllocation<
9393
dl.endian,
9494
// This `inspect` is okay since it is within the bounds of the allocation, it doesn't
9595
// affect interpreter execution (we inspect the result after interpreter execution),
96-
// and we properly interpret the relocation as a relocation pointer offset.
96+
// and we properly interpret the provenance as a relocation pointer offset.
9797
alloc.inspect_with_uninit_and_ptr_outside_interpreter(offset..(offset + pointer_size)),
9898
)
9999
.expect("const_alloc_to_llvm: could not read relocation pointer")
@@ -121,7 +121,7 @@ pub fn const_alloc_to_llvm<'ll>(cx: &CodegenCx<'ll, '_>, alloc: ConstAllocation<
121121
}
122122
if alloc.len() >= next_offset {
123123
let range = next_offset..alloc.len();
124-
// This `inspect` is okay since we have check that it is after all relocations, it is
124+
// This `inspect` is okay since we have check that it is after all provenance, it is
125125
// within the bounds of the allocation, and it doesn't affect interpreter execution (we
126126
// inspect the result after interpreter execution).
127127
append_chunks_of_init_and_uninit_bytes(&mut llvals, cx, alloc, range);
@@ -479,15 +479,15 @@ impl<'ll> StaticMethods for CodegenCx<'ll, '_> {
479479
//
480480
// We could remove this hack whenever we decide to drop macOS 10.10 support.
481481
if self.tcx.sess.target.is_like_osx {
482-
// The `inspect` method is okay here because we checked relocations, and
482+
// The `inspect` method is okay here because we checked for provenance, and
483483
// because we are doing this access to inspect the final interpreter state
484484
// (not as part of the interpreter execution).
485485
//
486486
// FIXME: This check requires that the (arbitrary) value of undefined bytes
487487
// happens to be zero. Instead, we should only check the value of defined bytes
488488
// and set all undefined bytes to zero if this allocation is headed for the
489489
// BSS.
490-
let all_bytes_are_zero = alloc.relocations().is_empty()
490+
let all_bytes_are_zero = alloc.provenance().is_empty()
491491
&& alloc
492492
.inspect_with_uninit_and_ptr_outside_interpreter(0..alloc.len())
493493
.iter()
@@ -511,9 +511,9 @@ impl<'ll> StaticMethods for CodegenCx<'ll, '_> {
511511
section.as_str().as_ptr().cast(),
512512
section.as_str().len() as c_uint,
513513
);
514-
assert!(alloc.relocations().is_empty());
514+
assert!(alloc.provenance().is_empty());
515515

516-
// The `inspect` method is okay here because we checked relocations, and
516+
// The `inspect` method is okay here because we checked for provenance, and
517517
// because we are doing this access to inspect the final interpreter state (not
518518
// as part of the interpreter execution).
519519
let bytes =

compiler/rustc_const_eval/src/interpret/intern.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ fn intern_shallow<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx, const_eval:
134134
alloc.mutability = Mutability::Not;
135135
};
136136
// link the alloc id to the actual allocation
137-
leftover_allocations.extend(alloc.relocations().iter().map(|&(_, alloc_id)| alloc_id));
137+
leftover_allocations.extend(alloc.provenance().iter().map(|&(_, alloc_id)| alloc_id));
138138
let alloc = tcx.intern_const_alloc(alloc);
139139
tcx.set_alloc_id_memory(alloc_id, alloc);
140140
None
@@ -191,10 +191,10 @@ impl<'rt, 'mir, 'tcx: 'mir, M: CompileTimeMachine<'mir, 'tcx, const_eval::Memory
191191
return Ok(true);
192192
};
193193

194-
// If there are no relocations in this allocation, it does not contain references
194+
// If there is no provenance in this allocation, it does not contain references
195195
// that point to another allocation, and we can avoid the interning walk.
196196
if let Some(alloc) = self.ecx.get_ptr_alloc(mplace.ptr, size, align)? {
197-
if !alloc.has_relocations() {
197+
if !alloc.has_provenance() {
198198
return Ok(false);
199199
}
200200
} else {
@@ -233,8 +233,8 @@ impl<'rt, 'mir, 'tcx: 'mir, M: CompileTimeMachine<'mir, 'tcx, const_eval::Memory
233233
}
234234

235235
fn visit_value(&mut self, mplace: &MPlaceTy<'tcx>) -> InterpResult<'tcx> {
236-
// Handle Reference types, as these are the only relocations supported by const eval.
237-
// Raw pointers (and boxes) are handled by the `leftover_relocations` logic.
236+
// Handle Reference types, as these are the only types with provenance supported by const eval.
237+
// Raw pointers (and boxes) are handled by the `leftover_allocations` logic.
238238
let tcx = self.ecx.tcx;
239239
let ty = mplace.layout.ty;
240240
if let ty::Ref(_, referenced_ty, ref_mutability) = *ty.kind() {
@@ -410,7 +410,7 @@ pub fn intern_const_alloc_recursive<
410410
// references and a `leftover_allocations` set (where we only have a todo-list here).
411411
// So we hand-roll the interning logic here again.
412412
match intern_kind {
413-
// Statics may contain mutable allocations even behind relocations.
413+
// Statics may point to mutable allocations.
414414
// Even for immutable statics it would be ok to have mutable allocations behind
415415
// raw pointers, e.g. for `static FOO: *const AtomicUsize = &AtomicUsize::new(42)`.
416416
InternKind::Static(_) => {}
@@ -441,7 +441,7 @@ pub fn intern_const_alloc_recursive<
441441
}
442442
let alloc = tcx.intern_const_alloc(alloc);
443443
tcx.set_alloc_id_memory(alloc_id, alloc);
444-
for &(_, alloc_id) in alloc.inner().relocations().iter() {
444+
for &(_, alloc_id) in alloc.inner().provenance().iter() {
445445
if leftover_allocations.insert(alloc_id) {
446446
todo.push(alloc_id);
447447
}

compiler/rustc_const_eval/src/interpret/machine.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
326326
/// cache the result. (This relies on `AllocMap::get_or` being able to add the
327327
/// owned allocation to the map even when the map is shared.)
328328
///
329-
/// This must only fail if `alloc` contains relocations.
329+
/// This must only fail if `alloc` contains provenance.
330330
fn adjust_allocation<'b>(
331331
ecx: &InterpCx<'mir, 'tcx, Self>,
332332
id: AllocId,

compiler/rustc_const_eval/src/interpret/memory.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
214214
self.allocate_raw_ptr(alloc, kind).unwrap()
215215
}
216216

217-
/// This can fail only of `alloc` contains relocations.
217+
/// This can fail only of `alloc` contains provenance.
218218
pub fn allocate_raw_ptr(
219219
&mut self,
220220
alloc: Allocation,
@@ -794,10 +794,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
794794
todo.extend(static_roots);
795795
while let Some(id) = todo.pop() {
796796
if reachable.insert(id) {
797-
// This is a new allocation, add its relocations to `todo`.
797+
// This is a new allocation, add the allocation it points to to `todo`.
798798
if let Some((_, alloc)) = self.memory.alloc_map.get(id) {
799799
todo.extend(
800-
alloc.relocations().values().filter_map(|prov| prov.get_alloc_id()),
800+
alloc.provenance().values().filter_map(|prov| prov.get_alloc_id()),
801801
);
802802
}
803803
}
@@ -833,7 +833,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> std::fmt::Debug for DumpAllocs<'a,
833833
allocs_to_print: &mut VecDeque<AllocId>,
834834
alloc: &Allocation<Prov, Extra>,
835835
) -> std::fmt::Result {
836-
for alloc_id in alloc.relocations().values().filter_map(|prov| prov.get_alloc_id()) {
836+
for alloc_id in alloc.provenance().values().filter_map(|prov| prov.get_alloc_id()) {
837837
allocs_to_print.push_back(alloc_id);
838838
}
839839
write!(fmt, "{}", display_allocation(tcx, alloc))
@@ -960,9 +960,9 @@ impl<'tcx, 'a, Prov: Provenance, Extra> AllocRef<'a, 'tcx, Prov, Extra> {
960960
.map_err(|e| e.to_interp_error(self.alloc_id))?)
961961
}
962962

963-
/// Returns whether the allocation has relocations for the entire range of the `AllocRef`.
964-
pub(crate) fn has_relocations(&self) -> bool {
965-
self.alloc.has_relocations(&self.tcx, self.range)
963+
/// Returns whether the allocation has provenance anywhere in the range of the `AllocRef`.
964+
pub(crate) fn has_provenance(&self) -> bool {
965+
self.alloc.range_has_provenance(&self.tcx, self.range)
966966
}
967967
}
968968

@@ -1078,17 +1078,17 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
10781078
return Ok(());
10791079
};
10801080

1081-
// This checks relocation edges on the src, which needs to happen before
1082-
// `prepare_relocation_copy`.
1081+
// This checks provenance edges on the src, which needs to happen before
1082+
// `prepare_provenance_copy`.
10831083
let src_bytes = src_alloc
10841084
.get_bytes_with_uninit_and_ptr(&tcx, src_range)
10851085
.map_err(|e| e.to_interp_error(src_alloc_id))?
10861086
.as_ptr(); // raw ptr, so we can also get a ptr to the destination allocation
1087-
// first copy the relocations to a temporary buffer, because
1088-
// `get_bytes_mut` will clear the relocations, which is correct,
1089-
// since we don't want to keep any relocations at the target.
1090-
let relocations =
1091-
src_alloc.prepare_relocation_copy(self, src_range, dest_offset, num_copies);
1087+
// first copy the provenance to a temporary buffer, because
1088+
// `get_bytes_mut` will clear the provenance, which is correct,
1089+
// since we don't want to keep any provenance at the target.
1090+
let provenance =
1091+
src_alloc.prepare_provenance_copy(self, src_range, dest_offset, num_copies);
10921092
// Prepare a copy of the initialization mask.
10931093
let compressed = src_alloc.compress_uninit_range(src_range);
10941094

@@ -1117,7 +1117,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
11171117
dest_alloc
11181118
.write_uninit(&tcx, dest_range)
11191119
.map_err(|e| e.to_interp_error(dest_alloc_id))?;
1120-
// We can forget about the relocations, this is all not initialized anyway.
1120+
// We can forget about the provenance, this is all not initialized anyway.
11211121
return Ok(());
11221122
}
11231123

@@ -1161,8 +1161,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
11611161
alloc_range(dest_offset, size), // just a single copy (i.e., not full `dest_range`)
11621162
num_copies,
11631163
);
1164-
// copy the relocations to the destination
1165-
dest_alloc.mark_relocation_range(relocations);
1164+
// copy the provenance to the destination
1165+
dest_alloc.mark_provenance_range(provenance);
11661166

11671167
Ok(())
11681168
}

0 commit comments

Comments
 (0)