Skip to content

Commit

Permalink
Auto merge of #118001 - TaKO8Ki:rollup-fedlwwj, r=TaKO8Ki
Browse files Browse the repository at this point in the history
Rollup of 5 pull requests

Successful merges:

 - #117649 (Move `lint_store`)
 - #117850 (bootstrap: simplify setting unstable-options for tools)
 - #117889 (docs(release): Clarify cargo entries)
 - #117946 (avoid exhaustive i16 test in Miri)
 - #117963 (`rustc_query_system` cleanups)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Nov 17, 2023
2 parents 15a791f + 68f5762 commit 4770d91
Show file tree
Hide file tree
Showing 22 changed files with 115 additions and 157 deletions.
21 changes: 10 additions & 11 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,17 @@ These APIs are now stable in const contexts:
Cargo
-----

- [fix: Set MSRV for internal packages](https://github.com/rust-lang/cargo/pull/12381/)
- [config: merge lists in precedence order](https://github.com/rust-lang/cargo/pull/12515/)
- [fix(update): Clarify meaning of --aggressive as --recursive](https://github.com/rust-lang/cargo/pull/12544/)
- [fix(update): Make `-p` more convenient by being positional](https://github.com/rust-lang/cargo/pull/12545/)
- [feat(help): Add styling to help output ](https://github.com/rust-lang/cargo/pull/12578/)
- [feat(pkgid): Allow incomplete versions when unambigious](https://github.com/rust-lang/cargo/pull/12614/)
- [feat: stabilize credential-process and registry-auth](https://github.com/rust-lang/cargo/pull/12649/)
- [feat(cli): Add '-n' to dry-run](https://github.com/rust-lang/cargo/pull/12660/)
- [In `Cargo.toml`, stabilize `[lints]`](https://github.com/rust-lang/cargo/pull/12648/)
- [Stabilize credential-process and registry-auth](https://github.com/rust-lang/cargo/pull/12649/)
- [Stabilize `--keep-going` build flag](https://github.com/rust-lang/cargo/pull/12568/)
- [Add styling to `--help` output](https://github.com/rust-lang/cargo/pull/12578/)
- [For `cargo clean`, add `--dry-run` flag and summary line at the end](https://github.com/rust-lang/cargo/pull/12638)
- [For `cargo update`, make `--package` more convenient by being positional](https://github.com/rust-lang/cargo/pull/12545/)
- [For `cargo update`, clarify meaning of --aggressive as --recursive](https://github.com/rust-lang/cargo/pull/12544/)
- [Add '-n' as an alias for `--dry-run`](https://github.com/rust-lang/cargo/pull/12660/)
- [Allow version-prefixes in pkgid's (e.g. `--package` flags) to resolve ambiguities](https://github.com/rust-lang/cargo/pull/12614/)
- [In `.cargo/config.toml`, merge lists in precedence order](https://github.com/rust-lang/cargo/pull/12515/)
- [Add support for `target.'cfg(..)'.linker`](https://github.com/rust-lang/cargo/pull/12535/)
- [Stabilize `--keep-going`](https://github.com/rust-lang/cargo/pull/12568/)
- [feat: Stabilize lints](https://github.com/rust-lang/cargo/pull/12648/)

<a id="1.74.0-Rustdoc"></a>

Expand Down Expand Up @@ -200,7 +200,6 @@ These APIs are now stable in const contexts:
Cargo
-----

- [Encode URL params correctly for `SourceId` in `Cargo.lock`.](https://github.com/rust-lang/cargo/pull/12280/)
- [Bail out an error when using `cargo::` in custom build script.](https://github.com/rust-lang/cargo/pull/12332/)

<a id="1.73.0-Misc"></a>
Expand Down
22 changes: 6 additions & 16 deletions compiler/rustc_driver_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use rustc_feature::find_gated_cfg;
use rustc_fluent_macro::fluent_messages;
use rustc_interface::util::{self, collect_crate_types, get_codegen_backend};
use rustc_interface::{interface, Queries};
use rustc_lint::{unerased_lint_store, LintStore};
use rustc_lint::unerased_lint_store;
use rustc_metadata::locator;
use rustc_session::config::{nightly_options, CG_OPTIONS, Z_OPTIONS};
use rustc_session::config::{ErrorOutputType, Input, OutFileName, OutputType, TrimmedDefPaths};
Expand Down Expand Up @@ -356,16 +356,7 @@ fn run_compiler(
let handler = EarlyErrorHandler::new(sopts.error_format);

if sopts.describe_lints {
let mut lint_store =
rustc_lint::new_lint_store(compiler.session().enable_internal_lints());
let registered_lints =
if let Some(register_lints) = compiler.register_lints() {
register_lints(compiler.session(), &mut lint_store);
true
} else {
false
};
describe_lints(compiler.session(), &lint_store, registered_lints);
describe_lints(compiler.session());
return;
}
let should_stop = print_crate_info(
Expand Down Expand Up @@ -442,9 +433,7 @@ fn run_compiler(
}

if sess.opts.describe_lints {
queries
.global_ctxt()?
.enter(|tcx| describe_lints(sess, unerased_lint_store(tcx), true));
describe_lints(sess);
return early_exit();
}

Expand Down Expand Up @@ -991,7 +980,7 @@ the command line flag directly.
}

/// Write to stdout lint command options, together with a list of all available lints
pub fn describe_lints(sess: &Session, lint_store: &LintStore, loaded_lints: bool) {
pub fn describe_lints(sess: &Session) {
safe_println!(
"
Available lint options:
Expand All @@ -1017,6 +1006,7 @@ Available lint options:
lints
}

let lint_store = unerased_lint_store(sess);
let (loaded, builtin): (Vec<_>, _) =
lint_store.get_lints().iter().cloned().partition(|&lint| lint.is_loaded);
let loaded = sort_lints(sess, loaded);
Expand Down Expand Up @@ -1094,7 +1084,7 @@ Available lint options:

print_lint_groups(builtin_groups, true);

match (loaded_lints, loaded.len(), loaded_groups.len()) {
match (sess.registered_lints, loaded.len(), loaded_groups.len()) {
(false, 0, _) | (false, _, 0) => {
safe_println!("Lint tools like Clippy can load additional lints and lint groups.");
}
Expand Down
15 changes: 10 additions & 5 deletions compiler/rustc_interface/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ pub type Result<T> = result::Result<T, ErrorGuaranteed>;
pub struct Compiler {
pub(crate) sess: Lrc<Session>,
codegen_backend: Lrc<dyn CodegenBackend>,
pub(crate) register_lints: Option<Box<dyn Fn(&Session, &mut LintStore) + Send + Sync>>,
pub(crate) override_queries: Option<fn(&Session, &mut Providers)>,
}

Expand All @@ -51,9 +50,6 @@ impl Compiler {
pub fn codegen_backend(&self) -> &Lrc<dyn CodegenBackend> {
&self.codegen_backend
}
pub fn register_lints(&self) -> &Option<Box<dyn Fn(&Session, &mut LintStore) + Send + Sync>> {
&self.register_lints
}
pub fn build_output_filenames(
&self,
sess: &Session,
Expand Down Expand Up @@ -485,10 +481,19 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
sess.opts.untracked_state_hash = hasher.finish()
}

// Even though the session holds the lint store, we can't build the
// lint store until after the session exists. And we wait until now
// so that `register_lints` sees the fully initialized session.
let mut lint_store = rustc_lint::new_lint_store(sess.enable_internal_lints());
if let Some(register_lints) = config.register_lints.as_deref() {
register_lints(&sess, &mut lint_store);
sess.registered_lints = true;
}
sess.lint_store = Some(Lrc::new(lint_store));

let compiler = Compiler {
sess: Lrc::new(sess),
codegen_backend: Lrc::from(codegen_backend),
register_lints: config.register_lints,
override_queries: config.override_queries,
};

Expand Down
17 changes: 2 additions & 15 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,6 @@ fn count_nodes(krate: &ast::Crate) -> usize {
counter.count
}

pub(crate) fn create_lint_store(
sess: &Session,
register_lints: Option<impl Fn(&Session, &mut LintStore)>,
) -> LintStore {
let mut lint_store = rustc_lint::new_lint_store(sess.enable_internal_lints());
if let Some(register_lints) = register_lints {
register_lints(sess, &mut lint_store);
}
lint_store
}

fn pre_expansion_lint<'a>(
sess: &Session,
features: &Features,
Expand Down Expand Up @@ -138,7 +127,7 @@ fn configure_and_expand(
let tcx = resolver.tcx();
let sess = tcx.sess;
let features = tcx.features();
let lint_store = unerased_lint_store(tcx);
let lint_store = unerased_lint_store(&tcx.sess);
let crate_name = tcx.crate_name(LOCAL_CRATE);
let lint_check_node = (&krate, pre_configured_attrs);
pre_expansion_lint(
Expand Down Expand Up @@ -330,7 +319,7 @@ fn early_lint_checks(tcx: TyCtxt<'_>, (): ()) {
}
});

let lint_store = unerased_lint_store(tcx);
let lint_store = unerased_lint_store(&tcx.sess);
rustc_lint::check_ast_node(
sess,
tcx.features(),
Expand Down Expand Up @@ -645,7 +634,6 @@ pub fn create_global_ctxt<'tcx>(
compiler: &'tcx Compiler,
crate_types: Vec<CrateType>,
stable_crate_id: StableCrateId,
lint_store: Lrc<LintStore>,
dep_graph: DepGraph,
untracked: Untracked,
gcx_cell: &'tcx OnceLock<GlobalCtxt<'tcx>>,
Expand Down Expand Up @@ -676,7 +664,6 @@ pub fn create_global_ctxt<'tcx>(
sess,
crate_types,
stable_crate_id,
lint_store,
arena,
hir_arena,
untracked,
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_interface/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,6 @@ impl<'tcx> Queries<'tcx> {
);
let dep_graph = setup_dep_graph(sess, crate_name, stable_crate_id)?;

let lint_store =
Lrc::new(passes::create_lint_store(sess, self.compiler.register_lints.as_deref()));
let cstore = FreezeLock::new(Box::new(CStore::new(
self.codegen_backend().metadata_loader(),
stable_crate_id,
Expand All @@ -164,7 +162,6 @@ impl<'tcx> Queries<'tcx> {
self.compiler,
crate_types,
stable_crate_id,
lint_store,
dep_graph,
untracked,
&self.gcx_cell,
Expand Down
32 changes: 5 additions & 27 deletions compiler/rustc_lint/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,9 +497,6 @@ pub struct LateContext<'tcx> {
/// Items accessible from the crate being checked.
pub effective_visibilities: &'tcx EffectiveVisibilities,

/// The store of registered lints and the lint levels.
pub lint_store: &'tcx LintStore,

pub last_node_with_lint_attrs: hir::HirId,

/// Generic type parameters in scope for the item we are in.
Expand All @@ -515,21 +512,14 @@ pub struct EarlyContext<'a> {
pub buffered: LintBuffer,
}

pub trait LintPassObject: Sized {}

impl LintPassObject for EarlyLintPassObject {}

impl LintPassObject for LateLintPassObject<'_> {}

pub trait LintContext: Sized {
type PassObject: LintPassObject;

pub trait LintContext {
fn sess(&self) -> &Session;
fn lints(&self) -> &LintStore;

/// Emit a lint at the appropriate level, with an optional associated span and an existing diagnostic.
/// Emit a lint at the appropriate level, with an optional associated span and an existing
/// diagnostic.
///
/// Return value of the `decorate` closure is ignored, see [`struct_lint_level`] for a detailed explanation.
/// Return value of the `decorate` closure is ignored, see [`struct_lint_level`] for a detailed
/// explanation.
///
/// [`struct_lint_level`]: rustc_middle::lint::struct_lint_level#decorate-signature
#[rustc_lint_diagnostics]
Expand Down Expand Up @@ -1059,17 +1049,11 @@ impl<'a> EarlyContext<'a> {
}

impl<'tcx> LintContext for LateContext<'tcx> {
type PassObject = LateLintPassObject<'tcx>;

/// Gets the overall compiler `Session` object.
fn sess(&self) -> &Session {
&self.tcx.sess
}

fn lints(&self) -> &LintStore {
&*self.lint_store
}

#[rustc_lint_diagnostics]
fn lookup<S: Into<MultiSpan>>(
&self,
Expand All @@ -1094,17 +1078,11 @@ impl<'tcx> LintContext for LateContext<'tcx> {
}

impl LintContext for EarlyContext<'_> {
type PassObject = EarlyLintPassObject;

/// Gets the overall compiler `Session` object.
fn sess(&self) -> &Session {
&self.builder.sess()
}

fn lints(&self) -> &LintStore {
self.builder.lint_store()
}

#[rustc_lint_diagnostics]
fn lookup<S: Into<MultiSpan>>(
&self,
Expand Down
22 changes: 13 additions & 9 deletions compiler/rustc_lint/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,25 @@
use crate::{passes::LateLintPassObject, LateContext, LateLintPass, LintStore};
use rustc_ast as ast;
use rustc_data_structures::stack::ensure_sufficient_stack;
use rustc_data_structures::sync::join;
use rustc_data_structures::sync::{join, Lrc};
use rustc_hir as hir;
use rustc_hir::def_id::{LocalDefId, LocalModDefId};
use rustc_hir::intravisit as hir_visit;
use rustc_middle::hir::nested_filter;
use rustc_middle::ty::{self, TyCtxt};
use rustc_session::lint::LintPass;
use rustc_session::Session;
use rustc_span::Span;

use std::any::Any;
use std::cell::Cell;

/// Extract the `LintStore` from the query context.
/// This function exists because we've erased `LintStore` as `dyn Any` in the context.
pub fn unerased_lint_store(tcx: TyCtxt<'_>) -> &LintStore {
let store: &dyn Any = &*tcx.lint_store;
/// This function exists because we've erased `LintStore` as `dyn Any` in the session.
pub fn unerased_lint_store(sess: &Session) -> &LintStore {
assert!(sess.lint_store.is_some());
let store: &Lrc<_> = sess.lint_store.as_ref().unwrap();
let store: &dyn Any = &**store;
store.downcast_ref().unwrap()
}

Expand Down Expand Up @@ -353,7 +356,6 @@ pub fn late_lint_mod<'tcx, T: LateLintPass<'tcx> + 'tcx>(
cached_typeck_results: Cell::new(None),
param_env: ty::ParamEnv::empty(),
effective_visibilities: &tcx.effective_visibilities(()),
lint_store: unerased_lint_store(tcx),
last_node_with_lint_attrs: tcx.hir().local_def_id_to_hir_id(module_def_id),
generics: None,
only_module: true,
Expand All @@ -362,8 +364,11 @@ pub fn late_lint_mod<'tcx, T: LateLintPass<'tcx> + 'tcx>(
// Note: `passes` is often empty. In that case, it's faster to run
// `builtin_lints` directly rather than bundling it up into the
// `RuntimeCombinedLateLintPass`.
let mut passes: Vec<_> =
unerased_lint_store(tcx).late_module_passes.iter().map(|mk_pass| (mk_pass)(tcx)).collect();
let mut passes: Vec<_> = unerased_lint_store(&tcx.sess)
.late_module_passes
.iter()
.map(|mk_pass| (mk_pass)(tcx))
.collect();
if passes.is_empty() {
late_lint_mod_inner(tcx, module_def_id, context, builtin_lints);
} else {
Expand Down Expand Up @@ -400,7 +405,7 @@ fn late_lint_mod_inner<'tcx, T: LateLintPass<'tcx>>(
fn late_lint_crate<'tcx>(tcx: TyCtxt<'tcx>) {
// Note: `passes` is often empty.
let mut passes: Vec<_> =
unerased_lint_store(tcx).late_passes.iter().map(|mk_pass| (mk_pass)(tcx)).collect();
unerased_lint_store(&tcx.sess).late_passes.iter().map(|mk_pass| (mk_pass)(tcx)).collect();

if passes.is_empty() {
return;
Expand All @@ -412,7 +417,6 @@ fn late_lint_crate<'tcx>(tcx: TyCtxt<'tcx>) {
cached_typeck_results: Cell::new(None),
param_env: ty::ParamEnv::empty(),
effective_visibilities: &tcx.effective_visibilities(()),
lint_store: unerased_lint_store(tcx),
last_node_with_lint_attrs: hir::CRATE_HIR_ID,
generics: None,
only_module: false,
Expand Down
8 changes: 2 additions & 6 deletions compiler/rustc_lint/src/levels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl LintLevelSets {
}

fn lint_expectations(tcx: TyCtxt<'_>, (): ()) -> Vec<(LintExpectationId, LintExpectation)> {
let store = unerased_lint_store(tcx);
let store = unerased_lint_store(&tcx.sess);

let mut builder = LintLevelsBuilder {
sess: tcx.sess,
Expand Down Expand Up @@ -152,7 +152,7 @@ fn lint_expectations(tcx: TyCtxt<'_>, (): ()) -> Vec<(LintExpectationId, LintExp

#[instrument(level = "trace", skip(tcx), ret)]
fn shallow_lint_levels_on(tcx: TyCtxt<'_>, owner: hir::OwnerId) -> ShallowLintLevelMap {
let store = unerased_lint_store(tcx);
let store = unerased_lint_store(&tcx.sess);
let attrs = tcx.hir_attrs(owner);

let mut levels = LintLevelsBuilder {
Expand Down Expand Up @@ -548,10 +548,6 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
self.features
}

pub(crate) fn lint_store(&self) -> &LintStore {
self.store
}

fn current_specs(&self) -> &FxHashMap<LintId, LevelAndSource> {
self.provider.current_specs()
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/dep_graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ mod dep_node;

pub use rustc_query_system::dep_graph::debug::EdgeFilter;
pub use rustc_query_system::dep_graph::{
debug::DepNodeFilter, hash_result, DepContext, DepGraphQuery, DepNodeColor, DepNodeIndex, Deps,
SerializedDepGraph, SerializedDepNodeIndex, TaskDeps, TaskDepsRef, WorkProduct, WorkProductId,
debug::DepNodeFilter, hash_result, DepContext, DepGraphQuery, DepNodeIndex, Deps,
SerializedDepGraph, SerializedDepNodeIndex, TaskDepsRef, WorkProduct, WorkProductId,
WorkProductMap,
};

Expand Down
Loading

0 comments on commit 4770d91

Please sign in to comment.