From e303c250f11c470b57688399959cfef017668ed7 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Wed, 18 Nov 2015 04:16:25 -0500 Subject: [PATCH] Change to a BTreeMap rather than sorting the keys of a FnvHashMap. --- src/librustc_front/hir.rs | 21 ++++++++++----------- src/librustc_front/lowering.rs | 7 +++---- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/librustc_front/hir.rs b/src/librustc_front/hir.rs index 4232254327cd..95d73daa632b 100644 --- a/src/librustc_front/hir.rs +++ b/src/librustc_front/hir.rs @@ -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, - pub items: FnvHashMap, + + // 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, } 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); } } diff --git a/src/librustc_front/lowering.rs b/src/librustc_front/lowering.rs index ad081598c112..b984f23c4c02 100644 --- a/src/librustc_front/lowering.rs +++ b/src/librustc_front/lowering.rs @@ -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, + items: BTreeMap, 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 };