Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PRISM] Use the splatkw instruction #9740

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 8 additions & 4 deletions prism_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -2749,12 +2749,16 @@ pm_compile_call(rb_iseq_t *iseq, const pm_call_node_t *call_node, LINK_ANCHOR *c
else if (!popped) {
ADD_INSN1(ret, &dummy_line_node, setn, INT2FIX(orig_argc + 1));
}
}

ADD_SEND_R(ret, &dummy_line_node, method_id, INT2FIX(orig_argc), block_iseq, INT2FIX(flags), kw_arg);
PM_POP_UNLESS_POPPED;
if ((flags & VM_CALL_KW_SPLAT) && (flags & VM_CALL_ARGS_BLOCKARG) && !(flags & VM_CALL_KW_SPLAT_MUT)) {
ADD_INSN(ret, &dummy_line_node, splatkw);
}
else {
ADD_SEND_R(ret, &dummy_line_node, method_id, INT2FIX(orig_argc), block_iseq, INT2FIX(flags), kw_arg);

ADD_SEND_R(ret, &dummy_line_node, method_id, INT2FIX(orig_argc), block_iseq, INT2FIX(flags), kw_arg);

if (pm_node->flags & PM_CALL_NODE_FLAGS_ATTRIBUTE_WRITE) {
PM_POP_UNLESS_POPPED;
}

if (call_node->base.flags & PM_CALL_NODE_FLAGS_SAFE_NAVIGATION) {
Expand Down
22 changes: 22 additions & 0 deletions test/ruby/test_compile_prism.rb
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,28 @@ def o.bar(**) = Hash(**)

o.bar(hello: "world")
RUBY

# Test that AssocSplatNode is evaluated before BlockArgumentNode using
# the splatkw instruction
assert_prism_eval(<<~RUBY)
o = Struct.new(:ary) do
def to_hash
ary << :to_hash
{}
end

def to_proc
ary << :to_proc
-> {}
end

def t(...); end
end.new
o.ary = []

o.t(**o, &o)
o.ary
RUBY
end

def test_HashNode
Expand Down