From 94a8feaa0110a9c9928a46af2309ab3fd3abf689 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20Hasi=C5=84ski?= Date: Sat, 11 Apr 2026 22:53:18 +0200 Subject: ZJIT: Annotate Float and Integer predicates Adds method annotations so ZJIT can emit the fast CCall path for pure Float cfunc predicates and propagate return types for numeric builtin predicates. Float cfuncs (leaf, no_gc, elidable): nan?, finite? BoolExact infinite? Fixnum | NilClass Integer/Float builtins (BoolExact return type): Integer#zero?, even?, odd? Float#zero?, positive?, negative? All targeted C bodies are pure (isnan/isfinite/isinf, FIXNUM bit tests, FLOAT_ZERO_P) so the annotations are safe. Microbench with --zjit-call-threshold=2, tight while loop, 20M iters: Float#nan? 0.140s -> 0.110s (~21%) Float#finite? 0.145s -> 0.114s (~21%) Float#infinite? 0.129s -> 0.094s (~27%) --- zjit/src/cruby_methods.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/zjit/src/cruby_methods.rs b/zjit/src/cruby_methods.rs index e104a0f320..96db1386f1 100644 --- a/zjit/src/cruby_methods.rs +++ b/zjit/src/cruby_methods.rs @@ -266,9 +266,18 @@ pub fn init() -> Annotations { annotate!(rb_cInteger, "[]", inline_integer_aref); annotate!(rb_cInteger, "to_s", types::StringExact); annotate!(rb_cString, "to_s", inline_string_to_s, types::StringExact); + annotate!(rb_cFloat, "nan?", types::BoolExact, no_gc, leaf, elidable); + annotate!(rb_cFloat, "finite?", types::BoolExact, no_gc, leaf, elidable); + annotate!(rb_cFloat, "infinite?", types::Fixnum.union(types::NilClass), no_gc, leaf, elidable); let thread_singleton = unsafe { rb_singleton_class(rb_cThread) }; annotate!(thread_singleton, "current", inline_thread_current, types::BasicObject, no_gc, leaf); + annotate_builtin!(rb_cInteger, "zero?", types::BoolExact); + annotate_builtin!(rb_cInteger, "even?", types::BoolExact); + annotate_builtin!(rb_cInteger, "odd?", types::BoolExact); + annotate_builtin!(rb_cFloat, "zero?", types::BoolExact); + annotate_builtin!(rb_cFloat, "positive?", types::BoolExact); + annotate_builtin!(rb_cFloat, "negative?", types::BoolExact); annotate_builtin!(rb_mKernel, "Float", types::Float); annotate_builtin!(rb_mKernel, "Integer", types::Integer); // TODO(max): Annotate rb_mKernel#class as returning types::Class. Right now there is a subtle -- cgit v1.2.3