Skip to content

Commit 4f1a0a8

Browse files
committed
ZJIT: Support inference of ModuleExact type
1 parent 350df4f commit 4f1a0a8

4 files changed

Lines changed: 43 additions & 33 deletions

File tree

zjit/src/hir.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5797,7 +5797,7 @@ mod opt_tests {
57975797
}
57985798

57995799
#[test]
5800-
fn module_instances_not_class_exact() {
5800+
fn module_instances_are_module_exact() {
58015801
eval("
58025802
def test = [Enumerable, Kernel]
58035803
test # Warm the constant cache
@@ -5807,10 +5807,10 @@ mod opt_tests {
58075807
bb0(v0:BasicObject):
58085808
PatchPoint SingleRactorMode
58095809
PatchPoint StableConstantNames(0x1000, Enumerable)
5810-
v11:BasicObject[VALUE(0x1008)] = Const Value(VALUE(0x1008))
5810+
v11:ModuleExact[VALUE(0x1008)] = Const Value(VALUE(0x1008))
58115811
PatchPoint SingleRactorMode
58125812
PatchPoint StableConstantNames(0x1010, Kernel)
5813-
v14:BasicObject[VALUE(0x1018)] = Const Value(VALUE(0x1018))
5813+
v14:ModuleExact[VALUE(0x1018)] = Const Value(VALUE(0x1018))
58145814
v7:ArrayExact = NewArray v11, v14
58155815
Return v7
58165816
"#]]);
@@ -5943,7 +5943,7 @@ mod opt_tests {
59435943
bb0(v0:BasicObject):
59445944
PatchPoint SingleRactorMode
59455945
PatchPoint StableConstantNames(0x1000, Kernel)
5946-
v7:BasicObject[VALUE(0x1008)] = Const Value(VALUE(0x1008))
5946+
v7:ModuleExact[VALUE(0x1008)] = Const Value(VALUE(0x1008))
59475947
Return v7
59485948
"#]]);
59495949
}

zjit/src/hir_type/gen_hir_type.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ def base_type name
7575
base_type "Set"
7676
base_type "Regexp"
7777
base_type "Class"
78+
base_type "Module"
7879

7980
(integer, integer_exact) = base_type "Integer"
8081
# CRuby partitions Integer into immediate and non-immediate variants.

zjit/src/hir_type/hir_type.inc.rs

Lines changed: 31 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

zjit/src/hir_type/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![allow(non_upper_case_globals)]
2-
use crate::cruby::{Qfalse, Qnil, Qtrue, VALUE, RUBY_T_ARRAY, RUBY_T_STRING, RUBY_T_HASH, RUBY_T_CLASS};
2+
use crate::cruby::{Qfalse, Qnil, Qtrue, VALUE, RUBY_T_ARRAY, RUBY_T_STRING, RUBY_T_HASH, RUBY_T_CLASS, RUBY_T_MODULE};
33
use crate::cruby::{rb_cInteger, rb_cFloat, rb_cArray, rb_cHash, rb_cString, rb_cSymbol, rb_cObject, rb_cTrueClass, rb_cFalseClass, rb_cNilClass, rb_cRange, rb_cSet, rb_cRegexp, rb_cClass, rb_cModule};
44
use crate::cruby::ClassRelationship;
55
use crate::cruby::get_class_name;
@@ -145,11 +145,6 @@ fn is_range_exact(val: VALUE) -> bool {
145145
val.class_of() == unsafe { rb_cRange }
146146
}
147147

148-
fn is_class_exact(val: VALUE) -> bool {
149-
// Objects with RUBY_T_CLASS type and not instances of Module
150-
val.builtin_type() == RUBY_T_CLASS && val.class_of() != unsafe { rb_cModule }
151-
}
152-
153148
impl Type {
154149
/// Create a `Type` from the given integer.
155150
pub const fn fixnum(val: i64) -> Type {
@@ -202,7 +197,10 @@ impl Type {
202197
else if is_string_exact(val) {
203198
Type { bits: bits::StringExact, spec: Specialization::Object(val) }
204199
}
205-
else if is_class_exact(val) {
200+
else if val.builtin_type() == RUBY_T_MODULE {
201+
Type { bits: bits::ModuleExact, spec: Specialization::Object(val) }
202+
}
203+
else if val.builtin_type() == RUBY_T_CLASS {
206204
Type { bits: bits::ClassExact, spec: Specialization::Object(val) }
207205
}
208206
else if val.class_of() == unsafe { rb_cRegexp } {
@@ -301,6 +299,7 @@ impl Type {
301299
if class == unsafe { rb_cFloat } { return true; }
302300
if class == unsafe { rb_cHash } { return true; }
303301
if class == unsafe { rb_cInteger } { return true; }
302+
if class == unsafe { rb_cModule } { return true; }
304303
if class == unsafe { rb_cNilClass } { return true; }
305304
if class == unsafe { rb_cObject } { return true; }
306305
if class == unsafe { rb_cRange } { return true; }
@@ -410,6 +409,7 @@ impl Type {
410409
if self.is_subtype(types::FloatExact) { return Some(unsafe { rb_cFloat }); }
411410
if self.is_subtype(types::HashExact) { return Some(unsafe { rb_cHash }); }
412411
if self.is_subtype(types::IntegerExact) { return Some(unsafe { rb_cInteger }); }
412+
if self.is_subtype(types::ModuleExact) { return Some(unsafe { rb_cModule }); }
413413
if self.is_subtype(types::NilClassExact) { return Some(unsafe { rb_cNilClass }); }
414414
if self.is_subtype(types::ObjectExact) { return Some(unsafe { rb_cObject }); }
415415
if self.is_subtype(types::RangeExact) { return Some(unsafe { rb_cRange }); }

0 commit comments

Comments
 (0)