Skip to content

Commit 8a38dab

Browse files
committed
Fixing clippy issues
1 parent 7f76277 commit 8a38dab

10 files changed

Lines changed: 96 additions & 88 deletions

File tree

mmtk/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fn main() {
1111

1212
let mmtk_dir = match std::env::var(mmtk_dir_key) {
1313
Ok(mmtk_val) => mmtk_val,
14-
_ => format!(".."),
14+
_ => "..".to_string(),
1515
};
1616

1717
// If bindings file already exists, no need to do anything

mmtk/src/active_plan.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub struct JuliaMutatorIterator<'a> {
1818

1919
impl<'a> JuliaMutatorIterator<'a> {
2020
fn new(guard: RwLockReadGuard<'a, HashMap<Address, Address>>) -> Self {
21-
let vec = guard.keys().map(|addr| *addr).collect();
21+
let vec = guard.keys().copied().collect();
2222
Self {
2323
_guard: guard,
2424
vec,
@@ -49,7 +49,7 @@ impl ActivePlan<JuliaVM> for VMActivePlan {
4949

5050
fn is_mutator(tls: VMThread) -> bool {
5151
// FIXME have a tls field to check whether it is a mutator tls
52-
MUTATORS.read().unwrap().keys().find(|mutator_addr| unsafe { &*mutator_addr.to_mut_ptr::<Mutator<JuliaVM>>() }.mutator_tls.0 == tls).is_some()
52+
MUTATORS.read().unwrap().keys().any(|mutator_addr| unsafe { &*mutator_addr.to_mut_ptr::<Mutator<JuliaVM>>() }.mutator_tls.0 == tls)
5353
}
5454

5555
fn mutator(_tls: VMMutatorThread) -> &'static mut Mutator<JuliaVM> {
@@ -67,7 +67,7 @@ impl ActivePlan<JuliaVM> for VMActivePlan {
6767
_worker: &mut GCWorker<JuliaVM>,
6868
) -> ObjectReference {
6969
queue.enqueue(object);
70-
return object;
70+
object
7171
}
7272
}
7373

@@ -80,17 +80,17 @@ pub extern "C" fn mmtk_new_mutator_iterator() -> *mut JuliaMutatorIterator<'stat
8080
}
8181

8282
#[no_mangle]
83-
pub extern "C" fn mmtk_get_next_mutator_tls(
83+
pub unsafe extern "C" fn mmtk_get_next_mutator_tls(
8484
iter: *mut JuliaMutatorIterator<'static>,
8585
) -> OpaquePointer {
86-
match unsafe { iter.as_mut() }.unwrap().next() {
86+
match { iter.as_mut() }.unwrap().next() {
8787
Some(m) => m.mutator_tls.0 .0,
8888
None => OpaquePointer::from_address(Address::ZERO),
8989
}
9090
}
9191

9292
#[no_mangle]
93-
pub extern "C" fn mmtk_close_mutator_iterator(iter: *mut JuliaMutatorIterator<'static>) {
93+
pub unsafe extern "C" fn mmtk_close_mutator_iterator(iter: *mut JuliaMutatorIterator<'static>) {
9494
// The boxed pointer will get dropped
9595
let _to_drop = unsafe { Box::from_raw(iter) };
9696
}

mmtk/src/api.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,27 +52,27 @@ pub extern "C" fn mmtk_gc_init(
5252
}
5353

5454
// Set heap size
55-
let success;
56-
if min_heap_size != 0 {
57-
info!(
58-
"Setting mmtk heap size to a variable size with min-max of {}-{} (in bytes)",
59-
min_heap_size, max_heap_size
60-
);
61-
success = builder.options.gc_trigger.set(
62-
mmtk::util::options::GCTriggerSelector::DynamicHeapSize(
63-
min_heap_size,
64-
max_heap_size,
65-
),
66-
);
67-
} else {
68-
info!(
69-
"Setting mmtk heap size to a fixed max of {} (in bytes)",
70-
max_heap_size
71-
);
72-
success = builder.options.gc_trigger.set(
73-
mmtk::util::options::GCTriggerSelector::FixedHeapSize(max_heap_size),
74-
);
75-
}
55+
let success =
56+
if min_heap_size != 0 {
57+
info!(
58+
"Setting mmtk heap size to a variable size with min-max of {}-{} (in bytes)",
59+
min_heap_size, max_heap_size
60+
);
61+
builder.options.gc_trigger.set(
62+
mmtk::util::options::GCTriggerSelector::DynamicHeapSize(
63+
min_heap_size,
64+
max_heap_size,
65+
),
66+
)
67+
} else {
68+
info!(
69+
"Setting mmtk heap size to a fixed max of {} (in bytes)",
70+
max_heap_size
71+
);
72+
builder.options.gc_trigger.set(
73+
mmtk::util::options::GCTriggerSelector::FixedHeapSize(max_heap_size),
74+
)
75+
};
7676
assert!(
7777
success,
7878
"Failed to set heap size to {}-{}",

mmtk/src/collection.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl Collection<JuliaVM> for VMCollection {
6161
AtomicBool::store(&BLOCK_FOR_GC, false, Ordering::SeqCst);
6262
AtomicBool::store(&WORLD_HAS_STOPPED, false, Ordering::SeqCst);
6363

64-
let &(_, ref cvar) = &*STW_COND.clone();
64+
let (_, cvar) = &*STW_COND.clone();
6565
cvar.notify_all();
6666

6767
info!(
@@ -109,7 +109,7 @@ impl Collection<JuliaVM> for VMCollection {
109109
}
110110

111111
fn is_collection_enabled() -> bool {
112-
unsafe { jl_get_gc_disable_counter() <= 0 }
112+
unsafe { jl_get_gc_disable_counter() == 0 }
113113
}
114114
}
115115

@@ -124,7 +124,7 @@ pub fn is_current_gc_nursery() -> bool {
124124
pub extern "C" fn mmtk_block_thread_for_gc() {
125125
AtomicBool::store(&BLOCK_FOR_GC, true, Ordering::SeqCst);
126126

127-
let &(ref lock, ref cvar) = &*STW_COND.clone();
127+
let (lock, cvar) = &*STW_COND.clone();
128128
let mut count = lock.lock().unwrap();
129129

130130
info!("Blocking for GC!");

mmtk/src/julia_finalizer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl ArrayListT {
7575
// Some arraylist_t pointers used in finalizer implementation.
7676

7777
/// ptls->finalizers: new finalizers are registered into this thread local list
78-
fn thread_local_finalizer_list(mutator: &Mutator<JuliaVM>) -> &mut ArrayListT {
78+
fn thread_local_finalizer_list(mutator: &mut Mutator<JuliaVM>) -> &mut ArrayListT {
7979
let list = unsafe { jl_gc_get_thread_finalizer_list(mutator.mutator_tls.0 .0) };
8080
unsafe { &mut *list.to_mut_ptr() }
8181
}

mmtk/src/julia_scanning.rs

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub unsafe fn mmtk_jl_to_typeof(t: Address) -> *const jl_datatype_t {
5757
let ty = jl_small_typeof[t_raw / std::mem::size_of::<Address>()];
5858
return ty;
5959
}
60-
return t.to_ptr::<jl_datatype_t>();
60+
t.to_ptr::<jl_datatype_t>()
6161
}
6262

6363
const PRINT_OBJ_TYPE: bool = false;
@@ -177,10 +177,10 @@ pub unsafe fn scan_julia_object<SV: SlotVisitor<JuliaVMSlot>>(obj: Address, clos
177177
process_slot(closure, slot);
178178
obj8_begin = obj8_begin.shift::<u8>(1);
179179
}
180-
} else if vtag_usize == ((jl_small_typeof_tags_jl_string_tag as usize) << 4) {
181-
if PRINT_OBJ_TYPE {
182-
println!("scan_julia_obj {}: string\n", obj);
183-
}
180+
} else if vtag_usize == ((jl_small_typeof_tags_jl_string_tag as usize) << 4)
181+
&& PRINT_OBJ_TYPE
182+
{
183+
println!("scan_julia_obj {}: string\n", obj);
184184
}
185185
return;
186186
} else {
@@ -310,9 +310,7 @@ pub unsafe fn scan_julia_object<SV: SlotVisitor<JuliaVMSlot>>(obj: Address, clos
310310

311311
let layout = (*vt).layout;
312312
let npointers = (*layout).npointers;
313-
if npointers == 0 {
314-
return;
315-
} else {
313+
if npointers != 0 {
316314
if vt == jl_binding_partition_type {
317315
let bpart_ptr = obj.to_mut_ptr::<jl_binding_partition_t>();
318316
let restriction = (*bpart_ptr).restriction._M_i;
@@ -383,16 +381,16 @@ pub unsafe fn mmtk_scan_gcstack<EV: SlotVisitor<JuliaVMSlot>>(
383381
let copy_stack = (*ta).ctx.copy_stack_custom();
384382

385383
#[cfg(feature = "julia_copy_stack")]
386-
if stkbuf != std::ptr::null_mut() && copy_stack != 0 {
384+
if !stkbuf.is_null() && copy_stack != 0 {
387385
let stkbuf_slot = Address::from_ptr(::std::ptr::addr_of!((*ta).ctx.stkbuf));
388386
process_slot(closure, stkbuf_slot);
389387
}
390388

391389
let mut s = (*ta).gcstack;
392-
let (mut offset, mut lb, mut ub) = (0 as isize, 0 as u64, u64::MAX);
390+
let (mut offset, mut lb, mut ub) = (0_isize, 0_u64, u64::MAX);
393391

394392
#[cfg(feature = "julia_copy_stack")]
395-
if stkbuf != std::ptr::null_mut() && copy_stack != 0 && (*ta).ptls == std::ptr::null_mut() {
393+
if !stkbuf.is_null() && copy_stack != 0 && (*ta).ptls.is_null() {
396394
if ((*ta).tid._M_i) < 0 {
397395
panic!("tid must be positive.")
398396
}
@@ -402,10 +400,10 @@ pub unsafe fn mmtk_scan_gcstack<EV: SlotVisitor<JuliaVMSlot>>(
402400
offset = (*ta).ctx.stkbuf as isize - lb as isize;
403401
}
404402

405-
if s != std::ptr::null_mut() {
403+
if !s.is_null() {
406404
let s_nroots_addr = ::std::ptr::addr_of!((*s).nroots);
407405
let mut nroots = read_stack(Address::from_ptr(s_nroots_addr), offset, lb, ub);
408-
debug_assert!(nroots.as_usize() as u32 <= std::u32::MAX);
406+
debug_assert!(nroots.as_usize() as u32 <= u32::MAX);
409407
let mut nr = nroots >> 2;
410408

411409
loop {
@@ -458,7 +456,7 @@ pub unsafe fn mmtk_scan_gcstack<EV: SlotVisitor<JuliaVMSlot>>(
458456
}
459457

460458
// just call into C, since the code is cold
461-
if (*ta).excstack != std::ptr::null_mut() {
459+
if !(*ta).excstack.is_null() {
462460
jl_gc_scan_julia_exc_obj(
463461
Address::from_ptr(ta),
464462
Address::from_mut_ptr(closure),
@@ -477,9 +475,9 @@ unsafe fn read_stack(addr: Address, offset: isize, lb: u64, ub: u64) -> Address
477475
#[inline(always)]
478476
fn get_stack_addr(addr: Address, offset: isize, lb: u64, ub: u64) -> Address {
479477
if addr.as_usize() >= lb as usize && addr.as_usize() < ub as usize {
480-
return addr + offset;
478+
addr + offset
481479
} else {
482-
return addr;
480+
addr
483481
}
484482
}
485483

@@ -532,14 +530,14 @@ pub fn mmtk_decode_restriction_value(pku: usize) -> usize {
532530
// need to apply (pku & ~0x7) to get the object to be traced
533531
// so we use (pku & 0x7) to get the offset from the object
534532
// and pass it to process_offset_slot
535-
return pku & 0x7;
533+
pku & 0x7
536534
}
537535

538536
#[cfg(not(target_pointer_width = "64"))]
539537
{
540538
// when not #ifdef _P64 we simply return pku.val
541539
// i.e., the offset is 0, since val is the first field
542-
return 0;
540+
0
543541
}
544542
}
545543

@@ -573,7 +571,7 @@ pub fn mmtk_jl_array_ndimwords(ndims: u32) -> usize {
573571
return 0;
574572
}
575573

576-
return (ndims - 2) as usize;
574+
(ndims - 2) as usize
577575
}
578576

579577
#[inline(always)]
@@ -602,7 +600,7 @@ pub unsafe fn mmtk_jl_svecref(vt: *mut jl_svec_t, i: usize) -> *const jl_datatyp
602600
let svec_data = mmtk_jl_svec_data(Address::from_mut_ptr(vt));
603601
let result_ptr = svec_data + i;
604602
let result = result_ptr.atomic_load::<AtomicUsize>(Ordering::Relaxed);
605-
::std::mem::transmute::<usize, *const jl_datatype_t>(result)
603+
result as *const _jl_datatype_t
606604
}
607605

608606
#[inline(always)]
@@ -624,32 +622,32 @@ pub unsafe fn mmtk_jl_fielddesc_size(fielddesc_type: u16) -> u32 {
624622

625623
const JL_BT_NON_PTR_ENTRY: usize = usize::MAX;
626624

627-
pub fn mmtk_jl_bt_is_native(bt_entry: *mut jl_bt_element_t) -> bool {
625+
pub unsafe fn mmtk_jl_bt_is_native(bt_entry: *mut jl_bt_element_t) -> bool {
628626
let entry = unsafe { (*bt_entry).__bindgen_anon_1.uintptr };
629627
entry != JL_BT_NON_PTR_ENTRY
630628
}
631629

632-
pub fn mmtk_jl_bt_entry_size(bt_entry: *mut jl_bt_element_t) -> usize {
630+
pub unsafe fn mmtk_jl_bt_entry_size(bt_entry: *mut jl_bt_element_t) -> usize {
633631
if mmtk_jl_bt_is_native(bt_entry) {
634632
1
635633
} else {
636634
2 + mmtk_jl_bt_num_jlvals(bt_entry) + mmtk_jl_bt_num_uintvals(bt_entry)
637635
}
638636
}
639637

640-
pub fn mmtk_jl_bt_num_jlvals(bt_entry: *mut jl_bt_element_t) -> usize {
638+
pub unsafe fn mmtk_jl_bt_num_jlvals(bt_entry: *mut jl_bt_element_t) -> usize {
641639
debug_assert!(!mmtk_jl_bt_is_native(bt_entry));
642640
let entry = unsafe { (*bt_entry.add(1)).__bindgen_anon_1.uintptr };
643641
entry & 0x7
644642
}
645643

646-
pub fn mmtk_jl_bt_num_uintvals(bt_entry: *mut jl_bt_element_t) -> usize {
644+
pub unsafe fn mmtk_jl_bt_num_uintvals(bt_entry: *mut jl_bt_element_t) -> usize {
647645
debug_assert!(!mmtk_jl_bt_is_native(bt_entry));
648646
let entry = unsafe { (*bt_entry.add(1)).__bindgen_anon_1.uintptr };
649647
(entry >> 3) & 0x7
650648
}
651649

652-
pub fn mmtk_jl_bt_entry_jlvalue(bt_entry: *mut jl_bt_element_t, i: usize) -> ObjectReference {
650+
pub unsafe fn mmtk_jl_bt_entry_jlvalue(bt_entry: *mut jl_bt_element_t, i: usize) -> ObjectReference {
653651
let entry = unsafe { (*bt_entry.add(2 + i)).__bindgen_anon_1.jlvalue };
654652
debug_assert!(!entry.is_null());
655653
unsafe { ObjectReference::from_raw_address_unchecked(Address::from_mut_ptr(entry)) }

mmtk/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(clippy::missing_safety_doc)]
2+
13
extern crate libc;
24
extern crate log;
35
extern crate mmtk;
@@ -31,6 +33,7 @@ pub mod julia_scanning;
3133
#[allow(improper_ctypes_definitions)]
3234
#[allow(non_upper_case_globals)]
3335
#[allow(non_snake_case)]
36+
#[allow(clippy::all)]
3437
pub mod julia_types;
3538

3639
#[derive(Default)]

mmtk/src/object_model.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl ObjectModel<JuliaVM> for VMObjectModel {
109109

110110
Self::LOCAL_FORWARDING_BITS_SPEC.store_atomic::<JuliaVM, u8>(
111111
from,
112-
0b10 as u8, // BEING_FORWARDED
112+
0b10_u8, // BEING_FORWARDED
113113
None,
114114
Ordering::SeqCst,
115115
);
@@ -126,8 +126,7 @@ impl ObjectModel<JuliaVM> for VMObjectModel {
126126
// not being called by objects in LOS
127127
debug_assert!(!is_object_in_los(&object));
128128

129-
let obj_size = unsafe { get_so_object_size(object) };
130-
obj_size
129+
unsafe { get_so_object_size(object) }
131130
}
132131

133132
fn get_size_when_copied(_object: ObjectReference) -> usize {
@@ -152,12 +151,11 @@ impl ObjectModel<JuliaVM> for VMObjectModel {
152151

153152
#[inline(always)]
154153
fn ref_to_object_start(object: ObjectReference) -> Address {
155-
let res = if is_object_in_los(&object) {
154+
if is_object_in_los(&object) {
156155
object.to_raw_address() - 48
157156
} else {
158157
unsafe { get_object_start_ref(object) }
159-
};
160-
res
158+
}
161159
}
162160

163161
#[inline(always)]
@@ -178,6 +176,7 @@ pub fn is_object_in_los(object: &ObjectReference) -> bool {
178176
}
179177

180178
#[inline(always)]
179+
/// This function uses mutable static variables and requires unsafe annotation
181180
pub unsafe fn get_so_object_size(object: ObjectReference) -> usize {
182181
let obj_address = object.to_raw_address();
183182
let mut vtag = mmtk_jl_typetagof(obj_address);
@@ -199,7 +198,7 @@ pub unsafe fn get_so_object_size(object: ObjectReference) -> usize {
199198
vtag = Address::from_usize(vtag_usize);
200199
} else if vtag_usize < ((jl_small_typeof_tags_jl_max_tags as usize) << 4) {
201200
if vtag_usize == ((jl_small_typeof_tags_jl_simplevector_tag as usize) << 4) {
202-
let length = (*obj_address.to_ptr::<jl_svec_t>()).length as usize;
201+
let length = (*obj_address.to_ptr::<jl_svec_t>()).length;
203202
let dtsz = length * std::mem::size_of::<Address>() + std::mem::size_of::<jl_svec_t>();
204203

205204
debug_assert!(
@@ -209,7 +208,7 @@ pub unsafe fn get_so_object_size(object: ObjectReference) -> usize {
209208
);
210209

211210
return llt_align(dtsz + JULIA_HEADER_SIZE, 16);
212-
} else if vtag_usize == ((jl_small_typeof_tags_jl_module_tag as usize) << 4) as usize {
211+
} else if vtag_usize == ((jl_small_typeof_tags_jl_module_tag as usize) << 4) {
213212
let dtsz = std::mem::size_of::<jl_module_t>();
214213
debug_assert!(
215214
dtsz + JULIA_HEADER_SIZE <= 2032,
@@ -276,9 +275,9 @@ pub unsafe fn get_so_object_size(object: ObjectReference) -> usize {
276275
let how = jl_gc_genericmemory_how(obj_address);
277276
let res = if how == 0 {
278277
let layout = (*(mmtk_jl_typetagof(obj_address).to_ptr::<jl_datatype_t>())).layout;
279-
let mut sz = (*layout).size as usize * (*m).length as usize;
278+
let mut sz = (*layout).size as usize * (*m).length;
280279
if (*layout).flags.arrayelem_isunion() != 0 {
281-
sz += (*m).length as usize;
280+
sz += (*m).length;
282281
}
283282

284283
let dtsz = llt_align(std::mem::size_of::<jl_genericmemory_t>(), 16);
@@ -301,7 +300,7 @@ pub unsafe fn get_so_object_size(object: ObjectReference) -> usize {
301300
dtsz + JULIA_HEADER_SIZE
302301
);
303302

304-
return llt_align(dtsz + JULIA_HEADER_SIZE, 16);
303+
llt_align(dtsz + JULIA_HEADER_SIZE, 16)
305304
}
306305

307306
#[inline(always)]

0 commit comments

Comments
 (0)