Skip to content

Commit 81b0c05

Browse files
committed
Auto merge of #55114 - oli-obk:fx#map, r=nikomatsakis
Deprecate the `FxHashMap()` and `FxHashSet()` constructor function hack
2 parents 74ff7dc + 53e92f4 commit 81b0c05

File tree

133 files changed

+428
-558
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+428
-558
lines changed

src/bootstrap/cache.rs

+8-12
Original file line numberDiff line numberDiff line change
@@ -169,19 +169,21 @@ impl Ord for Interned<String> {
169169
}
170170
}
171171

172-
struct TyIntern<T> {
172+
struct TyIntern<T: Hash + Clone + Eq> {
173173
items: Vec<T>,
174174
set: HashMap<T, Interned<T>>,
175175
}
176176

177-
impl<T: Hash + Clone + Eq> TyIntern<T> {
178-
fn new() -> TyIntern<T> {
177+
impl<T: Hash + Clone + Eq> Default for TyIntern<T> {
178+
fn default() -> Self {
179179
TyIntern {
180180
items: Vec::new(),
181-
set: HashMap::new(),
181+
set: Default::default(),
182182
}
183183
}
184+
}
184185

186+
impl<T: Hash + Clone + Eq> TyIntern<T> {
185187
fn intern_borrow<B>(&mut self, item: &B) -> Interned<T>
186188
where
187189
B: Eq + Hash + ToOwned<Owned=T> + ?Sized,
@@ -212,19 +214,13 @@ impl<T: Hash + Clone + Eq> TyIntern<T> {
212214
}
213215
}
214216

217+
#[derive(Default)]
215218
pub struct Interner {
216219
strs: Mutex<TyIntern<String>>,
217220
paths: Mutex<TyIntern<PathBuf>>,
218221
}
219222

220223
impl Interner {
221-
fn new() -> Interner {
222-
Interner {
223-
strs: Mutex::new(TyIntern::new()),
224-
paths: Mutex::new(TyIntern::new()),
225-
}
226-
}
227-
228224
pub fn intern_str(&self, s: &str) -> Interned<String> {
229225
self.strs.lock().unwrap().intern_borrow(s)
230226
}
@@ -238,7 +234,7 @@ impl Interner {
238234
}
239235

240236
lazy_static! {
241-
pub static ref INTERNER: Interner = Interner::new();
237+
pub static ref INTERNER: Interner = Interner::default();
242238
}
243239

244240
/// This is essentially a HashMap which allows storing any type in its input and

src/libarena/lib.rs

+23-31
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,9 @@ impl<T> TypedArenaChunk<T> {
114114

115115
const PAGE: usize = 4096;
116116

117-
impl<T> TypedArena<T> {
117+
impl<T> Default for TypedArena<T> {
118118
/// Creates a new `TypedArena`.
119-
#[inline]
120-
pub fn new() -> TypedArena<T> {
119+
fn default() -> TypedArena<T> {
121120
TypedArena {
122121
// We set both `ptr` and `end` to 0 so that the first call to
123122
// alloc() will trigger a grow().
@@ -127,7 +126,9 @@ impl<T> TypedArena<T> {
127126
_own: PhantomData,
128127
}
129128
}
129+
}
130130

131+
impl<T> TypedArena<T> {
131132
/// Allocates an object in the `TypedArena`, returning a reference to it.
132133
#[inline]
133134
pub fn alloc(&self, object: T) -> &mut T {
@@ -296,15 +297,17 @@ pub struct DroplessArena {
296297

297298
unsafe impl Send for DroplessArena {}
298299

299-
impl DroplessArena {
300-
pub fn new() -> DroplessArena {
300+
impl Default for DroplessArena {
301+
fn default() -> DroplessArena {
301302
DroplessArena {
302303
ptr: Cell::new(0 as *mut u8),
303304
end: Cell::new(0 as *mut u8),
304-
chunks: RefCell::new(vec![]),
305+
chunks: Default::default(),
305306
}
306307
}
308+
}
307309

310+
impl DroplessArena {
308311
pub fn in_arena<T: ?Sized>(&self, ptr: *const T) -> bool {
309312
let ptr = ptr as *const u8 as *mut u8;
310313
for chunk in &*self.chunks.borrow() {
@@ -419,18 +422,13 @@ impl DroplessArena {
419422
}
420423
}
421424

425+
#[derive(Default)]
426+
// FIXME(@Zoxc): this type is entirely unused in rustc
422427
pub struct SyncTypedArena<T> {
423428
lock: MTLock<TypedArena<T>>,
424429
}
425430

426431
impl<T> SyncTypedArena<T> {
427-
#[inline(always)]
428-
pub fn new() -> SyncTypedArena<T> {
429-
SyncTypedArena {
430-
lock: MTLock::new(TypedArena::new())
431-
}
432-
}
433-
434432
#[inline(always)]
435433
pub fn alloc(&self, object: T) -> &mut T {
436434
// Extend the lifetime of the result since it's limited to the lock guard
@@ -452,18 +450,12 @@ impl<T> SyncTypedArena<T> {
452450
}
453451
}
454452

453+
#[derive(Default)]
455454
pub struct SyncDroplessArena {
456455
lock: MTLock<DroplessArena>,
457456
}
458457

459458
impl SyncDroplessArena {
460-
#[inline(always)]
461-
pub fn new() -> SyncDroplessArena {
462-
SyncDroplessArena {
463-
lock: MTLock::new(DroplessArena::new())
464-
}
465-
}
466-
467459
#[inline(always)]
468460
pub fn in_arena<T: ?Sized>(&self, ptr: *const T) -> bool {
469461
self.lock.lock().in_arena(ptr)
@@ -508,7 +500,7 @@ mod tests {
508500

509501
#[test]
510502
pub fn test_unused() {
511-
let arena: TypedArena<Point> = TypedArena::new();
503+
let arena: TypedArena<Point> = TypedArena::default();
512504
assert!(arena.chunks.borrow().is_empty());
513505
}
514506

@@ -546,7 +538,7 @@ mod tests {
546538
}
547539
}
548540

549-
let arena = Wrap(TypedArena::new());
541+
let arena = Wrap(TypedArena::default());
550542

551543
let result = arena.alloc_outer(|| Outer {
552544
inner: arena.alloc_inner(|| Inner { value: 10 }),
@@ -557,15 +549,15 @@ mod tests {
557549

558550
#[test]
559551
pub fn test_copy() {
560-
let arena = TypedArena::new();
552+
let arena = TypedArena::default();
561553
for _ in 0..100000 {
562554
arena.alloc(Point { x: 1, y: 2, z: 3 });
563555
}
564556
}
565557

566558
#[bench]
567559
pub fn bench_copy(b: &mut Bencher) {
568-
let arena = TypedArena::new();
560+
let arena = TypedArena::default();
569561
b.iter(|| arena.alloc(Point { x: 1, y: 2, z: 3 }))
570562
}
571563

@@ -584,7 +576,7 @@ mod tests {
584576

585577
#[test]
586578
pub fn test_noncopy() {
587-
let arena = TypedArena::new();
579+
let arena = TypedArena::default();
588580
for _ in 0..100000 {
589581
arena.alloc(Noncopy {
590582
string: "hello world".to_string(),
@@ -595,15 +587,15 @@ mod tests {
595587

596588
#[test]
597589
pub fn test_typed_arena_zero_sized() {
598-
let arena = TypedArena::new();
590+
let arena = TypedArena::default();
599591
for _ in 0..100000 {
600592
arena.alloc(());
601593
}
602594
}
603595

604596
#[test]
605597
pub fn test_typed_arena_clear() {
606-
let mut arena = TypedArena::new();
598+
let mut arena = TypedArena::default();
607599
for _ in 0..10 {
608600
arena.clear();
609601
for _ in 0..10000 {
@@ -628,7 +620,7 @@ mod tests {
628620
fn test_typed_arena_drop_count() {
629621
let counter = Cell::new(0);
630622
{
631-
let arena: TypedArena<DropCounter> = TypedArena::new();
623+
let arena: TypedArena<DropCounter> = TypedArena::default();
632624
for _ in 0..100 {
633625
// Allocate something with drop glue to make sure it doesn't leak.
634626
arena.alloc(DropCounter { count: &counter });
@@ -640,7 +632,7 @@ mod tests {
640632
#[test]
641633
fn test_typed_arena_drop_on_clear() {
642634
let counter = Cell::new(0);
643-
let mut arena: TypedArena<DropCounter> = TypedArena::new();
635+
let mut arena: TypedArena<DropCounter> = TypedArena::default();
644636
for i in 0..10 {
645637
for _ in 0..100 {
646638
// Allocate something with drop glue to make sure it doesn't leak.
@@ -667,7 +659,7 @@ mod tests {
667659
fn test_typed_arena_drop_small_count() {
668660
DROP_COUNTER.with(|c| c.set(0));
669661
{
670-
let arena: TypedArena<SmallDroppable> = TypedArena::new();
662+
let arena: TypedArena<SmallDroppable> = TypedArena::default();
671663
for _ in 0..100 {
672664
// Allocate something with drop glue to make sure it doesn't leak.
673665
arena.alloc(SmallDroppable);
@@ -679,7 +671,7 @@ mod tests {
679671

680672
#[bench]
681673
pub fn bench_noncopy(b: &mut Bencher) {
682-
let arena = TypedArena::new();
674+
let arena = TypedArena::default();
683675
b.iter(|| {
684676
arena.alloc(Noncopy {
685677
string: "hello world".to_string(),

src/librustc/dep_graph/cgu_reuse_tracker.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ pub struct CguReuseTracker {
5151
impl CguReuseTracker {
5252
pub fn new() -> CguReuseTracker {
5353
let data = TrackerData {
54-
actual_reuse: FxHashMap(),
55-
expected_reuse: FxHashMap(),
54+
actual_reuse: Default::default(),
55+
expected_reuse: Default::default(),
5656
};
5757

5858
CguReuseTracker {

src/librustc/dep_graph/dep_tracking_map.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl<M: DepTrackingMapConfig> DepTrackingMap<M> {
3636
DepTrackingMap {
3737
phantom: PhantomData,
3838
graph,
39-
map: FxHashMap(),
39+
map: Default::default(),
4040
}
4141
}
4242
}

src/librustc/dep_graph/graph.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,11 @@ impl DepGraph {
101101
DepGraph {
102102
data: Some(Lrc::new(DepGraphData {
103103
previous_work_products: prev_work_products,
104-
dep_node_debug: Lock::new(FxHashMap()),
104+
dep_node_debug: Lock::new(Default::default()),
105105
current: Lock::new(CurrentDepGraph::new()),
106106
previous: prev_graph,
107107
colors: Lock::new(DepNodeColorMap::new(prev_graph_node_count)),
108-
loaded_from_cache: Lock::new(FxHashMap()),
108+
loaded_from_cache: Lock::new(Default::default()),
109109
})),
110110
fingerprints: Lrc::new(Lock::new(fingerprints)),
111111
}
@@ -209,7 +209,7 @@ impl DepGraph {
209209
|key| OpenTask::Regular(Lock::new(RegularOpenTask {
210210
node: key,
211211
reads: SmallVec::new(),
212-
read_set: FxHashSet(),
212+
read_set: Default::default(),
213213
})),
214214
|data, key, task| data.borrow_mut().complete_task(key, task))
215215
}
@@ -353,7 +353,7 @@ impl DepGraph {
353353
let (result, open_task) = ty::tls::with_context(|icx| {
354354
let task = OpenTask::Anon(Lock::new(AnonOpenTask {
355355
reads: SmallVec::new(),
356-
read_set: FxHashSet(),
356+
read_set: Default::default(),
357357
}));
358358

359359
let r = {
@@ -937,7 +937,7 @@ impl CurrentDepGraph {
937937
CurrentDepGraph {
938938
nodes: IndexVec::new(),
939939
edges: IndexVec::new(),
940-
node_to_node_index: FxHashMap(),
940+
node_to_node_index: Default::default(),
941941
anon_id_seed: stable_hasher.finish(),
942942
forbidden_edge,
943943
total_read_count: 0,

src/librustc/dep_graph/prev.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_data_structures::fx::FxHashMap;
1313
use super::dep_node::DepNode;
1414
use super::serialized::{SerializedDepGraph, SerializedDepNodeIndex};
1515

16-
#[derive(Debug, RustcEncodable, RustcDecodable)]
16+
#[derive(Debug, RustcEncodable, RustcDecodable, Default)]
1717
pub struct PreviousDepGraph {
1818
data: SerializedDepGraph,
1919
index: FxHashMap<DepNode, SerializedDepNodeIndex>,

src/librustc/dep_graph/query.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ impl DepGraphQuery {
2525
edges: &[(DepNode, DepNode)])
2626
-> DepGraphQuery {
2727
let mut graph = Graph::with_capacity(nodes.len(), edges.len());
28-
let mut indices = FxHashMap();
28+
let mut indices = FxHashMap::default();
2929
for node in nodes {
3030
indices.insert(node.clone(), graph.add_node(node.clone()));
3131
}

src/librustc/dep_graph/serialized.rs

+1-11
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ newtype_index! {
1919
}
2020

2121
/// Data for use when recompiling the **current crate**.
22-
#[derive(Debug, RustcEncodable, RustcDecodable)]
22+
#[derive(Debug, RustcEncodable, RustcDecodable, Default)]
2323
pub struct SerializedDepGraph {
2424
/// The set of all DepNodes in the graph
2525
pub nodes: IndexVec<SerializedDepNodeIndex, DepNode>,
@@ -36,16 +36,6 @@ pub struct SerializedDepGraph {
3636
}
3737

3838
impl SerializedDepGraph {
39-
40-
pub fn new() -> SerializedDepGraph {
41-
SerializedDepGraph {
42-
nodes: IndexVec::new(),
43-
fingerprints: IndexVec::new(),
44-
edge_list_indices: IndexVec::new(),
45-
edge_list_data: Vec::new(),
46-
}
47-
}
48-
4939
#[inline]
5040
pub fn edge_targets_from(&self,
5141
source: SerializedDepNodeIndex)

src/librustc/hir/map/definitions.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -421,10 +421,10 @@ impl Definitions {
421421
node_to_def_index: NodeMap(),
422422
def_index_to_node: [vec![], vec![]],
423423
node_to_hir_id: IndexVec::new(),
424-
parent_modules_of_macro_defs: FxHashMap(),
425-
expansions_that_defined: FxHashMap(),
426-
next_disambiguator: FxHashMap(),
427-
def_index_to_span: FxHashMap(),
424+
parent_modules_of_macro_defs: Default::default(),
425+
expansions_that_defined: Default::default(),
426+
next_disambiguator: Default::default(),
427+
def_index_to_span: Default::default(),
428428
}
429429
}
430430

src/librustc/hir/map/hir_id_validator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl<'a, 'hir: 'a> OuterVisitor<'a, 'hir> {
5151
HirIdValidator {
5252
hir_map,
5353
owner_def_index: None,
54-
hir_ids_seen: FxHashMap(),
54+
hir_ids_seen: Default::default(),
5555
errors: Vec::new(),
5656
}
5757
}

src/librustc/ich/hcx.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for Span {
370370
// recursing every time.
371371
thread_local! {
372372
static CACHE: RefCell<FxHashMap<hygiene::Mark, u64>> =
373-
RefCell::new(FxHashMap());
373+
RefCell::new(Default::default());
374374
}
375375

376376
let sub_hash: u64 = CACHE.with(|cache| {

src/librustc/ich/impls_ty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ for &'gcx ty::List<T>
3232
hasher: &mut StableHasher<W>) {
3333
thread_local! {
3434
static CACHE: RefCell<FxHashMap<(usize, usize), Fingerprint>> =
35-
RefCell::new(FxHashMap());
35+
RefCell::new(Default::default());
3636
}
3737

3838
let hash = CACHE.with(|cache| {

src/librustc/infer/freshen.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl<'a, 'gcx, 'tcx> TypeFreshener<'a, 'gcx, 'tcx> {
6262
TypeFreshener {
6363
infcx,
6464
freshen_count: 0,
65-
freshen_map: FxHashMap(),
65+
freshen_map: Default::default(),
6666
}
6767
}
6868

0 commit comments

Comments
 (0)