Skip to content

Commit

Permalink
implement RustcDecodable for NeoPlace
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed Jan 30, 2019
1 parent c278ff9 commit cf4da24
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1907,14 +1907,13 @@ pub enum Place<'tcx> {
}

/// A new Place repr
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[derive(Clone, Debug, PartialEq, Eq, Hash, RustcEncodable)]
pub struct NeoPlace<'tcx> {
pub base: PlaceBase<'tcx>,
pub elems: &'tcx [PlaceElem<'tcx>],
}

// FIXME
// impl<'tcx> serialize::UseSpecializedDecodable for &'tcx List<PlaceElem<'tcx>> {}
impl serialize::UseSpecializedDecodable for NeoPlace<'tcx> {}

impl NeoPlace<'tcx> {
/// Return `Some` if this place has no projections -- else return `None`.
Expand Down
24 changes: 24 additions & 0 deletions src/librustc/ty/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use std::hash::Hash;
use std::intrinsics;
use ty::{self, Ty, TyCtxt};
use ty::subst::Substs;
use mir;
use mir::interpret::Allocation;

/// The shorthand encoding uses an enum's variant index `usize`
Expand Down Expand Up @@ -264,6 +265,20 @@ pub fn decode_allocation<'a, 'tcx, D>(decoder: &mut D)
Ok(decoder.tcx().intern_const_alloc(Decodable::decode(decoder)?))
}

#[inline]
pub fn decode_neo_place<'a, 'tcx, D>(decoder: &mut D)
-> Result<mir::NeoPlace<'tcx>, D::Error>
where D: TyDecoder<'a, 'tcx>,
'tcx: 'a,
{
let base: mir::PlaceBase<'tcx> = Decodable::decode(decoder)?;
let len = decoder.read_usize()?;
let interned: Vec<mir::PlaceElem<'tcx>> = (0..len).map(|_| Decodable::decode(decoder))
.collect::<Result<_, _>>()?;
let elems: &'tcx [mir::PlaceElem<'tcx>] = decoder.tcx().mk_place_elems(interned.into_iter());
Ok(mir::NeoPlace { base, elems })
}

#[macro_export]
macro_rules! __impl_decoder_methods {
($($name:ident -> $ty:ty;)*) => {
Expand Down Expand Up @@ -404,6 +419,15 @@ macro_rules! implement_ty_decoder {
decode_allocation(self)
}
}

impl<$($typaram),*> SpecializedDecoder<$crate::mir::NeoPlace<'tcx>>
for $DecoderName<$($typaram),*> {
fn specialized_decode(
&mut self
) -> Result<$crate::mir::NeoPlace<'tcx>, Self::Error> {
decode_neo_place(self)
}
}
}
}
}

0 comments on commit cf4da24

Please sign in to comment.