summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--zjit/src/cruby_methods.rs3
-rw-r--r--zjit/src/hir.rs27
2 files changed, 30 insertions, 0 deletions
diff --git a/zjit/src/cruby_methods.rs b/zjit/src/cruby_methods.rs
index 77fd22fcd0..bc8f1d3b84 100644
--- a/zjit/src/cruby_methods.rs
+++ b/zjit/src/cruby_methods.rs
@@ -165,6 +165,7 @@ pub fn init() -> Annotations {
$(
props.$properties = true;
)*
+ #[allow(unused_unsafe)]
annotate_c_method(cfuncs, unsafe { $module }, $method_name, props);
}
}
@@ -204,6 +205,8 @@ pub fn init() -> Annotations {
annotate!(rb_cBasicObject, "!", types::BoolExact, no_gc, leaf, elidable);
annotate!(rb_cBasicObject, "initialize", types::NilClass, no_gc, leaf, elidable);
annotate!(rb_cString, "to_s", inline_string_to_s);
+ let thread_singleton = unsafe { rb_singleton_class(rb_cThread) };
+ annotate!(thread_singleton, "current", types::BasicObject, no_gc, leaf);
annotate_builtin!(rb_mKernel, "Float", types::Float);
annotate_builtin!(rb_mKernel, "Integer", types::Integer);
diff --git a/zjit/src/hir.rs b/zjit/src/hir.rs
index 2c07c21ac9..a032d9ec8a 100644
--- a/zjit/src/hir.rs
+++ b/zjit/src/hir.rs
@@ -12790,4 +12790,31 @@ mod opt_tests {
Return v30
");
}
+
+ #[test]
+ fn test_optimize_thread_current() {
+ eval("
+ def test = Thread.current
+ test
+ ");
+ assert_snapshot!(hir_string("test"), @r"
+ fn test@<compiled>:2:
+ bb0():
+ EntryPoint interpreter
+ v1:BasicObject = LoadSelf
+ Jump bb2(v1)
+ bb1(v4:BasicObject):
+ EntryPoint JIT(0)
+ Jump bb2(v4)
+ bb2(v6:BasicObject):
+ PatchPoint SingleRactorMode
+ PatchPoint StableConstantNames(0x1000, Thread)
+ v21:Class[VALUE(0x1008)] = Const Value(VALUE(0x1008))
+ PatchPoint MethodRedefined(Class@0x1010, current@0x1018, cme:0x1020)
+ PatchPoint NoSingletonClass(Class@0x1010)
+ v25:BasicObject = CCall current@0x1048, v21
+ CheckInterrupts
+ Return v25
+ ");
+ }
}