Skip to content

Commit a3903b1

Browse files
committed
Auto merge of #154032 - Zalathar:rollup-Aejl3zc, r=Zalathar
Rollup of 3 pull requests Successful merges: - #153998 (Move query-stack-frame spans into `QueryStackFrame`) - #153778 (Couple of driver interface improvements) - #154026 (Remove unused types `UnusedGenericParams` and `FiniteBitSet`)
2 parents 91775db + ba84805 commit a3903b1

26 files changed

Lines changed: 120 additions & 295 deletions

File tree

compiler/rustc_builtin_macros/src/env.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub(crate) fn expand_option_env<'cx>(
5151

5252
let sp = cx.with_def_site_ctxt(sp);
5353
let value = lookup_env(cx, var);
54-
cx.sess.psess.env_depinfo.borrow_mut().insert((var, value.as_ref().ok().copied()));
54+
cx.sess.env_depinfo.borrow_mut().insert((var, value.as_ref().ok().copied()));
5555
let e = match value {
5656
Err(VarError::NotPresent) => {
5757
let lt = cx.lifetime(sp, Ident::new(kw::StaticLifetime, sp));
@@ -130,7 +130,7 @@ pub(crate) fn expand_env<'cx>(
130130

131131
let span = cx.with_def_site_ctxt(sp);
132132
let value = lookup_env(cx, var);
133-
cx.sess.psess.env_depinfo.borrow_mut().insert((var, value.as_ref().ok().copied()));
133+
cx.sess.env_depinfo.borrow_mut().insert((var, value.as_ref().ok().copied()));
134134
let e = match value {
135135
Err(err) => {
136136
let ExprKind::Lit(token::Lit {

compiler/rustc_builtin_macros/src/source_util.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,6 @@ fn load_binary_file(
277277
match cx.source_map().load_binary_file(&resolved_path) {
278278
Ok(data) => {
279279
cx.sess
280-
.psess
281280
.file_depinfo
282281
.borrow_mut()
283282
.insert(Symbol::intern(&resolved_path.to_string_lossy()));

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_driver_impl/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ pub fn run_compiler(at_args: &[String], callbacks: &mut (dyn Callbacks + Send))
214214
file_loader: None,
215215
lint_caps: Default::default(),
216216
psess_created: None,
217-
hash_untracked_state: None,
217+
track_state: None,
218218
register_lints: None,
219219
override_queries: None,
220220
extra_symbols: Vec::new(),

compiler/rustc_expand/src/proc_macro_server.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,14 +475,15 @@ impl server::Server for Rustc<'_, '_> {
475475
}
476476

477477
fn track_env_var(&mut self, var: &str, value: Option<&str>) {
478-
self.psess()
478+
self.ecx
479+
.sess
479480
.env_depinfo
480481
.borrow_mut()
481482
.insert((Symbol::intern(var), value.map(Symbol::intern)));
482483
}
483484

484485
fn track_path(&mut self, path: &str) {
485-
self.psess().file_depinfo.borrow_mut().insert(Symbol::intern(path));
486+
self.ecx.sess.file_depinfo.borrow_mut().insert(Symbol::intern(path));
486487
}
487488

488489
fn literal_from_str(&mut self, s: &str) -> Result<Literal<Self::Span, Self::Symbol>, String> {

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_interface/src/interface.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use rustc_session::parse::ParseSess;
2222
use rustc_session::{CompilerIO, EarlyDiagCtxt, Session, lint};
2323
use rustc_span::source_map::{FileLoader, RealFileLoader, SourceMapInputs};
2424
use rustc_span::{FileName, sym};
25-
use rustc_target::spec::Target;
2625
use tracing::trace;
2726

2827
use crate::util;
@@ -337,11 +336,14 @@ pub struct Config {
337336
/// This is a callback from the driver that is called when [`ParseSess`] is created.
338337
pub psess_created: Option<Box<dyn FnOnce(&mut ParseSess) + Send>>,
339338

340-
/// This is a callback to hash otherwise untracked state used by the caller, if the
341-
/// hash changes between runs the incremental cache will be cleared.
339+
/// This is a callback to track otherwise untracked state used by the caller.
342340
///
343-
/// e.g. used by Clippy to hash its config file
344-
pub hash_untracked_state: Option<Box<dyn FnOnce(&Session, &mut StableHasher) + Send>>,
341+
/// You can write to `sess.env_depinfo` and `sess.file_depinfo` to track env vars and files.
342+
/// To track any other state you can write to the given hasher. If the hash changes between
343+
/// runs the incremental cache will be cleared.
344+
///
345+
/// The hashing functionality has no known user. FIXME should this be removed?
346+
pub track_state: Option<Box<dyn FnOnce(&Session, &mut StableHasher) + Send>>,
345347

346348
/// This is a callback from the driver that is called when we're registering lints;
347349
/// it is called during lint loading when we have the LintStore in a non-shared state.
@@ -364,8 +366,7 @@ pub struct Config {
364366
/// hotswapping branch of cg_clif" for "setting the codegen backend from a
365367
/// custom driver where the custom codegen backend has arbitrary data."
366368
/// (See #102759.)
367-
pub make_codegen_backend:
368-
Option<Box<dyn FnOnce(&config::Options, &Target) -> Box<dyn CodegenBackend> + Send>>,
369+
pub make_codegen_backend: Option<Box<dyn FnOnce(&Session) -> Box<dyn CodegenBackend> + Send>>,
369370

370371
/// The inner atomic value is set to true when a feature marked as `internal` is
371372
/// enabled. Makes it so that "please report a bug" is hidden, as ICEs with
@@ -419,20 +420,6 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
419420
// impl `Send`. Creating a new one is fine.
420421
let early_dcx = EarlyDiagCtxt::new(config.opts.error_format);
421422

422-
let codegen_backend = match config.make_codegen_backend {
423-
None => util::get_codegen_backend(
424-
&early_dcx,
425-
&config.opts.sysroot,
426-
config.opts.unstable_opts.codegen_backend.as_deref(),
427-
&target,
428-
),
429-
Some(make_codegen_backend) => {
430-
// N.B. `make_codegen_backend` takes precedence over
431-
// `target.default_codegen_backend`, which is ignored in this case.
432-
make_codegen_backend(&config.opts, &target)
433-
}
434-
};
435-
436423
let temps_dir = config.opts.unstable_opts.temps_dir.as_deref().map(PathBuf::from);
437424

438425
let mut sess = rustc_session::build_session(
@@ -450,6 +437,19 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
450437
config.using_internal_features,
451438
);
452439

440+
let codegen_backend = match config.make_codegen_backend {
441+
None => util::get_codegen_backend(
442+
&early_dcx,
443+
&sess.opts.sysroot,
444+
sess.opts.unstable_opts.codegen_backend.as_deref(),
445+
&sess.target,
446+
),
447+
Some(make_codegen_backend) => {
448+
// N.B. `make_codegen_backend` takes precedence over
449+
// `target.default_codegen_backend`, which is ignored in this case.
450+
make_codegen_backend(&sess)
451+
}
452+
};
453453
codegen_backend.init(&sess);
454454
sess.replaced_intrinsics = FxHashSet::from_iter(codegen_backend.replaced_intrinsics());
455455
sess.thin_lto_supported = codegen_backend.thin_lto_supported();
@@ -467,9 +467,9 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
467467
psess_created(&mut sess.psess);
468468
}
469469

470-
if let Some(hash_untracked_state) = config.hash_untracked_state {
470+
if let Some(track_state) = config.track_state {
471471
let mut hasher = StableHasher::new();
472-
hash_untracked_state(&sess, &mut hasher);
472+
track_state(&sess, &mut hasher);
473473
sess.opts.untracked_state_hash = hasher.finish()
474474
}
475475

compiler/rustc_interface/src/passes.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ fn env_var_os<'tcx>(tcx: TyCtxt<'tcx>, key: &'tcx OsStr) -> Option<&'tcx OsStr>
495495
// NOTE: This only works for passes run before `write_dep_info`. See that
496496
// for extension points for configuring environment variables to be
497497
// properly change-tracked.
498-
tcx.sess.psess.env_depinfo.borrow_mut().insert((
498+
tcx.sess.env_depinfo.borrow_mut().insert((
499499
Symbol::intern(&key.to_string_lossy()),
500500
value.as_ref().and_then(|value| value.to_str()).map(|value| Symbol::intern(value)),
501501
));
@@ -607,7 +607,7 @@ fn write_out_deps(tcx: TyCtxt<'_>, outputs: &OutputFilenames, out_filenames: &[P
607607

608608
// Account for explicitly marked-to-track files
609609
// (e.g. accessed in proc macros).
610-
let file_depinfo = sess.psess.file_depinfo.borrow();
610+
let file_depinfo = sess.file_depinfo.borrow();
611611

612612
let normalize_path = |path: PathBuf| escape_dep_filename(&path.to_string_lossy());
613613

@@ -719,7 +719,7 @@ fn write_out_deps(tcx: TyCtxt<'_>, outputs: &OutputFilenames, out_filenames: &[P
719719
}
720720

721721
// Emit special comments with information about accessed environment variables.
722-
let env_depinfo = sess.psess.env_depinfo.borrow();
722+
let env_depinfo = sess.env_depinfo.borrow();
723723
if !env_depinfo.is_empty() {
724724
// We will soon sort, so the initial order does not matter.
725725
#[allow(rustc::potential_query_instability)]

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
///

0 commit comments

Comments
 (0)