10000 Run various queries from other queries instead of explicitly in phases by oli-obk · Pull Request #108118 · rust-lang/rust · GitHub
[go: up one dir, main page]

Skip to content

Run various queries from other queries instead of explicitly in phases #108118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Leave it to the query system to invoke the typeck query instead of in…
…voking 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
  • Loading branch information
oli-obk committed Apr 21, 2023
commit e18d1f8d2ea0b0feabf7794fb7f5868e3b243709
2 changes: 0 additions & 2 deletions compiler/rustc_hir_analysis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is going to ensure that typecheck errors for all functions are reported without this call?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also regresses the quality of the output of -Ztime-passes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as mentioned in the main post

This phased order of query invocations was already a lie, as any query that looks at types (e.g. the wf checks run before) can cause e.g. const eval which invokes borrowck, which invokes typeck, ...

we already didn't produce correct time tracking for it


check_unused::check_crate(tcx);
check_for_entry_fn(tcx);

Expand Down
5 changes: 0 additions & 5 deletions compiler/rustc_hir_typeck/src/lib.rs
10000
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,6 @@ fn used_trait_imports(tcx: TyCtxt<'_>, def_id: LocalDefId) -> &UnordSet<LocalDef
&*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> {
let fallback = move || tcx.type_of(def_id.to_def_id()).subst_identity();
typeck_with_fallback(tcx, def_id, fallback)
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -871,10 +871,6 @@ rustc_queries! {
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 }
Expand Down
2 changes: 0 additions & 2 deletions src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<UnordSet<LocalDefId>> = LazyLock::new(UnordSet::default);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 1 addition & 7 deletions tests/ui/privacy/privacy2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
8 changes: 1 addition & 7 deletions tests/ui/privacy/privacy3.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
0