Skip to content

Commit

Permalink
Upgrade deps
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Saveau <[email protected]>
  • Loading branch information
SUPERCILEX committed Sep 22, 2023
1 parent aecfdeb commit 3d0f5d8
Show file tree
Hide file tree
Showing 13 changed files with 311 additions and 415 deletions.
584 changes: 239 additions & 345 deletions Cargo.lock

Large diffs are not rendered by default.

34 changes: 18 additions & 16 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,44 @@ categories = ["command-line-utilities", "development-tools", "development-tools:
license = "Apache-2.0"

[dependencies]
bytesize = "1.2.0"
bytesize = "1.3.0"
cfg-if = "1.0.0"
clap = { version = "4.3.9", features = ["derive", "wrap_help"] }
clap = { version = "4.4.4", features = ["derive", "wrap_help"] }
clap-num = "1.0.2"
clap-verbosity-flag = "2.0.1"
error-stack = "0.3.1"
# TODO use the real itoa once https://github.com/dtolnay/itoa/pull/34 goes through
itoa-const = "1.0.5"
log = { version = "0.4.19", features = ["release_max_level_info"] }
paste = "1.0.12"
error-stack = "0.4.1"
itoa = "1.0.9"
log = { version = "0.4.20", features = ["release_max_level_info"] }
paste = "1.0.14"
rand = { version = "0.8.5", default-features = false, features = ["std"] }
rand_distr = "0.4.3"
rand_xoshiro = "0.6.0"
simple_logger = { version = "4.2.0", default-features = false, features = ["colors"] }
sysexits = "0.6.1"
thiserror = "1.0.40"
sysexits = "0.7.2"
thiserror = "1.0.48"
thousands = "0.2.0"
tokio = { version = "1.29.0", features = ["rt"] }
tokio = { version = "1.32.0", features = ["rt"] }
tracing = { version = "0.1.37", features = ["release_max_level_off", "log"], optional = true }
tracing-chrome = { version = "0.7.1", optional = true }
tracing-subscriber = { version = "0.3.17", optional = true }
typed-builder = "0.14.0"
typed-builder = "0.16.2"

[target.'cfg(unix)'.dependencies]
rustix = { version = "0.38.0", features = ["fs"] }
rustix = { version = "0.38.14", features = ["fs"] }

[dev-dependencies]
criterion = "0.5.1"
expect-test = "1.4.1"
more-asserts = "0.3.1"
rand = { version = "0.8.5", default-features = false, features = ["std", "std_rng"] }
rstest = { version = "0.17.0", default-features = false }
rstest = { version = "0.18.2", default-features = false }
seahash = "4.1.0"
supercilex-tests = "0.3.3"
tempfile = "3.6.0"
trycmd = "0.14.16"
supercilex-tests = "0.3.4"
tempfile = "3.8.0"
trycmd = "0.14.17"

[build-dependencies]
itoa = "1.0.9"

[features]
trace = ["tracing", "tracing-chrome", "tracing-subscriber"]
Expand Down
28 changes: 17 additions & 11 deletions api.golden
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ impl core::marker::Unpin for ftzz::generator::Error
impl core::panic::unwind_safe::RefUnwindSafe for ftzz::generator::Error
impl core::panic::unwind_safe::UnwindSafe for ftzz::generator::Error
impl<C> error_stack::context::Context for ftzz::generator::Error where C: core::error::Error + core::marker::Send + core::marker::Sync + 'static
pub fn ftzz::generator::Error::provide<'a>(&'a self, demand: &mut core::any::Demand<'a>)
impl<E> core::any::Provider for ftzz::generator::Error where E: core::error::Error + core::marker::Sized
pub fn ftzz::generator::Error::provide<'a>(&'a self, demand: &mut core::any::Demand<'a>)
pub fn ftzz::generator::Error::provide<'a>(&'a self, request: &mut core::error::Request<'a>)
impl<T, U> core::convert::Into<U> for ftzz::generator::Error where U: core::convert::From<T>
pub fn ftzz::generator::Error::into(self) -> U
impl<T, U> core::convert::TryFrom<U> for ftzz::generator::Error where U: core::convert::Into<T>
Expand All @@ -41,6 +39,8 @@ impl<T> thousands::traits::Separable for ftzz::generator::Error where T: core::f
pub fn ftzz::generator::Error::separate_by_policy(&self, policy: thousands::policies::SeparatorPolicy<'_>) -> alloc::string::String
impl<T> tracing::instrument::Instrument for ftzz::generator::Error
impl<T> tracing::instrument::WithSubscriber for ftzz::generator::Error
impl<V, T> ppv_lite86::types::VZip<V> for ftzz::generator::Error where V: ppv_lite86::types::MultiLane<T>
pub fn ftzz::generator::Error::vzip(self) -> V
pub enum ftzz::generator::NumFilesWithRatioError
pub ftzz::generator::NumFilesWithRatioError::InvalidRatio
pub ftzz::generator::NumFilesWithRatioError::InvalidRatio::file_to_dir_ratio: core::num::nonzero::NonZeroU64
Expand All @@ -56,9 +56,7 @@ impl core::marker::Unpin for ftzz::generator::NumFilesWithRatioError
impl core::panic::unwind_safe::RefUnwindSafe for ftzz::generator::NumFilesWithRatioError
impl core::panic::unwind_safe::UnwindSafe for ftzz::generator::NumFilesWithRatioError
impl<C> error_stack::context::Context for ftzz::generator::NumFilesWithRatioError where C: core::error::Error + core::marker::Send + core::marker::Sync + 'static
pub fn ftzz::generator::NumFilesWithRatioError::provide<'a>(&'a self, demand: &mut core::any::Demand<'a>)
impl<E> core::any::Provider for ftzz::generator::NumFilesWithRatioError where E: core::error::Error + core::marker::Sized
pub fn ftzz::generator::NumFilesWithRatioError::provide<'a>(&'a self, demand: &mut core::any::Demand<'a>)
pub fn ftzz::generator::NumFilesWithRatioError::provide<'a>(&'a self, request: &mut core::error::Request<'a>)
impl<T, U> core::convert::Into<U> for ftzz::generator::NumFilesWithRatioError where U: core::convert::From<T>
pub fn ftzz::generator::NumFilesWithRatioError::into(self) -> U
impl<T, U> core::convert::TryFrom<U> for ftzz::generator::NumFilesWithRatioError where U: core::convert::Into<T>
Expand All @@ -81,13 +79,15 @@ impl<T> thousands::traits::Separable for ftzz::generator::NumFilesWithRatioError
pub fn ftzz::generator::NumFilesWithRatioError::separate_by_policy(&self, policy: thousands::policies::SeparatorPolicy<'_>) -> alloc::string::String
impl<T> tracing::instrument::Instrument for ftzz::generator::NumFilesWithRatioError
impl<T> tracing::instrument::WithSubscriber for ftzz::generator::NumFilesWithRatioError
impl<V, T> ppv_lite86::types::VZip<V> for ftzz::generator::NumFilesWithRatioError where V: ppv_lite86::types::MultiLane<T>
pub fn ftzz::generator::NumFilesWithRatioError::vzip(self) -> V
pub struct ftzz::generator::Generator
impl ftzz::generator::Generator
pub fn ftzz::generator::Generator::builder() -> ftzz::generator::GeneratorBuilder<((), (), (), (), (), (), (), ())>
impl ftzz::generator::Generator
pub fn ftzz::generator::Generator::generate(self, output: &mut impl core::fmt::Write) -> error_stack::result::Result<(), ftzz::generator::Error>
impl core::fmt::Debug for ftzz::generator::Generator
pub fn ftzz::generator::Generator::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
impl ftzz::generator::Generator
pub fn ftzz::generator::Generator::builder() -> ftzz::generator::GeneratorBuilder<((), (), (), (), (), (), (), ())>
impl core::marker::Send for ftzz::generator::Generator
impl core::marker::Sync for ftzz::generator::Generator
impl core::marker::Unpin for ftzz::generator::Generator
Expand All @@ -111,8 +111,12 @@ impl<T> core::convert::From<T> for ftzz::generator::Generator
pub fn ftzz::generator::Generator::from(t: T) -> T
impl<T> tracing::instrument::Instrument for ftzz::generator::Generator
impl<T> tracing::instrument::WithSubscriber for ftzz::generator::Generator
impl<V, T> ppv_lite86::types::VZip<V> for ftzz::generator::Generator where V: ppv_lite86::types::MultiLane<T>
pub fn ftzz::generator::Generator::vzip(self) -> V
pub struct ftzz::generator::GeneratorBuilder<TypedBuilderFields>
impl<__files_exact: GeneratorBuilder_Optional<bool>, __num_bytes: GeneratorBuilder_Optional<u64>, __fill_byte: GeneratorBuilder_Optional<core::option::Option<u8>>, __bytes_exact: GeneratorBuilder_Optional<bool>, __max_depth: GeneratorBuilder_Optional<u32>, __seed: GeneratorBuilder_Optional<u64>> ftzz::generator::GeneratorBuilder<((std::path::PathBuf), (ftzz::generator::NumFilesWithRatio), __files_exact, __num_bytes, __fill_byte, __bytes_exact, __max_depth, __seed)>
impl<TypedBuilderFields> core::clone::Clone for ftzz::generator::GeneratorBuilder<TypedBuilderFields> where TypedBuilderFields: core::clone::Clone
pub fn ftzz::generator::GeneratorBuilder<TypedBuilderFields>::clone(&self) -> Self
impl<__files_exact: typed_builder::Optional<bool>, __num_bytes: typed_builder::Optional<u64>, __fill_byte: typed_builder::Optional<core::option::Option<u8>>, __bytes_exact: typed_builder::Optional<bool>, __max_depth: typed_builder::Optional<u32>, __seed: typed_builder::Optional<u64>> ftzz::generator::GeneratorBuilder<((std::path::PathBuf), (ftzz::generator::NumFilesWithRatio), __files_exact, __num_bytes, __fill_byte, __bytes_exact, __max_depth, __seed)>
pub fn ftzz::generator::GeneratorBuilder<((std::path::PathBuf), (ftzz::generator::NumFilesWithRatio), __files_exact, __num_bytes, __fill_byte, __bytes_exact, __max_depth, __seed)>::build(self) -> ftzz::generator::Generator
impl<__num_files_with_ratio, __files_exact, __num_bytes, __fill_byte, __bytes_exact, __max_depth, __seed> ftzz::generator::GeneratorBuilder<((), __num_files_with_ratio, __files_exact, __num_bytes, __fill_byte, __bytes_exact, __max_depth, __seed)>
pub fn ftzz::generator::GeneratorBuilder<((), __num_files_with_ratio, __files_exact, __num_bytes, __fill_byte, __bytes_exact, __max_depth, __seed)>::root_dir(self, root_dir: std::path::PathBuf) -> ftzz::generator::GeneratorBuilder<((std::path::PathBuf), __num_files_with_ratio, __files_exact, __num_bytes, __fill_byte, __bytes_exact, __max_depth, __seed)>
Expand All @@ -130,8 +134,6 @@ impl<__root_dir, __num_files_with_ratio, __files_exact, __num_bytes, __fill_byte
pub fn ftzz::generator::GeneratorBuilder<(__root_dir, __num_files_with_ratio, __files_exact, __num_bytes, __fill_byte, (), __max_depth, __seed)>::bytes_exact(self, bytes_exact: bool) -> ftzz::generator::GeneratorBuilder<(__root_dir, __num_files_with_ratio, __files_exact, __num_bytes, __fill_byte, (bool), __max_depth, __seed)>
impl<__root_dir, __num_files_with_ratio, __num_bytes, __fill_byte, __bytes_exact, __max_depth, __seed> ftzz::generator::GeneratorBuilder<(__root_dir, __num_files_with_ratio, (), __num_bytes, __fill_byte, __bytes_exact, __max_depth, __seed)>
pub fn ftzz::generator::GeneratorBuilder<(__root_dir, __num_files_with_ratio, (), __num_bytes, __fill_byte, __bytes_exact, __max_depth, __seed)>::files_exact(self, files_exact: bool) -> ftzz::generator::GeneratorBuilder<(__root_dir, __num_files_with_ratio, (bool), __num_bytes, __fill_byte, __bytes_exact, __max_depth, __seed)>
impl<TypedBuilderFields> core::clone::Clone for ftzz::generator::GeneratorBuilder<TypedBuilderFields> where TypedBuilderFields: core::clone::Clone
pub fn ftzz::generator::GeneratorBuilder<TypedBuilderFields>::clone(&self) -> Self
impl<TypedBuilderFields> core::marker::Send for ftzz::generator::GeneratorBuilder<TypedBuilderFields> where TypedBuilderFields: core::marker::Send
impl<TypedBuilderFields> core::marker::Sync for ftzz::generator::GeneratorBuilder<TypedBuilderFields> where TypedBuilderFields: core::marker::Sync
impl<TypedBuilderFields> core::marker::Unpin for ftzz::generator::GeneratorBuilder<TypedBuilderFields> where TypedBuilderFields: core::marker::Unpin
Expand Down Expand Up @@ -159,6 +161,8 @@ impl<T> core::convert::From<T> for ftzz::generator::GeneratorBuilder<TypedBuilde
pub fn ftzz::generator::GeneratorBuilder<TypedBuilderFields>::from(t: T) -> T
impl<T> tracing::instrument::Instrument for ftzz::generator::GeneratorBuilder<TypedBuilderFields>
impl<T> tracing::instrument::WithSubscriber for ftzz::generator::GeneratorBuilder<TypedBuilderFields>
impl<V, T> ppv_lite86::types::VZip<V> for ftzz::generator::GeneratorBuilder<TypedBuilderFields> where V: ppv_lite86::types::MultiLane<T>
pub fn ftzz::generator::GeneratorBuilder<TypedBuilderFields>::vzip(self) -> V
pub struct ftzz::generator::NumFilesWithRatio
impl ftzz::generator::NumFilesWithRatio
pub fn ftzz::generator::NumFilesWithRatio::from_num_files(num_files: core::num::nonzero::NonZeroU64) -> Self
Expand Down Expand Up @@ -188,3 +192,5 @@ impl<T> core::convert::From<T> for ftzz::generator::NumFilesWithRatio
pub fn ftzz::generator::NumFilesWithRatio::from(t: T) -> T
impl<T> tracing::instrument::Instrument for ftzz::generator::NumFilesWithRatio
impl<T> tracing::instrument::WithSubscriber for ftzz::generator::NumFilesWithRatio
impl<V, T> ppv_lite86::types::VZip<V> for ftzz::generator::NumFilesWithRatio where V: ppv_lite86::types::MultiLane<T>
pub fn ftzz::generator::NumFilesWithRatio::vzip(self) -> V
1 change: 0 additions & 1 deletion benches/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ fn dense_generate(c: &mut Criterion) {
b.iter_with_large_drop(|| {
let dir = tempdir().unwrap();

let num_files = num_files;
Generator::builder()
.root_dir(dir.path().to_path_buf())
.num_files_with_ratio(
Expand Down
21 changes: 21 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use std::{fs::File, io::Write, ptr};

const MAX_CACHE_SIZE: usize = 1000;

fn main() {
let out_dir = std::env::var("OUT_DIR").unwrap();
let mut cache = File::create(format!("{out_dir}/file_name_cache.bin")).unwrap();

let mut buf = [0u8; 3000];
let mut num_buf = itoa::Buffer::new();

let buf_ptr = buf.as_mut_ptr().cast::<u8>();
for i in 0..MAX_CACHE_SIZE {
let bytes = num_buf.format(i).as_bytes();
unsafe {
ptr::copy_nonoverlapping(bytes.as_ptr(), buf_ptr.add(i * 3), bytes.len());
}
}

cache.write_all(&buf).unwrap();
}
4 changes: 2 additions & 2 deletions src/core/file_contents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl FileContentsGenerator for NoGeneratedFileContents {
0,
)
.map_err(io::Error::from)
.map(|_| 0)
.map(|()| 0)
} else {
use rustix::fs::{openat, OFlags, Mode};

Expand Down Expand Up @@ -142,7 +142,7 @@ impl<R: RngCore + 'static> FileContentsGenerator for PreDefinedGeneratedFileCont
if num_bytes > 0 {
File::create(file)
.and_then(|f| write_bytes(f, num_bytes, (fill_byte, random)))
.map(|_| num_bytes)
.map(|()| num_bytes)
} else {
NoGeneratedFileContents.create_file(file, file_num, retryable)
}
Expand Down
5 changes: 1 addition & 4 deletions src/core/files.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{fs::create_dir_all, io, io::ErrorKind::NotFound};

use error_stack::{IntoReport, Report, Result, ResultExt};
use error_stack::{Report, Result, ResultExt};

use crate::{
core::file_contents::FileContentsGenerator,
Expand Down Expand Up @@ -56,7 +56,6 @@ fn create_dirs(num_dirs: usize, dir: &mut FastPathBuf) -> Result<(), io::Error>
with_dir_name(i, |s| dir.push(s));

create_dir_all(&dir)
.into_report()
.attach_printable_lazy(|| format!("Failed to create directory {dir:?}"))?;

dir.pop();
Expand Down Expand Up @@ -93,7 +92,6 @@ fn create_files(

file.pop();
create_dir_all(&file)
.into_report()
.attach_printable_lazy(|| format!("Failed to create directory {file:?}"))?;
} else {
return Err(Report::new(e))
Expand All @@ -107,7 +105,6 @@ fn create_files(

bytes_written += contents
.create_file(file, i.try_into().unwrap_or(usize::MAX), false)
.into_report()
.attach_printable_lazy(|| format!("Failed to create file {file:?}"))?;

file.pop();
Expand Down
10 changes: 5 additions & 5 deletions src/core/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{
result,
};

use error_stack::{IntoReport, Result, ResultExt};
use error_stack::{Result, ResultExt};
use rand_distr::Normal;
use tokio::task::{JoinError, JoinHandle};

Expand Down Expand Up @@ -147,9 +147,10 @@ pub async fn run(
}) = scheduler.stack.last_mut()
{
let Some(DirChild {
files: target_file_count,
dirs: num_dirs_to_generate,
}) = child_dir_counts.pop() else {
files: target_file_count,
dirs: num_dirs_to_generate,
}) = child_dir_counts.pop()
else {
handle_directory_completion(&mut scheduler);
continue;
};
Expand Down Expand Up @@ -236,7 +237,6 @@ fn handle_task_result(
) -> Result<GeneratorTaskOutcome, Error> {
#[cfg(not(feature = "dry_run"))]
let outcome = task_result
.into_report()
.change_context(Error::TaskJoin)
.attach(ExitCode::from(sysexits::ExitCode::Software))?
.change_context(Error::Io)
Expand Down
6 changes: 1 addition & 5 deletions src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::{
thread,
};

use error_stack::{IntoReport, Report, Result, ResultExt};
use error_stack::{Report, Result, ResultExt};
use log::{log, Level};
use rand::SeedableRng;
use rand_xoshiro::Xoshiro256PlusPlus;
Expand Down Expand Up @@ -184,13 +184,11 @@ fn validated_options(
}: Generator,
) -> Result<Configuration, Error> {
create_dir_all(&root_dir)
.into_report()
.attach_printable_lazy(|| format!("Failed to create directory {root_dir:?}"))
.change_context(Error::InvalidEnvironment)
.attach(ExitCode::from(sysexits::ExitCode::IoErr))?;
if root_dir
.read_dir()
.into_report()
.attach_printable_lazy(|| format!("Failed to read directory {root_dir:?}"))
.change_context(Error::InvalidEnvironment)
.attach(ExitCode::from(sysexits::ExitCode::IoErr))?
Expand Down Expand Up @@ -315,7 +313,6 @@ fn print_configuration_info(
String::new()
},
)
.into_report()
.attach_printable("Failed to write to output stream")
.change_context(Error::Io)
.attach(ExitCode::from(sysexits::ExitCode::IoErr))
Expand Down Expand Up @@ -350,7 +347,6 @@ fn run_generator(config: Configuration) -> Result<GeneratorStats, Error> {
let runtime = tokio::runtime::Builder::new_current_thread()
.max_blocking_threads(parallelism.get())
.build()
.into_report()
.change_context(Error::RuntimeCreation)
.attach(ExitCode::from(sysexits::ExitCode::OsErr))?;

Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(const_trait_impl)]
#![feature(const_mut_refs)]
#![feature(let_chains)]
#![feature(const_option)]
#![feature(inline_const)]
Expand Down
3 changes: 1 addition & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::{
use clap::{builder::ArgPredicate, ArgAction, Args, Parser, Subcommand, ValueHint};
use clap_num::si_number;
use clap_verbosity_flag::Verbosity;
use error_stack::{IntoReport, ResultExt};
use error_stack::ResultExt;
use ftzz::generator::{Generator, NumFilesWithRatio, NumFilesWithRatioError};
use paste::paste;

Expand Down Expand Up @@ -243,7 +243,6 @@ fn ftzz(
let mut stdout = stdout();
match cmd {
Cmd::Generate(options) => Generator::try_from(options)
.into_report()
.change_context(CliError::InvalidArgs)?
.generate(&mut fmt_adapter::FmtWriteAdapter::from(&mut stdout))
.change_context(CliError::Generator),
Expand Down
26 changes: 4 additions & 22 deletions src/utils/file_names.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use std::{mem::MaybeUninit, ptr, slice};

use itoa_const as itoa;

struct FileNameCache {
cache: [MaybeUninit<u8>; 3000],
cache: &'static [u8],
}

/// Specialized cache for file names that takes advantage of our monotonically
Expand All @@ -19,28 +17,12 @@ struct FileNameCache {
/// with the binary.
impl FileNameCache {
const fn new() -> Self {
let mut buf = [MaybeUninit::<u8>::uninit(); 3000];
let mut num_buf = itoa::Buffer::new();

let buf_ptr = buf.as_mut_ptr().cast::<u8>();
// TODO use for loop once possible
let mut i = 0;
while i < Self::max_cache_size() {
let bytes = num_buf.format(i).as_bytes();
unsafe {
ptr::copy_nonoverlapping(
bytes.as_ptr(),
buf_ptr.add((i * 3) as usize),
bytes.len(),
);
}
i += 1;
Self {
cache: include_bytes!(concat!(env!("OUT_DIR"), "/file_name_cache.bin")),
}

Self { cache: buf }
}

const fn with_file_name<T, F: ~const FnOnce(&str) -> T>(&self, i: u16, f: F) -> T {
fn with_file_name<T, F: FnOnce(&str) -> T>(&self, i: u16, f: F) -> T {
debug_assert!(i < Self::max_cache_size());
f(unsafe {
std::str::from_utf8_unchecked(slice::from_raw_parts(
Expand Down
2 changes: 2 additions & 0 deletions tests/generator.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::items_after_test_module)]

use std::{
cmp::{max, min},
collections::VecDeque,
Expand Down

0 comments on commit 3d0f5d8

Please sign in to comment.