1
1
use ena:: unify:: { UnifyKey , UnifyValue } ;
2
2
use ir:: * ;
3
3
use std:: cmp:: min;
4
- use std:: fmt;
4
+ use std:: fmt:: { self , Debug } ;
5
5
use std:: u32;
6
6
7
7
#[ derive( Copy , Clone , PartialEq , Eq , Hash ) ]
@@ -25,7 +25,7 @@ impl TyInferenceVariable {
25
25
}
26
26
27
27
impl UnifyKey for TyInferenceVariable {
28
- type Value = InferenceValue ;
28
+ type Value = InferenceValue < Ty > ;
29
29
30
30
fn index ( & self ) -> u32 {
31
31
self . index
@@ -61,7 +61,7 @@ impl KrateInferenceVariable {
61
61
}
62
62
63
63
impl UnifyKey for KrateInferenceVariable {
64
- type Value = InferenceValue ;
64
+ type Value = InferenceValue < Krate > ;
65
65
66
66
fn index ( & self ) -> u32 {
67
67
self . index
@@ -80,29 +80,25 @@ impl UnifyKey for KrateInferenceVariable {
80
80
/// a universe index; when the inference variable is assigned a value,
81
81
/// it becomes bound and refers to an entry in the
82
82
/// `InferenceTable.value` vector.
83
- #[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
84
- pub enum InferenceValue {
83
+ #[ derive( Clone , Debug , PartialEq , Eq ) ]
84
+ pub enum InferenceValue < V : Clone + Debug > {
85
85
Unbound ( UniverseIndex ) ,
86
- Bound ( ValueIndex ) ,
86
+ Bound ( V ) ,
87
87
}
88
88
89
- impl UnifyValue for InferenceValue {
90
- fn unify_values ( a : & InferenceValue , b : & InferenceValue )
91
- -> Result < InferenceValue , ( InferenceValue , InferenceValue ) > {
92
- match ( * a, * b) {
93
- ( InferenceValue :: Unbound ( ui_a) , InferenceValue :: Unbound ( ui_b) ) => {
89
+ impl < V : Clone + Debug > UnifyValue for InferenceValue < V > {
90
+ fn unify_values ( a : & InferenceValue < V > , b : & InferenceValue < V > )
91
+ -> Result < InferenceValue < V > , ( InferenceValue < V > , InferenceValue < V > ) > {
92
+ match ( a, b) {
93
+ ( & InferenceValue :: Unbound ( ui_a) , & InferenceValue :: Unbound ( ui_b) ) => {
94
94
Ok ( InferenceValue :: Unbound ( min ( ui_a, ui_b) ) )
95
95
}
96
- ( bound @ InferenceValue :: Bound ( _) , InferenceValue :: Unbound ( _) ) |
97
- ( InferenceValue :: Unbound ( _) , bound @ InferenceValue :: Bound ( _) ) => {
98
- Ok ( bound)
96
+ ( bound @ & InferenceValue :: Bound ( _) , & InferenceValue :: Unbound ( _) ) |
97
+ ( & InferenceValue :: Unbound ( _) , bound @ & InferenceValue :: Bound ( _) ) => {
98
+ Ok ( bound. clone ( ) )
99
99
}
100
- ( InferenceValue :: Bound ( _) , InferenceValue :: Bound ( _) ) => {
101
- // we don't even try to allow unifying things that are
102
- // already bound; that is handled at a higher-level by
103
- // the `InferenceTable`; this could probably just be a
104
- // `panic!` actually
105
- Err ( ( * a, * b) )
100
+ ( & InferenceValue :: Bound ( _) , & InferenceValue :: Bound ( _) ) => {
101
+ panic ! ( "we should not be asked to unify two bound things" )
106
102
}
107
103
}
108
104
}
@@ -120,19 +116,3 @@ impl fmt::Debug for KrateInferenceVariable {
120
116
}
121
117
}
122
118
123
- /// An index into the `InferenceTable.values` vector.
124
- #[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
125
- pub struct ValueIndex {
126
- index : u32
127
- }
128
-
129
- impl ValueIndex {
130
- pub fn new ( value : usize ) -> ValueIndex {
131
- ValueIndex { index : value as u32 }
132
- }
133
-
134
- pub fn as_usize ( & self ) -> usize {
135
- self . index as usize
136
- }
137
- }
138
-
0 commit comments