Open TimDiekmann opened 4 years ago
Updated OP.
@TimDiekmann what are next steps? Are we waiting for potential feedback from users on our changes to the API before we proceed?
I'm currently testing the API with alloc-compose
. I also testing out, on how well taking &self
is working. While most allocators could use &self
instead of &mut self
this has a major downside: Cell
is !Sync
, so using internal mutability for Sync
allocators have to use atomics or other structs, which introduce more overhead. For the same reason, Bump
from bumpalo is also !Sync
.
I think those downside of &self
are actually advantages, see #55.
- deprecate
GlobalAlloc
Actively emitting deprecation warnings causes churn. What benefit does this bring in exchange?
- add
#[doc(hidden)]
toGlobalAlloc
GlobalAlloc
is stable, so there will always be legacy code that uses it (even if with deprecating warnings). Hiding its docs would be confusing to future readers of such code, for what benefit? Compared to documenting that using AllocRef
instead is preferred.
Isn't that the point of deprecation warnings? Error::source
was introduced in 1.30, Error::cause
was deprecated in 1.33. I expect many more people to use the Error
trait than the GlobalAlloc
trait. Sure, we could also just leave GlobalAlloc
alone :slightly_smiling_face:
Hiding its docs would be confusing to future readers of such code
Fair point.
@TimDiekmann Could you update the roadmap with recent changes and what's left for us to do?
Also, can we proceed with #7 now that unstable generic trait instantiations are supported?
Updated the roadmap.
Also, can we proceed with #7 now that unstable generic trait instantiations are supported?
rust-lang/rust#72314 is not merged yet as @Varkor asked for a few more tests. I will open a new issue for each collection when it's merged.
Thanks for cleaning up the roadmap and outstanding issues π
@Wodann FYI: We have started to implement #7.
Should AllocRef
be renamed Allocator
now or it's a different AllocRef?
Hey I see that the last message in this issue is 3yo, what's the current status? Is there any way to get involved and help move the needle a bit?
@MarinPostma If you use nightly, allocators are very much usable already (and have been since 2021-ish). I figure most people that need allocators already use them, and you can too.
You can make your own allocators and your own allocator-aware collections, and these days even most of alloc/std collections already work custom allocators (#7), with String being the notable holdout (there's a history of attempts to make it happen, current HEAD here https://github.com/rust-lang/rust/pull/101551).
Regarding allocators on stable: if you look at issues in this repository, you'll see we are still a long way off. Personally, I'd want to have some kind of MVP stabilized sooner, possibly at the expense of completely resolving questions such as #15.
Regarding involvement: I don't know of any easy things that need doing. #7 was such a list, but fruit has been picked.
Regarding allocators on stable: if you look at issues in this repository, you'll see we are still a long way off.
As a stopgap, I've seen many people adopt the use of https://github.com/zakarumych/allocator-api2 to get these apis in stable. This includes larger crates like hashbrown
In the spirit of seeking an MVP, is there anything blocking the stabilization of the "required" subset of core::alloc::Allocator
?
For example, consider an Allocator
with only two methods: allocate()
and deallocate()
. Are there any compatibility or stability concerns with stabilizing those two, and then leaving the optional methods for later?
pub unsafe trait Allocator {
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>;
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout);
}
The goal here would be to enable use of Allocator
with third-party crates that do their own alloc management, e.g. for arenas or custom Box
-like types.
I would like to come to the listed issues in the more or less indicated order. Linked issues are not necessarily confirmed, please consult the issues for more details.
AllocRef
:AllocRef
to take&self
MaybeUninit<u8>
rather thanu8
/Introduce a byte type~Allocator aware types:
AllocRef
onBox
GlobalAlloc
:GlobalAlloc
andAlloc
AllocRef
onSystem
withoutGlobalAlloc
GlobalAlloc
when stabilizingAllocRef
GlobalAlloc
whenAllocRef
is stabilized at least three months (two versions)Documentation:
AllocRef
allocator#[global_allocator]
really meansOther: