rustc_metadata: side-step ty{en,de}code for everything but Ty.

This commit is contained in:
Eduard Burtescu 2016-09-02 00:49:29 +03:00
parent 0863012fb9
commit bcbb4107a1
7 changed files with 99 additions and 380 deletions

View file

@ -668,7 +668,7 @@ pub enum IntVarValue {
/// from `T:'a` annotations appearing in the type definition. If
/// this is `None`, then the default is inherited from the
/// surrounding context. See RFC #599 for details.
#[derive(Copy, Clone)]
#[derive(Copy, Clone, RustcEncodable, RustcDecodable)]
pub enum ObjectLifetimeDefault<'tcx> {
/// Require an explicit annotation. Occurs when multiple
/// `T:'a` constraints are found.
@ -681,7 +681,7 @@ pub enum ObjectLifetimeDefault<'tcx> {
Specific(&'tcx Region),
}
#[derive(Clone)]
#[derive(Clone, RustcEncodable, RustcDecodable)]
pub struct TypeParameterDef<'tcx> {
pub name: Name,
pub def_id: DefId,
@ -691,7 +691,7 @@ pub struct TypeParameterDef<'tcx> {
pub object_lifetime_default: ObjectLifetimeDefault<'tcx>,
}
#[derive(Clone)]
#[derive(Clone, RustcEncodable, RustcDecodable)]
pub struct RegionParameterDef<'tcx> {
pub name: Name,
pub def_id: DefId,
@ -719,7 +719,7 @@ impl<'tcx> RegionParameterDef<'tcx> {
/// Information about the formal type/lifetime parameters associated
/// with an item or method. Analogous to hir::Generics.
#[derive(Clone, Debug)]
#[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
pub struct Generics<'tcx> {
pub parent: Option<DefId>,
pub parent_regions: u32,
@ -786,7 +786,7 @@ impl<'a, 'gcx, 'tcx> GenericPredicates<'tcx> {
}
}
#[derive(Clone, PartialEq, Eq, Hash)]
#[derive(Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
pub enum Predicate<'tcx> {
/// Corresponds to `where Foo : Bar<A,B,C>`. `Foo` here would be
/// the `Self` type of the trait reference and `A`, `B`, and `C`
@ -910,7 +910,7 @@ impl<'a, 'gcx, 'tcx> Predicate<'tcx> {
}
}
#[derive(Clone, PartialEq, Eq, Hash)]
#[derive(Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
pub struct TraitPredicate<'tcx> {
pub trait_ref: TraitRef<'tcx>
}
@ -967,11 +967,11 @@ impl<'tcx> PolyTraitPredicate<'tcx> {
}
}
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
#[derive(Clone, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable)]
pub struct EquatePredicate<'tcx>(pub Ty<'tcx>, pub Ty<'tcx>); // `0 == 1`
pub type PolyEquatePredicate<'tcx> = ty::Binder<EquatePredicate<'tcx>>;
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
#[derive(Clone, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable)]
pub struct OutlivesPredicate<A,B>(pub A, pub B); // `A : B`
pub type PolyOutlivesPredicate<A,B> = ty::Binder<OutlivesPredicate<A,B>>;
pub type PolyRegionOutlivesPredicate<'tcx> = PolyOutlivesPredicate<&'tcx ty::Region,
@ -990,7 +990,7 @@ pub type PolyTypeOutlivesPredicate<'tcx> = PolyOutlivesPredicate<Ty<'tcx>, &'tcx
/// equality between arbitrary types. Processing an instance of Form
/// #2 eventually yields one of these `ProjectionPredicate`
/// instances to normalize the LHS.
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
#[derive(Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
pub struct ProjectionPredicate<'tcx> {
pub projection_ty: ProjectionTy<'tcx>,
pub ty: Ty<'tcx>,

View file

@ -290,7 +290,7 @@ pub struct TraitObject<'tcx> {
/// Note that a `TraitRef` introduces a level of region binding, to
/// account for higher-ranked trait bounds like `T : for<'a> Foo<&'a
/// U>` or higher-ranked object types.
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
#[derive(Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
pub struct TraitRef<'tcx> {
pub def_id: DefId,
pub substs: &'tcx Substs<'tcx>,
@ -366,7 +366,7 @@ impl<'tcx> PolyExistentialTraitRef<'tcx> {
/// erase, or otherwise "discharge" these bound regions, we change the
/// type from `Binder<T>` to just `T` (see
/// e.g. `liberate_late_bound_regions`).
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable)]
pub struct Binder<T>(pub T);
impl<T> Binder<T> {
@ -414,7 +414,7 @@ impl fmt::Debug for TypeFlags {
/// Represents the projection of an associated type. In explicit UFCS
/// form this would be written `<T as Trait<..>>::N`.
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable)]
pub struct ProjectionTy<'tcx> {
/// The trait reference `T as Trait<..>`.
pub trait_ref: ty::TraitRef<'tcx>,
@ -430,7 +430,7 @@ pub struct BareFnTy<'tcx> {
pub sig: PolyFnSig<'tcx>,
}
#[derive(Clone, PartialEq, Eq, Hash)]
#[derive(Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
pub struct ClosureTy<'tcx> {
pub unsafety: hir::Unsafety,
pub abi: abi::Abi,
@ -443,7 +443,7 @@ pub struct ClosureTy<'tcx> {
/// - `inputs` is the list of arguments and their modes.
/// - `output` is the return type.
/// - `variadic` indicates whether this is a variadic function. (only true for foreign fns)
#[derive(Clone, PartialEq, Eq, Hash)]
#[derive(Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
pub struct FnSig<'tcx> {
pub inputs: Vec<Ty<'tcx>>,
pub output: Ty<'tcx>,

View file

@ -14,7 +14,7 @@ use hir::def_id::DefId;
use ty::{self, Ty, TyCtxt};
use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
use serialize;
use serialize::{self, Encodable, Encoder, Decodable, Decoder};
use syntax_pos::{Span, DUMMY_SP};
use core::nonzero::NonZero;
@ -128,8 +128,40 @@ impl<'tcx> TypeFoldable<'tcx> for Kind<'tcx> {
}
}
impl<'tcx> Encodable for Kind<'tcx> {
fn encode<E: Encoder>(&self, e: &mut E) -> Result<(), E::Error> {
e.emit_enum("Kind", |e| {
if let Some(ty) = self.as_type() {
e.emit_enum_variant("Ty", TYPE_TAG, 1, |e| {
e.emit_enum_variant_arg(0, |e| ty.encode(e))
})
} else if let Some(r) = self.as_region() {
e.emit_enum_variant("Region", REGION_TAG, 1, |e| {
e.emit_enum_variant_arg(0, |e| r.encode(e))
})
} else {
bug!()
}
})
}
}
impl<'tcx> Decodable for Kind<'tcx> {
fn decode<D: Decoder>(d: &mut D) -> Result<Kind<'tcx>, D::Error> {
d.read_enum("Kind", |d| {
d.read_enum_variant(&["Ty", "Region"], |d, tag| {
match tag {
TYPE_TAG => Ty::decode(d).map(Kind::from),
REGION_TAG => <&ty::Region>::decode(d).map(Kind::from),
_ => Err(d.error("invalid Kind tag"))
}
})
})
}
}
/// A substitution mapping type/region parameters to new values.
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
#[derive(Clone, PartialEq, Eq, Debug, Hash, RustcEncodable, RustcDecodable)]
pub struct Substs<'tcx> {
params: Vec<Kind<'tcx>>
}
@ -297,7 +329,6 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx Substs<'tcx> {
}
}
impl<'tcx> serialize::UseSpecializedEncodable for &'tcx Substs<'tcx> {}
impl<'tcx> serialize::UseSpecializedDecodable for &'tcx Substs<'tcx> {}
///////////////////////////////////////////////////////////////////////////