Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 033f471

Browse files
committed
Make rustc_index::bit_set available on stable
1 parent 4d0ebfc commit 033f471

File tree

2 files changed

+37
-12
lines changed

2 files changed

+37
-12
lines changed

compiler/rustc_index/src/bit_set.rs

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::slice;
99
use arrayvec::ArrayVec;
1010
use smallvec::{smallvec, SmallVec};
1111

12+
#[cfg(feature = "nightly")]
1213
use rustc_macros::{Decodable, Encodable};
1314

1415
use crate::{Idx, IndexVec};
@@ -111,7 +112,8 @@ macro_rules! bit_relations_inherent_impls {
111112
/// to or greater than the domain size. All operations that involve two bitsets
112113
/// will panic if the bitsets have differing domain sizes.
113114
///
114-
#[derive(Eq, PartialEq, Hash, Decodable, Encodable)]
115+
#[cfg_attr(feature = "nightly", derive(Decodable, Encodable))]
116+
#[derive(Eq, PartialEq, Hash)]
115117
pub struct BitSet<T> {
116118
domain_size: usize,
117119
words: SmallVec<[Word; 2]>,
@@ -491,10 +493,21 @@ impl<T: Idx> ChunkedBitSet<T> {
491493
match *chunk {
492494
Zeros(chunk_domain_size) => {
493495
if chunk_domain_size > 1 {
494-
// We take some effort to avoid copying the words.
495-
let words = Rc::<[Word; CHUNK_WORDS]>::new_zeroed();
496-
// SAFETY: `words` can safely be all zeroes.
497-
let mut words = unsafe { words.assume_init() };
496+
#[cfg(feature = "nightly")]
497+
let mut words = {
498+
// We take some effort to avoid copying the words.
499+
let words = Rc::<[Word; CHUNK_WORDS]>::new_zeroed();
500+
// SAFETY: `words` can safely be all zeroes.
501+
unsafe { words.assume_init() }
502+
};
503+
#[cfg(not(feature = "nightly"))]
504+
let mut words = {
505+
let words = mem::MaybeUninit::<[Word; CHUNK_WORDS]>::zeroed();
506+
// SAFETY: `words` can safely be all zeroes.
507+
let words = unsafe { words.assume_init() };
508+
// Unfortunate possibly-large copy
509+
Rc::new(words)
510+
};
498511
let words_ref = Rc::get_mut(&mut words).unwrap();
499512

500513
let (word_index, mask) = chunk_word_index_and_mask(elem);
@@ -545,10 +558,21 @@ impl<T: Idx> ChunkedBitSet<T> {
545558
Zeros(_) => false,
546559
Ones(chunk_domain_size) => {
547560
if chunk_domain_size > 1 {
548-
// We take some effort to avoid copying the words.
549-
let words = Rc::<[Word; CHUNK_WORDS]>::new_zeroed();
550-
// SAFETY: `words` can safely be all zeroes.
551-
let mut words = unsafe { words.assume_init() };
561+
#[cfg(feature = "nightly")]
562+
let mut words = {
563+
// We take some effort to avoid copying the words.
564+
let words = Rc::<[Word; CHUNK_WORDS]>::new_zeroed();
565+
// SAFETY: `words` can safely be all zeroes.
566+
unsafe { words.assume_init() }
567+
};
568+
#[cfg(not(feature = "nightly"))]
569+
let mut words = {
570+
let words = mem::MaybeUninit::<[Word; CHUNK_WORDS]>::zeroed();
571+
// SAFETY: `words` can safely be all zeroes.
572+
let words = unsafe { words.assume_init() };
573+
// Unfortunate possibly-large copy
574+
Rc::new(words)
575+
};
552576
let words_ref = Rc::get_mut(&mut words).unwrap();
553577

554578
// Set only the bits in use.
@@ -1564,7 +1588,8 @@ impl<T: Idx> From<BitSet<T>> for GrowableBitSet<T> {
15641588
///
15651589
/// All operations that involve a row and/or column index will panic if the
15661590
/// index exceeds the relevant bound.
1567-
#[derive(Clone, Eq, PartialEq, Hash, Decodable, Encodable)]
1591+
#[cfg_attr(feature = "nightly", derive(Decodable, Encodable))]
1592+
#[derive(Clone, Eq, PartialEq, Hash)]
15681593
pub struct BitMatrix<R: Idx, C: Idx> {
15691594
num_rows: usize,
15701595
num_columns: usize,
@@ -1993,7 +2018,8 @@ impl std::fmt::Debug for FiniteBitSet<u32> {
19932018

19942019
/// A fixed-sized bitset type represented by an integer type. Indices outwith than the range
19952020
/// representable by `T` are considered set.
1996-
#[derive(Copy, Clone, Eq, PartialEq, Decodable, Encodable)]
2021+
#[cfg_attr(feature = "nightly", derive(Decodable, Encodable))]
2022+
#[derive(Copy, Clone, Eq, PartialEq)]
19972023
pub struct FiniteBitSet<T: FiniteBitSetTy>(pub T);
19982024

19992025
impl<T: FiniteBitSetTy> FiniteBitSet<T> {

compiler/rustc_index/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
)]
1515
#![cfg_attr(feature = "nightly", allow(internal_features))]
1616

17-
#[cfg(feature = "nightly")]
1817
pub mod bit_set;
1918
#[cfg(feature = "nightly")]
2019
pub mod interval;

0 commit comments

Comments
 (0)