-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
rustc_mir: handle all aggregate kinds in, and always run, the deaggregator. #48052
Conversation
This might be a bit slow to run, let's see: @bors try |
⌛ Trying commit fda2441f1b34fd6135e7af93aec859ad7e4434ad with merge 23ae5261b60c2cf53547176a3b625359c00f6a5f... |
UI tests still broken on master, concealed test that needed to be updated. @bors try |
rustc_mir: handle all aggregate kinds in, and always run, the deaggregator. This helps with removing`Rvalue::Aggregate` from the MIR, and with enabling more optimizations. r? @nikomatsakis
if tcx.sess.opts.debugging_opts.mir_opt_level <= 2 { | ||
return; | ||
} | ||
|
||
// Don't run on constant MIR, because trans might not be able to | ||
// evaluate the modified MIR. | ||
// FIXME(eddyb) Remove check after miri is merged. | ||
let id = tcx.hir.as_local_node_id(source.def_id).unwrap(); | ||
match (tcx.hir.body_owner_kind(id), source.promoted) { |
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.
Nit: I find this match a bit hard to read. Maybe something like this?
let is_constant = source.promoted.is_some() || match tcx.hir.body_owner_kind(id) {
hir::BodyOwnerKind::Const | hir::BodyOwnerKind::Static(_) => true,
hir::BodyOwnerKind::Fn => tcx.is_const_fn(source.def_id),
};
if is_constant {
return;
}
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.
It's copied from elsewhere, this pattern is used in several passes - and this will hopefully go away ~soon anyway.
while let Some(i) = bb.statements[start..].iter().position(&can_deaggregate) { | ||
let i = start + i; | ||
|
||
// FIXME(eddyb) this is probably more expensive than it should be. |
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.
Seems fine, you could also drain()
and accumulate into a fresh vector or something...
let mut new_statements = vec![];
for statement in bb.statements.drain(..) {
if !can_deaggregate(statement) {
new_statements.push(statement);
}
...
}
though probably you would want to test first that there is at least one match.
lhs.clone().elem(ProjectionElem::ConstantIndex { | ||
offset, | ||
// FIXME(eddyb) `min_length` doesn't appear to be used. | ||
min_length: offset + 1, |
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.
It was intended to be used for slice patterns by borrow check, I believe (and perhaps to handle from_end
).
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 is still a WIP =)
r=me modulo that one nit about the |
@nikomatsakis I don't want to merge with the last commit (which turns this on by default) without perf results - if this is too slow we'd have to optimize it first or wait until we can remove |
// Lowering generator control-flow and variables | ||
// has to happen before we do anything else to them. | ||
generator::StateTransform, | ||
|
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.
We want to lower generator as late as possible, in particular we want to run at least SimplifyLocals
before the StateTransform
. Did you move this up because you triggered the sanity checks in StateTransform
?
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.
Yeah, those sanity checks don't survive past optimizations.
☀️ Test successful - status-travis |
@Mark-Simulacrum Can I get a perf run of this? |
I can reproduce the Travis failure (which didn't trigger on the @bors run) locally - and if I change
from 3 to 4 it passes. With only 3 CGUs, some may get merged (based on MIR complexity?)
According to this comment, the test is wrong and it should use 6 to ensure one CGU per module.I'll push a fix for the test. |
The perf results don't look great for #48052 (comment) seems irrelevant, it's really just slowed down by dealing with individual element destinations. @nikomatsakis Do we defer on array deaggregation, or take the hit? |
@eddyb maybe we should set a threshold? (e.g., deaggregate up to length 8 or 16 or something?) |
@nikomatsakis That's not as useful because my eventual plan is to just kill off |
So @eddyb and I discussed the My current feeling is that we should insert a threshold check for now so that deep-vector doesn't regress, and then re-evaluate as we make those changes. If we have to swallow a compilation time hit on this use case, so be it, but I'd rather wait until later. Also, I'd like to see some perf benchmarks covering big constants that are not cc @rust-lang/compiler -- thoughts? |
My position is that we should just not do arrays for now if that regresses too much. |
@eddyb that seems fine too, let's just open a FIXME |
r=me with that done |
@bors try |
rustc_mir: handle all aggregate kinds in, and always run, the deaggregator. This helps with removing`Rvalue::Aggregate` from the MIR, and with enabling more optimizations. r? @nikomatsakis
@bors retry
|
⌛ Testing commit c9fcede with merge a63e5c3a0377366521072aa3c6bfc5f9484efb52... |
☀️ Test successful - status-appveyor, status-travis |
Do I need to rebase or something?... |
@bors retry It seems we had accidentally revoked bors's push permission, thus the failure to merge. |
⌛ Testing commit c9fcede with merge 625d01a26b2254ee9cd54bf206b7b3c6e74ffbbb... |
💔 Test failed - status-appveyor |
⌛ Testing commit c9fcede with merge a9099f59b5a5d7f9ffb8b5b96f8c4757601c9e9c... |
💔 Test failed - status-appveyor |
rustc_mir: handle all aggregate kinds in, and always run, the deaggregator. This helps with removing`Rvalue::Aggregate` from the MIR, and with enabling more optimizations. r? @nikomatsakis
☀️ Test successful - status-appveyor, status-travis |
This helps with removing
Rvalue::Aggregate
from the MIR, and with enabling more optimizations.r? @nikomatsakis