@@ -44,6 +44,7 @@ use rustc_ast_pretty::pprust;
4444use rustc_data_structures:: captures:: Captures ;
4545use rustc_data_structures:: fingerprint:: Fingerprint ;
4646use rustc_data_structures:: fx:: FxHashSet ;
47+ use rustc_data_structures:: sorted_map:: SortedMap ;
4748use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
4849use rustc_data_structures:: sync:: Lrc ;
4950use rustc_errors:: { struct_span_err, Applicability } ;
@@ -66,7 +67,6 @@ use rustc_span::symbol::{kw, sym, Ident, Symbol};
6667use rustc_span:: { Span , DUMMY_SP } ;
6768
6869use smallvec:: SmallVec ;
69- use std:: collections:: BTreeMap ;
7070use tracing:: { debug, trace} ;
7171
7272macro_rules! arena_vec {
@@ -103,9 +103,9 @@ struct LoweringContext<'a, 'hir: 'a> {
103103 /// The items being lowered are collected here.
104104 owners : IndexVec < LocalDefId , Option < hir:: OwnerInfo < ' hir > > > ,
105105 /// Bodies inside the owner being lowered.
106- bodies : IndexVec < hir:: ItemLocalId , Option < & ' hir hir:: Body < ' hir > > > ,
106+ bodies : Vec < ( hir:: ItemLocalId , & ' hir hir:: Body < ' hir > ) > ,
107107 /// Attributes inside the owner being lowered.
108- attrs : BTreeMap < hir:: ItemLocalId , & ' hir [ Attribute ] > ,
108+ attrs : SortedMap < hir:: ItemLocalId , & ' hir [ Attribute ] > ,
109109
110110 generator_kind : Option < hir:: GeneratorKind > ,
111111
@@ -300,8 +300,8 @@ pub fn lower_crate<'a, 'hir>(
300300 nt_to_tokenstream,
301301 arena,
302302 owners,
303- bodies : IndexVec :: new ( ) ,
304- attrs : BTreeMap :: default ( ) ,
303+ bodies : Vec :: new ( ) ,
304+ attrs : SortedMap :: new ( ) ,
305305 catch_scope : None ,
306306 loop_scope : None ,
307307 is_in_loop_condition : false ,
@@ -478,7 +478,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
478478
479479 fn make_owner_info ( & mut self , node : hir:: OwnerNode < ' hir > ) -> hir:: OwnerInfo < ' hir > {
480480 let attrs = std:: mem:: take ( & mut self . attrs ) ;
481- let bodies = std:: mem:: take ( & mut self . bodies ) ;
481+ let mut bodies = std:: mem:: take ( & mut self . bodies ) ;
482482 let local_node_ids = std:: mem:: take ( & mut self . local_node_ids ) ;
483483 let trait_map = local_node_ids
484484 . into_iter ( )
@@ -490,13 +490,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
490490 . collect ( ) ;
491491
492492 #[ cfg( debug_assertions) ]
493- for ( & id, attrs) in attrs. iter ( ) {
493+ for ( id, attrs) in attrs. iter ( ) {
494494 // Verify that we do not store empty slices in the map.
495495 if attrs. is_empty ( ) {
496496 panic ! ( "Stored empty attributes for {:?}" , id) ;
497497 }
498498 }
499499
500+ bodies. sort_by_key ( |( k, _) | * k) ;
501+ let bodies = SortedMap :: from_presorted_elements ( bodies) ;
500502 let ( hash_including_bodies, hash_without_bodies) = self . hash_owner ( node, & bodies) ;
501503 let ( nodes, parenting) =
502504 index:: index_hir ( self . sess , self . resolver . definitions ( ) , node, & bodies) ;
@@ -517,7 +519,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
517519 fn hash_owner (
518520 & mut self ,
519521 node : hir:: OwnerNode < ' hir > ,
520- bodies : & IndexVec < hir:: ItemLocalId , Option < & ' hir hir:: Body < ' hir > > > ,
522+ bodies : & SortedMap < hir:: ItemLocalId , & ' hir hir:: Body < ' hir > > ,
521523 ) -> ( Fingerprint , Fingerprint ) {
522524 let mut hcx = self . resolver . create_stable_hashing_context ( ) ;
523525 let mut stable_hasher = StableHasher :: new ( ) ;
0 commit comments