diff --git a/Cargo.lock b/Cargo.lock index e945dc7..ae1b2c3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -484,26 +484,6 @@ dependencies = [ "syn", ] -[[package]] -name = "thiserror-core" -version = "1.0.50" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c001ee18b7e5e3f62cbf58c7fe220119e68d902bb7443179c0c8aef30090e999" -dependencies = [ - "thiserror-core-impl", -] - -[[package]] -name = "thiserror-core-impl" -version = "1.0.50" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4c60d69f36615a077cc7663b9cb8e42275722d23e58a7fa3d2c7f2915d09d04" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "tracing" version = "0.1.40" @@ -520,36 +500,23 @@ version = "0.1.32" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" -[[package]] -name = "trait-variant" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70977707304198400eb4835a78f6a9f928bf41bba420deb8fdb175cd965d77a7" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "ufotofu" -version = "0.3.0" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90d1fbdc439b2d48e0725dfe321025033d587530e74a1d7924c32e5e9f2d957a" +checksum = "c773ca845a07603d8ebe7292a3cefa20bf41305ce91246332c7fc1e3029eecaa" dependencies = [ "arbitrary", "either", - "thiserror-core", - "trait-variant", "ufotofu_queues", "wrapper", ] [[package]] name = "ufotofu_queues" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5ff287c701ff2a205cbafeaa78d691850ebb7ad91262f052b0495aff4c06d9" +checksum = "d903d5bc0e14d24559dac3b9690d004ad3fb08d66f93d87d28f5cb3466b5b55b" [[package]] name = "unicode-ident" diff --git a/data-model/Cargo.toml b/data-model/Cargo.toml index 39e46e9..b6a1b02 100644 --- a/data-model/Cargo.toml +++ b/data-model/Cargo.toml @@ -10,7 +10,7 @@ dev = ["dep:arbitrary"] [dependencies] either = "1.10.0" arbitrary = { version = "1.0.2", features = ["derive"], optional = true } -ufotofu = "0.3.0" +ufotofu = { version = "0.4.2", features = ["std"] } bytes = "1.6.0" syncify = "0.1.0" diff --git a/data-model/src/encoding/error.rs b/data-model/src/encoding/error.rs index 4e7deed..cec12ce 100644 --- a/data-model/src/encoding/error.rs +++ b/data-model/src/encoding/error.rs @@ -1,6 +1,6 @@ -use core::error::Error; use core::{fmt::Display, fmt::Formatter, num::TryFromIntError}; use either::Either; +use std::error::Error; use ufotofu::common::errors::OverwriteFullSliceError; /// Everything that can go wrong when decoding a value. diff --git a/data-model/src/encoding/relativity.rs b/data-model/src/encoding/relativity.rs index eaaeb0c..c9b433a 100644 --- a/data-model/src/encoding/relativity.rs +++ b/data-model/src/encoding/relativity.rs @@ -22,7 +22,7 @@ pub(super) mod encoding { #[syncify_replace(use crate::encoding::bytes::encoding_sync::produce_byte;)] use crate::encoding::bytes::encoding::produce_byte; - use core::mem::{size_of, MaybeUninit}; + use core::mem::size_of; use crate::{ encoding::{ @@ -121,12 +121,13 @@ pub(super) mod encoding { // Copy the raw path data of the prefix into the scratch buffer. unsafe { // safe because we just copied the accumulated component lengths for the first `lcp_component_count` components. - MaybeUninit::copy_from_slice( - buf.path_data_until_as_mut(lcp_component_count), - &reference.raw_buf()[size_of::() * (reference.get_component_count() + 1) - ..size_of::() * (reference.get_component_count() + 1) - + prefix.get_path_length()], - ); + buf.path_data_until_as_mut(lcp_component_count) + .copy_from_slice( + &reference.raw_buf()[size_of::() + * (reference.get_component_count() + 1) + ..size_of::() * (reference.get_component_count() + 1) + + prefix.get_path_length()], + ); } let remaining_component_count: usize = @@ -152,7 +153,7 @@ pub(super) mod encoding { // Decode the component itself into the scratch buffer. producer - .bulk_overwrite_full_slice_uninit(unsafe { + .bulk_overwrite_full_slice(unsafe { // Safe because we called set_component_Accumulated_length for all j <= i buf.path_data_as_mut(i) }) diff --git a/data-model/src/encoding/shared_buffers.rs b/data-model/src/encoding/shared_buffers.rs index 29d45fe..483df2d 100644 --- a/data-model/src/encoding/shared_buffers.rs +++ b/data-model/src/encoding/shared_buffers.rs @@ -1,7 +1,5 @@ //! Shared buffers to be reused across many decoding operations. -use core::mem::MaybeUninit; - use bytes::BytesMut; use crate::path::Path; @@ -10,15 +8,15 @@ use crate::path::Path; #[derive(Debug)] pub(crate) struct ScratchSpacePathDecoding { // The i-th usize holds the total lengths of the first i components. - component_accumulated_lengths: [MaybeUninit; MCC], - path_data: [MaybeUninit; MPL], + component_accumulated_lengths: [usize; MCC], + path_data: [u8; MPL], } impl ScratchSpacePathDecoding { pub fn new() -> Self { ScratchSpacePathDecoding { - component_accumulated_lengths: MaybeUninit::uninit_array(), - path_data: MaybeUninit::uninit_array(), + component_accumulated_lengths: [0; MCC], + path_data: [0; MPL], } } @@ -28,29 +26,27 @@ impl ScratchSpacePathDecoding { component_accumulated_length: usize, i: usize, ) { - MaybeUninit::write( - &mut self.component_accumulated_lengths[i], - component_accumulated_length, - ); + self.component_accumulated_lengths[i] = component_accumulated_length; } /// # Safety /// /// UB if length of slice is greater than `size_of::() * MCC`. pub unsafe fn set_many_component_accumulated_lengths_from_ne(&mut self, lengths: &[u8]) { - let slice: &mut [MaybeUninit] = core::slice::from_raw_parts_mut( + let slice: &mut [u8] = core::slice::from_raw_parts_mut( self.component_accumulated_lengths[..lengths.len() / size_of::()].as_mut_ptr() - as *mut MaybeUninit, + as *mut u8, lengths.len(), ); - MaybeUninit::copy_from_slice(slice, lengths); + + slice.copy_from_slice(lengths); } /// # Safety /// /// Memory must have been initialised with a prior call to set_component_accumulated_length for the same `i`. unsafe fn get_component_accumulated_length(&self, i: usize) -> usize { - MaybeUninit::assume_init(self.component_accumulated_lengths[i]) + self.component_accumulated_lengths[i] } /// Return a slice of the accumulated component lengths up to but excluding the `i`-th component, encoded as native-endian u8s. @@ -60,8 +56,7 @@ impl ScratchSpacePathDecoding { /// Memory must have been initialised with prior call to set_component_accumulated_length for all `j <= i` pub unsafe fn get_accumumulated_component_lengths(&self, i: usize) -> &[u8] { core::slice::from_raw_parts( - MaybeUninit::slice_assume_init_ref(&self.component_accumulated_lengths[..i]).as_ptr() - as *const u8, + self.component_accumulated_lengths[..i].as_ptr() as *const u8, i * size_of::(), ) } @@ -71,7 +66,7 @@ impl ScratchSpacePathDecoding { /// # Safety /// /// Accumulated component lengths for `i` and `i - 1` must have been set (only for `i` if `i == 0`). - pub unsafe fn path_data_as_mut(&mut self, i: usize) -> &mut [MaybeUninit] { + pub unsafe fn path_data_as_mut(&mut self, i: usize) -> &mut [u8] { let start = if i == 0 { 0 } else { @@ -86,7 +81,7 @@ impl ScratchSpacePathDecoding { /// # Safety /// /// Accumulated component lengths for `i - 1` must have been set (unless `i == 0`). - pub unsafe fn path_data_until_as_mut(&mut self, i: usize) -> &mut [MaybeUninit] { + pub unsafe fn path_data_until_as_mut(&mut self, i: usize) -> &mut [u8] { let end = self.get_component_accumulated_length(i - 1); &mut self.path_data[0..end] } @@ -103,7 +98,7 @@ impl ScratchSpacePathDecoding { } else { self.get_component_accumulated_length(i - 1) }; - return MaybeUninit::slice_assume_init_ref(&self.path_data[..end]); + &self.path_data[..end] } /// Copy the data from this struct into a new Path of `i` components. diff --git a/data-model/src/lib.rs b/data-model/src/lib.rs index ddc8ce0..71548af 100644 --- a/data-model/src/lib.rs +++ b/data-model/src/lib.rs @@ -1,14 +1,5 @@ //! Allo! -#![feature( - new_uninit, - async_fn_traits, - debug_closure_helpers, - maybe_uninit_uninit_array, - maybe_uninit_write_slice, - maybe_uninit_slice -)] - pub mod encoding; mod entry; pub use entry::*; diff --git a/data-model/src/path.rs b/data-model/src/path.rs index 4707103..dcfebee 100644 --- a/data-model/src/path.rs +++ b/data-model/src/path.rs @@ -162,7 +162,7 @@ impl core::fmt::Display for InvalidPathError { } } -impl core::error::Error for InvalidPathError {} +impl std::error::Error for InvalidPathError {} /// An immutable Willow [path](https://willowprotocol.org/specs/data-model/index.html#Path). Thread-safe, cheap to clone, cheap to take prefixes of, expensive to append to. /// @@ -846,7 +846,7 @@ mod encoding { // Decode the component itself into the scratch buffer. producer - .bulk_overwrite_full_slice_uninit(unsafe { + .bulk_overwrite_full_slice(unsafe { // Safe because we called set_component_Accumulated_length for all j <= i buf.path_data_as_mut(i) }) diff --git a/earthstar/Cargo.toml b/earthstar/Cargo.toml index 171cff7..fe52998 100644 --- a/earthstar/Cargo.toml +++ b/earthstar/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" either = "1.10.0" willow-data-model = { path = "../data-model" } arbitrary = { version = "1.0.2", features = ["derive"]} -ufotofu = "0.3.0" +ufotofu = { version = "0.4.2", features = ["std"] } [lints] -workspace = true \ No newline at end of file +workspace = true diff --git a/earthstar/src/cinn25519.rs b/earthstar/src/cinn25519.rs index be3fa3a..87d3fa2 100644 --- a/earthstar/src/cinn25519.rs +++ b/earthstar/src/cinn25519.rs @@ -136,10 +136,10 @@ impl Decodable Producer: BulkProducer, { if MIN_LENGTH == MAX_LENGTH { - let mut shortname_box = Box::new_uninit_slice(MIN_LENGTH); + let mut shortname_box = vec![0; MIN_LENGTH].into_boxed_slice(); - let shortname_bytes = producer - .bulk_overwrite_full_slice_uninit(shortname_box.as_mut()) + producer + .bulk_overwrite_full_slice(shortname_box.as_mut()) .await?; let mut underlying_slice = [0u8; 32]; @@ -149,7 +149,7 @@ impl Decodable .await?; return Ok(Self { - shortname: Shortname(shortname_bytes.to_vec()), + shortname: Shortname(shortname_box.into()), underlying: underlying_slice, }); } diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index 7e9ab60..5931bbd 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -11,7 +11,7 @@ cargo-fuzz = true workspace = true [dependencies] -ufotofu = { version = "0.3.0", features=["dev"]} +ufotofu = { version = "0.4.2", features = ["std", "dev"] } smol = "2.0.0" arbitrary = { version = "1.0.2", features = ["derive"] } libfuzzer-sys = { version = "0.4", features = ["arbitrary-derive"] } diff --git a/fuzz/src/encode.rs b/fuzz/src/encode.rs index a830a0e..38521ee 100644 --- a/fuzz/src/encode.rs +++ b/fuzz/src/encode.rs @@ -26,7 +26,7 @@ where let mut new_vec = Vec::new(); - new_vec.extend_from_slice(consumer.as_ref()); + new_vec.extend_from_slice(consumer.consumed()); // THis should eventually be a testproducer, when we are able to initialise one with some known data. let mut producer = FromBoxedSlice::from_vec(new_vec); @@ -53,7 +53,7 @@ where item.encode(&mut consumer).await.unwrap(); - let encoded = consumer.as_ref().as_slice(); + let encoded = consumer.as_ref(); assert_eq!(encoded, &data[0..producer.get_offset()]); } @@ -133,7 +133,7 @@ pub async fn relative_encoding_roundtrip( let mut new_vec = Vec::new(); - new_vec.extend_from_slice(consumer.as_ref()); + new_vec.extend_from_slice(consumer.consumed()); // THis should eventually be a testproducer, when we are able to initialise one with some known data. let mut producer = FromBoxedSlice::from_vec(new_vec); @@ -164,7 +164,7 @@ where .await .unwrap(); - let encoded = consumer.as_ref().as_slice(); + let encoded = consumer.as_ref(); assert_eq!(encoded, &data[0..producer.get_offset()]); } diff --git a/meadowcap/Cargo.toml b/meadowcap/Cargo.toml index ab84529..1dcf9ab 100644 --- a/meadowcap/Cargo.toml +++ b/meadowcap/Cargo.toml @@ -9,7 +9,7 @@ dev = ["dep:arbitrary"] [dependencies] signature = "2.2.0" -ufotofu = "0.3.0" +ufotofu = { version = "0.4.2", features = ["std"] } arbitrary = { version = "1.0.2", features = ["derive"], optional = true } either = "1.13.0" syncify = "0.1.0"