Skip to content

Papercuts using shared_vector in rustc #18

Description

@nnethercote

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions