Skip to content

Commit dae2aea

Browse files
committed
Annotate Regexp#casefold?
1 parent 08396d0 commit dae2aea

3 files changed

Lines changed: 40 additions & 3 deletions

File tree

test/ruby/test_zjit.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,26 @@ def test(x)
840840
}, call_threshold: 1, insns: [:branchnil]
841841
end
842842

843+
def test_regexp_casefold_true
844+
assert_compiles 'true', %q{
845+
def test
846+
/hello/i.casefold?
847+
end
848+
test
849+
test
850+
}
851+
end
852+
853+
def test_regexp_casefold_false
854+
assert_compiles 'false', %q{
855+
def test
856+
/hello/.casefold?
857+
end
858+
test
859+
test
860+
}
861+
end
862+
843863
# tool/ruby_vm/views/*.erb relies on the zjit instructions a) being contiguous and
844864
# b) being reliably ordered after all the other instructions.
845865
def test_instruction_order

zjit/src/cruby_methods.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ pub fn init() -> Annotations {
8080
annotate!(rb_cModule, "===", types::BoolExact, no_gc, leaf);
8181
annotate!(rb_cArray, "length", types::Fixnum, no_gc, leaf, elidable);
8282
annotate!(rb_cArray, "size", types::Fixnum, no_gc, leaf, elidable);
83+
annotate!(rb_cRegexp, "casefold?", types::BoolExact, no_gc, leaf, elidable);
8384

8485
Annotations {
8586
cfuncs: std::mem::take(cfuncs)

zjit/src/hir.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4620,6 +4620,19 @@ mod tests {
46204620
SideExit
46214621
"#]]);
46224622
}
4623+
4624+
#[test]
4625+
fn test_regexp_type() {
4626+
eval("
4627+
def test = /a/
4628+
");
4629+
assert_method_hir("test", expect![[r#"
4630+
fn test:
4631+
bb0(v0:BasicObject):
4632+
v2:RegexpExact[VALUE(0x1000)] = Const Value(VALUE(0x1000))
4633+
Return v2
4634+
"#]]);
4635+
}
46234636
}
46244637

46254638
#[cfg(test)]
@@ -6312,16 +6325,19 @@ mod opt_tests {
63126325
}
63136326

63146327
#[test]
6315-
fn test_regexp_type() {
6328+
fn test_regexp_casefold() {
63166329
eval("
6317-
def test = /a/
6330+
def test = /hello/i.casefold?
6331+
test
63186332
test
63196333
");
63206334
assert_optimized_method_hir("test", expect![[r#"
63216335
fn test:
63226336
bb0(v0:BasicObject):
63236337
v2:RegexpExact[VALUE(0x1000)] = Const Value(VALUE(0x1000))
6324-
Return v2
6338+
PatchPoint MethodRedefined(Regexp@0x1008, casefold?@0x1010)
6339+
v7:BoolExact = CCall casefold?@0x1018, v2
6340+
Return v7
63256341
"#]]);
63266342
}
63276343
}

0 commit comments

Comments
 (0)