From 56f1a3353e1429c7a74c1ea957e86c4ebea68ba3 Mon Sep 17 00:00:00 2001 From: Artem Storozhuk Date: Mon, 30 May 2022 16:38:55 +0300 Subject: [PATCH 1/3] Bump required toolchain version to 1.59.0 --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index 3ebf789f5..bb120e876 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -1.56.0 +1.59.0 From 772d33fdcc47624105f177d0a5e4014f16e4306a Mon Sep 17 00:00:00 2001 From: Artem Storozhuk Date: Mon, 30 May 2022 17:38:41 +0300 Subject: [PATCH 2/3] Fix clippy errors on CI (Linux) --- fil-proofs-param/src/bin/fakeipfsadd.rs | 2 - fil-proofs-param/src/bin/parampublish.rs | 2 +- fil-proofs-param/src/bin/srspublish.rs | 10 +-- fil-proofs-param/tests/paramfetch/session.rs | 71 ++++++++++--------- .../tests/parampublish/support/session.rs | 44 ++++++------ fil-proofs-param/tests/support/mod.rs | 1 - .../src/bin/check_parameters/main.rs | 2 +- .../src/bin/gpu-cpu-test/main.rs | 1 + filecoin-hashers/src/poseidon.rs | 8 +-- filecoin-proofs/tests/pieces.rs | 4 +- sha2raw/src/sha256_intrinsics.rs | 10 +-- storage-proofs-core/src/util.rs | 3 +- storage-proofs-porep/src/lib.rs | 1 + .../src/stacked/vanilla/cache.rs | 2 +- .../src/stacked/vanilla/create_label/multi.rs | 10 +-- .../src/stacked/vanilla/proof.rs | 4 +- .../src/stacked/vanilla/utils.rs | 21 +++--- 17 files changed, 90 insertions(+), 106 deletions(-) diff --git a/fil-proofs-param/src/bin/fakeipfsadd.rs b/fil-proofs-param/src/bin/fakeipfsadd.rs index 925cb58b0..63472c49b 100644 --- a/fil-proofs-param/src/bin/fakeipfsadd.rs +++ b/fil-proofs-param/src/bin/fakeipfsadd.rs @@ -16,8 +16,6 @@ enum Cli { Add { #[structopt(help = "Positional argument for the path to the file to add.")] file_path: String, - #[structopt(short = "Q", help = "Simulates the -Q argument to `ipfs add`.")] - quieter: bool, }, } diff --git a/fil-proofs-param/src/bin/parampublish.rs b/fil-proofs-param/src/bin/parampublish.rs index 7c9a9658b..07c198cfa 100644 --- a/fil-proofs-param/src/bin/parampublish.rs +++ b/fil-proofs-param/src/bin/parampublish.rs @@ -105,7 +105,7 @@ fn get_filenames_in_cache_dir() -> Vec { fn publish_file(ipfs_bin: &str, filename: &str) -> Result { let path = get_full_path_for_file_within_cache(filename); let output = Command::new(ipfs_bin) - .args(&["add", "-Q", path.to_str().unwrap()]) + .args(&["add", path.to_str().unwrap()]) .output() .expect("failed to run ipfs subprocess"); stderr() diff --git a/fil-proofs-param/src/bin/srspublish.rs b/fil-proofs-param/src/bin/srspublish.rs index 9ebf8e739..295e70537 100644 --- a/fil-proofs-param/src/bin/srspublish.rs +++ b/fil-proofs-param/src/bin/srspublish.rs @@ -77,7 +77,7 @@ fn get_filenames_in_cache_dir() -> Vec { fn publish_file(ipfs_bin: &str, filename: &str) -> Result { let path = get_full_path_for_file_within_cache(filename); let output = Command::new(ipfs_bin) - .args(&["add", "-Q", path.to_str().unwrap()]) + .args(&["add", path.to_str().unwrap()]) .output() .expect("failed to run ipfs subprocess"); stderr() @@ -102,14 +102,6 @@ fn write_param_map_to_disk(param_map: &ParameterMap, json_path: &str) -> Result< #[derive(Debug, StructOpt)] #[structopt(name = "srspublish", version = "1.0", about = CLI_ABOUT.as_str())] struct Cli { - #[structopt( - long = "list-all", - short = "a", - help = "The user will be prompted to select the files to publish from the set of all files \ - found in the cache dir. Excluding the -a/--list-all flag will result in the user being \ - prompted for a single param version number for filtering-in files in the cache dir." - )] - list_all_files: bool, #[structopt( long = "ipfs-bin", value_name = "PATH TO IPFS BINARY", diff --git a/fil-proofs-param/tests/paramfetch/session.rs b/fil-proofs-param/tests/paramfetch/session.rs index f41d14536..f54e7354f 100644 --- a/fil-proofs-param/tests/paramfetch/session.rs +++ b/fil-proofs-param/tests/paramfetch/session.rs @@ -63,42 +63,47 @@ impl ParamFetchSessionBuilder { /// Launch paramfetch in an environment configured by the builder. pub fn build(self) -> ParamFetchSession { - let mut p = spawn_bash_with_retries(10, Some(self.session_timeout_ms)) - .unwrap_or_else(|err| panic_any(err)); - - let cache_dir_path = format!("{:?}", self.cache_dir.path()); - - let paramfetch_path = cargo_bin("paramfetch"); - - let whitelist: String = self - .whitelisted_sector_sizes - .map(|wl| { - let mut s = "--sector-sizes=".to_string(); - s.push_str(&wl.join(",")); - s - }) - .unwrap_or_else(|| "".to_string()); - - let json_argument = if self.manifest.is_some() { - format!("--json={:?}", self.manifest.expect("missing manifest")) - } else { - "".to_string() + let session = match spawn_bash_with_retries(10, Some(self.session_timeout_ms)) { + Err(e) => panic_any(e), + Ok(mut session) => { + let cache_dir_path = format!("{:?}", self.cache_dir.path()); + + let paramfetch_path = cargo_bin("paramfetch"); + + let whitelist: String = self + .whitelisted_sector_sizes + .map(|wl| { + let mut s = "--sector-sizes=".to_string(); + s.push_str(&wl.join(",")); + s + }) + .unwrap_or_else(|| "".to_string()); + + let json_argument = if self.manifest.is_some() { + format!("--json={:?}", self.manifest.expect("missing manifest")) + } else { + "".to_string() + }; + + let cmd = format!( + "{}={} {:?} {} {} {}", + "FIL_PROOFS_PARAMETER_CACHE", // related to var name in core/src/settings.rs + cache_dir_path, + paramfetch_path, + if self.prompt_enabled { "" } else { "--all" }, + json_argument, + whitelist, + ); + + session + .execute(&cmd, ".*") + .expect("could not execute paramfetch"); + session + } }; - let cmd = format!( - "{}={} {:?} {} {} {}", - "FIL_PROOFS_PARAMETER_CACHE", // related to var name in core/src/settings.rs - cache_dir_path, - paramfetch_path, - if self.prompt_enabled { "" } else { "--all" }, - json_argument, - whitelist, - ); - - p.execute(&cmd, ".*").expect("could not execute paramfetch"); - ParamFetchSession { - pty_session: p, + pty_session: session, _cache_dir: self.cache_dir, } } diff --git a/fil-proofs-param/tests/parampublish/support/session.rs b/fil-proofs-param/tests/parampublish/support/session.rs index 36d581891..7a5e7f4d5 100644 --- a/fil-proofs-param/tests/parampublish/support/session.rs +++ b/fil-proofs-param/tests/parampublish/support/session.rs @@ -116,10 +116,29 @@ impl ParamPublishSessionBuilder { /// Launch parampublish in an environment configured by the builder. pub fn build(self) -> (ParamPublishSession, Vec) { - let mut p = spawn_bash_with_retries(10, Some(self.session_timeout_ms)) - .unwrap_or_else(|err| panic_any(err)); - - let cache_dir_path = format!("{:?}", self.cache_dir.path()); + let session = match spawn_bash_with_retries(10, Some(self.session_timeout_ms)) { + Err(err) => panic_any(err), + Ok(mut session) => { + let cache_dir_path = format!("{:?}", self.cache_dir.path()); + + let parampublish_path = cargo_bin("parampublish"); + + let cmd = format!( + "{}={} {:?} {} --ipfs-bin={:?} --json={:?}", + "FIL_PROOFS_PARAMETER_CACHE", // related to var name in core/src/settings.rs + cache_dir_path, + parampublish_path, + if self.list_all_files { "-a" } else { "" }, + self.ipfs_bin_path, + self.manifest + ); + + session + .execute(&cmd, ".*") + .expect("could not execute parampublish"); + session + } + }; let cache_contents: Vec = read_dir(&self.cache_dir) .unwrap_or_else(|_| panic_any(format!("failed to read cache dir {:?}", self.cache_dir))) @@ -127,24 +146,9 @@ impl ParamPublishSessionBuilder { .map(|x| x.path()) .collect(); - let parampublish_path = cargo_bin("parampublish"); - - let cmd = format!( - "{}={} {:?} {} --ipfs-bin={:?} --json={:?}", - "FIL_PROOFS_PARAMETER_CACHE", // related to var name in core/src/settings.rs - cache_dir_path, - parampublish_path, - if self.list_all_files { "-a" } else { "" }, - self.ipfs_bin_path, - self.manifest - ); - - p.execute(&cmd, ".*") - .expect("could not execute parampublish"); - ( ParamPublishSession { - pty_session: p, + pty_session: session, _cache_dir: self.cache_dir, }, cache_contents, diff --git a/fil-proofs-param/tests/support/mod.rs b/fil-proofs-param/tests/support/mod.rs index 6f663f626..4386db27a 100644 --- a/fil-proofs-param/tests/support/mod.rs +++ b/fil-proofs-param/tests/support/mod.rs @@ -25,7 +25,6 @@ impl FakeIpfsBin { pub fn compute_checksum>(&self, path: P) -> Result { let output = Command::new(&self.bin_path) .arg("add") - .arg("-Q") .arg(path.as_ref()) .output()?; diff --git a/fil-proofs-tooling/src/bin/check_parameters/main.rs b/fil-proofs-tooling/src/bin/check_parameters/main.rs index 99773de69..3f69ff6c8 100644 --- a/fil-proofs-tooling/src/bin/check_parameters/main.rs +++ b/fil-proofs-tooling/src/bin/check_parameters/main.rs @@ -8,7 +8,7 @@ use clap::{Arg, Command}; use storage_proofs_core::parameter_cache::read_cached_params; fn run_map(parameter_file: &Path) -> Result> { - read_cached_params(¶meter_file.to_path_buf()) + read_cached_params(parameter_file) } fn main() { diff --git a/fil-proofs-tooling/src/bin/gpu-cpu-test/main.rs b/fil-proofs-tooling/src/bin/gpu-cpu-test/main.rs index 1de4a8013..4dcee8192 100644 --- a/fil-proofs-tooling/src/bin/gpu-cpu-test/main.rs +++ b/fil-proofs-tooling/src/bin/gpu-cpu-test/main.rs @@ -56,6 +56,7 @@ impl FromStr for Mode { } #[derive(Debug)] +#[allow(dead_code)] pub struct RunInfo { elapsed: Duration, iterations: u8, diff --git a/filecoin-hashers/src/poseidon.rs b/filecoin-hashers/src/poseidon.rs index 86c69b30b..aa29b08cc 100644 --- a/filecoin-hashers/src/poseidon.rs +++ b/filecoin-hashers/src/poseidon.rs @@ -56,7 +56,7 @@ impl Hashable for PoseidonDomain { } } -#[derive(Copy, Clone, Debug, Serialize, Deserialize)] +#[derive(Default, Copy, Clone, Debug, Serialize, Deserialize)] pub struct PoseidonDomain(pub ::Repr); impl AsRef for PoseidonDomain { @@ -79,12 +79,6 @@ impl PartialEq for PoseidonDomain { impl Eq for PoseidonDomain {} -impl Default for PoseidonDomain { - fn default() -> PoseidonDomain { - PoseidonDomain(::Repr::default()) - } -} - impl Ord for PoseidonDomain { #[inline(always)] fn cmp(&self, other: &PoseidonDomain) -> Ordering { diff --git a/filecoin-proofs/tests/pieces.rs b/filecoin-proofs/tests/pieces.rs index 858af5b1f..3d50c5232 100644 --- a/filecoin-proofs/tests/pieces.rs +++ b/filecoin-proofs/tests/pieces.rs @@ -64,9 +64,7 @@ fn test_get_piece_alignment() { (300, 300, (208, 208)), ]; - for (bytes_in_sector, bytes_in_piece, (expected_left_align, expected_right_align)) in - table.clone() - { + for (bytes_in_sector, bytes_in_piece, (expected_left_align, expected_right_align)) in table { let PieceAlignment { left_bytes: UnpaddedBytesAmount(actual_left_align), right_bytes: UnpaddedBytesAmount(actual_right_align), diff --git a/sha2raw/src/sha256_intrinsics.rs b/sha2raw/src/sha256_intrinsics.rs index 27a4c9ba2..17ab2ba8c 100644 --- a/sha2raw/src/sha256_intrinsics.rs +++ b/sha2raw/src/sha256_intrinsics.rs @@ -18,11 +18,7 @@ use x86::{ pub unsafe fn compress256(state: &mut [u32; 8], blocks: &[&[u8]]) { assert_eq!(blocks.len() % 2, 0); - let mut state0: __m128i; - let mut state1: __m128i; - let mut msg: __m128i; - let mut tmp: __m128i; let mut msg0: __m128i; let mut msg1: __m128i; @@ -39,12 +35,12 @@ pub unsafe fn compress256(state: &mut [u32; 8], blocks: &[&[u8]]) { ); // Load initial values - tmp = _mm_loadu_si128(state.as_ptr().add(0) as *const __m128i); - state1 = _mm_loadu_si128(state.as_ptr().add(4) as *const __m128i); + let mut tmp = _mm_loadu_si128(state.as_ptr().add(0) as *const __m128i); + let mut state1 = _mm_loadu_si128(state.as_ptr().add(4) as *const __m128i); tmp = _mm_shuffle_epi32(tmp, 0xB1); // CDAB state1 = _mm_shuffle_epi32(state1, 0x1B); // EFGH - state0 = _mm_alignr_epi8(tmp, state1, 8); // ABEF + let mut state0 = _mm_alignr_epi8(tmp, state1, 8); // ABEF state1 = _mm_blend_epi16(state1, tmp, 0xF0); // CDGH for i in (0..blocks.len()).step_by(2) { diff --git a/storage-proofs-core/src/util.rs b/storage-proofs-core/src/util.rs index 823814a1d..31d9902b2 100644 --- a/storage-proofs-core/src/util.rs +++ b/storage-proofs-core/src/util.rs @@ -142,8 +142,7 @@ pub fn reverse_bit_numbering(bits: Vec) -> Vec { padded_bits .chunks(8) - .map(|chunk| chunk.iter().rev()) - .flatten() + .flat_map(|chunk| chunk.iter().rev()) .cloned() .collect() } diff --git a/storage-proofs-porep/src/lib.rs b/storage-proofs-porep/src/lib.rs index d00d8e69c..18f57c4a7 100644 --- a/storage-proofs-porep/src/lib.rs +++ b/storage-proofs-porep/src/lib.rs @@ -1,4 +1,5 @@ #![deny(clippy::all, clippy::perf, clippy::correctness, rust_2018_idioms)] +#![allow(clippy::mut_from_ref)] #![warn(clippy::unwrap_used)] #![cfg_attr(target_arch = "aarch64", feature(stdsimd))] #![warn(clippy::unnecessary_wraps)] diff --git a/storage-proofs-porep/src/stacked/vanilla/cache.rs b/storage-proofs-porep/src/stacked/vanilla/cache.rs index 81afac4bb..dc3ec6ce6 100644 --- a/storage-proofs-porep/src/stacked/vanilla/cache.rs +++ b/storage-proofs-porep/src/stacked/vanilla/cache.rs @@ -311,7 +311,7 @@ impl ParentCache { let mut digest_hex: String = "".to_string(); let sector_size = graph.size() * NODE_SIZE; - with_exclusive_lock(&path.to_path_buf(), |file| { + with_exclusive_lock(path, |file| { let cache_size = cache_entries as usize * NODE_BYTES * DEGREE; file.as_ref() .set_len(cache_size as u64) diff --git a/storage-proofs-porep/src/stacked/vanilla/create_label/multi.rs b/storage-proofs-porep/src/stacked/vanilla/create_label/multi.rs index e3a9ca38e..14711372e 100644 --- a/storage-proofs-porep/src/stacked/vanilla/create_label/multi.rs +++ b/storage-proofs-porep/src/stacked/vanilla/create_label/multi.rs @@ -58,8 +58,8 @@ fn fill_buffer( cur_node: u64, parents_cache: &CacheReader, mut cur_parent: &[u32], // parents for this node - layer_labels: &UnsafeSlice<'_, u32>, - exp_labels: Option<&UnsafeSlice<'_, u32>>, // None for layer0 + layer_labels: &UnsafeSlice, + exp_labels: Option<&UnsafeSlice>, // None for layer0 buf: &mut [u8], base_parent_missing: &mut BitMask, ) { @@ -140,15 +140,15 @@ fn fill_buffer( #[allow(clippy::too_many_arguments)] fn create_label_runner( parents_cache: &CacheReader, - layer_labels: &UnsafeSlice<'_, u32>, - exp_labels: Option<&UnsafeSlice<'_, u32>>, // None for layer 0 + layer_labels: &UnsafeSlice, + exp_labels: Option<&UnsafeSlice>, // None for layer 0 num_nodes: u64, cur_producer: &AtomicU64, cur_awaiting: &AtomicU64, stride: u64, lookahead: u64, ring_buf: &RingBuf, - base_parent_missing: &UnsafeSlice<'_, BitMask>, + base_parent_missing: &UnsafeSlice, ) { info!("created label runner"); // Label data bytes per node diff --git a/storage-proofs-porep/src/stacked/vanilla/proof.rs b/storage-proofs-porep/src/stacked/vanilla/proof.rs index 795c56cfe..33749d891 100644 --- a/storage-proofs-porep/src/stacked/vanilla/proof.rs +++ b/storage-proofs-porep/src/stacked/vanilla/proof.rs @@ -578,7 +578,7 @@ impl<'a, Tree: 'static + MerkleTreeTrait, G: 'static + Hasher> StackedDrg<'a, Tr ]; // gather all layer data. - for (layer_index, mut layer_bytes) in + for (layer_index, layer_bytes) in layer_data.iter_mut().enumerate() { let store = labels.labels_for_layer(layer_index + 1); @@ -586,7 +586,7 @@ impl<'a, Tree: 'static + MerkleTreeTrait, G: 'static + Hasher> StackedDrg<'a, Tr let end = start + chunked_nodes_count; store - .read_range_into(start, end, &mut layer_bytes) + .read_range_into(start, end, layer_bytes) .expect("failed to read store range"); } diff --git a/storage-proofs-porep/src/stacked/vanilla/utils.rs b/storage-proofs-porep/src/stacked/vanilla/utils.rs index 3ce5c3a0e..7a2a4adc2 100644 --- a/storage-proofs-porep/src/stacked/vanilla/utils.rs +++ b/storage-proofs-porep/src/stacked/vanilla/utils.rs @@ -4,44 +4,41 @@ use std::slice::{self, ChunksExactMut}; /// A slice type which can be shared between threads, but must be fully managed by the caller. /// Any synchronization must be ensured by the caller, which is why all access is `unsafe`. #[derive(Debug)] -pub struct UnsafeSlice<'a, T> { - // holds the data to ensure lifetime correctness - data: UnsafeCell<&'a mut [T]>, +pub struct UnsafeSlice { /// pointer to the data ptr: *mut T, /// Number of elements, not bytes. len: usize, } -unsafe impl<'a, T> Sync for UnsafeSlice<'a, T> {} +unsafe impl Sync for UnsafeSlice {} -impl<'a, T> UnsafeSlice<'a, T> { +impl UnsafeSlice { /// Takes mutable slice, to ensure that `UnsafeSlice` is the only user of this memory, until it gets dropped. - pub fn from_slice(source: &'a mut [T]) -> Self { + pub fn from_slice(source: &mut [T]) -> Self { let len = source.len(); let ptr = source.as_mut_ptr(); - let data = UnsafeCell::new(source); - Self { data, ptr, len } + Self { ptr, len } } /// Safety: The caller must ensure that there are no unsynchronized parallel access to the same regions. #[inline] - pub unsafe fn as_mut_slice(&self) -> &'a mut [T] { + pub unsafe fn as_mut_slice(&self) -> &mut [T] { slice::from_raw_parts_mut(self.ptr, self.len) } /// Safety: The caller must ensure that there are no unsynchronized parallel access to the same regions. #[inline] - pub unsafe fn as_slice(&self) -> &'a [T] { + pub unsafe fn as_slice(&self) -> &[T] { slice::from_raw_parts(self.ptr, self.len) } #[inline] - pub unsafe fn get(&self, index: usize) -> &'a T { + pub unsafe fn get(&self, index: usize) -> &T { &*self.ptr.add(index) } #[inline] - pub unsafe fn get_mut(&self, index: usize) -> &'a mut T { + pub unsafe fn get_mut(&self, index: usize) -> &mut T { &mut *self.ptr.add(index) } } From 4a1aa2e3a3fe61f78e61a57058c97c9c25c6f23a Mon Sep 17 00:00:00 2001 From: Artem Storozhuk Date: Tue, 31 May 2022 19:11:57 +0300 Subject: [PATCH 3/3] Requested changes --- fil-proofs-param/src/bin/fakeipfsadd.rs | 2 ++ fil-proofs-param/src/bin/parampublish.rs | 2 +- fil-proofs-param/src/bin/srspublish.rs | 2 +- fil-proofs-param/tests/paramfetch/session.rs | 4 ++-- .../tests/parampublish/support/session.rs | 4 ++-- fil-proofs-param/tests/support/mod.rs | 1 + sha2raw/src/sha256_intrinsics.rs | 11 ++++++--- storage-proofs-porep/src/lib.rs | 1 - .../src/stacked/vanilla/create_label/multi.rs | 10 ++++---- .../src/stacked/vanilla/utils.rs | 23 +++++++++++-------- 10 files changed, 36 insertions(+), 24 deletions(-) diff --git a/fil-proofs-param/src/bin/fakeipfsadd.rs b/fil-proofs-param/src/bin/fakeipfsadd.rs index 63472c49b..b1cf0dbc9 100644 --- a/fil-proofs-param/src/bin/fakeipfsadd.rs +++ b/fil-proofs-param/src/bin/fakeipfsadd.rs @@ -16,6 +16,8 @@ enum Cli { Add { #[structopt(help = "Positional argument for the path to the file to add.")] file_path: String, + #[structopt(short = "Q", help = "Simulates the -Q argument to `ipfs add`.")] + _quieter: bool, }, } diff --git a/fil-proofs-param/src/bin/parampublish.rs b/fil-proofs-param/src/bin/parampublish.rs index 07c198cfa..7c9a9658b 100644 --- a/fil-proofs-param/src/bin/parampublish.rs +++ b/fil-proofs-param/src/bin/parampublish.rs @@ -105,7 +105,7 @@ fn get_filenames_in_cache_dir() -> Vec { fn publish_file(ipfs_bin: &str, filename: &str) -> Result { let path = get_full_path_for_file_within_cache(filename); let output = Command::new(ipfs_bin) - .args(&["add", path.to_str().unwrap()]) + .args(&["add", "-Q", path.to_str().unwrap()]) .output() .expect("failed to run ipfs subprocess"); stderr() diff --git a/fil-proofs-param/src/bin/srspublish.rs b/fil-proofs-param/src/bin/srspublish.rs index 295e70537..91fc80325 100644 --- a/fil-proofs-param/src/bin/srspublish.rs +++ b/fil-proofs-param/src/bin/srspublish.rs @@ -77,7 +77,7 @@ fn get_filenames_in_cache_dir() -> Vec { fn publish_file(ipfs_bin: &str, filename: &str) -> Result { let path = get_full_path_for_file_within_cache(filename); let output = Command::new(ipfs_bin) - .args(&["add", path.to_str().unwrap()]) + .args(&["add", "-Q", path.to_str().unwrap()]) .output() .expect("failed to run ipfs subprocess"); stderr() diff --git a/fil-proofs-param/tests/paramfetch/session.rs b/fil-proofs-param/tests/paramfetch/session.rs index f54e7354f..0fdb4f9a4 100644 --- a/fil-proofs-param/tests/paramfetch/session.rs +++ b/fil-proofs-param/tests/paramfetch/session.rs @@ -63,7 +63,7 @@ impl ParamFetchSessionBuilder { /// Launch paramfetch in an environment configured by the builder. pub fn build(self) -> ParamFetchSession { - let session = match spawn_bash_with_retries(10, Some(self.session_timeout_ms)) { + let pty_session = match spawn_bash_with_retries(10, Some(self.session_timeout_ms)) { Err(e) => panic_any(e), Ok(mut session) => { let cache_dir_path = format!("{:?}", self.cache_dir.path()); @@ -103,7 +103,7 @@ impl ParamFetchSessionBuilder { }; ParamFetchSession { - pty_session: session, + pty_session, _cache_dir: self.cache_dir, } } diff --git a/fil-proofs-param/tests/parampublish/support/session.rs b/fil-proofs-param/tests/parampublish/support/session.rs index 7a5e7f4d5..5b050172e 100644 --- a/fil-proofs-param/tests/parampublish/support/session.rs +++ b/fil-proofs-param/tests/parampublish/support/session.rs @@ -116,7 +116,7 @@ impl ParamPublishSessionBuilder { /// Launch parampublish in an environment configured by the builder. pub fn build(self) -> (ParamPublishSession, Vec) { - let session = match spawn_bash_with_retries(10, Some(self.session_timeout_ms)) { + let pty_session = match spawn_bash_with_retries(10, Some(self.session_timeout_ms)) { Err(err) => panic_any(err), Ok(mut session) => { let cache_dir_path = format!("{:?}", self.cache_dir.path()); @@ -148,7 +148,7 @@ impl ParamPublishSessionBuilder { ( ParamPublishSession { - pty_session: session, + pty_session, _cache_dir: self.cache_dir, }, cache_contents, diff --git a/fil-proofs-param/tests/support/mod.rs b/fil-proofs-param/tests/support/mod.rs index 4386db27a..6f663f626 100644 --- a/fil-proofs-param/tests/support/mod.rs +++ b/fil-proofs-param/tests/support/mod.rs @@ -25,6 +25,7 @@ impl FakeIpfsBin { pub fn compute_checksum>(&self, path: P) -> Result { let output = Command::new(&self.bin_path) .arg("add") + .arg("-Q") .arg(path.as_ref()) .output()?; diff --git a/sha2raw/src/sha256_intrinsics.rs b/sha2raw/src/sha256_intrinsics.rs index 17ab2ba8c..531101250 100644 --- a/sha2raw/src/sha256_intrinsics.rs +++ b/sha2raw/src/sha256_intrinsics.rs @@ -14,11 +14,16 @@ use x86::{ /// Process a block with the SHA-256 algorithm. /// Based on https://github.com/noloader/SHA-Intrinsics/blob/master/sha256-x86.c +#[allow(clippy::needless_late_init)] #[inline(always)] pub unsafe fn compress256(state: &mut [u32; 8], blocks: &[&[u8]]) { assert_eq!(blocks.len() % 2, 0); + let mut state0: __m128i; + let mut state1: __m128i; + let mut msg: __m128i; + let mut tmp: __m128i; let mut msg0: __m128i; let mut msg1: __m128i; @@ -35,12 +40,12 @@ pub unsafe fn compress256(state: &mut [u32; 8], blocks: &[&[u8]]) { ); // Load initial values - let mut tmp = _mm_loadu_si128(state.as_ptr().add(0) as *const __m128i); - let mut state1 = _mm_loadu_si128(state.as_ptr().add(4) as *const __m128i); + tmp = _mm_loadu_si128(state.as_ptr().add(0) as *const __m128i); + state1 = _mm_loadu_si128(state.as_ptr().add(4) as *const __m128i); tmp = _mm_shuffle_epi32(tmp, 0xB1); // CDAB state1 = _mm_shuffle_epi32(state1, 0x1B); // EFGH - let mut state0 = _mm_alignr_epi8(tmp, state1, 8); // ABEF + state0 = _mm_alignr_epi8(tmp, state1, 8); // ABEF state1 = _mm_blend_epi16(state1, tmp, 0xF0); // CDGH for i in (0..blocks.len()).step_by(2) { diff --git a/storage-proofs-porep/src/lib.rs b/storage-proofs-porep/src/lib.rs index 18f57c4a7..d00d8e69c 100644 --- a/storage-proofs-porep/src/lib.rs +++ b/storage-proofs-porep/src/lib.rs @@ -1,5 +1,4 @@ #![deny(clippy::all, clippy::perf, clippy::correctness, rust_2018_idioms)] -#![allow(clippy::mut_from_ref)] #![warn(clippy::unwrap_used)] #![cfg_attr(target_arch = "aarch64", feature(stdsimd))] #![warn(clippy::unnecessary_wraps)] diff --git a/storage-proofs-porep/src/stacked/vanilla/create_label/multi.rs b/storage-proofs-porep/src/stacked/vanilla/create_label/multi.rs index 14711372e..e3a9ca38e 100644 --- a/storage-proofs-porep/src/stacked/vanilla/create_label/multi.rs +++ b/storage-proofs-porep/src/stacked/vanilla/create_label/multi.rs @@ -58,8 +58,8 @@ fn fill_buffer( cur_node: u64, parents_cache: &CacheReader, mut cur_parent: &[u32], // parents for this node - layer_labels: &UnsafeSlice, - exp_labels: Option<&UnsafeSlice>, // None for layer0 + layer_labels: &UnsafeSlice<'_, u32>, + exp_labels: Option<&UnsafeSlice<'_, u32>>, // None for layer0 buf: &mut [u8], base_parent_missing: &mut BitMask, ) { @@ -140,15 +140,15 @@ fn fill_buffer( #[allow(clippy::too_many_arguments)] fn create_label_runner( parents_cache: &CacheReader, - layer_labels: &UnsafeSlice, - exp_labels: Option<&UnsafeSlice>, // None for layer 0 + layer_labels: &UnsafeSlice<'_, u32>, + exp_labels: Option<&UnsafeSlice<'_, u32>>, // None for layer 0 num_nodes: u64, cur_producer: &AtomicU64, cur_awaiting: &AtomicU64, stride: u64, lookahead: u64, ring_buf: &RingBuf, - base_parent_missing: &UnsafeSlice, + base_parent_missing: &UnsafeSlice<'_, BitMask>, ) { info!("created label runner"); // Label data bytes per node diff --git a/storage-proofs-porep/src/stacked/vanilla/utils.rs b/storage-proofs-porep/src/stacked/vanilla/utils.rs index 7a2a4adc2..26c083401 100644 --- a/storage-proofs-porep/src/stacked/vanilla/utils.rs +++ b/storage-proofs-porep/src/stacked/vanilla/utils.rs @@ -1,44 +1,49 @@ +#![allow(clippy::mut_from_ref)] + use std::cell::UnsafeCell; use std::slice::{self, ChunksExactMut}; /// A slice type which can be shared between threads, but must be fully managed by the caller. /// Any synchronization must be ensured by the caller, which is why all access is `unsafe`. #[derive(Debug)] -pub struct UnsafeSlice { +pub struct UnsafeSlice<'a, T> { + // holds the data to ensure lifetime correctness + _data: UnsafeCell<&'a mut [T]>, /// pointer to the data ptr: *mut T, /// Number of elements, not bytes. len: usize, } -unsafe impl Sync for UnsafeSlice {} +unsafe impl<'a, T> Sync for UnsafeSlice<'a, T> {} -impl UnsafeSlice { +impl<'a, T> UnsafeSlice<'a, T> { /// Takes mutable slice, to ensure that `UnsafeSlice` is the only user of this memory, until it gets dropped. - pub fn from_slice(source: &mut [T]) -> Self { + pub fn from_slice(source: &'a mut [T]) -> Self { let len = source.len(); let ptr = source.as_mut_ptr(); - Self { ptr, len } + let _data = UnsafeCell::new(source); + Self { _data, ptr, len } } /// Safety: The caller must ensure that there are no unsynchronized parallel access to the same regions. #[inline] - pub unsafe fn as_mut_slice(&self) -> &mut [T] { + pub unsafe fn as_mut_slice(&self) -> &'a mut [T] { slice::from_raw_parts_mut(self.ptr, self.len) } /// Safety: The caller must ensure that there are no unsynchronized parallel access to the same regions. #[inline] - pub unsafe fn as_slice(&self) -> &[T] { + pub unsafe fn as_slice(&self) -> &'a [T] { slice::from_raw_parts(self.ptr, self.len) } #[inline] - pub unsafe fn get(&self, index: usize) -> &T { + pub unsafe fn get(&self, index: usize) -> &'a T { &*self.ptr.add(index) } #[inline] - pub unsafe fn get_mut(&self, index: usize) -> &mut T { + pub unsafe fn get_mut(&self, index: usize) -> &'a mut T { &mut *self.ptr.add(index) } }