Skip to content

Commit a7468c6

Browse files
committed
Auto merge of #99472 - RalfJung:provenance, r=oli-obk
interpret: rename Tag/PointerTag to Prov/Provenance We were pretty inconsistent with calling this the "tag" vs the "provenance" of the pointer; I think we should consistently call it "provenance". r? `@oli-obk`
2 parents 14dbfeb + 0ec3269 commit a7468c6

24 files changed

+607
-602
lines changed

compiler/rustc_const_eval/src/const_eval/machine.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
309309
ecx: &mut InterpCx<'mir, 'tcx, Self>,
310310
instance: ty::Instance<'tcx>,
311311
args: &[OpTy<'tcx>],
312-
dest: &PlaceTy<'tcx, Self::PointerTag>,
312+
dest: &PlaceTy<'tcx, Self::Provenance>,
313313
target: Option<mir::BasicBlock>,
314314
_unwind: StackPopUnwind,
315315
) -> InterpResult<'tcx> {
@@ -470,14 +470,14 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
470470
#[inline(always)]
471471
fn stack<'a>(
472472
ecx: &'a InterpCx<'mir, 'tcx, Self>,
473-
) -> &'a [Frame<'mir, 'tcx, Self::PointerTag, Self::FrameExtra>] {
473+
) -> &'a [Frame<'mir, 'tcx, Self::Provenance, Self::FrameExtra>] {
474474
&ecx.machine.stack
475475
}
476476

477477
#[inline(always)]
478478
fn stack_mut<'a>(
479479
ecx: &'a mut InterpCx<'mir, 'tcx, Self>,
480-
) -> &'a mut Vec<Frame<'mir, 'tcx, Self::PointerTag, Self::FrameExtra>> {
480+
) -> &'a mut Vec<Frame<'mir, 'tcx, Self::Provenance, Self::FrameExtra>> {
481481
&mut ecx.machine.stack
482482
}
483483

compiler/rustc_const_eval/src/interpret/cast.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ use super::{
1818
impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
1919
pub fn cast(
2020
&mut self,
21-
src: &OpTy<'tcx, M::PointerTag>,
21+
src: &OpTy<'tcx, M::Provenance>,
2222
cast_kind: CastKind,
2323
cast_ty: Ty<'tcx>,
24-
dest: &PlaceTy<'tcx, M::PointerTag>,
24+
dest: &PlaceTy<'tcx, M::Provenance>,
2525
) -> InterpResult<'tcx> {
2626
use rustc_middle::mir::CastKind::*;
2727
// FIXME: In which cases should we trigger UB when the source is uninit?
@@ -114,9 +114,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
114114

115115
pub fn misc_cast(
116116
&mut self,
117-
src: &ImmTy<'tcx, M::PointerTag>,
117+
src: &ImmTy<'tcx, M::Provenance>,
118118
cast_ty: Ty<'tcx>,
119-
) -> InterpResult<'tcx, Immediate<M::PointerTag>> {
119+
) -> InterpResult<'tcx, Immediate<M::Provenance>> {
120120
use rustc_type_ir::sty::TyKind::*;
121121
trace!("Casting {:?}: {:?} to {:?}", *src, src.layout.ty, cast_ty);
122122

@@ -173,9 +173,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
173173

174174
pub fn pointer_expose_address_cast(
175175
&mut self,
176-
src: &ImmTy<'tcx, M::PointerTag>,
176+
src: &ImmTy<'tcx, M::Provenance>,
177177
cast_ty: Ty<'tcx>,
178-
) -> InterpResult<'tcx, Immediate<M::PointerTag>> {
178+
) -> InterpResult<'tcx, Immediate<M::Provenance>> {
179179
assert_matches!(src.layout.ty.kind(), ty::RawPtr(_) | ty::FnPtr(_));
180180
assert!(cast_ty.is_integral());
181181

@@ -190,9 +190,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
190190

191191
pub fn pointer_from_exposed_address_cast(
192192
&mut self,
193-
src: &ImmTy<'tcx, M::PointerTag>,
193+
src: &ImmTy<'tcx, M::Provenance>,
194194
cast_ty: Ty<'tcx>,
195-
) -> InterpResult<'tcx, Immediate<M::PointerTag>> {
195+
) -> InterpResult<'tcx, Immediate<M::Provenance>> {
196196
assert!(src.layout.ty.is_integral());
197197
assert_matches!(cast_ty.kind(), ty::RawPtr(_));
198198

@@ -208,10 +208,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
208208

209209
pub fn cast_from_int_like(
210210
&self,
211-
scalar: Scalar<M::PointerTag>, // input value (there is no ScalarTy so we separate data+layout)
211+
scalar: Scalar<M::Provenance>, // input value (there is no ScalarTy so we separate data+layout)
212212
src_layout: TyAndLayout<'tcx>,
213213
cast_ty: Ty<'tcx>,
214-
) -> InterpResult<'tcx, Scalar<M::PointerTag>> {
214+
) -> InterpResult<'tcx, Scalar<M::Provenance>> {
215215
// Let's make sure v is sign-extended *if* it has a signed type.
216216
let signed = src_layout.abi.is_signed(); // Also asserts that abi is `Scalar`.
217217

@@ -245,9 +245,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
245245
})
246246
}
247247

248-
fn cast_from_float<F>(&self, f: F, dest_ty: Ty<'tcx>) -> Scalar<M::PointerTag>
248+
fn cast_from_float<F>(&self, f: F, dest_ty: Ty<'tcx>) -> Scalar<M::Provenance>
249249
where
250-
F: Float + Into<Scalar<M::PointerTag>> + FloatConvert<Single> + FloatConvert<Double>,
250+
F: Float + Into<Scalar<M::Provenance>> + FloatConvert<Single> + FloatConvert<Double>,
251251
{
252252
use rustc_type_ir::sty::TyKind::*;
253253
match *dest_ty.kind() {
@@ -279,8 +279,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
279279

280280
fn unsize_into_ptr(
281281
&mut self,
282-
src: &OpTy<'tcx, M::PointerTag>,
283-
dest: &PlaceTy<'tcx, M::PointerTag>,
282+
src: &OpTy<'tcx, M::Provenance>,
283+
dest: &PlaceTy<'tcx, M::Provenance>,
284284
// The pointee types
285285
source_ty: Ty<'tcx>,
286286
cast_ty: Ty<'tcx>,
@@ -335,9 +335,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
335335

336336
fn unsize_into(
337337
&mut self,
338-
src: &OpTy<'tcx, M::PointerTag>,
338+
src: &OpTy<'tcx, M::Provenance>,
339339
cast_ty: TyAndLayout<'tcx>,
340-
dest: &PlaceTy<'tcx, M::PointerTag>,
340+
dest: &PlaceTy<'tcx, M::Provenance>,
341341
) -> InterpResult<'tcx> {
342342
trace!("Unsizing {:?} of type {} into {:?}", *src, src.layout.ty, cast_ty.ty);
343343
match (&src.layout.ty.kind(), &cast_ty.ty.kind()) {

compiler/rustc_const_eval/src/interpret/eval_context.rs

+26-26
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl Drop for SpanGuard {
8181
}
8282

8383
/// A stack frame.
84-
pub struct Frame<'mir, 'tcx, Tag: Provenance = AllocId, Extra = ()> {
84+
pub struct Frame<'mir, 'tcx, Prov: Provenance = AllocId, Extra = ()> {
8585
////////////////////////////////////////////////////////////////////////////////
8686
// Function and callsite information
8787
////////////////////////////////////////////////////////////////////////////////
@@ -102,7 +102,7 @@ pub struct Frame<'mir, 'tcx, Tag: Provenance = AllocId, Extra = ()> {
102102

103103
/// The location where the result of the current stack frame should be written to,
104104
/// and its layout in the caller.
105-
pub return_place: PlaceTy<'tcx, Tag>,
105+
pub return_place: PlaceTy<'tcx, Prov>,
106106

107107
/// The list of locals for this stack frame, stored in order as
108108
/// `[return_ptr, arguments..., variables..., temporaries...]`.
@@ -111,7 +111,7 @@ pub struct Frame<'mir, 'tcx, Tag: Provenance = AllocId, Extra = ()> {
111111
/// can either directly contain `Scalar` or refer to some part of an `Allocation`.
112112
///
113113
/// Do *not* access this directly; always go through the machine hook!
114-
pub locals: IndexVec<mir::Local, LocalState<'tcx, Tag>>,
114+
pub locals: IndexVec<mir::Local, LocalState<'tcx, Prov>>,
115115

116116
/// The span of the `tracing` crate is stored here.
117117
/// When the guard is dropped, the span is exited. This gives us
@@ -166,32 +166,32 @@ pub enum StackPopCleanup {
166166

167167
/// State of a local variable including a memoized layout
168168
#[derive(Clone, Debug)]
169-
pub struct LocalState<'tcx, Tag: Provenance = AllocId> {
170-
pub value: LocalValue<Tag>,
169+
pub struct LocalState<'tcx, Prov: Provenance = AllocId> {
170+
pub value: LocalValue<Prov>,
171171
/// Don't modify if `Some`, this is only used to prevent computing the layout twice
172172
pub layout: Cell<Option<TyAndLayout<'tcx>>>,
173173
}
174174

175175
/// Current value of a local variable
176176
#[derive(Copy, Clone, Debug)] // Miri debug-prints these
177-
pub enum LocalValue<Tag: Provenance = AllocId> {
177+
pub enum LocalValue<Prov: Provenance = AllocId> {
178178
/// This local is not currently alive, and cannot be used at all.
179179
Dead,
180180
/// A normal, live local.
181181
/// Mostly for convenience, we re-use the `Operand` type here.
182182
/// This is an optimization over just always having a pointer here;
183183
/// we can thus avoid doing an allocation when the local just stores
184184
/// immediate values *and* never has its address taken.
185-
Live(Operand<Tag>),
185+
Live(Operand<Prov>),
186186
}
187187

188-
impl<'tcx, Tag: Provenance + 'static> LocalState<'tcx, Tag> {
188+
impl<'tcx, Prov: Provenance + 'static> LocalState<'tcx, Prov> {
189189
/// Read the local's value or error if the local is not yet live or not live anymore.
190190
///
191191
/// Note: This may only be invoked from the `Machine::access_local` hook and not from
192192
/// anywhere else. You may be invalidating machine invariants if you do!
193193
#[inline]
194-
pub fn access(&self) -> InterpResult<'tcx, &Operand<Tag>> {
194+
pub fn access(&self) -> InterpResult<'tcx, &Operand<Prov>> {
195195
match &self.value {
196196
LocalValue::Dead => throw_ub!(DeadLocal), // could even be "invalid program"?
197197
LocalValue::Live(val) => Ok(val),
@@ -204,16 +204,16 @@ impl<'tcx, Tag: Provenance + 'static> LocalState<'tcx, Tag> {
204204
/// Note: This may only be invoked from the `Machine::access_local_mut` hook and not from
205205
/// anywhere else. You may be invalidating machine invariants if you do!
206206
#[inline]
207-
pub fn access_mut(&mut self) -> InterpResult<'tcx, &mut Operand<Tag>> {
207+
pub fn access_mut(&mut self) -> InterpResult<'tcx, &mut Operand<Prov>> {
208208
match &mut self.value {
209209
LocalValue::Dead => throw_ub!(DeadLocal), // could even be "invalid program"?
210210
LocalValue::Live(val) => Ok(val),
211211
}
212212
}
213213
}
214214

215-
impl<'mir, 'tcx, Tag: Provenance> Frame<'mir, 'tcx, Tag> {
216-
pub fn with_extra<Extra>(self, extra: Extra) -> Frame<'mir, 'tcx, Tag, Extra> {
215+
impl<'mir, 'tcx, Prov: Provenance> Frame<'mir, 'tcx, Prov> {
216+
pub fn with_extra<Extra>(self, extra: Extra) -> Frame<'mir, 'tcx, Prov, Extra> {
217217
Frame {
218218
body: self.body,
219219
instance: self.instance,
@@ -227,7 +227,7 @@ impl<'mir, 'tcx, Tag: Provenance> Frame<'mir, 'tcx, Tag> {
227227
}
228228
}
229229

230-
impl<'mir, 'tcx, Tag: Provenance, Extra> Frame<'mir, 'tcx, Tag, Extra> {
230+
impl<'mir, 'tcx, Prov: Provenance, Extra> Frame<'mir, 'tcx, Prov, Extra> {
231231
/// Get the current location within the Frame.
232232
///
233233
/// If this is `Err`, we are not currently executing any particular statement in
@@ -422,14 +422,14 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
422422
}
423423

424424
#[inline(always)]
425-
pub(crate) fn stack(&self) -> &[Frame<'mir, 'tcx, M::PointerTag, M::FrameExtra>] {
425+
pub(crate) fn stack(&self) -> &[Frame<'mir, 'tcx, M::Provenance, M::FrameExtra>] {
426426
M::stack(self)
427427
}
428428

429429
#[inline(always)]
430430
pub(crate) fn stack_mut(
431431
&mut self,
432-
) -> &mut Vec<Frame<'mir, 'tcx, M::PointerTag, M::FrameExtra>> {
432+
) -> &mut Vec<Frame<'mir, 'tcx, M::Provenance, M::FrameExtra>> {
433433
M::stack_mut(self)
434434
}
435435

@@ -441,12 +441,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
441441
}
442442

443443
#[inline(always)]
444-
pub fn frame(&self) -> &Frame<'mir, 'tcx, M::PointerTag, M::FrameExtra> {
444+
pub fn frame(&self) -> &Frame<'mir, 'tcx, M::Provenance, M::FrameExtra> {
445445
self.stack().last().expect("no call frames exist")
446446
}
447447

448448
#[inline(always)]
449-
pub fn frame_mut(&mut self) -> &mut Frame<'mir, 'tcx, M::PointerTag, M::FrameExtra> {
449+
pub fn frame_mut(&mut self) -> &mut Frame<'mir, 'tcx, M::Provenance, M::FrameExtra> {
450450
self.stack_mut().last_mut().expect("no call frames exist")
451451
}
452452

@@ -503,7 +503,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
503503
/// stack frame), to bring it into the proper environment for this interpreter.
504504
pub(super) fn subst_from_frame_and_normalize_erasing_regions<T: TypeFoldable<'tcx>>(
505505
&self,
506-
frame: &Frame<'mir, 'tcx, M::PointerTag, M::FrameExtra>,
506+
frame: &Frame<'mir, 'tcx, M::Provenance, M::FrameExtra>,
507507
value: T,
508508
) -> Result<T, InterpError<'tcx>> {
509509
frame
@@ -540,7 +540,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
540540
#[inline(always)]
541541
pub fn layout_of_local(
542542
&self,
543-
frame: &Frame<'mir, 'tcx, M::PointerTag, M::FrameExtra>,
543+
frame: &Frame<'mir, 'tcx, M::Provenance, M::FrameExtra>,
544544
local: mir::Local,
545545
layout: Option<TyAndLayout<'tcx>>,
546546
) -> InterpResult<'tcx, TyAndLayout<'tcx>> {
@@ -569,7 +569,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
569569
/// This can fail to provide an answer for extern types.
570570
pub(super) fn size_and_align_of(
571571
&self,
572-
metadata: &MemPlaceMeta<M::PointerTag>,
572+
metadata: &MemPlaceMeta<M::Provenance>,
573573
layout: &TyAndLayout<'tcx>,
574574
) -> InterpResult<'tcx, Option<(Size, Align)>> {
575575
if !layout.is_unsized() {
@@ -655,7 +655,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
655655
#[inline]
656656
pub fn size_and_align_of_mplace(
657657
&self,
658-
mplace: &MPlaceTy<'tcx, M::PointerTag>,
658+
mplace: &MPlaceTy<'tcx, M::Provenance>,
659659
) -> InterpResult<'tcx, Option<(Size, Align)>> {
660660
self.size_and_align_of(&mplace.meta, &mplace.layout)
661661
}
@@ -665,7 +665,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
665665
&mut self,
666666
instance: ty::Instance<'tcx>,
667667
body: &'mir mir::Body<'tcx>,
668-
return_place: &PlaceTy<'tcx, M::PointerTag>,
668+
return_place: &PlaceTy<'tcx, M::Provenance>,
669669
return_to_block: StackPopCleanup,
670670
) -> InterpResult<'tcx> {
671671
trace!("body: {:#?}", body);
@@ -891,7 +891,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
891891
}
892892

893893
#[instrument(skip(self), level = "debug")]
894-
fn deallocate_local(&mut self, local: LocalValue<M::PointerTag>) -> InterpResult<'tcx> {
894+
fn deallocate_local(&mut self, local: LocalValue<M::Provenance>) -> InterpResult<'tcx> {
895895
if let LocalValue::Live(Operand::Indirect(MemPlace { ptr, .. })) = local {
896896
// All locals have a backing allocation, even if the allocation is empty
897897
// due to the local having ZST type. Hence we can `unwrap`.
@@ -909,7 +909,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
909909
pub fn eval_to_allocation(
910910
&self,
911911
gid: GlobalId<'tcx>,
912-
) -> InterpResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> {
912+
) -> InterpResult<'tcx, MPlaceTy<'tcx, M::Provenance>> {
913913
// For statics we pick `ParamEnv::reveal_all`, because statics don't have generics
914914
// and thus don't care about the parameter environment. While we could just use
915915
// `self.param_env`, that would mean we invoke the query to evaluate the static
@@ -927,7 +927,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
927927
}
928928

929929
#[must_use]
930-
pub fn dump_place(&self, place: Place<M::PointerTag>) -> PlacePrinter<'_, 'mir, 'tcx, M> {
930+
pub fn dump_place(&self, place: Place<M::Provenance>) -> PlacePrinter<'_, 'mir, 'tcx, M> {
931931
PlacePrinter { ecx: self, place }
932932
}
933933

@@ -956,7 +956,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
956956
/// Helper struct for the `dump_place` function.
957957
pub struct PlacePrinter<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> {
958958
ecx: &'a InterpCx<'mir, 'tcx, M>,
959-
place: Place<M::PointerTag>,
959+
place: Place<M::Provenance>,
960960
}
961961

962962
impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> std::fmt::Debug

compiler/rustc_const_eval/src/interpret/intern.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub trait CompileTimeMachine<'mir, 'tcx, T> = Machine<
3333
'mir,
3434
'tcx,
3535
MemoryKind = T,
36-
PointerTag = AllocId,
36+
Provenance = AllocId,
3737
ExtraFnVal = !,
3838
FrameExtra = (),
3939
AllocExtra = (),
@@ -474,7 +474,7 @@ impl<'mir, 'tcx: 'mir, M: super::intern::CompileTimeMachine<'mir, 'tcx, !>>
474474
layout: TyAndLayout<'tcx>,
475475
f: impl FnOnce(
476476
&mut InterpCx<'mir, 'tcx, M>,
477-
&PlaceTy<'tcx, M::PointerTag>,
477+
&PlaceTy<'tcx, M::Provenance>,
478478
) -> InterpResult<'tcx, ()>,
479479
) -> InterpResult<'tcx, ConstAllocation<'tcx>> {
480480
let dest = self.allocate(layout, MemoryKind::Stack)?;

0 commit comments

Comments
 (0)