-
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
Avoid placing immutable lvalues in allocas and zeroing them to cancel cleanup. #11445
Comments
I'm tempted to close this as a dupe of #5016, but there's certainly a lot here. So long as we continue to zero out on movements, we can't promote anything to values (they have to be in I think that @nikomatsakis is working on a patch that does this and requires that you move out of a variable in all branches (to completely eliminate zeroing on movement) |
I found out about #5016 a bit too late, but yeah, that's the main blocker. Pretty much any immutable lvalue that is passed by value (i.e. fits in a register) could otherwise be a I did take a look at @nikomatsakis' patch and cleanup does look a little better, but it still uses zeroing for |
I am working towards this goal, though my current branch does not yet remove zeroing, it just makes the semantics and lifetimes of temporaries better defined and more easily controlled. That said -- we always keep local variables in allocas and I don't expect this to change, because it enables better integration with debuginfo. |
That debuginfo integration is only required when compiling with |
It doesn't seem worth it to me to treat local variables differently depending on whether -Z extra-debug-info is set or not. That said, it may be that once we implement #5016, it's not a big change to make it possible to have by-ref or by-value lvalues, in which case I'm not opposed, but I think readability and general cleanliness of trans takes top priority in this case. Another way to cleanup that generated code would be to do a simple analysis that detects infallible functions and avoids generating landing pads. We'd probably have to store fallibility in the crate metadata, but it need not affect language semantics in any way. |
@nikomatsakis: we can put debug info on registers with |
Triage: updated code:
llvm ir:
It looks very different, is this fixed? |
Yes, static and dynamic drop have both gotten much better since (although filling drop still exists in marginal cases). |
fix some comments Thank you for making Clippy better! We're collecting our changelog from pull request descriptions. If your PR only includes internal changes, you can just write `changelog: none`. Otherwise, please write a short comment explaining your change. It's also helpful for us that the lint name is put within backticks (`` ` ` ``), and then encapsulated by square brackets (`[]`), for example: ``` changelog: [`lint_name`]: your change ``` If your PR fixes an issue, you can add `fixes #issue_number` into this PR description. This way the issue will be automatically closed when your PR is merged. If you added a new lint, here's a checklist for things that will be checked during review or continuous integration. - \[x] Followed [lint naming conventions][lint_naming] - \[x] Added passing UI tests (including committed `.stderr` file) - \[x] `cargo test` passes locally - \[x] Executed `cargo dev update_lints` - \[x] Added lint documentation - \[x] Run `cargo dev fmt` [lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints Note that you can skip the above if you are just opening a WIP PR in order to get feedback. Delete this line and everything above before opening your PR. --- *Please write a short comment explaining your change (or "none" for internal only changes)* changelog: none
This is the current LLVM IR generated at
--opt-level=0
for a seemingly noop transmute:Wherever
x
is moved out of, amemset
call is used to zero the pointer, to "cancel the cleanup" (drop glue ignores NULL pointers and objects with a drop flag of 0).The generated IR could look like this, without affecting semantics:
(it might be even possible to remove the alloca used for the inlined
transmute
call)The reason I wasn't able to implement this behavior in #11252 is the differing scope between the cleanup creation and the cleanup cancellation. It becomes obvious when we have multiple branches:
@huonw recalled someone mentioning requiring to move out of
x
in both branches, but I don't know if that's a viable solution.cc @nikomatsakis @pcwalton @thestinger
The text was updated successfully, but these errors were encountered: