@@ -19,26 +19,26 @@ pub trait Value<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>>: Copy
1919 // Get this value's layout.
2020 fn layout ( & self ) -> TyLayout < ' tcx > ;
2121
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 (
2424 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 > > ;
2727
2828 // Create this from an `MPlaceTy`.
2929 fn from_mem_place ( MPlaceTy < ' tcx , M :: PointerTag > ) -> Self ;
3030
31- // Read the current enum discriminant, and downcast to that. Also return the
32- // variant index.
31+ // Project to the given enum variant.
3332 fn project_downcast (
3433 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 > ;
3737
3838 // Project to the n-th field.
3939 fn project_field (
4040 self ,
41- ectx : & mut EvalContext < ' a , ' mir , ' tcx , M > ,
41+ ecx : & mut EvalContext < ' a , ' mir , ' tcx , M > ,
4242 field : u64 ,
4343 ) -> EvalResult < ' tcx , Self > ;
4444}
@@ -53,11 +53,11 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Value<'a, 'mir, 'tcx, M>
5353 }
5454
5555 #[ inline( always) ]
56- fn to_mem_place (
56+ fn to_op (
5757 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 )
6161 }
6262
6363 #[ inline( always) ]
@@ -68,19 +68,19 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Value<'a, 'mir, 'tcx, M>
6868 #[ inline( always) ]
6969 fn project_downcast (
7070 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 )
7575 }
7676
7777 #[ inline( always) ]
7878 fn project_field (
7979 self ,
80- ectx : & mut EvalContext < ' a , ' mir , ' tcx , M > ,
80+ ecx : & mut EvalContext < ' a , ' mir , ' tcx , M > ,
8181 field : u64 ,
8282 ) -> EvalResult < ' tcx , Self > {
83- ectx . operand_field ( self , field)
83+ ecx . operand_field ( self , field)
8484 }
8585}
8686impl < ' 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>
9292 }
9393
9494 #[ inline( always) ]
95- fn to_mem_place (
95+ fn to_op (
9696 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 ( ) )
100100 }
101101
102102 #[ inline( always) ]
@@ -107,19 +107,19 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Value<'a, 'mir, 'tcx, M>
107107 #[ inline( always) ]
108108 fn project_downcast (
109109 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 )
114114 }
115115
116116 #[ inline( always) ]
117117 fn project_field (
118118 self ,
119- ectx : & mut EvalContext < ' a , ' mir , ' tcx , M > ,
119+ ecx : & mut EvalContext < ' a , ' mir , ' tcx , M > ,
120120 field : u64 ,
121121 ) -> EvalResult < ' tcx , Self > {
122- ectx . mplace_field ( self , field)
122+ ecx . mplace_field ( self , field)
123123 }
124124}
125125impl < ' 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>
131131 }
132132
133133 #[ inline( always) ]
134- fn to_mem_place (
134+ fn to_op (
135135 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 )
140139 }
141140
142141 #[ inline( always) ]
@@ -147,19 +146,19 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Value<'a, 'mir, 'tcx, M>
147146 #[ inline( always) ]
148147 fn project_downcast (
149148 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 )
154153 }
155154
156155 #[ inline( always) ]
157156 fn project_field (
158157 self ,
159- ectx : & mut EvalContext < ' a , ' mir , ' tcx , M > ,
158+ ecx : & mut EvalContext < ' a , ' mir , ' tcx , M > ,
160159 field : u64 ,
161160 ) -> EvalResult < ' tcx , Self > {
162- ectx . place_field ( self , field)
161+ ecx . place_field ( self , field)
163162 }
164163}
165164
@@ -228,7 +227,7 @@ pub trait ValueVisitor<'a, 'mir, 'tcx: 'mir+'a, M: Machine<'a, 'mir, 'tcx>>: Siz
228227 MPlaceTy :: dangling ( v. layout ( ) , self . ecx ( ) )
229228 } else {
230229 // non-ZST array/slice/str cannot be immediate
231- v. to_mem_place ( self . ecx ( ) ) ?
230+ v. to_op ( self . ecx ( ) ) ?. to_mem_place ( )
232231 } ;
233232 // Now iterate over it.
234233 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
243242 match v. layout ( ) . variants {
244243 layout:: Variants :: NicheFilling { .. } |
245244 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( ) ) ;
248249 // recurse with the inner type
249250 return self . visit_field ( v, idx, inner) ;
250251 }
@@ -256,9 +257,9 @@ pub trait ValueVisitor<'a, 'mir, 'tcx: 'mir+'a, M: Machine<'a, 'mir, 'tcx>>: Siz
256257 match v. layout ( ) . ty . sty {
257258 ty:: Dynamic ( ..) => {
258259 // 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 ( ) ;
260261 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) ;
262263 // recurse with the inner type
263264 return self . visit_field ( v, 0 , Value :: from_mem_place ( inner) ) ;
264265 } ,
0 commit comments