Skip to content

Commit

Permalink
Fix invokebuiltin in Ruby MJIT
Browse files Browse the repository at this point in the history
  • Loading branch information
k0kubun committed Nov 14, 2022
1 parent 3dd4e38 commit 96d29df
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/mjit/compiler.rb
Expand Up @@ -446,9 +446,10 @@ def compile_ivar(insn_name, stack_size, pos, status, operands, body)
def compile_invokebuiltin(f, insn, stack_size, sp_inc, body, operands)
bf = C.RB_BUILTIN.new(operands[0])
if bf.compiler > 0
index = (insn.name == :invokebuiltin ? -1 : operands[1])
C.fprintf(f, "{\n")
C.fprintf(f, " VALUE val;\n")
C.builtin_compiler(f, bf, operands[1], stack_size, body.builtin_inline_p)
C.builtin_compiler(f, bf, index, stack_size, body.builtin_inline_p)
C.fprintf(f, " stack[#{stack_size + sp_inc - 1}] = val;\n")
C.fprintf(f, "}\n")
return true
Expand Down
12 changes: 9 additions & 3 deletions test/ruby/test_mjit.rb
Expand Up @@ -24,9 +24,6 @@ class TestMJIT < Test::Unit::TestCase
# not supported yet
:defineclass,

# to be tested
:invokebuiltin,

# never used
:opt_invokebuiltin_delegate,
].each do |insn|
Expand Down Expand Up @@ -600,6 +597,15 @@ def test_compile_insn_opt_regexpmatch2
assert_compile_once("'true' =~ /true/", result_inspect: '0', insns: %i[opt_regexpmatch2])
end

def test_compile_insn_invokebuiltin
iseq = eval(EnvUtil.invoke_ruby(['-e', <<~'EOS'], '', true).first)
p RubyVM::InstructionSequence.of([].method(:sample)).to_a
EOS
insns = collect_insns(iseq)
mark_tested_insn(:invokebuiltin, used_insns: insns)
assert_eval_with_jit('print [].sample(1)', stdout: '[]', success_count: 1)
end

def test_compile_insn_opt_invokebuiltin_delegate_leave
iseq = eval(EnvUtil.invoke_ruby(['-e', <<~'EOS'], '', true).first)
p RubyVM::InstructionSequence.of("\x00".method(:unpack)).to_a
Expand Down

0 comments on commit 96d29df

Please sign in to comment.