Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions compiler/rustc_data_structures/src/stable_hasher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,15 +555,6 @@ impl<R: Idx, C: Idx, CTX> HashStable<CTX> for bit_set::BitMatrix<R, C> {
}
}

impl<T, CTX> HashStable<CTX> for bit_set::FiniteBitSet<T>
where
T: HashStable<CTX> + bit_set::FiniteBitSetTy,
{
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
self.0.hash_stable(hcx, hasher);
}
}

impl_stable_traits_for_trivial_type!(::std::ffi::OsStr);

impl_stable_traits_for_trivial_type!(::std::path::Path);
Expand Down
113 changes: 1 addition & 112 deletions compiler/rustc_index/src/bit_set.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::marker::PhantomData;
#[cfg(not(feature = "nightly"))]
use std::mem;
use std::ops::{BitAnd, BitAndAssign, BitOrAssign, Bound, Not, Range, RangeBounds, Shl};
use std::ops::{Bound, Range, RangeBounds};
use std::rc::Rc;
use std::{fmt, iter, slice};

Expand Down Expand Up @@ -1736,114 +1736,3 @@ fn max_bit(word: Word) -> usize {
fn count_ones(words: &[Word]) -> usize {
words.iter().map(|word| word.count_ones() as usize).sum()
}

/// Integral type used to represent the bit set.
pub trait FiniteBitSetTy:
BitAnd<Output = Self>
+ BitAndAssign
+ BitOrAssign
+ Clone
+ Copy
+ Shl
+ Not<Output = Self>
+ PartialEq
+ Sized
{
/// Size of the domain representable by this type, e.g. 64 for `u64`.
const DOMAIN_SIZE: u32;

/// Value which represents the `FiniteBitSet` having every bit set.
const FILLED: Self;
/// Value which represents the `FiniteBitSet` having no bits set.
const EMPTY: Self;

/// Value for one as the integral type.
const ONE: Self;
/// Value for zero as the integral type.
const ZERO: Self;

/// Perform a checked left shift on the integral type.
fn checked_shl(self, rhs: u32) -> Option<Self>;
/// Perform a checked right shift on the integral type.
fn checked_shr(self, rhs: u32) -> Option<Self>;
}

impl FiniteBitSetTy for u32 {
const DOMAIN_SIZE: u32 = 32;

const FILLED: Self = Self::MAX;
const EMPTY: Self = Self::MIN;

const ONE: Self = 1u32;
const ZERO: Self = 0u32;

fn checked_shl(self, rhs: u32) -> Option<Self> {
self.checked_shl(rhs)
}

fn checked_shr(self, rhs: u32) -> Option<Self> {
self.checked_shr(rhs)
}
}

impl std::fmt::Debug for FiniteBitSet<u32> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:032b}", self.0)
}
}

/// A fixed-sized bitset type represented by an integer type. Indices outwith than the range
/// representable by `T` are considered set.
#[cfg_attr(feature = "nightly", derive(Decodable_NoContext, Encodable_NoContext))]
#[derive(Copy, Clone, Eq, PartialEq)]
pub struct FiniteBitSet<T: FiniteBitSetTy>(pub T);

impl<T: FiniteBitSetTy> FiniteBitSet<T> {
/// Creates a new, empty bitset.
pub fn new_empty() -> Self {
Self(T::EMPTY)
}

/// Sets the `index`th bit.
pub fn set(&mut self, index: u32) {
self.0 |= T::ONE.checked_shl(index).unwrap_or(T::ZERO);
}

/// Unsets the `index`th bit.
pub fn clear(&mut self, index: u32) {
self.0 &= !T::ONE.checked_shl(index).unwrap_or(T::ZERO);
}

/// Sets the `i`th to `j`th bits.
pub fn set_range(&mut self, range: Range<u32>) {
let bits = T::FILLED
.checked_shl(range.end - range.start)
.unwrap_or(T::ZERO)
.not()
.checked_shl(range.start)
.unwrap_or(T::ZERO);
self.0 |= bits;
}

/// Is the set empty?
pub fn is_empty(&self) -> bool {
self.0 == T::EMPTY
}

/// Returns the domain size of the bitset.
pub fn within_domain(&self, index: u32) -> bool {
index < T::DOMAIN_SIZE
}

/// Returns if the `index`th bit is set.
pub fn contains(&self, index: u32) -> Option<bool> {
self.within_domain(index)
.then(|| ((self.0.checked_shr(index).unwrap_or(T::ONE)) & T::ONE) == T::ONE)
}
}

impl<T: FiniteBitSetTy> Default for FiniteBitSet<T> {
fn default() -> Self {
Self::new_empty()
}
}
2 changes: 1 addition & 1 deletion compiler/rustc_metadata/src/rmeta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use rustc_middle::middle::resolve_bound_vars::ObjectLifetimeDefault;
use rustc_middle::mir;
use rustc_middle::mir::ConstValue;
use rustc_middle::ty::fast_reject::SimplifiedType;
use rustc_middle::ty::{self, Ty, TyCtxt, UnusedGenericParams};
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_middle::util::Providers;
use rustc_serialize::opaque::FileEncoder;
use rustc_session::config::{SymbolManglingVersion, TargetModifier};
Expand Down
10 changes: 0 additions & 10 deletions compiler/rustc_metadata/src/rmeta/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,6 @@ impl<T> IsDefault for LazyArray<T> {
}
}

impl IsDefault for UnusedGenericParams {
fn is_default(&self) -> bool {
// UnusedGenericParams encodes the *un*usedness as a bitset.
// This means that 0 corresponds to all bits used, which is indeed the default.
let is_default = self.bits() == 0;
debug_assert_eq!(is_default, self.all_used());
is_default
}
}

/// Helper trait, for encoding to, and decoding from, a fixed number of bytes.
/// Used mainly for Lazy positions and lengths.
///
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_middle/src/query/erase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,6 @@ impl_erasable_for_simple_types! {
rustc_hir::OwnerId,
rustc_hir::Stability,
rustc_hir::Upvar,
rustc_index::bit_set::FiniteBitSet<u32>,
rustc_middle::middle::deduced_param_attrs::DeducedParamAttrs,
rustc_middle::middle::dependency_format::Linkage,
rustc_middle::middle::exported_symbols::SymbolExportInfo,
Expand All @@ -383,7 +382,6 @@ impl_erasable_for_simple_types! {
rustc_middle::ty::Destructor,
rustc_middle::ty::fast_reject::SimplifiedType,
rustc_middle::ty::ImplPolarity,
rustc_middle::ty::UnusedGenericParams,
rustc_middle::ty::util::AlwaysRequiresDrop,
rustc_middle::ty::Visibility<rustc_span::def_id::DefId>,
rustc_middle::middle::codegen_fn_attrs::SanitizerFnAttrs,
Expand Down
50 changes: 1 addition & 49 deletions compiler/rustc_middle/src/ty/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ use rustc_hir as hir;
use rustc_hir::def::{CtorKind, DefKind, Namespace};
use rustc_hir::def_id::{CrateNum, DefId};
use rustc_hir::lang_items::LangItem;
use rustc_index::bit_set::FiniteBitSet;
use rustc_macros::{Decodable, Encodable, HashStable, Lift, TyDecodable, TyEncodable};
use rustc_macros::{HashStable, Lift, TyDecodable, TyEncodable};
use rustc_span::def_id::LOCAL_CRATE;
use rustc_span::{DUMMY_SP, Span};
use tracing::{debug, instrument};
Expand Down Expand Up @@ -941,50 +940,3 @@ fn needs_fn_once_adapter_shim(
(ty::ClosureKind::FnMut | ty::ClosureKind::FnOnce, _) => Err(()),
}
}

// Set bits represent unused generic parameters.
// An empty set indicates that all parameters are used.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Decodable, Encodable, HashStable)]
pub struct UnusedGenericParams(FiniteBitSet<u32>);

impl Default for UnusedGenericParams {
fn default() -> Self {
UnusedGenericParams::new_all_used()
}
}

impl UnusedGenericParams {
pub fn new_all_unused(amount: u32) -> Self {
let mut bitset = FiniteBitSet::new_empty();
bitset.set_range(0..amount);
Self(bitset)
}

pub fn new_all_used() -> Self {
Self(FiniteBitSet::new_empty())
}

pub fn mark_used(&mut self, idx: u32) {
self.0.clear(idx);
}

pub fn is_unused(&self, idx: u32) -> bool {
self.0.contains(idx).unwrap_or(false)
}

pub fn is_used(&self, idx: u32) -> bool {
!self.is_unused(idx)
}

pub fn all_used(&self) -> bool {
self.0.is_empty()
}

pub fn bits(&self) -> u32 {
self.0.0
}

pub fn from_bits(bits: u32) -> UnusedGenericParams {
UnusedGenericParams(FiniteBitSet(bits))
}
}
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub use self::context::{
CtxtInterners, CurrentGcx, Feed, FreeRegionInfo, GlobalCtxt, Lift, TyCtxt, TyCtxtFeed, tls,
};
pub use self::fold::*;
pub use self::instance::{Instance, InstanceKind, ReifyReason, UnusedGenericParams};
pub use self::instance::{Instance, InstanceKind, ReifyReason};
pub use self::list::{List, ListWithCachedTypeInfo};
pub use self::opaque_types::OpaqueTypeKey;
pub use self::pattern::{Pattern, PatternKind};
Expand Down
Loading