From fb850aebcd39f7dd7973adabf380bdc5bb22a369 Mon Sep 17 00:00:00 2001 From: Zalathar Date: Wed, 18 Mar 2026 10:36:19 +1100 Subject: [PATCH] Remove unused types `UnusedGenericParams` and `FiniteBitSet` These types have been unused since polymorphization was removed in . --- .../src/stable_hasher.rs | 9 -- compiler/rustc_index/src/bit_set.rs | 113 +----------------- compiler/rustc_metadata/src/rmeta/mod.rs | 2 +- compiler/rustc_metadata/src/rmeta/table.rs | 10 -- compiler/rustc_middle/src/query/erase.rs | 2 - compiler/rustc_middle/src/ty/instance.rs | 50 +------- compiler/rustc_middle/src/ty/mod.rs | 2 +- 7 files changed, 4 insertions(+), 184 deletions(-) diff --git a/compiler/rustc_data_structures/src/stable_hasher.rs b/compiler/rustc_data_structures/src/stable_hasher.rs index 9fb4d4352c2f6..f8e72d66d07ef 100644 --- a/compiler/rustc_data_structures/src/stable_hasher.rs +++ b/compiler/rustc_data_structures/src/stable_hasher.rs @@ -555,15 +555,6 @@ impl HashStable for bit_set::BitMatrix { } } -impl HashStable for bit_set::FiniteBitSet -where - T: HashStable + 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); diff --git a/compiler/rustc_index/src/bit_set.rs b/compiler/rustc_index/src/bit_set.rs index 68384c73ba25a..f833acf6824e4 100644 --- a/compiler/rustc_index/src/bit_set.rs +++ b/compiler/rustc_index/src/bit_set.rs @@ -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}; @@ -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 - + BitAndAssign - + BitOrAssign - + Clone - + Copy - + Shl - + Not - + 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; - /// Perform a checked right shift on the integral type. - fn checked_shr(self, rhs: u32) -> Option; -} - -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.checked_shl(rhs) - } - - fn checked_shr(self, rhs: u32) -> Option { - self.checked_shr(rhs) - } -} - -impl std::fmt::Debug for FiniteBitSet { - 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(pub T); - -impl FiniteBitSet { - /// 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) { - 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 { - self.within_domain(index) - .then(|| ((self.0.checked_shr(index).unwrap_or(T::ONE)) & T::ONE) == T::ONE) - } -} - -impl Default for FiniteBitSet { - fn default() -> Self { - Self::new_empty() - } -} diff --git a/compiler/rustc_metadata/src/rmeta/mod.rs b/compiler/rustc_metadata/src/rmeta/mod.rs index 80d7ae4e9cb38..9dee913e8389c 100644 --- a/compiler/rustc_metadata/src/rmeta/mod.rs +++ b/compiler/rustc_metadata/src/rmeta/mod.rs @@ -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}; diff --git a/compiler/rustc_metadata/src/rmeta/table.rs b/compiler/rustc_metadata/src/rmeta/table.rs index 5e256438ad953..3b0570dd373a8 100644 --- a/compiler/rustc_metadata/src/rmeta/table.rs +++ b/compiler/rustc_metadata/src/rmeta/table.rs @@ -44,16 +44,6 @@ impl IsDefault for LazyArray { } } -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. /// diff --git a/compiler/rustc_middle/src/query/erase.rs b/compiler/rustc_middle/src/query/erase.rs index d15e0b2a122b9..036aa2ed05a4a 100644 --- a/compiler/rustc_middle/src/query/erase.rs +++ b/compiler/rustc_middle/src/query/erase.rs @@ -356,7 +356,6 @@ impl_erasable_for_simple_types! { rustc_hir::OwnerId, rustc_hir::Stability, rustc_hir::Upvar, - rustc_index::bit_set::FiniteBitSet, rustc_middle::middle::deduced_param_attrs::DeducedParamAttrs, rustc_middle::middle::dependency_format::Linkage, rustc_middle::middle::exported_symbols::SymbolExportInfo, @@ -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_middle::middle::codegen_fn_attrs::SanitizerFnAttrs, diff --git a/compiler/rustc_middle/src/ty/instance.rs b/compiler/rustc_middle/src/ty/instance.rs index 4cea8b62f0b62..9759e376c0586 100644 --- a/compiler/rustc_middle/src/ty/instance.rs +++ b/compiler/rustc_middle/src/ty/instance.rs @@ -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}; @@ -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); - -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)) - } -} diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 01c351de93198..2b02d42890aa9 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -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};