Commit graph

555 commits

Author SHA1 Message Date
Peter Zhu
948c618bda [PRISM] Fix encoding of interpolated strings
Fixes ruby/prism#2313.
2024-02-05 11:55:44 -05:00
Jenny Shen
b35cdb4758 [PRISM] Implement opt_aset_with
Part of ruby/prism#2231

Co-authored-by: Adrianna Chang <adrianna.chang@shopify.com>
Co-authored-by: Peter Zhu <peter@peterzhu.ca>
2024-02-05 10:27:58 -05:00
Jenny Shen
8ed26a3f59 [PRISM] Refactor PM_CALL_NODE conditional
Co-authored-by: Peter Zhu <peter@peterzhu.ca>
2024-02-05 10:27:58 -05:00
Jenny Shen
8bc6fff322 [PRISM] Do not optimize safe navigation aref
Co-authored-by: Peter Zhu <peter@peterzhu.ca>
2024-02-04 11:05:02 -05:00
Jenny Shen
c5d4444761 [PRISM] Do not optimize safe navigation -@/freeze
Co-authored-by: Peter Zhu <peter@peterzhu.ca>
2024-02-04 11:05:02 -05:00
Alan Wu
0854d64862 [PRISM] Selectively dup array in foo(*splat, &block_arg) calls
This is essentially an adaptation of aae8223c70 ("Dup splat array in
certain cases where there is a block argument") to pass
`TestCall#test_call_block_order`.

This also makes PRISM emit `getblockparamproxy` in cases like
`def foo(&blk) = bar(&blk)` where it used the less efficient
`getblockparam` previously.

Remove the `popped` parameter from setup_args() because it should always
be ignored, and is in fact unused.
2024-02-02 22:25:08 -05:00
Alan Wu
90ae8eaeca [PRISM] Fix numbered parameters stealing local names
Previously, the local index of numbered parameters were assigned to
names of regular locals, making it hard to read both of them. Use proper
`_[1-9]` numbered parameters. This fixes `test_shapes.rb`.

Also, properly mark the iseq as having lead parameters.
2024-02-02 18:50:41 -05:00
Peter Zhu
24cdafb2f8 [PRISM] Fix indentation of pm_scope_node_init [ci skip] 2024-02-02 14:36:08 -05:00
Alan Wu
8d33be9833
[PRISM] Respect string encoding override in array literals
Fixes `TestZlibGzipReader#test_gets2`,
`Psych_Unit_Tests#test_spec_explicit_families`, and many failures in
`test_unicode_normalize.rb`.
2024-02-01 22:11:32 +00:00
Jenny Shen
4fbdbde088 [PRISM] dedup hash string keys
Fixes ruby/prism#2321

Co-authored-by:  Adrianna Chang <adrianna.chang@shopify.com>
Co-authored-by:  Peter Zhu <peter@peterzhu.ca>
2024-02-01 15:52:33 -05:00
Kevin Newton
332d2c92d8 [PRISM] Emit parse warnings 2024-02-01 15:52:19 -05:00
Alan Wu
b47d43fa9b [PRISM] Use rb_fstring() on all string literals
In addition to saving space by deduplicating, this also makes the
literals have code range like TestObjSpace#test_dump_string_coderange
expects. It's testing a detail, but we might as well use rb_fstring().

Note that `putstring` makes a mutable duplicate, so passing it an
fstring is fine.
2024-02-01 15:50:32 -05:00
Nikita Vasilevsky
c7fe3ecb49 [prism] Use block opening line as source_location line of lambda
There are several prism tests failing related to the `source_location`
for lambda returning line of the operator (`->`)
while original parser execution results in `source_location` line
pointing to the block opening location (`{` or `do`)

This commit changes `PM_LAMBDA_NODE` compilation case
to use block opening location instead of the whole node (operator)
opening location to get the line number to build block iseq
2024-02-01 15:23:39 -05:00
Alan Wu
1f226b41f0 [PRISM] Fix multiple return with splat and splat+kwsplat
Previously, `return *array, 1` didn't behave like `return [*array, 1]`
properly. Also, it crashed when splat and kwsplat is combined like in
`array = [*things, **hash]`.

Fix this by grouping `PM_ARGUMENTS_NODE` with `PM_ARRAY_NODE` handling and
combining splat and kwsplat handling.
2024-02-01 10:33:54 -05:00
Kevin Newton
a7b47f96f3 [PRISM] Add splatkw to super calls when necessary 2024-01-31 22:18:55 -05:00
Kevin Newton
d96b4586e4 [PRISM] Fix up index write nodes to match 2024-01-31 22:18:55 -05:00
Kevin Newton
d36c31ed9b [PRISM] Fix keywords in index write nodes 2024-01-31 22:18:55 -05:00
Kevin Newton
8acd1f708f [PRISM] Fix combination of safe navigation and ||= and &&= operators 2024-01-31 22:18:55 -05:00
Kevin Newton
4d01c59042 [PRISM] Fix combination of attribute write and safe navigation 2024-01-31 22:18:55 -05:00
Kevin Newton
b5a2c60d0a [PRISM] Support SCRIPT_LINES__ 2024-01-31 15:49:32 -05:00
Peter Zhu
cb98b018c0 [PRISM] Fix else with rescue
Fixes ruby/prism#2307.
2024-01-31 14:11:14 -05:00
Étienne Barrié
c28ee91263 [PRISM] Fix incorrect use of VM_CALL_KW_SPLAT_MUT in zsuper with keyword splat
This copies the changes from 771a2f039b.
Fixes ruby/prism#2310.
2024-01-31 13:41:49 -05:00
Kevin Newton
610636fd6b [PRISM] Mirror iseq APIs
Before this commit, we were mixing a lot of concerns with the prism
compile between RubyVM::InstructionSequence and the general entry
points to the prism parser/compiler.

This commit makes all of the various prism-related APIs mirror
their corresponding APIs in the existing parser/compiler. This means
we now have the correct frame naming, and it's much easier to follow
where the logic actually flows. Furthermore this consolidates a lot
of the prism initialization, making it easier to see where we could
potentially be raising errors.
2024-01-31 13:41:36 -05:00
Matt Valentine-House
8041b7d967 [PRISM] pm_compile_logical: Fix OrNode in IfNode predicate
Fixes: https://github.com/ruby/prism/issues/2294
2024-01-30 22:22:39 +00:00
Matt Valentine-House
1142ed2f50 [PRISM] Remove unneccessary uses of cond_seq
As this is compiled into only on the recursive call and then added, we
can just use `ret` directly
2024-01-30 22:22:39 +00:00
Aaron Patterson
8e708e4a07 Update forwarding locals for prism 2024-01-30 13:19:06 -05:00
Peter Zhu
c85e28d12a [PRISM] Remove unused variable 2024-01-30 10:29:11 -05:00
Kevin Newton
83966a57fe [PRISM] Method location for calls 2024-01-29 22:22:30 -05:00
Peter Zhu
bbb7ab906e [PRISM] Fix crash when multiple underscores
Fixes ruby/prism#2295.
2024-01-29 17:15:33 -05:00
Kevin Newton
3fb741069d [PRISM] Fix rescue frame label 2024-01-29 16:38:11 -05:00
Peter Zhu
8e1fe15b4a [PRISM] Implement opt_str_uminus 2024-01-29 16:34:25 -05:00
Peter Zhu
32bbf47500 [PRISM] Use opt_str_freeze instruction
Fixes ruby/prism#2290.
2024-01-29 14:53:34 -05:00
Matt Valentine-House
d7501c4031 [PRISM] Fix InterpolatedStringNode
If the first element of an interpolated string node is an embedded
statement, CRuby "pre-initializes" the interpolation with a string of
known encoding to concat into.

This patch replicates thate behaviour in Prism
2024-01-29 19:13:53 +00:00
Peter Zhu
3d3d9e8397 [PRISM] Support US-ASCII symbols 2024-01-29 13:56:54 -05:00
Peter Zhu
d980c89273 [PRISM] Support ASCII-8BIT symbols 2024-01-29 13:56:54 -05:00
Peter Zhu
f634c7a268 [PRISM] Support UTF-8 symbols
Fixes ruby/prism#2242.
2024-01-29 13:56:54 -05:00
Peter Zhu
9a5a11f3d0 [PRISM] Use the splatkw instruction
Fixes ruby/prism#2272.
2024-01-29 11:42:40 -05:00
Matt Valentine-House
c422805bbb [PRISM] Fix encoding for interpolated strings.
This wasn't taking into account strings with flags set on the containing
node that could affect the encoding. It does now
2024-01-29 10:04:16 -05:00
Kevin Newton
cb9a47f2ac [PRISM] Fix branchif ADD_INSN1 2024-01-26 16:46:31 -05:00
Peter Zhu
a120529020 [PRISM] Fix loop in rescue blocks
Fixes ruby/prism#2250.

Co-Authored-By: Kevin Newton <kddnewton@gmail.com>
2024-01-26 16:07:24 -05:00
Peter Zhu
59bb78ebd0 [PRISM] Fix for s390x
On s390x, a long is 8 bytes. st_data_t is an unsigned long but
pm_constant_id_t is a 4 byte integer. We need to cast it to st_data_t
when passing it to ST functions.
2024-01-26 15:41:06 -05:00
Peter Zhu
3d996e827f [PRISM] Keyword arguments incorrectly passed as mutable
Fixes ruby/prism#2279.
2024-01-26 14:58:29 -05:00
Matt Valentine-House
e452caac10 [PRISM] Fix next inside rescue 2024-01-25 15:10:52 -05:00
Kevin Newton
1301422dfe [PRISM] Fix VM_CALL_ARGS_SPLAT_MUT failures 2024-01-25 11:11:50 -05:00
Peter Zhu
f769d68a69 [PRISM] Fix getblockparamproxy for forwarding arguments 2024-01-24 17:32:43 -05:00
Peter Zhu
7d61454f2e [PRISM] Fix method calls in keyword arguments
Fixes ruby/prism#2248.
2024-01-24 15:18:06 -05:00
Aaron Patterson
94f3f9502c Fix repeated block param
Co-Authored-By: Matt Valentine-House <matt@eightbitraptor.com>
2024-01-24 12:04:44 -08:00
Aaron Patterson
1817af5074 Fix local table size / index for repeated kwrest
Co-Authored-By: Matt Valentine-House <matt@eightbitraptor.com>
2024-01-24 12:04:44 -08:00
Aaron Patterson
13c76e40d3 Fix local table size and variable offset for repeated keywords
Co-Authored-By: Matt Valentine-House <matt@eightbitraptor.com>
2024-01-24 12:04:44 -08:00
Aaron Patterson
8b7e78f156 Fix local table size and index for required post underscore
Co-Authored-By: Matt Valentine-House <matt@eightbitraptor.com>
2024-01-24 12:04:44 -08:00