Skip to content

Commit cf4da24

Browse files
committed
implement RustcDecodable for NeoPlace
1 parent c278ff9 commit cf4da24

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/librustc/mir/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1907,14 +1907,13 @@ pub enum Place<'tcx> {
19071907
}
19081908

19091909
/// A new Place repr
1910-
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
1910+
#[derive(Clone, Debug, PartialEq, Eq, Hash, RustcEncodable)]
19111911
pub struct NeoPlace<'tcx> {
19121912
pub base: PlaceBase<'tcx>,
19131913
pub elems: &'tcx [PlaceElem<'tcx>],
19141914
}
19151915

1916-
// FIXME
1917-
// impl<'tcx> serialize::UseSpecializedDecodable for &'tcx List<PlaceElem<'tcx>> {}
1916+
impl serialize::UseSpecializedDecodable for NeoPlace<'tcx> {}
19181917

19191918
impl NeoPlace<'tcx> {
19201919
/// Return `Some` if this place has no projections -- else return `None`.

src/librustc/ty/codec.rs

+24
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use std::hash::Hash;
1414
use std::intrinsics;
1515
use ty::{self, Ty, TyCtxt};
1616
use ty::subst::Substs;
17+
use mir;
1718
use mir::interpret::Allocation;
1819

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

268+
#[inline]
269+
pub fn decode_neo_place<'a, 'tcx, D>(decoder: &mut D)
270+
-> Result<mir::NeoPlace<'tcx>, D::Error>
271+
where D: TyDecoder<'a, 'tcx>,
272+
'tcx: 'a,
273+
{
274+
let base: mir::PlaceBase<'tcx> = Decodable::decode(decoder)?;
275+
let len = decoder.read_usize()?;
276+
let interned: Vec<mir::PlaceElem<'tcx>> = (0..len).map(|_| Decodable::decode(decoder))
277+
.collect::<Result<_, _>>()?;
278+
let elems: &'tcx [mir::PlaceElem<'tcx>] = decoder.tcx().mk_place_elems(interned.into_iter());
279+
Ok(mir::NeoPlace { base, elems })
280+
}
281+
267282
#[macro_export]
268283
macro_rules! __impl_decoder_methods {
269284
($($name:ident -> $ty:ty;)*) => {
@@ -404,6 +419,15 @@ macro_rules! implement_ty_decoder {
404419
decode_allocation(self)
405420
}
406421
}
422+
423+
impl<$($typaram),*> SpecializedDecoder<$crate::mir::NeoPlace<'tcx>>
424+
for $DecoderName<$($typaram),*> {
425+
fn specialized_decode(
426+
&mut self
427+
) -> Result<$crate::mir::NeoPlace<'tcx>, Self::Error> {
428+
decode_neo_place(self)
429+
}
430+
}
407431
}
408432
}
409433
}

0 commit comments

Comments
 (0)