Change to a BTreeMap rather than sorting the keys of a FnvHashMap.

This commit is contained in:
Niko Matsakis 2015-11-18 04:16:25 -05:00
parent db97c93c99
commit e303c250f1
2 changed files with 13 additions and 15 deletions

View File

@ -36,7 +36,7 @@ pub use self::Visibility::*;
pub use self::PathParameters::*;
use intravisit::Visitor;
use rustc_data_structures::fnv::FnvHashMap;
use std::collections::BTreeMap;
use syntax::codemap::{self, Span, Spanned, DUMMY_SP, ExpnId};
use syntax::abi::Abi;
use syntax::ast::{Name, Ident, NodeId, DUMMY_NODE_ID, TokenTree, AsmDialect};
@ -329,7 +329,14 @@ pub struct Crate {
pub config: CrateConfig,
pub span: Span,
pub exported_macros: Vec<MacroDef>,
pub items: FnvHashMap<NodeId, Item>,
// NB: We use a BTreeMap here so that `visit_all_items` iterates
// over the ids in increasing order. In principle it should not
// matter what order we visit things in, but in *practice* it
// does, because it can affect the order in which errors are
// detected, which in turn can make compile-fail tests yield
// slightly different results.
pub items: BTreeMap<NodeId, Item>,
}
impl Crate {
@ -346,15 +353,7 @@ impl Crate {
/// approach. You should override `visit_nested_item` in your
/// visitor and then call `intravisit::walk_crate` instead.
pub fn visit_all_items<'hir, V:Visitor<'hir>>(&'hir self, visitor: &mut V) {
// In principle, we could just iterate over the hashmap, but
// in practice that makes the order of error reporting vary
// with small changes in the input etc etc, which makes the
// test base hard to maintain. So instead we sort by node-id
// so as to get reproducible results.
let mut pairs: Vec<_> = self.items.iter().collect();
pairs.sort_by(|&(id1, _), &(id2, _)| id1.cmp(id2));
for (_, item) in pairs {
for (_, item) in &self.items {
visitor.visit_item(item);
}
}

View File

@ -63,8 +63,8 @@
use hir;
use std::collections::BTreeMap;
use std::collections::HashMap;
use syntax::ast::*;
use syntax::ptr::P;
use syntax::codemap::{respan, Spanned, Span};
@ -72,7 +72,6 @@ use syntax::owned_slice::OwnedSlice;
use syntax::parse::token::{self, str_to_ident};
use syntax::std_inject;
use syntax::visit::{self, Visitor};
use rustc_data_structures::fnv::FnvHashMap;
use std::cell::{Cell, RefCell};
@ -700,7 +699,7 @@ pub fn lower_mod(lctx: &LoweringContext, m: &Mod) -> hir::Mod {
}
struct ItemLowerer<'lcx, 'interner: 'lcx> {
items: FnvHashMap<NodeId, hir::Item>,
items: BTreeMap<NodeId, hir::Item>,
lctx: &'lcx LoweringContext<'interner>,
}
@ -713,7 +712,7 @@ impl<'lcx, 'interner> Visitor<'lcx> for ItemLowerer<'lcx, 'interner> {
pub fn lower_crate(lctx: &LoweringContext, c: &Crate) -> hir::Crate {
let items = {
let mut item_lowerer = ItemLowerer { items: FnvHashMap(), lctx: lctx };
let mut item_lowerer = ItemLowerer { items: BTreeMap::new(), lctx: lctx };
visit::walk_crate(&mut item_lowerer, c);
item_lowerer.items
};