Skip to content

Commit d144272

Browse files
authored
ZJIT: Don't push Ruby frame for Thread#current (ruby#14832)
Fix Shopify#795
1 parent de31017 commit d144272

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

zjit/src/cruby_methods.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ pub fn init() -> Annotations {
165165
$(
166166
props.$properties = true;
167167
)*
168+
#[allow(unused_unsafe)]
168169
annotate_c_method(cfuncs, unsafe { $module }, $method_name, props);
169170
}
170171
}
@@ -204,6 +205,8 @@ pub fn init() -> Annotations {
204205
annotate!(rb_cBasicObject, "!", types::BoolExact, no_gc, leaf, elidable);
205206
annotate!(rb_cBasicObject, "initialize", types::NilClass, no_gc, leaf, elidable);
206207
annotate!(rb_cString, "to_s", inline_string_to_s);
208+
let thread_singleton = unsafe { rb_singleton_class(rb_cThread) };
209+
annotate!(thread_singleton, "current", types::BasicObject, no_gc, leaf);
207210

208211
annotate_builtin!(rb_mKernel, "Float", types::Float);
209212
annotate_builtin!(rb_mKernel, "Integer", types::Integer);

zjit/src/hir.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12790,4 +12790,31 @@ mod opt_tests {
1279012790
Return v30
1279112791
");
1279212792
}
12793+
12794+
#[test]
12795+
fn test_optimize_thread_current() {
12796+
eval("
12797+
def test = Thread.current
12798+
test
12799+
");
12800+
assert_snapshot!(hir_string("test"), @r"
12801+
fn test@<compiled>:2:
12802+
bb0():
12803+
EntryPoint interpreter
12804+
v1:BasicObject = LoadSelf
12805+
Jump bb2(v1)
12806+
bb1(v4:BasicObject):
12807+
EntryPoint JIT(0)
12808+
Jump bb2(v4)
12809+
bb2(v6:BasicObject):
12810+
PatchPoint SingleRactorMode
12811+
PatchPoint StableConstantNames(0x1000, Thread)
12812+
v21:Class[VALUE(0x1008)] = Const Value(VALUE(0x1008))
12813+
PatchPoint MethodRedefined(Class@0x1010, current@0x1018, cme:0x1020)
12814+
PatchPoint NoSingletonClass(Class@0x1010)
12815+
v25:BasicObject = CCall current@0x1048, v21
12816+
CheckInterrupts
12817+
Return v25
12818+
");
12819+
}
1279312820
}

0 commit comments

Comments
 (0)