Skip to content

Commit 08396d0

Browse files
committed
ZJIT: Support Regexp type
1 parent f4ea42a commit 08396d0

6 files changed

Lines changed: 45 additions & 15 deletions

File tree

zjit/bindgen/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ fn main() {
188188
.allowlist_var("rb_cHash")
189189
.allowlist_var("rb_cSet")
190190
.allowlist_var("rb_cClass")
191+
.allowlist_var("rb_cRegexp")
191192
.allowlist_var("rb_cISeq")
192193

193194
// From include/ruby/internal/fl_type.h

zjit/src/cruby_bindings.inc.rs

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

zjit/src/hir.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6310,4 +6310,18 @@ mod opt_tests {
63106310
Return v7
63116311
"#]]);
63126312
}
6313+
6314+
#[test]
6315+
fn test_regexp_type() {
6316+
eval("
6317+
def test = /a/
6318+
test
6319+
");
6320+
assert_optimized_method_hir("test", expect![[r#"
6321+
fn test:
6322+
bb0(v0:BasicObject):
6323+
v2:RegexpExact[VALUE(0x1000)] = Const Value(VALUE(0x1000))
6324+
Return v2
6325+
"#]]);
6326+
}
63136327
}

zjit/src/hir_type/gen_hir_type.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ def base_type name
7373
base_type "Hash"
7474
base_type "Range"
7575
base_type "Set"
76+
base_type "Regexp"
7677

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

zjit/src/hir_type/hir_type.inc.rs

Lines changed: 23 additions & 14 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: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![allow(non_upper_case_globals)]
22
use crate::cruby::{Qfalse, Qnil, Qtrue, VALUE, RUBY_T_ARRAY, RUBY_T_STRING, RUBY_T_HASH};
3-
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};
3+
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};
44
use crate::cruby::ClassRelationship;
55
use crate::cruby::get_class_name;
66
use crate::cruby::ruby_sym_to_rust_string;
@@ -197,6 +197,9 @@ impl Type {
197197
else if is_string_exact(val) {
198198
Type { bits: bits::StringExact, spec: Specialization::Object(val) }
199199
}
200+
else if val.class_of() == unsafe { rb_cRegexp } {
201+
Type { bits: bits::RegexpExact, spec: Specialization::Object(val) }
202+
}
200203
else if val.class_of() == unsafe { rb_cSet } {
201204
Type { bits: bits::SetExact, spec: Specialization::Object(val) }
202205
}
@@ -292,6 +295,7 @@ impl Type {
292295
if class == unsafe { rb_cNilClass } { return true; }
293296
if class == unsafe { rb_cObject } { return true; }
294297
if class == unsafe { rb_cRange } { return true; }
298+
if class == unsafe { rb_cRegexp } { return true; }
295299
if class == unsafe { rb_cString } { return true; }
296300
if class == unsafe { rb_cSymbol } { return true; }
297301
if class == unsafe { rb_cTrueClass } { return true; }

0 commit comments

Comments
 (0)