Граф коммитов

39 Коммитов

Автор SHA1 Сообщение Дата
Hiroshi SHIBATA d242e8416e
Revert all of commits after Prism 0.19.0 release
We should bundle released version of Prism for Ruby 3.3.0
2023-12-16 11:08:51 +08:00
Ufuk Kayserilioglu 0a31cb1a37 [ruby/prism] Finish keyword hash node flag refactor by renaming flag
https://github.com/ruby/prism/commit/7f812389f8
2023-12-15 18:45:36 +00:00
Kevin Newton 278ce27ee4 [ruby/prism] Flag for attribute write on calls
https://github.com/ruby/prism/commit/465731969c
2023-12-12 15:55:54 +00:00
Ufuk Kayserilioglu 25b9a0cbc8 [ruby/prism] Add `STATIC_KEYS` flag for `KeywordHashNode`
https://github.com/ruby/prism/commit/aa83de39c1
2023-12-12 13:05:08 +00:00
Kevin Newton b673b5b432 [ruby/prism] Split up CallNode in target position
In this commit we're splitting up the call nodes that were in target
positions (that is, for loop indices, rescue error captures, and
multi assign targets).

Previously, we would simply leave the call nodes in place. This had
the benefit of keeping the AST relatively simple, but had the
downside of not being very explicit. If a static analysis tool wanted
to only look at call nodes, it could easily be confused because the
method would have 1 fewer argument than it would actually be called
with.

This also brings some consistency to the AST. All of the nodes in
a target position are now *TargetNode nodes. These should all be
treated the same, and the call nodes can now be treated the same.

Finally, there is benefit to memory. Because being in a target
position ensures we don't have some fields, we can strip down the
number of fields on these nodes.

So this commit introduces two new nodes: CallTargetNode and
IndexTargetNode. For CallTargetNode we get to drop the opening_loc,
closing_loc, arguments, and block. Those can never be present. We
also get to mark their fields as non-null, so they will always be
seen as present.

The IndexTargetNode keeps around most of its fields but gets to
drop both the name (because it will always be []=) and the
message_loc (which was always super confusing because it included
the arguments by virtue of being inside the []).

Overall, this adds complexity to the AST at the expense of memory
savings and explicitness. I believe this tradeoff is worth it in
this case, especially because these are very much not common nodes
in the first place.

https://github.com/ruby/prism/commit/3ef71cdb45
2023-12-11 15:32:31 +00:00
Kevin Newton 98e3552cfb [ruby/prism] Add necessary encoding flags for symbols and regex
This doesn't actually fix the encodings for symbols and regex,
unfortunately. But I wanted to get this change in because it is
the last AST change we're going to make before 3.3 is released.

So, if consumers want, they can start to check these flags to
determine the encoding, even though it will be wrong. Then once we
actually set them correctly, everything should work.

https://github.com/ruby/prism/commit/9b35f7e891
2023-12-08 18:59:52 +00:00
Kevin Newton c05278e425 [ruby/prism] Update ordering of integer base flags
https://github.com/ruby/prism/commit/d711950d5f
2023-12-07 16:00:41 +00:00
Kevin Newton fe6ee5e921 [ruby/prism] Move flag position consistently to front
https://github.com/ruby/prism/commit/6e69a81737
2023-12-06 20:50:02 +00:00
Kevin Newton 82f18baa21 [ruby/prism] Provide flags for changing encodings
https://github.com/ruby/prism/commit/e838eaff6f
2023-12-06 14:23:38 -05:00
Jemma Issroff 018dbf18d5 [ruby/prism] Add locals_body_index to DefNode, BlockNode, LambdaNode
The locals_body_index gives the index in the locals array where
the locals from the body start. This allows compilers to easily
index past the parameters in the locals array.

https://github.com/ruby/prism/commit/5d4627b890
2023-12-06 09:55:48 -05:00
Kevin Newton cdb74d74af [ruby/prism] Change numbered parameters
Previously numbered parameters were a field on blocks and lambdas
that indicated the maximum number of numbered parameters in either
the block or lambda, respectively. However they also had a
parameters field that would always be nil in these cases.

This changes it so that we introduce a NumberedParametersNode that
goes in place of parameters, which has a single uint8_t maximum
field on it. That field contains the maximum numbered parameter in
either the block or lambda.

As a part of the PR, I'm introducing a new UInt8Field type that
can be used on nodes, which is just to make it a little more
explicit what the maximum values can be (the maximum is actually 9,
since it only goes up to _9). Plus we can do a couple of nice
things in serialization like just read a single byte.

https://github.com/ruby/prism/commit/2d87303903
2023-12-01 12:03:09 -05:00
Kevin Newton 4938390177 [ruby/prism] Implicit rest nodes
Fundamentally, `foo { |bar,| }` is different from `foo { |bar, *| }`
because of arity checks. This PR introduces a new node to handle
that, `ImplicitRestNode`, which goes in the `rest` slot of parameter
nodes instead of `RestParameterNode` instances.

This is also used in a couple of other places, namely:

* pattern matching: `foo in [bar,]`
* multi target: `for foo, in bar do end`
* multi write: `foo, = bar`

Now the only splat nodes with a `NULL` value are when you're
forwarding, as in: `def foo(*) = bar(*)`.

https://github.com/ruby/prism/commit/dba2a3b652
2023-11-28 22:33:50 +00:00
Jemma Issroff 04cbcd37b1 [ruby/prism] Add numbered_parameters field to BlockNode and LambdaNode
We are aware at parse time how many numbered parameters we have
on a BlockNode or LambdaNode, but prior to this commit, did not
store that information anywhere in its own right.

The numbered parameters were stored as locals, but this does not
distinguish them from other locals that have been set, for example
in `a { b = 1; _1 }` there is nothing on the AST that distinguishes
b from _1.

Consumers such as the compiler need to know information about how
many numbered parameters exist to set up their own tables around
parameters. Since we have this information at parse time, we should
compute it here, instead of deferring the work later on.

https://github.com/ruby/prism/commit/bf4a1e124d
2023-11-28 21:08:46 +00:00
Benoit Daloze 018e6abf85 [ruby/prism] Move CallNode#name field between receiver and arguments
* The same order as in source code.
* CallOrWriteNode, CallOperatorWriteNode, CallAndWriteNode already have
  the correct order so it was also inconsistent with them.

https://github.com/ruby/prism/commit/4434e4bc22
2023-11-22 12:15:20 +00:00
Jemma Issroff 8e80cad9e9 [ruby/prism] Add SPLAT flag on ArrayNode indicating if it contains splat element(s)
This commit puts a SPLAT flag on any ArrayNodes which contain
SplatNode elements

https://github.com/ruby/prism/commit/2fc1e7f181
2023-11-21 22:30:53 +00:00
Jemma Issroff 3db21d2d4c [PRISM] Rename flag to CONTAINS_KEYWORD_SPLAT
We need to do this change first on ruby/ruby before merging to
ruby/prism to avoid breaking ruby/ruby CI
2023-11-21 17:29:07 -05:00
Kevin Newton ddacc08528 [ruby/prism] Remove string concat in favor of a flat list
Right now when you have a lot of string concats it ends up being
difficult to work with because of the depth of the tree. You end
up descending very far for every string literal that is part of the
concat.

There are already times when we use an interpolated string node to
group together two string segments that are part of the same string
(like when they are interupted by the contents of a heredoc). This
commit takes the same approach and replaces string concats with
interpolated string nodes.

Now that they're a flat list, they should be much easier to work
with. There's still some missing information here that would be
useful to consumers: whether or not there is _actually_ any
interpolation contained in the list. We could remedy this with
another node type that is named something like string list, or we
could add a flag to interpolated string node indicating that there
is interpolation. Either way I want to solve that in a follow-up
commit, since this commit is valuable on its own.

https://github.com/ruby/prism/commit/1e7ae3ad1b
2023-11-21 11:35:46 -05:00
Kevin Newton 9fa524dd41 [ruby/prism] Split up CaseNode and CaseMatchNode
(https://github.com/ruby/prism/pull/1801)

https://github.com/ruby/prism/commit/4c1391ea56
2023-11-21 02:38:07 +00:00
Kevin Newton e269096d15 [ruby/prism] Replace match write locals with match write targets
https://github.com/ruby/prism/commit/eec1862967
2023-11-20 18:00:44 -05:00
Kevin Newton d2e7a70ee6 [ruby/prism] Track the then keyword for conditionals
https://github.com/ruby/prism/commit/fef0019a25
2023-11-15 23:08:11 +00:00
Kevin Newton 690f3bbf5d [ruby/prism] Last remaining missing C comments
https://github.com/ruby/prism/commit/e327449db6
2023-11-01 13:10:29 -04:00
Kevin Newton 0a460b23e0 [ruby/prism] Add comments on flags
https://github.com/ruby/prism/commit/3abd09c803
2023-11-01 13:10:29 -04:00
Kevin Newton 5df14ecebe [ruby/prism] Fix up Ruby docs
https://github.com/ruby/prism/commit/8062849d0d
2023-11-01 13:10:29 -04:00
Kevin Newton bb2e1d8eef [ruby/prism] Fix rescue modifier comment
https://github.com/ruby/prism/commit/e13f2e4590
2023-11-01 17:03:10 +00:00
Jemma Issroff e80ca70b9b [ruby/prism] Flip incorrect names of OptionalKeywordParameterNode and RequiredKeywordParameterNode
https://github.com/ruby/prism/commit/c31f61e898
2023-11-01 14:40:45 +00:00
Jemma Issroff d0625099e0 [ruby/prism] Split KeywordParameterNode into Optional and Required
Prior to this commit, KeywordParameterNode included both optional
and required keywords. With this commit, it is split in two, with
`OptionalKeywordParameterNode`s no longer having a value field.

https://github.com/ruby/prism/commit/89084d9af4
2023-11-01 14:40:44 +00:00
Kevin Newton a40e2b8ee9 [ruby/prism] Fix parsing lone assoc splat within hash patterns
https://github.com/ruby/prism/commit/1da5e05672
2023-10-27 02:09:33 +00:00
Kevin Newton 018f0a9c5f [ruby/prism] Rename to lefts/rights
https://github.com/ruby/prism/commit/e6deed05a5
2023-10-26 14:59:13 -04:00
Kevin Newton 922f48f081 [ruby/prism] Remove RequiredDestructuredParameterNode in favor of MultiTargetNode
https://github.com/ruby/prism/commit/6d1858192e
2023-10-26 14:59:07 -04:00
Kevin Newton 234e8fb819 [ruby/prism] Split up multi target/write targets
https://github.com/ruby/prism/commit/dda7a0da52
2023-10-26 14:58:48 -04:00
Jemma Issroff 7e4ee92de2 [ruby/prism] Add KeywordSplat flag to ArgumentsNode
Method calls with keyword splat args compile differently than
without since they merge the keyword arg hash with the keyword splat
hash. We know this information at parse time, so can set a flag
which the compiler can use.

https://github.com/ruby/prism/commit/e5f8a9a3cd
2023-10-26 18:47:50 +00:00
Kevin Newton 2a6f7cd925 [ruby/prism] Index{Operator,And,Or}WriteNode
Right now, our Call{Operator,And,Or}WriteNode nodes represent two
different concepts:

```ruby
foo.bar += 1
foo[bar] += 1
```

These two statements are different in what they can support. The
former can never have arguments (or an opening_loc or closing_loc).
The former can also never have a block. Also, the former is a
variable method name.

The latter is always going to be []/[]=, it can have any number of
arguments including blocks (`foo[&bar] ||= 1`), and will always
have an opening_loc and closing_loc.

Furthermore, these statements end of having to take different paths
through the various compilers because with the latter you have to
consider the arguments and the block, whereas the former can
perform some additional peephole optimizations since there are
fewer values on the stack.

For these reasons, I'm introducing Index{Operator,And,Or}WriteNode.
These nodes never have a read_name or write_name on them because
they are always []/[]=. They also support blocks, which the previous
write nodes didn't. As a benefit of introducing these nodes, I've
removed the opening_loc, closing_loc, and arguments from the older
write nodes because they will always be null.

For the serialized format, both of these nodes end up being
smaller, and for in-memory we're storing fewer things in general,
so we have savings all around.

I don't love that we are introducing another node that is a call
node since we generally want consumers to only have to handle a
single call, but these nodes are so specific that they would have
to be handled separately anyway since in fact call 2 methods.

https://github.com/ruby/prism/commit/70155db9cd
2023-10-18 14:23:26 +00:00
Kevin Newton 8e477af1d4 [ruby/prism] Put names on back reference read nodes
https://github.com/ruby/prism/commit/10a6403293
2023-10-14 14:15:54 +00:00
eileencodes 42484d1281 [ruby/prism] Move common flags to top bits
Moves the common flag bits to the top. This lets us eliminate the `COMMON`
constant, and also allows us to group encoding flags on a nibble so we
can more easily mask them.

https://github.com/ruby/prism/commit/895508659e
2023-10-13 19:38:57 +00:00
Kevin Newton d06523bc52 [ruby/prism] Remove now-defunct semantic_field from nodes
https://github.com/ruby/prism/commit/c82a9dad64
2023-10-13 15:31:30 -04:00
Nathan Froyd e0c66b4749 [ruby/prism] [rust] write flag accessor functions
https://github.com/ruby/prism/commit/f2333ba4c8
2023-10-04 14:22:16 +00:00
Benoit Daloze 87dad067e0 Sync with prism CallNode#name changes
* https://github.com/ruby/prism/pull/1533
2023-10-02 09:18:56 -04:00
Kevin Newton 4f73a7c2f7 Sync to prism rename commits 2023-09-27 13:57:38 -04:00
Kevin Newton 8ab56869a6 Rename YARP filepaths to prism filepaths 2023-09-27 13:57:38 -04:00