@@ -10,15 +10,10 @@ use crate::tokenstream::{DelimSpan, Spacing, TokenTree};
10
10
use crate :: tokenstream:: { LazyAttrTokenStream , TokenStream } ;
11
11
use crate :: util:: comments;
12
12
use crate :: util:: literal:: escape_string_symbol;
13
- use rustc_data_structures:: sync:: WorkerLocal ;
14
13
use rustc_index:: bit_set:: GrowableBitSet ;
15
14
use rustc_span:: symbol:: { sym, Ident , Symbol } ;
16
15
use rustc_span:: Span ;
17
- use std:: cell:: Cell ;
18
16
use std:: iter;
19
- #[ cfg( debug_assertions) ]
20
- use std:: ops:: BitXor ;
21
- #[ cfg( debug_assertions) ]
22
17
use std:: sync:: atomic:: { AtomicU32 , Ordering } ;
23
18
use thin_vec:: { thin_vec, ThinVec } ;
24
19
@@ -40,39 +35,16 @@ impl MarkedAttrs {
40
35
}
41
36
}
42
37
43
- pub struct AttrIdGenerator ( WorkerLocal < Cell < u32 > > ) ;
44
-
45
- #[ cfg( debug_assertions) ]
46
- static MAX_ATTR_ID : AtomicU32 = AtomicU32 :: new ( u32:: MAX ) ;
38
+ pub struct AttrIdGenerator ( AtomicU32 ) ;
47
39
48
40
impl AttrIdGenerator {
49
41
pub fn new ( ) -> Self {
50
- // We use `(index as u32).reverse_bits()` to initialize the
51
- // starting value of AttrId in each worker thread.
52
- // The `index` is the index of the worker thread.
53
- // This ensures that the AttrId generated in each thread is unique.
54
- AttrIdGenerator ( WorkerLocal :: new ( |index| {
55
- let index: u32 = index. try_into ( ) . unwrap ( ) ;
56
-
57
- #[ cfg( debug_assertions) ]
58
- {
59
- let max_id = ( ( index + 1 ) . next_power_of_two ( ) - 1 ) . bitxor ( u32:: MAX ) . reverse_bits ( ) ;
60
- MAX_ATTR_ID . fetch_min ( max_id, Ordering :: Release ) ;
61
- }
62
-
63
- Cell :: new ( index. reverse_bits ( ) )
64
- } ) )
42
+ AttrIdGenerator ( AtomicU32 :: new ( 0 ) )
65
43
}
66
44
67
45
pub fn mk_attr_id ( & self ) -> AttrId {
68
- let id = self . 0 . get ( ) ;
69
-
70
- // Ensure the assigned attr_id does not overlap the bits
71
- // representing the number of threads.
72
- #[ cfg( debug_assertions) ]
73
- assert ! ( id <= MAX_ATTR_ID . load( Ordering :: Acquire ) ) ;
74
-
75
- self . 0 . set ( id + 1 ) ;
46
+ let id = self . 0 . fetch_add ( 1 , Ordering :: Relaxed ) ;
47
+ assert ! ( id != u32 :: MAX ) ;
76
48
AttrId :: from_u32 ( id)
77
49
}
78
50
}
0 commit comments