Hi, I am experimenting with used shared_vector in rustc to replace the Arc<Vec<TokenTree>> type that is currently used for token streams. It's a nice crate! While working on this I found a few annoyances and missing things that I had to work around, and I thought it would be useful feedback to mention them. I will summarize here but you can also see more details by looking for FIXME(shared_vector) comments in the draft PR at rust-lang/rust#159048.
- An empty
AtomicSharedVector is always given a capacity of 16 due to a check in raw::allocate_buffer_header. This is really surprising and undesirable and I currently work around it by having a static empty token stream that I clone in the empty case.
- The docs for
AtomicSharedVector says "Creates an empty shared buffer without allocating memory." which is untrue, and would be untrue even if the capacity was zero.
Vector lacks a by-value impl IntoIterator impl. (It only has impls on &Vector and &mut Vector.)
Vector and AtomicSharedVector both lack a FromIterator impl, so can't be constructed with collect.
AtomicSharedVector doesn't impl Eq even though it impls PartialEq.
AtomicSharedVector doesn't impl Hash.
AtomicSharedVector lacks splice. (Vector has it, so I currently use into_unique + into_shared_atomic as a workaround.)
- When pushing to an empty
Vector the capacity goes from zero to eight. In comparison, std::vec::Vec goes from zero to four. There's no perfect choice here, but four feels better to me. We have lots of short token streams and it's annoying to have a length of one or two and a capacity of eight.
Hi, I am experimenting with used
shared_vectorin rustc to replace theArc<Vec<TokenTree>>type that is currently used for token streams. It's a nice crate! While working on this I found a few annoyances and missing things that I had to work around, and I thought it would be useful feedback to mention them. I will summarize here but you can also see more details by looking forFIXME(shared_vector)comments in the draft PR at rust-lang/rust#159048.AtomicSharedVectoris always given a capacity of 16 due to a check inraw::allocate_buffer_header. This is really surprising and undesirable and I currently work around it by having a static empty token stream that I clone in the empty case.AtomicSharedVectorsays "Creates an empty shared buffer without allocating memory." which is untrue, and would be untrue even if the capacity was zero.Vectorlacks a by-value implIntoIteratorimpl. (It only has impls on&Vectorand&mut Vector.)VectorandAtomicSharedVectorboth lack aFromIteratorimpl, so can't be constructed withcollect.AtomicSharedVectordoesn't implEqeven though it implsPartialEq.AtomicSharedVectordoesn't implHash.AtomicSharedVectorlackssplice. (Vectorhas it, so I currently useinto_unique+into_shared_atomicas a workaround.)Vectorthe capacity goes from zero to eight. In comparison,std::vec::Vecgoes from zero to four. There's no perfect choice here, but four feels better to me. We have lots of short token streams and it's annoying to have a length of one or two and a capacity of eight.