[pull] master from ruby:master#937
Merged
pull[bot] merged 8 commits intoturkdevops:masterfrom Apr 16, 2026
Merged
Conversation
* ZJIT: Fix getlocal with level=0 reading stale EP data YARVINSN_getlocal always loaded from EP memory, even for level=0 locals. But setlocal_WC_0 only updates the JIT's FrameState without writing to EP. When the Ruby compiler emits getlocal (non-WC variant) for a level=0 local after setlocal_WC_0, the EP load returned stale data. This caused Array#pack with buffer: keyword to silently lose the buffer argument when the array contained local variable references, because the buffer VALUE read from EP was nil/stale instead of the actual string. Fix: when level=0 and locals are not invalidated, use the FrameState value (same optimization as getlocal_WC_0). This matches what setlocal_WC_0 writes to. * ZJIT: Add regression test for getlocal level=0 fix Verify that Array#pack with a buffer: keyword reads the correct buffer VALUE when the buffer is a local variable set via setlocal_WC_0 and read via getlocal (non-WC variant). Before the fix, this returned b.size == 1 (stale EP data) instead of 2 (buffer updated by pack).
Add FloatAdd, FloatSub, FloatMul, FloatDiv HIR instructions that lower to gen_prepare_leaf_call_with_gc followed by a direct ccall to rb_float_plus/minus/mul/div. This skips CCallWithFrame overhead (frame push/pop, stack and locals spill) while remaining GC-safe since PC and SP are saved to cfp before the call. The inline functions guard the receiver as Flonum (cheap tag check: (val & 3) == 2) and accept either Flonum or Fixnum as the second operand. HeapFloat operands fall back to CCallWithFrame via the default Send path. Using Flonum guards instead of Float guards avoids an expensive class pointer load from memory. ruby-bench nbody: 46ms -> 33ms (-28%)
Add FloatToInt HIR instruction that truncates a Flonum to Integer via rb_jit_flo_to_i with GC preparation. The helper uses trunc() for truncation toward zero, then returns Fixnum (LONG2FIX) or Bignum (rb_dbl2big) depending on magnitude. rb_jit_flo_to_i is a new JIT helper in jit.c, following the same pattern as rb_jit_fix_div_fix for wrapping a static C function.
Address review feedback: 1. Move the helper from jit.c (shared YJIT/ZJIT glue) to zjit.c since it is only used by ZJIT. 2. Instead of duplicating the truncation logic, export flo_to_i from numeric.c and call it from the ZJIT helper, keeping the implementation centralized. The new rb_zjit_flo_to_i wrapper in zjit.c delegates directly to flo_to_i, so there is no deviation from the Float#to_i semantics.
The previous commit exposed flo_to_i as a non-static global, which tripped tool/leaked-globals because it lacks the rb_ prefix. Keep flo_to_i static and add a new public wrapper rb_flo_to_i in numeric.c that delegates to it. ZJIT now calls rb_flo_to_i directly from Rust (no zjit.c wrapper needed).
The zjit-bindgen CI check regenerates cruby_bindings.inc.rs from headers and diffs against the committed file. Since rb_flo_to_i is declared next to rb_float_plus/minus/mul/div in internal/numeric.h, bindgen emits it there. Match that order in both the allowlist and the generated output.
Co-authored-by: Bob Singh <bobsingh.dev@users.noreply.gitlab.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
See Commits and Changes for more details.
Created by
pull[bot] (v2.0.0-alpha.4)
Can you help keep this open source service alive? 💖 Please sponsor : )