Skip to content
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

Remove ItemLikeVisitor impls from rustc_typeck #96531

Merged

Conversation

kckeiks
Copy link
Contributor

@kckeiks kckeiks commented Apr 28, 2022

Issue #95004
cc @cjgillot

@rustbot rustbot added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Apr 28, 2022
@rust-highfive
Copy link
Contributor

r? @davidtwco

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 28, 2022
@kckeiks kckeiks force-pushed the remove-item-like-visitor-from-rustc-typeck branch from 80650cd to abad872 Compare April 28, 2022 19:17
@@ -1,4 +1,4 @@
error: no path from `x::<impl Foo for char>` to `typeck`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cjgillot the modifications in compiler/rustc_typeck/src/coherence/inherent_impls.rs caused this change.

Copy link
Contributor

Choose a reason for hiding this comment

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

The current code checks each module independently. Having those checks performed on the whole crate at once create new dependency edges. This may be what causes the diagnostic changes.

Copy link
Contributor

Choose a reason for hiding this comment

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

This can be resolved by adding a eval_always to the hir_crate_items query declaration.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hir_crate_items already has eval_always.

    /// All items in the crate.
    query hir_crate_items(_: ()) -> rustc_middle::hir::ModuleItems {
        storage(ArenaCacheSelector<'tcx>)
        eval_always
        desc { "get HIR crate items" }
    }

@jackh726
Copy link
Member

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 28, 2022
@bors
Copy link
Collaborator

bors commented Apr 28, 2022

⌛ Trying commit abad872c7640a34667505b3420af54f8631893e8 with merge 630a088a8b3689dbbaa9db4b857353a49586c7fe...

Copy link
Contributor

@cjgillot cjgillot left a comment

Choose a reason for hiding this comment

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

I did a first read through from afar. The current code performs typechecking by module, and isolates modules from each another using dedicated queries. What is the benefit of removing the queries? Can't they be implemented using hir_module_items?

@@ -1,4 +1,4 @@
error: no path from `x::<impl Foo for char>` to `typeck`
Copy link
Contributor

Choose a reason for hiding this comment

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

The current code checks each module independently. Having those checks performed on the whole crate at once create new dependency edges. This may be what causes the diagnostic changes.

@kckeiks
Copy link
Contributor Author

kckeiks commented Apr 28, 2022

I did a first read through from afar. The current code performs typechecking by module, and isolates modules from each another using dedicated queries. What is the benefit of removing the queries? Can't they be implemented using hir_module_items?

@cjgillot Sorry, maybe I missed something. This is the current code using those two queries like this:

tcx.sess.time("item_types_checking", || { 
  tcx.hir().for_each_module(|module| tcx.ensure().check_mod_item_types(module))
});

// and

tcx.hir().for_each_module(module| tcx.ensure().check_mod_impl_wf(module)) });

It seemed to me, that in both of these cases, the code is going over all of the Items in the crate so I think it is more straight forward and simpler to loop over tcx.hir().items. I think if we used hir_module_items, we would be doing two traversals, one from calling for_each_module and one from hir_module_items so the changes I proposed avoid that. Please let me know if I missed something or am misunderstanding.

I was not going to remove the queries but that is the only place where they are used so I removed them. I can put them back?

@cjgillot
Copy link
Contributor

I agree that query and no-query code basically do the same thing.
The queries are used to isolate dependencies tracking. In incremental mode, this allows to skip check_mod_item_types and check_mod_impl_wf in unmodified files while recomputing them in modified files.
I'd prefer you put them back in place please.
(I eventually plan to migrate more of typechecking analyses to operate per-module instead of whole-crate.)

@kckeiks
Copy link
Contributor Author

kckeiks commented Apr 28, 2022

I agree that query and no-query code basically do the same thing. The queries are used to isolate dependencies tracking. In incremental mode, this allows to skip check_mod_item_types and check_mod_impl_wf in unmodified files while recomputing them in modified files. I'd prefer you put them back in place please. (I eventually plan to migrate more of typechecking analyses to operate per-module instead of whole-crate.)

I will do that. Looks like I need to research/learn more about the query system. I will message you in Zulip with questions :)

@bors
Copy link
Collaborator

bors commented Apr 28, 2022

☀️ Try build successful - checks-actions
Build commit: 630a088a8b3689dbbaa9db4b857353a49586c7fe (630a088a8b3689dbbaa9db4b857353a49586c7fe)

@rust-timer
Copy link
Collaborator

Queued 630a088a8b3689dbbaa9db4b857353a49586c7fe with parent 1388b38, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (630a088a8b3689dbbaa9db4b857353a49586c7fe): comparison url.

Summary:

  • Primary benchmarks: 😿 relevant regressions found
  • Secondary benchmarks: 😿 relevant regressions found
Regressions 😿
(primary)
Regressions 😿
(secondary)
Improvements 🎉
(primary)
Improvements 🎉
(secondary)
All 😿 🎉
(primary)
count1 83 48 0 0 83
mean2 4.3% 5.5% N/A N/A 4.3%
max 24.3% 36.9% N/A N/A 24.3%

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@bors rollup=never
@rustbot label: +S-waiting-on-review -S-waiting-on-perf +perf-regression

Footnotes

  1. number of relevant changes

  2. the arithmetic mean of the percent change

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Apr 28, 2022
@davidtwco
Copy link
Member

r? @cjgillot

@rust-highfive rust-highfive assigned cjgillot and unassigned davidtwco Apr 29, 2022
@kckeiks kckeiks force-pushed the remove-item-like-visitor-from-rustc-typeck branch from abad872 to c966b98 Compare April 29, 2022 17:24
@kckeiks
Copy link
Contributor Author

kckeiks commented Apr 29, 2022

I added back the two queries and addressed the feedback.

@kckeiks kckeiks force-pushed the remove-item-like-visitor-from-rustc-typeck branch from c966b98 to b9d15d3 Compare April 29, 2022 17:29
tcx.ensure().typeck(it.def_id);
maybe_check_static_with_link_section(tcx, it.def_id, it.span);
check_static_inhabited(tcx, it.def_id, it.span);
match tcx.hir().def_kind(id.def_id) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
match tcx.hir().def_kind(id.def_id) {
match tcx.def_kind(id.def_id) {

tcx.def_kind is a query, and is cached. tcx.hir().def_kind recomputes the value every time, and should be made inaccessible in favor of the query.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I see there are some I left over. I'll make an update.

let inferred_outlives_of = tcx.inferred_outlives_of(id.def_id);
struct_span_err!(
tcx.sess,
tcx.hir().span(id.hir_id()),
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
tcx.hir().span(id.hir_id()),
tcx.def_span(id.def_id),

@cjgillot
Copy link
Contributor

@bors try @rust-timer queue

kckeiks added 14 commits May 6, 2022 11:55
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
…l_wf query

Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
@kckeiks kckeiks force-pushed the remove-item-like-visitor-from-rustc-typeck branch from f0bb18a to 91ef3ba Compare May 6, 2022 16:11
@kckeiks
Copy link
Contributor Author

kckeiks commented May 6, 2022

umbrella The latest upstream changes (presumably #96735) made this pull request unmergeable. Please resolve the merge conflicts.

@cjgillot I fixed the conflict. Let me know if there is anything else that I should address.

@cjgillot
Copy link
Contributor

cjgillot commented May 6, 2022

@bors r+

@bors
Copy link
Collaborator

bors commented May 6, 2022

📌 Commit 91ef3ba has been approved by cjgillot

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 6, 2022
@bors
Copy link
Collaborator

bors commented May 7, 2022

⌛ Testing commit 91ef3ba with merge f6e5570...

@bors
Copy link
Collaborator

bors commented May 7, 2022

☀️ Test successful - checks-actions
Approved by: cjgillot
Pushing f6e5570 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 7, 2022
@bors bors merged commit f6e5570 into rust-lang:master May 7, 2022
@rustbot rustbot added this to the 1.62.0 milestone May 7, 2022
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (f6e5570): comparison url.

Summary:

  • Primary benchmarks: 🎉 relevant improvements found
  • Secondary benchmarks: 🎉 relevant improvements found
Regressions 😿
(primary)
Regressions 😿
(secondary)
Improvements 🎉
(primary)
Improvements 🎉
(secondary)
All 😿 🎉
(primary)
count1 0 0 9 9 9
mean2 N/A N/A -0.3% -0.4% -0.3%
max N/A N/A -0.4% -0.6% -0.4%

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

@rustbot label: -perf-regression

Footnotes

  1. number of relevant changes

  2. the arithmetic mean of the percent change

xFrednet pushed a commit to xFrednet/rust that referenced this pull request May 21, 2022
…-rustc-typeck, r=cjgillot

Remove ItemLikeVisitor impls from rustc_typeck

Issue rust-lang#95004
cc `@cjgillot`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants