Skip to content

Commit 31106af

Browse files
aidenfoxiveyk0kubun
authored andcommitted
Add miscellaneous Clippy 'corrections' pt. 2 (Shopify/zjit#95)
* Remove immediately deferenced borrow operators source: https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow * Remove unnecessary cast as i64 Since Const::CInt64 wraps i64, it is unnecessary to cast to i64. * Remove unnecessary borrow operators * Beautify assign operation syntax * Use .is_null() convenience method * Omit .into() call from u32 to u32 * Use more descriptive std::ptr::null<VALUE>() In lieu of casting a literal as a type, opt to use the convenience type. * Use sized integer literal * Simplify pattern matching to explicit check
1 parent 14f0b83 commit 31106af

File tree

6 files changed

+15
-15
lines changed

6 files changed

+15
-15
lines changed

zjit/src/backend/arm64/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1281,7 +1281,7 @@ impl Assembler
12811281
// No bytes dropped, so the pos markers point to valid code
12821282
for (insn_idx, pos) in pos_markers {
12831283
if let Insn::PosMarker(callback) = self.insns.get(insn_idx).unwrap() {
1284-
callback(pos, &cb);
1284+
callback(pos, cb);
12851285
} else {
12861286
panic!("non-PosMarker in pos_markers insn_idx={insn_idx} {self:?}");
12871287
}

zjit/src/backend/lir.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ impl<'a> Iterator for InsnOpndIterator<'a> {
758758
match self.idx {
759759
0 => {
760760
self.idx += 1;
761-
Some(&opnd)
761+
Some(opnd)
762762
},
763763
_ => None
764764
}
@@ -789,11 +789,11 @@ impl<'a> Iterator for InsnOpndIterator<'a> {
789789
match self.idx {
790790
0 => {
791791
self.idx += 1;
792-
Some(&opnd0)
792+
Some(opnd0)
793793
}
794794
1 => {
795795
self.idx += 1;
796-
Some(&opnd1)
796+
Some(opnd1)
797797
}
798798
_ => None
799799
}

zjit/src/codegen.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub extern "C" fn rb_zjit_iseq_gen_entry_point(iseq: IseqPtr, _ec: EcPtr) -> *co
7575
});
7676

7777
// Assert that the ISEQ compiles if RubyVM::ZJIT.assert_compiles is enabled
78-
if ZJITState::assert_compiles_enabled() && code_ptr == std::ptr::null() {
78+
if ZJITState::assert_compiles_enabled() && code_ptr.is_null() {
7979
let iseq_location = iseq_get_location(iseq, 0);
8080
panic!("Failed to compile: {iseq_location}");
8181
}

zjit/src/hir.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ pub struct InsnPrinter<'a> {
407407
impl<'a> std::fmt::Display for InsnPrinter<'a> {
408408
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
409409
match &self.inner {
410-
Insn::Const { val } => { write!(f, "Const {}", val.print(&self.ptr_map)) }
410+
Insn::Const { val } => { write!(f, "Const {}", val.print(self.ptr_map)) }
411411
Insn::Param { idx } => { write!(f, "Param {idx}") }
412412
Insn::NewArray { elements } => {
413413
write!(f, "NewArray")?;
@@ -462,8 +462,8 @@ impl<'a> std::fmt::Display for InsnPrinter<'a> {
462462
Insn::FixnumGt { left, right, .. } => { write!(f, "FixnumGt {left}, {right}") },
463463
Insn::FixnumGe { left, right, .. } => { write!(f, "FixnumGe {left}, {right}") },
464464
Insn::GuardType { val, guard_type, .. } => { write!(f, "GuardType {val}, {guard_type}") },
465-
Insn::GuardBitEquals { val, expected, .. } => { write!(f, "GuardBitEquals {val}, {}", expected.print(&self.ptr_map)) },
466-
Insn::PatchPoint(invariant) => { write!(f, "PatchPoint {}", invariant.print(&self.ptr_map)) },
465+
Insn::GuardBitEquals { val, expected, .. } => { write!(f, "GuardBitEquals {val}, {}", expected.print(self.ptr_map)) },
466+
Insn::PatchPoint(invariant) => { write!(f, "PatchPoint {}", invariant.print(self.ptr_map)) },
467467
Insn::GetConstantPath { ic } => { write!(f, "GetConstantPath {:p}", self.ptr_map.map_ptr(ic)) },
468468
insn => { write!(f, "{insn:?}") }
469469
}
@@ -802,7 +802,7 @@ impl Function {
802802
Insn::Const { val: Const::CInt8(val) } => Type::from_cint(types::CInt8, *val as i64),
803803
Insn::Const { val: Const::CInt16(val) } => Type::from_cint(types::CInt16, *val as i64),
804804
Insn::Const { val: Const::CInt32(val) } => Type::from_cint(types::CInt32, *val as i64),
805-
Insn::Const { val: Const::CInt64(val) } => Type::from_cint(types::CInt64, *val as i64),
805+
Insn::Const { val: Const::CInt64(val) } => Type::from_cint(types::CInt64, *val),
806806
Insn::Const { val: Const::CUInt8(val) } => Type::from_cint(types::CUInt8, *val as i64),
807807
Insn::Const { val: Const::CUInt16(val) } => Type::from_cint(types::CUInt16, *val as i64),
808808
Insn::Const { val: Const::CUInt32(val) } => Type::from_cint(types::CUInt32, *val as i64),
@@ -1260,7 +1260,7 @@ fn ep_offset_to_local_idx(iseq: IseqPtr, ep_offset: u32) -> usize {
12601260

12611261
impl FrameState {
12621262
fn new(iseq: IseqPtr) -> FrameState {
1263-
FrameState { iseq, pc: 0 as *const VALUE, insn_idx: 0, stack: vec![], locals: vec![] }
1263+
FrameState { iseq, pc: std::ptr::null::<VALUE>(), insn_idx: 0, stack: vec![], locals: vec![] }
12641264
}
12651265

12661266
/// Get the number of stack operands
@@ -1343,7 +1343,7 @@ fn compute_jump_targets(iseq: *const rb_iseq_t) -> Vec<u32> {
13431343
let mut jump_targets = HashSet::new();
13441344
while insn_idx < iseq_size {
13451345
// Get the current pc and opcode
1346-
let pc = unsafe { rb_iseq_pc_at_idx(iseq, insn_idx.into()) };
1346+
let pc = unsafe { rb_iseq_pc_at_idx(iseq, insn_idx) };
13471347

13481348
// try_into() call below is unfortunate. Maybe pick i32 instead of usize for opcodes.
13491349
let opcode: u32 = unsafe { rb_iseq_opcode_at_pc(iseq, pc) }
@@ -1409,7 +1409,7 @@ pub fn iseq_to_hir(iseq: *const rb_iseq_t) -> Result<Function, ParseError> {
14091409
entry_state.locals.push(fun.push_insn(fun.entry_block, Insn::Const { val: Const::Value(Qnil) }));
14101410
}
14111411
}
1412-
queue.push_back((entry_state, fun.entry_block, /*insn_idx=*/0 as u32));
1412+
queue.push_back((entry_state, fun.entry_block, /*insn_idx=*/0_u32));
14131413

14141414
let mut visited = HashSet::new();
14151415

@@ -1438,7 +1438,7 @@ pub fn iseq_to_hir(iseq: *const rb_iseq_t) -> Result<Function, ParseError> {
14381438
while insn_idx < iseq_size {
14391439
state.insn_idx = insn_idx as usize;
14401440
// Get the current pc and opcode
1441-
let pc = unsafe { rb_iseq_pc_at_idx(iseq, insn_idx.into()) };
1441+
let pc = unsafe { rb_iseq_pc_at_idx(iseq, insn_idx) };
14421442
state.pc = pc;
14431443
let exit_state = state.clone();
14441444

zjit/src/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ pub extern "C" fn rb_zjit_init(options: *const u8) {
136136
unsafe { rb_zjit_enabled_p = true; }
137137
});
138138

139-
if let Err(_) = result {
139+
if result.is_err() {
140140
println!("ZJIT: zjit_init() panicked. Aborting.");
141141
std::process::abort();
142142
}

zjit/src/virtualmem.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ impl<A: Allocator> VirtualMemory<A> {
213213
unreachable!("unknown arch");
214214
}
215215
}
216-
self.mapped_region_bytes = self.mapped_region_bytes + alloc_size;
216+
self.mapped_region_bytes += alloc_size;
217217

218218
self.current_write_page = Some(page_addr);
219219
} else {

0 commit comments

Comments
 (0)