]> git.lizzy.rs Git - rust.git/commitdiff
Change to a BTreeMap rather than sorting the keys of a FnvHashMap.
authorNiko Matsakis <niko@alum.mit.edu>
Wed, 18 Nov 2015 09:16:25 +0000 (04:16 -0500)
committerNiko Matsakis <niko@alum.mit.edu>
Thu, 19 Nov 2015 00:23:29 +0000 (19:23 -0500)
src/librustc_front/hir.rs
src/librustc_front/lowering.rs

index 4232254327cdec14221f85577018cc2c17603016..95d73daa632b15eaea6752a8f7d6c2d48ddde8bb 100644 (file)
@@ -36,7 +36,7 @@
 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 @@ pub fn item(&self, id: NodeId) -> &Item {
     /// 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);
         }
     }
index ad081598c1124a479221b9fe97d1914716aa9652..b984f23c4c02a8541bd63f8dad750fc597a6a1ed 100644 (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::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 @@ fn visit_item(&mut self, item: &'lcx Item) {
 
 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
     };