3333
3434use infer:: { InferCtxt , InferOk , InferResult , RegionVariableOrigin , TypeVariableOrigin } ;
3535use rustc_data_structures:: indexed_vec:: Idx ;
36+ use serialize:: UseSpecializedDecodable ;
3637use std:: fmt:: Debug ;
3738use std:: ops:: Index ;
3839use syntax:: codemap:: Span ;
@@ -49,14 +50,16 @@ use rustc_data_structures::fx::FxHashMap;
4950/// A "canonicalized" type `V` is one where all free inference
5051/// variables have been rewriten to "canonical vars". These are
5152/// numbered starting from 0 in order of first appearance.
52- #[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash ) ]
53+ #[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash , RustcDecodable , RustcEncodable ) ]
5354pub struct Canonical < ' gcx , V > {
5455 pub variables : CanonicalVarInfos < ' gcx > ,
5556 pub value : V ,
5657}
5758
5859pub type CanonicalVarInfos < ' gcx > = & ' gcx Slice < CanonicalVarInfo > ;
5960
61+ impl < ' gcx > UseSpecializedDecodable for CanonicalVarInfos < ' gcx > { }
62+
6063/// A set of values corresponding to the canonical variables from some
6164/// `Canonical`. You can give these values to
6265/// `canonical_value.substitute` to substitute them into the canonical
@@ -69,7 +72,7 @@ pub type CanonicalVarInfos<'gcx> = &'gcx Slice<CanonicalVarInfo>;
6972/// You can also use `infcx.fresh_inference_vars_for_canonical_vars`
7073/// to get back a `CanonicalVarValues` containing fresh inference
7174/// variables.
72- #[ derive( Clone , Debug , PartialEq , Eq , Hash ) ]
75+ #[ derive( Clone , Debug , PartialEq , Eq , Hash , RustcDecodable , RustcEncodable ) ]
7376pub struct CanonicalVarValues < ' tcx > {
7477 pub var_values : IndexVec < CanonicalVar , Kind < ' tcx > > ,
7578}
@@ -78,15 +81,15 @@ pub struct CanonicalVarValues<'tcx> {
7881/// canonical value. This is sufficient information for code to create
7982/// a copy of the canonical value in some other inference context,
8083/// with fresh inference variables replacing the canonical values.
81- #[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash ) ]
84+ #[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash , RustcDecodable , RustcEncodable ) ]
8285pub struct CanonicalVarInfo {
8386 pub kind : CanonicalVarKind ,
8487}
8588
8689/// Describes the "kind" of the canonical variable. This is a "kind"
8790/// in the type-theory sense of the term -- i.e., a "meta" type system
8891/// that analyzes type-like values.
89- #[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash ) ]
92+ #[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash , RustcDecodable , RustcEncodable ) ]
9093pub enum CanonicalVarKind {
9194 /// Some kind of type inference variable.
9295 Ty ( CanonicalTyVarKind ) ,
@@ -100,7 +103,7 @@ pub enum CanonicalVarKind {
100103/// 22.) can only be instantiated with integral/float types (e.g.,
101104/// usize or f32). In order to faithfully reproduce a type, we need to
102105/// know what set of types a given type variable can be unified with.
103- #[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash ) ]
106+ #[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash , RustcDecodable , RustcEncodable ) ]
104107pub enum CanonicalTyVarKind {
105108 /// General type variable `?T` that can be unified with arbitrary types.
106109 General ,
@@ -855,11 +858,14 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for CanonicalVarValuesSubst<'cx, 'g
855858}
856859
857860CloneTypeFoldableAndLiftImpls ! {
861+ :: infer:: canonical:: Certainty ,
862+ :: infer:: canonical:: CanonicalVarInfo ,
863+ :: infer:: canonical:: CanonicalVarKind ,
864+ }
865+
866+ CloneTypeFoldableImpls ! {
858867 for <' tcx> {
859- :: infer:: canonical:: Certainty ,
860- :: infer:: canonical:: CanonicalVarInfo ,
861868 :: infer:: canonical:: CanonicalVarInfos <' tcx>,
862- :: infer:: canonical:: CanonicalVarKind ,
863869 }
864870}
865871
@@ -870,6 +876,13 @@ BraceStructTypeFoldableImpl! {
870876 } where C : TypeFoldable <' tcx>
871877}
872878
879+ BraceStructLiftImpl ! {
880+ impl <' a, ' tcx, T > Lift <' tcx> for Canonical <' a, T > {
881+ type Lifted = Canonical <' tcx, T :: Lifted >;
882+ variables, value
883+ } where T : Lift <' tcx>
884+ }
885+
873886impl < ' tcx > CanonicalVarValues < ' tcx > {
874887 fn iter < ' a > ( & ' a self ) -> impl Iterator < Item = Kind < ' tcx > > + ' a {
875888 self . var_values . iter ( ) . cloned ( )
0 commit comments