From e18d1f8d2ea0b0feabf7794fb7f5868e3b243709 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 16 Feb 2023 15:28:29 +0000 Subject: [PATCH] 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 --- compiler/rustc_hir_analysis/src/lib.rs | 2 -- compiler/rustc_hir_typeck/src/lib.rs | 5 ----- compiler/rustc_middle/src/query/mod.rs | 4 ---- src/librustdoc/core.rs | 2 -- .../bugs/ice-substitution.stderr | 2 +- tests/ui/privacy/privacy2.stderr | 8 +------- tests/ui/privacy/privacy3.stderr | 8 +------- 7 files changed, 3 insertions(+), 28 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/lib.rs b/compiler/rustc_hir_analysis/src/lib.rs index 4c28e28f964..a4b797f77f7 100644 --- a/compiler/rustc_hir_analysis/src/lib.rs +++ b/compiler/rustc_hir_analysis/src/lib.rs @@ -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.sess.time("item_bodies_checking", || tcx.typeck_item_bodies(())); - check_unused::check_crate(tcx); check_for_entry_fn(tcx); diff --git a/compiler/rustc_hir_typeck/src/lib.rs b/compiler/rustc_hir_typeck/src/lib.rs index 08d3593f91f..5ccac9a6925 100644 --- a/compiler/rustc_hir_typeck/src/lib.rs +++ b/compiler/rustc_hir_typeck/src/lib.rs @@ -152,10 +152,6 @@ fn used_trait_imports(tcx: TyCtxt<'_>, def_id: LocalDefId) -> &UnordSet, (): ()) { - 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> { let fallback = move || tcx.type_of(def_id.to_def_id()).subst_identity(); typeck_with_fallback(tcx, def_id, fallback) @@ -479,7 +475,6 @@ fn has_expected_num_generic_args( pub fn provide(providers: &mut Providers) { method::provide(providers); *providers = Providers { - typeck_item_bodies, typeck, diagnostic_only_typeck, has_typeck_results, diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index f81c1c39fc1..3b8f833a9bd 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -871,10 +871,6 @@ separate_provide_extern } - query typeck_item_bodies(_: ()) -> () { - desc { "type-checking all item bodies" } - } - query typeck(key: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> { desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) } cache_on_disk_if { true } diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index b392ba05836..46834a1d7f4 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -258,8 +258,6 @@ pub(crate) fn create_config( override_queries: Some(|_sess, providers, _external_providers| { // Most lints will require typechecking, so just don't run them. 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 providers.used_trait_imports = |_, _| { static EMPTY_SET: LazyLock> = LazyLock::new(UnordSet::default); diff --git a/tests/ui/associated-inherent-types/bugs/ice-substitution.stderr b/tests/ui/associated-inherent-types/bugs/ice-substitution.stderr index 7b0d1c50516..1648cfb266b 100644 --- a/tests/ui/associated-inherent-types/bugs/ice-substitution.stderr +++ b/tests/ui/associated-inherent-types/bugs/ice-substitution.stderr @@ -2,5 +2,5 @@ error: the compiler unexpectedly panicked. this is a bug. query stack during panic: #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 diff --git a/tests/ui/privacy/privacy2.stderr b/tests/ui/privacy/privacy2.stderr index 882f314655d..c2a33ce1f59 100644 --- a/tests/ui/privacy/privacy2.stderr +++ b/tests/ui/privacy/privacy2.stderr @@ -23,13 +23,7 @@ LL | pub fn foo() {} error: requires `sized` lang_item -error: requires `sized` lang_item - -error: requires `sized` lang_item - -error: requires `sized` lang_item - -error: aborting due to 6 previous errors +error: aborting due to 3 previous errors Some errors have detailed explanations: E0432, E0603. For more information about an error, try `rustc --explain E0432`. diff --git a/tests/ui/privacy/privacy3.stderr b/tests/ui/privacy/privacy3.stderr index 42ce456d962..22c1e48b07d 100644 --- a/tests/ui/privacy/privacy3.stderr +++ b/tests/ui/privacy/privacy3.stderr @@ -6,12 +6,6 @@ LL | use bar::gpriv; error: requires `sized` lang_item -error: requires `sized` lang_item - -error: requires `sized` lang_item - -error: requires `sized` lang_item - -error: aborting due to 5 previous errors +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0432`.