summaryrefslogtreecommitdiff
path: root/prism_compile.c
AgeCommit message (Collapse)Author
2024-01-24[PRISM] Handle implicit lvar write in hash patternKevin Newton
2024-01-24[PRISM] Fix forwarding from within blockPeter Zhu
Fixes ruby/prism#2253.
2024-01-24[PRISM] Fix crash in anonymous block with forwarding argumentsPeter Zhu
Fixes ruby/prism#2262.
2024-01-24Move filling in the rest of the locals to the endAaron Patterson
2024-01-24Insert all locals in the locals index tableAaron Patterson
Prism provides an index (local_body_index) which is supposed to point at the start of locals declared in the method body. Prism assumed that method body locals would only occur _after_ parameter names. Unfortunately this assumption is not correct, which meant that we would in some cases not insert all locals in the local table. This commit iterates over locals a second time, inserting any that didn't get inserted on the first pass. Fixes: https://github.com/ruby/prism/issues/2245 Co-Authored-By: Matt Valentine-House <matt@eightbitraptor.com>
2024-01-24[PRISM] Fix anonymous keyword argumentsPeter Zhu
Fixes ruby/prism#2256.
2024-01-24[PRISM] Remove dead code from prism_compile.cKevin Newton
Previously, we were using the main pm_compile_node switch to compile target nodes. Eventually we switched to pm_compile_target_node and updated all the call sites. As such, all of this has become dead code. However, the multi target code was reused for both parameters and multi writes (it was just incorrect for multi writes). So that code has now been moved into its own function that is more specific to destructured parameters (and has more assertions to that effect). Overall now you should not see target nodes when you call into pm_compile_node, since they are more specialized and require more special handling.
2024-01-24[PRISM] Use lvar depths for startingKevin Newton
2024-01-24[PRISM] Nested MultiWriteNode with method callsPeter Zhu
Fixes ruby/prism#2247.
2024-01-23[PRISM] Fix anonymous splat nodesPeter Zhu
Fixes ruby/prism#2257.
2024-01-23[PRISM] Fix block fowardingPeter Zhu
2024-01-23[PRISM] Support block parameters with no namePeter Zhu
Fixes ruby/prism#2249.
2024-01-22Handle trailing commas on blocksAaron Patterson
We need to set a special flag on block iseqs when there is a trailing comma. Fixes: https://github.com/ruby/prism/issues/2244
2024-01-22Check keyword parameters correctlyAaron Patterson
We weren't checking the right offsets when compiling methods with keyword parameters that had complex code. Fixes: https://github.com/ruby/prism/issues/2228
2024-01-22[PRISM] Fix keyword arguments in IndexOrWriteNodePeter Zhu
Fixes ruby/prism#2236.
2024-01-22[PRISM] Fix splat and block in asetPeter Zhu
2024-01-22[PRISM] Fix block in asetPeter Zhu
Fixes ruby/prism#2223.
2024-01-22[PRISM] Force semicolon at the end of PM macrosPeter Zhu
2024-01-22[PRISM] Use PM_SWAP macroPeter Zhu
2024-01-22[PRISM] Use PM_POP macroPeter Zhu
2024-01-22Fix compiling rescue + ensureAaron Patterson
When we're compiling begin / rescue / ensure nodes, we need to "wrap" the code in the begin statements correctly. The wrapping is like this: (ensure code (rescue code (begin code))) This patch pulls the each leg in to its own function, then calls the appropriate wrapping function depending on whether there are ensure / rescue legs. Fixes: https://github.com/ruby/prism/issues/2221
2024-01-22[PRISM] Fix keyword splat in IndexAndWriteNode and IndexOrWriteNodePeter Zhu
Fixes ruby/prism#2232 and ruby/prism#2234.
2024-01-22[PRISM] Insert concatarray for index targets with splatKevin Newton
2024-01-22[PRISM] Fix line for leave instructionsKevin Newton
2024-01-22[PRISM] Fix keywords arguments in IndexAndWriteNodePeter Zhu
Fixes ruby/prism#2233.
2024-01-22[PRISM] Fix up source line for 1-indexed line numbersKevin Newton
2024-01-22[PRISM] Freeze regex literals in iseqsKevin Newton
2024-01-22[PRISM] Fix incorrect ordering of MultiTargetNodePeter Zhu
Fixes ruby/prism#2218.
2024-01-22[PRISM] Add TP call/return events to method ISEQsMatt Valentine-House
2024-01-19[PRISM] Revisit target nodesKevin Newton
2024-01-19[PRISM] Fix ensure code running twiceeileencodes
Fixes: ruby/prism#2212
2024-01-19Fix kwarg orderingAaron Patterson
Required keyword arguments need to come first. Fixes: https://github.com/ruby/prism/issues/2158 Co-authored-by: Kevin Newton <kddnewton@gmail.com>
2024-01-19[PRISM] Fix typo with pm_scope_node_destroyPeter Zhu
We need to run the pm_scope_node_destroy after compiling the iseq.
2024-01-19Fix ensure code when running break in a while loopAaron Patterson
We need to run ensure code when breaking from a while loop Co-authored-by: John Hawthorn <jhawthorn@github.com> Co-authored-by: Kevin Newton <kddnewton@gmail.com>
2024-01-19[PRISM] Fix indentation for PM_SCOPE_NODE [ci skip]Peter Zhu
2024-01-18[PRISM] Add function to free scope nodePeter Zhu
pm_scope_node_destroy frees the scope node after we're done using it to make sure that the index_lookup_table is not leaked. For example: 10.times do 100_000.times do RubyVM::InstructionSequence.compile_prism("begin; 1; rescue; 2; end") end puts `ps -o rss= -p #{$$}` end Before: 33056 50304 67776 84544 101520 118448 135712 152352 169136 186656 After: 15264 15296 15408 17040 17152 17152 18320 18352 18400 18608
2024-01-18[PRISM] Pass pm_scope_node_t by referencePeter Zhu
We can pass pm_scope_node_t by reference to pm_new_child_iseq rather than by value.
2024-01-18[PRISM] Correct checkmatch flags for splat in rescueMatt Valentine-House
2024-01-18[PRISM] Fix case splat with no predicateMatt Valentine-House
2024-01-18[PRISM] Fix indentation in switch [ci skip]Peter Zhu
2024-01-18[PRISM] Fix memory leak in case nodesPeter Zhu
The temporary array conditions_labels is heap allocated and never freed. We can use alloca instead to stack allocate it so that we don't need to manually free it. For example: code = "case; #{100.times.map { "when #{it}; " }.join}; end" 10.times do 10_000.times do RubyVM::InstructionSequence.compile_prism(code) end puts `ps -o rss= -p #{$$}` end Before: 21376 30304 38800 47184 55456 64192 72288 80400 89040 97104 After: 13088 13632 13760 14016 14688 14992 15120 15232 15744 15744
2024-01-18[PRISM] Fix memory leak in iseqPeter Zhu
rb_iseq_compile_prism_node calls both rb_translate_prism and iseq_setup. Both of these functions call iseq_set_sequence. This means that the first iseq_set_sequence will leak because the iseq will be overwritten. For example: 10.times do 100_000.times do RubyVM::InstructionSequence.compile_prism("") end puts `ps -o rss= -p #{$$}` end Before: 20528 27328 33840 40208 46400 52960 59168 65600 71888 78352 After: 13696 13712 13712 13712 13712 14352 14352 14992 14992 14992
2024-01-17[Prism] Implement defined? for PM_UNLESS_NODEeileencodes
Ruby code: ```ruby defined?(unless true; 1; end) ``` Instructions: ``` "********* Ruby *************" == disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(59,16)> 0000 putobject "expression" ( 59)[Li] 0002 leave "********* PRISM *************" == disasm: #<ISeq:<compiled>@<compiled>:58 (58,0)-(58,16)> 0000 putobject "expression" ( 58)[Li] 0002 leave ``` Related: ruby/prism#2188
2024-01-17[Prism] Implement defined? for PM_UNTIL_NODEeileencodes
Ruby code: ```ruby defined?(until a == 1; end) ``` Instructions: ``` "********* Ruby *************" == disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(59,16)> 0000 putobject "expression" ( 59)[Li] 0002 leave "********* PRISM *************" == disasm: #<ISeq:<compiled>@<compiled>:58 (58,0)-(58,16)> 0000 putobject "expression" ( 58)[Li] 0002 leave ``` Related: ruby/prism#2188
2024-01-17[Prism] Implement defined? for PM_WHILE_NODEeileencodes
Ruby code: ```ruby defined?(while a != 1; end) ``` Instructions: ``` "********* Ruby *************" == disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(59,16)> 0000 putobject "expression" ( 59)[Li] 0002 leave "********* PRISM *************" == disasm: #<ISeq:<compiled>@<compiled>:58 (58,0)-(58,16)> 0000 putobject "expression" ( 58)[Li] 0002 leave ``` Related: ruby/prism#2188
2024-01-17[Prism] Implement defined? for PM_SINGLETON_CLASS_NODEeileencodes
Ruby code: ```ruby defined?(class << self; end) ``` Instructions: ``` "********* Ruby *************" == disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(59,16)> 0000 putobject "expression" ( 59)[Li] 0002 leave "********* PRISM *************" == disasm: #<ISeq:<compiled>@<compiled>:58 (58,0)-(58,16)> 0000 putobject "expression" ( 58)[Li] 0002 leave ``` Related: ruby/prism#2188
2024-01-17[Prism] Implement defined? for PM_RATIONAL_NODEeileencodes
Ruby code: ```ruby defined?(1.2r) ``` Instructions: ``` "********* Ruby *************" == disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(59,16)> 0000 putobject "expression" ( 59)[Li] 0002 leave "********* PRISM *************" == disasm: #<ISeq:<compiled>@<compiled>:58 (58,0)-(58,16)> 0000 putobject "expression" ( 58)[Li] 0002 leave ``` Related: ruby/prism#2188
2024-01-17[Prism] Implement defined? for PM_MODULE_NODEeileencodes
Ruby code: ```ruby defined?(module M; end) ``` Instructions: ``` "********* Ruby *************" == disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(59,16)> 0000 putobject "expression" ( 59)[Li] 0002 leave "********* PRISM *************" == disasm: #<ISeq:<compiled>@<compiled>:58 (58,0)-(58,16)> 0000 putobject "expression" ( 58)[Li] 0002 leave ``` Related: ruby/prism#2188
2024-01-17[Prism] Implement defined? for PM_MATCH_REQUIRED_NODEeileencodes
Ruby code: ```ruby defined?(1 => 1) ``` Instructions: ``` "********* Ruby *************" == disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(59,16)> 0000 putobject "expression" ( 59)[Li] 0002 leave "********* PRISM *************" == disasm: #<ISeq:<compiled>@<compiled>:58 (58,0)-(58,16)> 0000 putobject "expression" ( 58)[Li] 0002 leave ``` Related: ruby/prism#2188
2024-01-17[Prism] Implement defined? for PM_MATCH_WRITE_NODEeileencodes
Ruby code: ```ruby defined?(/(?<foo>bar)/ =~ 'barbar') ``` Instructions: ``` "********* Ruby *************" == disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(59,35)> local table (size: 1, argc: 0 [opts: 0, rest: -1, post: 0, block: -1, kw: -1@-1, kwrest: -1]) [ 1] foo@0 0000 putobject "expression" ( 59)[Li] 0002 leave "********* PRISM *************" == disasm: #<ISeq:<compiled>@<compiled>:58 (58,0)-(58,35)> local table (size: 1, argc: 0 [opts: 0, rest: -1, post: 0, block: -1, kw: -1@-1, kwrest: -1]) [ 1] foo@0 0000 putobject "expression" ( 58)[Li] 0002 leave ``` Related: ruby/prism#2188