@@ -19,26 +19,26 @@ pub trait Value<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>>: Copy
19
19
// Get this value's layout.
20
20
fn layout ( & self ) -> TyLayout < ' tcx > ;
21
21
22
- // Make this a `MPlaceTy`, or panic if that's not possible .
23
- fn to_mem_place (
22
+ // Make this into an `OpTy` .
23
+ fn to_op (
24
24
self ,
25
- ectx : & EvalContext < ' a , ' mir , ' tcx , M > ,
26
- ) -> EvalResult < ' tcx , MPlaceTy < ' tcx , M :: PointerTag > > ;
25
+ ecx : & EvalContext < ' a , ' mir , ' tcx , M > ,
26
+ ) -> EvalResult < ' tcx , OpTy < ' tcx , M :: PointerTag > > ;
27
27
28
28
// Create this from an `MPlaceTy`.
29
29
fn from_mem_place ( MPlaceTy < ' tcx , M :: PointerTag > ) -> Self ;
30
30
31
- // Read the current enum discriminant, and downcast to that. Also return the
32
- // variant index.
31
+ // Project to the given enum variant.
33
32
fn project_downcast (
34
33
self ,
35
- ectx : & EvalContext < ' a , ' mir , ' tcx , M >
36
- ) -> EvalResult < ' tcx , ( Self , usize ) > ;
34
+ ecx : & EvalContext < ' a , ' mir , ' tcx , M > ,
35
+ variant : usize ,
36
+ ) -> EvalResult < ' tcx , Self > ;
37
37
38
38
// Project to the n-th field.
39
39
fn project_field (
40
40
self ,
41
- ectx : & mut EvalContext < ' a , ' mir , ' tcx , M > ,
41
+ ecx : & mut EvalContext < ' a , ' mir , ' tcx , M > ,
42
42
field : u64 ,
43
43
) -> EvalResult < ' tcx , Self > ;
44
44
}
@@ -53,11 +53,11 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Value<'a, 'mir, 'tcx, M>
53
53
}
54
54
55
55
#[ inline( always) ]
56
- fn to_mem_place (
56
+ fn to_op (
57
57
self ,
58
- _ectx : & EvalContext < ' a , ' mir , ' tcx , M > ,
59
- ) -> EvalResult < ' tcx , MPlaceTy < ' tcx , M :: PointerTag > > {
60
- Ok ( self . to_mem_place ( ) )
58
+ _ecx : & EvalContext < ' a , ' mir , ' tcx , M > ,
59
+ ) -> EvalResult < ' tcx , OpTy < ' tcx , M :: PointerTag > > {
60
+ Ok ( self )
61
61
}
62
62
63
63
#[ inline( always) ]
@@ -68,19 +68,19 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Value<'a, 'mir, 'tcx, M>
68
68
#[ inline( always) ]
69
69
fn project_downcast (
70
70
self ,
71
- ectx : & EvalContext < ' a , ' mir , ' tcx , M >
72
- ) -> EvalResult < ' tcx , ( Self , usize ) > {
73
- let idx = ectx . read_discriminant ( self ) ? . 1 ;
74
- Ok ( ( ectx . operand_downcast ( self , idx ) ? , idx ) )
71
+ ecx : & EvalContext < ' a , ' mir , ' tcx , M > ,
72
+ variant : usize ,
73
+ ) -> EvalResult < ' tcx , Self > {
74
+ ecx . operand_downcast ( self , variant )
75
75
}
76
76
77
77
#[ inline( always) ]
78
78
fn project_field (
79
79
self ,
80
- ectx : & mut EvalContext < ' a , ' mir , ' tcx , M > ,
80
+ ecx : & mut EvalContext < ' a , ' mir , ' tcx , M > ,
81
81
field : u64 ,
82
82
) -> EvalResult < ' tcx , Self > {
83
- ectx . operand_field ( self , field)
83
+ ecx . operand_field ( self , field)
84
84
}
85
85
}
86
86
impl < ' a , ' mir , ' tcx , M : Machine < ' a , ' mir , ' tcx > > Value < ' a , ' mir , ' tcx , M >
@@ -92,11 +92,11 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Value<'a, 'mir, 'tcx, M>
92
92
}
93
93
94
94
#[ inline( always) ]
95
- fn to_mem_place (
95
+ fn to_op (
96
96
self ,
97
- _ectx : & EvalContext < ' a , ' mir , ' tcx , M > ,
98
- ) -> EvalResult < ' tcx , MPlaceTy < ' tcx , M :: PointerTag > > {
99
- Ok ( self )
97
+ _ecx : & EvalContext < ' a , ' mir , ' tcx , M > ,
98
+ ) -> EvalResult < ' tcx , OpTy < ' tcx , M :: PointerTag > > {
99
+ Ok ( self . into ( ) )
100
100
}
101
101
102
102
#[ inline( always) ]
@@ -107,19 +107,19 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Value<'a, 'mir, 'tcx, M>
107
107
#[ inline( always) ]
108
108
fn project_downcast (
109
109
self ,
110
- ectx : & EvalContext < ' a , ' mir , ' tcx , M >
111
- ) -> EvalResult < ' tcx , ( Self , usize ) > {
112
- let idx = ectx . read_discriminant ( self . into ( ) ) ? . 1 ;
113
- Ok ( ( ectx . mplace_downcast ( self , idx ) ? , idx ) )
110
+ ecx : & EvalContext < ' a , ' mir , ' tcx , M > ,
111
+ variant : usize ,
112
+ ) -> EvalResult < ' tcx , Self > {
113
+ ecx . mplace_downcast ( self , variant )
114
114
}
115
115
116
116
#[ inline( always) ]
117
117
fn project_field (
118
118
self ,
119
- ectx : & mut EvalContext < ' a , ' mir , ' tcx , M > ,
119
+ ecx : & mut EvalContext < ' a , ' mir , ' tcx , M > ,
120
120
field : u64 ,
121
121
) -> EvalResult < ' tcx , Self > {
122
- ectx . mplace_field ( self , field)
122
+ ecx . mplace_field ( self , field)
123
123
}
124
124
}
125
125
impl < ' a , ' mir , ' tcx , M : Machine < ' a , ' mir , ' tcx > > Value < ' a , ' mir , ' tcx , M >
@@ -131,12 +131,11 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Value<'a, 'mir, 'tcx, M>
131
131
}
132
132
133
133
#[ inline( always) ]
134
- fn to_mem_place (
134
+ fn to_op (
135
135
self ,
136
- ectx : & EvalContext < ' a , ' mir , ' tcx , M > ,
137
- ) -> EvalResult < ' tcx , MPlaceTy < ' tcx , M :: PointerTag > > {
138
- // If this refers to a local, assert that it already has an allocation.
139
- Ok ( ectx. place_to_op ( self ) ?. to_mem_place ( ) )
136
+ ecx : & EvalContext < ' a , ' mir , ' tcx , M > ,
137
+ ) -> EvalResult < ' tcx , OpTy < ' tcx , M :: PointerTag > > {
138
+ ecx. place_to_op ( self )
140
139
}
141
140
142
141
#[ inline( always) ]
@@ -147,19 +146,19 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Value<'a, 'mir, 'tcx, M>
147
146
#[ inline( always) ]
148
147
fn project_downcast (
149
148
self ,
150
- ectx : & EvalContext < ' a , ' mir , ' tcx , M >
151
- ) -> EvalResult < ' tcx , ( Self , usize ) > {
152
- let idx = ectx . read_discriminant ( ectx . place_to_op ( self ) ? ) ? . 1 ;
153
- Ok ( ( ectx . place_downcast ( self , idx ) ? , idx ) )
149
+ ecx : & EvalContext < ' a , ' mir , ' tcx , M > ,
150
+ variant : usize ,
151
+ ) -> EvalResult < ' tcx , Self > {
152
+ ecx . place_downcast ( self , variant )
154
153
}
155
154
156
155
#[ inline( always) ]
157
156
fn project_field (
158
157
self ,
159
- ectx : & mut EvalContext < ' a , ' mir , ' tcx , M > ,
158
+ ecx : & mut EvalContext < ' a , ' mir , ' tcx , M > ,
160
159
field : u64 ,
161
160
) -> EvalResult < ' tcx , Self > {
162
- ectx . place_field ( self , field)
161
+ ecx . place_field ( self , field)
163
162
}
164
163
}
165
164
@@ -228,7 +227,7 @@ pub trait ValueVisitor<'a, 'mir, 'tcx: 'mir+'a, M: Machine<'a, 'mir, 'tcx>>: Siz
228
227
MPlaceTy :: dangling ( v. layout ( ) , & self . ecx ( ) )
229
228
} else {
230
229
// non-ZST array/slice/str cannot be immediate
231
- v. to_mem_place ( self . ecx ( ) ) ?
230
+ v. to_op ( self . ecx ( ) ) ?. to_mem_place ( )
232
231
} ;
233
232
// Now iterate over it.
234
233
for ( i, field) in self . ecx ( ) . mplace_array_fields ( mplace) ?. enumerate ( ) {
@@ -243,8 +242,10 @@ pub trait ValueVisitor<'a, 'mir, 'tcx: 'mir+'a, M: Machine<'a, 'mir, 'tcx>>: Siz
243
242
match v. layout ( ) . variants {
244
243
layout:: Variants :: NicheFilling { .. } |
245
244
layout:: Variants :: Tagged { .. } => {
246
- let ( inner, idx) = v. project_downcast ( self . ecx ( ) ) ?;
247
- trace ! ( "variant layout: {:#?}" , inner. layout( ) ) ;
245
+ let op = v. to_op ( self . ecx ( ) ) ?;
246
+ let idx = self . ecx ( ) . read_discriminant ( op) ?. 1 ;
247
+ let inner = v. project_downcast ( self . ecx ( ) , idx) ?;
248
+ trace ! ( "walk_value: variant layout: {:#?}" , inner. layout( ) ) ;
248
249
// recurse with the inner type
249
250
return self . visit_field ( v, idx, inner) ;
250
251
}
@@ -256,9 +257,9 @@ pub trait ValueVisitor<'a, 'mir, 'tcx: 'mir+'a, M: Machine<'a, 'mir, 'tcx>>: Siz
256
257
match v. layout ( ) . ty . sty {
257
258
ty:: Dynamic ( ..) => {
258
259
// immediate trait objects are not a thing
259
- let dest = v. to_mem_place ( self . ecx ( ) ) ?;
260
+ let dest = v. to_op ( self . ecx ( ) ) ?. to_mem_place ( ) ;
260
261
let inner = self . ecx ( ) . unpack_dyn_trait ( dest) ?. 1 ;
261
- trace ! ( "dyn object layout: {:#?}" , inner. layout) ;
262
+ trace ! ( "walk_value: dyn object layout: {:#?}" , inner. layout) ;
262
263
// recurse with the inner type
263
264
return self . visit_field ( v, 0 , Value :: from_mem_place ( inner) ) ;
264
265
} ,
0 commit comments