Skip to content

Commit 418a118

Browse files
committed
Change to a BTreeMap rather than sorting the keys of a FnvHashMap.
1 parent bbe8e9e commit 418a118

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

src/librustc_front/hir.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub use self::Visibility::*;
3636
pub use self::PathParameters::*;
3737

3838
use intravisit::Visitor;
39-
use rustc_data_structures::fnv::FnvHashMap;
39+
use std::collections::BTreeMap;
4040
use syntax::codemap::{self, Span, Spanned, DUMMY_SP, ExpnId};
4141
use syntax::abi::Abi;
4242
use syntax::ast::{Name, Ident, NodeId, DUMMY_NODE_ID, TokenTree, AsmDialect};
@@ -329,7 +329,14 @@ pub struct Crate {
329329
pub config: CrateConfig,
330330
pub span: Span,
331331
pub exported_macros: Vec<MacroDef>,
332-
pub items: FnvHashMap<NodeId, Item>,
332+
333+
// NB: We use a BTreeMap here so that `visit_all_items` iterates
334+
// over the ids in increasing order. In principle it should not
335+
// matter what order we visit things in, but in *practice* it
336+
// does, because it can affect the order in which errors are
337+
// detected, which in turn can make compile-fail tests yield
338+
// slightly different results.
339+
pub items: BTreeMap<NodeId, Item>,
333340
}
334341

335342
impl Crate {
@@ -346,15 +353,7 @@ impl Crate {
346353
/// approach. You should override `visit_nested_item` in your
347354
/// visitor and then call `intravisit::walk_crate` instead.
348355
pub fn visit_all_items<'hir, V:Visitor<'hir>>(&'hir self, visitor: &mut V) {
349-
// In principle, we could just iterate over the hashmap, but
350-
// in practice that makes the order of error reporting vary
351-
// with small changes in the input etc etc, which makes the
352-
// test base hard to maintain. So instead we sort by node-id
353-
// so as to get reproducible results.
354-
let mut pairs: Vec<_> = self.items.iter().collect();
355-
pairs.sort_by(|&(id1, _), &(id2, _)| id1.cmp(id2));
356-
357-
for (_, item) in pairs {
356+
for (_, item) in &self.items {
358357
visitor.visit_item(item);
359358
}
360359
}

src/librustc_front/lowering.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,15 @@
6363

6464
use hir;
6565

66+
use std::collections::BTreeMap;
6667
use std::collections::HashMap;
67-
6868
use syntax::ast::*;
6969
use syntax::ptr::P;
7070
use syntax::codemap::{respan, Spanned, Span};
7171
use syntax::owned_slice::OwnedSlice;
7272
use syntax::parse::token::{self, str_to_ident};
7373
use syntax::std_inject;
7474
use syntax::visit::{self, Visitor};
75-
use rustc_data_structures::fnv::FnvHashMap;
7675

7776
use std::cell::{Cell, RefCell};
7877

@@ -700,7 +699,7 @@ pub fn lower_mod(lctx: &LoweringContext, m: &Mod) -> hir::Mod {
700699
}
701700

702701
struct ItemLowerer<'lcx, 'interner: 'lcx> {
703-
items: FnvHashMap<NodeId, hir::Item>,
702+
items: BTreeMap<NodeId, hir::Item>,
704703
lctx: &'lcx LoweringContext<'interner>,
705704
}
706705

@@ -713,7 +712,7 @@ impl<'lcx, 'interner> Visitor<'lcx> for ItemLowerer<'lcx, 'interner> {
713712

714713
pub fn lower_crate(lctx: &LoweringContext, c: &Crate) -> hir::Crate {
715714
let items = {
716-
let mut item_lowerer = ItemLowerer { items: FnvHashMap(), lctx: lctx };
715+
let mut item_lowerer = ItemLowerer { items: BTreeMap::new(), lctx: lctx };
717716
visit::walk_crate(&mut item_lowerer, c);
718717
item_lowerer.items
719718
};

0 commit comments

Comments
 (0)