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