diff options
| author | Max Bernstein <ruby@bernsteinbear.com> | 2026-03-25 09:59:31 -0400 |
|---|---|---|
| committer | Max Bernstein <tekknolagi@gmail.com> | 2026-03-25 14:02:09 -0400 |
| commit | 8514166d54eec6ecb5cb79d56d4ea6cf74d4a390 (patch) | |
| tree | efb74d9b85a81c263b18307729c4a5c958f786cf /zjit | |
| parent | be783db2c2bb73456f808291aa4f72fa02861641 (diff) | |
ZJIT: Adjust Type API for checking signedness
Diffstat (limited to 'zjit')
| -rw-r--r-- | zjit/src/hir.rs | 2 | ||||
| -rw-r--r-- | zjit/src/hir_type/mod.rs | 13 |
2 files changed, 14 insertions, 1 deletions
diff --git a/zjit/src/hir.rs b/zjit/src/hir.rs index f2e0218117..0891a59fa2 100644 --- a/zjit/src/hir.rs +++ b/zjit/src/hir.rs @@ -5296,7 +5296,7 @@ impl Function { } Insn::AdjustBounds { index, .. } => { // If index is known nonnegative, then we don't need to adjust bounds. - if self.type_of(index).cint64_value().filter(|&i| i >= 0).is_some() { + if self.type_of(index).known_nonnegative() { self.make_equal_to(insn_id, index); // Don't bother re-inferring the type of index; we already know it. continue; diff --git a/zjit/src/hir_type/mod.rs b/zjit/src/hir_type/mod.rs index e1e2c1a810..1e6c0d2df7 100644 --- a/zjit/src/hir_type/mod.rs +++ b/zjit/src/hir_type/mod.rs @@ -411,6 +411,19 @@ impl Type { } } + fn int_spec_signed(&self) -> Option<i64> { + assert!(self.is_subtype(types::CSigned), "int_spec_signed() only makes sense for signed integer types"); + match self.spec { + Specialization::Int(val) => Some(val as i64), + _ => None, + } + } + + pub fn known_nonnegative(&self) -> bool { + assert!(self.is_subtype(types::CSigned), "nonnegative() only makes sense for signed integer types"); + self.int_spec_signed().map_or(false, |val| val >= 0) + } + /// Return true if the Type has object specialization and false otherwise. pub fn ruby_object_known(&self) -> bool { matches!(self.spec, Specialization::Object(_)) |
