Skip to content
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

Ensure we can optimize out does-nothing drops like array::IntoIter<NotNeedsDrop, N> #139422

Open
scottmcm opened this issue Apr 5, 2025 · 1 comment
Labels
A-mir-opt Area: MIR optimizations C-optimization Category: An issue highlighting optimization opportunities or PRs implementing such T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@scottmcm
Copy link
Member

scottmcm commented Apr 5, 2025

Noticed this looking at #139415.

We already do this for !needs_drop types, but std::array::IntoIter<&mut usize, 1> does have a Drop, and thus needs_drop is true because it's not trivially obvious that the Drop::drop won't actually do anything.

But if you look at https://rust.godbolt.org/z/raWrq6rsY you can see that we're emitting the call to the drop.

This probably is about inlining drop shims in MIR? Might be another way, though, if somehow we could notice in cg_ssa.

@scottmcm scottmcm added the A-mir-opt Area: MIR optimizations label Apr 5, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 5, 2025
@the8472
Copy link
Member

the8472 commented Apr 5, 2025

Could we help the compiler to make a better needs_drop determination by having an unsafe NoDrop marker trait?

Hrrm, I guess it would be rather limited, a newtype would already defeat that.

@jieyouxu jieyouxu added C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-optimization Category: An issue highlighting optimization opportunities or PRs implementing such and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. C-enhancement Category: An issue proposing an enhancement or a PR with one. labels Apr 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-mir-opt Area: MIR optimizations C-optimization Category: An issue highlighting optimization opportunities or PRs implementing such T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants