-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Make dead code check a query. #93466
Conversation
r? @nagisa (rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
@bors try @rust-timer queue |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
⌛ Trying commit d5edd89788d774568e72164be10a85003618e085 with merge 8d9357a1dbad121b8b946ee45f26ec538118ca50... |
☀️ Try build successful - checks-actions |
Queued 8d9357a1dbad121b8b946ee45f26ec538118ca50 with parent a00e130, future comparison URL. |
Finished benchmarking commit (8d9357a1dbad121b8b946ee45f26ec538118ca50): comparison url. Summary: This benchmark run shows 69 relevant improvements 🎉 but 19 relevant regressions 😿 to instruction counts.
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 led to changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @bors rollup=never |
Could you please add a description to the PR and the commit describing the motivation behind this change (i.e. why is this change being made)? |
@nagisa added one. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM overall. r=me with the two suggestions applied.
@@ -999,7 +999,11 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> { | |||
tcx.ensure().check_private_in_public(()); | |||
}, | |||
{ | |||
sess.time("death_checking", || rustc_passes::dead::check_crate(tcx)); | |||
sess.time("death_checking", || { | |||
tcx.hir().par_for_each_module(|module| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This par_
has no effect right now because we don't build with parallel_compiler
, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. When we are not in parallel_compiler
, for_each_module
and par_for_each_module
are actually the same code.
compiler/rustc_passes/src/dead.rs
Outdated
@@ -726,6 +728,9 @@ impl<'tcx> Visitor<'tcx> for DeadVisitor<'tcx> { | |||
} | |||
|
|||
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) { | |||
if let hir::ItemKind::Mod(..) = item.kind { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, this looks slightly awkward to me. I wonder if it wouldn't be slightly more straightforward if visit_mod
was overriden to be empty and then call walk_mod(visitor, module, module_id)
when entering the visitor in check_mod_deathness
?
That said, no strong opinion. Feel free to ignore, if you current approach is better.
Hm, as for the perf results, it seems like the improvements are almost universally for the incr-unchanged case (naturally), and all the regressions come from incr-changed ones. From the looks of it, the additional cost may be in serializing the query results or some similar query system overhead (for e.g. here just the query to compute live items takes as much time as the |
This comment has been minimized.
This comment has been minimized.
@cjgillot will you be looking into the perf regressions? I would not necessarily consider them hard blockers to landing this PR, but having a well researched description (since mine above is broadly just a guess) of why the perf hit is occurring in the first place would be nice. @bors try @rust-timer queue (not expecting significant changes in results, but the structure of the change will change the output of the timings somewhat and its better to be looking at the “current” version) |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
⌛ Trying commit 2c388378967e0ae6acbae938354c3e5d3f8e6c40 with merge 0c4e6240c88e78143766255d9e71641b59b94632... |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
☀️ Try build successful - checks-actions |
Queued 0c4e6240c88e78143766255d9e71641b59b94632 with parent 8c7f2bf, future comparison URL. |
The logic itself is not changed, so I lean towards query overhead. Without digging very deep in the perf results:
My guess is query system overhead: result hashing and dependency bookkeeping are responsible for the regression. Both are possible ( |
I just realised what could be the at least partially the cause.
to the best of my knowledge means that every time The I wonder if storing the live symbols into |
@bors try @rust-timer queue |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
⌛ Trying commit b615df8d38887490c1b5955a654bd768ccbf9086 with merge fe3d394eec18b66eb89c81e6048e3bb4480c71b5... |
☀️ Try build successful - checks-actions |
Queued fe3d394eec18b66eb89c81e6048e3bb4480c71b5 with parent 86f5e17, future comparison URL. |
Finished benchmarking commit (fe3d394eec18b66eb89c81e6048e3bb4480c71b5): comparison url. Summary: This benchmark run shows 67 relevant improvements 🎉 but 8 relevant regressions 😿 to instruction counts.
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 led to changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @bors rollup=never |
Looks great now. r=me with a cleaned up history. |
@bors r=nagisa |
📌 Commit 4e7d47b has been approved by |
☀️ Test successful - checks-actions |
Finished benchmarking commit (d5f9c40): comparison url. Summary: This benchmark run shows 69 relevant improvements 🎉 but 12 relevant regressions 😿 to instruction counts.
If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression |
This PR does seem to regress, in instruction counts, both |
Is it, really? Wouldn't running |
Switching between
|
Dead code check is run for each invocation of the compiler, even if no modifications were involved.
This PR makes dead code check a query keyed on the module. This allows to skip the check when a module has not changed.
To perform this, a query
live_symbols_and_ignored_derived_traits
is introduced to encapsulate the global analysis of finding live symbols. The second querycheck_mod_deathness
outputs diagnostics for each module based on this first query's results.