Leave it to the query system to invoke the typeck query instead of invoking it eagerly.

Later queries that are run on all body owners will invoke typeck as they need information from its result to perform their own logic
This commit is contained in:
Oli Scherer 2023-02-16 15:28:29 +00:00
parent 409661936f
commit e18d1f8d2e
7 changed files with 3 additions and 28 deletions

View File

@ -496,8 +496,6 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
tcx.hir().for_each_module(|module| tcx.ensure().check_mod_item_types(module)) tcx.hir().for_each_module(|module| tcx.ensure().check_mod_item_types(module))
}); });
tcx.sess.time("item_bodies_checking", || tcx.typeck_item_bodies(()));
check_unused::check_crate(tcx); check_unused::check_crate(tcx);
check_for_entry_fn(tcx); check_for_entry_fn(tcx);

View File

@ -152,10 +152,6 @@ fn used_trait_imports(tcx: TyCtxt<'_>, def_id: LocalDefId) -> &UnordSet<LocalDef
&*tcx.typeck(def_id).used_trait_imports &*tcx.typeck(def_id).used_trait_imports
} }
fn typeck_item_bodies(tcx: TyCtxt<'_>, (): ()) {
tcx.hir().par_body_owners(|body_owner_def_id| tcx.ensure().typeck(body_owner_def_id));
}
fn typeck<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &ty::TypeckResults<'tcx> { fn typeck<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &ty::TypeckResults<'tcx> {
let fallback = move || tcx.type_of(def_id.to_def_id()).subst_identity(); let fallback = move || tcx.type_of(def_id.to_def_id()).subst_identity();
typeck_with_fallback(tcx, def_id, fallback) typeck_with_fallback(tcx, def_id, fallback)
@ -479,7 +475,6 @@ fn has_expected_num_generic_args(
pub fn provide(providers: &mut Providers) { pub fn provide(providers: &mut Providers) {
method::provide(providers); method::provide(providers);
*providers = Providers { *providers = Providers {
typeck_item_bodies,
typeck, typeck,
diagnostic_only_typeck, diagnostic_only_typeck,
has_typeck_results, has_typeck_results,

View File

@ -871,10 +871,6 @@
separate_provide_extern separate_provide_extern
} }
query typeck_item_bodies(_: ()) -> () {
desc { "type-checking all item bodies" }
}
query typeck(key: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> { query typeck(key: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> {
desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) } desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) }
cache_on_disk_if { true } cache_on_disk_if { true }

View File

@ -258,8 +258,6 @@ pub(crate) fn create_config(
override_queries: Some(|_sess, providers, _external_providers| { override_queries: Some(|_sess, providers, _external_providers| {
// Most lints will require typechecking, so just don't run them. // Most lints will require typechecking, so just don't run them.
providers.lint_mod = |_, _| {}; providers.lint_mod = |_, _| {};
// Prevent `rustc_hir_analysis::check_crate` from calling `typeck` on all bodies.
providers.typeck_item_bodies = |_, _| {};
// hack so that `used_trait_imports` won't try to call typeck // hack so that `used_trait_imports` won't try to call typeck
providers.used_trait_imports = |_, _| { providers.used_trait_imports = |_, _| {
static EMPTY_SET: LazyLock<UnordSet<LocalDefId>> = LazyLock::new(UnordSet::default); static EMPTY_SET: LazyLock<UnordSet<LocalDefId>> = LazyLock::new(UnordSet::default);

View File

@ -2,5 +2,5 @@ error: the compiler unexpectedly panicked. this is a bug.
query stack during panic: query stack during panic:
#0 [typeck] type-checking `weird` #0 [typeck] type-checking `weird`
#1 [typeck_item_bodies] type-checking all item bodies #1 [used_trait_imports] finding used_trait_imports `weird`
end of query stack end of query stack

View File

@ -23,13 +23,7 @@ LL | pub fn foo() {}
error: requires `sized` lang_item error: requires `sized` lang_item
error: requires `sized` lang_item error: aborting due to 3 previous errors
error: requires `sized` lang_item
error: requires `sized` lang_item
error: aborting due to 6 previous errors
Some errors have detailed explanations: E0432, E0603. Some errors have detailed explanations: E0432, E0603.
For more information about an error, try `rustc --explain E0432`. For more information about an error, try `rustc --explain E0432`.

View File

@ -6,12 +6,6 @@ LL | use bar::gpriv;
error: requires `sized` lang_item error: requires `sized` lang_item
error: requires `sized` lang_item error: aborting due to 2 previous errors
error: requires `sized` lang_item
error: requires `sized` lang_item
error: aborting due to 5 previous errors
For more information about this error, try `rustc --explain E0432`. For more information about this error, try `rustc --explain E0432`.