@@ -30,7 +30,7 @@ use crate::with_session_globals;
3030use crate :: { HashStableContext , Span , DUMMY_SP } ;
3131
3232use crate :: def_id:: { CrateNum , DefId , StableCrateId , CRATE_DEF_ID , LOCAL_CRATE } ;
33- use rustc_data_structures:: fingerprint:: { Fingerprint , PackedFingerprint } ;
33+ use rustc_data_structures:: fingerprint:: Fingerprint ;
3434use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
3535use rustc_data_structures:: stable_hasher:: HashingControls ;
3636use rustc_data_structures:: stable_hasher:: { Hash64 , HashStable , StableHasher } ;
@@ -195,11 +195,12 @@ impl LocalExpnId {
195195 #[ instrument( level = "trace" , skip( ctx) , ret) ]
196196 pub fn create_untracked_expansion (
197197 mut expn_data : ExpnData ,
198- dep_node : FakeDepNode ,
198+ hash_extra : impl Hash + Copy + fmt :: Debug ,
199199 ctx : impl HashStableContext ,
200+ disambiguation_map : & Lock < UnhashMap < Hash64 , u32 > > ,
200201 ) -> LocalExpnId {
201202 debug_assert_eq ! ( expn_data. parent. krate, LOCAL_CRATE ) ;
202- let expn_hash = update_disambiguator ( & mut expn_data, dep_node , ctx) ;
203+ let expn_hash = update_disambiguator ( & mut expn_data, hash_extra , ctx, disambiguation_map ) ;
203204 HygieneData :: with ( |data| {
204205 let expn_id = data. local_expn_data . push ( Some ( expn_data) ) ;
205206 let _eid = data. local_expn_hashes . push ( expn_hash) ;
@@ -218,11 +219,12 @@ impl LocalExpnId {
218219 pub fn set_untracked_expn_data (
219220 self ,
220221 mut expn_data : ExpnData ,
221- dep_node : FakeDepNode ,
222+ hash_extra : impl Hash + Copy + fmt :: Debug ,
222223 ctx : impl HashStableContext ,
224+ disambiguation_map : & Lock < UnhashMap < Hash64 , u32 > > ,
223225 ) {
224226 debug_assert_eq ! ( expn_data. parent. krate, LOCAL_CRATE ) ;
225- let expn_hash = update_disambiguator ( & mut expn_data, dep_node , ctx) ;
227+ let expn_hash = update_disambiguator ( & mut expn_data, hash_extra , ctx, disambiguation_map ) ;
226228 HygieneData :: with ( |data| {
227229 let old_expn_data = & mut data. local_expn_data [ self ] ;
228230 assert ! ( old_expn_data. is_none( ) , "expansion data is reset for an expansion ID" ) ;
@@ -349,14 +351,6 @@ impl ExpnId {
349351 }
350352}
351353
352- /// This struct is meant to be a surrogate for the actual `DepNode` in rustc_middle.
353- /// Both types should be kept in sync.
354- #[ derive( Copy , Clone , Debug , Hash , PartialEq , Eq ) ]
355- pub struct FakeDepNode {
356- pub kind : u16 ,
357- pub hash : PackedFingerprint ,
358- }
359-
360354#[ derive( Debug ) ]
361355pub struct HygieneData {
362356 /// Each expansion should have an associated expansion data, but sometimes there's a delay
@@ -371,12 +365,6 @@ pub struct HygieneData {
371365 expn_hash_to_expn_id : UnhashMap < ExpnHash , ExpnId > ,
372366 syntax_context_data : Vec < SyntaxContextData > ,
373367 syntax_context_map : FxHashMap < ( SyntaxContext , ExpnId , Transparency ) , SyntaxContext > ,
374- /// Maps the `local_hash` of an `ExpnData` to the next disambiguator value.
375- /// This is used by `update_disambiguator` to keep track of which `ExpnData`s
376- /// would have collisions without a disambiguator.
377- /// The keys of this map are always computed with `ExpnData.disambiguator`
378- /// set to 0.
379- expn_data_disambiguators : FxHashMap < FakeDepNode , FxHashMap < Hash64 , u32 > > ,
380368}
381369
382370impl HygieneData {
@@ -405,7 +393,6 @@ impl HygieneData {
405393 dollar_crate_name: kw:: DollarCrate ,
406394 } ] ,
407395 syntax_context_map : FxHashMap :: default ( ) ,
408- expn_data_disambiguators : FxHashMap :: default ( ) ,
409396 }
410397 }
411398
@@ -1049,10 +1036,10 @@ impl ExpnData {
10491036 }
10501037
10511038 #[ inline]
1052- fn hash_expn ( & self , dep_node : FakeDepNode , ctx : & mut impl HashStableContext ) -> Hash64 {
1039+ fn hash_expn ( & self , hash_extra : impl Hash , ctx : & mut impl HashStableContext ) -> Hash64 {
10531040 let mut hasher = StableHasher :: new ( ) ;
10541041 self . hash_stable ( ctx, & mut hasher) ;
1055- dep_node . hash ( & mut hasher) ;
1042+ hash_extra . hash ( & mut hasher) ;
10561043 hasher. finish ( )
10571044 }
10581045}
@@ -1478,44 +1465,38 @@ impl<D: Decoder> Decodable<D> for SyntaxContext {
14781465#[ instrument( level = "trace" , skip( ctx) , ret) ]
14791466fn update_disambiguator (
14801467 expn_data : & mut ExpnData ,
1481- dep_node : FakeDepNode ,
1468+ hash_extra : impl Hash + Copy + fmt :: Debug ,
14821469 mut ctx : impl HashStableContext ,
1470+ disambiguation_map : & Lock < UnhashMap < Hash64 , u32 > > ,
14831471) -> ExpnHash {
14841472 // This disambiguator should not have been set yet.
14851473 assert_eq ! ( expn_data. disambiguator, 0 , "Already set disambiguator for ExpnData: {expn_data:?}" ) ;
14861474 assert_default_hashing_controls ( & ctx, "ExpnData (disambiguator)" ) ;
1487- let mut expn_hash = expn_data. hash_expn ( dep_node , & mut ctx) ;
1475+ let mut expn_hash = expn_data. hash_expn ( hash_extra , & mut ctx) ;
14881476 debug ! ( ?expn_hash) ;
14891477
1490- let disambiguator = HygieneData :: with ( |data| {
1478+ let disambiguator = {
14911479 // If this is the first ExpnData with a given hash, then keep our
14921480 // disambiguator at 0 (the default u32 value)
1493- let disambig = data
1494- . expn_data_disambiguators
1495- . entry ( dep_node)
1496- . or_default ( )
1497- . entry ( expn_hash)
1498- . or_default ( ) ;
1481+ let mut disambiguation_map = disambiguation_map. lock ( ) ;
1482+ let disambig = disambiguation_map. entry ( expn_hash) . or_default ( ) ;
14991483 let disambiguator = * disambig;
15001484 * disambig += 1 ;
15011485 disambiguator
1502- } ) ;
1486+ } ;
15031487
15041488 if disambiguator != 0 {
15051489 debug ! ( "Set disambiguator for expn_data={:?} expn_hash={:?}" , expn_data, expn_hash) ;
15061490
15071491 expn_data. disambiguator = disambiguator;
1508- expn_hash = expn_data. hash_expn ( dep_node , & mut ctx) ;
1492+ expn_hash = expn_data. hash_expn ( hash_extra , & mut ctx) ;
15091493
15101494 // Verify that the new disambiguator makes the hash unique
1511- #[ cfg( debug_assertions) ]
1512- HygieneData :: with ( |data| {
1513- assert_eq ! (
1514- data. expn_data_disambiguators[ & dep_node] . get( & expn_hash) ,
1515- None ,
1516- "Hash collision after disambiguator update!" ,
1517- ) ;
1518- } ) ;
1495+ debug_assert_eq ! (
1496+ disambiguation_map. lock( ) . get( & expn_hash) ,
1497+ None ,
1498+ "Hash collision after disambiguator update!" ,
1499+ ) ;
15191500 }
15201501
15211502 ExpnHash :: new ( ctx. def_path_hash ( LOCAL_CRATE . as_def_id ( ) ) . stable_crate_id ( ) , expn_hash)
0 commit comments