diff options
author | Alan Wu <XrXr@users.noreply.github.com> | 2022-10-04 22:48:05 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-04 22:48:05 -0400 |
commit | 7293bfe1bf8a696bd218a52582e9026e5e638458 (patch) | |
tree | e45b5f267ce6567c783d1b14e16afb007de40497 /bootstraptest | |
parent | 5fc68e1101d38c9ced4d07ef1526467618109de3 (diff) | |
download | ruby-7293bfe1bf8a696bd218a52582e9026e5e638458.tar.gz |
YJIT: add support for calling bmethods (#6489)
* YJIT: fix a parameter name
* YJIT: add support for calling bmethods
This commit adds support for the VM_METHOD_TYPE_BMETHOD method type in
YJIT. You can get these type of methods from facilities like
Kernel#define_singleton_method and Module#define_method.
Even though the body of these methods are blocks, the parameter setup
for them is exactly the same as VM_METHOD_TYPE_ISEQ, so we can reuse
the same logic in gen_send_iseq(). You can see this from how
vm_call_bmethod() eventually calls setup_parameters_complex() with
arg_setup_method.
Bmethods do need their frame environment to be setup differently. We
handle this by allowing callers of gen_send_iseq() to control the iseq,
the frame flag, and the prev_ep. The `prev_ep` goes into the same
location as the block handler would go into in an iseq method frame.
Co-authored-by: John Hawthorn <john@hawthorn.email>
Co-authored-by: John Hawthorn <john@hawthorn.email>
Diffstat (limited to 'bootstraptest')
-rw-r--r-- | bootstraptest/test_yjit.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/bootstraptest/test_yjit.rb b/bootstraptest/test_yjit.rb index 2dff7d591a..2dc460c628 100644 --- a/bootstraptest/test_yjit.rb +++ b/bootstraptest/test_yjit.rb @@ -3309,3 +3309,31 @@ assert_equal 'true', %q{ end foo(Foo.new) } + +# bmethod +assert_equal '[1, 2, 3]', %q{ + one = 1 + define_method(:foo) do + one + end + + 3.times.map { |i| foo + i } +} + +# return inside bmethod +assert_equal 'ok', %q{ + define_method(:foo) do + 1.tap { return :ok } + end + + foo +} + +# bmethod optional and keywords +assert_equal '[[1, nil, 2]]', %q{ + define_method(:opt_and_kwargs) do |a = {}, b: nil, c: nil| + [a, b, c] + end + + 5.times.map { opt_and_kwargs(1, c: 2) }.uniq +} |