33
33
34
34
use infer:: { InferCtxt , InferOk , InferResult , RegionVariableOrigin , TypeVariableOrigin } ;
35
35
use rustc_data_structures:: indexed_vec:: Idx ;
36
+ use serialize:: UseSpecializedDecodable ;
36
37
use std:: fmt:: Debug ;
37
38
use std:: ops:: Index ;
38
39
use syntax:: codemap:: Span ;
@@ -49,14 +50,16 @@ use rustc_data_structures::fx::FxHashMap;
49
50
/// A "canonicalized" type `V` is one where all free inference
50
51
/// variables have been rewriten to "canonical vars". These are
51
52
/// 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 ) ]
53
54
pub struct Canonical < ' gcx , V > {
54
55
pub variables : CanonicalVarInfos < ' gcx > ,
55
56
pub value : V ,
56
57
}
57
58
58
59
pub type CanonicalVarInfos < ' gcx > = & ' gcx Slice < CanonicalVarInfo > ;
59
60
61
+ impl < ' gcx > UseSpecializedDecodable for CanonicalVarInfos < ' gcx > { }
62
+
60
63
/// A set of values corresponding to the canonical variables from some
61
64
/// `Canonical`. You can give these values to
62
65
/// `canonical_value.substitute` to substitute them into the canonical
@@ -69,7 +72,7 @@ pub type CanonicalVarInfos<'gcx> = &'gcx Slice<CanonicalVarInfo>;
69
72
/// You can also use `infcx.fresh_inference_vars_for_canonical_vars`
70
73
/// to get back a `CanonicalVarValues` containing fresh inference
71
74
/// variables.
72
- #[ derive( Clone , Debug , PartialEq , Eq , Hash ) ]
75
+ #[ derive( Clone , Debug , PartialEq , Eq , Hash , RustcDecodable , RustcEncodable ) ]
73
76
pub struct CanonicalVarValues < ' tcx > {
74
77
pub var_values : IndexVec < CanonicalVar , Kind < ' tcx > > ,
75
78
}
@@ -78,15 +81,15 @@ pub struct CanonicalVarValues<'tcx> {
78
81
/// canonical value. This is sufficient information for code to create
79
82
/// a copy of the canonical value in some other inference context,
80
83
/// 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 ) ]
82
85
pub struct CanonicalVarInfo {
83
86
pub kind : CanonicalVarKind ,
84
87
}
85
88
86
89
/// Describes the "kind" of the canonical variable. This is a "kind"
87
90
/// in the type-theory sense of the term -- i.e., a "meta" type system
88
91
/// that analyzes type-like values.
89
- #[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash ) ]
92
+ #[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash , RustcDecodable , RustcEncodable ) ]
90
93
pub enum CanonicalVarKind {
91
94
/// Some kind of type inference variable.
92
95
Ty ( CanonicalTyVarKind ) ,
@@ -100,7 +103,7 @@ pub enum CanonicalVarKind {
100
103
/// 22.) can only be instantiated with integral/float types (e.g.,
101
104
/// usize or f32). In order to faithfully reproduce a type, we need to
102
105
/// 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 ) ]
104
107
pub enum CanonicalTyVarKind {
105
108
/// General type variable `?T` that can be unified with arbitrary types.
106
109
General ,
@@ -855,11 +858,14 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for CanonicalVarValuesSubst<'cx, 'g
855
858
}
856
859
857
860
CloneTypeFoldableAndLiftImpls ! {
861
+ :: infer:: canonical:: Certainty ,
862
+ :: infer:: canonical:: CanonicalVarInfo ,
863
+ :: infer:: canonical:: CanonicalVarKind ,
864
+ }
865
+
866
+ CloneTypeFoldableImpls ! {
858
867
for <' tcx> {
859
- :: infer:: canonical:: Certainty ,
860
- :: infer:: canonical:: CanonicalVarInfo ,
861
868
:: infer:: canonical:: CanonicalVarInfos <' tcx>,
862
- :: infer:: canonical:: CanonicalVarKind ,
863
869
}
864
870
}
865
871
@@ -870,6 +876,13 @@ BraceStructTypeFoldableImpl! {
870
876
} where C : TypeFoldable <' tcx>
871
877
}
872
878
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
+
873
886
impl < ' tcx > CanonicalVarValues < ' tcx > {
874
887
fn iter < ' a > ( & ' a self ) -> impl Iterator < Item = Kind < ' tcx > > + ' a {
875
888
self . var_values . iter ( ) . cloned ( )
0 commit comments