Skip to content

Commit 77b019f

Browse files
st0012XrXr
andauthored
ZJIT: Use type alias for num-profile and call-threshold's types (ruby#14777)
Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>
1 parent 40d704a commit 77b019f

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

zjit/src/options.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,26 @@ use crate::cruby::*;
66
use std::collections::HashSet;
77

88
/// Default --zjit-num-profiles
9-
const DEFAULT_NUM_PROFILES: u32 = 5;
9+
const DEFAULT_NUM_PROFILES: NumProfiles = 5;
10+
pub type NumProfiles = u32;
1011

1112
/// Default --zjit-call-threshold. This should be large enough to avoid compiling
1213
/// warmup code, but small enough to perform well on micro-benchmarks.
13-
pub const DEFAULT_CALL_THRESHOLD: u64 = 30;
14+
pub const DEFAULT_CALL_THRESHOLD: CallThreshold = 30;
15+
pub type CallThreshold = u64;
1416

1517
/// Number of calls to start profiling YARV instructions.
1618
/// They are profiled `rb_zjit_call_threshold - rb_zjit_profile_threshold` times,
1719
/// which is equal to --zjit-num-profiles.
1820
#[unsafe(no_mangle)]
1921
#[allow(non_upper_case_globals)]
20-
pub static mut rb_zjit_profile_threshold: u64 = DEFAULT_CALL_THRESHOLD - DEFAULT_NUM_PROFILES as u64;
22+
pub static mut rb_zjit_profile_threshold: CallThreshold = DEFAULT_CALL_THRESHOLD - DEFAULT_NUM_PROFILES as CallThreshold;
2123

2224
/// Number of calls to compile ISEQ with ZJIT at jit_compile() in vm.c.
2325
/// --zjit-call-threshold=1 compiles on first execution without profiling information.
2426
#[unsafe(no_mangle)]
2527
#[allow(non_upper_case_globals)]
26-
pub static mut rb_zjit_call_threshold: u64 = DEFAULT_CALL_THRESHOLD;
28+
pub static mut rb_zjit_call_threshold: CallThreshold = DEFAULT_CALL_THRESHOLD;
2729

2830
/// ZJIT command-line options. This is set before rb_zjit_init() sets
2931
/// ZJITState so that we can query some options while loading builtins.
@@ -40,7 +42,7 @@ pub struct Options {
4042
pub mem_bytes: usize,
4143

4244
/// Number of times YARV instructions should be profiled.
43-
pub num_profiles: u32,
45+
pub num_profiles: NumProfiles,
4446

4547
/// Enable YJIT statsitics
4648
pub stats: bool,
@@ -319,14 +321,14 @@ fn update_profile_threshold() {
319321
unsafe { rb_zjit_profile_threshold = 0; }
320322
} else {
321323
// Otherwise, profile instructions at least once.
322-
let num_profiles = get_option!(num_profiles) as u64;
323-
unsafe { rb_zjit_profile_threshold = rb_zjit_call_threshold.saturating_sub(num_profiles).max(1) };
324+
let num_profiles = get_option!(num_profiles);
325+
unsafe { rb_zjit_profile_threshold = rb_zjit_call_threshold.saturating_sub(num_profiles.into()).max(1) };
324326
}
325327
}
326328

327329
/// Update --zjit-call-threshold for testing
328330
#[cfg(test)]
329-
pub fn set_call_threshold(call_threshold: u64) {
331+
pub fn set_call_threshold(call_threshold: CallThreshold) {
330332
unsafe { rb_zjit_call_threshold = call_threshold; }
331333
rb_zjit_prepare_options();
332334
update_profile_threshold();

zjit/src/profile.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// We use the YARV bytecode constants which have a CRuby-style name
44
#![allow(non_upper_case_globals)]
55

6-
use crate::{cruby::*, gc::get_or_create_iseq_payload, options::get_option};
6+
use crate::{cruby::*, gc::get_or_create_iseq_payload, options::{get_option, NumProfiles}};
77
use crate::distribution::{Distribution, DistributionSummary};
88
use crate::stats::Counter::profile_time_ns;
99
use crate::stats::with_time_stat;
@@ -278,7 +278,7 @@ pub struct IseqProfile {
278278
opnd_types: Vec<Vec<TypeDistribution>>,
279279

280280
/// Number of profiled executions for each YARV instruction, indexed by the instruction index
281-
num_profiles: Vec<u32>,
281+
num_profiles: Vec<NumProfiles>,
282282
}
283283

284284
impl IseqProfile {

0 commit comments

Comments
 (0)