Skip to content

[pull] master from ruby:master#1006

Merged
pull[bot] merged 4 commits into
turkdevops:masterfrom
ruby:master
May 13, 2026
Merged

[pull] master from ruby:master#1006
pull[bot] merged 4 commits into
turkdevops:masterfrom
ruby:master

Conversation

@pull
Copy link
Copy Markdown

@pull pull Bot commented May 13, 2026

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 : )

dak2 and others added 4 commits May 12, 2026 20:39
…6828)

## Summary

`GuardType` narrows only its result id, not the original input. 
A later guard on the same input therefore looks unfoldable to `fold_constants` even though the side-exit semantics already prove the narrower type.
Canonicalize rewrites later uses to the most recent `Guard*` result, making the redundant guard foldable.
For example, in this CFG-join shape:

 ```ruby
  def test(n, cond)                                                                                                           
    if cond   
      a = n + 1
    else                                                                                                                      
      a = n + 2
    end                                                                                                                       
    n + a   # `n` gets a redundant Fixnum guard here
  end
 ```

This PR adds a block-local HIR `canonicalize` pass that walks each block in RPO and rewrites every operand through union-find plus a per-block `rewrite_map` keyed on the most recent `Guard*` for that value. 
After canonicalization, `infer_types` can narrow merge-block parameter types and `fold_constants` can then drop the redundant guards in both shapes above.

Inspired by Cranelift's canonicalize https://cfallin.org/blog/2026/04/09/aegraph/

Fixes: Shopify#978

## Benchmarks

Bench (arm64 linux devcontainer, ruby/ruby-bench, warmup=10 bench=20)

```
  Throughput              master/staged
    lobsters              1.021 (+2.1%, within ±3-6% noise)
    railsbench            1.012 (+1.2%, within ±3-4% noise)

  --zjit-stats            lobsters / railsbench
    code_region_bytes     -1.1%   / -1.0%   (redundant CFG-join guards still removed)
    guard_type_count      -29.4%  / +30.1%  (railsbench likely single-run noise) ⚠
    compile_hir_time      +14.6%  / +13.7%  (canonicalize_time: 67ms / 31ms)
    invalidation_time      ±0%    /  ±0%
```
…cks (#16888)

* Swap conditionals so HIR -> LIR is easier

We're going to give HIR regular BBs which means each block can end with
up to two jump instructions.  IfTrue/IfFalse will always be followed by
a Jump, so when we lower to LIR this change will make the lowering more
natural.  We'll only have to emit a jz/jnz for the IfTrue/IfFalse cases,
and the Jump instructions will be naturally handled

* Convert HIR EBB to regular BB

This commit converts HIR EBB to regular BB.  It ensures that all basic
blocks in HIR end with 1 or 2 jump instructions, and that there are no
jump instructions that appear mid-block.

* implement condbranch

* remove num_successors (we do not need it)

* oops!

* oops!

* Do not use clone

* fix insta

* remove comment

* check for terminator in rpo loop

* peek at next instruction for new blocks in the jit entry

* add comment
Now that ece14b6 has landed, we get
this for free.

We will eventually add value numbering, which will do more, but for now
remove this ad-hoc code.
[Bug #22064]

Compare-by-identity sets use the address for hashing, so we must pin it
so the object does not move in GC compaction. Objects in a compare-by-identity
set is not currently pinned, causing the set to be broken if the object
is moved.

For example:

    set = Set.new.compare_by_identity

    o = Object.new
    set.add(o)

    puts set.include?(o)

    GC.verify_compaction_references(expand_heap: true, toward: :empty)

    puts set.include?(o)

It should output true twice, but it outputs true and false.
@pull pull Bot locked and limited conversation to collaborators May 13, 2026
@pull pull Bot added the ⤵️ pull label May 13, 2026
@pull pull Bot merged commit baec5bb into turkdevops:master May 13, 2026
1 of 3 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants