From 0f535fb2a78b5be7b721c9877f6450ed48756166 Mon Sep 17 00:00:00 2001 From: Artem Storozhuk Date: Tue, 31 May 2022 19:11:57 +0300 Subject: [PATCH] Requested changes --- fil-proofs-param/src/bin/fakeipfsadd.rs | 2 ++ fil-proofs-param/tests/paramfetch/session.rs | 4 ++-- .../tests/parampublish/support/session.rs | 4 ++-- sha2raw/src/sha256_intrinsics.rs | 11 +++++++--- .../src/stacked/vanilla/create_label/multi.rs | 10 ++++----- .../src/stacked/vanilla/utils.rs | 21 +++++++++++-------- 6 files changed, 31 insertions(+), 21 deletions(-) diff --git a/fil-proofs-param/src/bin/fakeipfsadd.rs b/fil-proofs-param/src/bin/fakeipfsadd.rs index 63472c49b8..b1cf0dbc94 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/tests/paramfetch/session.rs b/fil-proofs-param/tests/paramfetch/session.rs index f54e7354f8..0fdb4f9a4b 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 7a5e7f4d5e..5b050172e4 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/sha2raw/src/sha256_intrinsics.rs b/sha2raw/src/sha256_intrinsics.rs index 17ab2ba8cd..5311012508 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/stacked/vanilla/create_label/multi.rs b/storage-proofs-porep/src/stacked/vanilla/create_label/multi.rs index 14711372ea..e3a9ca38ec 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 7a2a4adc2f..a4506d3789 100644 --- a/storage-proofs-porep/src/stacked/vanilla/utils.rs +++ b/storage-proofs-porep/src/stacked/vanilla/utils.rs @@ -4,41 +4,44 @@ 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) } }