diff --git a/Cargo.toml b/Cargo.toml index e32eb50c..c78a8a33 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,8 @@ keywords = ["database", "embedded", "in-memory", "index", "storage"] categories = ["database-implementations", "data-structures", "caching"] [features] -default = ["wti-predictable-search"] +default = ["std", "wti-predictable-search"] +std = [] perf_measurements = ["dep:performance_measurement", "dep:performance_measurement_codegen"] s3-support = ["dep:rusty-s3", "dep:url", "dep:reqwest", "dep:walkdir", "worktable_codegen/s3-support"] # Moves unique WorkTablesIndex structural CDC work out of the table mutation @@ -45,6 +46,7 @@ data_bucket = { version = "^0.5, >=0.5.7" } derive_more = { version = "2", features = ["from", "error", "display", "debug", "into"] } eyre = "0.6" fastrand = "2" +hashbrown = "0.15" futures = "0.3" indexset = { package = "WorkTablesIndex", version = "^0.0, >=0.0.12", default-features = false, features = ["concurrent", "cdc", "multimap"] } vanilla_indexset = { package = "indexset", version = "0.15", features = ["concurrent", "cdc", "multimap"] } diff --git a/codegen/src/generators/in_memory/index/cdc.rs b/codegen/src/generators/in_memory/index/cdc.rs index ed85e087..3394f3f5 100644 --- a/codegen/src/generators/in_memory/index/cdc.rs +++ b/codegen/src/generators/in_memory/index/cdc.rs @@ -311,7 +311,7 @@ impl InMemoryGenerator { fn process_difference_remove_cdc( &self, link: Link, - difference: std::collections::HashMap<&str, Difference<#avt_type_ident>> + difference: worktable::prelude::HashMap<&str, Difference<#avt_type_ident>> ) -> (#events_ident, Result<(), IndexError<#available_index_ident>>) { #(#process_difference_rows)* (#events_ident { @@ -381,7 +381,7 @@ impl InMemoryGenerator { fn process_difference_insert_cdc( &self, link: Link, - difference: std::collections::HashMap<&str, Difference<#avt_type_ident>> + difference: worktable::prelude::HashMap<&str, Difference<#avt_type_ident>> ) -> (#events_ident, Result<(), IndexError<#available_index_ident>>) { let mut inserted_indexes: Vec<#available_index_ident> = vec![]; let mut partial_events = #events_ident::default(); diff --git a/codegen/src/generators/in_memory/index/usual.rs b/codegen/src/generators/in_memory/index/usual.rs index 2c90abc7..5329a29e 100644 --- a/codegen/src/generators/in_memory/index/usual.rs +++ b/codegen/src/generators/in_memory/index/usual.rs @@ -245,7 +245,7 @@ impl InMemoryGenerator { fn process_difference_remove( &self, link: Link, - difference: std::collections::HashMap<&str, Difference<#avt_type_ident>> + difference: worktable::prelude::HashMap<&str, Difference<#avt_type_ident>> ) -> core::result::Result<(), IndexError<#avt_index_ident>> { #(#process_difference_remove_rows)* core::result::Result::Ok(()) @@ -304,7 +304,7 @@ impl InMemoryGenerator { fn process_difference_insert( &self, link: Link, - difference: std::collections::HashMap<&str, Difference<#avt_type_ident>> + difference: worktable::prelude::HashMap<&str, Difference<#avt_type_ident>> ) -> core::result::Result<(), IndexError<#avt_index_ident>> { let mut inserted_indexes: Vec<#avt_index_ident> = vec![]; #(#process_difference_insert_rows)* diff --git a/codegen/src/generators/in_memory/locks.rs b/codegen/src/generators/in_memory/locks.rs index 78b40aec..1153c65c 100644 --- a/codegen/src/generators/in_memory/locks.rs +++ b/codegen/src/generators/in_memory/locks.rs @@ -24,7 +24,7 @@ impl InMemoryGenerator { .keys() .map(|i| { let name = Ident::new(format!("{i}_lock").as_str(), Span::mixed_site()); - quote! { #name: Option>, } + quote! { #name: Option>, } }) .collect(); @@ -124,8 +124,8 @@ impl InMemoryGenerator { .collect(); quote! { - fn with_lock(id: u16) -> (Self, std::sync::Arc) { - let lock = std::sync::Arc::new(Lock::new(id)); + fn with_lock(id: u16) -> (Self, worktable::prelude::Arc) { + let lock = worktable::prelude::Arc::new(Lock::new(id)); ( Self { #(#rows),* @@ -154,9 +154,9 @@ impl InMemoryGenerator { quote! { #[allow(clippy::mutable_key_type)] - fn lock(&mut self, id: u16) -> (std::collections::HashSet>, std::sync::Arc) { - let mut set = std::collections::HashSet::new(); - let lock = std::sync::Arc::new(Lock::new(id)); + fn lock(&mut self, id: u16) -> (worktable::prelude::HashSet>, worktable::prelude::Arc) { + let mut set = worktable::prelude::HashSet::new(); + let lock = worktable::prelude::Arc::new(Lock::new(id)); #(#rows)* (set, lock) @@ -186,8 +186,8 @@ impl InMemoryGenerator { quote! { #[allow(clippy::mutable_key_type)] - fn merge(&mut self, other: &mut Self) -> std::collections::HashSet> { - let mut set = std::collections::HashSet::new(); + fn merge(&mut self, other: &mut Self) -> worktable::prelude::HashSet> { + let mut set = worktable::prelude::HashSet::new(); #(#rows)* set } diff --git a/codegen/src/generators/in_memory/primary_key.rs b/codegen/src/generators/in_memory/primary_key.rs index 8d58b84f..ac4db3e9 100644 --- a/codegen/src/generators/in_memory/primary_key.rs +++ b/codegen/src/generators/in_memory/primary_key.rs @@ -140,14 +140,14 @@ impl InMemoryGenerator { /// atomic of primitive. fn get_generator_from_type(type_: &TokenStream, i: &Ident) -> syn::Result { Ok(match type_.to_string().as_str() { - "u8" => quote! { std::sync::atomic::AtomicU8 }, - "u16" => quote! { std::sync::atomic::AtomicU16 }, - "u32" => quote! { std::sync::atomic::AtomicU32 }, - "u64" => quote! { std::sync::atomic::AtomicU64 }, - "i8" => quote! { std::sync::atomic::AtomicI8 }, - "i16" => quote! { std::sync::atomic::AtomicI16 }, - "i32" => quote! { std::sync::atomic::AtomicI32 }, - "i64" => quote! { std::sync::atomic::AtomicI64 }, + "u8" => quote! { core::sync::atomic::AtomicU8 }, + "u16" => quote! { core::sync::atomic::AtomicU16 }, + "u32" => quote! { core::sync::atomic::AtomicU32 }, + "u64" => quote! { core::sync::atomic::AtomicU64 }, + "i8" => quote! { core::sync::atomic::AtomicI8 }, + "i16" => quote! { core::sync::atomic::AtomicI16 }, + "i32" => quote! { core::sync::atomic::AtomicI32 }, + "i64" => quote! { core::sync::atomic::AtomicI64 }, // The accepted set is `worktable_dsl::AUTOINCREMENT_TYPES`, and the // arms above must stay equal to it. `check` uses that list to // answer "would the macro accept this", so a second copy drifting diff --git a/codegen/src/generators/in_memory/queries/delete.rs b/codegen/src/generators/in_memory/queries/delete.rs index 911f7e9a..efcde879 100644 --- a/codegen/src/generators/in_memory/queries/delete.rs +++ b/codegen/src/generators/in_memory/queries/delete.rs @@ -186,7 +186,7 @@ impl InMemoryGenerator { quote! { pub async fn #name(&self, by: #type_) -> core::result::Result<(), WorkTableError> { let _bulk_mutation = self.0.lock_manager.bulk_mutation_guard(); - let pks = std::cell::RefCell::new(Vec::new()); + let pks = core::cell::RefCell::new(Vec::new()); self.iter_with(|row| { if row.#field == by { pks.borrow_mut().push(row.get_primary_key()); diff --git a/codegen/src/generators/in_memory/queries/locks.rs b/codegen/src/generators/in_memory/queries/locks.rs index cf80019f..11e15c77 100644 --- a/codegen/src/generators/in_memory/queries/locks.rs +++ b/codegen/src/generators/in_memory/queries/locks.rs @@ -95,9 +95,9 @@ impl InMemoryGenerator { quote! { #[allow(clippy::mutable_key_type)] - pub fn #ident(&mut self, id: u16) -> (std::collections::HashSet>, std::sync::Arc) { - let mut set = std::collections::HashSet::new(); - let new_lock = std::sync::Arc::new(Lock::new(id)); + pub fn #ident(&mut self, id: u16) -> (worktable::prelude::HashSet>, worktable::prelude::Arc) { + let mut set = worktable::prelude::HashSet::new(); + let new_lock = worktable::prelude::Arc::new(Lock::new(id)); #(#inner)* (set, new_lock) } diff --git a/codegen/src/generators/in_memory/queries/select.rs b/codegen/src/generators/in_memory/queries/select.rs index 42139128..744cd0ea 100644 --- a/codegen/src/generators/in_memory/queries/select.rs +++ b/codegen/src/generators/in_memory/queries/select.rs @@ -32,7 +32,7 @@ impl InMemoryGenerator { // Acquire the grace-period guard only when iteration starts. // Merely constructing and retaining a query builder must not // stall retired-link reclamation. - let iter = std::iter::once_with(move || { + let iter = core::iter::once_with(move || { let read_guard = self.0.data.read_guard(); self.0.primary_index.pk_map .iter_values() @@ -55,7 +55,7 @@ impl InMemoryGenerator { return None; } current_link = replacement; - std::hint::spin_loop(); + core::hint::spin_loop(); } None }) diff --git a/codegen/src/generators/in_memory/queries/update.rs b/codegen/src/generators/in_memory/queries/update.rs index 04af1554..a10c90bf 100644 --- a/codegen/src/generators/in_memory/queries/update.rs +++ b/codegen/src/generators/in_memory/queries/update.rs @@ -42,7 +42,7 @@ impl InMemoryGenerator { .keys() .map(|i| { quote! { - std::mem::swap(&mut archived.inner.#i, &mut archived_row.#i); + core::mem::swap(&mut archived.inner.#i, &mut archived_row.#i); } }) .collect::>(); @@ -273,8 +273,8 @@ impl InMemoryGenerator { let avt_type_ident = name_generator.get_available_type_ident(); quote! { if let core::result::Result::Err(e) = #write { - let mut reversed_diffs: std::collections::HashMap<&str, Difference<#avt_type_ident>> = - std::collections::HashMap::new(); + let mut reversed_diffs: worktable::prelude::HashMap<&str, Difference<#avt_type_ident>> = + worktable::prelude::HashMap::new(); for (key, diff) in diffs { reversed_diffs.insert(key, Difference { old: diff.new, new: diff.old }); } @@ -460,7 +460,7 @@ impl InMemoryGenerator { let row_old = self.0.data.select_non_ghosted(link)?; let row_new = row.clone(); let updated_bytes: Vec = vec![]; - let mut diffs: std::collections::HashMap<&str, Difference<#avt_type_ident>> = std::collections::HashMap::new(); + let mut diffs: worktable::prelude::HashMap<&str, Difference<#avt_type_ident>> = worktable::prelude::HashMap::new(); } } else { quote! { @@ -605,7 +605,7 @@ impl InMemoryGenerator { .iter() .map(|i| { quote! { - std::mem::swap(&mut archived.inner.#i, &mut archived_row.#i); + core::mem::swap(&mut archived.inner.#i, &mut archived_row.#i); } }) .collect::>(); @@ -680,7 +680,7 @@ impl InMemoryGenerator { .iter() .map(|i| { quote! { - std::mem::swap(&mut archived.inner.#i, &mut archived_row.#i); + core::mem::swap(&mut archived.inner.#i, &mut archived_row.#i); } }) .collect::>(); @@ -830,7 +830,7 @@ impl InMemoryGenerator { pks.sort_unstable(); pks.dedup(); - let mut guards: std::collections::HashMap<_, _> = std::collections::HashMap::new(); + let mut guards: worktable::prelude::HashMap<_, _> = worktable::prelude::HashMap::new(); // Full-row locks, not per-column custom locks: each row's // unsized reinsert path mutates the whole row under these // guards, and one uniform lock kind keeps every concurrent @@ -902,7 +902,7 @@ impl InMemoryGenerator { .iter() .map(|i| { quote! { - std::mem::swap(&mut archived.inner.#i, &mut archived_row.#i); + core::mem::swap(&mut archived.inner.#i, &mut archived_row.#i); } }) .collect::>(); diff --git a/codegen/src/generators/in_memory/table/impls.rs b/codegen/src/generators/in_memory/table/impls.rs index 198e390a..9d4554de 100644 --- a/codegen/src/generators/in_memory/table/impls.rs +++ b/codegen/src/generators/in_memory/table/impls.rs @@ -109,7 +109,7 @@ impl InMemoryGenerator { #row_fields_ident> where #primary_key_type: From, - R: std::ops::RangeBounds + 'a, + R: core::ops::RangeBounds + 'a, Pk: Clone + 'a, { let converted_range = ( @@ -118,7 +118,7 @@ impl InMemoryGenerator { ); // Delay the grace-period guard until the returned iterator is // consumed so an idle query builder cannot pin reclamation. - let rows = std::iter::once_with(move || { + let rows = core::iter::once_with(move || { let read_guard = self.0.data.read_guard(); self.0.primary_index.pk_map .range_links(converted_range) @@ -302,7 +302,7 @@ impl InMemoryGenerator { let exponent = core::cmp::min(backoff_spins - 8, 8); let micros = core::cmp::min(1u64 << exponent, 256); backoff_spins = backoff_spins.saturating_add(1); - tokio::time::sleep(std::time::Duration::from_micros(micros)).await; + tokio::time::sleep(core::time::Duration::from_micros(micros)).await; } } } @@ -343,7 +343,7 @@ impl InMemoryGenerator { /// assigned contiguous keys before `insert_many`. Interleaved /// `get_next_pk` calls keep working and never overlap a /// reservation. - pub fn reserve_pks(&self, count: usize) -> std::ops::Range<#pk_inner_type> { + pub fn reserve_pks(&self, count: usize) -> core::ops::Range<#pk_inner_type> { self.0.reserve_pks(count) } } @@ -375,7 +375,7 @@ impl InMemoryGenerator { quote! { pub async fn iter_with_async< F: Fn(#row_type) -> Fut, - Fut: std::future::Future> + Fut: core::future::Future> >(&self, f: F) -> core::result::Result<(), WorkTableError> { #inner } @@ -436,8 +436,8 @@ impl InMemoryGenerator { let lock_type = name_generator.get_lock_type_ident(); quote! { - pub fn vacuum(&self) -> std::sync::Arc { - std::sync::Arc::new(EmptyDataVacuum::< + pub fn vacuum(&self) -> worktable::prelude::Arc { + worktable::prelude::Arc::new(EmptyDataVacuum::< _, _, _, @@ -448,10 +448,10 @@ impl InMemoryGenerator { _ >::new( #table_name, - std::sync::Arc::clone(&self.0.data), - std::sync::Arc::clone(&self.0.lock_manager), - std::sync::Arc::clone(&self.0.primary_index), - std::sync::Arc::clone(&self.0.indexes), + worktable::prelude::Arc::clone(&self.0.data), + worktable::prelude::Arc::clone(&self.0.lock_manager), + worktable::prelude::Arc::clone(&self.0.primary_index), + worktable::prelude::Arc::clone(&self.0.indexes), )) } } diff --git a/codegen/src/generators/in_memory/table/index_fns.rs b/codegen/src/generators/in_memory/table/index_fns.rs index 35d51744..1317e50c 100644 --- a/codegen/src/generators/in_memory/table/index_fns.rs +++ b/codegen/src/generators/in_memory/table/index_fns.rs @@ -99,7 +99,7 @@ impl InMemoryGenerator { if current_link == Some(link) { return None; } - std::hint::spin_loop(); + core::hint::spin_loop(); } None }; @@ -140,7 +140,7 @@ impl InMemoryGenerator { #column_range_type, #row_fields_ident> { - let rows = std::iter::once_with(move || { + let rows = core::iter::once_with(move || { let read_guard = self.0.data.read_guard(); self.0.indexes.#field_ident .get(#by) @@ -173,7 +173,7 @@ impl InMemoryGenerator { let (range_bounds, range_arg) = if is_float(type_.to_string().as_str()) { ( - quote! { std::ops::RangeBounds<#type_> }, + quote! { core::ops::RangeBounds<#type_> }, quote! { ( predicate_range.0.as_ref().map(|v| OrderedFloat(*v)), @@ -183,7 +183,7 @@ impl InMemoryGenerator { ) } else { ( - quote! { std::ops::RangeBounds<#type_> }, + quote! { core::ops::RangeBounds<#type_> }, quote! { predicate_range.clone() }, ) }; @@ -216,7 +216,7 @@ impl InMemoryGenerator { }; let predicate_filter = quote! { .filter(move |row| { - std::ops::RangeBounds::contains(&predicate_range, &row.#row_field_ident) + core::ops::RangeBounds::contains(&predicate_range, &row.#row_field_ident) }) }; @@ -231,7 +231,7 @@ impl InMemoryGenerator { #predicate_setup // Query construction is not an active read. Pin the grace // period on the first row lookup instead. - let rows = std::iter::once_with(move || { + let rows = core::iter::once_with(move || { let read_guard = self.0.data.read_guard(); #index_range .filter_map(#select_row) diff --git a/codegen/src/generators/in_memory/table/select_executor.rs b/codegen/src/generators/in_memory/table/select_executor.rs index 0dd2560b..4538de0e 100644 --- a/codegen/src/generators/in_memory/table/select_executor.rs +++ b/codegen/src/generators/in_memory/table/select_executor.rs @@ -44,7 +44,7 @@ impl InMemoryGenerator { ); let range_ident = Ident::new(&format!("Range{variant}"), Span::call_site()); quote! { - #variant_ident(std::ops::#range_ident<#ty_ident>), + #variant_ident(core::ops::#range_ident<#ty_ident>), } }) .collect(); @@ -65,8 +65,8 @@ impl InMemoryGenerator { ); let range_ident = Ident::new(&format!("Range{variant}"), Span::call_site()); quote! { - impl From> for #column_range_type { - fn from(range: std::ops::#range_ident<#ty_ident>) -> Self { + impl From> for #column_range_type { + fn from(range: core::ops::#range_ident<#ty_ident>) -> Self { Self::#variant_ident(range) } } @@ -100,8 +100,8 @@ impl InMemoryGenerator { let col_ident = Ident::new(&column.to_string(), Span::call_site()); quote! { #row_fields_ident::#column_variant => { - let cmp = a.#col_ident.partial_cmp(&b.#col_ident).unwrap_or(std::cmp::Ordering::Equal); - if cmp != std::cmp::Ordering::Equal { + let cmp = a.#col_ident.partial_cmp(&b.#col_ident).unwrap_or(core::cmp::Ordering::Equal); + if cmp != core::cmp::Ordering::Equal { return match order { Order::Asc => cmp, Order::Desc => cmp.reverse(), @@ -165,7 +165,7 @@ impl InMemoryGenerator { _ => continue, } } - std::cmp::Ordering::Equal + core::cmp::Ordering::Equal }); iter = Box::new(items.into_iter()); }; diff --git a/codegen/src/generators/partitions.rs b/codegen/src/generators/partitions.rs index 5cf07732..5fed340e 100644 --- a/codegen/src/generators/partitions.rs +++ b/codegen/src/generators/partitions.rs @@ -38,7 +38,7 @@ pub fn expand(name: &Ident, key: &PartitionKey, persistence: Persistence) -> Tok pub fn partition_or_create( &self, #key_name: #key_ty, - ) -> Result, worktable::partition::PartitionError> { + ) -> Result, worktable::partition::PartitionError> { self.inner.get_or_create(#key_name as u64, <#table as Default>::default) } } @@ -82,7 +82,7 @@ pub fn expand(name: &Ident, key: &PartitionKey, persistence: Persistence) -> Tok /// The partition routed to by `#key_name`, if it exists. #[inline] - pub fn partition(&self, #key_name: #key_ty) -> Option> { + pub fn partition(&self, #key_name: #key_ty) -> Option> { self.inner.partition(#key_name as u64) } @@ -94,7 +94,7 @@ pub fn expand(name: &Ident, key: &PartitionKey, persistence: Persistence) -> Tok &self, #key_name: #key_ty, make: F, - ) -> Result, worktable::partition::PartitionError> + ) -> Result, worktable::partition::PartitionError> where F: FnOnce() -> #table, { @@ -146,7 +146,7 @@ pub fn expand(name: &Ident, key: &PartitionKey, persistence: Persistence) -> Tok /// grace period). Removal and creation reclaim opportunistically, /// so a router shared behind an `Arc` does not accumulate removed /// partitions; `collect` is available for removal-only phases. - pub fn remove(&self, #key_name: #key_ty) -> Option> { + pub fn remove(&self, #key_name: #key_ty) -> Option> { self.inner.remove(#key_name as u64) } @@ -156,7 +156,7 @@ pub fn expand(name: &Ident, key: &PartitionKey, persistence: Persistence) -> Tok } /// Every live partition with its key. - pub fn iter(&self) -> Vec<(#key_ty, std::sync::Arc<#table>)> { + pub fn iter(&self) -> Vec<(#key_ty, worktable::prelude::Arc<#table>)> { self.inner .iter() .into_iter() diff --git a/codegen/src/generators/persist/index/cdc.rs b/codegen/src/generators/persist/index/cdc.rs index 8aee8d6a..69bde2a4 100644 --- a/codegen/src/generators/persist/index/cdc.rs +++ b/codegen/src/generators/persist/index/cdc.rs @@ -338,7 +338,7 @@ impl PersistGenerator { fn process_difference_remove_cdc( &self, link: Link, - difference: std::collections::HashMap<&str, Difference<#avt_type_ident>> + difference: worktable::prelude::HashMap<&str, Difference<#avt_type_ident>> ) -> (#events_ident, Result<(), IndexError<#available_index_ident>>) { #(#process_difference_rows)* (#events_ident { @@ -408,7 +408,7 @@ impl PersistGenerator { fn process_difference_insert_cdc( &self, link: Link, - difference: std::collections::HashMap<&str, Difference<#avt_type_ident>> + difference: worktable::prelude::HashMap<&str, Difference<#avt_type_ident>> ) -> (#events_ident, Result<(), IndexError<#available_index_ident>>) { let mut inserted_indexes: Vec<#available_index_ident> = vec![]; let mut partial_events = #events_ident::default(); diff --git a/codegen/src/generators/persist/index/usual.rs b/codegen/src/generators/persist/index/usual.rs index e8629cc8..19663c79 100644 --- a/codegen/src/generators/persist/index/usual.rs +++ b/codegen/src/generators/persist/index/usual.rs @@ -236,7 +236,7 @@ impl PersistGenerator { fn process_difference_remove( &self, link: Link, - difference: std::collections::HashMap<&str, Difference<#avt_type_ident>> + difference: worktable::prelude::HashMap<&str, Difference<#avt_type_ident>> ) -> core::result::Result<(), IndexError<#avt_index_ident>> { #(#process_difference_remove_rows)* core::result::Result::Ok(()) @@ -293,7 +293,7 @@ impl PersistGenerator { fn process_difference_insert( &self, link: Link, - difference: std::collections::HashMap<&str, Difference<#avt_type_ident>> + difference: worktable::prelude::HashMap<&str, Difference<#avt_type_ident>> ) -> core::result::Result<(), IndexError<#avt_index_ident>> { let mut inserted_indexes: Vec<#avt_index_ident> = vec![]; #(#process_difference_insert_rows)* diff --git a/codegen/src/generators/persist/locks.rs b/codegen/src/generators/persist/locks.rs index 92a88a0c..86b55b60 100644 --- a/codegen/src/generators/persist/locks.rs +++ b/codegen/src/generators/persist/locks.rs @@ -24,7 +24,7 @@ impl PersistGenerator { .keys() .map(|i| { let name = Ident::new(format!("{i}_lock").as_str(), Span::mixed_site()); - quote! { #name: Option>, } + quote! { #name: Option>, } }) .collect(); @@ -124,8 +124,8 @@ impl PersistGenerator { .collect(); quote! { - fn with_lock(id: u16) -> (Self, std::sync::Arc) { - let lock = std::sync::Arc::new(Lock::new(id)); + fn with_lock(id: u16) -> (Self, worktable::prelude::Arc) { + let lock = worktable::prelude::Arc::new(Lock::new(id)); ( Self { #(#rows),* @@ -154,9 +154,9 @@ impl PersistGenerator { quote! { #[allow(clippy::mutable_key_type)] - fn lock(&mut self, id: u16) -> (std::collections::HashSet>, std::sync::Arc) { - let mut set = std::collections::HashSet::new(); - let lock = std::sync::Arc::new(Lock::new(id)); + fn lock(&mut self, id: u16) -> (worktable::prelude::HashSet>, worktable::prelude::Arc) { + let mut set = worktable::prelude::HashSet::new(); + let lock = worktable::prelude::Arc::new(Lock::new(id)); #(#rows)* (set, lock) @@ -186,8 +186,8 @@ impl PersistGenerator { quote! { #[allow(clippy::mutable_key_type)] - fn merge(&mut self, other: &mut Self) -> std::collections::HashSet> { - let mut set = std::collections::HashSet::new(); + fn merge(&mut self, other: &mut Self) -> worktable::prelude::HashSet> { + let mut set = worktable::prelude::HashSet::new(); #(#rows)* set } diff --git a/codegen/src/generators/persist/primary_key.rs b/codegen/src/generators/persist/primary_key.rs index 59b002b9..47f3192b 100644 --- a/codegen/src/generators/persist/primary_key.rs +++ b/codegen/src/generators/persist/primary_key.rs @@ -133,14 +133,14 @@ impl PersistGenerator { fn get_generator_from_type(type_: &TokenStream, i: &Ident) -> syn::Result { Ok(match type_.to_string().as_str() { - "u8" => quote! { std::sync::atomic::AtomicU8 }, - "u16" => quote! { std::sync::atomic::AtomicU16 }, - "u32" => quote! { std::sync::atomic::AtomicU32 }, - "u64" => quote! { std::sync::atomic::AtomicU64 }, - "i8" => quote! { std::sync::atomic::AtomicI8 }, - "i16" => quote! { std::sync::atomic::AtomicI16 }, - "i32" => quote! { std::sync::atomic::AtomicI32 }, - "i64" => quote! { std::sync::atomic::AtomicI64 }, + "u8" => quote! { core::sync::atomic::AtomicU8 }, + "u16" => quote! { core::sync::atomic::AtomicU16 }, + "u32" => quote! { core::sync::atomic::AtomicU32 }, + "u64" => quote! { core::sync::atomic::AtomicU64 }, + "i8" => quote! { core::sync::atomic::AtomicI8 }, + "i16" => quote! { core::sync::atomic::AtomicI16 }, + "i32" => quote! { core::sync::atomic::AtomicI32 }, + "i64" => quote! { core::sync::atomic::AtomicI64 }, // The accepted set is `worktable_dsl::AUTOINCREMENT_TYPES`, and the // arms above must stay equal to it. `check` uses that list to // answer "would the macro accept this", so a second copy drifting diff --git a/codegen/src/generators/persist/queries/delete.rs b/codegen/src/generators/persist/queries/delete.rs index c2efa53c..b08d496b 100644 --- a/codegen/src/generators/persist/queries/delete.rs +++ b/codegen/src/generators/persist/queries/delete.rs @@ -219,7 +219,7 @@ impl PersistGenerator { quote! { pub async fn #name(&self, by: #type_) -> core::result::Result<(), WorkTableError> { let _bulk_mutation = self.0.lock_manager.bulk_mutation_guard(); - let pks = std::cell::RefCell::new(Vec::new()); + let pks = core::cell::RefCell::new(Vec::new()); self.iter_with(|row| { if row.#field == by { pks.borrow_mut().push(row.get_primary_key()); diff --git a/codegen/src/generators/persist/queries/locks.rs b/codegen/src/generators/persist/queries/locks.rs index c6f0c3ee..3b685c39 100644 --- a/codegen/src/generators/persist/queries/locks.rs +++ b/codegen/src/generators/persist/queries/locks.rs @@ -95,9 +95,9 @@ impl PersistGenerator { quote! { #[allow(clippy::mutable_key_type)] - pub fn #ident(&mut self, id: u16) -> (std::collections::HashSet>, std::sync::Arc) { - let mut set = std::collections::HashSet::new(); - let new_lock = std::sync::Arc::new(Lock::new(id)); + pub fn #ident(&mut self, id: u16) -> (worktable::prelude::HashSet>, worktable::prelude::Arc) { + let mut set = worktable::prelude::HashSet::new(); + let new_lock = worktable::prelude::Arc::new(Lock::new(id)); #(#inner)* (set, new_lock) } diff --git a/codegen/src/generators/persist/queries/select.rs b/codegen/src/generators/persist/queries/select.rs index 7627a6fb..581c4fd6 100644 --- a/codegen/src/generators/persist/queries/select.rs +++ b/codegen/src/generators/persist/queries/select.rs @@ -32,7 +32,7 @@ impl PersistGenerator { // Acquire the grace-period guard only when iteration starts. // Merely constructing and retaining a query builder must not // stall retired-link reclamation. - let iter = std::iter::once_with(move || { + let iter = core::iter::once_with(move || { let read_guard = self.0.data.read_guard(); self.0.primary_index.pk_map .iter_values() @@ -55,7 +55,7 @@ impl PersistGenerator { return None; } current_link = replacement; - std::hint::spin_loop(); + core::hint::spin_loop(); } None }) diff --git a/codegen/src/generators/persist/queries/update.rs b/codegen/src/generators/persist/queries/update.rs index ffd41658..91b1bcfa 100644 --- a/codegen/src/generators/persist/queries/update.rs +++ b/codegen/src/generators/persist/queries/update.rs @@ -42,7 +42,7 @@ impl PersistGenerator { .keys() .map(|i| { quote! { - std::mem::swap(&mut archived.inner.#i, &mut archived_row.#i); + core::mem::swap(&mut archived.inner.#i, &mut archived_row.#i); } }) .collect::>(); @@ -311,8 +311,8 @@ impl PersistGenerator { // compensation above). let mut merged_events = secondary_keys_events; if row_holds_old_values { - let mut reversed_diffs: std::collections::HashMap<&str, Difference<#avt_type_ident>> = - std::collections::HashMap::new(); + let mut reversed_diffs: worktable::prelude::HashMap<&str, Difference<#avt_type_ident>> = + worktable::prelude::HashMap::new(); for (key, diff) in diffs { reversed_diffs.insert(key, Difference { old: diff.new, new: diff.old }); } @@ -507,7 +507,7 @@ impl PersistGenerator { quote! { let row_old = self.0.data.select_non_ghosted(link)?; let row_new = row.clone(); - let mut diffs: std::collections::HashMap<&str, Difference<#avt_type_ident>> = std::collections::HashMap::new(); + let mut diffs: worktable::prelude::HashMap<&str, Difference<#avt_type_ident>> = worktable::prelude::HashMap::new(); } } else { quote! {} @@ -615,7 +615,7 @@ impl PersistGenerator { .iter() .map(|i| { quote! { - std::mem::swap(&mut archived.inner.#i, &mut archived_row.#i); + core::mem::swap(&mut archived.inner.#i, &mut archived_row.#i); } }) .collect::>(); @@ -693,7 +693,7 @@ impl PersistGenerator { .iter() .map(|i| { quote! { - std::mem::swap(&mut archived.inner.#i, &mut archived_row.#i); + core::mem::swap(&mut archived.inner.#i, &mut archived_row.#i); } }) .collect::>(); @@ -860,7 +860,7 @@ impl PersistGenerator { pks.sort_unstable(); pks.dedup(); - let mut guards: std::collections::HashMap<_, _> = std::collections::HashMap::new(); + let mut guards: worktable::prelude::HashMap<_, _> = worktable::prelude::HashMap::new(); // Full-row locks, not per-column custom locks: each row's // unsized reinsert path mutates the whole row under these // guards, and one uniform lock kind keeps every concurrent @@ -933,7 +933,7 @@ impl PersistGenerator { .iter() .map(|i| { quote! { - std::mem::swap(&mut archived.inner.#i, &mut archived_row.#i); + core::mem::swap(&mut archived.inner.#i, &mut archived_row.#i); } }) .collect::>(); diff --git a/codegen/src/generators/persist/table/impls.rs b/codegen/src/generators/persist/table/impls.rs index 39e453b2..80a1ef93 100644 --- a/codegen/src/generators/persist/table/impls.rs +++ b/codegen/src/generators/persist/table/impls.rs @@ -254,13 +254,13 @@ impl PersistGenerator { }; let index_setup = if self.columns.primary_index_backend == crate::common::model::IndexBackend::Arctic { quote! { - inner.primary_index = std::sync::Arc::new(PrimaryIndex::from_map( + inner.primary_index = worktable::prelude::Arc::new(PrimaryIndex::from_map( PersistentArcticIndex::<#pk_type, OffsetEqLink<#const_name>>::default() )); } } else if pk_types_unsized { quote! { - inner.primary_index = std::sync::Arc::new(PrimaryIndex::from_map( + inner.primary_index = worktable::prelude::Arc::new(PrimaryIndex::from_map( #wti_map::<#pk_type, OffsetEqLink<#const_name>, UnsizedNode<_>>::with_maximum_node_size(#const_name) )); } @@ -268,19 +268,19 @@ impl PersistGenerator { match self.columns.primary_index_backend { crate::common::model::IndexBackend::WorktablesIndex => quote! { let size = get_index_page_size_from_data_length::<#pk_type>(#const_name); - inner.primary_index = std::sync::Arc::new(PrimaryIndex::from_map( + inner.primary_index = worktable::prelude::Arc::new(PrimaryIndex::from_map( #wti_map::<_, OffsetEqLink<#const_name>>::with_maximum_node_size(size) )); }, crate::common::model::IndexBackend::Indexset => quote! { let size = get_index_page_size_from_data_length::<#pk_type>(#const_name); - inner.primary_index = std::sync::Arc::new(PrimaryIndex::from_map( + inner.primary_index = worktable::prelude::Arc::new(PrimaryIndex::from_map( UpstreamIndexMap::<_, OffsetEqLink<#const_name>>::with_maximum_node_size(size) )); }, crate::common::model::IndexBackend::Arctic => unreachable!("handled before variable-size dispatch"), crate::common::model::IndexBackend::Congee => quote! { - inner.primary_index = std::sync::Arc::new(PrimaryIndex::from_map( + inner.primary_index = worktable::prelude::Arc::new(PrimaryIndex::from_map( PersistentCongeeIndex::<#pk_type, OffsetEqLink<#const_name>>::default() )); }, @@ -409,7 +409,7 @@ impl PersistGenerator { #row_fields_ident> where #primary_key_type: From, - R: std::ops::RangeBounds + 'a, + R: core::ops::RangeBounds + 'a, Pk: Clone + 'a, { let converted_range = ( @@ -418,7 +418,7 @@ impl PersistGenerator { ); // Delay the grace-period guard until the returned iterator is // consumed so an idle query builder cannot pin reclamation. - let rows = std::iter::once_with(move || { + let rows = core::iter::once_with(move || { let read_guard = self.0.data.read_guard(); self.0.primary_index.pk_map .range_links(converted_range) @@ -648,7 +648,7 @@ impl PersistGenerator { let exponent = core::cmp::min(backoff_spins - 8, 8); let micros = core::cmp::min(1u64 << exponent, 256); backoff_spins = backoff_spins.saturating_add(1); - tokio::time::sleep(std::time::Duration::from_micros(micros)).await; + tokio::time::sleep(core::time::Duration::from_micros(micros)).await; } } } @@ -689,7 +689,7 @@ impl PersistGenerator { /// assigned contiguous keys before `insert_many`. Interleaved /// `get_next_pk` calls keep working and never overlap a /// reservation. - pub fn reserve_pks(&self, count: usize) -> std::ops::Range<#pk_inner_type> { + pub fn reserve_pks(&self, count: usize) -> core::ops::Range<#pk_inner_type> { self.0.reserve_pks(count) } } @@ -732,7 +732,7 @@ impl PersistGenerator { quote! { pub async fn iter_with_async< F: Fn(#row_type) -> Fut, - Fut: std::future::Future> + Fut: core::future::Future> >(&self, f: F) -> core::result::Result<(), WorkTableError> { #inner } @@ -794,8 +794,8 @@ impl PersistGenerator { let lock_type = name_generator.get_lock_type_ident(); quote! { - pub fn vacuum(&self) -> std::sync::Arc { - std::sync::Arc::new(EmptyDataVacuum::< + pub fn vacuum(&self) -> worktable::prelude::Arc { + worktable::prelude::Arc::new(EmptyDataVacuum::< _, _, _, @@ -807,10 +807,10 @@ impl PersistGenerator { #secondary_index_events >::new( #table_name, - std::sync::Arc::clone(&self.0.data), - std::sync::Arc::clone(&self.0.lock_manager), - std::sync::Arc::clone(&self.0.primary_index), - std::sync::Arc::clone(&self.0.indexes), + worktable::prelude::Arc::clone(&self.0.data), + worktable::prelude::Arc::clone(&self.0.lock_manager), + worktable::prelude::Arc::clone(&self.0.primary_index), + worktable::prelude::Arc::clone(&self.0.indexes), ).with_persistence(self.1.vacuum_sink())) } } diff --git a/codegen/src/generators/persist/table/index_fns.rs b/codegen/src/generators/persist/table/index_fns.rs index e6712995..20f6f5e2 100644 --- a/codegen/src/generators/persist/table/index_fns.rs +++ b/codegen/src/generators/persist/table/index_fns.rs @@ -99,7 +99,7 @@ impl PersistGenerator { if current_link == Some(link) { return None; } - std::hint::spin_loop(); + core::hint::spin_loop(); } None }; @@ -140,7 +140,7 @@ impl PersistGenerator { #column_range_type, #row_fields_ident> { - let rows = std::iter::once_with(move || { + let rows = core::iter::once_with(move || { let read_guard = self.0.data.read_guard(); self.0.indexes.#field_ident .get(#by) @@ -173,7 +173,7 @@ impl PersistGenerator { let (range_bounds, range_arg) = if is_float(type_.to_string().as_str()) { ( - quote! { std::ops::RangeBounds<#type_> }, + quote! { core::ops::RangeBounds<#type_> }, quote! { ( predicate_range.0.as_ref().map(|v| OrderedFloat(*v)), @@ -183,7 +183,7 @@ impl PersistGenerator { ) } else { ( - quote! { std::ops::RangeBounds<#type_> }, + quote! { core::ops::RangeBounds<#type_> }, quote! { predicate_range.clone() }, ) }; @@ -216,7 +216,7 @@ impl PersistGenerator { }; let predicate_filter = quote! { .filter(move |row| { - std::ops::RangeBounds::contains(&predicate_range, &row.#row_field_ident) + core::ops::RangeBounds::contains(&predicate_range, &row.#row_field_ident) }) }; @@ -231,7 +231,7 @@ impl PersistGenerator { #predicate_setup // Query construction is not an active read. Pin the grace // period on the first row lookup instead. - let rows = std::iter::once_with(move || { + let rows = core::iter::once_with(move || { let read_guard = self.0.data.read_guard(); #index_range .filter_map(#select_row) diff --git a/codegen/src/generators/persist/table/select_executor.rs b/codegen/src/generators/persist/table/select_executor.rs index 1499d250..bec09452 100644 --- a/codegen/src/generators/persist/table/select_executor.rs +++ b/codegen/src/generators/persist/table/select_executor.rs @@ -44,7 +44,7 @@ impl PersistGenerator { ); let range_ident = Ident::new(&format!("Range{variant}"), Span::call_site()); quote! { - #variant_ident(std::ops::#range_ident<#ty_ident>), + #variant_ident(core::ops::#range_ident<#ty_ident>), } }) .collect(); @@ -65,8 +65,8 @@ impl PersistGenerator { ); let range_ident = Ident::new(&format!("Range{variant}"), Span::call_site()); quote! { - impl From> for #column_range_type { - fn from(range: std::ops::#range_ident<#ty_ident>) -> Self { + impl From> for #column_range_type { + fn from(range: core::ops::#range_ident<#ty_ident>) -> Self { Self::#variant_ident(range) } } @@ -100,8 +100,8 @@ impl PersistGenerator { let col_ident = Ident::new(&column.to_string(), Span::call_site()); quote! { #row_fields_ident::#column_variant => { - let cmp = a.#col_ident.partial_cmp(&b.#col_ident).unwrap_or(std::cmp::Ordering::Equal); - if cmp != std::cmp::Ordering::Equal { + let cmp = a.#col_ident.partial_cmp(&b.#col_ident).unwrap_or(core::cmp::Ordering::Equal); + if cmp != core::cmp::Ordering::Equal { return match order { Order::Asc => cmp, Order::Desc => cmp.reverse(), @@ -165,7 +165,7 @@ impl PersistGenerator { _ => continue, } } - std::cmp::Ordering::Equal + core::cmp::Ordering::Equal }); iter = Box::new(items.into_iter()); }; diff --git a/codegen/src/generators/read_only/index/usual.rs b/codegen/src/generators/read_only/index/usual.rs index 0af30608..9739b3bc 100644 --- a/codegen/src/generators/read_only/index/usual.rs +++ b/codegen/src/generators/read_only/index/usual.rs @@ -236,7 +236,7 @@ impl ReadOnlyGenerator { fn process_difference_remove( &self, link: Link, - difference: std::collections::HashMap<&str, Difference<#avt_type_ident>> + difference: worktable::prelude::HashMap<&str, Difference<#avt_type_ident>> ) -> core::result::Result<(), IndexError<#avt_index_ident>> { #(#process_difference_remove_rows)* core::result::Result::Ok(()) @@ -293,7 +293,7 @@ impl ReadOnlyGenerator { fn process_difference_insert( &self, link: Link, - difference: std::collections::HashMap<&str, Difference<#avt_type_ident>> + difference: worktable::prelude::HashMap<&str, Difference<#avt_type_ident>> ) -> core::result::Result<(), IndexError<#avt_index_ident>> { let mut inserted_indexes: Vec<#avt_index_ident> = vec![]; #(#process_difference_insert_rows)* diff --git a/codegen/src/generators/read_only/locks.rs b/codegen/src/generators/read_only/locks.rs index 280afd28..ffa50040 100644 --- a/codegen/src/generators/read_only/locks.rs +++ b/codegen/src/generators/read_only/locks.rs @@ -24,7 +24,7 @@ impl ReadOnlyGenerator { .keys() .map(|i| { let name = Ident::new(format!("{i}_lock").as_str(), Span::mixed_site()); - quote! { #name: Option>, } + quote! { #name: Option>, } }) .collect(); @@ -124,8 +124,8 @@ impl ReadOnlyGenerator { .collect(); quote! { - fn with_lock(id: u16) -> (Self, std::sync::Arc) { - let lock = std::sync::Arc::new(Lock::new(id)); + fn with_lock(id: u16) -> (Self, worktable::prelude::Arc) { + let lock = worktable::prelude::Arc::new(Lock::new(id)); ( Self { #(#rows),* @@ -154,9 +154,9 @@ impl ReadOnlyGenerator { quote! { #[allow(clippy::mutable_key_type)] - fn lock(&mut self, id: u16) -> (std::collections::HashSet>, std::sync::Arc) { - let mut set = std::collections::HashSet::new(); - let lock = std::sync::Arc::new(Lock::new(id)); + fn lock(&mut self, id: u16) -> (worktable::prelude::HashSet>, worktable::prelude::Arc) { + let mut set = worktable::prelude::HashSet::new(); + let lock = worktable::prelude::Arc::new(Lock::new(id)); #(#rows)* (set, lock) @@ -186,8 +186,8 @@ impl ReadOnlyGenerator { quote! { #[allow(clippy::mutable_key_type)] - fn merge(&mut self, other: &mut Self) -> std::collections::HashSet> { - let mut set = std::collections::HashSet::new(); + fn merge(&mut self, other: &mut Self) -> worktable::prelude::HashSet> { + let mut set = worktable::prelude::HashSet::new(); #(#rows)* set } diff --git a/codegen/src/generators/read_only/primary_key.rs b/codegen/src/generators/read_only/primary_key.rs index 192a2e44..8c8274c7 100644 --- a/codegen/src/generators/read_only/primary_key.rs +++ b/codegen/src/generators/read_only/primary_key.rs @@ -133,14 +133,14 @@ impl ReadOnlyGenerator { fn get_generator_from_type(type_: &TokenStream, i: &Ident) -> syn::Result { Ok(match type_.to_string().as_str() { - "u8" => quote! { std::sync::atomic::AtomicU8 }, - "u16" => quote! { std::sync::atomic::AtomicU16 }, - "u32" => quote! { std::sync::atomic::AtomicU32 }, - "u64" => quote! { std::sync::atomic::AtomicU64 }, - "i8" => quote! { std::sync::atomic::AtomicI8 }, - "i16" => quote! { std::sync::atomic::AtomicI16 }, - "i32" => quote! { std::sync::atomic::AtomicI32 }, - "i64" => quote! { std::sync::atomic::AtomicI64 }, + "u8" => quote! { core::sync::atomic::AtomicU8 }, + "u16" => quote! { core::sync::atomic::AtomicU16 }, + "u32" => quote! { core::sync::atomic::AtomicU32 }, + "u64" => quote! { core::sync::atomic::AtomicU64 }, + "i8" => quote! { core::sync::atomic::AtomicI8 }, + "i16" => quote! { core::sync::atomic::AtomicI16 }, + "i32" => quote! { core::sync::atomic::AtomicI32 }, + "i64" => quote! { core::sync::atomic::AtomicI64 }, // The accepted set is `worktable_dsl::AUTOINCREMENT_TYPES`, and the // arms above must stay equal to it. `check` uses that list to // answer "would the macro accept this", so a second copy drifting diff --git a/codegen/src/generators/read_only/queries/select.rs b/codegen/src/generators/read_only/queries/select.rs index 0adcbe70..8c46e611 100644 --- a/codegen/src/generators/read_only/queries/select.rs +++ b/codegen/src/generators/read_only/queries/select.rs @@ -32,7 +32,7 @@ impl ReadOnlyGenerator { // Acquire the grace-period guard only when iteration starts. // Merely constructing and retaining a query builder must not // stall retired-link reclamation. - let iter = std::iter::once_with(move || { + let iter = core::iter::once_with(move || { let read_guard = self.0.data.read_guard(); self.0.primary_index.pk_map .iter_values() @@ -55,7 +55,7 @@ impl ReadOnlyGenerator { return None; } current_link = replacement; - std::hint::spin_loop(); + core::hint::spin_loop(); } None }) diff --git a/codegen/src/generators/read_only/table/impls.rs b/codegen/src/generators/read_only/table/impls.rs index 6e4577b6..db0fd756 100644 --- a/codegen/src/generators/read_only/table/impls.rs +++ b/codegen/src/generators/read_only/table/impls.rs @@ -237,19 +237,19 @@ impl ReadOnlyGenerator { let pk_types_unsized = is_unsized_vec(pk_types); let index_setup = if self.columns.primary_index_backend == crate::common::model::IndexBackend::Arctic { quote! { - inner.primary_index = std::sync::Arc::new(PrimaryIndex::from_map( + inner.primary_index = worktable::prelude::Arc::new(PrimaryIndex::from_map( ArcticIndex::<#pk_type, OffsetEqLink<#const_name>>::default() )); } } else if self.columns.primary_index_backend == crate::common::model::IndexBackend::Congee { quote! { - inner.primary_index = std::sync::Arc::new(PrimaryIndex::from_map( + inner.primary_index = worktable::prelude::Arc::new(PrimaryIndex::from_map( CongeeIndex::<#pk_type, OffsetEqLink<#const_name>>::default() )); } } else if pk_types_unsized { quote! { - inner.primary_index = std::sync::Arc::new(PrimaryIndex::from_map( + inner.primary_index = worktable::prelude::Arc::new(PrimaryIndex::from_map( IndexMap::<#pk_type, OffsetEqLink<#const_name>, UnsizedNode<_>>::with_maximum_node_size(#const_name) )); } @@ -260,7 +260,7 @@ impl ReadOnlyGenerator { }; quote! { let size = get_index_page_size_from_data_length::<#pk_type>(#const_name); - inner.primary_index = std::sync::Arc::new(PrimaryIndex::from_map( + inner.primary_index = worktable::prelude::Arc::new(PrimaryIndex::from_map( #pk_map::<_, OffsetEqLink<#const_name>>::with_maximum_node_size(size) )); } @@ -369,7 +369,7 @@ impl ReadOnlyGenerator { #row_fields_ident> where #primary_key_type: From, - R: std::ops::RangeBounds + 'a, + R: core::ops::RangeBounds + 'a, Pk: Clone + 'a, { let converted_range = ( @@ -378,7 +378,7 @@ impl ReadOnlyGenerator { ); // Delay the grace-period guard until the returned iterator is // consumed so an idle query builder cannot pin reclamation. - let rows = std::iter::once_with(move || { + let rows = core::iter::once_with(move || { let read_guard = self.0.data.read_guard(); self.0.primary_index.pk_map .range_links(converted_range) @@ -460,7 +460,7 @@ impl ReadOnlyGenerator { quote! { pub async fn iter_with_async< F: Fn(#row_type) -> Fut, - Fut: std::future::Future> + Fut: core::future::Future> >(&self, f: F) -> core::result::Result<(), WorkTableError> { #inner } diff --git a/codegen/src/generators/read_only/table/index_fns.rs b/codegen/src/generators/read_only/table/index_fns.rs index 98a1d0f6..13ebb9c8 100644 --- a/codegen/src/generators/read_only/table/index_fns.rs +++ b/codegen/src/generators/read_only/table/index_fns.rs @@ -99,7 +99,7 @@ impl ReadOnlyGenerator { if current_link == Some(link) { return None; } - std::hint::spin_loop(); + core::hint::spin_loop(); } None }; @@ -140,7 +140,7 @@ impl ReadOnlyGenerator { #column_range_type, #row_fields_ident> { - let rows = std::iter::once_with(move || { + let rows = core::iter::once_with(move || { let read_guard = self.0.data.read_guard(); self.0.indexes.#field_ident .get(#by) @@ -173,7 +173,7 @@ impl ReadOnlyGenerator { let (range_bounds, range_arg) = if is_float(type_.to_string().as_str()) { ( - quote! { std::ops::RangeBounds<#type_> }, + quote! { core::ops::RangeBounds<#type_> }, quote! { ( predicate_range.0.as_ref().map(|v| OrderedFloat(*v)), @@ -183,7 +183,7 @@ impl ReadOnlyGenerator { ) } else { ( - quote! { std::ops::RangeBounds<#type_> }, + quote! { core::ops::RangeBounds<#type_> }, quote! { predicate_range.clone() }, ) }; @@ -216,7 +216,7 @@ impl ReadOnlyGenerator { }; let predicate_filter = quote! { .filter(move |row| { - std::ops::RangeBounds::contains(&predicate_range, &row.#row_field_ident) + core::ops::RangeBounds::contains(&predicate_range, &row.#row_field_ident) }) }; @@ -231,7 +231,7 @@ impl ReadOnlyGenerator { #predicate_setup // Query construction is not an active read. Pin the grace // period on the first row lookup instead. - let rows = std::iter::once_with(move || { + let rows = core::iter::once_with(move || { let read_guard = self.0.data.read_guard(); #index_range .filter_map(#select_row) diff --git a/codegen/src/generators/read_only/table/select_executor.rs b/codegen/src/generators/read_only/table/select_executor.rs index bd8b3f7c..7ebe9806 100644 --- a/codegen/src/generators/read_only/table/select_executor.rs +++ b/codegen/src/generators/read_only/table/select_executor.rs @@ -44,7 +44,7 @@ impl ReadOnlyGenerator { ); let range_ident = Ident::new(&format!("Range{variant}"), Span::call_site()); quote! { - #variant_ident(std::ops::#range_ident<#ty_ident>), + #variant_ident(core::ops::#range_ident<#ty_ident>), } }) .collect(); @@ -65,8 +65,8 @@ impl ReadOnlyGenerator { ); let range_ident = Ident::new(&format!("Range{variant}"), Span::call_site()); quote! { - impl From> for #column_range_type { - fn from(range: std::ops::#range_ident<#ty_ident>) -> Self { + impl From> for #column_range_type { + fn from(range: core::ops::#range_ident<#ty_ident>) -> Self { Self::#variant_ident(range) } } @@ -100,8 +100,8 @@ impl ReadOnlyGenerator { let col_ident = Ident::new(&column.to_string(), Span::call_site()); quote! { #row_fields_ident::#column_variant => { - let cmp = a.#col_ident.partial_cmp(&b.#col_ident).unwrap_or(std::cmp::Ordering::Equal); - if cmp != std::cmp::Ordering::Equal { + let cmp = a.#col_ident.partial_cmp(&b.#col_ident).unwrap_or(core::cmp::Ordering::Equal); + if cmp != core::cmp::Ordering::Equal { return match order { Order::Asc => cmp, Order::Desc => cmp.reverse(), @@ -165,7 +165,7 @@ impl ReadOnlyGenerator { _ => continue, } } - std::cmp::Ordering::Equal + core::cmp::Ordering::Equal }); iter = Box::new(items.into_iter()); }; diff --git a/codegen/src/mem_stat/mod.rs b/codegen/src/mem_stat/mod.rs index ea8d6b49..b674be14 100644 --- a/codegen/src/mem_stat/mod.rs +++ b/codegen/src/mem_stat/mod.rs @@ -3,11 +3,11 @@ use quote::quote; use syn::{Data, DeriveInput, Fields, Result, Type}; fn gen_heap_size_body(data: &Data) -> Result { - gen_mem_fn_body(data, quote! { heap_size() }, quote! { std::mem::size_of::() }) + gen_mem_fn_body(data, quote! { heap_size() }, quote! { core::mem::size_of::() }) } fn gen_used_size_body(data: &Data) -> Result { - gen_mem_fn_body(data, quote! { used_size() }, quote! { std::mem::size_of::() }) + gen_mem_fn_body(data, quote! { used_size() }, quote! { core::mem::size_of::() }) } fn gen_mem_fn_body(data: &Data, method: TokenStream, default_for_copy: TokenStream) -> Result { diff --git a/codegen/src/persist_index/generator.rs b/codegen/src/persist_index/generator.rs index 49b78938..be1ddce7 100644 --- a/codegen/src/persist_index/generator.rs +++ b/codegen/src/persist_index/generator.rs @@ -303,7 +303,7 @@ impl Generator { // is ceil(len / stride). The previous divisor used // stride + header and an unconditional +1. let page_id = file_length.div_ceil(#page_const_name as u64); - let next_page_id = std::sync::Arc::new(std::sync::atomic::AtomicU32::new(page_id as u32)); + let next_page_id = worktable::prelude::Arc::new(core::sync::atomic::AtomicU32::new(page_id as u32)); let toc = IndexTableOfContents::<_, { #page_const_name as u32 }>::parse_from_file(&mut file, 0.into(), next_page_id.clone()).await?; for page_id in toc.iter().map(|(_, page_id)| page_id) { let index = parse_page::<_, { #page_const_name as u32 }>(&mut file, (*page_id).into()).await?; diff --git a/codegen/src/persist_index/mod.rs b/codegen/src/persist_index/mod.rs index ef17c461..c284b9d4 100644 --- a/codegen/src/persist_index/mod.rs +++ b/codegen/src/persist_index/mod.rs @@ -46,7 +46,7 @@ mod tests { #[derive(Debug, Default, Clone)] pub struct TestIndex { test_idx: TreeIndex, - exchnage_idx: TreeIndex>> + exchnage_idx: TreeIndex>> } }; diff --git a/codegen/src/persist_index/parser.rs b/codegen/src/persist_index/parser.rs index f7023697..4cb43d36 100644 --- a/codegen/src/persist_index/parser.rs +++ b/codegen/src/persist_index/parser.rs @@ -46,7 +46,7 @@ mod tests { #[derive(Debug, Default, Clone)] pub struct TestIndex { test_idx: TreeIndex, - exchnage_idx: TreeIndex>> + exchnage_idx: TreeIndex>> } }; assert!(Parser::parse_struct(input).is_ok()) diff --git a/codegen/src/persist_index/space/events.rs b/codegen/src/persist_index/space/events.rs index 28b66819..720096ad 100644 --- a/codegen/src/persist_index/space/events.rs +++ b/codegen/src/persist_index/space/events.rs @@ -100,8 +100,8 @@ impl Generator { .collect(); quote! { - fn first_evs(&self) -> std::collections::HashMap<#avt_index_ident, Option> { - let mut map = std::collections::HashMap::new(); + fn first_evs(&self) -> worktable::prelude::HashMap<#avt_index_ident, Option> { + let mut map = worktable::prelude::HashMap::new(); #(#fields_first)* map } @@ -126,8 +126,8 @@ impl Generator { .collect(); quote! { - fn last_evs(&self) -> std::collections::HashMap<#avt_index_ident, Option> { - let mut map = std::collections::HashMap::new(); + fn last_evs(&self) -> worktable::prelude::HashMap<#avt_index_ident, Option> { + let mut map = worktable::prelude::HashMap::new(); #(#fields_last)* map } @@ -200,7 +200,7 @@ impl Generator { quote! { fn iter_event_ids(&self) -> impl Iterator { - > as Iterator>::flatten( + > as Iterator>::flatten( vec![ #(#fields_iter),* ] diff --git a/codegen/src/persist_table/generator/space_file/mod.rs b/codegen/src/persist_table/generator/space_file/mod.rs index 93626f25..de314722 100644 --- a/codegen/src/persist_table/generator/space_file/mod.rs +++ b/codegen/src/persist_table/generator/space_file/mod.rs @@ -241,7 +241,7 @@ impl Generator { data.set_page_id(page_id.into()); page_id += 1; - std::sync::Arc::new(data) + worktable::prelude::Arc::new(data) }) .collect(); let data = DataPages::from_data(data) @@ -251,13 +251,13 @@ impl Generator { #primary_index_init let table = WorkTable { - data: std::sync::Arc::new(data), - primary_index: std::sync::Arc::new(primary_index), - indexes: std::sync::Arc::new(indexes), + data: worktable::prelude::Arc::new(data), + primary_index: worktable::prelude::Arc::new(primary_index), + indexes: worktable::prelude::Arc::new(indexes), pk_gen: PrimaryKeyGeneratorState::from_state(self.data_info.inner.pk_gen_state), - lock_manager: std::sync::Arc::new(LockMap::<#lock_type, #pk_type>::default()), + lock_manager: worktable::prelude::Arc::new(LockMap::<#lock_type, #pk_type>::default()), table_name: #table_name, - pk_phantom: std::marker::PhantomData, + pk_phantom: core::marker::PhantomData, }; table.validate_persisted_state(path)?; @@ -310,7 +310,7 @@ impl Generator { data.set_page_id(page_id.into()); page_id += 1; - std::sync::Arc::new(data) + worktable::prelude::Arc::new(data) }) .collect(); let data = DataPages::from_data(data) @@ -320,13 +320,13 @@ impl Generator { #primary_index_init let table = WorkTable { - data: std::sync::Arc::new(data), - primary_index: std::sync::Arc::new(primary_index), - indexes: std::sync::Arc::new(indexes), + data: worktable::prelude::Arc::new(data), + primary_index: worktable::prelude::Arc::new(primary_index), + indexes: worktable::prelude::Arc::new(indexes), pk_gen: PrimaryKeyGeneratorState::from_state(self.data_info.inner.pk_gen_state), - lock_manager: std::sync::Arc::new(LockMap::<#lock_type, #pk_type>::default()), + lock_manager: worktable::prelude::Arc::new(LockMap::<#lock_type, #pk_type>::default()), table_name: #table_name, - pk_phantom: std::marker::PhantomData, + pk_phantom: core::marker::PhantomData, }; table.validate_persisted_state(path)?; @@ -381,7 +381,7 @@ impl Generator { // header on top of the full stride and lagged one page // behind roughly every 512 pages. let count = file_length.div_ceil(#page_const_name as u64); - let next_page_id = std::sync::Arc::new(std::sync::atomic::AtomicU32::new(count as u32)); + let next_page_id = worktable::prelude::Arc::new(core::sync::atomic::AtomicU32::new(count as u32)); let toc = IndexTableOfContents::<_, { #page_const_name as u32 }>::parse_from_file(&mut primary_file, 0.into(), next_page_id.clone()).await?; for page_id in toc.iter().map(|(_, page_id)| page_id) { #parse_pk_page diff --git a/codegen/src/persist_table/generator/space_file/worktable_impls.rs b/codegen/src/persist_table/generator/space_file/worktable_impls.rs index c3d19f7d..fdf7981f 100644 --- a/codegen/src/persist_table/generator/space_file/worktable_impls.rs +++ b/codegen/src/persist_table/generator/space_file/worktable_impls.rs @@ -33,13 +33,13 @@ impl Generator { /// Retires an Arc-owned table generation after the caller's /// quiesce barrier has stopped new leases and drained old ones. pub async fn unload_gracefully( - self: std::sync::Arc, - timeout: std::time::Duration, + self: worktable::prelude::Arc, + timeout: core::time::Duration, quiesce: F, ) -> Result> where F: FnOnce() -> Fut, - Fut: std::future::Future, + Fut: core::future::Future, { // Attribute the generation at the retirement request. The // quiesce callback can give background maintenance time to @@ -54,10 +54,10 @@ impl Generator { )); } - let owned = match std::sync::Arc::try_unwrap(self) { + let owned = match worktable::prelude::Arc::try_unwrap(self) { Ok(owned) => owned, Err(arc) => { - let outstanding = std::sync::Arc::strong_count(&arc).saturating_sub(1); + let outstanding = worktable::prelude::Arc::strong_count(&arc).saturating_sub(1); return Err(UnloadFailure::retained( arc, eyre::eyre!("cannot unload generation: {outstanding} Arc lease(s) remain"), diff --git a/src/features/s3_support.rs b/src/features/s3_support.rs index 6a93ced7..1b690edb 100644 --- a/src/features/s3_support.rs +++ b/src/features/s3_support.rs @@ -1,8 +1,9 @@ -use std::fmt::Debug; -use std::hash::Hash; -use std::marker::PhantomData; +use alloc::{string::String, string::ToString}; +use core::fmt::Debug; +use core::hash::Hash; +use core::marker::PhantomData; use std::path::Path; -use std::time::Duration; +use core::time::Duration; use reqwest::Client; use rusty_s3::{Bucket, Credentials, S3Action, UrlStyle}; diff --git a/src/in_memory/data.rs b/src/in_memory/data.rs index 7b15d55e..e8af1756 100644 --- a/src/in_memory/data.rs +++ b/src/in_memory/data.rs @@ -1,8 +1,9 @@ -use std::cell::UnsafeCell; -use std::fmt::Debug; -use std::marker::PhantomData; -use std::ops::{Deref, DerefMut}; -use std::sync::atomic::{AtomicU32, AtomicU64, Ordering}; +use alloc::{vec::Vec}; +use core::cell::UnsafeCell; +use core::fmt::Debug; +use core::marker::PhantomData; +use core::ops::{Deref, DerefMut}; +use core::sync::atomic::{AtomicU32, AtomicU64, Ordering}; use data_bucket::page::INNER_PAGE_SIZE; use data_bucket::page::PageId; @@ -37,7 +38,7 @@ struct CellLocks { impl Default for CellLocks { fn default() -> Self { Self { - slots: std::array::from_fn(|_| AtomicU64::new(0)), + slots: core::array::from_fn(|_| AtomicU64::new(0)), } } } @@ -59,10 +60,10 @@ impl CellLocks { #[inline] fn wait(spins: &mut u32) { if *spins < 64 { - std::hint::spin_loop(); + core::hint::spin_loop(); *spins += 1; } else { - std::thread::yield_now(); + crate::util::yield_now(); } } @@ -497,7 +498,7 @@ impl Data { // Use ptr::copy for overlapping memory regions (safe for shifting left) // When moving left (dst_offset < src_offset), this works correctly unsafe { - std::ptr::copy( + core::ptr::copy( inner_data.as_ptr().add(src_offset), inner_data.as_mut_ptr().add(dst_offset), length, @@ -567,10 +568,12 @@ impl Data { .map_err(|_| ExecutionError::LiveCellCountUnderflow) } + #[cfg(feature = "std")] pub(crate) fn has_live_cells(&self) -> bool { self.live_cells.load(Ordering::Acquire) != 0 } + #[cfg(feature = "std")] pub(crate) fn live_cell_count(&self) -> u32 { self.live_cells.load(Ordering::Acquire) } @@ -605,8 +608,9 @@ pub enum ExecutionError { #[cfg(test)] mod tests { - use std::sync::atomic::Ordering; - use std::sync::{Arc, mpsc}; + use core::sync::atomic::Ordering; + use alloc::sync::Arc; +use std::sync::mpsc; use std::thread; use rkyv::{Archive, Deserialize, Serialize}; diff --git a/src/in_memory/empty_link_registry.rs b/src/in_memory/empty_link_registry.rs index 825c7ccc..12426925 100644 --- a/src/in_memory/empty_link_registry.rs +++ b/src/in_memory/empty_link_registry.rs @@ -1,5 +1,6 @@ -use std::sync::Arc; -use std::sync::atomic::{AtomicU64, AtomicUsize, Ordering}; +use alloc::{vec::Vec}; +use alloc::sync::Arc; +use core::sync::atomic::{AtomicU64, AtomicUsize, Ordering}; use data_bucket::Link; use data_bucket::page::PageId; @@ -65,13 +66,13 @@ impl IndexOrdLink { } impl PartialOrd for IndexOrdLink { - fn partial_cmp(&self, other: &Self) -> Option { + fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } } impl Ord for IndexOrdLink { - fn cmp(&self, other: &Self) -> std::cmp::Ordering { + fn cmp(&self, other: &Self) -> core::cmp::Ordering { self.absolute_index().cmp(&other.absolute_index()) } } @@ -138,7 +139,7 @@ pub struct EmptyLinkRegistry { /// reclamation, and the most valuable. A scattered single-row delete says /// nothing about where to look, so [`Self::push`] does not record /// anything and only [`Self::push_many`] does. - targeted_pages: FairMutex>, + targeted_pages: FairMutex>, } /// A [`Link`] popped from the registry, together with the read guard that @@ -418,11 +419,11 @@ impl EmptyLinkRegistry { /// ranged delete emptied part of, and it is where a sweep should look /// first. fn note_coalesced_pages(&self, links: &[Link], runs: &[IndexOrdLink]) { - let mut links_per_page: std::collections::BTreeMap = Default::default(); + let mut links_per_page: alloc::collections::BTreeMap = Default::default(); for link in links { *links_per_page.entry(link.page_id).or_default() += 1; } - let mut runs_per_page: std::collections::BTreeMap = Default::default(); + let mut runs_per_page: alloc::collections::BTreeMap = Default::default(); for run in runs { *runs_per_page.entry(run.0.page_id).or_default() += 1; } @@ -443,8 +444,8 @@ impl EmptyLinkRegistry { /// Draining rather than reading: a sweep that has taken them is /// responsible for them, and leaving them would make every later sweep /// re-prioritise pages that are already compact. - pub fn take_targeted_pages(&self) -> std::collections::BTreeSet { - std::mem::take(&mut *self.targeted_pages.lock()) + pub fn take_targeted_pages(&self) -> alloc::collections::BTreeSet { + core::mem::take(&mut *self.targeted_pages.lock()) } /// Wakes a parked vacuum when freeing crossed the configured threshold. diff --git a/src/in_memory/pages.rs b/src/in_memory/pages.rs index f118dff5..30977454 100644 --- a/src/in_memory/pages.rs +++ b/src/in_memory/pages.rs @@ -1,3 +1,4 @@ +use alloc::{boxed::Box, vec::Vec}; use arc_swap::ArcSwap; use data_bucket::page::PageId; use derive_more::{Display, Error, From}; @@ -12,14 +13,13 @@ use rkyv::{ ser::{Serializer, allocator::ArenaHandle, sharing::Share}, util::AlignedVec, }; -use std::collections::{HashSet, VecDeque}; -use std::marker::PhantomData; -use std::sync::atomic::{AtomicPtr, AtomicU32, AtomicUsize}; -use std::{ - fmt::Debug, - sync::Arc, - sync::atomic::{AtomicU64, Ordering}, -}; +use alloc::collections::VecDeque; +use hashbrown::HashSet; +use core::marker::PhantomData; +use core::sync::atomic::{AtomicPtr, AtomicU32, AtomicUsize}; +use alloc::sync::Arc; +use core::fmt::Debug; +use core::sync::atomic::{AtomicU64, Ordering}; use crate::in_memory::empty_link_registry::EmptyLinkRegistry; use crate::prelude::ArchivedRowWrapper; @@ -75,7 +75,7 @@ struct PageDirectoryChunk { impl PageDirectoryChunk { fn new() -> Self { Self { - pages: std::array::from_fn(|_| AtomicPtr::new(std::ptr::null_mut())), + pages: core::array::from_fn(|_| AtomicPtr::new(core::ptr::null_mut())), } } } @@ -95,7 +95,7 @@ struct PageDirectory { impl PageDirectory { fn new(pages: &[Arc]) -> Self { let directory = Self { - roots: std::array::from_fn(|_| AtomicPtr::new(std::ptr::null_mut())), + roots: core::array::from_fn(|_| AtomicPtr::new(core::ptr::null_mut())), chunks: Mutex::new(Vec::new()), }; for (index, page) in pages.iter().enumerate() { @@ -115,7 +115,7 @@ impl PageDirectory { chunk = root.load(Ordering::Acquire); if chunk.is_null() { chunks.push(Box::new(PageDirectoryChunk::new())); - chunk = std::ptr::from_ref::>( + chunk = core::ptr::from_ref::>( chunks.last().expect("the chunk was just appended").as_ref(), ) .cast_mut(); @@ -358,7 +358,7 @@ where /// thread can later collect it; it executes only after every reader /// pinned right now has unpinned. fn retire(&self, item: Retired) { - self.retire_many(std::iter::once(item)); + self.retire_many(core::iter::once(item)); } /// Queue several retired items behind one grace marker. @@ -1138,16 +1138,19 @@ where Ok(()) } + #[cfg(feature = "std")] pub(crate) fn page_has_cells(&self, page_id: PageId) -> Result { let page = self.page_ref(page_id)?; Ok(page.has_live_cells()) } + #[cfg(feature = "std")] pub(crate) fn page_live_cell_count(&self, page_id: PageId) -> Result { let page = self.page_ref(page_id)?; Ok(page.live_cell_count()) } + #[cfg(feature = "std")] pub(crate) fn set_loaded_row_count(&self, count: usize) -> Result<(), ExecutionError> { let count = u64::try_from(count).map_err(|_| ExecutionError::RowCountOverflow)?; self.row_count.store(count, Ordering::Release); @@ -1156,6 +1159,7 @@ where /// Completes the vacuum's source-side accounting after every index has /// been swung to the destination link. + #[cfg(feature = "std")] pub(crate) fn remove_moved_cell(&self, link: Link) -> Result<(), ExecutionError> { self.remove_cell(link) } @@ -1188,6 +1192,7 @@ where /// concurrent low-level mutation may access either physical row while the /// move is in progress. After success, the caller must swing every index /// reference to the returned link before retiring `from_link`. + #[cfg(feature = "std")] pub(crate) unsafe fn move_row_for_vacuum( &self, from_link: Link, @@ -1258,7 +1263,7 @@ where /// Heap bytes reserved by the fixed-size data-page allocations. pub fn allocated_bytes(&self) -> usize { - self.pages.load().len() * std::mem::size_of::::WrappedRow, DATA_LENGTH>>() + self.pages.load().len() * core::mem::size_of::::WrappedRow, DATA_LENGTH>>() } /// Pages allocated but currently on the empty list, so reusable without @@ -1302,6 +1307,7 @@ where /// current page serves as the sweep's first destination. Concurrent /// inserts are safe: the insert path rechecks `current_page_id` under the /// page barrier before writing and retries if the target changed. + #[cfg(feature = "std")] pub(crate) fn rotate_current_for_vacuum(&self, page_id: PageId) { debug_assert!( self.get_page(page_id).is_some(), @@ -1348,12 +1354,12 @@ impl ExecutionError { #[cfg(test)] mod tests { - use std::collections::HashSet; - use std::sync::Arc; - use std::sync::atomic::Ordering; + use hashbrown::HashSet; + use alloc::sync::Arc; + use core::sync::atomic::Ordering; use std::sync::mpsc; use std::thread; - use std::time::Duration; + use core::time::Duration; use std::time::Instant; use parking_lot::RwLock; @@ -1627,7 +1633,7 @@ mod tests { impl Drop for RemoteReader { fn drop(&mut self) { let (disconnected, _rx) = mpsc::channel(); - let _ = std::mem::replace(&mut self.commands, disconnected); + let _ = core::mem::replace(&mut self.commands, disconnected); if let Some(thread) = self.thread.take() { thread.join().unwrap(); } diff --git a/src/in_memory/row.rs b/src/in_memory/row.rs index 5b38803b..d282da18 100644 --- a/src/in_memory/row.rs +++ b/src/in_memory/row.rs @@ -1,5 +1,5 @@ use rkyv::Archive; -use std::fmt::Debug; +use core::fmt::Debug; pub trait PublicationSafe: Send + Sync + 'static {} diff --git a/src/index/arctic.rs b/src/index/arctic.rs index 42336285..d28ef6e7 100644 --- a/src/index/arctic.rs +++ b/src/index/arctic.rs @@ -1,10 +1,11 @@ //! Arctic adapter for memory-only unique WorkTable indexes. -use std::borrow::Borrow; -use std::fmt::{self, Debug}; -use std::marker::PhantomData; -use std::ops::{Bound, RangeBounds}; -use std::sync::atomic::{AtomicUsize, Ordering}; +use alloc::{string::String, vec::Vec}; +use core::borrow::Borrow; +use core::fmt::{self, Debug}; +use core::marker::PhantomData; +use core::ops::{Bound, RangeBounds}; +use core::sync::atomic::{AtomicUsize, Ordering}; use arctic::{ConcurrentMap, Key, Order}; @@ -327,6 +328,7 @@ where self.inner.allocated_node_bytes() } + #[cfg(feature = "std")] pub(crate) fn export_topology( &mut self, mut encode: impl FnMut(&V) -> T, @@ -337,6 +339,7 @@ where self.inner.export_topology(|value| encode(&V::from_arctic(*value))) } + #[cfg(feature = "std")] pub(crate) fn from_topology( topology: arctic::topology::Topology, mut decode: impl FnMut(T) -> V, @@ -481,8 +484,9 @@ where #[cfg(test)] mod tests { - use std::ops::Bound; - use std::sync::{Arc, Barrier}; + use core::ops::Bound; + use alloc::sync::Arc; +use std::sync::Barrier; use super::{ArcticIndex, UniqueIndex}; diff --git a/src/index/arctic_multi.rs b/src/index/arctic_multi.rs index 744eba81..a1bc1f70 100644 --- a/src/index/arctic_multi.rs +++ b/src/index/arctic_multi.rs @@ -45,10 +45,11 @@ //! the dead entry and retries with a fresh slot, and the SMR guard it holds //! keeps the memory valid throughout. -use std::borrow::Borrow; -use std::fmt::{self, Debug}; -use std::ops::{Bound, ControlFlow, RangeBounds}; -use std::sync::atomic::{AtomicUsize, Ordering}; +use alloc::{boxed::Box, vec::Vec}; +use core::borrow::Borrow; +use core::fmt::{self, Debug}; +use core::ops::{Bound, ControlFlow, RangeBounds}; +use core::sync::atomic::{AtomicUsize, Ordering}; use arctic::{ConcurrentMap, Key as ArcticNativeKey, Order}; use parking_lot::RwLock; @@ -190,7 +191,7 @@ where /// Returns every `(key, value)` pair stored under `key`, in insertion /// order, as a stable snapshot. An unknown key yields an empty iterator. - pub fn get(&self, key: &K) -> std::vec::IntoIter<(K, V)> { + pub fn get(&self, key: &K) -> alloc::vec::IntoIter<(K, V)> { let raw = key.to_arctic(); let Some(slot) = self.inner.get(raw.borrow()) else { return Vec::new().into_iter(); @@ -222,7 +223,7 @@ where let mut slots = 0; while let Some((_, slot)) = entries.lend() { let links = slot.read(); - slots += std::mem::size_of::>>() + links.links.capacity() * std::mem::size_of::(); + slots += core::mem::size_of::>>() + links.links.capacity() * core::mem::size_of::(); } self.inner.allocated_node_bytes() + slots } @@ -287,8 +288,9 @@ where #[cfg(test)] mod tests { - use std::ops::Bound; - use std::sync::{Arc, Barrier}; + use core::ops::Bound; + use alloc::sync::Arc; +use std::sync::Barrier; use super::ArcticMultiIndex; diff --git a/src/index/available_index.rs b/src/index/available_index.rs index 32b18991..a9b3e4ac 100644 --- a/src/index/available_index.rs +++ b/src/index/available_index.rs @@ -1,3 +1,4 @@ +use alloc::{string::String, string::ToString}; pub trait AvailableIndex { fn to_string_value(&self) -> String; } diff --git a/src/index/congee.rs b/src/index/congee.rs index e564c754..b5cea170 100644 --- a/src/index/congee.rs +++ b/src/index/congee.rs @@ -1,9 +1,10 @@ //! Congee adapter for memory-only unique WorkTable indexes. -use std::fmt::{self, Debug}; -use std::ops::{Bound, RangeBounds}; -use std::sync::Arc; -use std::sync::atomic::{AtomicUsize, Ordering}; +use alloc::{vec::Vec}; +use core::fmt::{self, Debug}; +use core::ops::{Bound, RangeBounds}; +use alloc::sync::Arc; +use core::sync::atomic::{AtomicUsize, Ordering}; use congee::{CongeeRaw, DefaultAllocator}; use parking_lot::Mutex; @@ -53,7 +54,7 @@ pub struct CongeeIndex { // serialize mutations until the backend offers the required visibility. mutation: Mutex<()>, len: AtomicUsize, - marker: std::marker::PhantomData<(K, V)>, + marker: core::marker::PhantomData<(K, V)>, } impl Debug for CongeeIndex { @@ -79,7 +80,7 @@ where inner: CongeeRaw::new_with_drainer(DefaultAllocator {}, drainer), mutation: Mutex::new(()), len: AtomicUsize::new(0), - marker: std::marker::PhantomData, + marker: core::marker::PhantomData, } } } @@ -113,7 +114,7 @@ where // SAFETY: callers guarantee that `pointer` was produced by // `Arc::into_raw(...).expose_provenance()` for the same `V` and still // owns one strong reference. - unsafe { Arc::from_raw(std::ptr::with_exposed_provenance(pointer)) } + unsafe { Arc::from_raw(core::ptr::with_exposed_provenance(pointer)) } } #[inline] @@ -180,12 +181,13 @@ where .map(|(key, pointer)| { // SAFETY: the pinned epoch keeps every returned tree-owned // pointer alive until its value has been cloned. - let value = unsafe { &*std::ptr::with_exposed_provenance::(pointer) }; + let value = unsafe { &*core::ptr::with_exposed_provenance::(pointer) }; (K::from_congee(key), value.clone()) }) .collect() } + #[cfg(feature = "std")] pub(crate) fn export_topology( &mut self, mut encode: impl FnMut(&V) -> T, @@ -193,10 +195,11 @@ where self.inner.export_topology(|pointer| { // SAFETY: every raw payload is a live tree-owned `Arc` pointer, // and the exclusive borrow prevents removal while it is cloned. - unsafe { encode(&*std::ptr::with_exposed_provenance::(pointer)) } + unsafe { encode(&*core::ptr::with_exposed_provenance::(pointer)) } }) } + #[cfg(feature = "std")] pub(crate) fn from_topology( topology: congee::topology::Topology, mut decode: impl FnMut(T) -> V, @@ -217,7 +220,7 @@ where inner, mutation: Mutex::new(()), len: AtomicUsize::new(len), - marker: std::marker::PhantomData, + marker: core::marker::PhantomData, }) } } @@ -238,7 +241,7 @@ where let pointer = self.inner.get(&key.into_congee(), &guard)?; // SAFETY: the epoch guard keeps the tree-owned `Arc` alive for the // duration of `read`, and the pointer originated from `Arc::into_raw`. - let value = unsafe { &*std::ptr::with_exposed_provenance::(pointer) }; + let value = unsafe { &*core::ptr::with_exposed_provenance::(pointer) }; Some(read(value)) } @@ -334,8 +337,9 @@ where #[cfg(test)] mod tests { - use std::ops::Bound; - use std::sync::{Arc, Barrier}; + use core::ops::Bound; + use alloc::sync::Arc; +use std::sync::Barrier; use super::{CongeeIndex, UniqueIndex}; diff --git a/src/index/persistent_art.rs b/src/index/persistent_art.rs index eda5a690..fe14b819 100644 --- a/src/index/persistent_art.rs +++ b/src/index/persistent_art.rs @@ -6,12 +6,13 @@ //! different stripes remain concurrent because their Set/Remove records //! commute during recovery. -use std::array; -use std::collections::hash_map::DefaultHasher; -use std::fmt::{self, Debug}; -use std::hash::{Hash, Hasher}; -use std::ops::RangeBounds; -use std::sync::atomic::{AtomicU64, Ordering}; +use alloc::{vec::Vec}; +use core::array; +use rustc_hash::FxHasher as DefaultHasher; +use core::fmt::{self, Debug}; +use core::hash::{Hash, Hasher}; +use core::ops::RangeBounds; +use core::sync::atomic::{AtomicU64, Ordering}; use data_bucket::Link; use indexset::cdc::change::{ChangeEvent, Id}; @@ -49,7 +50,7 @@ where K: ArcticKey, V: Clone + Debug + PartialEq + Send + Sync + 'static, { - pub fn get(&self, key: &K) -> std::vec::IntoIter<(K, V)> { + pub fn get(&self, key: &K) -> alloc::vec::IntoIter<(K, V)> { self.inner.get(key) } @@ -128,7 +129,7 @@ impl PersistentArtIndex { } fn mutation_stripe(&self, key: &K) -> &Mutex<()> { - let mut hasher = DefaultHasher::new(); + let mut hasher = DefaultHasher::default(); key.hash(&mut hasher); &self.mutation_stripes[hasher.finish() as usize % MUTATION_STRIPES] } @@ -318,7 +319,8 @@ where #[cfg(test)] mod tests { - use std::sync::{Arc, Barrier}; + use alloc::sync::Arc; +use std::sync::Barrier; use super::*; diff --git a/src/index/persistent_wti.rs b/src/index/persistent_wti.rs index 8c05edde..2ea194c0 100644 --- a/src/index/persistent_wti.rs +++ b/src/index/persistent_wti.rs @@ -9,11 +9,12 @@ //! not claims about the live WTI node position or maximum; the shadow validates //! that marker and derives the real structural metadata itself. -use std::array; -use std::fmt::{self, Debug}; -use std::hash::{Hash, Hasher}; -use std::ops::RangeBounds; -use std::sync::atomic::{AtomicU64, Ordering}; +use alloc::{vec::Vec}; +use core::array; +use core::fmt::{self, Debug}; +use core::hash::{Hash, Hasher}; +use core::ops::RangeBounds; +use core::sync::atomic::{AtomicU64, Ordering}; use data_bucket::Link; use indexset::cdc::change::{ChangeEvent, Id}; @@ -285,7 +286,7 @@ where #[cfg(test)] mod tests { - use std::collections::HashSet; + use hashbrown::HashSet; use data_bucket::page::PageId; diff --git a/src/index/primary_index.rs b/src/index/primary_index.rs index d8883498..da6db678 100644 --- a/src/index/primary_index.rs +++ b/src/index/primary_index.rs @@ -1,8 +1,9 @@ //! Primary-key to row-location index. -use std::fmt::Debug; -use std::hash::Hash; -use std::marker::PhantomData; +use alloc::{vec::Vec}; +use core::fmt::Debug; +use core::hash::Hash; +use core::marker::PhantomData; use data_bucket::Link; use indexset::cdc::change::ChangeEvent; diff --git a/src/index/table_index/cdc.rs b/src/index/table_index/cdc.rs index 0cb4a588..215ee422 100644 --- a/src/index/table_index/cdc.rs +++ b/src/index/table_index/cdc.rs @@ -1,5 +1,6 @@ -use std::fmt::Debug; -use std::hash::Hash; +use alloc::{vec::Vec}; +use core::fmt::Debug; +use core::hash::Hash; use data_bucket::Link; use indexset::cdc::change::ChangeEvent; diff --git a/src/index/table_index/mod.rs b/src/index/table_index/mod.rs index a405b5d3..3690227f 100644 --- a/src/index/table_index/mod.rs +++ b/src/index/table_index/mod.rs @@ -1,5 +1,5 @@ -use std::fmt::Debug; -use std::hash::Hash; +use core::fmt::Debug; +use core::hash::Hash; use data_bucket::Link; use indexset::core::multipair::MultiPair; diff --git a/src/index/table_index/util.rs b/src/index/table_index/util.rs index 4ffc57cb..b99a9a5a 100644 --- a/src/index/table_index/util.rs +++ b/src/index/table_index/util.rs @@ -1,3 +1,4 @@ +use alloc::{vec::Vec}; use indexset::cdc::change::ChangeEvent; use indexset::core::multipair::MultiPair; use indexset::core::pair::Pair; diff --git a/src/index/table_secondary_index/cdc.rs b/src/index/table_secondary_index/cdc.rs index 804014d8..1aaa41f6 100644 --- a/src/index/table_secondary_index/cdc.rs +++ b/src/index/table_secondary_index/cdc.rs @@ -1,4 +1,5 @@ -use std::collections::HashMap; +use alloc::{vec::Vec}; +use hashbrown::HashMap; use data_bucket::Link; diff --git a/src/index/table_secondary_index/index_events.rs b/src/index/table_secondary_index/index_events.rs index 9183da9b..6696d5aa 100644 --- a/src/index/table_secondary_index/index_events.rs +++ b/src/index/table_secondary_index/index_events.rs @@ -1,6 +1,6 @@ use crate::prelude::IndexChangeEventId; use indexset::cdc::change; -use std::collections::HashMap; +use hashbrown::HashMap; pub trait TableSecondaryIndexEventsOps { fn extend(&mut self, another: Self) diff --git a/src/index/table_secondary_index/info.rs b/src/index/table_secondary_index/info.rs index 569a4953..f9f533fe 100644 --- a/src/index/table_secondary_index/info.rs +++ b/src/index/table_secondary_index/info.rs @@ -1,3 +1,4 @@ +use alloc::{vec::Vec}; use crate::prelude::IndexInfo; pub trait TableSecondaryIndexInfo { diff --git a/src/index/table_secondary_index/mod.rs b/src/index/table_secondary_index/mod.rs index 69434a82..a27db6d3 100644 --- a/src/index/table_secondary_index/mod.rs +++ b/src/index/table_secondary_index/mod.rs @@ -1,9 +1,10 @@ +use alloc::{vec::Vec}; mod cdc; mod index_events; mod info; use data_bucket::Link; -use std::collections::HashMap; +use hashbrown::HashMap; use crate::WorkTableError; use crate::{AvailableIndex, Difference}; diff --git a/src/index/unique.rs b/src/index/unique.rs index 55e559f3..7f963470 100644 --- a/src/index/unique.rs +++ b/src/index/unique.rs @@ -4,9 +4,10 @@ //! backend's guard type. That keeps generated code independent from the //! concurrency and reclamation strategy used by each index implementation. -use std::fmt::Debug; -use std::hash::Hash; -use std::ops::RangeBounds; +use alloc::{vec::Vec}; +use core::fmt::Debug; +use core::hash::Hash; +use core::ops::RangeBounds; use crate::IndexMap; use indexset::core::node::NodeLike; @@ -206,7 +207,7 @@ pub type UpstreamIndexPair = VanillaPair; #[cfg(test)] mod tests { - use std::sync::Arc; + use alloc::sync::Arc; use super::{UniqueIndex, UpstreamIndexMap}; use crate::{ArcticIndex, CongeeIndex, IndexMap}; @@ -260,7 +261,7 @@ mod tests { let iterated = index.iter_values().find(|(candidate, _)| *candidate == key); panic!( "backend={}, key={key}, point={value:?}, iterated={iterated:?}", - std::any::type_name::(), + core::any::type_name::(), ); } } @@ -292,7 +293,7 @@ mod tests { threads.push(std::thread::spawn(move || { for sequence in 0..1_000_u64 { let key = worker * 1_000 + sequence; - let backend = std::any::type_name::(); + let backend = core::any::type_name::(); assert_eq!( index.insert_value_checked(key, key + 1), Some(()), diff --git a/src/index/unsized_node.rs b/src/index/unsized_node.rs index eefd0c8c..38c4a42a 100644 --- a/src/index/unsized_node.rs +++ b/src/index/unsized_node.rs @@ -1,11 +1,12 @@ +use alloc::vec::Vec; use data_bucket::{SizeMeasurable, UnsizedIndexPageUtility, VariableSizeMeasurable}; use indexset::core::node::NodeLike; -use std::borrow::Borrow; -use std::collections::Bound; -use std::fmt::Debug; -use std::ops::Deref; -use std::slice::Iter; +use core::borrow::Borrow; +use core::ops::Bound; +use core::fmt::Debug; +use core::ops::Deref; +use core::slice::Iter; pub const UNSIZED_HEADER_LENGTH: u32 = 64; @@ -238,7 +239,7 @@ where fn replace(&mut self, idx: usize, value: T) -> Option { let value_size = value.aligned_size(); if let Some(old) = self.inner.get_mut(idx) { - let old = std::mem::replace(old, value); + let old = core::mem::replace(old, value); self.length += value_size; self.removed_length += old.aligned_size(); if idx + 1 == self.inner.len() { diff --git a/src/lib.rs b/src/lib.rs index 173b172f..2560e278 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,9 +1,18 @@ +#![cfg_attr(not(feature = "std"), no_std)] #![doc = include_str!("../docs/crate.md")] +#[macro_use] +extern crate alloc; + +/// Generated code names `worktable::` paths, which must also resolve inside +/// this crate, where `worktable!` is invoked for the persistence queue. +extern crate self as worktable; + pub mod in_memory; mod index; pub mod lock; mod mem_stat; +#[cfg(feature = "std")] pub mod migration; pub mod partition; pub mod persistence; @@ -16,6 +25,7 @@ mod util; pub mod features; pub use index::*; +#[cfg(feature = "std")] pub use persistence::{ LoadMode, PersistedWorkTable, PersistenceConfig, PersistenceLoadError, UnloadFailure, UnloadReport, }; @@ -34,22 +44,29 @@ pub use worktable_dsl; pub use worktable_codegen::s3_sync_persistence; pub mod prelude { + pub use alloc::collections::BTreeMap; + pub use alloc::sync::Arc; + pub use alloc::vec::IntoIter; + pub use hashbrown::{HashMap, HashSet}; + pub use crate::in_memory::{ArchivedRowWrapper, Data, DataPages, Query, RowWrapper, StorableRow}; pub use crate::lock::FullRowLock; pub use crate::lock::{Lock, RowLock}; pub use crate::lock::{LockAcquirer, LockGuard, LockMap, PendingLock}; pub use crate::mem_stat::MemStat; pub use crate::partition::{MAX_PARTITIONS, PartRef, PartitionError, PartitionSet}; + pub use crate::persistence::{AcknowledgeOperation, DeleteOperation, InsertOperation, Operation, OperationId}; + pub use crate::persistence::{OperationType, UpdateOperation, validate_events}; + #[cfg(feature = "std")] pub use crate::persistence::{ - AcknowledgeOperation, ArtPersistenceKey, DeleteOperation, DiskConfig, DiskPersistenceEngine, - IndexTableOfContents, InsertOperation, LoadMode, Operation, OperationId, PersistedWorkTable, PersistenceConfig, - PersistenceEngine, PersistenceError, PersistenceIndexCorruption, PersistenceLoadError, PersistenceMonitor, - PersistenceResult, PersistenceState, PersistenceTask, ReadOnlyPersistenceEngine, SpaceArcticIndex, - SpaceArcticMultiIndex, SpaceArcticStringIndex, SpaceCongeeIndex, SpaceData, SpaceDataOps, SpaceIndex, - SpaceIndexOps, SpaceIndexUnsized, SpaceLogicalIndex, SpaceLogicalIndexUnsized, SpaceLogicalMultiIndex, - SpaceLogicalMultiIndexUnsized, SpaceSecondaryIndexOps, TocEntryOversizedError, UnloadFailure, UnloadReport, - UpdateOperation, load_persisted_state, map_index_pages_to_toc_and_general, - map_unsized_index_pages_to_toc_and_general, reconstruct_multi_index_nodes, validate_events, + ArtPersistenceKey, DiskConfig, DiskPersistenceEngine, IndexTableOfContents, LoadMode, PersistedWorkTable, + PersistenceConfig, PersistenceEngine, PersistenceError, PersistenceIndexCorruption, PersistenceLoadError, + PersistenceMonitor, PersistenceResult, PersistenceState, PersistenceTask, ReadOnlyPersistenceEngine, + SpaceArcticIndex, SpaceArcticMultiIndex, SpaceArcticStringIndex, SpaceCongeeIndex, SpaceData, SpaceDataOps, + SpaceIndex, SpaceIndexOps, SpaceIndexUnsized, SpaceLogicalIndex, SpaceLogicalIndexUnsized, + SpaceLogicalMultiIndex, SpaceLogicalMultiIndexUnsized, SpaceSecondaryIndexOps, TocEntryOversizedError, + UnloadFailure, UnloadReport, load_persisted_state, map_index_pages_to_toc_and_general, + map_unsized_index_pages_to_toc_and_general, reconstruct_multi_index_nodes, }; pub use crate::primary_key::{ PrimaryKeyGenerator, PrimaryKeyGeneratorRange, PrimaryKeyGeneratorState, TablePrimaryKey, @@ -63,9 +80,10 @@ pub mod prelude { PersistentArcticIndex, PersistentArcticMultiIndex, PersistentArtIndex, PersistentCongeeIndex, PersistentWtiIndex, PrimaryIndex, TableIndex, TableIndexCdc, TableRow, TableSecondaryIndex, TableSecondaryIndexCdc, TableSecondaryIndexEventsOps, TableSecondaryIndexInfo, UniqueIndex, UnsizedNode, - UpstreamIndexMap, UpstreamIndexPair, WorkTable, WorkTableError, vacuum::EmptyDataVacuum, - vacuum::VacuumPersistence, vacuum::WorkTableVacuum, validate_arctic_link, + UpstreamIndexMap, UpstreamIndexPair, WorkTable, WorkTableError, validate_arctic_link, }; + #[cfg(feature = "std")] + pub use crate::{vacuum::EmptyDataVacuum, vacuum::VacuumPersistence, vacuum::WorkTableVacuum}; pub use data_bucket::{ DATA_VERSION, DataPage, GENERAL_HEADER_SIZE, GeneralHeader, GeneralPage, INNER_PAGE_SIZE, IndexPage, Interval, Link, PAGE_SIZE, PageType, Persistable, PersistableIndex, SizeMeasurable, SizeMeasure, SpaceInfoPage, diff --git a/src/lock/map.rs b/src/lock/map.rs index ea79742e..5e94760b 100644 --- a/src/lock/map.rs +++ b/src/lock/map.rs @@ -1,10 +1,11 @@ -use std::collections::HashMap; -use std::collections::hash_map::DefaultHasher; -use std::fmt::Debug; -use std::hash::{Hash, Hasher}; -use std::ops::Deref; -use std::sync::Arc; -use std::sync::atomic::{AtomicU16, AtomicU64, AtomicUsize, Ordering}; +use alloc::{vec::Vec}; +use hashbrown::HashMap; +use rustc_hash::FxHasher as DefaultHasher; +use core::fmt::Debug; +use core::hash::{Hash, Hasher}; +use core::ops::Deref; +use alloc::sync::Arc; +use core::sync::atomic::{AtomicU16, AtomicU64, AtomicUsize, Ordering}; use parking_lot::RwLock; @@ -138,7 +139,7 @@ impl Default for LockMap { Self { map: RwLock::new(HashMap::new()), next_id: AtomicU16::default(), - mutation_stripes: Arc::new(std::array::from_fn(|_| MutationStripe::default())), + mutation_stripes: Arc::new(core::array::from_fn(|_| MutationStripe::default())), bulk_mutations: Arc::default(), } } @@ -283,7 +284,7 @@ where } fn stripe_of(key: &PrimaryKey) -> usize { - let mut hasher = DefaultHasher::new(); + let mut hasher = DefaultHasher::default(); key.hash(&mut hasher); (hasher.finish() as usize) % MUTATION_STRIPE_COUNT } @@ -343,9 +344,9 @@ where while gate.serving.load(Ordering::Acquire) != ticket { if spins < 16 { spins += 1; - std::hint::spin_loop(); + core::hint::spin_loop(); } else { - std::thread::yield_now(); + crate::util::yield_now(); } } diff --git a/src/lock/mod.rs b/src/lock/mod.rs index db352d32..a5768722 100644 --- a/src/lock/mod.rs +++ b/src/lock/mod.rs @@ -1,15 +1,16 @@ +use alloc::{vec::Vec}; mod map; mod row_lock; -use std::cell::Cell; -use std::fmt::Debug; -use std::future::Future; -use std::hash::{Hash, Hasher}; -use std::marker::PhantomData; -use std::pin::Pin; -use std::sync::Arc; -use std::sync::atomic::{AtomicBool, Ordering}; -use std::task::{Context, Poll}; +use core::cell::Cell; +use core::fmt::Debug; +use core::future::Future; +use core::hash::{Hash, Hasher}; +use core::marker::PhantomData; +use core::pin::Pin; +use alloc::sync::Arc; +use core::sync::atomic::{AtomicBool, Ordering}; +use core::task::{Context, Poll}; use futures::task::AtomicWaker; use parking_lot::Mutex; @@ -261,7 +262,7 @@ impl Future for LockWait { // Spin phase: try up to MAX_SPINS before going async for _ in 0..MAX_SPINS { - std::hint::spin_loop(); + core::hint::spin_loop(); if !self.locked.load(Ordering::Acquire) { return Poll::Ready(()); } diff --git a/src/lock/row_lock.rs b/src/lock/row_lock.rs index 9e8aff49..2f707637 100644 --- a/src/lock/row_lock.rs +++ b/src/lock/row_lock.rs @@ -1,7 +1,7 @@ -use std::collections::HashSet; -use std::fmt::Debug; -use std::hash::Hash; -use std::sync::Arc; +use hashbrown::HashSet; +use core::fmt::Debug; +use core::hash::Hash; +use alloc::sync::Arc; use crate::lock::{Lock, LockGuard, LockMap, LockWait}; diff --git a/src/mem_stat/mod.rs b/src/mem_stat/mod.rs index 8b45b3db..20abb84f 100644 --- a/src/mem_stat/mod.rs +++ b/src/mem_stat/mod.rs @@ -1,9 +1,10 @@ +use alloc::{boxed::Box, string::String, vec::Vec}; mod primitives; -use std::collections::HashMap; -use std::fmt::Debug; -use std::rc::Rc; -use std::sync::Arc; +use hashbrown::HashMap; +use core::fmt::Debug; +use alloc::rc::Rc; +use alloc::sync::Arc; use data_bucket::Link; use data_bucket::page::PageId; @@ -55,7 +56,7 @@ impl< PkMap, > where - PrimaryKey: Clone + Ord + Send + 'static + std::hash::Hash, + PrimaryKey: Clone + Ord + Send + 'static + core::hash::Hash, Row: StorableRow + Send + Clone + 'static, ::WrappedRow: RowWrapper, PkMap: UniqueIndex> + MemStat, @@ -81,10 +82,10 @@ impl MemStat for Option { impl MemStat for Vec { fn heap_size(&self) -> usize { - self.capacity() * std::mem::size_of::() + self.iter().map(|v| v.heap_size()).sum::() + self.capacity() * core::mem::size_of::() + self.iter().map(|v| v.heap_size()).sum::() } fn used_size(&self) -> usize { - self.len() * std::mem::size_of::() + self.iter().map(|v| v.used_size()).sum::() + self.len() * core::mem::size_of::() + self.iter().map(|v| v.used_size()).sum::() } } @@ -104,7 +105,7 @@ where Node: NodeLike> + Send + 'static, { fn heap_size(&self) -> usize { - let slot_size = std::mem::size_of::>(); + let slot_size = core::mem::size_of::>(); let base_heap = self.capacity() * slot_size; let kv_heap: usize = self.iter().map(|(k, v)| k.heap_size() + v.heap_size()).sum(); @@ -113,7 +114,7 @@ where } fn used_size(&self) -> usize { - let pair_size = std::mem::size_of::>(); + let pair_size = core::mem::size_of::>(); let base = self.len() * pair_size; let used: usize = self.iter().map(|(k, v)| k.used_size() + v.used_size()).sum(); @@ -129,14 +130,14 @@ where Node: VanillaNodeLike> + Send + 'static, { fn heap_size(&self) -> usize { - let slot_size = std::mem::size_of::>(); + let slot_size = core::mem::size_of::>(); let base_heap = self.capacity() * slot_size; let kv_heap: usize = self.iter().map(|(k, v)| k.heap_size() + v.heap_size()).sum(); base_heap + kv_heap } fn used_size(&self) -> usize { - let pair_size = std::mem::size_of::>(); + let pair_size = core::mem::size_of::>(); let base = self.len() * pair_size; let used: usize = self.iter().map(|(k, v)| k.used_size() + v.used_size()).sum(); base + used @@ -151,7 +152,7 @@ where fn heap_size(&self) -> usize { let values = self.iter_values().map(|(_, value)| value.heap_size()).sum::(); self.allocated_node_bytes() - + self.len() * (std::mem::size_of::() + 2 * std::mem::size_of::()) + + self.len() * (core::mem::size_of::() + 2 * core::mem::size_of::()) + values } @@ -170,7 +171,7 @@ where } fn used_size(&self) -> usize { - self.len() * std::mem::size_of::<(K, V)>() + self.len() * core::mem::size_of::<(K, V)>() } } @@ -184,7 +185,7 @@ where } fn used_size(&self) -> usize { - self.len() * std::mem::size_of::<(K, V)>() + self.len() * core::mem::size_of::<(K, V)>() } } @@ -220,7 +221,7 @@ where Node: NodeLike> + Send + 'static, { fn heap_size(&self) -> usize { - let slot_size = std::mem::size_of::>(); + let slot_size = core::mem::size_of::>(); let base_heap = self.capacity() * slot_size; let kv_heap: usize = self.iter().map(|(k, v)| k.heap_size() + v.heap_size()).sum(); @@ -229,7 +230,7 @@ where } fn used_size(&self) -> usize { - let pair_size = std::mem::size_of::>(); + let pair_size = core::mem::size_of::>(); let base = self.len() * pair_size; let used: usize = self.iter().map(|(k, v)| k.used_size() + v.used_size()).sum(); @@ -240,32 +241,32 @@ where impl MemStat for Box { fn heap_size(&self) -> usize { - std::mem::size_of::() + (**self).heap_size() + core::mem::size_of::() + (**self).heap_size() } fn used_size(&self) -> usize { - std::mem::size_of::() + (**self).used_size() + core::mem::size_of::() + (**self).used_size() } } impl MemStat for Arc { fn heap_size(&self) -> usize { - std::mem::size_of::() + (**self).heap_size() + core::mem::size_of::() + (**self).heap_size() } fn used_size(&self) -> usize { - std::mem::size_of::() + (**self).used_size() + core::mem::size_of::() + (**self).used_size() } } impl MemStat for Rc { fn heap_size(&self) -> usize { - std::mem::size_of::() + (**self).heap_size() + core::mem::size_of::() + (**self).heap_size() } fn used_size(&self) -> usize { - std::mem::size_of::() + (**self).used_size() + core::mem::size_of::() + (**self).used_size() } } -impl MemStat for HashMap { +impl MemStat for HashMap { fn heap_size(&self) -> usize { let bucket_size = size_of::<(K, V)>(); let base_heap = self.capacity() * bucket_size; diff --git a/src/mem_stat/primitives.rs b/src/mem_stat/primitives.rs index ee159f96..348b2484 100644 --- a/src/mem_stat/primitives.rs +++ b/src/mem_stat/primitives.rs @@ -29,23 +29,24 @@ impl_memstat_zero!( char, u128, i128, - std::num::NonZeroU8, - std::num::NonZeroU16, - std::num::NonZeroU32, - std::num::NonZeroU64, - std::num::NonZeroU128, - std::num::NonZeroUsize, - std::num::NonZeroI8, - std::num::NonZeroI16, - std::num::NonZeroI32, - std::num::NonZeroI64, - std::num::NonZeroI128, - std::num::NonZeroIsize, - std::time::Duration, - std::time::SystemTime, - std::time::Instant + core::num::NonZeroU8, + core::num::NonZeroU16, + core::num::NonZeroU32, + core::num::NonZeroU64, + core::num::NonZeroU128, + core::num::NonZeroUsize, + core::num::NonZeroI8, + core::num::NonZeroI16, + core::num::NonZeroI32, + core::num::NonZeroI64, + core::num::NonZeroI128, + core::num::NonZeroIsize, + core::time::Duration ); +#[cfg(feature = "std")] +impl_memstat_zero!(std::time::SystemTime, std::time::Instant); + impl_memstat_zero!( [u8], [i8], diff --git a/src/partition/mod.rs b/src/partition/mod.rs index fdc2779b..e96fd4c9 100644 --- a/src/partition/mod.rs +++ b/src/partition/mod.rs @@ -55,6 +55,7 @@ //! instance measures 110 KB and 6.1 ms to construct, of which 95 percent is //! inside `PersistenceEngine::new`. +use alloc::{boxed::Box, vec::Vec}; // Under `--cfg wt_loom` the atomics and the mutex come from loom, which explores // every interleaving of them rather than whichever one this machine happened // to produce. `Arc` stays `std`: loom's has no `into_raw` or @@ -67,10 +68,10 @@ use loom::sync::atomic::{AtomicPtr, AtomicUsize, Ordering}; use loom::sync::{Mutex, MutexGuard}; #[cfg(not(wt_loom))] use parking_lot::{Mutex, MutexGuard}; -use std::collections::VecDeque; -use std::sync::Arc; +use alloc::collections::VecDeque; +use alloc::sync::Arc; #[cfg(not(wt_loom))] -use std::sync::atomic::{AtomicPtr, AtomicUsize, Ordering}; +use core::sync::atomic::{AtomicPtr, AtomicUsize, Ordering}; use crate::mem_stat::MemStat; #[cfg(not(wt_loom))] @@ -109,7 +110,7 @@ struct Chunk { impl Chunk { fn empty() -> Box { Box::new(Chunk { - slots: std::array::from_fn(|_| AtomicPtr::new(std::ptr::null_mut())), + slots: core::array::from_fn(|_| AtomicPtr::new(core::ptr::null_mut())), }) } } @@ -144,7 +145,7 @@ pub struct PartRef<'a, T> { value: &'a T, } -impl std::ops::Deref for PartRef<'_, T> { +impl core::ops::Deref for PartRef<'_, T> { type Target = T; fn deref(&self) -> &T { @@ -180,7 +181,7 @@ impl Default for PartitionSet { impl PartitionSet { pub fn new() -> Self { Self { - spine: (0..MAX_CHUNKS).map(|_| AtomicPtr::new(std::ptr::null_mut())).collect(), + spine: (0..MAX_CHUNKS).map(|_| AtomicPtr::new(core::ptr::null_mut())).collect(), live: AtomicUsize::new(0), grow: Mutex::new(VecDeque::new()), #[cfg(not(wt_loom))] @@ -488,7 +489,7 @@ impl PartitionSet { let table = { let mut retired = self.lock(); let chunk = self.chunk(idx)?; - let p = chunk.slots[idx % CHUNK].swap(std::ptr::null_mut(), Ordering::AcqRel); + let p = chunk.slots[idx % CHUNK].swap(core::ptr::null_mut(), Ordering::AcqRel); if p.is_null() { return None; } @@ -594,13 +595,13 @@ impl PartitionSet { } } -impl std::fmt::Debug for PartitionSet { +impl core::fmt::Debug for PartitionSet { /// Deliberately shallow: a partition set can hold thousands of tables and /// printing them would be useless as well as slow. - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.debug_struct("PartitionSet") .field("live", &self.len()) - .field("table", &std::any::type_name::()) + .field("table", &core::any::type_name::()) .finish() } } @@ -608,7 +609,7 @@ impl std::fmt::Debug for PartitionSet { impl Drop for PartitionSet { fn drop(&mut self) { for cell in &self.spine { - let p = cell.swap(std::ptr::null_mut(), Ordering::AcqRel); + let p = cell.swap(core::ptr::null_mut(), Ordering::AcqRel); if p.is_null() { continue; } @@ -616,7 +617,7 @@ impl Drop for PartitionSet { // published exactly once, and nothing else frees it. let chunk = unsafe { Box::from_raw(p) }; for slot in chunk.slots.iter() { - let sp = slot.swap(std::ptr::null_mut(), Ordering::AcqRel); + let sp = slot.swap(core::ptr::null_mut(), Ordering::AcqRel); if !sp.is_null() { // Safety: a live slot owns one strong reference. drop(unsafe { Arc::from_raw(sp as *const T) }); @@ -652,8 +653,8 @@ pub enum PartitionError { OutOfRange { key: u64 }, } -impl std::fmt::Display for PartitionError { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Display for PartitionError { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match self { PartitionError::OutOfRange { key } => { write!(f, "partition key {key} exceeds the maximum of {MAX_PARTITIONS}") @@ -662,7 +663,7 @@ impl std::fmt::Display for PartitionError { } } -impl std::error::Error for PartitionError {} +impl core::error::Error for PartitionError {} #[cfg(all(test, not(wt_loom)))] mod tests; diff --git a/src/partition/tests.rs b/src/partition/tests.rs index a18f9e68..769c366f 100644 --- a/src/partition/tests.rs +++ b/src/partition/tests.rs @@ -1,5 +1,6 @@ +use alloc::{string::ToString, vec::Vec}; use super::*; -use std::sync::atomic::AtomicU32; +use core::sync::atomic::AtomicU32; #[derive(Debug, PartialEq)] struct Counted(u64); @@ -119,7 +120,7 @@ fn concurrent_creation_of_one_key_makes_one_table() { #[test] fn concurrent_readers_see_a_partition_created_under_them() { let set: Arc> = Arc::new(PartitionSet::new()); - let stop = Arc::new(std::sync::atomic::AtomicBool::new(false)); + let stop = Arc::new(core::sync::atomic::AtomicBool::new(false)); let reader = { let set = set.clone(); let stop = stop.clone(); @@ -389,7 +390,7 @@ fn a_reader_racing_a_remove_never_touches_freed_memory() { let drops = Arc::new(AtomicU32::new(0)); let set: Arc> = Arc::new(PartitionSet::new()); - let stop = Arc::new(std::sync::atomic::AtomicBool::new(false)); + let stop = Arc::new(core::sync::atomic::AtomicBool::new(false)); let seen = Arc::new(AtomicU32::new(0)); let readers: Vec<_> = (0..if cfg!(miri) { 2 } else { 3 }) @@ -434,7 +435,7 @@ fn a_reader_racing_a_remove_never_touches_freed_memory() { for k in 0..KEYS { set.get_or_create(k, || make(k, &drops)).unwrap(); } - let deadline = std::time::Instant::now() + std::time::Duration::from_secs(30); + let deadline = std::time::Instant::now() + core::time::Duration::from_secs(30); while seen.load(Ordering::Relaxed) == 0 && std::time::Instant::now() < deadline { std::thread::yield_now(); } @@ -447,7 +448,7 @@ fn a_reader_racing_a_remove_never_touches_freed_memory() { // read to finish, never a zero-reader instant. The pre-epoch retire list // could only assert the opposite here (everything retired, nothing // freed, unbounded growth through the shared router). - let reclaim_deadline = std::time::Instant::now() + std::time::Duration::from_secs(30); + let reclaim_deadline = std::time::Instant::now() + core::time::Duration::from_secs(30); while drops.load(Ordering::SeqCst) == 0 && std::time::Instant::now() < reclaim_deadline { set.collect(); std::thread::yield_now(); @@ -473,7 +474,7 @@ fn a_reader_racing_a_remove_never_touches_freed_memory() { // Drain the remainder through the shared handle: no `&mut`, no // `Arc::try_unwrap` gymnastics needed for reclamation any more. - let drain_deadline = std::time::Instant::now() + std::time::Duration::from_secs(30); + let drain_deadline = std::time::Instant::now() + core::time::Duration::from_secs(30); while set.retired_len() > 0 && std::time::Instant::now() < drain_deadline { set.collect(); } @@ -669,7 +670,7 @@ fn mem_stat_reports_each_partition_and_their_sum() { // `size_of::()` on top of the payload, because that is what the // allocation actually holds. Derived rather than hard coded so the // expectation is the rule, not one machine's numbers. - let overhead = std::mem::size_of::(); + let overhead = core::mem::size_of::(); for (k, size) in [(3u64, 17usize), (1, 5), (2048, 300)] { set.get_or_create(k, || Sized_(size)).unwrap(); } @@ -698,6 +699,6 @@ fn partition_error_says_which_key_and_which_bound() { ); // The `Error` impl is what a caller using `?` and `eyre` will format. - let as_error: &dyn std::error::Error = &out_of_range; + let as_error: &dyn core::error::Error = &out_of_range; assert_eq!(as_error.to_string(), text); } diff --git a/src/persistence/engine.rs b/src/persistence/engine.rs index 37254f6f..ae23ba46 100644 --- a/src/persistence/engine.rs +++ b/src/persistence/engine.rs @@ -1,8 +1,9 @@ -use std::fmt::Debug; +use alloc::{string::String, vec::Vec}; +use core::fmt::Debug; use std::fs; -use std::future::Future; -use std::hash::Hash; -use std::marker::PhantomData; +use core::future::Future; +use core::hash::Hash; +use core::marker::PhantomData; use std::panic::{AssertUnwindSafe, resume_unwind}; use std::path::Path; diff --git a/src/persistence/error.rs b/src/persistence/error.rs index fbfac49e..d1c9324d 100644 --- a/src/persistence/error.rs +++ b/src/persistence/error.rs @@ -1,9 +1,10 @@ -use std::error::Error; -use std::fmt::{Display, Formatter}; -use std::future::Future; +use alloc::{string::String, string::ToString}; +use core::error::Error; +use core::fmt::{Display, Formatter}; +use core::future::Future; use std::panic::AssertUnwindSafe; use std::path::{Path, PathBuf}; -use std::sync::Arc; +use alloc::sync::Arc; use futures::FutureExt; @@ -39,7 +40,7 @@ impl PersistenceLoadError { } impl Display for PersistenceLoadError { - fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, formatter: &mut Formatter<'_>) -> core::fmt::Result { write!( formatter, "torn or corrupt persisted table at {}: {}", @@ -111,7 +112,7 @@ impl PersistenceIndexCorruption { } impl Display for PersistenceIndexCorruption { - fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, formatter: &mut Formatter<'_>) -> core::fmt::Result { write!( formatter, "persisted index at {} was quarantined: {}", @@ -137,7 +138,7 @@ pub enum PersistenceError { } impl Display for PersistenceError { - fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, formatter: &mut Formatter<'_>) -> core::fmt::Result { match self { Self::Closing => formatter.write_str("persistence task is closing"), Self::Closed => formatter.write_str("persistence task is closed"), diff --git a/src/persistence/mod.rs b/src/persistence/mod.rs index b5e03ce3..b5d9e853 100644 --- a/src/persistence/mod.rs +++ b/src/persistence/mod.rs @@ -1,11 +1,14 @@ -use std::future::Future; +use core::future::Future; -use data_bucket::page::PageId; +#[cfg(feature = "std")] use crate::persistence::operation::BatchOperation; +#[cfg(feature = "std")] pub use engine::DiskConfig; +#[cfg(feature = "std")] pub use engine::DiskPersistenceEngine; +#[cfg(feature = "std")] pub use error::{ PersistenceError, PersistenceIndexCorruption, PersistenceLoadError, PersistenceResult, PersistenceState, load_persisted_state, @@ -14,7 +17,9 @@ pub use operation::{ AcknowledgeOperation, DeleteOperation, InsertOperation, Operation, OperationId, OperationType, UpdateOperation, validate_events, }; +#[cfg(feature = "std")] pub use readonly_engine::ReadOnlyPersistenceEngine; +#[cfg(feature = "std")] pub use space::{ ArtPersistenceKey, IndexTableOfContents, SpaceArcticIndex, SpaceArcticMultiIndex, SpaceArcticStringIndex, SpaceCongeeIndex, SpaceData, SpaceDataOps, SpaceIndex, SpaceIndexOps, SpaceIndexUnsized, SpaceLogicalIndex, @@ -22,6 +27,7 @@ pub use space::{ TocEntryOversizedError, map_index_pages_to_toc_and_general, map_unsized_index_pages_to_toc_and_general, reconstruct_multi_index_nodes, }; +#[cfg(feature = "std")] pub use task::{PersistenceMonitor, PersistenceTask}; /// Result of retiring one Arc-owned persisted table generation. @@ -39,13 +45,13 @@ pub struct UnloadReport { /// can keep serving it or retry. A failure returned by `close` has no retained /// generation because shutdown was already attempted and consumed it. pub struct UnloadFailure { - generation: Option>, + generation: Option>, error: eyre::Report, } impl UnloadFailure { #[doc(hidden)] - pub fn retained(generation: std::sync::Arc, error: eyre::Report) -> Self { + pub fn retained(generation: alloc::sync::Arc, error: eyre::Report) -> Self { Self { generation: Some(generation), error, @@ -61,7 +67,7 @@ impl UnloadFailure { } /// Returns the still-live generation when shutdown never began. - pub fn into_generation(self) -> Option> { + pub fn into_generation(self) -> Option> { self.generation } @@ -71,8 +77,8 @@ impl UnloadFailure { } } -impl std::fmt::Debug for UnloadFailure { - fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for UnloadFailure { + fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { formatter .debug_struct("UnloadFailure") .field("generation_retained", &self.generation.is_some()) @@ -81,19 +87,27 @@ impl std::fmt::Debug for UnloadFailure { } } -impl std::fmt::Display for UnloadFailure { - fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Display for UnloadFailure { + fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { self.error.fmt(formatter) } } -impl std::error::Error for UnloadFailure {} +impl core::error::Error for UnloadFailure {} + +#[cfg(feature = "std")] +use data_bucket::page::PageId; +#[cfg(feature = "std")] mod engine; +#[cfg(feature = "std")] mod error; pub mod operation; +#[cfg(feature = "std")] mod readonly_engine; +#[cfg(feature = "std")] mod space; +#[cfg(feature = "std")] mod task; // TODO: remove this @@ -142,6 +156,7 @@ where } } +#[cfg(feature = "std")] pub trait PersistenceEngine { type Config: PersistenceConfig; diff --git a/src/persistence/operation/batch.rs b/src/persistence/operation/batch.rs index 958bcfc0..246cf871 100644 --- a/src/persistence/operation/batch.rs +++ b/src/persistence/operation/batch.rs @@ -1,7 +1,9 @@ -use std::collections::HashMap; -use std::fmt::Debug; -use std::hash::Hash; -use std::marker::PhantomData; +use alloc::boxed::Box; +use alloc::{string::ToString, vec::Vec}; +use hashbrown::HashMap; +use core::fmt::Debug; +use core::hash::Hash; +use core::marker::PhantomData; use data_bucket::page::PageId; use data_bucket::{Link, SizeMeasurable}; @@ -484,9 +486,10 @@ where #[cfg(test)] mod tests { - use std::collections::HashMap; + use hashbrown::HashMap; use data_bucket::Link; + use data_bucket::page::PageId; use indexset::core::pair::Pair; use uuid::Uuid; @@ -534,7 +537,7 @@ mod tests { // Deliberately reverse vector order: operation ids, not incidental // collection order, define which bytes are newest. let batch = latest_data_writes(&[insert(2, new_link, vec![2; 6]), insert(1, old_link, vec![1; 4])]); - let writes = batch.get(&1.into()).unwrap(); + let writes = batch.get(&PageId::from(1u32)).unwrap(); assert_eq!(writes, &vec![(new_link, vec![2; 6])]); } @@ -554,7 +557,7 @@ mod tests { for _ in 0..128 { let batch = latest_data_writes(&[insert(2, newer_link, vec![2; 8]), insert(1, older_link, vec![1; 8])]); - let writes = batch.get(&1.into()).unwrap(); + let writes = batch.get(&PageId::from(1u32)).unwrap(); assert_eq!(writes, &vec![(older_link, vec![1; 8]), (newer_link, vec![2; 8])]); } @@ -579,7 +582,7 @@ mod tests { ]); assert_eq!( - batch.get(&1.into()).unwrap(), + batch.get(&PageId::from(1u32)).unwrap(), &vec![(older_link, vec![1; 8]), (newer_link, vec![2; 8])] ); } @@ -602,7 +605,7 @@ mod tests { multi_insert(1, new_link, vec![2; 6]), ]); - assert_eq!(batch.get(&1.into()).unwrap(), &vec![(new_link, vec![2; 6])]); + assert_eq!(batch.get(&PageId::from(1u32)).unwrap(), &vec![(new_link, vec![2; 6])]); } #[tokio::test] @@ -634,7 +637,7 @@ mod tests { } fn iter_event_ids(&self) -> impl Iterator { - std::iter::empty() + core::iter::empty() } fn sort(&mut self) {} @@ -734,7 +737,7 @@ mod tests { let data = batch.get_batch_data_op().unwrap(); assert_eq!( - data.get(&1.into()).unwrap(), + data.get(&PageId::from(1u32)).unwrap(), &vec![(survivor_link, vec![7; 4])], "the surviving data-only write must stay in the applied batch" ); diff --git a/src/persistence/operation/mod.rs b/src/persistence/operation/mod.rs index 5f7954fc..3097abbe 100644 --- a/src/persistence/operation/mod.rs +++ b/src/persistence/operation/mod.rs @@ -1,11 +1,12 @@ +#[cfg(feature = "std")] mod batch; #[allow(clippy::module_inception)] mod operation; mod util; -use std::cmp::Ordering; -use std::fmt::Debug; -use std::hash::{Hash, Hasher}; +use core::cmp::Ordering; +use core::fmt::Debug; +use core::hash::{Hash, Hasher}; use data_bucket::SizeMeasurable; use derive_more::Display; @@ -14,6 +15,7 @@ use uuid::Uuid; use crate::prelude::From; +#[cfg(feature = "std")] pub use batch::{BatchInnerRow, BatchInnerWorkTable, BatchOperation}; pub use operation::{AcknowledgeOperation, DeleteOperation, InsertOperation, Operation, UpdateOperation}; pub use util::validate_events; diff --git a/src/persistence/operation/operation.rs b/src/persistence/operation/operation.rs index 36af8298..acc09017 100644 --- a/src/persistence/operation/operation.rs +++ b/src/persistence/operation/operation.rs @@ -1,5 +1,6 @@ -use std::fmt::Debug; -use std::hash::{Hash, Hasher}; +use alloc::{vec::Vec}; +use core::fmt::Debug; +use core::hash::{Hash, Hasher}; use data_bucket::Link; use indexset::cdc::change::ChangeEvent; diff --git a/src/persistence/operation/util.rs b/src/persistence/operation/util.rs index 405a9ce3..fc204953 100644 --- a/src/persistence/operation/util.rs +++ b/src/persistence/operation/util.rs @@ -1,7 +1,8 @@ +use alloc::{vec::Vec}; use data_bucket::Link; use indexset::cdc::change::{self, ChangeEvent}; use indexset::core::pair::Pair; -use std::fmt::Debug; +use core::fmt::Debug; pub fn validate_events(evs: &mut Vec>>) -> Vec>> where @@ -20,7 +21,7 @@ where } } - removed_events.sort_by_key(|ev2| std::cmp::Reverse(ev2.id())); + removed_events.sort_by_key(|ev2| core::cmp::Reverse(ev2.id())); removed_events } diff --git a/src/persistence/readonly_engine.rs b/src/persistence/readonly_engine.rs index 27a19d25..b35389bc 100644 --- a/src/persistence/readonly_engine.rs +++ b/src/persistence/readonly_engine.rs @@ -1,5 +1,5 @@ -use std::fmt::Debug; -use std::hash::Hash; +use core::fmt::Debug; +use core::hash::Hash; use crate::TableSecondaryIndexEventsOps; use crate::persistence::operation::{BatchOperation, Operation}; diff --git a/src/persistence/space/art_index.rs b/src/persistence/space/art_index.rs index d2db86c6..f3da8281 100644 --- a/src/persistence/space/art_index.rs +++ b/src/persistence/space/art_index.rs @@ -6,9 +6,10 @@ //! applies the WAL, writes a new native checkpoint atomically, and drops the //! temporary tree; no duplicate ART is retained during normal operation. -use std::fmt::Debug; -use std::hash::Hash; -use std::marker::PhantomData; +use alloc::{borrow::ToOwned, string::String, vec::Vec}; +use core::fmt::Debug; +use core::hash::Hash; +use core::marker::PhantomData; use std::path::{Path, PathBuf}; use data_bucket::{Link, page::PageId}; @@ -76,14 +77,14 @@ macro_rules! impl_art_persistence_key { ($($type:ty),+ $(,)?) => { $( impl ArtPersistenceKey for $type { - const WIDTH: u8 = std::mem::size_of::() as u8; + const WIDTH: u8 = core::mem::size_of::() as u8; fn encode_art_key(&self, output: &mut Vec) { output.extend_from_slice(&self.to_be_bytes()); } fn decode_art_key(bytes: &[u8]) -> eyre::Result { - let bytes: [u8; std::mem::size_of::()] = bytes + let bytes: [u8; core::mem::size_of::()] = bytes .try_into() .map_err(|_| eyre!("invalid {}-byte ART key", Self::WIDTH))?; Ok(Self::from_be_bytes(bytes)) @@ -112,7 +113,7 @@ macro_rules! impl_art_persistence_key_signed { ($($type:ty => $raw:ty),+ $(,)?) => { $( impl ArtPersistenceKey for $type { - const WIDTH: u8 = std::mem::size_of::() as u8; + const WIDTH: u8 = core::mem::size_of::() as u8; fn encode_art_key(&self, output: &mut Vec) { let raw = (*self as $raw) ^ ((1 as $raw) << (<$raw>::BITS - 1)); @@ -120,7 +121,7 @@ macro_rules! impl_art_persistence_key_signed { } fn decode_art_key(bytes: &[u8]) -> eyre::Result { - let bytes: [u8; std::mem::size_of::()] = bytes + let bytes: [u8; core::mem::size_of::()] = bytes .try_into() .map_err(|_| eyre!("invalid {}-byte ART key", Self::WIDTH))?; let raw = <$raw>::from_be_bytes(bytes) ^ ((1 as $raw) << (<$raw>::BITS - 1)); @@ -384,7 +385,7 @@ impl ArtFile { fn encode_wal_record(record: &WalRecord) -> Vec { let mut key = Vec::new(); record.key.encode_art_key(&mut key); - let variable_prefix = usize::from(K::WIDTH == 0) * std::mem::size_of::(); + let variable_prefix = usize::from(K::WIDTH == 0) * core::mem::size_of::(); let mut bytes = Vec::with_capacity(9 + variable_prefix + key.len() + 12); bytes.extend_from_slice(&record.event_id.to_le_bytes()); match record.op { @@ -717,7 +718,7 @@ where path, Backend::ArcticVariable, table_version, - encode_multi_pairs(std::iter::empty::<(K, Link)>()), + encode_multi_pairs(core::iter::empty::<(K, Link)>()), ) .await?, }) @@ -922,7 +923,7 @@ where K: ArtPersistenceKey + ArcticKey, { async fn new(path: PathBuf, table_version: u32) -> eyre::Result { - let snapshot = encode_multi_pairs(std::iter::empty::<(K, Link)>()); + let snapshot = encode_multi_pairs(core::iter::empty::<(K, Link)>()); Ok(Self { file: ArtFile::open(path, Backend::ArcticMulti, table_version, snapshot).await?, }) @@ -1439,7 +1440,7 @@ mod tests { assert_eq!(decode_multi_pairs::(&bytes).unwrap(), pairs); assert!(decode_multi_pairs::(&bytes[..bytes.len() - 1]).is_err()); assert_eq!( - decode_multi_pairs::(&encode_multi_pairs(std::iter::empty::<(u64, Link)>())).unwrap(), + decode_multi_pairs::(&encode_multi_pairs(core::iter::empty::<(u64, Link)>())).unwrap(), vec![] ); } diff --git a/src/persistence/space/data.rs b/src/persistence/space/data.rs index dd200019..6476f95f 100644 --- a/src/persistence/space/data.rs +++ b/src/persistence/space/data.rs @@ -1,4 +1,5 @@ -use std::collections::HashSet; +use alloc::{string::String, string::ToString, vec::Vec}; +use hashbrown::HashSet; use std::io::SeekFrom; use std::path::Path; @@ -206,7 +207,7 @@ impl SpaceData

) -> bool { - let free_ranges = std::mem::take(&mut self.info.inner.empty_links_list); + let free_ranges = core::mem::take(&mut self.info.inner.empty_links_list); let (remaining, changed) = subtract_used_ranges(free_ranges, used_links); self.info.inner.empty_links_list = remaining; changed diff --git a/src/persistence/space/index/mod.rs b/src/persistence/space/index/mod.rs index d4cbc625..0522bc7b 100644 --- a/src/persistence/space/index/mod.rs +++ b/src/persistence/space/index/mod.rs @@ -1,15 +1,16 @@ +use alloc::{string::String, string::ToString, vec::Vec}; mod page_aliases; mod reconstruct; mod table_of_contents; mod unsized_; mod util; -use std::collections::HashMap; -use std::fmt::Debug; -use std::hash::Hash; +use hashbrown::HashMap; +use core::fmt::Debug; +use core::hash::Hash; use std::path::Path; -use std::sync::Arc; -use std::sync::atomic::{AtomicU32, Ordering}; +use alloc::sync::Arc; +use core::sync::atomic::{AtomicU32, Ordering}; use convert_case::{Case, Casing}; use data_bucket::page::{IndexValue, PageId}; diff --git a/src/persistence/space/index/page_aliases.rs b/src/persistence/space/index/page_aliases.rs index 131dd05d..627588e4 100644 --- a/src/persistence/space/index/page_aliases.rs +++ b/src/persistence/space/index/page_aliases.rs @@ -5,6 +5,7 @@ //! when a split or a max-remove re-keys a page mid-batch while later events //! still name a historical maximum. +use alloc::vec::Vec; use data_bucket::Link; use data_bucket::page::PageId; use eyre::eyre; @@ -35,7 +36,7 @@ pub(super) struct PageAliasEntry { impl Default for PageAliases { fn default() -> Self { Self { - inline: std::array::from_fn(|_| None), + inline: core::array::from_fn(|_| None), overflow: Vec::new(), } } diff --git a/src/persistence/space/index/reconstruct.rs b/src/persistence/space/index/reconstruct.rs index dab116ca..5335a372 100644 --- a/src/persistence/space/index/reconstruct.rs +++ b/src/persistence/space/index/reconstruct.rs @@ -4,7 +4,8 @@ //! generic function that can be unit-tested with synthetic pages; the proc //! macro only generates type plumbing and node attachment. -use std::fmt::Debug; +use alloc::{vec::Vec}; +use core::fmt::Debug; use indexset::core::multipair::MultiPair; use indexset::core::pair::Pair; @@ -173,7 +174,7 @@ mod tests { for b in nodes.iter().skip(i + 1) { assert_ne!( a.last().unwrap().cmp(b.last().unwrap()), - std::cmp::Ordering::Equal, + core::cmp::Ordering::Equal, "two node maxima compare Equal: {:?} vs {:?}", a.last().unwrap(), b.last().unwrap() @@ -247,7 +248,7 @@ mod tests { assert_eq!(flatten(&nodes[..1]), vec![(1, 1), (1, 2), (2, 30)]); // Every stored entry is distinct. That is what the discriminator counter was // for; identity is now the `(key, value)` pair itself. - let mut seen = std::collections::BTreeSet::new(); + let mut seen = alloc::collections::BTreeSet::new(); for p in nodes.iter().flatten() { assert!(seen.insert((p.key, p.value)), "duplicate entry {:?}", (p.key, p.value)); } diff --git a/src/persistence/space/index/table_of_contents.rs b/src/persistence/space/index/table_of_contents.rs index 633c1cf5..66f64069 100644 --- a/src/persistence/space/index/table_of_contents.rs +++ b/src/persistence/space/index/table_of_contents.rs @@ -1,6 +1,7 @@ -use std::fmt::Debug; -use std::sync::Arc; -use std::sync::atomic::{AtomicU32, Ordering}; +use alloc::vec::Vec; +use core::fmt::Debug; +use alloc::sync::Arc; +use core::sync::atomic::{AtomicU32, Ordering}; use data_bucket::page::PageId; use data_bucket::{ @@ -26,8 +27,8 @@ pub struct TocEntryOversizedError { pub segment_capacity: usize, } -impl std::fmt::Display for TocEntryOversizedError { - fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Display for TocEntryOversizedError { + fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!( formatter, "table-of-contents entry needs {} bytes but a whole empty segment holds only {}", @@ -36,7 +37,7 @@ impl std::fmt::Display for TocEntryOversizedError { } } -impl std::error::Error for TocEntryOversizedError {} +impl core::error::Error for TocEntryOversizedError {} #[derive(Debug)] pub struct IndexTableOfContents { @@ -317,8 +318,8 @@ where mod tests { use crate::persistence::space::index::table_of_contents::IndexTableOfContents; use data_bucket::page::PageId; - use std::sync::Arc; - use std::sync::atomic::AtomicU32; + use alloc::sync::Arc; + use core::sync::atomic::AtomicU32; #[test] fn empty() { diff --git a/src/persistence/space/index/unsized_.rs b/src/persistence/space/index/unsized_.rs index dd7cdad0..30789c7c 100644 --- a/src/persistence/space/index/unsized_.rs +++ b/src/persistence/space/index/unsized_.rs @@ -1,8 +1,9 @@ -use std::collections::HashMap; -use std::fmt::Debug; -use std::hash::Hash; -use std::sync::Arc; -use std::sync::atomic::{AtomicU32, Ordering}; +use alloc::{string::String, vec::Vec}; +use hashbrown::HashMap; +use core::fmt::Debug; +use core::hash::Hash; +use alloc::sync::Arc; +use core::sync::atomic::{AtomicU32, Ordering}; use data_bucket::page::PageId; use data_bucket::{ diff --git a/src/persistence/space/index/util.rs b/src/persistence/space/index/util.rs index cde98019..225f3fae 100644 --- a/src/persistence/space/index/util.rs +++ b/src/persistence/space/index/util.rs @@ -1,10 +1,11 @@ +use alloc::{vec::Vec}; use crate::prelude::IndexTableOfContents; use data_bucket::{ GeneralHeader, GeneralPage, IndexPage, Link, PageType, SizeMeasurable, UnsizedIndexPage, VariableSizeMeasurable, }; -use std::fmt::Debug; -use std::sync::Arc; -use std::sync::atomic::{AtomicU32, Ordering}; +use core::fmt::Debug; +use alloc::sync::Arc; +use core::sync::atomic::{AtomicU32, Ordering}; #[allow(clippy::type_complexity)] pub fn map_index_pages_to_toc_and_general( diff --git a/src/persistence/space/logical_index.rs b/src/persistence/space/logical_index.rs index e2e948fc..ec4aa643 100644 --- a/src/persistence/space/logical_index.rs +++ b/src/persistence/space/logical_index.rs @@ -5,8 +5,9 @@ //! this persistence-worker-owned index derives the structural events required //! by the unchanged WTI disk format. -use std::fmt::Debug; -use std::hash::Hash; +use alloc::{string::String, vec::Vec}; +use core::fmt::Debug; +use core::hash::Hash; use std::path::{Path, PathBuf}; use data_bucket::{Link, SizeMeasurable, SpaceId, VariableSizeMeasurable}; @@ -171,7 +172,7 @@ impl Debug for SpaceLogicalIndex) -> std::fmt::Result { + fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { formatter.debug_struct("SpaceLogicalIndex").finish_non_exhaustive() } } @@ -273,7 +274,7 @@ impl Debug for SpaceLogicalIndexUnsized) -> std::fmt::Result { + fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { formatter .debug_struct("SpaceLogicalIndexUnsized") .finish_non_exhaustive() @@ -381,7 +382,7 @@ impl Debug for SpaceLogicalMultiIndex) -> std::fmt::Result { + fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { formatter.debug_struct("SpaceLogicalMultiIndex").finish_non_exhaustive() } } @@ -483,7 +484,7 @@ impl Debug for SpaceLogicalMultiIndexUnsized) -> std::fmt::Result { + fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { formatter .debug_struct("SpaceLogicalMultiIndexUnsized") .finish_non_exhaustive() @@ -577,7 +578,7 @@ where #[cfg(test)] mod tests { - use std::collections::BTreeMap as StdBTreeMap; + use alloc::collections::BTreeMap as StdBTreeMap; use data_bucket::page::PageId; diff --git a/src/persistence/space/mod.rs b/src/persistence/space/mod.rs index 4f9d280b..ea885b2c 100644 --- a/src/persistence/space/mod.rs +++ b/src/persistence/space/mod.rs @@ -1,10 +1,11 @@ +use alloc::{string::String, vec::Vec}; mod art_index; mod data; mod index; mod logical_index; -use std::collections::HashMap; -use std::future::Future; +use hashbrown::HashMap; +use core::future::Future; use std::path::Path; use data_bucket::page::PageId; diff --git a/src/persistence/task.rs b/src/persistence/task.rs index fc67f09f..deebeb72 100644 --- a/src/persistence/task.rs +++ b/src/persistence/task.rs @@ -1,10 +1,13 @@ -use std::collections::{HashMap, HashSet, VecDeque}; -use std::fmt::Debug; -use std::hash::Hash; -use std::marker::PhantomData; -use std::sync::Arc; -use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; -use std::time::Duration; +use alloc::boxed::Box; +use alloc::{borrow::ToOwned, string::String, string::ToString, vec::Vec}; +use alloc::collections::VecDeque; +use hashbrown::{HashMap, HashSet}; +use core::fmt::Debug; +use core::hash::Hash; +use core::marker::PhantomData; +use alloc::sync::Arc; +use core::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; +use core::time::Duration; use data_bucket::page::PageId; use parking_lot::Mutex as ParkingMutex; @@ -480,8 +483,8 @@ where #[cfg(test)] mod lifecycle_tests { - use std::collections::HashMap; - use std::sync::atomic::{AtomicUsize, Ordering}; + use hashbrown::HashMap; + use core::sync::atomic::{AtomicUsize, Ordering}; use super::*; @@ -508,7 +511,7 @@ mod lifecycle_tests { } fn iter_event_ids(&self) -> impl Iterator { - std::iter::empty() + core::iter::empty() } fn sort(&mut self) {} @@ -727,7 +730,7 @@ mod lifecycle_tests { .unwrap(); assert_eq!( - batch.get(&1.into()).unwrap(), + batch.get(&PageId::from(1u32)).unwrap(), &vec![ ( Link { @@ -791,7 +794,7 @@ mod lifecycle_tests { .get_batch_data_op() .unwrap(); - let page_one_writes = batch.get(&1.into()).unwrap(); + let page_one_writes = batch.get(&PageId::from(1u32)).unwrap(); assert_eq!( page_one_writes, &vec![ @@ -815,7 +818,7 @@ mod lifecycle_tests { "the complete earlier group must be applied" ); assert!( - !batch.contains_key(&2.into()), + !batch.contains_key(&PageId::from(2u32)), "the blocking group must stay queued, not be applied without its earlier events" ); assert_eq!(analyzer.len(), 2, "both rows of the blocked group remain queued"); @@ -1162,7 +1165,7 @@ pub struct Queue { len: Arc, lifecycle: Arc, #[cfg(test)] - pop_race_window_gate: Option>, + pop_race_window_gate: Option>, } impl Queue { diff --git a/src/primary_key.rs b/src/primary_key.rs index ff73bbec..c38ec520 100644 --- a/src/primary_key.rs +++ b/src/primary_key.rs @@ -1,4 +1,5 @@ -use std::sync::atomic::{ + +use core::sync::atomic::{ AtomicI8, AtomicI16, AtomicI32, AtomicI64, AtomicU8, AtomicU16, AtomicU32, AtomicU64, Ordering, }; @@ -21,7 +22,7 @@ pub trait PrimaryKeyGeneratorRange { /// /// Concurrent `reserve` and [`PrimaryKeyGenerator::next`] calls never /// observe overlapping keys. - fn reserve(&self, count: usize) -> std::ops::Range; + fn reserve(&self, count: usize) -> core::ops::Range; } pub trait PrimaryKeyGeneratorState { @@ -52,7 +53,7 @@ macro_rules! atomic_primary_key { } impl PrimaryKeyGeneratorRange<$ty> for $atomic_ty { - fn reserve(&self, count: usize) -> std::ops::Range<$ty> { + fn reserve(&self, count: usize) -> core::ops::Range<$ty> { let count = <$ty>::try_from(count).unwrap_or_else(|_| { panic!( "autoincrement primary key space exhausted: cannot reserve {count} {} keys", @@ -142,7 +143,7 @@ mod tests { #[test] fn concurrent_reservations_never_overlap() { - use std::sync::Arc; + use alloc::sync::Arc; let generator = Arc::new(AtomicU64::from_state(0)); let mut handles = vec![]; diff --git a/src/table/mod.rs b/src/table/mod.rs index eeba4d01..2b6d18c8 100644 --- a/src/table/mod.rs +++ b/src/table/mod.rs @@ -1,9 +1,13 @@ +use alloc::{string::String, vec::Vec}; pub mod select; pub mod system_info; +#[cfg(feature = "std")] pub mod vacuum; use crate::in_memory::{ArchivedRowWrapper, DataPages, RowWrapper, StorableRow}; -use crate::persistence::{AcknowledgeOperation, InsertOperation, Operation, PersistenceLoadError}; +use crate::persistence::{AcknowledgeOperation, InsertOperation, Operation}; +#[cfg(feature = "std")] +use crate::persistence::PersistenceLoadError; use crate::prelude::{Link, LockMap, OperationId, PrimaryKeyGeneratorState}; use crate::primary_key::{PrimaryKeyGenerator, TablePrimaryKey}; use crate::util::OffsetEqLink; @@ -24,11 +28,13 @@ use rkyv::ser::allocator::ArenaHandle; use rkyv::ser::sharing::Share; use rkyv::util::AlignedVec; use rkyv::{Archive, Deserialize, Portable, Serialize}; -use std::collections::HashSet; -use std::fmt::Debug; -use std::marker::PhantomData; +#[cfg(feature = "std")] +use hashbrown::HashSet; +use core::fmt::Debug; +use core::marker::PhantomData; +#[cfg(feature = "std")] use std::path::Path; -use std::sync::Arc; +use alloc::sync::Arc; use uuid::Uuid; /// Keys per chunk when a bulk delete takes its mutation guards. /// @@ -51,7 +57,7 @@ pub struct WorkTable< const DATA_LENGTH: usize = INNER_PAGE_SIZE, PkMap = IndexMap>, > where - PrimaryKey: Clone + Ord + Send + 'static + std::hash::Hash, + PrimaryKey: Clone + Ord + Send + 'static + core::hash::Hash, Row: StorableRow + Send + Clone + 'static, PkMap: crate::UniqueIndex>, { @@ -94,7 +100,7 @@ impl< PkMap, > where - PrimaryKey: Debug + Clone + Ord + Send + TablePrimaryKey + std::hash::Hash, + PrimaryKey: Debug + Clone + Ord + Send + TablePrimaryKey + core::hash::Hash, SecondaryIndexes: Default, PkGen: Default, PkMap: crate::UniqueIndex>, @@ -127,7 +133,7 @@ impl< > WorkTable where Row: TableRow, - PrimaryKey: Debug + Clone + Ord + Send + TablePrimaryKey + std::hash::Hash, + PrimaryKey: Debug + Clone + Ord + Send + TablePrimaryKey + core::hash::Hash, PkMap: crate::UniqueIndex>, Row: StorableRow + Send + Clone + 'static, ::WrappedRow: RowWrapper, @@ -138,6 +144,7 @@ where /// This load-only scan prevents a torn index link from turning zeroed or /// unrelated bytes into a plausible row. It deliberately does not run on /// steady-state operations. + #[cfg(feature = "std")] pub fn validate_persisted_state(&self, path: impl AsRef) -> Result<(), PersistenceLoadError> where <::WrappedRow as Archive>::Archived: Portable @@ -146,7 +153,7 @@ where { let path = path.as_ref(); let mut links = HashSet::with_capacity(self.primary_index.pk_map.len()); - let mut cells_by_page = std::collections::HashMap::::new(); + let mut cells_by_page = hashbrown::HashMap::::new(); for (primary_key, offset_link) in self.primary_index.pk_map.iter_values() { if !links.insert(offset_link) { @@ -211,7 +218,7 @@ where /// caller can iterate it directly while pre-assigning contiguous keys to a /// batch of rows for `insert_many`. Interleaved [`Self::get_next_pk`] /// calls keep working and never overlap a reservation. - pub fn reserve_pks(&self, count: usize) -> std::ops::Range + pub fn reserve_pks(&self, count: usize) -> core::ops::Range where PkGen: crate::primary_key::PrimaryKeyGeneratorRange, { @@ -238,7 +245,7 @@ where if current_link == Some(link) { return None; } - std::hint::spin_loop(); + core::hint::spin_loop(); } None } @@ -475,7 +482,7 @@ where /// Returns the keys actually deleted, in key order. pub fn delete_range(&self, range: R) -> Result, BatchDeleteError> where - R: std::ops::RangeBounds, + R: core::ops::RangeBounds, Row: Archive + Clone + for<'a> Serialize, Share>, rkyv::rancor::Error>>, @@ -531,8 +538,8 @@ where .primary_index .pk_map .range_values(( - std::ops::Bound::Included(chunk[0].clone()), - std::ops::Bound::Included(chunk[chunk.len() - 1].clone()), + core::ops::Bound::Included(chunk[0].clone()), + core::ops::Bound::Included(chunk[chunk.len() - 1].clone()), )) .map(|(key, link)| (key, link.into())) .collect(); @@ -1089,8 +1096,8 @@ where ops.push(Operation::Insert(InsertOperation { id: OperationId::Multi(batch_id), pk_gen_state: self.pk_gen.get_state(), - primary_key_events: std::mem::take(&mut forward_primary[row_index]), - secondary_keys_events: std::mem::take(&mut forward_secondary[row_index]), + primary_key_events: core::mem::take(&mut forward_primary[row_index]), + secondary_keys_events: core::mem::take(&mut forward_secondary[row_index]), bytes, link: *link, })); @@ -1349,7 +1356,7 @@ pub enum BatchInsertError { /// batch needs to know the prefix already succeeded rather than assume nothing /// happened. #[derive(Debug, Display, Error)] -pub enum BatchDeleteError { +pub enum BatchDeleteError { /// One key could not be deleted. Everything before it was. #[display("batch delete stopped at {key:?} after {deleted} deleted: {source}")] Key { @@ -1376,5 +1383,6 @@ pub enum WorkTableError { PrimaryUpdateTry, PagesError(in_memory::PagesExecutionError), #[display("{}", _0)] - PersistenceError(#[error(not(source))] std::sync::Arc), + #[cfg(feature = "std")] + PersistenceError(#[error(not(source))] alloc::sync::Arc), } diff --git a/src/table/select/mod.rs b/src/table/select/mod.rs index 5b9fc6e6..fe7de3ed 100644 --- a/src/table/select/mod.rs +++ b/src/table/select/mod.rs @@ -1,4 +1,4 @@ -use std::collections::VecDeque; +use alloc::collections::VecDeque; mod query; diff --git a/src/table/select/query.rs b/src/table/select/query.rs index 2b2f3f66..d946d81e 100644 --- a/src/table/select/query.rs +++ b/src/table/select/query.rs @@ -1,7 +1,8 @@ +use alloc::{vec::Vec}; use crate::WorkTableError; use crate::select::{Order, QueryParams}; -use std::collections::VecDeque; +use alloc::collections::VecDeque; pub struct SelectQueryBuilder where diff --git a/src/table/system_info.rs b/src/table/system_info.rs index 49e95761..51196380 100644 --- a/src/table/system_info.rs +++ b/src/table/system_info.rs @@ -1,5 +1,6 @@ +use alloc::{string::String, string::ToString, vec::Vec}; use prettytable::{Table, format::consts::FORMAT_NO_BORDER_LINE_SEPARATOR, row}; -use std::fmt::{self, Debug, Display, Formatter}; +use core::fmt::{self, Debug, Display, Formatter}; use crate::in_memory::{RowWrapper, StorableRow}; use crate::mem_stat::MemStat; @@ -55,7 +56,7 @@ impl< PkMap, > WorkTable where - PrimaryKey: Debug + Clone + Ord + Send + 'static + std::hash::Hash, + PrimaryKey: Debug + Clone + Ord + Send + 'static + core::hash::Hash, Row: StorableRow + Send + Clone + 'static, ::WrappedRow: RowWrapper, PkMap: UniqueIndex>, diff --git a/src/table/vacuum/fragmentation_info.rs b/src/table/vacuum/fragmentation_info.rs index 6541e014..4a554297 100644 --- a/src/table/vacuum/fragmentation_info.rs +++ b/src/table/vacuum/fragmentation_info.rs @@ -12,7 +12,8 @@ //! //! [`WorkTable`]: crate::table::WorkTable -use std::collections::HashMap; +use alloc::{vec::Vec}; +use hashbrown::HashMap; use data_bucket::page::PageId; use data_bucket::{INNER_PAGE_SIZE, Link}; diff --git a/src/table/vacuum/manager.rs b/src/table/vacuum/manager.rs index 566ed452..2ac62d34 100644 --- a/src/table/vacuum/manager.rs +++ b/src/table/vacuum/manager.rs @@ -1,7 +1,8 @@ -use std::collections::HashMap; -use std::sync::Arc; -use std::sync::atomic::{AtomicU64, Ordering}; -use std::time::Duration; +use alloc::{string::ToString, vec::Vec}; +use hashbrown::HashMap; +use alloc::sync::Arc; +use core::sync::atomic::{AtomicU64, Ordering}; +use core::time::Duration; use tokio::task::AbortHandle; use parking_lot::RwLock; diff --git a/src/table/vacuum/mod.rs b/src/table/vacuum/mod.rs index 74fc55db..d14b7bc9 100644 --- a/src/table/vacuum/mod.rs +++ b/src/table/vacuum/mod.rs @@ -1,3 +1,5 @@ +use alloc::boxed::Box; +use alloc::{vec::Vec}; use async_trait::async_trait; use data_bucket::Link; diff --git a/src/table/vacuum/pacing.rs b/src/table/vacuum/pacing.rs index 1ff64c9d..ea4bf81f 100644 --- a/src/table/vacuum/pacing.rs +++ b/src/table/vacuum/pacing.rs @@ -15,8 +15,8 @@ //! the preceding check. Every insert, delete and upsert passes through those //! stripes, including mutations that never ask for reclaimable space. -use std::sync::atomic::{AtomicBool, AtomicU64, Ordering}; -use std::time::Duration; +use core::sync::atomic::{AtomicBool, AtomicU64, Ordering}; +use core::time::Duration; use smart_default::SmartDefault; @@ -114,7 +114,7 @@ pub trait ForegroundActivity { impl ForegroundActivity for crate::lock::LockMap where - PrimaryKey: Clone + std::fmt::Debug + Eq + std::hash::Hash, + PrimaryKey: Clone + core::fmt::Debug + Eq + core::hash::Hash, { fn mutations_in_flight(&self) -> usize { crate::lock::LockMap::mutations_in_flight(self) @@ -163,8 +163,8 @@ impl VacuumPacing { #[cfg(test)] mod tests { - use std::sync::Arc; - use std::sync::atomic::{AtomicBool, AtomicU64, Ordering}; + use alloc::sync::Arc; + use core::sync::atomic::{AtomicBool, AtomicU64, Ordering}; use super::*; diff --git a/src/table/vacuum/vacuum.rs b/src/table/vacuum/vacuum.rs index 47030bca..752c85a9 100644 --- a/src/table/vacuum/vacuum.rs +++ b/src/table/vacuum/vacuum.rs @@ -1,9 +1,12 @@ -use std::collections::VecDeque; -use std::fmt::Debug; -use std::marker::PhantomData; -use std::sync::Arc; -use std::sync::atomic::{AtomicU64, Ordering}; -use std::time::{Duration, Instant}; +use alloc::boxed::Box; +use alloc::vec::Vec; +use alloc::collections::VecDeque; +use core::fmt::Debug; +use core::marker::PhantomData; +use alloc::sync::Arc; +use core::sync::atomic::{AtomicU64, Ordering}; +use core::time::Duration; +use std::time::Instant; /// How long retirements have to stop arriving for a delete burst to count as /// over. Short enough that a sweep still follows a delete promptly, long @@ -85,7 +88,7 @@ pub struct EmptyDataVacuum< const DATA_LENGTH: usize, SecondaryEvents = (), > where - PrimaryKey: Clone + Ord + Send + 'static + std::hash::Hash, + PrimaryKey: Clone + Ord + Send + 'static + core::hash::Hash, Row: StorableRow + Send + Clone + 'static + Debug, PkMap: UniqueIndex>, { @@ -139,7 +142,7 @@ impl< > where Row: TableRow + StorableRow + Send + Clone + 'static, - PrimaryKey: Debug + Clone + Ord + Send + TablePrimaryKey + std::hash::Hash, + PrimaryKey: Debug + Clone + Ord + Send + TablePrimaryKey + core::hash::Hash, PkMap: UniqueIndex>, ::WrappedRow: RowWrapper, Row: Archive @@ -684,7 +687,7 @@ impl< > where Row: TableRow + StorableRow + Send + Sync + Clone + 'static, - PrimaryKey: Debug + Clone + Ord + Send + Sync + TablePrimaryKey + std::hash::Hash, + PrimaryKey: Debug + Clone + Ord + Send + Sync + TablePrimaryKey + core::hash::Hash, PkMap: UniqueIndex> + Send + Sync + 'static, ::WrappedRow: RowWrapper, Row: Archive @@ -737,9 +740,10 @@ where #[cfg(test)] mod tests { - use std::collections::{HashMap, VecDeque}; - use std::sync::Arc; - use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; + use alloc::collections::VecDeque; +use hashbrown::HashMap; + use alloc::sync::Arc; + use core::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; use data_bucket::Link; use data_bucket::page::PageId; @@ -747,7 +751,7 @@ mod tests { use crate::in_memory::{ArchivedRowWrapper, RowWrapper, StorableRow}; use crate::prelude::*; - use std::time::Duration; + use core::time::Duration; use crate::vacuum::vacuum::{CandidateMove, EmptyDataVacuum}; use crate::vacuum::{VacuumGate, VacuumPacing, WorkTableVacuum}; diff --git a/src/util/mod.rs b/src/util/mod.rs index 7b1adf10..ac5cc7a4 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -1,8 +1,22 @@ pub(crate) mod epoch; mod offset_eq_link; +#[cfg(feature = "std")] mod optimized_vec; mod ordered_float; pub use offset_eq_link::OffsetEqLink; +#[cfg(feature = "std")] pub use optimized_vec::OptimizedVec; pub use ordered_float::{OrderedF32Def, OrderedF64Def}; + +/// Give up the rest of the timeslice after a spin has stopped paying. +/// +/// Under `std` that is the operating system's yield. Without one there is no +/// scheduler to yield to, so the spin hint is the whole of what can be done. +#[inline] +pub(crate) fn yield_now() { + #[cfg(feature = "std")] + std::thread::yield_now(); + #[cfg(not(feature = "std"))] + core::hint::spin_loop(); +} diff --git a/src/util/offset_eq_link.rs b/src/util/offset_eq_link.rs index 0b39d0db..a1c3c3c5 100644 --- a/src/util/offset_eq_link.rs +++ b/src/util/offset_eq_link.rs @@ -22,20 +22,20 @@ impl OffsetEqLink { } } -impl std::hash::Hash for OffsetEqLink { - fn hash(&self, state: &mut H) { +impl core::hash::Hash for OffsetEqLink { + fn hash(&self, state: &mut H) { self.absolute_index().hash(state); } } impl PartialOrd for OffsetEqLink { - fn partial_cmp(&self, other: &Self) -> Option { + fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } } impl Ord for OffsetEqLink { - fn cmp(&self, other: &Self) -> std::cmp::Ordering { + fn cmp(&self, other: &Self) -> core::cmp::Ordering { self.absolute_index().cmp(&other.absolute_index()) } } @@ -48,7 +48,7 @@ impl PartialEq for OffsetEqLink { impl Eq for OffsetEqLink {} -impl std::ops::Deref for OffsetEqLink { +impl core::ops::Deref for OffsetEqLink { type Target = Link; fn deref(&self) -> &Self::Target { @@ -85,7 +85,7 @@ impl SizeMeasurable for OffsetEqLink { mod tests { use super::*; use data_bucket::page::PageId; - use std::collections::HashSet; + use hashbrown::HashSet; const TEST_DATA_LENGTH: usize = 4096; diff --git a/src/util/optimized_vec.rs b/src/util/optimized_vec.rs index c26114d0..9570ec9b 100644 --- a/src/util/optimized_vec.rs +++ b/src/util/optimized_vec.rs @@ -1,3 +1,4 @@ +use alloc::vec::Vec; /// Struct for storing data in a vector with stable indexes and slot reuse. /// Slots are `Option`: `remove` is `Option::take`, so the value moves out /// without a `Clone` bound and the slot is freed immediately. The previous @@ -201,7 +202,7 @@ mod tests { /// count proves the removed value is the only remaining owner. #[test] fn test_optimized_vec_remove_moves_without_clone() { - use std::rc::Rc; + use alloc::rc::Rc; struct NotClone(#[allow(dead_code)] Rc<()>); diff --git a/src/util/ordered_float.rs b/src/util/ordered_float.rs index 598be510..29ff13e3 100644 --- a/src/util/ordered_float.rs +++ b/src/util/ordered_float.rs @@ -4,7 +4,7 @@ use rkyv::{Archive, Deserialize, Serialize}; #[rkyv(remote = ordered_float::OrderedFloat, archived = ArchivedF64)] #[rkyv(derive(Debug))] pub struct OrderedF64Def { - #[rkyv(getter = std::ops::Deref::deref)] + #[rkyv(getter = core::ops::Deref::deref)] value: f64, } @@ -18,7 +18,7 @@ impl From for ordered_float::OrderedFloat { #[rkyv(remote = ordered_float::OrderedFloat, archived = ArchivedF32)] #[rkyv(derive(Debug))] pub struct OrderedF32Def { - #[rkyv(getter = std::ops::Deref::deref)] + #[rkyv(getter = core::ops::Deref::deref)] value: f32, } diff --git a/tests/persistence/space_data.rs b/tests/persistence/space_data.rs index 191c0322..b6015e94 100644 --- a/tests/persistence/space_data.rs +++ b/tests/persistence/space_data.rs @@ -1,4 +1,4 @@ -use std::collections::HashMap; +use worktable::prelude::HashMap; use data_bucket::{INNER_PAGE_SIZE, Link, PAGE_SIZE, parse_general_header_by_index}; use worktable::prelude::{SpaceData, SpaceDataOps};