@@ -7,6 +7,7 @@ use rustc::mir::interpret::{
7
7
read_target_uint, AllocId , Allocation , ConstValue , GlobalAlloc , InterpResult , Scalar ,
8
8
} ;
9
9
use rustc:: ty:: { layout:: Align , Const , ConstKind } ;
10
+ use rustc_data_structures:: fx:: FxHashSet ;
10
11
use rustc_mir:: interpret:: {
11
12
ImmTy , InterpCx , Machine , Memory , MemoryKind , OpTy , PlaceTy , Pointer ,
12
13
StackPopCleanup , StackPopInfo ,
@@ -19,11 +20,11 @@ use crate::prelude::*;
19
20
20
21
#[ derive( Default ) ]
21
22
pub struct ConstantCx {
22
- todo : HashSet < TodoItem > ,
23
- done : HashSet < DataId > ,
23
+ todo : Vec < TodoItem > ,
24
+ done : FxHashSet < DataId > ,
24
25
}
25
26
26
- #[ derive( Copy , Clone , Debug , Eq , PartialEq , Hash ) ]
27
+ #[ derive( Copy , Clone , Debug ) ]
27
28
enum TodoItem {
28
29
Alloc ( AllocId ) ,
29
30
Static ( DefId ) ,
@@ -39,7 +40,7 @@ impl ConstantCx {
39
40
}
40
41
41
42
pub fn codegen_static ( constants_cx : & mut ConstantCx , def_id : DefId ) {
42
- constants_cx. todo . insert ( TodoItem :: Static ( def_id) ) ;
43
+ constants_cx. todo . push ( TodoItem :: Static ( def_id) ) ;
43
44
}
44
45
45
46
fn codegen_static_ref < ' tcx > (
@@ -109,7 +110,7 @@ pub fn trans_const_value<'tcx>(
109
110
let alloc_kind = fx. tcx . alloc_map . lock ( ) . get ( ptr. alloc_id ) ;
110
111
let base_addr = match alloc_kind {
111
112
Some ( GlobalAlloc :: Memory ( alloc) ) => {
112
- fx. constants_cx . todo . insert ( TodoItem :: Alloc ( ptr. alloc_id ) ) ;
113
+ fx. constants_cx . todo . push ( TodoItem :: Alloc ( ptr. alloc_id ) ) ;
113
114
let data_id = data_id_for_alloc_id ( fx. module , ptr. alloc_id , alloc. align ) ;
114
115
let local_data_id = fx. module . declare_data_in_func ( data_id, & mut fx. bcx . func ) ;
115
116
#[ cfg( debug_assertions) ]
@@ -139,7 +140,7 @@ pub fn trans_const_value<'tcx>(
139
140
}
140
141
ConstValue :: ByRef { alloc, offset } => {
141
142
let alloc_id = fx. tcx . alloc_map . lock ( ) . create_memory_alloc ( alloc) ;
142
- fx. constants_cx . todo . insert ( TodoItem :: Alloc ( alloc_id) ) ;
143
+ fx. constants_cx . todo . push ( TodoItem :: Alloc ( alloc_id) ) ;
143
144
let data_id = data_id_for_alloc_id ( fx. module , alloc_id, alloc. align ) ;
144
145
let local_data_id = fx. module . declare_data_in_func ( data_id, & mut fx. bcx . func ) ;
145
146
let global_ptr = fx. bcx . ins ( ) . global_value ( fx. pointer_type , local_data_id) ;
@@ -195,7 +196,7 @@ fn trans_const_place<'tcx>(
195
196
196
197
//println!("const value: {:?} allocation: {:?}", value, alloc);
197
198
let alloc_id = fx. tcx . alloc_map . lock ( ) . create_memory_alloc ( alloc) ;
198
- fx. constants_cx . todo . insert ( TodoItem :: Alloc ( alloc_id) ) ;
199
+ fx. constants_cx . todo . push ( TodoItem :: Alloc ( alloc_id) ) ;
199
200
let data_id = data_id_for_alloc_id ( fx. module , alloc_id, alloc. align ) ;
200
201
let local_data_id = fx. module . declare_data_in_func ( data_id, & mut fx. bcx . func ) ;
201
202
#[ cfg( debug_assertions) ]
@@ -287,7 +288,7 @@ fn cplace_for_dataid<'tcx>(
287
288
fn define_all_allocs ( tcx : TyCtxt < ' _ > , module : & mut Module < impl Backend > , cx : & mut ConstantCx ) {
288
289
let memory = Memory :: < TransPlaceInterpreter > :: new ( tcx. at ( DUMMY_SP ) , ( ) ) ;
289
290
290
- while let Some ( todo_item) = pop_set ( & mut cx. todo ) {
291
+ while let Some ( todo_item) = cx. todo . pop ( ) {
291
292
let ( data_id, alloc) = match todo_item {
292
293
TodoItem :: Alloc ( alloc_id) => {
293
294
//println!("alloc_id {}", alloc_id);
@@ -356,7 +357,7 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut Module<impl Backend>, cx: &mu
356
357
continue ;
357
358
}
358
359
GlobalAlloc :: Memory ( _) => {
359
- cx. todo . insert ( TodoItem :: Alloc ( reloc) ) ;
360
+ cx. todo . push ( TodoItem :: Alloc ( reloc) ) ;
360
361
data_id_for_alloc_id ( module, reloc, alloc. align )
361
362
}
362
363
GlobalAlloc :: Static ( def_id) => {
@@ -387,15 +388,6 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut Module<impl Backend>, cx: &mu
387
388
assert ! ( cx. todo. is_empty( ) , "{:?}" , cx. todo) ;
388
389
}
389
390
390
- fn pop_set < T : Copy + Eq + :: std:: hash:: Hash > ( set : & mut HashSet < T > ) -> Option < T > {
391
- if let Some ( elem) = set. iter ( ) . next ( ) . map ( |elem| * elem) {
392
- set. remove ( & elem) ;
393
- Some ( elem)
394
- } else {
395
- None
396
- }
397
- }
398
-
399
391
struct TransPlaceInterpreter ;
400
392
401
393
impl < ' mir , ' tcx > Machine < ' mir , ' tcx > for TransPlaceInterpreter {
0 commit comments