@@ -7,6 +7,7 @@ use std::collections::hash_map::Entry;
7
7
use std:: hash:: Hash ;
8
8
9
9
use rustc_data_structures:: fx:: FxHashMap ;
10
+ use std:: fmt;
10
11
11
12
use rustc_ast:: Mutability ;
12
13
use rustc_hir:: def_id:: DefId ;
@@ -179,6 +180,28 @@ impl<K: Hash + Eq, V> interpret::AllocMap<K, V> for FxHashMap<K, V> {
179
180
crate type CompileTimeEvalContext < ' mir , ' tcx > =
180
181
InterpCx < ' mir , ' tcx , CompileTimeInterpreter < ' mir , ' tcx > > ;
181
182
183
+ #[ derive( Debug , PartialEq , Eq , Copy , Clone ) ]
184
+ pub enum MemoryKind {
185
+ Heap ,
186
+ }
187
+
188
+ impl fmt:: Display for MemoryKind {
189
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
190
+ match self {
191
+ MemoryKind :: Heap => write ! ( f, "heap allocation" ) ,
192
+ }
193
+ }
194
+ }
195
+
196
+ impl interpret:: MayLeak for MemoryKind {
197
+ #[ inline( always) ]
198
+ fn may_leak ( self ) -> bool {
199
+ match self {
200
+ MemoryKind :: Heap => false ,
201
+ }
202
+ }
203
+ }
204
+
182
205
impl interpret:: MayLeak for ! {
183
206
#[ inline( always) ]
184
207
fn may_leak ( self ) -> bool {
@@ -222,6 +245,8 @@ impl<'mir, 'tcx: 'mir> CompileTimeEvalContext<'mir, 'tcx> {
222
245
impl < ' mir , ' tcx > interpret:: Machine < ' mir , ' tcx > for CompileTimeInterpreter < ' mir , ' tcx > {
223
246
compile_time_machine ! ( <' mir, ' tcx>) ;
224
247
248
+ type MemoryKind = MemoryKind ;
249
+
225
250
type MemoryExtra = MemoryExtra ;
226
251
227
252
fn find_mir_or_eval_fn (
@@ -317,7 +342,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
317
342
let ptr = ecx. memory . allocate (
318
343
Size :: from_bytes ( size as u64 ) ,
319
344
align,
320
- interpret:: MemoryKind :: ConstHeap ,
345
+ interpret:: MemoryKind :: Machine ( MemoryKind :: Heap ) ,
321
346
) ;
322
347
ecx. write_scalar ( Scalar :: Ptr ( ptr) , dest) ?;
323
348
}
0 commit comments