Skip to content

Commit fab144d

Browse files
mivertowskiclaude
andcommitted
Fix clippy warnings and formatting issues
- Use derive(Default) with #[default] attribute for SizeBucket and QueueTier - Remove unused std::io::Write import in persistent_fdtd.rs - Apply cargo fmt formatting fixes across multiple files Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 5fa0559 commit fab144d

10 files changed

Lines changed: 174 additions & 83 deletions

File tree

crates/ringkernel-core/src/analytics_context.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,20 @@ impl AnalyticsContext {
178178
/// # Type Parameters
179179
///
180180
/// * `T` - Element type (must be Copy and have a meaningful zero value)
181-
pub fn allocate_typed<T: Copy + Default + 'static>(&mut self, count: usize) -> AllocationHandle {
181+
pub fn allocate_typed<T: Copy + Default + 'static>(
182+
&mut self,
183+
count: usize,
184+
) -> AllocationHandle {
182185
let size = count * std::mem::size_of::<T>();
183186
let handle = self.allocate(size);
184187

185188
// Track typed allocation
186189
self.stats.typed_allocations += 1;
187-
*self.stats.allocations_by_type.entry(TypeId::of::<T>()).or_insert(0) += 1;
190+
*self
191+
.stats
192+
.allocations_by_type
193+
.entry(TypeId::of::<T>())
194+
.or_insert(0) += 1;
188195

189196
handle
190197
}
@@ -337,7 +344,9 @@ impl AnalyticsContextBuilder {
337344
/// Build the context.
338345
pub fn build(self) -> AnalyticsContext {
339346
let mut ctx = match self.expected_allocations {
340-
Some(cap) => AnalyticsContext::with_capacity(self.name, cap.max(self.preallocations.len())),
347+
Some(cap) => {
348+
AnalyticsContext::with_capacity(self.name, cap.max(self.preallocations.len()))
349+
}
341350
None => AnalyticsContext::new(self.name),
342351
};
343352

crates/ringkernel-core/src/dispatcher.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,7 @@ impl KernelDispatcher {
247247
// Dispatch via K2K broker
248248
let receipt = self
249249
.broker
250-
.send_priority(
251-
source,
252-
kernel_id,
253-
envelope,
254-
self.config.default_priority,
255-
)
250+
.send_priority(source, kernel_id, envelope, self.config.default_priority)
256251
.await?;
257252

258253
// Update metrics

crates/ringkernel-core/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,16 @@ pub mod prelude {
8686
};
8787
pub use crate::context::*;
8888
pub use crate::control::*;
89+
pub use crate::dispatcher::{
90+
DispatcherBuilder, DispatcherConfig, DispatcherMetrics, KernelDispatcher,
91+
};
8992
pub use crate::domain::{Domain, DomainMessage, DomainParseError};
9093
pub use crate::error::*;
9194
pub use crate::health::{
9295
BackoffStrategy, CircuitBreaker, CircuitBreakerConfig, CircuitBreakerStats, CircuitState,
9396
DegradationLevel, DegradationManager, DegradationStats, HealthCheck, HealthCheckResult,
9497
HealthChecker, HealthStatus, KernelHealth, KernelWatchdog, LoadSheddingPolicy, RetryPolicy,
9598
};
96-
pub use crate::dispatcher::{
97-
DispatcherBuilder, DispatcherConfig, DispatcherMetrics, KernelDispatcher,
98-
};
9999
pub use crate::hlc::*;
100100
pub use crate::k2k::{
101101
DeliveryStatus, K2KBroker, K2KBuilder, K2KConfig, K2KEndpoint, K2KMessage,

crates/ringkernel-core/src/memory.rs

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -324,13 +324,14 @@ pub fn create_pool(
324324
///
325325
/// Provides predefined size classes for efficient multi-size pooling.
326326
/// Allocations are rounded up to the smallest bucket that fits.
327-
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
327+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
328328
pub enum SizeBucket {
329329
/// Tiny buffers (256 bytes) - metadata, small messages.
330330
Tiny,
331331
/// Small buffers (1 KB) - typical message payloads.
332332
Small,
333333
/// Medium buffers (4 KB) - page-sized allocations.
334+
#[default]
334335
Medium,
335336
/// Large buffers (16 KB) - batch operations.
336337
Large,
@@ -399,12 +400,6 @@ impl SizeBucket {
399400
}
400401
}
401402

402-
impl Default for SizeBucket {
403-
fn default() -> Self {
404-
Self::Medium
405-
}
406-
}
407-
408403
impl std::fmt::Display for SizeBucket {
409404
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
410405
match self {
@@ -442,7 +437,11 @@ impl StratifiedPoolStats {
442437

443438
/// Get hit rate for a specific bucket.
444439
pub fn bucket_hit_rate(&self, bucket: SizeBucket) -> f64 {
445-
let allocs = self.allocations_per_bucket.get(&bucket).copied().unwrap_or(0);
440+
let allocs = self
441+
.allocations_per_bucket
442+
.get(&bucket)
443+
.copied()
444+
.unwrap_or(0);
446445
let hits = self.hits_per_bucket.get(&bucket).copied().unwrap_or(0);
447446
if allocs == 0 {
448447
0.0
@@ -495,7 +494,10 @@ impl StratifiedMemoryPool {
495494

496495
for bucket in SizeBucket::ALL {
497496
let pool_name = format!("{}_{}", name, bucket);
498-
buckets.insert(bucket, MemoryPool::new(pool_name, bucket.size(), max_buffers_per_bucket));
497+
buckets.insert(
498+
bucket,
499+
MemoryPool::new(pool_name, bucket.size(), max_buffers_per_bucket),
500+
);
499501
}
500502

501503
Self {
@@ -552,7 +554,10 @@ impl StratifiedMemoryPool {
552554

553555
/// Get current size of a specific bucket pool.
554556
pub fn bucket_size(&self, bucket: SizeBucket) -> usize {
555-
self.buckets.get(&bucket).map(|p| p.current_size()).unwrap_or(0)
557+
self.buckets
558+
.get(&bucket)
559+
.map(|p| p.current_size())
560+
.unwrap_or(0)
556561
}
557562

558563
/// Get total buffers currently pooled across all buckets.
@@ -662,7 +667,10 @@ pub fn create_stratified_pool_with_capacity(
662667
name: impl Into<String>,
663668
max_buffers_per_bucket: usize,
664669
) -> SharedStratifiedPool {
665-
Arc::new(StratifiedMemoryPool::with_capacity(name, max_buffers_per_bucket))
670+
Arc::new(StratifiedMemoryPool::with_capacity(
671+
name,
672+
max_buffers_per_bucket,
673+
))
666674
}
667675

668676
// ============================================================================
@@ -698,7 +706,11 @@ impl std::fmt::Debug for PressureReaction {
698706
match self {
699707
Self::None => write!(f, "PressureReaction::None"),
700708
Self::Shrink { target_utilization } => {
701-
write!(f, "PressureReaction::Shrink {{ target_utilization: {} }}", target_utilization)
709+
write!(
710+
f,
711+
"PressureReaction::Shrink {{ target_utilization: {} }}",
712+
target_utilization
713+
)
702714
}
703715
Self::Callback(_) => write!(f, "PressureReaction::Callback(<fn>)"),
704716
}
@@ -1006,9 +1018,9 @@ mod tests {
10061018
let pool = StratifiedMemoryPool::new("test");
10071019

10081020
// Allocate different sizes
1009-
let buf1 = pool.allocate(100); // Tiny
1010-
let buf2 = pool.allocate(500); // Small
1011-
let buf3 = pool.allocate(2000); // Medium
1021+
let buf1 = pool.allocate(100); // Tiny
1022+
let buf2 = pool.allocate(500); // Small
1023+
let buf3 = pool.allocate(2000); // Medium
10121024

10131025
assert_eq!(buf1.bucket(), SizeBucket::Tiny);
10141026
assert_eq!(buf2.bucket(), SizeBucket::Small);
@@ -1046,14 +1058,20 @@ mod tests {
10461058
let pool = StratifiedMemoryPool::new("test");
10471059

10481060
// Allocate from different buckets
1049-
let _buf1 = pool.allocate(100); // Tiny
1050-
let _buf2 = pool.allocate(500); // Small
1051-
let _buf3 = pool.allocate(100); // Tiny again
1061+
let _buf1 = pool.allocate(100); // Tiny
1062+
let _buf2 = pool.allocate(500); // Small
1063+
let _buf3 = pool.allocate(100); // Tiny again
10521064

10531065
let stats = pool.stats();
10541066
assert_eq!(stats.total_allocations, 3);
1055-
assert_eq!(stats.allocations_per_bucket.get(&SizeBucket::Tiny), Some(&2));
1056-
assert_eq!(stats.allocations_per_bucket.get(&SizeBucket::Small), Some(&1));
1067+
assert_eq!(
1068+
stats.allocations_per_bucket.get(&SizeBucket::Tiny),
1069+
Some(&2)
1070+
);
1071+
assert_eq!(
1072+
stats.allocations_per_bucket.get(&SizeBucket::Small),
1073+
Some(&1)
1074+
);
10571075
}
10581076

10591077
#[test]
@@ -1173,7 +1191,9 @@ mod tests {
11731191
let none = PressureReaction::None;
11741192
assert!(format!("{:?}", none).contains("None"));
11751193

1176-
let shrink = PressureReaction::Shrink { target_utilization: 0.5 };
1194+
let shrink = PressureReaction::Shrink {
1195+
target_utilization: 0.5,
1196+
};
11771197
assert!(format!("{:?}", shrink).contains("0.5"));
11781198

11791199
let callback = PressureReaction::Callback(Box::new(|_| {}));

crates/ringkernel-core/src/persistent_message.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,7 @@ mod tests {
256256

257257
table.register(HandlerRegistration::new(1, "fraud_check", 1001));
258258
table.register(HandlerRegistration::new(2, "aggregate", 1002));
259-
table.register(
260-
HandlerRegistration::new(3, "pattern_detect", 1003).with_response(2003),
261-
);
259+
table.register(HandlerRegistration::new(3, "pattern_detect", 1003).with_response(2003));
262260

263261
assert_eq!(table.len(), 3);
264262
assert_eq!(table.max_handler_id(), 3);

crates/ringkernel-core/src/queue.rs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -381,11 +381,12 @@ impl MessageQueue for BoundedQueue {
381381
///
382382
/// Instead of dynamic resizing (which is complex for GPU memory),
383383
/// we provide predefined tiers that can be selected based on expected load.
384-
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
384+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
385385
pub enum QueueTier {
386386
/// Small queues (256 messages) - low traffic, minimal memory.
387387
Small,
388388
/// Medium queues (1024 messages) - moderate traffic.
389+
#[default]
389390
Medium,
390391
/// Large queues (4096 messages) - high traffic.
391392
Large,
@@ -449,12 +450,6 @@ impl QueueTier {
449450
}
450451
}
451452

452-
impl Default for QueueTier {
453-
fn default() -> Self {
454-
Self::Medium
455-
}
456-
}
457-
458453
/// Factory for creating appropriately-sized message queues.
459454
///
460455
/// # Example
@@ -492,7 +487,10 @@ impl QueueFactory {
492487
///
493488
/// * `messages_per_second` - Expected message throughput
494489
/// * `headroom_ms` - Desired buffer time in milliseconds
495-
pub fn create_for_throughput(messages_per_second: u64, headroom_ms: u64) -> Box<dyn MessageQueue> {
490+
pub fn create_for_throughput(
491+
messages_per_second: u64,
492+
headroom_ms: u64,
493+
) -> Box<dyn MessageQueue> {
496494
let tier = QueueTier::for_throughput(messages_per_second, headroom_ms);
497495
Box::new(Self::create_mpsc(tier))
498496
}
@@ -586,7 +584,11 @@ impl QueueMonitor {
586584
/// Suggest whether to upgrade the queue tier based on observed utilization.
587585
///
588586
/// Returns `Some(QueueTier)` if upgrade is recommended, `None` otherwise.
589-
pub fn suggest_upgrade(&self, queue: &dyn MessageQueue, current_tier: QueueTier) -> Option<QueueTier> {
587+
pub fn suggest_upgrade(
588+
&self,
589+
queue: &dyn MessageQueue,
590+
current_tier: QueueTier,
591+
) -> Option<QueueTier> {
590592
let stats = queue.stats();
591593
let utilization = self.utilization(queue);
592594

@@ -642,7 +644,11 @@ pub struct QueueMetrics {
642644

643645
impl QueueMetrics {
644646
/// Capture metrics from a queue.
645-
pub fn capture(queue: &dyn MessageQueue, monitor: &QueueMonitor, current_tier: Option<QueueTier>) -> Self {
647+
pub fn capture(
648+
queue: &dyn MessageQueue,
649+
monitor: &QueueMonitor,
650+
current_tier: Option<QueueTier>,
651+
) -> Self {
646652
let health = monitor.check(queue);
647653
let utilization = monitor.utilization(queue);
648654
let stats = queue.stats();
@@ -785,7 +791,10 @@ mod tests {
785791
assert_eq!(QueueTier::for_throughput(20000, 100), QueueTier::Large);
786792

787793
// Very high traffic - 100000 msg/s with 100ms buffer = 10000 msgs needed
788-
assert_eq!(QueueTier::for_throughput(100000, 100), QueueTier::ExtraLarge);
794+
assert_eq!(
795+
QueueTier::for_throughput(100000, 100),
796+
QueueTier::ExtraLarge
797+
);
789798
}
790799

791800
#[test]
@@ -899,7 +908,9 @@ mod tests {
899908
for _ in 0..(QueueTier::ExtraLarge.capacity() * 3 / 4) {
900909
large_queue.try_enqueue(make_envelope()).unwrap();
901910
}
902-
assert!(monitor.suggest_upgrade(&large_queue, QueueTier::ExtraLarge).is_none());
911+
assert!(monitor
912+
.suggest_upgrade(&large_queue, QueueTier::ExtraLarge)
913+
.is_none());
903914
}
904915

905916
#[test]

crates/ringkernel-cuda-codegen/src/persistent_fdtd.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,6 @@ pub fn compile_persistent_fdtd_to_ptx(config: &PersistentFdtdConfig) -> Result<S
850850
let cuda_code = generate_persistent_fdtd_kernel(config);
851851

852852
// Use nvcc to compile to PTX
853-
use std::io::Write;
854853
use std::process::Command;
855854

856855
// Write to temp file

crates/ringkernel-cuda-codegen/src/ring_kernel.rs

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,7 +1435,12 @@ pub fn generate_handler_dispatch_code(table: &CudaDispatchTable, indent: &str) -
14351435
let mut code = String::new();
14361436

14371437
if table.is_empty() {
1438-
writeln!(code, "{}// No handlers registered - dispatch table empty", indent).unwrap();
1438+
writeln!(
1439+
code,
1440+
"{}// No handlers registered - dispatch table empty",
1441+
indent
1442+
)
1443+
.unwrap();
14391444
return code;
14401445
}
14411446

@@ -1534,7 +1539,10 @@ struct __align__(64) ExtendedH2KMessage {
15341539
/// # Returns
15351540
///
15361541
/// Complete CUDA kernel code with handler dispatch.
1537-
pub fn generate_multi_handler_kernel(config: &RingKernelConfig, table: &CudaDispatchTable) -> String {
1542+
pub fn generate_multi_handler_kernel(
1543+
config: &RingKernelConfig,
1544+
table: &CudaDispatchTable,
1545+
) -> String {
15381546
let mut code = String::new();
15391547

15401548
// Struct definitions
@@ -1994,9 +2002,9 @@ mod tests {
19942002

19952003
#[test]
19962004
fn test_generate_handler_dispatch_code_single_handler() {
1997-
let table = CudaDispatchTable::new()
1998-
.with_handler(CudaHandlerInfo::new(1, "handle_fraud")
1999-
.with_message_type("FraudCheck", 1001));
2005+
let table = CudaDispatchTable::new().with_handler(
2006+
CudaHandlerInfo::new(1, "handle_fraud").with_message_type("FraudCheck", 1001),
2007+
);
20002008

20012009
let code = generate_handler_dispatch_code(&table, " ");
20022010

@@ -2010,13 +2018,17 @@ mod tests {
20102018
#[test]
20112019
fn test_generate_handler_dispatch_code_multiple_handlers() {
20122020
let table = CudaDispatchTable::new()
2013-
.with_handler(CudaHandlerInfo::new(1, "handle_fraud")
2014-
.with_message_type("FraudCheck", 1001))
2015-
.with_handler(CudaHandlerInfo::new(2, "handle_aggregate")
2016-
.with_message_type("Aggregate", 1002)
2017-
.with_response())
2018-
.with_handler(CudaHandlerInfo::new(5, "handle_pattern")
2019-
.with_message_type("Pattern", 1005));
2021+
.with_handler(
2022+
CudaHandlerInfo::new(1, "handle_fraud").with_message_type("FraudCheck", 1001),
2023+
)
2024+
.with_handler(
2025+
CudaHandlerInfo::new(2, "handle_aggregate")
2026+
.with_message_type("Aggregate", 1002)
2027+
.with_response(),
2028+
)
2029+
.with_handler(
2030+
CudaHandlerInfo::new(5, "handle_pattern").with_message_type("Pattern", 1005),
2031+
);
20202032

20212033
let code = generate_handler_dispatch_code(&table, " ");
20222034

@@ -2030,9 +2042,10 @@ mod tests {
20302042

20312043
#[test]
20322044
fn test_generate_handler_dispatch_code_with_inline_body() {
2033-
let table = CudaDispatchTable::new()
2034-
.with_handler(CudaHandlerInfo::new(1, "inline_handler")
2035-
.with_cuda_body("int result = msg->payload[0] * 2;\nresponse->result = result;"));
2045+
let table = CudaDispatchTable::new().with_handler(
2046+
CudaHandlerInfo::new(1, "inline_handler")
2047+
.with_cuda_body("int result = msg->payload[0] * 2;\nresponse->result = result;"),
2048+
);
20362049

20372050
let code = generate_handler_dispatch_code(&table, " ");
20382051

0 commit comments

Comments
 (0)