File tree Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,10 @@ use rustc_index::vec::{Idx, IndexVec};
6
6
7
7
use crate :: * ;
8
8
9
+ /// We cannot use the `newtype_index!` macro because we have to use 0 as a
10
+ /// sentinel value meaning that the identifier is not assigned. This is because
11
+ /// the pthreads static initializers initialize memory with zeros (see the
12
+ /// `src/shims/sync.rs` file).
9
13
macro_rules! declare_id {
10
14
( $name: ident) => {
11
15
/// 0 is used to indicate that the id was not yet assigned and,
@@ -22,9 +26,13 @@ macro_rules! declare_id {
22
26
23
27
impl Idx for $name {
24
28
fn new( idx: usize ) -> Self {
29
+ // We use 0 as a sentinel value (see the comment above) and,
30
+ // therefore, need to shift by one when converting from an index
31
+ // into a vector.
25
32
$name( NonZeroU32 :: new( u32 :: try_from( idx) . unwrap( ) + 1 ) . unwrap( ) )
26
33
}
27
34
fn index( self ) -> usize {
35
+ // See the comment in `Self::new`.
28
36
usize :: try_from( self . 0 . get( ) - 1 ) . unwrap( )
29
37
}
30
38
}
You can’t perform that action at this time.
0 commit comments