-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Refactor arena API to permit reuse, play nicely with new #10444
Comments
Note: this plan is not quite actionable, I think it relies on a few features (most obviously the deref trait; less obviously #10445) that are not yet implemented. |
I started sketching out the container side of an allocator API before hitting #8059. With an implementation of vectors and unique pointers taking an allocator type parameter and an allocator instance via a https://github.com/thestinger/rust-core/blob/master/core/vec.rs |
One thing we have to be careful of: multiple memory pools and arenas can share the same
This has the advantage of hiding the memory pool and being more compatible with the |
triage: |
Sure, not sure how much it helps to have it around. |
Add new `redundant_async_block` lint Fixes rust-lang#10444 changelog: [`redundant_async_block`]: new lint to detect `async { future.await }`
For a variety of reasons, I think the arena API should be restructured. This is part of a larger plan to better enable smart pointers and I didn't intend to start by writing out about arenas, but my hand was forced by #10390 where I found myself elaborating on the arena plan in a comment, so let me go ahead and write this down.
Goals of this plan:
new(arena) ...
operatorIn a nutshell, I would like to change arena's signature from:
to:
The memory pool would be the thing that holds the memory. When it is destroyed, the memory is freed. The arena is the allocator itself. distinction between the memory pool and the arena is kind of meaningless and unfortunate. The end goal is to have the arena type be parameterized by a lifetime (
'pool
) that corresponds to the lifetime of the returned values, rather than having the lifetime of the returned values be derived from the lifetime of theself
pointer in thealloc()
call. At the moment, this requires another object to tie the lifetime to, hence the "memory pool".The motivations for this change are:
It allows us to remove the unsafe code that makes an arena artificially mutable.
It will play better with a future
new(arena) Expr
operator, because it allows us to fit in with a (higher-kinded) allocator trait that looks something like:trait Allocator { // Ptr :: * => *
fn alloc(&mut self) -> Ptr;
}
The implementation would look something like this (waving hands wildly with respect to syntax):
ArenaAlloc
would be smart pointer that acts like an owned pointer.The downside of this is that to create an arena, at least today -- and pending the resolution of #3511 -- you would have to do two steps:
If we resolve #3511 in favor of inference, one could write:
but it is still necessary for the
MemoryPool
to be created by the caller, so that the caller can free it.To solve this without a distinct object, we'd need a different kind of lifetime: more or less the
'self
people sometime ask for, a lifetime that is associated with a struct and means "as long as it lives". This is a separate feature request and I'll open an issue about it, but I'm a bit handwavy on how it will work.cc @pnkfelix (per our discussion about reaps)
The text was updated successfully, but these errors were encountered: