@@ -159,6 +159,19 @@ impl<Tag> MemPlace<Tag> {
159
159
Some ( meta) => Immediate :: ScalarPair ( self . ptr . into ( ) , meta. into ( ) ) ,
160
160
}
161
161
}
162
+
163
+ pub fn offset (
164
+ self ,
165
+ offset : Size ,
166
+ meta : Option < Scalar < Tag > > ,
167
+ cx : & impl HasDataLayout ,
168
+ ) -> EvalResult < ' tcx , Self > {
169
+ Ok ( MemPlace {
170
+ ptr : self . ptr . ptr_offset ( offset, cx) ?,
171
+ align : self . align . restrict_for_offset ( offset) ,
172
+ meta,
173
+ } )
174
+ }
162
175
}
163
176
164
177
impl < ' tcx , Tag > MPlaceTy < ' tcx , Tag > {
@@ -174,6 +187,19 @@ impl<'tcx, Tag> MPlaceTy<'tcx, Tag> {
174
187
}
175
188
}
176
189
190
+ pub fn offset (
191
+ self ,
192
+ offset : Size ,
193
+ meta : Option < Scalar < Tag > > ,
194
+ layout : TyLayout < ' tcx > ,
195
+ cx : & impl HasDataLayout ,
196
+ ) -> EvalResult < ' tcx , Self > {
197
+ Ok ( MPlaceTy {
198
+ mplace : self . mplace . offset ( offset, meta, cx) ?,
199
+ layout,
200
+ } )
201
+ }
202
+
177
203
#[ inline]
178
204
fn from_aligned_ptr ( ptr : Pointer < Tag > , layout : TyLayout < ' tcx > ) -> Self {
179
205
MPlaceTy { mplace : MemPlace :: from_ptr ( ptr, layout. align . abi ) , layout }
@@ -367,13 +393,9 @@ where
367
393
( None , offset)
368
394
} ;
369
395
370
- let ptr = base. ptr . ptr_offset ( offset, self ) ?;
371
- let align = base. align
372
- // We do not look at `base.layout.align` nor `field_layout.align`, unlike
373
- // codegen -- mostly to see if we can get away with that
374
- . restrict_for_offset ( offset) ; // must be last thing that happens
375
-
376
- Ok ( MPlaceTy { mplace : MemPlace { ptr, align, meta } , layout : field_layout } )
396
+ // We do not look at `base.layout.align` nor `field_layout.align`, unlike
397
+ // codegen -- mostly to see if we can get away with that
398
+ base. offset ( offset, meta, field_layout, self )
377
399
}
378
400
379
401
// Iterates over all fields of an array. Much more efficient than doing the
@@ -391,14 +413,7 @@ where
391
413
} ;
392
414
let layout = base. layout . field ( self , 0 ) ?;
393
415
let dl = & self . tcx . data_layout ;
394
- Ok ( ( 0 ..len) . map ( move |i| {
395
- let ptr = base. ptr . ptr_offset ( i * stride, dl) ?;
396
- let align = base. align . restrict_for_offset ( i * stride) ;
397
- Ok ( MPlaceTy {
398
- mplace : MemPlace { ptr, align, meta : None } ,
399
- layout
400
- } )
401
- } ) )
416
+ Ok ( ( 0 ..len) . map ( move |i| base. offset ( i * stride, None , layout, dl) ) )
402
417
}
403
418
404
419
pub fn mplace_subslice (
@@ -417,8 +432,6 @@ where
417
432
stride * from,
418
433
_ => bug ! ( "Unexpected layout of index access: {:#?}" , base. layout) ,
419
434
} ;
420
- let ptr = base. ptr . ptr_offset ( from_offset, self ) ?;
421
- let align = base. align . restrict_for_offset ( from_offset) ;
422
435
423
436
// Compute meta and new layout
424
437
let inner_len = len - to - from;
@@ -435,11 +448,7 @@ where
435
448
bug ! ( "cannot subslice non-array type: `{:?}`" , base. layout. ty) ,
436
449
} ;
437
450
let layout = self . layout_of ( ty) ?;
438
-
439
- Ok ( MPlaceTy {
440
- mplace : MemPlace { ptr, align, meta } ,
441
- layout
442
- } )
451
+ base. offset ( from_offset, meta, layout, self )
443
452
}
444
453
445
454
pub fn mplace_downcast (
0 commit comments