1
Fork 0

assert that we are (de)seiralizing ProvenanceMap correctly

This commit is contained in:
Ralf Jung 2022-11-14 13:37:08 +01:00
parent 03b2598924
commit 68af46c112
5 changed files with 16 additions and 16 deletions

View file

@ -112,7 +112,7 @@ pub struct Memory<'mir, 'tcx, M: Machine<'mir, 'tcx>> {
/// A reference to some allocation that was already bounds-checked for the given region /// A reference to some allocation that was already bounds-checked for the given region
/// and had the on-access machine hooks run. /// and had the on-access machine hooks run.
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub struct AllocRef<'a, 'tcx, Prov, Extra> { pub struct AllocRef<'a, 'tcx, Prov: Provenance, Extra> {
alloc: &'a Allocation<Prov, Extra>, alloc: &'a Allocation<Prov, Extra>,
range: AllocRange, range: AllocRange,
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
@ -120,7 +120,7 @@ pub struct AllocRef<'a, 'tcx, Prov, Extra> {
} }
/// A reference to some allocation that was already bounds-checked for the given region /// A reference to some allocation that was already bounds-checked for the given region
/// and had the on-access machine hooks run. /// and had the on-access machine hooks run.
pub struct AllocRefMut<'a, 'tcx, Prov, Extra> { pub struct AllocRefMut<'a, 'tcx, Prov: Provenance, Extra> {
alloc: &'a mut Allocation<Prov, Extra>, alloc: &'a mut Allocation<Prov, Extra>,
range: AllocRange, range: AllocRange,
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,

View file

@ -36,7 +36,7 @@ pub use init_mask::{InitChunk, InitChunkIter};
// hashed. (see the `Hash` impl below for more details), so the impl is not derived. // hashed. (see the `Hash` impl below for more details), so the impl is not derived.
#[derive(Clone, Eq, PartialEq, PartialOrd, Ord, TyEncodable, TyDecodable)] #[derive(Clone, Eq, PartialEq, PartialOrd, Ord, TyEncodable, TyDecodable)]
#[derive(HashStable)] #[derive(HashStable)]
pub struct Allocation<Prov = AllocId, Extra = ()> { pub struct Allocation<Prov: Provenance = AllocId, Extra = ()> {
/// The actual bytes of the allocation. /// The actual bytes of the allocation.
/// Note that the bytes of a pointer represent the offset of the pointer. /// Note that the bytes of a pointer represent the offset of the pointer.
bytes: Box<[u8]>, bytes: Box<[u8]>,
@ -108,9 +108,7 @@ impl hash::Hash for Allocation {
/// (`ConstAllocation`) are used quite a bit. /// (`ConstAllocation`) are used quite a bit.
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, HashStable)] #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, HashStable)]
#[rustc_pass_by_value] #[rustc_pass_by_value]
pub struct ConstAllocation<'tcx, Prov = AllocId, Extra = ()>( pub struct ConstAllocation<'tcx>(pub Interned<'tcx, Allocation>);
pub Interned<'tcx, Allocation<Prov, Extra>>,
);
impl<'tcx> fmt::Debug for ConstAllocation<'tcx> { impl<'tcx> fmt::Debug for ConstAllocation<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@ -120,8 +118,8 @@ impl<'tcx> fmt::Debug for ConstAllocation<'tcx> {
} }
} }
impl<'tcx, Prov, Extra> ConstAllocation<'tcx, Prov, Extra> { impl<'tcx> ConstAllocation<'tcx> {
pub fn inner(self) -> &'tcx Allocation<Prov, Extra> { pub fn inner(self) -> &'tcx Allocation {
self.0.0 self.0.0
} }
} }
@ -220,7 +218,7 @@ impl AllocRange {
} }
// The constructors are all without extra; the extra gets added by a machine hook later. // The constructors are all without extra; the extra gets added by a machine hook later.
impl<Prov> Allocation<Prov> { impl<Prov: Provenance> Allocation<Prov> {
/// Creates an allocation initialized by the given bytes /// Creates an allocation initialized by the given bytes
pub fn from_bytes<'a>( pub fn from_bytes<'a>(
slice: impl Into<Cow<'a, [u8]>>, slice: impl Into<Cow<'a, [u8]>>,
@ -278,7 +276,7 @@ impl<Prov> Allocation<Prov> {
impl Allocation { impl Allocation {
/// Adjust allocation from the ones in tcx to a custom Machine instance /// Adjust allocation from the ones in tcx to a custom Machine instance
/// with a different Provenance and Extra type. /// with a different Provenance and Extra type.
pub fn adjust_from_tcx<Prov, Extra, Err>( pub fn adjust_from_tcx<Prov: Provenance, Extra, Err>(
self, self,
cx: &impl HasDataLayout, cx: &impl HasDataLayout,
extra: Extra, extra: Extra,
@ -311,7 +309,7 @@ impl Allocation {
} }
/// Raw accessors. Provide access to otherwise private bytes. /// Raw accessors. Provide access to otherwise private bytes.
impl<Prov, Extra> Allocation<Prov, Extra> { impl<Prov: Provenance, Extra> Allocation<Prov, Extra> {
pub fn len(&self) -> usize { pub fn len(&self) -> usize {
self.bytes.len() self.bytes.len()
} }

View file

@ -22,15 +22,17 @@ pub struct ProvenanceMap<Prov = AllocId> {
bytes: Option<Box<SortedMap<Size, Prov>>>, bytes: Option<Box<SortedMap<Size, Prov>>>,
} }
impl<D: Decoder, Prov: Decodable<D>> Decodable<D> for ProvenanceMap<Prov> { impl<D: Decoder, Prov: Provenance + Decodable<D>> Decodable<D> for ProvenanceMap<Prov> {
fn decode(d: &mut D) -> Self { fn decode(d: &mut D) -> Self {
assert!(!Prov::OFFSET_IS_ADDR); // only `AllocId` is ever serialized
Self { ptrs: Decodable::decode(d), bytes: None } Self { ptrs: Decodable::decode(d), bytes: None }
} }
} }
impl<S: Encoder, Prov: Encodable<S>> Encodable<S> for ProvenanceMap<Prov> { impl<S: Encoder, Prov: Provenance + Encodable<S>> Encodable<S> for ProvenanceMap<Prov> {
fn encode(&self, s: &mut S) { fn encode(&self, s: &mut S) {
let Self { ptrs, bytes } = self; let Self { ptrs, bytes } = self;
assert!(!Prov::OFFSET_IS_ADDR); // only `AllocId` is ever serialized
debug_assert!(bytes.is_none()); debug_assert!(bytes.is_none());
ptrs.encode(s) ptrs.encode(s)
} }

View file

@ -788,7 +788,7 @@ pub fn write_allocations<'tcx>(
/// After the hex dump, an ascii dump follows, replacing all unprintable characters (control /// After the hex dump, an ascii dump follows, replacing all unprintable characters (control
/// characters or characters whose value is larger than 127) with a `.` /// characters or characters whose value is larger than 127) with a `.`
/// This also prints provenance adequately. /// This also prints provenance adequately.
pub fn display_allocation<'a, 'tcx, Prov, Extra>( pub fn display_allocation<'a, 'tcx, Prov: Provenance, Extra>(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
alloc: &'a Allocation<Prov, Extra>, alloc: &'a Allocation<Prov, Extra>,
) -> RenderAllocation<'a, 'tcx, Prov, Extra> { ) -> RenderAllocation<'a, 'tcx, Prov, Extra> {
@ -796,7 +796,7 @@ pub fn display_allocation<'a, 'tcx, Prov, Extra>(
} }
#[doc(hidden)] #[doc(hidden)]
pub struct RenderAllocation<'a, 'tcx, Prov, Extra> { pub struct RenderAllocation<'a, 'tcx, Prov: Provenance, Extra> {
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
alloc: &'a Allocation<Prov, Extra>, alloc: &'a Allocation<Prov, Extra>,
} }

View file

@ -266,7 +266,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine<'mir, 'tcx>
_tcx: TyCtxt<'tcx>, _tcx: TyCtxt<'tcx>,
_machine: &Self, _machine: &Self,
_alloc_id: AllocId, _alloc_id: AllocId,
alloc: ConstAllocation<'tcx, Self::Provenance, Self::AllocExtra>, alloc: ConstAllocation<'tcx>,
_static_def_id: Option<DefId>, _static_def_id: Option<DefId>,
is_write: bool, is_write: bool,
) -> InterpResult<'tcx> { ) -> InterpResult<'tcx> {