summaryrefslogtreecommitdiff
path: root/prism_compile.c
diff options
context:
space:
mode:
authoreileencodes <[email protected]>2024-07-17 13:26:02 -0400
committerKevin Newton <[email protected]>2024-07-18 10:12:20 -0400
commitaa3030ac24389f838fd85390601489c60fd13877 ()
tree6affa736f23103ceaa92c29928a134e5fc3c87d1 /prism_compile.c
parentc304bf13b55a30b9982f9c9e6187f5b56fc731b0 (diff)
Fix empty hash instruction
When we have an empty hash the iseq should have a `newhash` but instead had a `duphash`. To fix, check if the node's elements are equal to `0`. If so we want a `newhash`, otherwise use the original `duphash` instructions. Before: ``` == disasm: #<ISeq:<main>@test2.rb:1 (1,0)-(1,2)> 0000 duphash {} ( 1)[Li] 0002 leave ``` After: ``` == disasm: #<ISeq:<main>@test2.rb:1 (1,0)-(1,2)> 0000 newhash 0 ( 1)[Li] 0002 leave ``` Fixes the test `TestYJIT#test_compile_newhash`. Related to ruby/prism#2935
Notes: Merged: https://.com/ruby/ruby/pull/11190
-rw-r--r--prism_compile.c13
1 files changed, 10 insertions, 3 deletions
@@ -7164,9 +7164,16 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
// is popped, then we know we don't need to do anything since it's
// statically known.
if (!popped) {
- VALUE value = pm_static_literal_value(iseq, node, scope_node);
- PUSH_INSN1(ret, location, duphash, value);
- RB_OBJ_WRITTEN(iseq, Qundef, value);
}
}
else {