Skip to content

Commit e679a24

Browse files
committed
ZJIT: Move is_meta_class() from hir::Function to VALUE
`self` was unused.
1 parent 55f2a8d commit e679a24

2 files changed

Lines changed: 15 additions & 13 deletions

File tree

zjit/src/cruby.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,19 @@ impl VALUE {
475475
true
476476
}
477477

478+
/// A metaclass is the singleton class of an object that is a `Module`.
479+
/// This is internal terminology from `class.c`.
480+
pub fn is_metaclass(self) -> bool {
481+
unsafe {
482+
if RB_TYPE_P(self, RUBY_T_CLASS) && rb_zjit_singleton_class_p(self) {
483+
let attached = rb_class_attached_object(self);
484+
RB_TYPE_P(attached, RUBY_T_CLASS) || RB_TYPE_P(attached, RUBY_T_MODULE)
485+
} else {
486+
false
487+
}
488+
}
489+
}
490+
478491
/// Return true for a static (non-heap) Ruby symbol (RB_STATIC_SYM_P)
479492
pub fn static_sym_p(self) -> bool {
480493
let VALUE(cval) = self;

zjit/src/hir.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3078,17 +3078,6 @@ impl Function {
30783078
}
30793079
}
30803080

3081-
fn is_metaclass(&self, object: VALUE) -> bool {
3082-
unsafe {
3083-
if RB_TYPE_P(object, RUBY_T_CLASS) && rb_zjit_singleton_class_p(object) {
3084-
let attached = rb_class_attached_object(object);
3085-
RB_TYPE_P(attached, RUBY_T_CLASS) || RB_TYPE_P(attached, RUBY_T_MODULE)
3086-
} else {
3087-
false
3088-
}
3089-
}
3090-
}
3091-
30923081
pub fn load_rbasic_flags(&mut self, block: BlockId, recv: InsnId) -> InsnId {
30933082
self.push_insn(block, Insn::LoadField { recv, id: ID!(_rbasic_flags), offset: RUBY_OFFSET_RBASIC_FLAGS, return_type: types::CUInt64 })
30943083
}
@@ -3308,7 +3297,7 @@ impl Function {
33083297
} else if !has_block && def_type == VM_METHOD_TYPE_IVAR && args.is_empty() {
33093298
// Check if we're accessing ivars of a Class or Module object as they require single-ractor mode.
33103299
// We omit gen_prepare_non_leaf_call on gen_getivar, so it's unsafe to raise for multi-ractor mode.
3311-
if self.is_metaclass(klass) && !self.assume_single_ractor_mode(block, state) {
3300+
if klass.is_metaclass() && !self.assume_single_ractor_mode(block, state) {
33123301
self.push_insn_id(block, insn_id); continue;
33133302
}
33143303
// Check singleton class assumption first, before emitting other patchpoints
@@ -3328,7 +3317,7 @@ impl Function {
33283317
} else if let (false, VM_METHOD_TYPE_ATTRSET, &[val]) = (has_block, def_type, args.as_slice()) {
33293318
// Check if we're accessing ivars of a Class or Module object as they require single-ractor mode.
33303319
// We omit gen_prepare_non_leaf_call on gen_getivar, so it's unsafe to raise for multi-ractor mode.
3331-
if self.is_metaclass(klass) && !self.assume_single_ractor_mode(block, state) {
3320+
if klass.is_metaclass() && !self.assume_single_ractor_mode(block, state) {
33323321
self.push_insn_id(block, insn_id); continue;
33333322
}
33343323

0 commit comments

Comments
 (0)