-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Fix leaks from panics in destructors #125923
base: master
Are you sure you want to change the base?
Conversation
Some changes occurred in match lowering cc @Nadrieril |
This comment has been minimized.
This comment has been minimized.
087332f
to
b0a0228
Compare
This comment has been minimized.
This comment has been minimized.
b0a0228
to
28ac9be
Compare
@bors try @rust-timer queue r? @pnkfelix (as you've reviewed #78373 3 years ago :3) am looking through these changes myself but would like you to also take a look |
This comment has been minimized.
This comment has been minimized.
Fix leaks from panics in destructors Resurrects rust-lang#78373. This avoids the problem with rust-lang#80949 by not unscheduling drops of function arguments until after the call (so they still get a drop terminator on the function unwind path). Closes rust-lang#47949 r? `@lcnr`
Went through it and mostly understand this PR, am very much not comfortable enough to approve it myself 😅 Thanks @matthewjasper for picking this up again ❤️ really happy about this |
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (1c34390): comparison URL. Overall result: ❌ regressions - ACTION NEEDEDBenchmarking 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 @bors rollup=never Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)Results (primary -1.8%, secondary -4.0%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResults (primary 2.4%, secondary 73.0%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeResults (primary 1.1%, secondary 1.3%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Bootstrap: 673.596s -> 675.825s (0.33%) |
fab4067
to
5a260c7
Compare
5a260c7
to
016ce8f
Compare
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
Large arrays/tuples can have enough operands that removing items one at a time is significantly slower than creating a hash set first.
When building the MIR we sometimes try to unschedule drops. In this we assert that the drop has already been scheduled. Opaque types however may be initialized with an expression kind that we know doesn't have a type that needs to be dropped. To fix this we don't panic if we can't find the drop of a variable with an opaque type.
db9397e
to
3e0db6a
Compare
(will take a day to check this out locally and fully understand these changes in 1-2 weeks if nobody else tries to review it by then) It looks like the crater run still detected some ICE? |
Yes, the push 3 days ago was a fix and test for that ICE |
I really thought that given some time over the weekend I'd be able to review this, but no, this part of the compiler is too unfamiliar to me. r? lcnr |
@bors try |
Fix leaks from panics in destructors Resurrects rust-lang#78373. This avoids the problem with rust-lang#80949 by not unscheduling drops of function arguments until after the call (so they still get a drop terminator on the function unwind path). Closes rust-lang#47949 r? `@lcnr`
☀️ Try build successful - checks-actions |
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
🎉 Experiment
|
@@ -1141,6 +1142,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { | |||
{ | |||
return; | |||
} | |||
// Opaque type may not have been scheduled if its underlying | |||
// type does not need drop. | |||
None if self.local_decls[local].ty.has_opaque_types() => return, |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
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.
so the affected code is
fn if_no_else(c: bool) -> impl Sized {
if c {}
}
where the opaque type gets unified with ()
and ()
does not need drop while impl Sized
does? 🤔 we probably never emit drop for the return value of an if
without an else block or sth?
} else if let Some(destination_local) = destination.as_local() | ||
&& let Some(scope) = scope | ||
{ | ||
this.schedule_drop(span, scope, destination_local, DropKind::Value); |
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 necessary to avoid ICEing when trying to unschedule the drop of a previous match arm here https://github.com/matthewjasper/rust/blob/3e0db6a36f01a5a8978ced19e0b83ebca5cd103c/compiler/rustc_mir_build/src/build/matches/mod.rs#L480-L484
however, this is not enough as we don't schedule a drop if the destination_ty
is an opaque
fn test_me() -> impl Sized {
match 1 {
1 => 'ret: {
break 'ret test_me();
}
_ => {},
};
}
fn main() {}
It works if the destination_ty
is ()
as in this case unschedule_drop
is a noop as needs_drop
returns false
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.
I am very confused by expr_into_dest
.
Ignoring that opaque types require drop even if their hidden type don't means that the destination of stuff like ExprKind::Borrow
would now add a drop, and more importantly, tries to remove a drop in unschedule_drop
, expr_into_dest
has to schedule the drop for dest
to be the last drop in the given scope. If it does not, we just ICE when trying to unschedule the drop for the destination in matches/if else.
I've added an assert that stuff could get unscheduled and it always passes, see a57f57b
stopped my review for now in case you have thoughts here as my next steps would probably be to attempt to significantly restructure the code to see if it works 😅 I feel like the current setup is very prone to break in the future (and also very sus wrt to opaque types, which is more an opaque type issue than an issue with your impl) While reviewing I've made some changes to document/rename things which were confusing to me, the important commit is here 4ba5010 |
@rustbot author |
Resurrects #78373.
This avoids the problem with #80949 by not unscheduling drops of function arguments until after the call (so they still get a drop terminator on the function unwind path).
Closes #47949
r? @lcnr