missed optimimization: needless clone of stdlib non-copy type is not eliminated
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
code: https://rust.godbolt.org/z/5M1nnhEbY (godbolt isn't letting me copy it for some reason)
compiler version: 1.85.0
I understand that technically Clone can have side effects, but standard library types should be able to use some sort of perma-unstable attribute to assert that their Clone impl does not (technically calling the allocator is an arbitrary side-effect, but i believe rust already has a policy that allocations can be eliminated).
Types that use derive(Clone), where all of the fields are pure types, should also have their clone impls marked as safe.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the Godbolt example with compiler version 1.85.0 and compare the generated code for the standard-library non-copy type. Investigate how the compiler represents Clone side effects and derived Clone implementations, then define a regression check showing when the needless clone is eliminated without changing observable behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100