Use () for analysis.

This commit is contained in:
Camille GILLOT 2021-05-11 14:50:54 +02:00
parent 0bde3b1f80
commit 1fb9cad50a
9 changed files with 16 additions and 24 deletions

View File

@ -21,7 +21,6 @@ use rustc_data_structures::sync::SeqCst;
use rustc_errors::registry::{InvalidErrorCode, Registry};
use rustc_errors::{ErrorReported, PResult};
use rustc_feature::find_gated_cfg;
use rustc_hir::def_id::LOCAL_CRATE;
use rustc_interface::util::{self, collect_crate_types, get_builtin_codegen_backend};
use rustc_interface::{interface, Queries};
use rustc_lint::LintStore;
@ -389,7 +388,7 @@ fn run_compiler(
}
queries.global_ctxt()?.peek_mut().enter(|tcx| {
let result = tcx.analysis(LOCAL_CRATE);
let result = tcx.analysis(());
if sess.opts.debugging_opts.save_analysis {
let crate_name = queries.crate_name()?.peek().clone();
sess.time("save_analysis", || {

View File

@ -4,7 +4,6 @@ use rustc_ast as ast;
use rustc_ast_pretty::pprust;
use rustc_errors::ErrorReported;
use rustc_hir as hir;
use rustc_hir::def_id::LOCAL_CRATE;
use rustc_hir_pretty as pprust_hir;
use rustc_middle::hir::map as hir_map;
use rustc_middle::ty::{self, TyCtxt};
@ -74,7 +73,7 @@ where
f(&annotation, tcx.hir().krate())
}
PpHirMode::Typed => {
abort_on_err(tcx.analysis(LOCAL_CRATE), tcx.sess);
abort_on_err(tcx.analysis(()), tcx.sess);
let annotation = TypedAnnotation { tcx, maybe_typeck_results: Cell::new(None) };
tcx.dep_graph.with_ignore(|| f(&annotation, tcx.hir().krate()))
@ -475,7 +474,7 @@ fn print_with_analysis(
ppm: PpMode,
ofile: Option<&Path>,
) -> Result<(), ErrorReported> {
tcx.analysis(LOCAL_CRATE)?;
tcx.analysis(())?;
let out = match ppm {
Mir => {

View File

@ -12,7 +12,7 @@ use rustc_data_structures::temp_dir::MaybeTempDir;
use rustc_data_structures::{box_region_allow_access, declare_box_region_type, parallel};
use rustc_errors::{ErrorReported, PResult};
use rustc_expand::base::ExtCtxt;
use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
use rustc_hir::def_id::LOCAL_CRATE;
use rustc_hir::Crate;
use rustc_lint::LintStore;
use rustc_metadata::creader::CStore;
@ -809,9 +809,7 @@ pub fn create_global_ctxt<'tcx>(
/// Runs the resolution, type-checking, region checking and other
/// miscellaneous analysis passes on the crate.
fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
assert_eq!(cnum, LOCAL_CRATE);
fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
rustc_passes::hir_id_validator::check_crate(tcx);
let sess = tcx.sess;

View File

@ -285,7 +285,7 @@ impl<'tcx> Queries<'tcx> {
self.ongoing_codegen.compute(|| {
let outputs = self.prepare_outputs()?;
self.global_ctxt()?.peek_mut().enter(|tcx| {
tcx.analysis(LOCAL_CRATE).ok();
tcx.analysis(()).ok();
// Don't do code generation if there were any errors
self.session().compile_status()?;

View File

@ -361,9 +361,9 @@ pub fn provide(providers: &mut Providers) {
assert_eq!(cnum, LOCAL_CRATE);
CStore::from_tcx(tcx).has_global_allocator()
},
postorder_cnums: |tcx, cnum| {
assert_eq!(cnum, LOCAL_CRATE);
tcx.arena.alloc_slice(&CStore::from_tcx(tcx).crate_dependencies_in_postorder(cnum))
postorder_cnums: |tcx, ()| {
tcx.arena
.alloc_slice(&CStore::from_tcx(tcx).crate_dependencies_in_postorder(LOCAL_CRATE))
},
..*providers

View File

@ -251,7 +251,7 @@ pub fn used_crates(tcx: TyCtxt<'_>, prefer: LinkagePreference) -> Vec<(CrateNum,
Some((cnum, path))
})
.collect::<Vec<_>>();
let mut ordering = tcx.postorder_cnums(LOCAL_CRATE).to_owned();
let mut ordering = tcx.postorder_cnums(()).to_owned();
ordering.reverse();
libs.sort_by_cached_key(|&(a, _)| ordering.iter().position(|x| *x == a));
libs

View File

@ -114,7 +114,7 @@ rustc_queries! {
cache_on_disk_if { key.is_local() }
}
query analysis(key: CrateNum) -> Result<(), ErrorReported> {
query analysis(key: ()) -> Result<(), ErrorReported> {
eval_always
desc { "running analysis passes on this crate" }
}
@ -1381,7 +1381,7 @@ rustc_queries! {
eval_always
desc { "looking at the source for a crate" }
}
query postorder_cnums(_: CrateNum) -> &'tcx [CrateNum] {
query postorder_cnums(_: ()) -> &'tcx [CrateNum] {
eval_always
desc { "generating a postorder list of CrateNums" }
}
@ -1394,8 +1394,7 @@ rustc_queries! {
eval_always
desc { |tcx| "maybe_unused_trait_import for `{}`", tcx.def_path_str(def_id.to_def_id()) }
}
query maybe_unused_extern_crates(_: CrateNum)
-> &'tcx [(LocalDefId, Span)] {
query maybe_unused_extern_crates(_: ()) -> &'tcx [(LocalDefId, Span)] {
eval_always
desc { "looking up all possibly unused extern crates" }
}

View File

@ -2795,10 +2795,7 @@ pub fn provide(providers: &mut ty::query::Providers) {
tcx.crate_name
};
providers.maybe_unused_trait_import = |tcx, id| tcx.maybe_unused_trait_imports.contains(&id);
providers.maybe_unused_extern_crates = |tcx, cnum| {
assert_eq!(cnum, LOCAL_CRATE);
&tcx.maybe_unused_extern_crates[..]
};
providers.maybe_unused_extern_crates = |tcx, ()| &tcx.maybe_unused_extern_crates[..];
providers.names_imported_by_glob_use =
|tcx, id| tcx.arena.alloc(tcx.glob_map.get(&id).cloned().unwrap_or_default());

View File

@ -1,7 +1,7 @@
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_errors::Applicability;
use rustc_hir as hir;
use rustc_hir::def_id::{DefId, LocalDefId, LOCAL_CRATE};
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::itemlikevisit::ItemLikeVisitor;
use rustc_middle::ty::TyCtxt;
use rustc_session::lint;
@ -77,7 +77,7 @@ fn unused_crates_lint(tcx: TyCtxt<'_>) {
// can always suggest removing (no matter which edition we are
// in).
let unused_extern_crates: FxHashMap<LocalDefId, Span> = tcx
.maybe_unused_extern_crates(LOCAL_CRATE)
.maybe_unused_extern_crates(())
.iter()
.filter(|&&(def_id, _)| {
// The `def_id` here actually was calculated during resolution (at least