diff --git a/compiler/rustc_data_structures/src/sharded.rs b/compiler/rustc_data_structures/src/sharded.rs index 9f5c97ae798e3..40cbf14958e77 100644 --- a/compiler/rustc_data_structures/src/sharded.rs +++ b/compiler/rustc_data_structures/src/sharded.rs @@ -20,6 +20,9 @@ pub const SHARDS: usize = 1 << SHARD_BITS; /// An array of cache-line aligned inner locked structures with convenience methods. pub struct Sharded { + /// This mask is used to ensure that accesses are inbounds of `shards`. + /// When dynamic thread safety is off, this field is set to 0 causing only + /// a single shard to be used for greater cache efficiency. #[cfg(parallel_compiler)] mask: usize, shards: [CacheAligned>; SHARDS], @@ -56,6 +59,7 @@ impl Sharded { #[inline(always)] fn count(&self) -> usize { + // `self.mask` is always one below the used shard count self.mask() + 1 }