@@ -30,7 +30,7 @@ use crate::with_session_globals;
30
30
use crate :: { HashStableContext , Span , DUMMY_SP } ;
31
31
32
32
use 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 ;
34
34
use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
35
35
use rustc_data_structures:: stable_hasher:: HashingControls ;
36
36
use rustc_data_structures:: stable_hasher:: { Hash64 , HashStable , StableHasher } ;
@@ -195,11 +195,12 @@ impl LocalExpnId {
195
195
#[ instrument( level = "trace" , skip( ctx) , ret) ]
196
196
pub fn create_untracked_expansion (
197
197
mut expn_data : ExpnData ,
198
- dep_node : FakeDepNode ,
198
+ hash_extra : impl Hash + Copy + fmt :: Debug ,
199
199
ctx : impl HashStableContext ,
200
+ disambiguation_map : & Lock < UnhashMap < Hash64 , u32 > > ,
200
201
) -> LocalExpnId {
201
202
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 ) ;
203
204
HygieneData :: with ( |data| {
204
205
let expn_id = data. local_expn_data . push ( Some ( expn_data) ) ;
205
206
let _eid = data. local_expn_hashes . push ( expn_hash) ;
@@ -218,11 +219,12 @@ impl LocalExpnId {
218
219
pub fn set_untracked_expn_data (
219
220
self ,
220
221
mut expn_data : ExpnData ,
221
- dep_node : FakeDepNode ,
222
+ hash_extra : impl Hash + Copy + fmt :: Debug ,
222
223
ctx : impl HashStableContext ,
224
+ disambiguation_map : & Lock < UnhashMap < Hash64 , u32 > > ,
223
225
) {
224
226
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 ) ;
226
228
HygieneData :: with ( |data| {
227
229
let old_expn_data = & mut data. local_expn_data [ self ] ;
228
230
assert ! ( old_expn_data. is_none( ) , "expansion data is reset for an expansion ID" ) ;
@@ -349,14 +351,6 @@ impl ExpnId {
349
351
}
350
352
}
351
353
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
-
360
354
#[ derive( Debug ) ]
361
355
pub struct HygieneData {
362
356
/// Each expansion should have an associated expansion data, but sometimes there's a delay
@@ -371,12 +365,6 @@ pub struct HygieneData {
371
365
expn_hash_to_expn_id : UnhashMap < ExpnHash , ExpnId > ,
372
366
syntax_context_data : Vec < SyntaxContextData > ,
373
367
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 > > ,
380
368
}
381
369
382
370
impl HygieneData {
@@ -405,7 +393,6 @@ impl HygieneData {
405
393
dollar_crate_name: kw:: DollarCrate ,
406
394
} ] ,
407
395
syntax_context_map : FxHashMap :: default ( ) ,
408
- expn_data_disambiguators : FxHashMap :: default ( ) ,
409
396
}
410
397
}
411
398
@@ -1049,10 +1036,10 @@ impl ExpnData {
1049
1036
}
1050
1037
1051
1038
#[ 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 {
1053
1040
let mut hasher = StableHasher :: new ( ) ;
1054
1041
self . hash_stable ( ctx, & mut hasher) ;
1055
- dep_node . hash ( & mut hasher) ;
1042
+ hash_extra . hash ( & mut hasher) ;
1056
1043
hasher. finish ( )
1057
1044
}
1058
1045
}
@@ -1478,44 +1465,38 @@ impl<D: Decoder> Decodable<D> for SyntaxContext {
1478
1465
#[ instrument( level = "trace" , skip( ctx) , ret) ]
1479
1466
fn update_disambiguator (
1480
1467
expn_data : & mut ExpnData ,
1481
- dep_node : FakeDepNode ,
1468
+ hash_extra : impl Hash + Copy + fmt :: Debug ,
1482
1469
mut ctx : impl HashStableContext ,
1470
+ disambiguation_map : & Lock < UnhashMap < Hash64 , u32 > > ,
1483
1471
) -> ExpnHash {
1484
1472
// This disambiguator should not have been set yet.
1485
1473
assert_eq ! ( expn_data. disambiguator, 0 , "Already set disambiguator for ExpnData: {expn_data:?}" ) ;
1486
1474
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) ;
1488
1476
debug ! ( ?expn_hash) ;
1489
1477
1490
- let disambiguator = HygieneData :: with ( |data| {
1478
+ let disambiguator = {
1491
1479
// If this is the first ExpnData with a given hash, then keep our
1492
1480
// 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 ( ) ;
1499
1483
let disambiguator = * disambig;
1500
1484
* disambig += 1 ;
1501
1485
disambiguator
1502
- } ) ;
1486
+ } ;
1503
1487
1504
1488
if disambiguator != 0 {
1505
1489
debug ! ( "Set disambiguator for expn_data={:?} expn_hash={:?}" , expn_data, expn_hash) ;
1506
1490
1507
1491
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) ;
1509
1493
1510
1494
// 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
+ ) ;
1519
1500
}
1520
1501
1521
1502
ExpnHash :: new ( ctx. def_path_hash ( LOCAL_CRATE . as_def_id ( ) ) . stable_crate_id ( ) , expn_hash)
0 commit comments