@@ -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
const ENFORCE_VALIDITY : bool = false ; // this is still WIP
237
244
238
245
/// Returns Ok() when the function was handled, fail otherwise
@@ -308,7 +315,7 @@ impl<'a, 'mir, 'tcx> Machine<'a, 'mir, 'tcx> for Evaluator<'tcx> {
308
315
fn find_foreign_static (
309
316
tcx : TyCtxtAt < ' a , ' tcx , ' tcx > ,
310
317
def_id : DefId ,
311
- ) -> EvalResult < ' tcx , & ' tcx Allocation > {
318
+ ) -> EvalResult < ' tcx , Cow < ' tcx , Allocation > > {
312
319
let attrs = tcx. get_attrs ( def_id) ;
313
320
let link_name = match attr:: first_attr_value_str_by_name ( & attrs, "link_name" ) {
314
321
Some ( name) => name. as_str ( ) ,
@@ -319,14 +326,13 @@ impl<'a, 'mir, 'tcx> Machine<'a, 'mir, 'tcx> for Evaluator<'tcx> {
319
326
"__cxa_thread_atexit_impl" => {
320
327
// This should be all-zero, pointer-sized
321
328
let data = vec ! [ 0 ; tcx. data_layout. pointer_size. bytes( ) as usize ] ;
322
- let alloc = Allocation :: from_bytes ( & data[ ..] , tcx. data_layout . pointer_align ) ;
323
- tcx. intern_const_alloc ( alloc)
329
+ Allocation :: from_bytes ( & data[ ..] , tcx. data_layout . pointer_align )
324
330
}
325
331
_ => return err ! ( Unimplemented (
326
332
format!( "can't access foreign static: {}" , link_name) ,
327
333
) ) ,
328
334
} ;
329
- Ok ( alloc)
335
+ Ok ( Cow :: Owned ( alloc) )
330
336
}
331
337
332
338
fn validation_op (
@@ -344,4 +350,11 @@ impl<'a, 'mir, 'tcx> Machine<'a, 'mir, 'tcx> for Evaluator<'tcx> {
344
350
// We are not interested in detecting loops
345
351
Ok ( ( ) )
346
352
}
353
+
354
+ fn static_with_default_tag (
355
+ alloc : & ' _ Allocation
356
+ ) -> Cow < ' _ , Allocation < Self :: PointerTag > > {
357
+ let alloc = alloc. clone ( ) ;
358
+ Cow :: Owned ( alloc)
359
+ }
347
360
}
0 commit comments