-
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
Alloc methods should take layout by reference #48458
Comments
I feel that Layout being passed by-value is very intended. It is 2-usize worth of data, which will usually be split over registers for the call and end up being more efficient than going through a reference. |
clippy warning about this seems like a false positive though. |
Fair enough. @Manishearth do you have thoughts on clippy's behavior here? Is this just one of those situations in which the right move is to silence clippy with an |
Hmm, Layout is Copy, Clippy shouldn't be warning on Copy period. Will have a look |
Doesn't look like it's |
That seems incorrect? In this case the clippy lint is working as it should; taking non-copy types by-move isn't really good. If you're doing this for perf reasons slap on an allow. |
Incorrect in that |
Layout should be Copy. If it's not because it's considered a hazard (much like how Range isn't Copy) then it should be passed by reference because otherwise it gets consumed each time and needs explicit cloning. |
Also, IIRC, the reason that it's not
Given the rest of this comment, I tend to agree. |
Yeah, that reasoning makes sense. In that case these APIs definitely should operate by-ref. |
cc @gankro |
@joshlf This is the first I hear of (FWIW I care less about the details of the |
Hmm, I don't see a compelling reason to make
All that to say, I don't think how the optimizer is going to pass it around should be the criteria to decide on |
@SimonSapin weird, I could have sworn that I'd brought this issue up before and that was the answer. I couldn't find it by Googling, though, so maybe I was just dreaming. |
@joshlf It’s quite possible that someone said that, but it wasn’t me so I can’t tell you about reasoning and such. |
I found it; see my previous comment. |
I chatted with @pnkfelix about this today. It’s been several years now since the allocation APIs was considered as hypothetically enabling GC integration, but nothing concrete has happened in that space since. In particular, the idea was that users would have to go through the allocator to create a But now we have a |
Implement Copy for std::alloc::Layout Fixes #48458
Currently, the methods of the
Alloc
trait that take aLayout
take it by value. This is unnecessary, and makes clippy unhappy. Instead, they should take theirLayout
arguments by reference.The text was updated successfully, but these errors were encountered: