Skip to content

Commit ae7b07f

Browse files
committed
interpret: rename base_pointer -> root_pointer
also in Miri, "base tag" -> "root tag"
1 parent 9e239bd commit ae7b07f

File tree

14 files changed

+53
-53
lines changed

14 files changed

+53
-53
lines changed

compiler/rustc_const_eval/src/interpret/machine.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -288,15 +288,15 @@ pub trait Machine<'mir, 'tcx: 'mir>: Sized {
288288
}
289289

290290
/// Return the `AllocId` for the given thread-local static in the current thread.
291-
fn thread_local_static_base_pointer(
291+
fn thread_local_static_pointer(
292292
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
293293
def_id: DefId,
294294
) -> InterpResult<'tcx, Pointer<Self::Provenance>> {
295295
throw_unsup!(ThreadLocalStatic(def_id))
296296
}
297297

298-
/// Return the root pointer for the given `extern static`.
299-
fn extern_static_base_pointer(
298+
/// Return the `AllocId` for the given `extern static`.
299+
fn extern_static_pointer(
300300
ecx: &InterpCx<'mir, 'tcx, Self>,
301301
def_id: DefId,
302302
) -> InterpResult<'tcx, Pointer<Self::Provenance>>;
@@ -354,7 +354,7 @@ pub trait Machine<'mir, 'tcx: 'mir>: Sized {
354354
///
355355
/// `kind` is the kind of the allocation the pointer points to; it can be `None` when
356356
/// it's a global and `GLOBAL_KIND` is `None`.
357-
fn adjust_alloc_base_pointer(
357+
fn adjust_alloc_root_pointer(
358358
ecx: &InterpCx<'mir, 'tcx, Self>,
359359
ptr: Pointer,
360360
kind: Option<MemoryKind<Self::MemoryKind>>,
@@ -598,7 +598,7 @@ pub macro compile_time_machine(<$mir: lifetime, $tcx: lifetime>) {
598598
Ok(alloc)
599599
}
600600

601-
fn extern_static_base_pointer(
601+
fn extern_static_pointer(
602602
ecx: &InterpCx<$mir, $tcx, Self>,
603603
def_id: DefId,
604604
) -> InterpResult<$tcx, Pointer> {
@@ -607,7 +607,7 @@ pub macro compile_time_machine(<$mir: lifetime, $tcx: lifetime>) {
607607
}
608608

609609
#[inline(always)]
610-
fn adjust_alloc_base_pointer(
610+
fn adjust_alloc_root_pointer(
611611
_ecx: &InterpCx<$mir, $tcx, Self>,
612612
ptr: Pointer<CtfeProvenance>,
613613
_kind: Option<MemoryKind<Self::MemoryKind>>,

compiler/rustc_const_eval/src/interpret/memory.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
165165
///
166166
/// This function can fail only if `ptr` points to an `extern static`.
167167
#[inline]
168-
pub fn global_base_pointer(
168+
pub fn global_root_pointer(
169169
&self,
170170
ptr: Pointer<CtfeProvenance>,
171171
) -> InterpResult<'tcx, Pointer<M::Provenance>> {
@@ -178,7 +178,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
178178
bug!("global memory cannot point to thread-local static")
179179
}
180180
Some(GlobalAlloc::Static(def_id)) if self.tcx.is_foreign_item(def_id) => {
181-
return M::extern_static_base_pointer(self, def_id);
181+
return M::extern_static_pointer(self, def_id);
182182
}
183183
None => {
184184
assert!(
@@ -189,7 +189,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
189189
_ => {}
190190
}
191191
// And we need to get the provenance.
192-
M::adjust_alloc_base_pointer(self, ptr, M::GLOBAL_KIND.map(MemoryKind::Machine))
192+
M::adjust_alloc_root_pointer(self, ptr, M::GLOBAL_KIND.map(MemoryKind::Machine))
193193
}
194194

195195
pub fn fn_ptr(&mut self, fn_val: FnVal<'tcx, M::ExtraFnVal>) -> Pointer<M::Provenance> {
@@ -203,9 +203,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
203203
id
204204
}
205205
};
206-
// Functions are global allocations, so make sure we get the right base pointer.
206+
// Functions are global allocations, so make sure we get the right root pointer.
207207
// We know this is not an `extern static` so this cannot fail.
208-
self.global_base_pointer(Pointer::from(id)).unwrap()
208+
self.global_root_pointer(Pointer::from(id)).unwrap()
209209
}
210210

211211
pub fn allocate_ptr(
@@ -246,7 +246,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
246246
);
247247
let alloc = M::adjust_allocation(self, id, Cow::Owned(alloc), Some(kind))?;
248248
self.memory.alloc_map.insert(id, (kind, alloc.into_owned()));
249-
M::adjust_alloc_base_pointer(self, Pointer::from(id), Some(kind))
249+
M::adjust_alloc_root_pointer(self, Pointer::from(id), Some(kind))
250250
}
251251

252252
pub fn reallocate_ptr(

compiler/rustc_const_eval/src/interpret/operand.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -764,15 +764,15 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
764764
// Other cases need layout.
765765
let adjust_scalar = |scalar| -> InterpResult<'tcx, _> {
766766
Ok(match scalar {
767-
Scalar::Ptr(ptr, size) => Scalar::Ptr(self.global_base_pointer(ptr)?, size),
767+
Scalar::Ptr(ptr, size) => Scalar::Ptr(self.global_root_pointer(ptr)?, size),
768768
Scalar::Int(int) => Scalar::Int(int),
769769
})
770770
};
771771
let layout = from_known_layout(self.tcx, self.param_env, layout, || self.layout_of(ty))?;
772772
let imm = match val_val {
773773
mir::ConstValue::Indirect { alloc_id, offset } => {
774774
// This is const data, no mutation allowed.
775-
let ptr = self.global_base_pointer(Pointer::new(
775+
let ptr = self.global_root_pointer(Pointer::new(
776776
CtfeProvenance::from(alloc_id).as_immutable(),
777777
offset,
778778
))?;
@@ -784,7 +784,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
784784
// This is const data, no mutation allowed.
785785
let alloc_id = self.tcx.reserve_and_set_memory_alloc(data);
786786
let ptr = Pointer::new(CtfeProvenance::from(alloc_id).as_immutable(), Size::ZERO);
787-
Immediate::new_slice(self.global_base_pointer(ptr)?.into(), meta, self)
787+
Immediate::new_slice(self.global_root_pointer(ptr)?.into(), meta, self)
788788
}
789789
};
790790
Ok(OpTy { op: Operand::Immediate(imm), layout })

compiler/rustc_const_eval/src/interpret/place.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,7 @@ where
10101010
) -> InterpResult<'tcx, MPlaceTy<'tcx, M::Provenance>> {
10111011
// This must be an allocation in `tcx`
10121012
let _ = self.tcx.global_alloc(raw.alloc_id);
1013-
let ptr = self.global_base_pointer(Pointer::from(raw.alloc_id))?;
1013+
let ptr = self.global_root_pointer(Pointer::from(raw.alloc_id))?;
10141014
let layout = self.layout_of(raw.ty)?;
10151015
Ok(self.ptr_to_mplace(ptr.into(), layout))
10161016
}

compiler/rustc_const_eval/src/interpret/step.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
144144
use rustc_middle::mir::Rvalue::*;
145145
match *rvalue {
146146
ThreadLocalRef(did) => {
147-
let ptr = M::thread_local_static_base_pointer(self, did)?;
147+
let ptr = M::thread_local_static_pointer(self, did)?;
148148
self.write_pointer(ptr, &dest)?;
149149
}
150150

compiler/rustc_const_eval/src/interpret/traits.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
2828
ensure_monomorphic_enough(*self.tcx, poly_trait_ref)?;
2929

3030
let vtable_symbolic_allocation = self.tcx.reserve_and_set_vtable_alloc(ty, poly_trait_ref);
31-
let vtable_ptr = self.global_base_pointer(Pointer::from(vtable_symbolic_allocation))?;
31+
let vtable_ptr = self.global_root_pointer(Pointer::from(vtable_symbolic_allocation))?;
3232
Ok(vtable_ptr.into())
3333
}
3434

src/tools/miri/src/alloc_addresses/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
287287
}
288288

289289
/// Convert a relative (tcx) pointer to a Miri pointer.
290-
fn adjust_alloc_base_pointer(
290+
fn adjust_alloc_root_pointer(
291291
&self,
292292
ptr: Pointer<CtfeProvenance>,
293293
tag: BorTag,
@@ -319,7 +319,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
319319
ecx.alloc_id_from_addr(addr.bytes())?
320320
};
321321

322-
// This cannot fail: since we already have a pointer with that provenance, adjust_alloc_base_pointer
322+
// This cannot fail: since we already have a pointer with that provenance, adjust_alloc_root_pointer
323323
// must have been called in the past, so we can just look up the address in the map.
324324
let base_addr = *ecx.machine.alloc_addresses.borrow().base_addr.get(&alloc_id).unwrap();
325325

src/tools/miri/src/borrow_tracker/mod.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ pub struct GlobalStateInner {
8989
borrow_tracker_method: BorrowTrackerMethod,
9090
/// Next unused pointer ID (tag).
9191
next_ptr_tag: BorTag,
92-
/// Table storing the "base" tag for each allocation.
93-
/// The base tag is the one used for the initial pointer.
92+
/// Table storing the "root" tag for each allocation.
93+
/// The root tag is the one used for the initial pointer.
9494
/// We need this in a separate table to handle cyclic statics.
95-
base_ptr_tags: FxHashMap<AllocId, BorTag>,
95+
root_ptr_tags: FxHashMap<AllocId, BorTag>,
9696
/// Next unused call ID (for protectors).
9797
next_call_id: CallId,
9898
/// All currently protected tags.
@@ -175,7 +175,7 @@ impl GlobalStateInner {
175175
GlobalStateInner {
176176
borrow_tracker_method,
177177
next_ptr_tag: BorTag::one(),
178-
base_ptr_tags: FxHashMap::default(),
178+
root_ptr_tags: FxHashMap::default(),
179179
next_call_id: NonZero::new(1).unwrap(),
180180
protected_tags: FxHashMap::default(),
181181
tracked_pointer_tags,
@@ -213,8 +213,8 @@ impl GlobalStateInner {
213213
}
214214
}
215215

216-
pub fn base_ptr_tag(&mut self, id: AllocId, machine: &MiriMachine<'_, '_>) -> BorTag {
217-
self.base_ptr_tags.get(&id).copied().unwrap_or_else(|| {
216+
pub fn root_ptr_tag(&mut self, id: AllocId, machine: &MiriMachine<'_, '_>) -> BorTag {
217+
self.root_ptr_tags.get(&id).copied().unwrap_or_else(|| {
218218
let tag = self.new_ptr();
219219
if self.tracked_pointer_tags.contains(&tag) {
220220
machine.emit_diagnostic(NonHaltingDiagnostic::CreatedPointerTag(
@@ -223,14 +223,14 @@ impl GlobalStateInner {
223223
None,
224224
));
225225
}
226-
trace!("New allocation {:?} has base tag {:?}", id, tag);
227-
self.base_ptr_tags.try_insert(id, tag).unwrap();
226+
trace!("New allocation {:?} has rpot tag {:?}", id, tag);
227+
self.root_ptr_tags.try_insert(id, tag).unwrap();
228228
tag
229229
})
230230
}
231231

232232
pub fn remove_unreachable_allocs(&mut self, allocs: &LiveAllocs<'_, '_, '_>) {
233-
self.base_ptr_tags.retain(|id, _| allocs.is_live(*id));
233+
self.root_ptr_tags.retain(|id, _| allocs.is_live(*id));
234234
}
235235
}
236236

src/tools/miri/src/borrow_tracker/stacked_borrows/diagnostics.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fn err_sb_ub<'tcx>(
2020
#[derive(Clone, Debug)]
2121
pub struct AllocHistory {
2222
id: AllocId,
23-
base: (Item, Span),
23+
root: (Item, Span),
2424
creations: smallvec::SmallVec<[Creation; 1]>,
2525
invalidations: smallvec::SmallVec<[Invalidation; 1]>,
2626
protectors: smallvec::SmallVec<[Protection; 1]>,
@@ -225,7 +225,7 @@ impl AllocHistory {
225225
pub fn new(id: AllocId, item: Item, machine: &MiriMachine<'_, '_>) -> Self {
226226
Self {
227227
id,
228-
base: (item, machine.current_span()),
228+
root: (item, machine.current_span()),
229229
creations: SmallVec::new(),
230230
invalidations: SmallVec::new(),
231231
protectors: SmallVec::new(),
@@ -342,15 +342,15 @@ impl<'history, 'ecx, 'mir, 'tcx> DiagnosticCx<'history, 'ecx, 'mir, 'tcx> {
342342
})
343343
})
344344
.or_else(|| {
345-
// If we didn't find a retag that created this tag, it might be the base tag of
345+
// If we didn't find a retag that created this tag, it might be the root tag of
346346
// this allocation.
347-
if self.history.base.0.tag() == tag {
347+
if self.history.root.0.tag() == tag {
348348
Some((
349349
format!(
350-
"{tag:?} was created here, as the base tag for {:?}",
350+
"{tag:?} was created here, as the root tag for {:?}",
351351
self.history.id
352352
),
353-
self.history.base.1.data(),
353+
self.history.root.1.data(),
354354
))
355355
} else {
356356
None

src/tools/miri/src/borrow_tracker/stacked_borrows/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -518,9 +518,9 @@ impl Stacks {
518518
// not through a pointer). That is, whenever we directly write to a local, this will pop
519519
// everything else off the stack, invalidating all previous pointers,
520520
// and in particular, *all* raw pointers.
521-
MemoryKind::Stack => (state.base_ptr_tag(id, machine), Permission::Unique),
521+
MemoryKind::Stack => (state.root_ptr_tag(id, machine), Permission::Unique),
522522
// Everything else is shared by default.
523-
_ => (state.base_ptr_tag(id, machine), Permission::SharedReadWrite),
523+
_ => (state.root_ptr_tag(id, machine), Permission::SharedReadWrite),
524524
};
525525
Stacks::new(size, perm, base_tag, id, machine)
526526
}

src/tools/miri/src/borrow_tracker/stacked_borrows/stack.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl Stack {
4747
let mut first_removed = None;
4848

4949
// We never consider removing the bottom-most tag. For stacks without an unknown
50-
// bottom this preserves the base tag.
50+
// bottom this preserves the root tag.
5151
// Note that the algorithm below is based on considering the tag at read_idx - 1,
5252
// so precisely considering the tag at index 0 for removal when we have an unknown
5353
// bottom would complicate the implementation. The simplification of not considering
@@ -93,7 +93,7 @@ impl Stack {
9393
self.unique_range = 0..self.len();
9494
}
9595

96-
// Replace any Items which have been collected with the base item, a known-good value.
96+
// Replace any Items which have been collected with the root item, a known-good value.
9797
for i in 0..CACHE_LEN {
9898
if self.cache.idx[i] >= first_removed {
9999
self.cache.items[i] = self.borrows[0];
@@ -331,7 +331,7 @@ impl<'tcx> Stack {
331331
self.verify_cache_consistency();
332332
}
333333

334-
/// Construct a new `Stack` using the passed `Item` as the base tag.
334+
/// Construct a new `Stack` using the passed `Item` as the root tag.
335335
pub fn new(item: Item) -> Self {
336336
Stack {
337337
borrows: vec![item],
@@ -438,8 +438,8 @@ impl<'tcx> Stack {
438438
let mut removed = 0;
439439
let mut cursor = 0;
440440
// Remove invalid entries from the cache by rotating them to the end of the cache, then
441-
// keep track of how many invalid elements there are and overwrite them with the base tag.
442-
// The base tag here serves as a harmless default value.
441+
// keep track of how many invalid elements there are and overwrite them with the root tag.
442+
// The root tag here serves as a harmless default value.
443443
for _ in 0..CACHE_LEN - 1 {
444444
if self.cache.idx[cursor] >= start {
445445
self.cache.idx[cursor..CACHE_LEN - removed].rotate_left(1);

src/tools/miri/src/borrow_tracker/tree_borrows/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl<'tcx> Tree {
3737
_kind: MemoryKind,
3838
machine: &MiriMachine<'_, 'tcx>,
3939
) -> Self {
40-
let tag = state.base_ptr_tag(id, machine); // Fresh tag for the root
40+
let tag = state.root_ptr_tag(id, machine); // Fresh tag for the root
4141
let span = machine.current_span();
4242
Tree::new(tag, size, span)
4343
}

src/tools/miri/src/machine.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ pub struct MiriMachine<'mir, 'tcx> {
503503
/// Crates which are considered local for the purposes of error reporting.
504504
pub(crate) local_crates: Vec<CrateNum>,
505505

506-
/// Mapping extern static names to their base pointer.
506+
/// Mapping extern static names to their pointer.
507507
extern_statics: FxHashMap<Symbol, Pointer<Provenance>>,
508508

509509
/// The random number generator used for resolving non-determinism.
@@ -1042,14 +1042,14 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
10421042
ecx.generate_nan(inputs)
10431043
}
10441044

1045-
fn thread_local_static_base_pointer(
1045+
fn thread_local_static_pointer(
10461046
ecx: &mut MiriInterpCx<'mir, 'tcx>,
10471047
def_id: DefId,
10481048
) -> InterpResult<'tcx, Pointer<Provenance>> {
10491049
ecx.get_or_create_thread_local_alloc(def_id)
10501050
}
10511051

1052-
fn extern_static_base_pointer(
1052+
fn extern_static_pointer(
10531053
ecx: &MiriInterpCx<'mir, 'tcx>,
10541054
def_id: DefId,
10551055
) -> InterpResult<'tcx, Pointer<Provenance>> {
@@ -1135,7 +1135,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
11351135
weak_memory: buffer_alloc,
11361136
backtrace,
11371137
},
1138-
|ptr| ecx.global_base_pointer(ptr),
1138+
|ptr| ecx.global_root_pointer(ptr),
11391139
)?;
11401140

11411141
if matches!(kind, MemoryKind::Machine(kind) if kind.should_save_allocation_span()) {
@@ -1148,7 +1148,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
11481148
Ok(Cow::Owned(alloc))
11491149
}
11501150

1151-
fn adjust_alloc_base_pointer(
1151+
fn adjust_alloc_root_pointer(
11521152
ecx: &MiriInterpCx<'mir, 'tcx>,
11531153
ptr: Pointer<CtfeProvenance>,
11541154
kind: Option<MemoryKind>,
@@ -1159,22 +1159,22 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
11591159
// The machine promises to never call us on thread-local or extern statics.
11601160
match ecx.tcx.try_get_global_alloc(alloc_id) {
11611161
Some(GlobalAlloc::Static(def_id)) if ecx.tcx.is_thread_local_static(def_id) => {
1162-
panic!("adjust_alloc_base_pointer called on thread-local static")
1162+
panic!("adjust_alloc_root_pointer called on thread-local static")
11631163
}
11641164
Some(GlobalAlloc::Static(def_id)) if ecx.tcx.is_foreign_item(def_id) => {
1165-
panic!("adjust_alloc_base_pointer called on extern static")
1165+
panic!("adjust_alloc_root_pointer called on extern static")
11661166
}
11671167
_ => {}
11681168
}
11691169
}
11701170
// FIXME: can we somehow preserve the immutability of `ptr`?
11711171
let tag = if let Some(borrow_tracker) = &ecx.machine.borrow_tracker {
1172-
borrow_tracker.borrow_mut().base_ptr_tag(alloc_id, &ecx.machine)
1172+
borrow_tracker.borrow_mut().root_ptr_tag(alloc_id, &ecx.machine)
11731173
} else {
11741174
// Value does not matter, SB is disabled
11751175
BorTag::default()
11761176
};
1177-
ecx.adjust_alloc_base_pointer(ptr, tag, kind)
1177+
ecx.adjust_alloc_root_pointer(ptr, tag, kind)
11781178
}
11791179

11801180
/// Called on `usize as ptr` casts.

src/tools/miri/tests/fail/both_borrows/invalidate_against_protector3.stack.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | unsafe { *x = 0 };
66
|
77
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
88
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
9-
help: <TAG> was created here, as the base tag for ALLOC
9+
help: <TAG> was created here, as the root tag for ALLOC
1010
--> $DIR/invalidate_against_protector3.rs:LL:CC
1111
|
1212
LL | let ptr = alloc(Layout::for_value(&0i32)) as *mut i32;

0 commit comments

Comments
 (0)