diff options
author | Takashi Kokubun <[email protected]> | 2023-04-02 23:22:53 -0700 |
---|---|---|
committer | Takashi Kokubun <[email protected]> | 2023-04-02 23:24:14 -0700 |
commit | 3bacc3877a8d61a2e66f6b9d874a60f3be0e7f53 (patch) | |
tree | 0fc6f555a15bea8312f4de546c6bc50ddecf1fec /lib/ruby_vm/rjit/compiler.rb | |
parent | eb51248c4c673d6b3d62503f8f4c79d75a52edaa (diff) |
RJIT: Find a best matching block version
Diffstat (limited to 'lib/ruby_vm/rjit/compiler.rb')
-rw-r--r-- | lib/ruby_vm/rjit/compiler.rb | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/lib/ruby_vm/rjit/compiler.rb b/lib/ruby_vm/rjit/compiler.rb index 64a212adba..e714669889 100644 --- a/lib/ruby_vm/rjit/compiler.rb +++ b/lib/ruby_vm/rjit/compiler.rb @@ -354,8 +354,25 @@ module RubyVM::RJIT # @param [RubyVM::RJIT::Context] ctx # @return [RubyVM::RJIT::Block,NilClass] def find_block(iseq, pc, ctx) - src = ctx - rjit_blocks(iseq)[pc].find do |block| + versions = rjit_blocks(iseq)[pc] + + best_version = nil + best_diff = Float::INFINITY + + versions.each do |block| + # Note that we always prefer the first matching + # version found because of inline-cache chains + case ctx.diff(block.ctx) + in TypeDiff::Compatible[diff] if diff < best_diff + best_version = block + best_diff = diff + else + end + end + + return best_version + + versions.find do |block| dst = block.ctx # Can only lookup the first version in the chain |