fitzgen / bumpalo

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

Can `bumpalo::collections::vec::Vec` be `Send`? #132

Closed haberman closed 2 years ago

haberman commented 2 years ago

Currently bumpalo::collections::vec::Vec is not Send. Is there a reason for this?

I notice that std::vec::Vec is Send. It seems like both the standard Vec and the bumpalo Vec will point at unaliased memory, so Send should be safe?

Digging a little deeper, I notice that bumpalo::collections::RawVec uses NonNull<T> for its pointer, whereas std::vec::Vec uses Unique<T>. Perhaps the bumpalo Vec could use Unique<T> also?

fitzgen commented 2 years ago

If it was send then bump would have to be sync (which it very much is not) since the vec holds a ref to the bump and will use it to realloc as needed when capacity gets filled and another item is being pushed

fitzgen commented 2 years ago

Note that std vec is only send when the A is send, which wouldn’t be true when A=&’a Bump

haberman commented 2 years ago

I forgot that the vec holds a ref to the bump.

I guess it could work if the bump was passed explicitly for all operations that can realloc? That would be a different type though.