use std::marker::PhantomData; use rustc_index::vec::Idx; pub struct AppendOnlyVec { #[cfg(not(parallel_compiler))] vec: elsa::vec::FrozenVec, #[cfg(parallel_compiler)] vec: elsa::sync::LockFreeFrozenVec, _marker: PhantomData, } impl AppendOnlyVec { pub fn new() -> Self { Self { #[cfg(not(parallel_compiler))] vec: elsa::vec::FrozenVec::new(), #[cfg(parallel_compiler)] vec: elsa::sync::LockFreeFrozenVec::new(), _marker: PhantomData, } } pub fn push(&self, val: T) -> I { #[cfg(not(parallel_compiler))] let i = self.vec.len(); #[cfg(not(parallel_compiler))] self.vec.push(val); #[cfg(parallel_compiler)] let i = self.vec.push(val); I::new(i) } pub fn get(&self, i: I) -> Option { let i = i.index(); #[cfg(not(parallel_compiler))] return self.vec.get_copy(i); #[cfg(parallel_compiler)] return self.vec.get(i); } }