Skip to content

Commit

Permalink
YJIT: Add support for **kwrest parameters
Browse files Browse the repository at this point in the history
Now that `...` uses `**kwrest` instead of regular splat and
ruby2keywords, we need to support these type of methods to
support `...` well.
  • Loading branch information
XrXr committed Feb 12, 2024
1 parent 7af97dc commit 2131d04
Show file tree
Hide file tree
Showing 6 changed files with 234 additions and 102 deletions.
28 changes: 28 additions & 0 deletions test/ruby/test_yjit.rb
Expand Up @@ -1532,6 +1532,34 @@ def calls(obj, empty, &)
RUBY
end

def test_kwrest
assert_compiles(<<~RUBY, result: true, no_send_fallbacks: true)
def req_rest(r1:, **kwrest) = [r1, kwrest]
def opt_rest(r1: 1.succ, **kwrest) = [r1, kwrest]
def kwrest(**kwrest) = kwrest
def calls
[
[1, {}] == req_rest(r1: 1),
[1, {:r2=>2, :r3=>3}] == req_rest(r1: 1, r2: 2, r3: 3),
[1, {:r2=>2, :r3=>3}] == req_rest(r2: 2, r1:1, r3: 3),
[1, {:r2=>2, :r3=>3}] == req_rest(r2: 2, r3: 3, r1: 1),
[2, {}] == opt_rest,
[2, { r2: 2, r3: 3 }] == opt_rest(r2: 2, r3: 3),
[0, { r2: 2, r3: 3 }] == opt_rest(r1: 0, r3: 3, r2: 2),
[0, { r2: 2, r3: 3 }] == opt_rest(r2: 2, r1: 0, r3: 3),
[1, { r2: 2, r3: 3 }] == opt_rest(r2: 2, r3: 3, r1: 1),
{} == kwrest,
{ r0: 88, r1: 99 } == kwrest(r0: 88, r1: 99),
]
end
calls.all?
RUBY
end

private

def code_gc_helpers
Expand Down
3 changes: 1 addition & 2 deletions yjit/bindgen/src/main.rs
Expand Up @@ -196,8 +196,6 @@ fn main() {
.allowlist_type("rb_call_data")
.blocklist_type("rb_callcache.*") // Not used yet - opaque to make it easy to import rb_call_data
.opaque_type("rb_callcache.*")
.blocklist_type("rb_callinfo_kwarg") // Contains a VALUE[] array of undefined size, so we don't import
.opaque_type("rb_callinfo_kwarg")
.allowlist_type("rb_callinfo")

// From vm_insnhelper.h
Expand Down Expand Up @@ -267,6 +265,7 @@ fn main() {
.allowlist_var("VM_BLOCK_HANDLER_NONE")
.allowlist_type("vm_frame_env_flags")
.allowlist_type("rb_seq_param_keyword_struct")
.allowlist_type("rb_callinfo_kwarg")
.allowlist_type("ruby_basic_operators")
.allowlist_var(".*_REDEFINED_OP_FLAG")
.allowlist_type("rb_num_t")
Expand Down

0 comments on commit 2131d04

Please sign in to comment.