@@ -13,6 +13,9 @@ extern crate rustc_mir;
13
13
extern crate rustc_target;
14
14
extern crate syntax;
15
15
16
+ use std:: collections:: HashMap ;
17
+ use std:: borrow:: Cow ;
18
+
16
19
use rustc:: ty:: { self , TyCtxt , query:: TyCtxtAt } ;
17
20
use rustc:: ty:: layout:: { TyLayout , LayoutOf , Size } ;
18
21
use rustc:: hir:: def_id:: DefId ;
@@ -21,11 +24,10 @@ use rustc::mir;
21
24
use syntax:: ast:: Mutability ;
22
25
use syntax:: attr;
23
26
24
- use std:: collections:: HashMap ;
25
27
26
28
pub use rustc:: mir:: interpret:: * ;
27
29
pub use rustc_mir:: interpret:: * ;
28
- pub use rustc_mir:: interpret;
30
+ pub use rustc_mir:: interpret:: { self , AllocMap } ; // resolve ambiguity
29
31
30
32
mod fn_call;
31
33
mod operator;
@@ -34,13 +36,15 @@ mod helpers;
34
36
mod tls;
35
37
mod locks;
36
38
mod range_map;
39
+ mod mono_hash_map;
37
40
38
41
use fn_call:: EvalContextExt as MissingFnsEvalContextExt ;
39
42
use operator:: EvalContextExt as OperatorEvalContextExt ;
40
43
use intrinsic:: EvalContextExt as IntrinsicEvalContextExt ;
41
44
use tls:: { EvalContextExt as TlsEvalContextExt , TlsData } ;
42
45
use range_map:: RangeMap ;
43
46
use helpers:: FalibleScalarExt ;
47
+ use mono_hash_map:: MonoHashMap ;
44
48
45
49
pub fn create_ecx < ' a , ' mir : ' a , ' tcx : ' mir > (
46
50
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
@@ -231,8 +235,11 @@ pub struct Evaluator<'tcx> {
231
235
impl < ' a , ' mir , ' tcx > Machine < ' a , ' mir , ' tcx > for Evaluator < ' tcx > {
232
236
type MemoryData = ( ) ;
233
237
type MemoryKinds = MiriMemoryKind ;
238
+ type PointerTag = ( ) ; // still WIP
234
239
235
- const MUT_STATIC_KIND : Option < MiriMemoryKind > = Some ( MiriMemoryKind :: MutStatic ) ;
240
+ type MemoryMap = MonoHashMap < AllocId , ( MemoryKind < MiriMemoryKind > , Allocation < ( ) > ) > ;
241
+
242
+ const STATIC_KIND : Option < MiriMemoryKind > = Some ( MiriMemoryKind :: MutStatic ) ;
236
243
237
244
/// Returns Ok() when the function was handled, fail otherwise
238
245
fn find_fn (
@@ -307,7 +314,7 @@ impl<'a, 'mir, 'tcx> Machine<'a, 'mir, 'tcx> for Evaluator<'tcx> {
307
314
fn find_foreign_static (
308
315
tcx : TyCtxtAt < ' a , ' tcx , ' tcx > ,
309
316
def_id : DefId ,
310
- ) -> EvalResult < ' tcx , & ' tcx Allocation > {
317
+ ) -> EvalResult < ' tcx , Cow < ' tcx , Allocation > > {
311
318
let attrs = tcx. get_attrs ( def_id) ;
312
319
let link_name = match attr:: first_attr_value_str_by_name ( & attrs, "link_name" ) {
313
320
Some ( name) => name. as_str ( ) ,
@@ -318,14 +325,13 @@ impl<'a, 'mir, 'tcx> Machine<'a, 'mir, 'tcx> for Evaluator<'tcx> {
318
325
"__cxa_thread_atexit_impl" => {
319
326
// This should be all-zero, pointer-sized
320
327
let data = vec ! [ 0 ; tcx. data_layout. pointer_size. bytes( ) as usize ] ;
321
- let alloc = Allocation :: from_bytes ( & data[ ..] , tcx. data_layout . pointer_align ) ;
322
- tcx. intern_const_alloc ( alloc)
328
+ Allocation :: from_bytes ( & data[ ..] , tcx. data_layout . pointer_align )
323
329
}
324
330
_ => return err ! ( Unimplemented (
325
331
format!( "can't access foreign static: {}" , link_name) ,
326
332
) ) ,
327
333
} ;
328
- Ok ( alloc)
334
+ Ok ( Cow :: Owned ( alloc) )
329
335
}
330
336
331
337
fn validation_op (
@@ -343,4 +349,11 @@ impl<'a, 'mir, 'tcx> Machine<'a, 'mir, 'tcx> for Evaluator<'tcx> {
343
349
// We are not interested in detecting loops
344
350
Ok ( ( ) )
345
351
}
352
+
353
+ fn static_with_default_tag (
354
+ alloc : & ' _ Allocation
355
+ ) -> Cow < ' _ , Allocation < Self :: PointerTag > > {
356
+ let alloc = alloc. clone ( ) ;
357
+ Cow :: Owned ( alloc)
358
+ }
346
359
}
0 commit comments