@@ -44,6 +44,7 @@ use rustc_ast_pretty::pprust;
44
44
use rustc_data_structures:: captures:: Captures ;
45
45
use rustc_data_structures:: fingerprint:: Fingerprint ;
46
46
use rustc_data_structures:: fx:: FxHashSet ;
47
+ use rustc_data_structures:: sorted_map:: SortedMap ;
47
48
use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
48
49
use rustc_data_structures:: sync:: Lrc ;
49
50
use rustc_errors:: { struct_span_err, Applicability } ;
@@ -66,7 +67,6 @@ use rustc_span::symbol::{kw, sym, Ident, Symbol};
66
67
use rustc_span:: { Span , DUMMY_SP } ;
67
68
68
69
use smallvec:: SmallVec ;
69
- use std:: collections:: BTreeMap ;
70
70
use tracing:: { debug, trace} ;
71
71
72
72
macro_rules! arena_vec {
@@ -103,9 +103,9 @@ struct LoweringContext<'a, 'hir: 'a> {
103
103
/// The items being lowered are collected here.
104
104
owners : IndexVec < LocalDefId , Option < hir:: OwnerInfo < ' hir > > > ,
105
105
/// 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 > ) > ,
107
107
/// Attributes inside the owner being lowered.
108
- attrs : BTreeMap < hir:: ItemLocalId , & ' hir [ Attribute ] > ,
108
+ attrs : SortedMap < hir:: ItemLocalId , & ' hir [ Attribute ] > ,
109
109
110
110
generator_kind : Option < hir:: GeneratorKind > ,
111
111
@@ -300,8 +300,8 @@ pub fn lower_crate<'a, 'hir>(
300
300
nt_to_tokenstream,
301
301
arena,
302
302
owners,
303
- bodies : IndexVec :: new ( ) ,
304
- attrs : BTreeMap :: default ( ) ,
303
+ bodies : Vec :: new ( ) ,
304
+ attrs : SortedMap :: new ( ) ,
305
305
catch_scope : None ,
306
306
loop_scope : None ,
307
307
is_in_loop_condition : false ,
@@ -478,7 +478,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
478
478
479
479
fn make_owner_info ( & mut self , node : hir:: OwnerNode < ' hir > ) -> hir:: OwnerInfo < ' hir > {
480
480
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 ) ;
482
482
let local_node_ids = std:: mem:: take ( & mut self . local_node_ids ) ;
483
483
let trait_map = local_node_ids
484
484
. into_iter ( )
@@ -490,13 +490,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
490
490
. collect ( ) ;
491
491
492
492
#[ cfg( debug_assertions) ]
493
- for ( & id, attrs) in attrs. iter ( ) {
493
+ for ( id, attrs) in attrs. iter ( ) {
494
494
// Verify that we do not store empty slices in the map.
495
495
if attrs. is_empty ( ) {
496
496
panic ! ( "Stored empty attributes for {:?}" , id) ;
497
497
}
498
498
}
499
499
500
+ bodies. sort_by_key ( |( k, _) | * k) ;
501
+ let bodies = SortedMap :: from_presorted_elements ( bodies) ;
500
502
let ( hash_including_bodies, hash_without_bodies) = self . hash_owner ( node, & bodies) ;
501
503
let ( nodes, parenting) =
502
504
index:: index_hir ( self . sess , self . resolver . definitions ( ) , node, & bodies) ;
@@ -517,7 +519,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
517
519
fn hash_owner (
518
520
& mut self ,
519
521
node : hir:: OwnerNode < ' hir > ,
520
- bodies : & IndexVec < hir:: ItemLocalId , Option < & ' hir hir:: Body < ' hir > > > ,
522
+ bodies : & SortedMap < hir:: ItemLocalId , & ' hir hir:: Body < ' hir > > ,
521
523
) -> ( Fingerprint , Fingerprint ) {
522
524
let mut hcx = self . resolver . create_stable_hashing_context ( ) ;
523
525
let mut stable_hasher = StableHasher :: new ( ) ;
0 commit comments