1
Fork 0

Auto merge of #85178 - cjgillot:local-crate, r=oli-obk

Remove CrateNum parameter for queries that only work on local crate

The pervasive `CrateNum` parameter is a remnant of the multi-crate rustc idea.

Using `()` as query key in those cases avoids having to worry about the validity of the query key.
This commit is contained in:
bors 2021-05-17 01:42:03 +00:00
commit 3396a383bb
70 changed files with 281 additions and 404 deletions

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;
@ -805,9 +805,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;
@ -816,15 +814,14 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
sess.time("misc_checking_1", || {
parallel!(
{
entry_point = sess
.time("looking_for_entry_point", || rustc_passes::entry::find_entry_point(tcx));
entry_point = sess.time("looking_for_entry_point", || tcx.entry_fn(()));
sess.time("looking_for_plugin_registrar", || {
plugin::build::find_plugin_registrar(tcx)
sess.time("looking_for_plugin_registrar", || tcx.ensure().plugin_registrar_fn(()));
sess.time("looking_for_derive_registrar", || {
tcx.ensure().proc_macro_decls_static(())
});
sess.time("looking_for_derive_registrar", || proc_macro_decls::find(tcx));
let cstore = tcx
.cstore_as_any()
.downcast_ref::<CStore>()
@ -903,11 +900,11 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
sess.time("misc_checking_3", || {
parallel!(
{
tcx.ensure().privacy_access_levels(LOCAL_CRATE);
tcx.ensure().privacy_access_levels(());
parallel!(
{
tcx.ensure().check_private_in_public(LOCAL_CRATE);
tcx.ensure().check_private_in_public(());
},
{
sess.time("death_checking", || rustc_passes::dead::check_crate(tcx));

View file

@ -1,21 +1,15 @@
use rustc_hir as hir;
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
use rustc_hir::def_id::LocalDefId;
use rustc_hir::itemlikevisit::ItemLikeVisitor;
use rustc_middle::ty::query::Providers;
use rustc_middle::ty::TyCtxt;
use rustc_span::symbol::sym;
pub fn find(tcx: TyCtxt<'_>) -> Option<DefId> {
tcx.proc_macro_decls_static(LOCAL_CRATE)
}
fn proc_macro_decls_static(tcx: TyCtxt<'_>, cnum: CrateNum) -> Option<DefId> {
assert_eq!(cnum, LOCAL_CRATE);
fn proc_macro_decls_static(tcx: TyCtxt<'_>, (): ()) -> Option<LocalDefId> {
let mut finder = Finder { tcx, decls: None };
tcx.hir().krate().visit_all_item_likes(&mut finder);
finder.decls.map(|id| tcx.hir().local_def_id(id).to_def_id())
finder.decls.map(|id| tcx.hir().local_def_id(id))
}
struct Finder<'tcx> {

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()?;
@ -302,7 +302,7 @@ impl<'tcx> Queries<'tcx> {
/// to write UI tests that actually test that compilation succeeds without reporting
/// an error.
fn check_for_rustc_errors_attr(tcx: TyCtxt<'_>) {
let def_id = match tcx.entry_fn(LOCAL_CRATE) {
let def_id = match tcx.entry_fn(()) {
Some((def_id, _)) => def_id,
_ => return,
};