@@ -45,6 +45,7 @@ use rustc_ast_pretty::pprust;
4545use rustc_data_structures:: captures:: Captures ;
4646use rustc_data_structures:: fingerprint:: Fingerprint ;
4747use rustc_data_structures:: fx:: FxHashSet ;
48+ use rustc_data_structures:: sorted_map:: SortedMap ;
4849use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
4950use rustc_data_structures:: sync:: Lrc ;
5051use rustc_errors:: { struct_span_err, Applicability } ;
@@ -67,7 +68,6 @@ use rustc_span::symbol::{kw, sym, Ident, Symbol};
6768use rustc_span:: { Span , DUMMY_SP } ;
6869
6970use smallvec:: SmallVec ;
70- use std:: collections:: BTreeMap ;
7171use tracing:: { debug, trace} ;
7272
7373macro_rules! arena_vec {
@@ -104,9 +104,9 @@ struct LoweringContext<'a, 'hir: 'a> {
104104 /// The items being lowered are collected here.
105105 owners : IndexVec < LocalDefId , Option < hir:: OwnerInfo < ' hir > > > ,
106106 /// Bodies inside the owner being lowered.
107- bodies : IndexVec < hir:: ItemLocalId , Option < & ' hir hir:: Body < ' hir > > > ,
107+ bodies : Vec < ( hir:: ItemLocalId , & ' hir hir:: Body < ' hir > ) > ,
108108 /// Attributes inside the owner being lowered.
109- attrs : BTreeMap < hir:: ItemLocalId , & ' hir [ Attribute ] > ,
109+ attrs : SortedMap < hir:: ItemLocalId , & ' hir [ Attribute ] > ,
110110
111111 generator_kind : Option < hir:: GeneratorKind > ,
112112
@@ -301,8 +301,8 @@ pub fn lower_crate<'a, 'hir>(
301301 nt_to_tokenstream,
302302 arena,
303303 owners,
304- bodies : IndexVec :: new ( ) ,
305- attrs : BTreeMap :: default ( ) ,
304+ bodies : Vec :: new ( ) ,
305+ attrs : SortedMap :: new ( ) ,
306306 catch_scope : None ,
307307 loop_scope : None ,
308308 is_in_loop_condition : false ,
@@ -479,7 +479,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
479479
480480 fn make_owner_info ( & mut self , node : hir:: OwnerNode < ' hir > ) -> hir:: OwnerInfo < ' hir > {
481481 let attrs = std:: mem:: take ( & mut self . attrs ) ;
482- let bodies = std:: mem:: take ( & mut self . bodies ) ;
482+ let mut bodies = std:: mem:: take ( & mut self . bodies ) ;
483483 let local_node_ids = std:: mem:: take ( & mut self . local_node_ids ) ;
484484 let trait_map = local_node_ids
485485 . into_iter ( )
@@ -491,13 +491,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
491491 . collect ( ) ;
492492
493493 #[ cfg( debug_assertions) ]
494- for ( & id, attrs) in attrs. iter ( ) {
494+ for ( id, attrs) in attrs. iter ( ) {
495495 // Verify that we do not store empty slices in the map.
496496 if attrs. is_empty ( ) {
497497 panic ! ( "Stored empty attributes for {:?}" , id) ;
498498 }
499499 }
500500
501+ bodies. sort_by_key ( |( k, _) | * k) ;
502+ let bodies = SortedMap :: from_presorted_elements ( bodies) ;
501503 let ( hash_including_bodies, hash_without_bodies) = self . hash_owner ( node, & bodies) ;
502504 let ( nodes, parenting) =
503505 index:: index_hir ( self . sess , self . resolver . definitions ( ) , node, & bodies) ;
@@ -518,7 +520,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
518520 fn hash_owner (
519521 & mut self ,
520522 node : hir:: OwnerNode < ' hir > ,
521- bodies : & IndexVec < hir:: ItemLocalId , Option < & ' hir hir:: Body < ' hir > > > ,
523+ bodies : & SortedMap < hir:: ItemLocalId , & ' hir hir:: Body < ' hir > > ,
522524 ) -> ( Fingerprint , Fingerprint ) {
523525 let mut hcx = self . resolver . create_stable_hashing_context ( ) ;
524526 let mut stable_hasher = StableHasher :: new ( ) ;
0 commit comments