-
Notifications
You must be signed in to change notification settings - Fork 13.3k
rustc_arena: handle recursive allocation, don't trust size_hint #79154
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
rustc_arena: handle recursive allocation, don't trust size_hint #79154
Conversation
In `DroplessArena::alloc_from_iter`, handle allocating from iterators whose `next` calls may themselves allocate on the arena. Also, do not trust the iterator's `size_hint` implementation for correctness. These changes were already made for `TypedArena` in rust-lang#67003.
r? @davidtwco (rust_highfive has picked a reviewer for you, use r? to override) |
I attempted to implement a performance mitigation to avoid the extra copying in certain cases, but it didn't work out. If an exact size hint was available, the mitigation would copy into an appropriately-sized It managed to worsen performance, probably due to a combination of complexity, that it doesn't avoid allocating sometimes like the |
Is this PR a good idea? First, next allocating doesn't cause any issues for the dropless arena. We do Regarding the second point, if cc @bugadani |
Ah, okay. I see I missed the critical difference as to why this was safe for With Nevermind then. :) |
Yup, that's the logic! |
In
DroplessArena::alloc_from_iter
, handle allocating from iteratorswhose
next
calls may themselves allocate on the arena. Also, do nottrust the iterator's
size_hint
implementation for correctness.These changes were already made for
TypedArena
in #67003.