Skip to content

Commit 8de628d

Browse files
committed
ZJIT: s/as_usize/to_usize/ to comply with rust API guidelines
When the name is `as_*`, the guideline expects the return type to be a reference type. Also, it's good to have contrast in the naming from the more dangerous `as usize` cast `IntoUsize` is meant to be preferred over. See: https://rust-lang.github.io/api-guidelines/naming.html
1 parent c2bce54 commit 8de628d

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

zjit/src/cast.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,35 @@
1616
/// the method `into()` also causes a name conflict.
1717
pub(crate) trait IntoUsize {
1818
/// Convert to usize. Implementation conditional on width of [usize].
19-
fn as_usize(self) -> usize;
19+
fn to_usize(self) -> usize;
2020
}
2121

2222
#[cfg(target_pointer_width = "64")]
2323
impl IntoUsize for u64 {
24-
fn as_usize(self) -> usize {
24+
fn to_usize(self) -> usize {
2525
self as usize
2626
}
2727
}
2828

2929
#[cfg(target_pointer_width = "64")]
3030
impl IntoUsize for u32 {
31-
fn as_usize(self) -> usize {
31+
fn to_usize(self) -> usize {
3232
self as usize
3333
}
3434
}
3535

3636
impl IntoUsize for u16 {
3737
/// Alias for `.into()`. For convenience so you could use the trait for
3838
/// all unsgined types.
39-
fn as_usize(self) -> usize {
39+
fn to_usize(self) -> usize {
4040
self.into()
4141
}
4242
}
4343

4444
impl IntoUsize for u8 {
4545
/// Alias for `.into()`. For convenience so you could use the trait for
4646
/// all unsgined types.
47-
fn as_usize(self) -> usize {
47+
fn to_usize(self) -> usize {
4848
self.into()
4949
}
5050
}

zjit/src/codegen.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ fn gen_ccall_with_frame(
736736
});
737737

738738
asm_comment!(asm, "switch to new SP register");
739-
let sp_offset = (caller_stack_size + VM_ENV_DATA_SIZE.as_usize()) * SIZEOF_VALUE;
739+
let sp_offset = (caller_stack_size + VM_ENV_DATA_SIZE.to_usize()) * SIZEOF_VALUE;
740740
let new_sp = asm.add(SP, sp_offset.into());
741741
asm.mov(SP, new_sp);
742742

@@ -792,7 +792,7 @@ fn gen_ccall_variadic(
792792
});
793793

794794
asm_comment!(asm, "switch to new SP register");
795-
let sp_offset = (state.stack().len() - args.len() + VM_ENV_DATA_SIZE.as_usize()) * SIZEOF_VALUE;
795+
let sp_offset = (state.stack().len() - args.len() + VM_ENV_DATA_SIZE.to_usize()) * SIZEOF_VALUE;
796796
let new_sp = asm.add(SP, sp_offset.into());
797797
asm.mov(SP, new_sp);
798798

@@ -975,7 +975,7 @@ fn gen_load_ivar_embedded(asm: &mut Assembler, self_val: Opnd, id: ID, index: u1
975975
// See ROBJECT_FIELDS() from include/ruby/internal/core/robject.h
976976

977977
asm_comment!(asm, "Load embedded ivar id={} index={}", id.contents_lossy(), index);
978-
let offs = ROBJECT_OFFSET_AS_ARY as i32 + (SIZEOF_VALUE * index.as_usize()) as i32;
978+
let offs = ROBJECT_OFFSET_AS_ARY as i32 + (SIZEOF_VALUE * index.to_usize()) as i32;
979979
let self_val = asm.load(self_val);
980980
let ivar_opnd = Opnd::mem(64, self_val, offs);
981981
asm.load(ivar_opnd)
@@ -990,7 +990,7 @@ fn gen_load_ivar_extended(asm: &mut Assembler, self_val: Opnd, id: ID, index: u1
990990
let tbl_opnd = asm.load(Opnd::mem(64, self_val, ROBJECT_OFFSET_AS_HEAP_FIELDS as i32));
991991

992992
// Read the ivar from the extended table
993-
let ivar_opnd = Opnd::mem(64, tbl_opnd, (SIZEOF_VALUE * index.as_usize()) as i32);
993+
let ivar_opnd = Opnd::mem(64, tbl_opnd, (SIZEOF_VALUE * index.to_usize()) as i32);
994994
asm.load(ivar_opnd)
995995
}
996996

@@ -1174,8 +1174,8 @@ fn gen_send_without_block_direct(
11741174
) -> lir::Opnd {
11751175
gen_incr_counter(asm, Counter::iseq_optimized_send_count);
11761176

1177-
let local_size = unsafe { get_iseq_body_local_table_size(iseq) }.as_usize();
1178-
let stack_growth = state.stack_size() + local_size + unsafe { get_iseq_body_stack_max(iseq) }.as_usize();
1177+
let local_size = unsafe { get_iseq_body_local_table_size(iseq) }.to_usize();
1178+
let stack_growth = state.stack_size() + local_size + unsafe { get_iseq_body_stack_max(iseq) }.to_usize();
11791179
gen_stack_overflow_check(jit, asm, state, stack_growth);
11801180

11811181
// Save cfp->pc and cfp->sp for the caller frame
@@ -1211,7 +1211,7 @@ fn gen_send_without_block_direct(
12111211
});
12121212

12131213
asm_comment!(asm, "switch to new SP register");
1214-
let sp_offset = (state.stack().len() + local_size - args.len() + VM_ENV_DATA_SIZE.as_usize()) * SIZEOF_VALUE;
1214+
let sp_offset = (state.stack().len() + local_size - args.len() + VM_ENV_DATA_SIZE.to_usize()) * SIZEOF_VALUE;
12151215
let new_sp = asm.add(SP, sp_offset.into());
12161216
asm.mov(SP, new_sp);
12171217

@@ -1889,7 +1889,7 @@ fn param_opnd(idx: usize) -> Opnd {
18891889
/// Inverse of ep_offset_to_local_idx(). See ep_offset_to_local_idx() for details.
18901890
pub fn local_idx_to_ep_offset(iseq: IseqPtr, local_idx: usize) -> i32 {
18911891
let local_size = unsafe { get_iseq_body_local_table_size(iseq) };
1892-
local_size_and_idx_to_ep_offset(local_size.as_usize(), local_idx)
1892+
local_size_and_idx_to_ep_offset(local_size.to_usize(), local_idx)
18931893
}
18941894

18951895
/// Convert the number of locals and a local index to an offset from the EP
@@ -2005,8 +2005,8 @@ c_callable! {
20052005
rb_set_cfp_sp(cfp, sp);
20062006

20072007
// Fill nils to uninitialized (non-argument) locals
2008-
let local_size = get_iseq_body_local_table_size(iseq).as_usize();
2009-
let num_params = get_iseq_body_param_size(iseq).as_usize();
2008+
let local_size = get_iseq_body_local_table_size(iseq).to_usize();
2009+
let num_params = get_iseq_body_param_size(iseq).to_usize();
20102010
let base = sp.offset(-local_size_and_idx_to_bp_offset(local_size, num_params) as isize);
20112011
slice::from_raw_parts_mut(base, local_size - num_params).fill(Qnil);
20122012
}

zjit/src/hir.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1873,7 +1873,7 @@ impl Function {
18731873
/// Set self.param_types. They are copied to the param types of jit_entry_blocks.
18741874
fn set_param_types(&mut self) {
18751875
let iseq = self.iseq;
1876-
let param_size = unsafe { get_iseq_body_param_size(iseq) }.as_usize();
1876+
let param_size = unsafe { get_iseq_body_param_size(iseq) }.to_usize();
18771877
let rest_param_idx = iseq_rest_param_idx(iseq);
18781878

18791879
self.param_types.push(types::BasicObject); // self
@@ -3885,7 +3885,7 @@ pub enum ParseError {
38853885

38863886
/// Return the number of locals in the current ISEQ (includes parameters)
38873887
fn num_locals(iseq: *const rb_iseq_t) -> usize {
3888-
(unsafe { get_iseq_body_local_table_size(iseq) }).as_usize()
3888+
(unsafe { get_iseq_body_local_table_size(iseq) }).to_usize()
38893889
}
38903890

38913891
/// If we can't handle the type of send (yet), bail out.
@@ -4896,7 +4896,7 @@ fn compile_entry_block(fun: &mut Function, jit_entry_insns: &[u32]) {
48964896
/// Compile initial locals for an entry_block for the interpreter
48974897
fn compile_entry_state(fun: &mut Function, entry_block: BlockId) -> (InsnId, FrameState) {
48984898
let iseq = fun.iseq;
4899-
let param_size = unsafe { get_iseq_body_param_size(iseq) }.as_usize();
4899+
let param_size = unsafe { get_iseq_body_param_size(iseq) }.to_usize();
49004900
let rest_param_idx = iseq_rest_param_idx(iseq);
49014901

49024902
let self_param = fun.push_insn(entry_block, Insn::LoadSelf);
@@ -4929,7 +4929,7 @@ fn compile_jit_entry_block(fun: &mut Function, jit_entry_idx: usize, target_bloc
49294929
/// Compile params and initial locals for a jit_entry_block
49304930
fn compile_jit_entry_state(fun: &mut Function, jit_entry_block: BlockId) -> (InsnId, FrameState) {
49314931
let iseq = fun.iseq;
4932-
let param_size = unsafe { get_iseq_body_param_size(iseq) }.as_usize();
4932+
let param_size = unsafe { get_iseq_body_param_size(iseq) }.to_usize();
49334933

49344934
let self_param = fun.push_insn(jit_entry_block, Insn::Param);
49354935
let mut entry_state = FrameState::new(iseq);

0 commit comments

Comments
 (0)