diff options
author | Kevin Newton <kddnewton@gmail.com> | 2023-10-17 11:15:56 -0400 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2023-10-18 14:23:26 +0000 |
commit | 2a6f7cd9255b61e21cead0c761a513bde2899728 (patch) | |
tree | 7d8f270506d907f970973cdb576513e7d3b62b93 /prism/config.yml | |
parent | ef3f9f1a685effb51543d1f08831692fa68863a2 (diff) | |
download | ruby-2a6f7cd9255b61e21cead0c761a513bde2899728.tar.gz |
[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
Diffstat (limited to 'prism/config.yml')
-rw-r--r-- | prism/config.yml | 104 |
1 files changed, 83 insertions, 21 deletions
diff --git a/prism/config.yml b/prism/config.yml index 6eaa6f1365..89d3113938 100644 --- a/prism/config.yml +++ b/prism/config.yml @@ -633,13 +633,6 @@ nodes: type: location? - name: message_loc type: location? - - name: opening_loc - type: location? - - name: arguments - type: node? - kind: ArgumentsNode - - name: closing_loc - type: location? - name: flags type: flags kind: CallNodeFlags @@ -706,13 +699,6 @@ nodes: type: location? - name: message_loc type: location? - - name: opening_loc - type: location? - - name: arguments - type: node? - kind: ArgumentsNode - - name: closing_loc - type: location? - name: flags type: flags kind: CallNodeFlags @@ -739,13 +725,6 @@ nodes: type: location? - name: message_loc type: location? - - name: opening_loc - type: location? - - name: arguments - type: node? - kind: ArgumentsNode - - name: closing_loc - type: location? - name: flags type: flags kind: CallNodeFlags @@ -1446,6 +1425,89 @@ nodes: case a; in b then c end ^^^^^^^^^^^ + - name: IndexAndWriteNode + fields: + - name: receiver + type: node? + - name: call_operator_loc + type: location? + - name: opening_loc + type: location + - name: arguments + type: node? + kind: ArgumentsNode + - name: closing_loc + type: location + - name: block + type: node? + - name: flags + type: flags + kind: CallNodeFlags + - name: operator_loc + type: location + - name: value + type: node + comment: | + Represents the use of the `&&=` operator on a call to the `[]` method. + + foo.bar[baz] &&= value + ^^^^^^^^^^^^^^^^^^^^^^ + - name: IndexOperatorWriteNode + fields: + - name: receiver + type: node? + - name: call_operator_loc + type: location? + - name: opening_loc + type: location + - name: arguments + type: node? + kind: ArgumentsNode + - name: closing_loc + type: location + - name: block + type: node? + - name: flags + type: flags + kind: CallNodeFlags + - name: operator + type: constant + - name: operator_loc + type: location + - name: value + type: node + comment: | + Represents the use of an assignment operator on a call to `[]`. + + foo.bar[baz] += value + ^^^^^^^^^^^^^^^^^^^^^ + - name: IndexOrWriteNode + fields: + - name: receiver + type: node? + - name: call_operator_loc + type: location? + - name: opening_loc + type: location + - name: arguments + type: node? + kind: ArgumentsNode + - name: closing_loc + type: location + - name: block + type: node? + - name: flags + type: flags + kind: CallNodeFlags + - name: operator_loc + type: location + - name: value + type: node + comment: | + Represents the use of the `||=` operator on a call to `[]`. + + foo.bar[baz] ||= value + ^^^^^^^^^^^^^^^^^^^^^^ - name: InstanceVariableAndWriteNode fields: - name: name |