@@ -294,7 +294,12 @@ impl<Prov: Provenance, Bytes: AllocBytes> Allocation<Prov, (), Bytes> {
294294 Allocation :: from_bytes ( slice, Align :: ONE , Mutability :: Not )
295295 }
296296
297- fn uninit_inner < R > ( size : Size , align : Align , fail : impl FnOnce ( ) -> R ) -> Result < Self , R > {
297+ fn new_inner < R > (
298+ size : Size ,
299+ align : Align ,
300+ zero_init : bool ,
301+ fail : impl FnOnce ( ) -> R ,
302+ ) -> Result < Self , R > {
298303 // We raise an error if we cannot create the allocation on the host.
299304 // This results in an error that can happen non-deterministically, since the memory
300305 // available to the compiler can change between runs. Normally queries are always
@@ -306,7 +311,7 @@ impl<Prov: Provenance, Bytes: AllocBytes> Allocation<Prov, (), Bytes> {
306311 Ok ( Allocation {
307312 bytes,
308313 provenance : ProvenanceMap :: new ( ) ,
309- init_mask : InitMask :: new ( size, false ) ,
314+ init_mask : InitMask :: new ( size, zero_init ) ,
310315 align,
311316 mutability : Mutability :: Mut ,
312317 extra : ( ) ,
@@ -315,8 +320,8 @@ impl<Prov: Provenance, Bytes: AllocBytes> Allocation<Prov, (), Bytes> {
315320
316321 /// Try to create an Allocation of `size` bytes, failing if there is not enough memory
317322 /// available to the compiler to do so.
318- pub fn try_uninit < ' tcx > ( size : Size , align : Align ) -> InterpResult < ' tcx , Self > {
319- Self :: uninit_inner ( size, align, || {
323+ pub fn try_new < ' tcx > ( size : Size , align : Align , zero_init : bool ) -> InterpResult < ' tcx , Self > {
324+ Self :: new_inner ( size, align, zero_init , || {
320325 ty:: tls:: with ( |tcx| tcx. dcx ( ) . delayed_bug ( "exhausted memory during interpretation" ) ) ;
321326 InterpErrorKind :: ResourceExhaustion ( ResourceExhaustionInfo :: MemoryExhausted )
322327 } )
@@ -328,51 +333,8 @@ impl<Prov: Provenance, Bytes: AllocBytes> Allocation<Prov, (), Bytes> {
328333 ///
329334 /// Example use case: To obtain an Allocation filled with specific data,
330335 /// first call this function and then call write_scalar to fill in the right data.
331- pub fn uninit ( size : Size , align : Align ) -> Self {
332- match Self :: uninit_inner ( size, align, || {
333- panic ! (
334- "interpreter ran out of memory: cannot create allocation of {} bytes" ,
335- size. bytes( )
336- ) ;
337- } ) {
338- Ok ( x) => x,
339- Err ( x) => x,
340- }
341- }
342-
343- fn zeroed_inner < R > ( size : Size , align : Align , fail : impl FnOnce ( ) -> R ) -> Result < Self , R > {
344- // We raise an error if we cannot create the allocation on the host.
345- // This results in an error that can happen non-deterministically, since the memory
346- // available to the compiler can change between runs. Normally queries are always
347- // deterministic. However, we can be non-deterministic here because all uses of const
348- // evaluation (including ConstProp!) will make compilation fail (via hard error
349- // or ICE) upon encountering a `MemoryExhausted` error.
350- let bytes = Bytes :: zeroed ( size, align) . ok_or_else ( fail) ?;
351-
352- Ok ( Allocation {
353- bytes,
354- provenance : ProvenanceMap :: new ( ) ,
355- init_mask : InitMask :: new ( size, true ) ,
356- align,
357- mutability : Mutability :: Mut ,
358- extra : ( ) ,
359- } )
360- }
361-
362- /// Try to create an Allocation of `size` zero-initialized bytes, failing if there is not enough memory
363- /// available to the compiler to do so.
364- pub fn try_zeroed < ' tcx > ( size : Size , align : Align ) -> InterpResult < ' tcx , Self > {
365- Self :: zeroed_inner ( size, align, || {
366- ty:: tls:: with ( |tcx| tcx. dcx ( ) . delayed_bug ( "exhausted memory during interpretation" ) ) ;
367- InterpErrorKind :: ResourceExhaustion ( ResourceExhaustionInfo :: MemoryExhausted )
368- } )
369- . into ( )
370- }
371-
372- /// Try to create an Allocation of `size` zero-initialized bytes, panics if there is not enough memory
373- /// available to the compiler to do so.
374- pub fn zeroed ( size : Size , align : Align ) -> Self {
375- match Self :: zeroed_inner ( size, align, || {
336+ pub fn new ( size : Size , align : Align , zero_init : bool ) -> Self {
337+ match Self :: new_inner ( size, align, zero_init, || {
376338 panic ! (
377339 "interpreter ran out of memory: cannot create allocation of {} bytes" ,
378340 size. bytes( )
0 commit comments