Skip to content

Commit 8698863

Browse files
committed
Auto merge of #154030 - Zalathar:rollup-STlnAhI, r=Zalathar
Rollup of 3 pull requests Successful merges: - #153727 (When single impl can satisfy inference error, suggest type) - #153998 (Move query-stack-frame spans into `QueryStackFrame`) - #154026 (Remove unused types `UnusedGenericParams` and `FiniteBitSet`)
2 parents 91775db + 5825bed commit 8698863

19 files changed

Lines changed: 195 additions & 239 deletions

File tree

compiler/rustc_data_structures/src/stable_hasher.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -555,15 +555,6 @@ impl<R: Idx, C: Idx, CTX> HashStable<CTX> for bit_set::BitMatrix<R, C> {
555555
}
556556
}
557557

558-
impl<T, CTX> HashStable<CTX> for bit_set::FiniteBitSet<T>
559-
where
560-
T: HashStable<CTX> + bit_set::FiniteBitSetTy,
561-
{
562-
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
563-
self.0.hash_stable(hcx, hasher);
564-
}
565-
}
566-
567558
impl_stable_traits_for_trivial_type!(::std::ffi::OsStr);
568559

569560
impl_stable_traits_for_trivial_type!(::std::path::Path);

compiler/rustc_index/src/bit_set.rs

Lines changed: 1 addition & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::marker::PhantomData;
22
#[cfg(not(feature = "nightly"))]
33
use std::mem;
4-
use std::ops::{BitAnd, BitAndAssign, BitOrAssign, Bound, Not, Range, RangeBounds, Shl};
4+
use std::ops::{Bound, Range, RangeBounds};
55
use std::rc::Rc;
66
use std::{fmt, iter, slice};
77

@@ -1736,114 +1736,3 @@ fn max_bit(word: Word) -> usize {
17361736
fn count_ones(words: &[Word]) -> usize {
17371737
words.iter().map(|word| word.count_ones() as usize).sum()
17381738
}
1739-
1740-
/// Integral type used to represent the bit set.
1741-
pub trait FiniteBitSetTy:
1742-
BitAnd<Output = Self>
1743-
+ BitAndAssign
1744-
+ BitOrAssign
1745-
+ Clone
1746-
+ Copy
1747-
+ Shl
1748-
+ Not<Output = Self>
1749-
+ PartialEq
1750-
+ Sized
1751-
{
1752-
/// Size of the domain representable by this type, e.g. 64 for `u64`.
1753-
const DOMAIN_SIZE: u32;
1754-
1755-
/// Value which represents the `FiniteBitSet` having every bit set.
1756-
const FILLED: Self;
1757-
/// Value which represents the `FiniteBitSet` having no bits set.
1758-
const EMPTY: Self;
1759-
1760-
/// Value for one as the integral type.
1761-
const ONE: Self;
1762-
/// Value for zero as the integral type.
1763-
const ZERO: Self;
1764-
1765-
/// Perform a checked left shift on the integral type.
1766-
fn checked_shl(self, rhs: u32) -> Option<Self>;
1767-
/// Perform a checked right shift on the integral type.
1768-
fn checked_shr(self, rhs: u32) -> Option<Self>;
1769-
}
1770-
1771-
impl FiniteBitSetTy for u32 {
1772-
const DOMAIN_SIZE: u32 = 32;
1773-
1774-
const FILLED: Self = Self::MAX;
1775-
const EMPTY: Self = Self::MIN;
1776-
1777-
const ONE: Self = 1u32;
1778-
const ZERO: Self = 0u32;
1779-
1780-
fn checked_shl(self, rhs: u32) -> Option<Self> {
1781-
self.checked_shl(rhs)
1782-
}
1783-
1784-
fn checked_shr(self, rhs: u32) -> Option<Self> {
1785-
self.checked_shr(rhs)
1786-
}
1787-
}
1788-
1789-
impl std::fmt::Debug for FiniteBitSet<u32> {
1790-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1791-
write!(f, "{:032b}", self.0)
1792-
}
1793-
}
1794-
1795-
/// A fixed-sized bitset type represented by an integer type. Indices outwith than the range
1796-
/// representable by `T` are considered set.
1797-
#[cfg_attr(feature = "nightly", derive(Decodable_NoContext, Encodable_NoContext))]
1798-
#[derive(Copy, Clone, Eq, PartialEq)]
1799-
pub struct FiniteBitSet<T: FiniteBitSetTy>(pub T);
1800-
1801-
impl<T: FiniteBitSetTy> FiniteBitSet<T> {
1802-
/// Creates a new, empty bitset.
1803-
pub fn new_empty() -> Self {
1804-
Self(T::EMPTY)
1805-
}
1806-
1807-
/// Sets the `index`th bit.
1808-
pub fn set(&mut self, index: u32) {
1809-
self.0 |= T::ONE.checked_shl(index).unwrap_or(T::ZERO);
1810-
}
1811-
1812-
/// Unsets the `index`th bit.
1813-
pub fn clear(&mut self, index: u32) {
1814-
self.0 &= !T::ONE.checked_shl(index).unwrap_or(T::ZERO);
1815-
}
1816-
1817-
/// Sets the `i`th to `j`th bits.
1818-
pub fn set_range(&mut self, range: Range<u32>) {
1819-
let bits = T::FILLED
1820-
.checked_shl(range.end - range.start)
1821-
.unwrap_or(T::ZERO)
1822-
.not()
1823-
.checked_shl(range.start)
1824-
.unwrap_or(T::ZERO);
1825-
self.0 |= bits;
1826-
}
1827-
1828-
/// Is the set empty?
1829-
pub fn is_empty(&self) -> bool {
1830-
self.0 == T::EMPTY
1831-
}
1832-
1833-
/// Returns the domain size of the bitset.
1834-
pub fn within_domain(&self, index: u32) -> bool {
1835-
index < T::DOMAIN_SIZE
1836-
}
1837-
1838-
/// Returns if the `index`th bit is set.
1839-
pub fn contains(&self, index: u32) -> Option<bool> {
1840-
self.within_domain(index)
1841-
.then(|| ((self.0.checked_shr(index).unwrap_or(T::ONE)) & T::ONE) == T::ONE)
1842-
}
1843-
}
1844-
1845-
impl<T: FiniteBitSetTy> Default for FiniteBitSet<T> {
1846-
fn default() -> Self {
1847-
Self::new_empty()
1848-
}
1849-
}

compiler/rustc_metadata/src/rmeta/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use rustc_middle::middle::resolve_bound_vars::ObjectLifetimeDefault;
3333
use rustc_middle::mir;
3434
use rustc_middle::mir::ConstValue;
3535
use rustc_middle::ty::fast_reject::SimplifiedType;
36-
use rustc_middle::ty::{self, Ty, TyCtxt, UnusedGenericParams};
36+
use rustc_middle::ty::{self, Ty, TyCtxt};
3737
use rustc_middle::util::Providers;
3838
use rustc_serialize::opaque::FileEncoder;
3939
use rustc_session::config::{SymbolManglingVersion, TargetModifier};

compiler/rustc_metadata/src/rmeta/table.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,6 @@ impl<T> IsDefault for LazyArray<T> {
4444
}
4545
}
4646

47-
impl IsDefault for UnusedGenericParams {
48-
fn is_default(&self) -> bool {
49-
// UnusedGenericParams encodes the *un*usedness as a bitset.
50-
// This means that 0 corresponds to all bits used, which is indeed the default.
51-
let is_default = self.bits() == 0;
52-
debug_assert_eq!(is_default, self.all_used());
53-
is_default
54-
}
55-
}
56-
5747
/// Helper trait, for encoding to, and decoding from, a fixed number of bytes.
5848
/// Used mainly for Lazy positions and lengths.
5949
///

compiler/rustc_middle/src/query/erase.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,6 @@ impl_erasable_for_simple_types! {
356356
rustc_hir::OwnerId,
357357
rustc_hir::Stability,
358358
rustc_hir::Upvar,
359-
rustc_index::bit_set::FiniteBitSet<u32>,
360359
rustc_middle::middle::deduced_param_attrs::DeducedParamAttrs,
361360
rustc_middle::middle::dependency_format::Linkage,
362361
rustc_middle::middle::exported_symbols::SymbolExportInfo,
@@ -383,7 +382,6 @@ impl_erasable_for_simple_types! {
383382
rustc_middle::ty::Destructor,
384383
rustc_middle::ty::fast_reject::SimplifiedType,
385384
rustc_middle::ty::ImplPolarity,
386-
rustc_middle::ty::UnusedGenericParams,
387385
rustc_middle::ty::util::AlwaysRequiresDrop,
388386
rustc_middle::ty::Visibility<rustc_span::def_id::DefId>,
389387
rustc_middle::middle::codegen_fn_attrs::SanitizerFnAttrs,

compiler/rustc_middle/src/query/plumbing.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@ use rustc_data_structures::sync::{AtomicU64, WorkerLocal};
88
use rustc_errors::Diag;
99
use rustc_hir::def_id::{DefId, LocalDefId};
1010
use rustc_hir::hir_id::OwnerId;
11-
use rustc_span::{Span, Spanned};
11+
use rustc_span::Span;
1212
pub use sealed::IntoQueryParam;
1313

1414
use crate::dep_graph::{DepKind, DepNodeIndex, SerializedDepNodeIndex};
1515
use crate::ich::StableHashingContext;
1616
use crate::queries::{ExternProviders, Providers, QueryArenas, QueryVTables, TaggedQueryKey};
1717
use crate::query::on_disk_cache::OnDiskCache;
18-
use crate::query::stack::QueryStackFrame;
19-
use crate::query::{QueryCache, QueryJob};
18+
use crate::query::{QueryCache, QueryJob, QueryStackFrame};
2019
use crate::ty::TyCtxt;
2120

2221
/// For a particular query, keeps track of "active" keys, i.e. keys whose
@@ -53,10 +52,10 @@ pub enum ActiveKeyStatus<'tcx> {
5352
#[derive(Debug)]
5453
pub struct CycleError<'tcx> {
5554
/// The query and related span that uses the cycle.
56-
pub usage: Option<Spanned<QueryStackFrame<'tcx>>>,
55+
pub usage: Option<QueryStackFrame<'tcx>>,
5756

5857
/// The span here corresponds to the reason for which this query was required.
59-
pub cycle: Vec<Spanned<QueryStackFrame<'tcx>>>,
58+
pub cycle: Vec<QueryStackFrame<'tcx>>,
6059
}
6160

6261
#[derive(Debug)]
@@ -505,7 +504,7 @@ macro_rules! define_callbacks {
505504

506505
/// Identifies a query by kind and key. This is in contrast to `QueryJobId` which is just a number.
507506
#[allow(non_camel_case_types)]
508-
#[derive(Clone, Debug)]
507+
#[derive(Clone, Copy, Debug)]
509508
pub enum TaggedQueryKey<'tcx> {
510509
$(
511510
$name($name::Key<'tcx>),

compiler/rustc_middle/src/query/stack.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
use rustc_span::Span;
2+
13
use crate::queries::TaggedQueryKey;
24

35
/// Description of a frame in the query stack.
46
///
57
/// This is mostly used in case of cycles for error reporting.
6-
#[derive(Clone, Debug)]
8+
#[derive(Debug)]
79
pub struct QueryStackFrame<'tcx> {
10+
pub span: Span,
11+
812
/// The query and key of the query method call that this stack frame
913
/// corresponds to.
1014
///

compiler/rustc_middle/src/ty/instance.rs

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ use rustc_hir as hir;
66
use rustc_hir::def::{CtorKind, DefKind, Namespace};
77
use rustc_hir::def_id::{CrateNum, DefId};
88
use rustc_hir::lang_items::LangItem;
9-
use rustc_index::bit_set::FiniteBitSet;
10-
use rustc_macros::{Decodable, Encodable, HashStable, Lift, TyDecodable, TyEncodable};
9+
use rustc_macros::{HashStable, Lift, TyDecodable, TyEncodable};
1110
use rustc_span::def_id::LOCAL_CRATE;
1211
use rustc_span::{DUMMY_SP, Span};
1312
use tracing::{debug, instrument};
@@ -941,50 +940,3 @@ fn needs_fn_once_adapter_shim(
941940
(ty::ClosureKind::FnMut | ty::ClosureKind::FnOnce, _) => Err(()),
942941
}
943942
}
944-
945-
// Set bits represent unused generic parameters.
946-
// An empty set indicates that all parameters are used.
947-
#[derive(Debug, Copy, Clone, Eq, PartialEq, Decodable, Encodable, HashStable)]
948-
pub struct UnusedGenericParams(FiniteBitSet<u32>);
949-
950-
impl Default for UnusedGenericParams {
951-
fn default() -> Self {
952-
UnusedGenericParams::new_all_used()
953-
}
954-
}
955-
956-
impl UnusedGenericParams {
957-
pub fn new_all_unused(amount: u32) -> Self {
958-
let mut bitset = FiniteBitSet::new_empty();
959-
bitset.set_range(0..amount);
960-
Self(bitset)
961-
}
962-
963-
pub fn new_all_used() -> Self {
964-
Self(FiniteBitSet::new_empty())
965-
}
966-
967-
pub fn mark_used(&mut self, idx: u32) {
968-
self.0.clear(idx);
969-
}
970-
971-
pub fn is_unused(&self, idx: u32) -> bool {
972-
self.0.contains(idx).unwrap_or(false)
973-
}
974-
975-
pub fn is_used(&self, idx: u32) -> bool {
976-
!self.is_unused(idx)
977-
}
978-
979-
pub fn all_used(&self) -> bool {
980-
self.0.is_empty()
981-
}
982-
983-
pub fn bits(&self) -> u32 {
984-
self.0.0
985-
}
986-
987-
pub fn from_bits(bits: u32) -> UnusedGenericParams {
988-
UnusedGenericParams(FiniteBitSet(bits))
989-
}
990-
}

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub use self::context::{
8585
CtxtInterners, CurrentGcx, Feed, FreeRegionInfo, GlobalCtxt, Lift, TyCtxt, TyCtxtFeed, tls,
8686
};
8787
pub use self::fold::*;
88-
pub use self::instance::{Instance, InstanceKind, ReifyReason, UnusedGenericParams};
88+
pub use self::instance::{Instance, InstanceKind, ReifyReason};
8989
pub use self::list::{List, ListWithCachedTypeInfo};
9090
pub use self::opaque_types::OpaqueTypeKey;
9191
pub use self::pattern::{Pattern, PatternKind};

compiler/rustc_query_impl/src/execution.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_errors::FatalError;
99
use rustc_middle::dep_graph::{DepGraphData, DepNodeKey, SerializedDepNodeIndex};
1010
use rustc_middle::query::{
1111
ActiveKeyStatus, CycleError, EnsureMode, QueryCache, QueryJob, QueryJobId, QueryKey,
12-
QueryLatch, QueryMode, QueryStackFrame, QueryState, QueryVTable,
12+
QueryLatch, QueryMode, QueryState, QueryVTable,
1313
};
1414
use rustc_middle::ty::TyCtxt;
1515
use rustc_middle::verify_ich::incremental_verify_ich;
@@ -75,8 +75,8 @@ fn collect_active_query_jobs_inner<'tcx, C>(
7575
if let ActiveKeyStatus::Started(job) = status {
7676
// It's fine to call `create_tagged_key` with the shard locked,
7777
// because it's just a `TaggedQueryKey` variant constructor.
78-
let frame = QueryStackFrame { tagged_key: (query.create_tagged_key)(*key) };
79-
job_map.insert(job.id, QueryJobInfo { frame, job: job.clone() });
78+
let tagged_key = (query.create_tagged_key)(*key);
79+
job_map.insert(job.id, QueryJobInfo { tagged_key, job: job.clone() });
8080
}
8181
}
8282
};

0 commit comments

Comments
 (0)