From f30c5956f5a755c532cc2a29f089a908bc0201fe Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Mon, 11 Dec 2023 21:52:56 +0100 Subject: [PATCH] Make `rustc_index::bit_set` available on stable --- compiler/rustc_index/src/bit_set.rs | 48 ++++++++++++++++++++++------- compiler/rustc_index/src/lib.rs | 1 - 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/compiler/rustc_index/src/bit_set.rs b/compiler/rustc_index/src/bit_set.rs index d0b4889b45f..3ea1a52ae28 100644 --- a/compiler/rustc_index/src/bit_set.rs +++ b/compiler/rustc_index/src/bit_set.rs @@ -9,6 +9,7 @@ use std::slice; use arrayvec::ArrayVec; use smallvec::{smallvec, SmallVec}; +#[cfg(feature = "nightly")] use rustc_macros::{Decodable, Encodable}; use crate::{Idx, IndexVec}; @@ -111,7 +112,8 @@ macro_rules! bit_relations_inherent_impls { /// to or greater than the domain size. All operations that involve two bitsets /// will panic if the bitsets have differing domain sizes. /// -#[derive(Eq, PartialEq, Hash, Decodable, Encodable)] +#[cfg_attr(feature = "nightly", derive(Decodable, Encodable))] +#[derive(Eq, PartialEq, Hash)] pub struct BitSet { domain_size: usize, words: SmallVec<[Word; 2]>, @@ -491,10 +493,21 @@ impl ChunkedBitSet { match *chunk { Zeros(chunk_domain_size) => { if chunk_domain_size > 1 { - // We take some effort to avoid copying the words. - let words = Rc::<[Word; CHUNK_WORDS]>::new_zeroed(); - // SAFETY: `words` can safely be all zeroes. - let mut words = unsafe { words.assume_init() }; + #[cfg(feature = "nightly")] + let mut words = { + // We take some effort to avoid copying the words. + let words = Rc::<[Word; CHUNK_WORDS]>::new_zeroed(); + // SAFETY: `words` can safely be all zeroes. + unsafe { words.assume_init() } + }; + #[cfg(not(feature = "nightly"))] + let mut words = { + let words = mem::MaybeUninit::<[Word; CHUNK_WORDS]>::zeroed(); + // SAFETY: `words` can safely be all zeroes. + let words = unsafe { words.assume_init() }; + // Unfortunate possibly-large copy + Rc::new(words) + }; let words_ref = Rc::get_mut(&mut words).unwrap(); let (word_index, mask) = chunk_word_index_and_mask(elem); @@ -545,10 +558,21 @@ impl ChunkedBitSet { Zeros(_) => false, Ones(chunk_domain_size) => { if chunk_domain_size > 1 { - // We take some effort to avoid copying the words. - let words = Rc::<[Word; CHUNK_WORDS]>::new_zeroed(); - // SAFETY: `words` can safely be all zeroes. - let mut words = unsafe { words.assume_init() }; + #[cfg(feature = "nightly")] + let mut words = { + // We take some effort to avoid copying the words. + let words = Rc::<[Word; CHUNK_WORDS]>::new_zeroed(); + // SAFETY: `words` can safely be all zeroes. + unsafe { words.assume_init() } + }; + #[cfg(not(feature = "nightly"))] + let mut words = { + let words = mem::MaybeUninit::<[Word; CHUNK_WORDS]>::zeroed(); + // SAFETY: `words` can safely be all zeroes. + let words = unsafe { words.assume_init() }; + // Unfortunate possibly-large copy + Rc::new(words) + }; let words_ref = Rc::get_mut(&mut words).unwrap(); // Set only the bits in use. @@ -1564,7 +1588,8 @@ impl From> for GrowableBitSet { /// /// All operations that involve a row and/or column index will panic if the /// index exceeds the relevant bound. -#[derive(Clone, Eq, PartialEq, Hash, Decodable, Encodable)] +#[cfg_attr(feature = "nightly", derive(Decodable, Encodable))] +#[derive(Clone, Eq, PartialEq, Hash)] pub struct BitMatrix { num_rows: usize, num_columns: usize, @@ -1993,7 +2018,8 @@ impl std::fmt::Debug for FiniteBitSet { /// A fixed-sized bitset type represented by an integer type. Indices outwith than the range /// representable by `T` are considered set. -#[derive(Copy, Clone, Eq, PartialEq, Decodable, Encodable)] +#[cfg_attr(feature = "nightly", derive(Decodable, Encodable))] +#[derive(Copy, Clone, Eq, PartialEq)] pub struct FiniteBitSet(pub T); impl FiniteBitSet { diff --git a/compiler/rustc_index/src/lib.rs b/compiler/rustc_index/src/lib.rs index c5602392c53..185e0c7d698 100644 --- a/compiler/rustc_index/src/lib.rs +++ b/compiler/rustc_index/src/lib.rs @@ -14,7 +14,6 @@ )] #![cfg_attr(feature = "nightly", allow(internal_features))] -#[cfg(feature = "nightly")] pub mod bit_set; #[cfg(feature = "nightly")] pub mod interval;