@@ -11,7 +11,7 @@ use std::ptr;
11
11
use std:: borrow:: Cow ;
12
12
13
13
use rustc:: ty:: { self , Instance , ParamEnv , query:: TyCtxtAt } ;
14
- use rustc:: ty:: layout:: { Align , TargetDataLayout , Size , HasDataLayout } ;
14
+ use rustc:: ty:: layout:: { Align , MemoryPosition , TargetDataLayout , Size , HasDataLayout } ;
15
15
use rustc_data_structures:: fx:: { FxHashSet , FxHashMap } ;
16
16
17
17
use syntax:: ast:: Mutability ;
@@ -165,11 +165,10 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
165
165
166
166
pub fn allocate (
167
167
& mut self ,
168
- size : Size ,
169
- align : Align ,
168
+ mem_pos : MemoryPosition ,
170
169
kind : MemoryKind < M :: MemoryKinds > ,
171
170
) -> Pointer < M :: PointerTag > {
172
- let alloc = Allocation :: undef ( size, align) ;
171
+ let alloc = Allocation :: undef ( mem_pos . size , mem_pos . align ) ;
173
172
self . allocate_with ( alloc, kind)
174
173
}
175
174
@@ -196,9 +195,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
196
195
pub fn reallocate (
197
196
& mut self ,
198
197
ptr : Pointer < M :: PointerTag > ,
199
- old_size_and_align : Option < ( Size , Align ) > ,
200
- new_size : Size ,
201
- new_align : Align ,
198
+ old_mem_pos : Option < MemoryPosition > ,
199
+ new_mem_pos : MemoryPosition ,
202
200
kind : MemoryKind < M :: MemoryKinds > ,
203
201
) -> InterpResult < ' tcx , Pointer < M :: PointerTag > > {
204
202
if ptr. offset . bytes ( ) != 0 {
@@ -207,18 +205,18 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
207
205
208
206
// For simplicities' sake, we implement reallocate as "alloc, copy, dealloc".
209
207
// This happens so rarely, the perf advantage is outweighed by the maintenance cost.
210
- let new_ptr = self . allocate ( new_size , new_align , kind) ;
211
- let old_size = match old_size_and_align {
212
- Some ( ( size , _align ) ) => size,
208
+ let new_ptr = self . allocate ( new_mem_pos , kind) ;
209
+ let old_size = match old_mem_pos {
210
+ Some ( old_mem_pos ) => old_mem_pos . size ,
213
211
None => self . get_raw ( ptr. alloc_id ) ?. size ,
214
212
} ;
215
213
self . copy (
216
214
ptr,
217
215
new_ptr,
218
- old_size. min ( new_size ) ,
216
+ old_size. min ( new_mem_pos . size ) ,
219
217
/*nonoverlapping*/ true ,
220
218
) ?;
221
- self . deallocate ( ptr, old_size_and_align , kind) ?;
219
+ self . deallocate ( ptr, old_mem_pos , kind) ?;
222
220
223
221
Ok ( new_ptr)
224
222
}
@@ -237,7 +235,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
237
235
pub fn deallocate (
238
236
& mut self ,
239
237
ptr : Pointer < M :: PointerTag > ,
240
- old_size_and_align : Option < ( Size , Align ) > ,
238
+ old_mem_pos : Option < MemoryPosition > ,
241
239
kind : MemoryKind < M :: MemoryKinds > ,
242
240
) -> InterpResult < ' tcx > {
243
241
trace ! ( "deallocating: {}" , ptr. alloc_id) ;
@@ -270,7 +268,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
270
268
format!( "{:?}" , kind) ,
271
269
) )
272
270
}
273
- if let Some ( ( size, align) ) = old_size_and_align {
271
+ if let Some ( MemoryPosition { size, align} ) = old_mem_pos {
274
272
if size != alloc. size || align != alloc. align {
275
273
let bytes = alloc. size ;
276
274
throw_unsup ! ( IncorrectAllocationInformation ( size, bytes, align, alloc. align) )
0 commit comments