@@ -27,40 +27,30 @@ use super::{
27
27
/// operations and wide pointers. This idea was taken from rustc's codegen.
28
28
/// In particular, thanks to `ScalarPair`, arithmetic operations and casts can be entirely
29
29
/// defined on `Immediate`, and do not have to work with a `Place`.
30
- #[ derive( Copy , Clone , PartialEq , Eq , HashStable , Hash ) ]
31
- pub enum Immediate < Tag = AllocId > {
30
+ #[ derive( Copy , Clone , PartialEq , Eq , HashStable , Hash , Debug ) ]
31
+ pub enum Immediate < Tag : Provenance = AllocId > {
32
32
Scalar ( ScalarMaybeUninit < Tag > ) ,
33
33
ScalarPair ( ScalarMaybeUninit < Tag > , ScalarMaybeUninit < Tag > ) ,
34
34
}
35
35
36
36
#[ cfg( all( target_arch = "x86_64" , target_pointer_width = "64" ) ) ]
37
37
rustc_data_structures:: static_assert_size!( Immediate , 56 ) ;
38
38
39
- impl < Tag : Provenance > std:: fmt:: Debug for Immediate < Tag > {
40
- fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
41
- use Immediate :: * ;
42
- match self {
43
- Scalar ( s) => f. debug_tuple ( "Scalar" ) . field ( s) . finish ( ) ,
44
- ScalarPair ( s1, s2) => f. debug_tuple ( "ScalarPair" ) . field ( s1) . field ( s2) . finish ( ) ,
45
- }
46
- }
47
- }
48
-
49
- impl < Tag > From < ScalarMaybeUninit < Tag > > for Immediate < Tag > {
39
+ impl < Tag : Provenance > From < ScalarMaybeUninit < Tag > > for Immediate < Tag > {
50
40
#[ inline( always) ]
51
41
fn from ( val : ScalarMaybeUninit < Tag > ) -> Self {
52
42
Immediate :: Scalar ( val)
53
43
}
54
44
}
55
45
56
- impl < Tag > From < Scalar < Tag > > for Immediate < Tag > {
46
+ impl < Tag : Provenance > From < Scalar < Tag > > for Immediate < Tag > {
57
47
#[ inline( always) ]
58
48
fn from ( val : Scalar < Tag > ) -> Self {
59
49
Immediate :: Scalar ( val. into ( ) )
60
50
}
61
51
}
62
52
63
- impl < ' tcx , Tag > Immediate < Tag > {
53
+ impl < ' tcx , Tag : Provenance > Immediate < Tag > {
64
54
pub fn from_pointer ( p : Pointer < Tag > , cx : & impl HasDataLayout ) -> Self {
65
55
Immediate :: Scalar ( ScalarMaybeUninit :: from_pointer ( p, cx) )
66
56
}
@@ -93,22 +83,15 @@ impl<'tcx, Tag> Immediate<Tag> {
93
83
94
84
// ScalarPair needs a type to interpret, so we often have an immediate and a type together
95
85
// as input for binary and cast operations.
96
- #[ derive( Copy , Clone ) ]
97
- pub struct ImmTy < ' tcx , Tag = AllocId > {
86
+ #[ derive( Copy , Clone , Debug ) ]
87
+ pub struct ImmTy < ' tcx , Tag : Provenance = AllocId > {
98
88
imm : Immediate < Tag > ,
99
89
pub layout : TyAndLayout < ' tcx > ,
100
90
}
101
91
102
92
#[ cfg( all( target_arch = "x86_64" , target_pointer_width = "64" ) ) ]
103
93
rustc_data_structures:: static_assert_size!( ImmTy <' _>, 72 ) ;
104
94
105
- impl < ' tcx , Tag : Provenance > std:: fmt:: Debug for ImmTy < ' tcx , Tag > {
106
- fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
107
- let ImmTy { imm, layout } = self ;
108
- f. debug_struct ( "ImmTy" ) . field ( "imm" , imm) . field ( "layout" , layout) . finish ( )
109
- }
110
- }
111
-
112
95
impl < Tag : Provenance > std:: fmt:: Display for ImmTy < ' tcx , Tag > {
113
96
fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
114
97
/// Helper function for printing a scalar to a FmtPrinter
@@ -156,7 +139,7 @@ impl<Tag: Provenance> std::fmt::Display for ImmTy<'tcx, Tag> {
156
139
}
157
140
}
158
141
159
- impl < ' tcx , Tag > std:: ops:: Deref for ImmTy < ' tcx , Tag > {
142
+ impl < ' tcx , Tag : Provenance > std:: ops:: Deref for ImmTy < ' tcx , Tag > {
160
143
type Target = Immediate < Tag > ;
161
144
#[ inline( always) ]
162
145
fn deref ( & self ) -> & Immediate < Tag > {
@@ -167,68 +150,51 @@ impl<'tcx, Tag> std::ops::Deref for ImmTy<'tcx, Tag> {
167
150
/// An `Operand` is the result of computing a `mir::Operand`. It can be immediate,
168
151
/// or still in memory. The latter is an optimization, to delay reading that chunk of
169
152
/// memory and to avoid having to store arbitrary-sized data here.
170
- #[ derive( Copy , Clone , PartialEq , Eq , HashStable , Hash ) ]
171
- pub enum Operand < Tag = AllocId > {
153
+ #[ derive( Copy , Clone , PartialEq , Eq , HashStable , Hash , Debug ) ]
154
+ pub enum Operand < Tag : Provenance = AllocId > {
172
155
Immediate ( Immediate < Tag > ) ,
173
156
Indirect ( MemPlace < Tag > ) ,
174
157
}
175
158
176
- impl < Tag : Provenance > std:: fmt:: Debug for Operand < Tag > {
177
- fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
178
- use Operand :: * ;
179
- match self {
180
- Immediate ( i) => f. debug_tuple ( "Immediate" ) . field ( i) . finish ( ) ,
181
- Indirect ( p) => f. debug_tuple ( "Indirect" ) . field ( p) . finish ( ) ,
182
- }
183
- }
184
- }
185
-
186
- #[ derive( Copy , Clone , PartialEq , Eq , Hash ) ]
187
- pub struct OpTy < ' tcx , Tag = AllocId > {
159
+ #[ derive( Copy , Clone , PartialEq , Eq , Hash , Debug ) ]
160
+ pub struct OpTy < ' tcx , Tag : Provenance = AllocId > {
188
161
op : Operand < Tag > , // Keep this private; it helps enforce invariants.
189
162
pub layout : TyAndLayout < ' tcx > ,
190
163
}
191
164
192
165
#[ cfg( all( target_arch = "x86_64" , target_pointer_width = "64" ) ) ]
193
- rustc_data_structures:: static_assert_size!( OpTy <' _, ( ) >, 80 ) ;
194
-
195
- impl < ' tcx , Tag : Provenance > std:: fmt:: Debug for OpTy < ' tcx , Tag > {
196
- fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
197
- let OpTy { op, layout } = self ;
198
- f. debug_struct ( "OpTy" ) . field ( "op" , op) . field ( "layout" , layout) . finish ( )
199
- }
200
- }
166
+ rustc_data_structures:: static_assert_size!( OpTy <' _>, 80 ) ;
201
167
202
- impl < ' tcx , Tag > std:: ops:: Deref for OpTy < ' tcx , Tag > {
168
+ impl < ' tcx , Tag : Provenance > std:: ops:: Deref for OpTy < ' tcx , Tag > {
203
169
type Target = Operand < Tag > ;
204
170
#[ inline( always) ]
205
171
fn deref ( & self ) -> & Operand < Tag > {
206
172
& self . op
207
173
}
208
174
}
209
175
210
- impl < ' tcx , Tag : Copy > From < MPlaceTy < ' tcx , Tag > > for OpTy < ' tcx , Tag > {
176
+ impl < ' tcx , Tag : Provenance > From < MPlaceTy < ' tcx , Tag > > for OpTy < ' tcx , Tag > {
211
177
#[ inline( always) ]
212
178
fn from ( mplace : MPlaceTy < ' tcx , Tag > ) -> Self {
213
179
OpTy { op : Operand :: Indirect ( * mplace) , layout : mplace. layout }
214
180
}
215
181
}
216
182
217
- impl < ' tcx , Tag : Copy > From < & ' _ MPlaceTy < ' tcx , Tag > > for OpTy < ' tcx , Tag > {
183
+ impl < ' tcx , Tag : Provenance > From < & ' _ MPlaceTy < ' tcx , Tag > > for OpTy < ' tcx , Tag > {
218
184
#[ inline( always) ]
219
185
fn from ( mplace : & MPlaceTy < ' tcx , Tag > ) -> Self {
220
186
OpTy { op : Operand :: Indirect ( * * mplace) , layout : mplace. layout }
221
187
}
222
188
}
223
189
224
- impl < ' tcx , Tag > From < ImmTy < ' tcx , Tag > > for OpTy < ' tcx , Tag > {
190
+ impl < ' tcx , Tag : Provenance > From < ImmTy < ' tcx , Tag > > for OpTy < ' tcx , Tag > {
225
191
#[ inline( always) ]
226
192
fn from ( val : ImmTy < ' tcx , Tag > ) -> Self {
227
193
OpTy { op : Operand :: Immediate ( val. imm ) , layout : val. layout }
228
194
}
229
195
}
230
196
231
- impl < ' tcx , Tag : Copy > ImmTy < ' tcx , Tag > {
197
+ impl < ' tcx , Tag : Provenance > ImmTy < ' tcx , Tag > {
232
198
#[ inline]
233
199
pub fn from_scalar ( val : Scalar < Tag > , layout : TyAndLayout < ' tcx > ) -> Self {
234
200
ImmTy { imm : val. into ( ) , layout }
@@ -259,10 +225,7 @@ impl<'tcx, Tag: Copy> ImmTy<'tcx, Tag> {
259
225
}
260
226
261
227
#[ inline]
262
- pub fn to_const_int ( self ) -> ConstInt
263
- where
264
- Tag : Provenance ,
265
- {
228
+ pub fn to_const_int ( self ) -> ConstInt {
266
229
assert ! ( self . layout. ty. is_integral( ) ) ;
267
230
let int = self . to_scalar ( ) . expect ( "to_const_int doesn't work on scalar pairs" ) . assert_int ( ) ;
268
231
ConstInt :: new ( int, self . layout . ty . is_signed ( ) , self . layout . ty . is_ptr_sized_integral ( ) )
0 commit comments