fitzgen / bumpalo

A fast bump allocation arena for Rust
https://docs.rs/bumpalo
Apache License 2.0
1.39k stars 110 forks source link

Use `MaybeUninit` in the return type for `[try_]alloc_layout` #93

Open fitzgen opened 3 years ago

fitzgen commented 3 years ago

MaybeUninit wasn't stable when these APIs were added. Now it is.

Note that this is a breaking change and will require a version bump.

rtfeldman commented 1 year ago

I'd be happy to implement this! To clarify, is the idea to have the return type for those two functions use &[MaybeUninit<u8>] instead of NonNull<u8>?

That makes more sense to me than MaybeUninit<&[u8]> because the slice's metadata is initialized (e.g. its length is available without unsafe), it's just the bytes that aren't.

fitzgen commented 12 months ago

I'd be happy to implement this! To clarify, is the idea to have the return type for those two functions use &[MaybeUninit<u8>] instead of NonNull<u8>?

That makes more sense to me than MaybeUninit<&[u8]> because the slice's metadata is initialized (e.g. its length is available without unsafe), it's just the bytes that aren't.

That is correct.

However I don't think we actually want to implement this until we're ready for a breaking change to bumpalo, which probably won't be until std supports custom allocators or some other really well motivated reason.

We would also want to double check that this change doesn't regress the performance of allocation, since all the allocation APIs are built on top of these methods.