diff options
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 |