| Age | Commit message (Collapse) | Author |
|
|
|
Fixes ruby/prism#2253.
|
|
Fixes ruby/prism#2262.
|
|
|
|
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>
|
|
Fixes ruby/prism#2256.
|
|
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.
|
|
|
|
Fixes ruby/prism#2247.
|
|
Fixes ruby/prism#2257.
|
|
|
|
Fixes ruby/prism#2249.
|
|
We need to set a special flag on block iseqs when there is a trailing
comma.
Fixes: https://github.com/ruby/prism/issues/2244
|
|
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
|
|
Fixes ruby/prism#2236.
|
|
|
|
Fixes ruby/prism#2223.
|
|
|
|
|
|
|
|
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
|
|
Fixes ruby/prism#2232 and ruby/prism#2234.
|
|
|
|
|
|
Fixes ruby/prism#2233.
|
|
|
|
|
|
Fixes ruby/prism#2218.
|
|
|
|
|
|
Fixes: ruby/prism#2212
|
|
Required keyword arguments need to come first.
Fixes: https://github.com/ruby/prism/issues/2158
Co-authored-by: Kevin Newton <kddnewton@gmail.com>
|
|
We need to run the pm_scope_node_destroy after compiling the iseq.
|
|
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>
|
|
|
|
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
|
|
We can pass pm_scope_node_t by reference to pm_new_child_iseq rather
than by value.
|
|
|
|
|
|
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|