From 3e3e70d529d8c7d7c4d7bc4fefc9f109393b9245 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:19:43 +0200 Subject: Merging upstream version 1.69.0+dfsg1. Signed-off-by: Daniel Baumann --- compiler/rustc_data_structures/src/sync/vec.rs | 41 ++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 compiler/rustc_data_structures/src/sync/vec.rs (limited to 'compiler/rustc_data_structures/src/sync') diff --git a/compiler/rustc_data_structures/src/sync/vec.rs b/compiler/rustc_data_structures/src/sync/vec.rs new file mode 100644 index 000000000..cbea4f059 --- /dev/null +++ b/compiler/rustc_data_structures/src/sync/vec.rs @@ -0,0 +1,41 @@ +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); + } +} -- cgit v1.2.3