Skip to content

Commit

Permalink
replaces once_cell::sync::OnceCell with std::sync::OnceLock (#33140)
Browse files Browse the repository at this point in the history
std::sync::OnceLock has become stable since rust 1.70.0 and there is no
longer a need for an external crate dependency.
  • Loading branch information
behzadnouri authored Sep 6, 2023
1 parent 0c896c6 commit 88ee8f5
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 34 deletions.
3 changes: 0 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ num_cpus = "1.16.0"
num_enum = "0.6.1"
num-derive = "0.3"
num-traits = "0.2"
once_cell = "1.18.0"
openssl = "0.10"
ouroboros = "0.15.6"
parking_lot = "0.12"
Expand Down
1 change: 0 additions & 1 deletion accounts-db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ num-derive = { workspace = true }
num-traits = { workspace = true }
num_cpus = { workspace = true }
num_enum = { workspace = true }
once_cell = { workspace = true }
ouroboros = { workspace = true }
percentage = { workspace = true }
qualifier_attr = { workspace = true }
Expand Down
7 changes: 3 additions & 4 deletions accounts-db/src/accounts_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use {
secondary_index::*,
},
log::*,
once_cell::sync::OnceCell,
ouroboros::self_referencing,
rand::{thread_rng, Rng},
rayon::{
Expand All @@ -37,7 +36,7 @@ use {
path::PathBuf,
sync::{
atomic::{AtomicBool, AtomicU64, AtomicU8, AtomicUsize, Ordering},
Arc, Mutex, RwLock, RwLockReadGuard, RwLockWriteGuard,
Arc, Mutex, OnceLock, RwLock, RwLockReadGuard, RwLockWriteGuard,
},
},
thiserror::Error,
Expand Down Expand Up @@ -703,7 +702,7 @@ pub struct AccountsIndex<T: IndexValue, U: DiskIndexValue + From<T> + Into<T>> {
pub max_distance_to_min_scan_slot: AtomicU64,

/// populated at generate_index time - accounts that could possibly be rent paying
pub rent_paying_accounts_by_partition: OnceCell<RentPayingAccountsByPartition>,
pub rent_paying_accounts_by_partition: OnceLock<RentPayingAccountsByPartition>,
}

impl<T: IndexValue, U: DiskIndexValue + From<T> + Into<T>> AccountsIndex<T, U> {
Expand Down Expand Up @@ -737,7 +736,7 @@ impl<T: IndexValue, U: DiskIndexValue + From<T> + Into<T>> AccountsIndex<T, U> {
roots_removed: AtomicUsize::default(),
active_scans: AtomicUsize::default(),
max_distance_to_min_scan_slot: AtomicU64::default(),
rent_paying_accounts_by_partition: OnceCell::default(),
rent_paying_accounts_by_partition: OnceLock::default(),
}
}

Expand Down
8 changes: 4 additions & 4 deletions accounts-db/src/tiered_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ use {
error::TieredStorageError,
footer::{AccountBlockFormat, AccountMetaFormat, OwnersBlockFormat},
index::AccountIndexFormat,
once_cell::sync::OnceCell,
readable::TieredStorageReader,
solana_sdk::{account::ReadableAccount, hash::Hash},
std::{
borrow::Borrow,
fs::OpenOptions,
path::{Path, PathBuf},
sync::OnceLock,
},
writer::TieredStorageWriter,
};
Expand All @@ -45,7 +45,7 @@ pub struct TieredStorageFormat {

#[derive(Debug)]
pub struct TieredStorage {
reader: OnceCell<TieredStorageReader>,
reader: OnceLock<TieredStorageReader>,
format: Option<TieredStorageFormat>,
path: PathBuf,
}
Expand All @@ -66,7 +66,7 @@ impl TieredStorage {
/// is called.
pub fn new_writable(path: impl Into<PathBuf>, format: TieredStorageFormat) -> Self {
Self {
reader: OnceCell::<TieredStorageReader>::new(),
reader: OnceLock::<TieredStorageReader>::new(),
format: Some(format),
path: path.into(),
}
Expand All @@ -77,7 +77,7 @@ impl TieredStorage {
pub fn new_readonly(path: impl Into<PathBuf>) -> TieredStorageResult<Self> {
let path = path.into();
Ok(Self {
reader: OnceCell::with_value(TieredStorageReader::new_from_path(&path)?),
reader: TieredStorageReader::new_from_path(&path).map(OnceLock::from)?,
format: None,
path,
})
Expand Down
2 changes: 0 additions & 2 deletions frozen-abi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ bs58 = { workspace = true }
bv = { workspace = true, features = ["serde"] }
lazy_static = { workspace = true }
log = { workspace = true, features = ["std"] }
once_cell = { workspace = true }
serde = { workspace = true, features = ["derive", "rc"] }
serde_bytes = { workspace = true }
serde_derive = { workspace = true }
Expand All @@ -32,7 +31,6 @@ either = { workspace = true, features = ["use_std"] }
generic-array = { workspace = true, features = ["serde", "more_lengths"] }
im = { workspace = true, features = ["rayon", "serde"] }
memmap2 = { workspace = true }
once_cell = { workspace = true, features = ["alloc", "race"] }
subtle = { workspace = true }

[target.'cfg(any(unix, windows))'.dependencies]
Expand Down
6 changes: 0 additions & 6 deletions frozen-abi/src/abi_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,9 +555,3 @@ impl<O: AbiEnumVisitor, E: AbiEnumVisitor> AbiEnumVisitor for Result<O, E> {
digester.create_child()
}
}

impl<T: AbiExample> AbiExample for once_cell::sync::OnceCell<T> {
fn example() -> Self {
Self::with_value(T::example())
}
}
3 changes: 0 additions & 3 deletions programs/sbf/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ num-derive = { workspace = true }
num-traits = { workspace = true }
num_cpus = { workspace = true }
num_enum = { workspace = true }
once_cell = { workspace = true }
ouroboros = { workspace = true }
percentage = { workspace = true }
rand = { workspace = true }
Expand Down
39 changes: 30 additions & 9 deletions runtime/src/vote_account.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#[cfg(RUSTC_WITH_SPECIALIZATION)]
use solana_frozen_abi::abi_example::AbiExample;
use {
itertools::Itertools,
once_cell::sync::OnceCell,
serde::ser::{Serialize, Serializer},
solana_sdk::{
account::{AccountSharedData, ReadableAccount},
Expand All @@ -12,7 +13,7 @@ use {
cmp::Ordering,
collections::{hash_map::Entry, HashMap},
iter::FromIterator,
sync::Arc,
sync::{Arc, OnceLock},
},
thiserror::Error,
};
Expand All @@ -29,20 +30,20 @@ pub enum Error {
InvalidOwner(/*owner:*/ Pubkey),
}

#[derive(Debug, AbiExample)]
#[derive(Debug)]
struct VoteAccountInner {
account: AccountSharedData,
vote_state: OnceCell<Result<VoteState, Error>>,
vote_state: OnceLock<Result<VoteState, Error>>,
}

pub type VoteAccountsHashMap = HashMap<Pubkey, (/*stake:*/ u64, VoteAccount)>;

#[derive(Clone, Debug, AbiExample, Deserialize)]
#[derive(Clone, Debug, Deserialize)]
#[serde(from = "Arc<VoteAccountsHashMap>")]
pub struct VoteAccounts {
vote_accounts: Arc<VoteAccountsHashMap>,
// Inner Arc is meant to implement copy-on-write semantics.
staked_nodes: OnceCell<
staked_nodes: OnceLock<
Arc<
HashMap<
Pubkey, // VoteAccount.vote_state.node_pubkey.
Expand Down Expand Up @@ -243,7 +244,7 @@ impl TryFrom<AccountSharedData> for VoteAccountInner {
}
Ok(Self {
account,
vote_state: OnceCell::new(),
vote_state: OnceLock::new(),
})
}
}
Expand All @@ -262,7 +263,7 @@ impl Default for VoteAccounts {
fn default() -> Self {
Self {
vote_accounts: Arc::default(),
staked_nodes: OnceCell::new(),
staked_nodes: OnceLock::new(),
}
}
}
Expand All @@ -281,7 +282,7 @@ impl From<Arc<VoteAccountsHashMap>> for VoteAccounts {
fn from(vote_accounts: Arc<VoteAccountsHashMap>) -> Self {
Self {
vote_accounts,
staked_nodes: OnceCell::new(),
staked_nodes: OnceLock::new(),
}
}
}
Expand Down Expand Up @@ -316,6 +317,26 @@ impl Serialize for VoteAccounts {
}
}

#[cfg(RUSTC_WITH_SPECIALIZATION)]
impl AbiExample for VoteAccountInner {
fn example() -> Self {
Self {
account: AccountSharedData::example(),
vote_state: OnceLock::from(Result::<VoteState, Error>::example()),
}
}
}

#[cfg(RUSTC_WITH_SPECIALIZATION)]
impl AbiExample for VoteAccounts {
fn example() -> Self {
Self {
vote_accounts: Arc::<VoteAccountsHashMap>::example(),
staked_nodes: OnceLock::from(Arc::<HashMap<Pubkey, u64>>::example()),
}
}
}

#[cfg(test)]
mod tests {
use {
Expand Down

0 comments on commit 88ee8f5

Please sign in to comment.