@@ -11,7 +11,7 @@ use std::ptr;
1111use std:: borrow:: Cow ;
1212
1313use 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 } ;
1515use rustc_data_structures:: fx:: { FxHashSet , FxHashMap } ;
1616
1717use syntax:: ast:: Mutability ;
@@ -165,11 +165,10 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
165165
166166 pub fn allocate (
167167 & mut self ,
168- size : Size ,
169- align : Align ,
168+ mem_pos : MemoryPosition ,
170169 kind : MemoryKind < M :: MemoryKinds > ,
171170 ) -> Pointer < M :: PointerTag > {
172- let alloc = Allocation :: undef ( size, align) ;
171+ let alloc = Allocation :: undef ( mem_pos . size , mem_pos . align ) ;
173172 self . allocate_with ( alloc, kind)
174173 }
175174
@@ -196,9 +195,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
196195 pub fn reallocate (
197196 & mut self ,
198197 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 ,
202200 kind : MemoryKind < M :: MemoryKinds > ,
203201 ) -> InterpResult < ' tcx , Pointer < M :: PointerTag > > {
204202 if ptr. offset . bytes ( ) != 0 {
@@ -207,18 +205,18 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
207205
208206 // For simplicities' sake, we implement reallocate as "alloc, copy, dealloc".
209207 // 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 ,
213211 None => self . get_raw ( ptr. alloc_id ) ?. size ,
214212 } ;
215213 self . copy (
216214 ptr,
217215 new_ptr,
218- old_size. min ( new_size ) ,
216+ old_size. min ( new_mem_pos . size ) ,
219217 /*nonoverlapping*/ true ,
220218 ) ?;
221- self . deallocate ( ptr, old_size_and_align , kind) ?;
219+ self . deallocate ( ptr, old_mem_pos , kind) ?;
222220
223221 Ok ( new_ptr)
224222 }
@@ -237,7 +235,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
237235 pub fn deallocate (
238236 & mut self ,
239237 ptr : Pointer < M :: PointerTag > ,
240- old_size_and_align : Option < ( Size , Align ) > ,
238+ old_mem_pos : Option < MemoryPosition > ,
241239 kind : MemoryKind < M :: MemoryKinds > ,
242240 ) -> InterpResult < ' tcx > {
243241 trace ! ( "deallocating: {}" , ptr. alloc_id) ;
@@ -270,7 +268,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
270268 format!( "{:?}" , kind) ,
271269 ) )
272270 }
273- if let Some ( ( size, align) ) = old_size_and_align {
271+ if let Some ( MemoryPosition { size, align} ) = old_mem_pos {
274272 if size != alloc. size || align != alloc. align {
275273 let bytes = alloc. size ;
276274 throw_unsup ! ( IncorrectAllocationInformation ( size, bytes, align, alloc. align) )
0 commit comments