replaces once_cell::sync::OnceCell with std::sync::OnceLock (#33140)

std::sync::OnceLock has become stable since rust 1.70.0 and there is no
longer a need for an external crate dependency.
This commit is contained in:
behzad nouri 2023-09-06 16:46:51 +00:00 committed by GitHub
parent 0c896c6076
commit 88ee8f5820
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 37 additions and 34 deletions

3
Cargo.lock generated
View File

@ -5173,7 +5173,6 @@ dependencies = [
"num-traits",
"num_cpus",
"num_enum 0.6.1",
"once_cell",
"ouroboros",
"percentage",
"qualifier_attr",
@ -5937,7 +5936,6 @@ dependencies = [
"lazy_static",
"log",
"memmap2",
"once_cell",
"rustc_version 0.4.0",
"serde",
"serde_bytes",
@ -6854,7 +6852,6 @@ dependencies = [
"num-traits",
"num_cpus",
"num_enum 0.6.1",
"once_cell",
"ouroboros",
"percentage",
"rand 0.8.5",

View File

@ -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"

View File

@ -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 }

View File

@ -13,7 +13,6 @@ use {
secondary_index::*,
},
log::*,
once_cell::sync::OnceCell,
ouroboros::self_referencing,
rand::{thread_rng, Rng},
rayon::{
@ -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,
@ -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> {
@ -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(),
}
}

View File

@ -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,
};
@ -45,7 +45,7 @@ pub struct TieredStorageFormat {
#[derive(Debug)]
pub struct TieredStorage {
reader: OnceCell<TieredStorageReader>,
reader: OnceLock<TieredStorageReader>,
format: Option<TieredStorageFormat>,
path: PathBuf,
}
@ -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(),
}
@ -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,
})

View File

@ -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 }
@ -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]

View File

@ -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())
}
}

View File

@ -4496,7 +4496,6 @@ dependencies = [
"num-traits",
"num_cpus",
"num_enum 0.6.1",
"once_cell",
"ouroboros",
"percentage",
"qualifier_attr",
@ -4942,7 +4941,6 @@ dependencies = [
"lazy_static",
"log",
"memmap2",
"once_cell",
"rustc_version",
"serde",
"serde_bytes",
@ -5548,7 +5546,6 @@ dependencies = [
"num-traits",
"num_cpus",
"num_enum 0.6.1",
"once_cell",
"ouroboros",
"percentage",
"rand 0.8.5",

View File

@ -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 }

View File

@ -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},
@ -12,7 +13,7 @@ use {
cmp::Ordering,
collections::{hash_map::Entry, HashMap},
iter::FromIterator,
sync::Arc,
sync::{Arc, OnceLock},
},
thiserror::Error,
};
@ -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.
@ -243,7 +244,7 @@ impl TryFrom<AccountSharedData> for VoteAccountInner {
}
Ok(Self {
account,
vote_state: OnceCell::new(),
vote_state: OnceLock::new(),
})
}
}
@ -262,7 +263,7 @@ impl Default for VoteAccounts {
fn default() -> Self {
Self {
vote_accounts: Arc::default(),
staked_nodes: OnceCell::new(),
staked_nodes: OnceLock::new(),
}
}
}
@ -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(),
}
}
}
@ -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 {