Skip to content

Commit 590dae7

Browse files
tekknolagijhawthornluke-gruber
committed
ZJIT: Constant fold IsA
Co-authored-by: John Hawthorn <john.hawthorn@shopify.com> Co-authored-by: Luke Gruber <luke.gruber@shopify.com>
1 parent 8e52bd1 commit 590dae7

6 files changed

Lines changed: 438 additions & 351 deletions

File tree

zjit/src/hir.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4679,6 +4679,24 @@ impl Function {
46794679
// Don't bother re-inferring the type of str; we already know it.
46804680
continue;
46814681
}
4682+
Insn::IsA { val, class } => 'is_a: {
4683+
let class_type = self.type_of(class);
4684+
if !class_type.is_subtype(types::Class) {
4685+
break 'is_a insn_id;
4686+
}
4687+
let Some(class_value) = class_type.ruby_object() else {
4688+
break 'is_a insn_id;
4689+
};
4690+
let val_type = self.type_of(val);
4691+
let the_class = Type::from_class_inexact(class_value);
4692+
if val_type.is_subtype(the_class) {
4693+
self.new_insn(Insn::Const { val: Const::Value(Qtrue) })
4694+
} else if !val_type.could_be(the_class) {
4695+
self.new_insn(Insn::Const { val: Const::Value(Qfalse) })
4696+
} else {
4697+
insn_id
4698+
}
4699+
}
46824700
Insn::FixnumAdd { left, right, .. } => {
46834701
self.fold_fixnum_bop(insn_id, left, right, |l, r| match (l, r) {
46844702
(Some(l), Some(r)) => l.checked_add(r),

0 commit comments

Comments
 (0)