Skip to content

Commit 94620a8

Browse files
authored
Add clippy lints (#659)
* Add clippy lints Adds a variety of clippy lints such that it doesn't interfere more than necessary with the current code style. Does not enable `shadow_unrelated` yet. Signed-off-by: Moritz Hoffmann <[email protected]> * Add components for CI Signed-off-by: Moritz Hoffmann <[email protected]> * Forgot clippy.toml Signed-off-by: Moritz Hoffmann <[email protected]> * Fix lgalloc example on Windows Signed-off-by: Moritz Hoffmann <[email protected]> * Test warning without failing Signed-off-by: Moritz Hoffmann <[email protected]> * Maybe this? Signed-off-by: Moritz Hoffmann <[email protected]> * Getting closer, maybe this works on Windows, too? Signed-off-by: Moritz Hoffmann <[email protected]> * Separate clippy job Signed-off-by: Moritz Hoffmann <[email protected]> --------- Signed-off-by: Moritz Hoffmann <[email protected]>
1 parent ee10f84 commit 94620a8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+493
-412
lines changed

.github/workflows/miri.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ jobs:
1313
- uses: actions-rust-lang/setup-rust-toolchain@v1
1414
with:
1515
toolchain: nightly
16-
- name: Install miri
17-
run: rustup component add miri
16+
components: miri
1817
- name: Cargo test
1918
run: cargo miri test

.github/workflows/test.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,24 @@ jobs:
2323
- uses: actions-rust-lang/setup-rust-toolchain@v1
2424
with:
2525
toolchain: ${{ matrix.toolchain }}
26+
components: clippy
2627
- name: Cargo test
2728
run: cargo test --workspace --all-targets
2829

30+
# Check for clippy warnings
31+
clippy:
32+
name: Cargo clippy
33+
runs-on: ubuntu-latest
34+
steps:
35+
- uses: actions/checkout@v4
36+
- uses: actions-rust-lang/setup-rust-toolchain@v1
37+
with:
38+
components: clippy
39+
- name: Cargo clippy
40+
run: cargo clippy --workspace --all-targets
41+
env:
42+
RUSTFLAGS: "" # Don't make test fail on clippy
43+
2944
# Check mdbook files for errors
3045
mdbook:
3146
name: test mdBook

Cargo.toml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,70 @@ edition = "2021"
1515
[workspace.dependencies]
1616
columnar = "0.3"
1717

18+
[workspace.lints.clippy]
19+
type_complexity = "allow"
20+
option_map_unit_fn = "allow"
21+
wrong_self_convention = "allow"
22+
should_implement_trait = "allow"
23+
module_inception = "allow"
24+
25+
#as_conversions = "warn"
26+
bool_comparison = "warn"
27+
borrow_interior_mutable_const = "warn"
28+
borrowed_box = "warn"
29+
builtin_type_shadow = "warn"
30+
clone_on_ref_ptr = "warn"
31+
crosspointer_transmute = "warn"
32+
dbg_macro = "warn"
33+
deref_addrof = "warn"
34+
disallowed_macros = "warn"
35+
disallowed_methods = "warn"
36+
disallowed_types = "warn"
37+
double_must_use = "warn"
38+
double_neg = "warn"
39+
double_parens = "warn"
40+
duplicate_underscore_argument = "warn"
41+
excessive_precision = "warn"
42+
extra_unused_lifetimes = "warn"
43+
from_over_into = "warn"
44+
match_overlapping_arm = "warn"
45+
must_use_unit = "warn"
46+
mut_mutex_lock = "warn"
47+
needless_borrow = "warn"
48+
needless_pass_by_ref_mut = "warn"
49+
needless_question_mark = "warn"
50+
needless_return = "warn"
51+
no_effect = "warn"
52+
panicking_overflow_checks = "warn"
53+
partialeq_ne_impl = "warn"
54+
print_literal = "warn"
55+
redundant_closure = "warn"
56+
redundant_closure_call = "warn"
57+
redundant_field_names = "warn"
58+
redundant_pattern = "warn"
59+
redundant_slicing = "warn"
60+
redundant_static_lifetimes = "warn"
61+
same_item_push = "warn"
62+
shadow_unrelated = "warn"
63+
single_component_path_imports = "warn"
64+
suspicious_assignment_formatting = "warn"
65+
suspicious_else_formatting = "warn"
66+
suspicious_unary_op_formatting = "warn"
67+
todo = "warn"
68+
transmutes_expressible_as_ptr_casts = "warn"
69+
unnecessary_cast = "warn"
70+
unnecessary_lazy_evaluations = "warn"
71+
unnecessary_mut_passed = "warn"
72+
unnecessary_unwrap = "warn"
73+
unused_async = "warn"
74+
useless_asref = "warn"
75+
useless_conversion = "warn"
76+
useless_format = "warn"
77+
wildcard_in_or_patterns = "warn"
78+
write_literal = "warn"
79+
zero_divided_by_zero = "warn"
80+
zero_prefixed_literal = "warn"
81+
1882
[profile.release]
1983
opt-level = 3
2084
debug = true

bytes/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ homepage = "https://github.com/TimelyDataflow/timely-dataflow"
1111
repository = "https://github.com/TimelyDataflow/timely-dataflow.git"
1212
keywords = ["timely", "dataflow", "bytes"]
1313
license = "MIT"
14+
15+
[lints]
16+
workspace = true

bytes/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ pub mod arc {
9494
let result = BytesMut {
9595
ptr: self.ptr,
9696
len: index,
97-
sequestered: self.sequestered.clone(),
97+
sequestered: Arc::clone(&self.sequestered),
9898
};
9999

100100
self.ptr = self.ptr.wrapping_add(index);
@@ -204,7 +204,7 @@ pub mod arc {
204204
let result = Bytes {
205205
ptr: self.ptr,
206206
len: index,
207-
sequestered: self.sequestered.clone(),
207+
sequestered: Arc::clone(&self.sequestered),
208208
};
209209

210210
self.ptr = self.ptr.wrapping_add(index);

clippy.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ignore-interior-mutability = ["timely::dataflow::operators::capability::Capability"]

communication/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ repository = "https://github.com/TimelyDataflow/timely-dataflow.git"
1313
keywords = ["timely", "dataflow"]
1414
license = "MIT"
1515

16+
[lints]
17+
workspace = true
18+
1619
[features]
1720
default = ["getopts"]
1821

communication/examples/comm_hello.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ fn main() {
3232
let (mut senders, mut receiver) = allocator.allocate(0);
3333

3434
// send typed data along each channel
35-
for i in 0 .. allocator.peers() {
36-
senders[i].send(Message { payload: format!("hello, {}", i)});
37-
senders[i].done();
35+
for (i, sender) in senders.iter_mut().enumerate() {
36+
sender.send(Message { payload: format!("hello, {}", i)});
37+
sender.done();
3838
}
3939

4040
// no support for termination notification,

communication/examples/lgalloc.rs

Lines changed: 97 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,126 @@
1-
#![cfg(any(target_os = "linux", target_os = "macos"))]
1+
//! Test using lgalloc as the allocator for zero-copy data transfer.
2+
//! Note that this example only works on Linux and MacOS.
3+
4+
#[cfg(any(target_os = "linux", target_os = "macos"))]
5+
mod example {
6+
use std::ops::{Deref, DerefMut};
7+
use std::ptr::NonNull;
8+
use timely_communication::{Allocate, Bytesable};
9+
use timely_communication::allocator::zero_copy::bytes_slab::BytesRefill;
10+
11+
/// A wrapper that indicates the serialization/deserialization strategy.
12+
pub struct Message {
13+
/// Text contents.
14+
pub payload: String,
15+
}
216

3-
use std::ops::{Deref, DerefMut};
4-
use std::ptr::NonNull;
5-
use timely_communication::{Allocate, Bytesable};
6-
use timely_communication::allocator::zero_copy::bytes_slab::BytesRefill;
17+
impl Bytesable for Message {
18+
fn from_bytes(bytes: timely_bytes::arc::Bytes) -> Self {
19+
Message { payload: std::str::from_utf8(&bytes[..]).unwrap().to_string() }
20+
}
721

8-
/// A wrapper that indicates the serialization/deserialization strategy.
9-
pub struct Message {
10-
/// Text contents.
11-
pub payload: String,
12-
}
22+
fn length_in_bytes(&self) -> usize {
23+
self.payload.len()
24+
}
1325

14-
impl Bytesable for Message {
15-
fn from_bytes(bytes: timely_bytes::arc::Bytes) -> Self {
16-
Message { payload: std::str::from_utf8(&bytes[..]).unwrap().to_string() }
26+
fn into_bytes<W: ::std::io::Write>(&self, writer: &mut W) {
27+
writer.write_all(self.payload.as_bytes()).unwrap();
28+
}
1729
}
1830

19-
fn length_in_bytes(&self) -> usize {
20-
self.payload.len()
31+
fn lgalloc_refill(size: usize) -> Box<LgallocHandle> {
32+
let (pointer, capacity, handle) = lgalloc::allocate::<u8>(size).unwrap();
33+
let handle = Some(handle);
34+
Box::new(LgallocHandle { handle, pointer, capacity })
2135
}
2236

23-
fn into_bytes<W: ::std::io::Write>(&self, writer: &mut W) {
24-
writer.write_all(self.payload.as_bytes()).unwrap();
37+
struct LgallocHandle {
38+
handle: Option<lgalloc::Handle>,
39+
pointer: NonNull<u8>,
40+
capacity: usize,
2541
}
26-
}
2742

28-
fn lgalloc_refill(size: usize) -> Box<LgallocHandle> {
29-
let (pointer, capacity, handle) = lgalloc::allocate::<u8>(size).unwrap();
30-
let handle = Some(handle);
31-
Box::new(LgallocHandle { handle, pointer, capacity })
32-
}
33-
34-
struct LgallocHandle {
35-
handle: Option<lgalloc::Handle>,
36-
pointer: NonNull<u8>,
37-
capacity: usize,
38-
}
39-
40-
impl Deref for LgallocHandle {
41-
type Target = [u8];
42-
#[inline(always)]
43-
fn deref(&self) -> &Self::Target {
44-
unsafe { std::slice::from_raw_parts(self.pointer.as_ptr(), self.capacity) }
43+
impl Deref for LgallocHandle {
44+
type Target = [u8];
45+
#[inline(always)]
46+
fn deref(&self) -> &Self::Target {
47+
unsafe { std::slice::from_raw_parts(self.pointer.as_ptr(), self.capacity) }
48+
}
4549
}
46-
}
4750

48-
impl DerefMut for LgallocHandle {
49-
#[inline(always)]
50-
fn deref_mut(&mut self) -> &mut Self::Target {
51-
unsafe { std::slice::from_raw_parts_mut(self.pointer.as_ptr(), self.capacity) }
51+
impl DerefMut for LgallocHandle {
52+
#[inline(always)]
53+
fn deref_mut(&mut self) -> &mut Self::Target {
54+
unsafe { std::slice::from_raw_parts_mut(self.pointer.as_ptr(), self.capacity) }
55+
}
5256
}
53-
}
5457

55-
impl Drop for LgallocHandle {
56-
fn drop(&mut self) {
57-
lgalloc::deallocate(self.handle.take().unwrap());
58+
impl Drop for LgallocHandle {
59+
fn drop(&mut self) {
60+
lgalloc::deallocate(self.handle.take().unwrap());
61+
}
5862
}
59-
}
6063

61-
fn main() {
62-
let mut config = lgalloc::LgAlloc::new();
63-
config.enable().with_path(std::env::temp_dir());
64-
lgalloc::lgalloc_set_config(&config);
64+
pub(crate) fn main() {
65+
let mut lgconfig = lgalloc::LgAlloc::new();
66+
lgconfig.enable().with_path(std::env::temp_dir());
67+
lgalloc::lgalloc_set_config(&lgconfig);
6568

66-
let refill = BytesRefill {
67-
logic: std::sync::Arc::new(|size| lgalloc_refill(size) as Box<dyn DerefMut<Target=[u8]>>),
68-
limit: None,
69-
};
69+
let refill = BytesRefill {
70+
logic: std::sync::Arc::new(|size| lgalloc_refill(size) as Box<dyn DerefMut<Target=[u8]>>),
71+
limit: None,
72+
};
7073

71-
// extract the configuration from user-supplied arguments, initialize the computation.
72-
let config = timely_communication::Config::ProcessBinary(4);
73-
let (allocators, others) = config.try_build_with(refill).unwrap();
74-
let guards = timely_communication::initialize_from(allocators, others, |mut allocator| {
74+
// extract the configuration from user-supplied arguments, initialize the computation.
75+
let config = timely_communication::Config::ProcessBinary(4);
76+
let (allocators, others) = config.try_build_with(refill).unwrap();
77+
let guards = timely_communication::initialize_from(allocators, others, |mut allocator| {
7578

76-
println!("worker {} of {} started", allocator.index(), allocator.peers());
79+
println!("worker {} of {} started", allocator.index(), allocator.peers());
7780

78-
// allocates a pair of senders list and one receiver.
79-
let (mut senders, mut receiver) = allocator.allocate(0);
81+
// allocates a pair of senders list and one receiver.
82+
let (mut senders, mut receiver) = allocator.allocate(0);
8083

81-
// send typed data along each channel
82-
for i in 0 .. allocator.peers() {
83-
senders[i].send(Message { payload: format!("hello, {}", i)});
84-
senders[i].done();
85-
}
84+
// send typed data along each channel
85+
for (i, sender) in senders.iter_mut().enumerate() {
86+
sender.send(Message { payload: format!("hello, {}", i)});
87+
sender.done();
88+
}
8689

87-
// no support for termination notification,
88-
// we have to count down ourselves.
89-
let mut received = 0;
90-
while received < allocator.peers() {
90+
// no support for termination notification,
91+
// we have to count down ourselves.
92+
let mut received = 0;
93+
while received < allocator.peers() {
9194

92-
allocator.receive();
95+
allocator.receive();
9396

94-
if let Some(message) = receiver.recv() {
95-
println!("worker {}: received: <{}>", allocator.index(), message.payload);
96-
received += 1;
97-
}
97+
if let Some(message) = receiver.recv() {
98+
println!("worker {}: received: <{}>", allocator.index(), message.payload);
99+
received += 1;
100+
}
98101

99-
allocator.release();
100-
}
102+
allocator.release();
103+
}
101104

102-
allocator.index()
103-
});
105+
allocator.index()
106+
});
104107

105-
// computation runs until guards are joined or dropped.
106-
if let Ok(guards) = guards {
107-
for guard in guards.join() {
108-
println!("result: {:?}", guard);
108+
// computation runs until guards are joined or dropped.
109+
if let Ok(guards) = guards {
110+
for guard in guards.join() {
111+
println!("result: {:?}", guard);
112+
}
109113
}
114+
else { println!("error in computation"); }
110115
}
111-
else { println!("error in computation"); }
116+
}
117+
118+
// Disable entirely on non-Linux and non-MacOS platforms.
119+
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
120+
mod example {
121+
pub fn main() { }
122+
}
123+
124+
pub fn main() {
125+
example::main();
112126
}

communication/src/allocator/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ pub trait Allocate {
9494
(thread::ThreadPusher<T>,
9595
thread::ThreadPuller<T>)
9696
{
97-
thread::Thread::new_from(identifier, self.events().clone())
97+
thread::Thread::new_from(identifier, Rc::clone(self.events()))
9898
}
9999

100100
/// Allocates a broadcast channel, where each pushed message is received by all.

communication/src/allocator/process.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl PeerBuilder for Process {
102102
peers,
103103
buzzers_send: bsend,
104104
buzzers_recv: brecv,
105-
channels: channels.clone(),
105+
channels: Arc::clone(&channels),
106106
counters_send: counters_send.clone(),
107107
counters_recv: recv,
108108
}
@@ -173,7 +173,7 @@ impl Allocate for Process {
173173
.map(|s| Box::new(s) as Box<dyn Push<T>>)
174174
.collect::<Vec<_>>();
175175

176-
let recv = Box::new(CountPuller::new(recv, identifier, self.inner.events().clone())) as Box<dyn Pull<T>>;
176+
let recv = Box::new(CountPuller::new(recv, identifier, Rc::clone(self.inner.events()))) as Box<dyn Pull<T>>;
177177

178178
(sends, recv)
179179
}

0 commit comments

Comments
 (0)