Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions zjit/src/cruby_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ pub fn init() -> Annotations {
annotate!(rb_mKernel, "itself", inline_kernel_itself);
annotate!(rb_mKernel, "block_given?", inline_kernel_block_given_p);
annotate!(rb_cString, "bytesize", types::Fixnum, no_gc, leaf);
annotate!(rb_cString, "bytesize", types::Fixnum, no_gc, leaf, elidable);
annotate!(rb_cString, "size", types::Fixnum, no_gc, leaf, elidable);
annotate!(rb_cString, "length", types::Fixnum, no_gc, leaf, elidable);
annotate!(rb_cString, "to_s", types::StringExact);
annotate!(rb_cString, "getbyte", inline_string_getbyte);
annotate!(rb_cString, "empty?", types::BoolExact, no_gc, leaf, elidable);
Expand Down
177 changes: 177 additions & 0 deletions zjit/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15499,4 +15499,181 @@ mod opt_tests {
Return v28
");
}

#[test]
fn test_specialize_string_size() {
eval(r#"
def test(s)
s.size
end
test("asdf")
"#);
assert_snapshot!(hir_string("test"), @r"
fn test@<compiled>:3:
bb0():
EntryPoint interpreter
v1:BasicObject = LoadSelf
v2:BasicObject = GetLocal l0, SP@4
Jump bb2(v1, v2)
bb1(v5:BasicObject, v6:BasicObject):
EntryPoint JIT(0)
Jump bb2(v5, v6)
bb2(v8:BasicObject, v9:BasicObject):
PatchPoint MethodRedefined(String@0x1000, size@0x1008, cme:0x1010)
PatchPoint NoSingletonClass(String@0x1000)
v25:StringExact = GuardType v9, StringExact
IncrCounter inline_cfunc_optimized_send_count
v27:Fixnum = CCall size@0x1038, v25
CheckInterrupts
Return v27
");
}

#[test]
fn test_elide_string_size() {
eval(r#"
def test(s)
s.size
5
end
test("asdf")
"#);
assert_snapshot!(hir_string("test"), @r"
fn test@<compiled>:3:
bb0():
EntryPoint interpreter
v1:BasicObject = LoadSelf
v2:BasicObject = GetLocal l0, SP@4
Jump bb2(v1, v2)
bb1(v5:BasicObject, v6:BasicObject):
EntryPoint JIT(0)
Jump bb2(v5, v6)
bb2(v8:BasicObject, v9:BasicObject):
PatchPoint MethodRedefined(String@0x1000, size@0x1008, cme:0x1010)
PatchPoint NoSingletonClass(String@0x1000)
v28:StringExact = GuardType v9, StringExact
IncrCounter inline_cfunc_optimized_send_count
v19:Fixnum[5] = Const Value(5)
CheckInterrupts
Return v19
");
}

#[test]
fn test_specialize_string_bytesize() {
eval(r#"
def test(s)
s.bytesize
end
test("asdf")
"#);
assert_snapshot!(hir_string("test"), @r"
fn test@<compiled>:3:
bb0():
EntryPoint interpreter
v1:BasicObject = LoadSelf
v2:BasicObject = GetLocal l0, SP@4
Jump bb2(v1, v2)
bb1(v5:BasicObject, v6:BasicObject):
EntryPoint JIT(0)
Jump bb2(v5, v6)
bb2(v8:BasicObject, v9:BasicObject):
PatchPoint MethodRedefined(String@0x1000, bytesize@0x1008, cme:0x1010)
PatchPoint NoSingletonClass(String@0x1000)
v23:StringExact = GuardType v9, StringExact
IncrCounter inline_cfunc_optimized_send_count
v25:Fixnum = CCall bytesize@0x1038, v23
CheckInterrupts
Return v25
");
}

#[test]
fn test_elide_string_bytesize() {
eval(r#"
def test(s)
s.bytesize
5
end
test("asdf")
"#);
assert_snapshot!(hir_string("test"), @r"
fn test@<compiled>:3:
bb0():
EntryPoint interpreter
v1:BasicObject = LoadSelf
v2:BasicObject = GetLocal l0, SP@4
Jump bb2(v1, v2)
bb1(v5:BasicObject, v6:BasicObject):
EntryPoint JIT(0)
Jump bb2(v5, v6)
bb2(v8:BasicObject, v9:BasicObject):
PatchPoint MethodRedefined(String@0x1000, bytesize@0x1008, cme:0x1010)
PatchPoint NoSingletonClass(String@0x1000)
v26:StringExact = GuardType v9, StringExact
IncrCounter inline_cfunc_optimized_send_count
v17:Fixnum[5] = Const Value(5)
CheckInterrupts
Return v17
");
}

#[test]
fn test_specialize_string_length() {
eval(r#"
def test(s)
s.length
end
test("asdf")
"#);
assert_snapshot!(hir_string("test"), @r"
fn test@<compiled>:3:
bb0():
EntryPoint interpreter
v1:BasicObject = LoadSelf
v2:BasicObject = GetLocal l0, SP@4
Jump bb2(v1, v2)
bb1(v5:BasicObject, v6:BasicObject):
EntryPoint JIT(0)
Jump bb2(v5, v6)
bb2(v8:BasicObject, v9:BasicObject):
PatchPoint MethodRedefined(String@0x1000, length@0x1008, cme:0x1010)
PatchPoint NoSingletonClass(String@0x1000)
v25:StringExact = GuardType v9, StringExact
IncrCounter inline_cfunc_optimized_send_count
v27:Fixnum = CCall length@0x1038, v25
CheckInterrupts
Return v27
");
}

#[test]
fn test_elide_string_length() {
eval(r#"
def test(s)
s.length
4
end
test("this should get removed")
"#);
assert_snapshot!(hir_string("test"), @r"
fn test@<compiled>:3:
bb0():
EntryPoint interpreter
v1:BasicObject = LoadSelf
v2:BasicObject = GetLocal l0, SP@4
Jump bb2(v1, v2)
bb1(v5:BasicObject, v6:BasicObject):
EntryPoint JIT(0)
Jump bb2(v5, v6)
bb2(v8:BasicObject, v9:BasicObject):
PatchPoint MethodRedefined(String@0x1000, length@0x1008, cme:0x1010)
PatchPoint NoSingletonClass(String@0x1000)
v28:StringExact = GuardType v9, StringExact
IncrCounter inline_cfunc_optimized_send_count
v19:Fixnum[4] = Const Value(4)
CheckInterrupts
Return v19
");
}
}