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};
66
77use crate :: * ;
88
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).
913macro_rules! declare_id {
1014 ( $name: ident) => {
1115 /// 0 is used to indicate that the id was not yet assigned and,
@@ -22,9 +26,13 @@ macro_rules! declare_id {
2226
2327 impl Idx for $name {
2428 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.
2532 $name( NonZeroU32 :: new( u32 :: try_from( idx) . unwrap( ) + 1 ) . unwrap( ) )
2633 }
2734 fn index( self ) -> usize {
35+ // See the comment in `Self::new`.
2836 usize :: try_from( self . 0 . get( ) - 1 ) . unwrap( )
2937 }
3038 }
You can’t perform that action at this time.
0 commit comments