1
Fork 0

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

View file

@ -4,7 +4,6 @@ use rustc_ast as ast;
use rustc_ast_pretty::pprust; use rustc_ast_pretty::pprust;
use rustc_errors::ErrorReported; use rustc_errors::ErrorReported;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::LOCAL_CRATE;
use rustc_hir_pretty as pprust_hir; use rustc_hir_pretty as pprust_hir;
use rustc_middle::hir::map as hir_map; use rustc_middle::hir::map as hir_map;
use rustc_middle::ty::{self, TyCtxt}; use rustc_middle::ty::{self, TyCtxt};
@ -74,7 +73,7 @@ where
f(&annotation, tcx.hir().krate()) f(&annotation, tcx.hir().krate())
} }
PpHirMode::Typed => { 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) }; let annotation = TypedAnnotation { tcx, maybe_typeck_results: Cell::new(None) };
tcx.dep_graph.with_ignore(|| f(&annotation, tcx.hir().krate())) tcx.dep_graph.with_ignore(|| f(&annotation, tcx.hir().krate()))
@ -475,7 +474,7 @@ fn print_with_analysis(
ppm: PpMode, ppm: PpMode,
ofile: Option<&Path>, ofile: Option<&Path>,
) -> Result<(), ErrorReported> { ) -> Result<(), ErrorReported> {
tcx.analysis(LOCAL_CRATE)?; tcx.analysis(())?;
let out = match ppm { let out = match ppm {
Mir => { 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_data_structures::{box_region_allow_access, declare_box_region_type, parallel};
use rustc_errors::{ErrorReported, PResult}; use rustc_errors::{ErrorReported, PResult};
use rustc_expand::base::ExtCtxt; 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_hir::Crate;
use rustc_lint::LintStore; use rustc_lint::LintStore;
use rustc_metadata::creader::CStore; use rustc_metadata::creader::CStore;
@ -809,9 +809,7 @@ pub fn create_global_ctxt<'tcx>(
/// Runs the resolution, type-checking, region checking and other /// Runs the resolution, type-checking, region checking and other
/// miscellaneous analysis passes on the crate. /// miscellaneous analysis passes on the crate.
fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> { fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
assert_eq!(cnum, LOCAL_CRATE);
rustc_passes::hir_id_validator::check_crate(tcx); rustc_passes::hir_id_validator::check_crate(tcx);
let sess = tcx.sess; let sess = tcx.sess;

View file

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

View file

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

View file

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

View file

@ -114,7 +114,7 @@ rustc_queries! {
cache_on_disk_if { key.is_local() } cache_on_disk_if { key.is_local() }
} }
query analysis(key: CrateNum) -> Result<(), ErrorReported> { query analysis(key: ()) -> Result<(), ErrorReported> {
eval_always eval_always
desc { "running analysis passes on this crate" } desc { "running analysis passes on this crate" }
} }
@ -1381,7 +1381,7 @@ rustc_queries! {
eval_always eval_always
desc { "looking at the source for a crate" } desc { "looking at the source for a crate" }
} }
query postorder_cnums(_: CrateNum) -> &'tcx [CrateNum] { query postorder_cnums(_: ()) -> &'tcx [CrateNum] {
eval_always eval_always
desc { "generating a postorder list of CrateNums" } desc { "generating a postorder list of CrateNums" }
} }
@ -1394,8 +1394,7 @@ rustc_queries! {
eval_always eval_always
desc { |tcx| "maybe_unused_trait_import for `{}`", tcx.def_path_str(def_id.to_def_id()) } desc { |tcx| "maybe_unused_trait_import for `{}`", tcx.def_path_str(def_id.to_def_id()) }
} }
query maybe_unused_extern_crates(_: CrateNum) query maybe_unused_extern_crates(_: ()) -> &'tcx [(LocalDefId, Span)] {
-> &'tcx [(LocalDefId, Span)] {
eval_always eval_always
desc { "looking up all possibly unused extern crates" } 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 tcx.crate_name
}; };
providers.maybe_unused_trait_import = |tcx, id| tcx.maybe_unused_trait_imports.contains(&id); providers.maybe_unused_trait_import = |tcx, id| tcx.maybe_unused_trait_imports.contains(&id);
providers.maybe_unused_extern_crates = |tcx, cnum| { providers.maybe_unused_extern_crates = |tcx, ()| &tcx.maybe_unused_extern_crates[..];
assert_eq!(cnum, LOCAL_CRATE);
&tcx.maybe_unused_extern_crates[..]
};
providers.names_imported_by_glob_use = providers.names_imported_by_glob_use =
|tcx, id| tcx.arena.alloc(tcx.glob_map.get(&id).cloned().unwrap_or_default()); |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_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir as hir; 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_hir::itemlikevisit::ItemLikeVisitor;
use rustc_middle::ty::TyCtxt; use rustc_middle::ty::TyCtxt;
use rustc_session::lint; use rustc_session::lint;
@ -77,7 +77,7 @@ fn unused_crates_lint(tcx: TyCtxt<'_>) {
// can always suggest removing (no matter which edition we are // can always suggest removing (no matter which edition we are
// in). // in).
let unused_extern_crates: FxHashMap<LocalDefId, Span> = tcx let unused_extern_crates: FxHashMap<LocalDefId, Span> = tcx
.maybe_unused_extern_crates(LOCAL_CRATE) .maybe_unused_extern_crates(())
.iter() .iter()
.filter(|&&(def_id, _)| { .filter(|&&(def_id, _)| {
// The `def_id` here actually was calculated during resolution (at least // The `def_id` here actually was calculated during resolution (at least