-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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 sure we handle backwards_incompatible_lint
drops appropriately in drop elaboration
#134486
Conversation
@@ -411,6 +405,27 @@ impl DropTree { | |||
}; | |||
cfg.terminate(block, drop_node.data.source_info, terminator); | |||
} | |||
DropKind::ForLint => { |
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 ended up adjusting this to act like DropKind::Storage
, but inserting a BackwardIncompatibleDropHint
instead of a StorageDead
. Previously we'd insert a drop terminator here.
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.
Makes sense.
@@ -822,6 +832,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { | |||
}); | |||
block = next; | |||
} | |||
DropKind::ForLint => { |
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.
Previously we were inserting a drop terminator for tail calls. Not certain if this is ever reachable, but it's more correct.
continue; | ||
} | ||
|
||
if storage_dead_on_unwind { |
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'm not certain if we need to handle this unwind block here.
} | ||
|
||
bb29 (cleanup): { | ||
drop(_5) -> [return: bb16, unwind terminate(cleanup)]; |
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.
notably, this is the drop terminator that is bad. previously we were unwinding to bb14, which would drop _5
, then which branched to bb15 -> bb30 which tested a drop flag for _5
(which was never set to false), which branched to bb29 where we would drop _5
yet again.
@nikomatsakis I just want to make sure that you are aware of my comment in #132861 (comment). This approach of using MIR to implement the lint means that it does not work with I also want to make sure you are aware that there are significant false negatives with this lint (such as the basic example in #132861 (comment)), even when doing a full build. That pattern unfortunately happens quite often due to the introduction of |
Hmm! I'll check into that tomorrow morning. Also, doh, the dropck code was indeed an oversight on my part. I'm amazed that didn't trigger test failures! But I guess the drops are rarely inserted. |
(#131326 is on beta, nominating for backport) |
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.
r+
This comment has been minimized.
This comment has been minimized.
@bors p=1 Fixes P-critical unsoundness in beta |
(btw @nikomatsakis, bors doesn't pick up r+ from review comments, only in regular comments) |
@bors p=10 (scheduling before a rollup) |
🌲 The tree is currently closed for pull requests below priority 100. This pull request will be tested once the tree is reopened. |
@jieyouxu thanks! (re: bors, I was intentionally waiting to see that CI was good first...appreciate you forwarding the r= though!) |
🤔 this pr is against the master branch |
@matthiaskrgr: It will get backported. |
|
||
#![deny(tail_expr_drop_order)] | ||
|
||
use std::backtrace::Backtrace; |
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 was probably unintentionally copy-pasted from my mcve
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.
lol ya, doesn't really matter bc i'm not gonna fix it now, and doesn't affect the test
☀️ Test successful - checks-actions |
Finished benchmarking commit (11663cd): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)Results (primary 0.5%)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.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 767.394s -> 769.451s (0.27%) |
I'm not 100% certain, but the changes to the drop handling might be able to trigger an ICE related to
cf. #134541. |
I'm not at home atm but earlier I tried to use nightly-2024-12-20 in the rust-toolchain file of the project from which I created the MCVE and it indeed ICEd with a very similar message (again, not at home right now so I cannot confirm if it has to do something with this patch) |
[beta] backports - Do not call `extern_crate` on current trait on crate mismatch errors rust-lang#133585 - Correctly handle comments in attributes in doctests source code rust-lang#134260 - Correctly document CTFE behavior of is_null and methods that call is_null. rust-lang#134325 - Make sure we handle `backwards_incompatible_lint` drops appropriately in drop elaboration rust-lang#134486 - Bump compiler `cc` to 1.2.5 rust-lang#134505 - Handle `DropKind::ForLint` in coroutines correctly rust-lang#134575 - docs: inline `std::ffi::c_str` types to `std::ffi` rust-lang#134791 - docs: inline `alloc::ffi::c_str` types to `alloc::ffi` rust-lang#134851 r? cuviper
In #131326, a new kind of scheduled drop (
drop_kind: DropKind::Value
+backwards_incompatible_lint: true
) was added so that we could insert a new kind of no-op MIR statement (backward incompatible drop
) for linting purposes.These drops were intended to have no side-effects, but drop elaboration code forgot to handle these drops specially and they were handled otherwise as normal drops in most of the code. This ends up being unsound since we insert more than one drop call for some values, which means that
Drop::drop
could be called more than once.This PR fixes this by splitting out the
DropKind::ForLint
and adjusting the code. I'm not totally certain if all of the places I've adjusted are either reachable or correct, but I'm pretty certain that it's more correct than it was previously.cc @dingxiangfei2009
r? nikomatsakis
Fixes #134482