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

353 Коммитов

Автор 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
Gopal Patel b9542246c9 [ruby/prism] Fix majority of RBS type mismatches
https://github.com/ruby/prism/commit/62cc50e41b
2023-12-15 21:14:58 +00:00
eileencodes 2e8cfcac91 [ruby/prism] String literal hash keys should be frozen
String literal hash keys can't be mutated by the user so we should mark
them as frozen. We were seeing instructions for hashes with string
literal keys using two `putstring` instructions when it should be a
`putobject` and `putstring`.

Code example:

```ruby
{ "a" => "b" }
```

Instructions before:

```
"********* Ruby *************"
== disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(2,14)>
0000 putobject                              "a"                       (   2)[Li]
0002 putstring                              "b"
0004 newhash                                2
0006 leave
"********* PRISM *************"
== disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(1,14)>
0000 putstring                              "a"                       (   1)[Li]
0002 putstring                              "b"
0004 newhash                                2
0006 leave
```

Instructions after:

```
"********* Ruby *************"
== disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(2,14)>
0000 putobject                              "a"                       (   2)[Li]
0002 putstring                              "b"
0004 newhash                                2
0006 leave

"********* PRISM *************"
== disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(1,14)>
0000 putobject                              "a"                       (   1)[Li]
0002 putstring                              "b"
0004 newhash                                2
0006 leave
```

https://github.com/ruby/prism/commit/b14ae55385
2023-12-15 20:55:13 +00: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 f38814564b [ruby/prism] Fix eval parsing depth
https://github.com/ruby/prism/commit/89bf7a4948
2023-12-15 15:19:50 +00:00
Kevin Newton fe9b42f024 [ruby/prism] Invalid pinned locals in pattern matching
https://github.com/ruby/prism/commit/3a67b37a56
2023-12-15 15:03:49 +00:00
Kevin Newton 854ff25f4f [ruby/prism] Add TODO comment
https://github.com/ruby/prism/commit/885d1d78cb
2023-12-15 13:26:40 +00:00
TSUYUSATO Kitsune 16830a4783 [ruby/prism] Add an error for `in` keyword in arguments
Fix https://github.com/ruby/prism/pull/2026

https://github.com/ruby/prism/commit/c4b41cd477
2023-12-15 13:25:54 +00:00
Kevin Newton 8bbe835cd8
Bump prism to version 0.19.0 2023-12-14 15:06:09 -05:00
Kevin Newton 019fff3a86 [ruby/prism] Fix parse result for nesting pattern matching
https://github.com/ruby/prism/commit/ee6fc9ee87
2023-12-14 18:54:46 +00:00
Ufuk Kayserilioglu 01f21d5729 [ruby/prism] Fix the implementation of the flag on keyword hash nodes
The previous implementation was incorrect since it was just checking for all keys in assoc nodes to be static literals but the actual check is that all keys in assoc nodes must be symbol nodes.

This commit fixes that implementation, and, also, aliases the flag to `PM_KEYWORD_HASH_NODE_FLAGS_SYMBOL_KEYS` so that ruby/ruby can start using the new flag name.

I intend to later change the real flag name to `PM_KEYWORD_HASH_NODE_FLAGS_SYMBOL_KEYS` and remove the alias.

https://github.com/ruby/prism/commit/f5099c79ce
2023-12-14 18:05:54 +00:00
TSUYUSATO Kitsune 3658798dbb [ruby/prism] Make equality operators non-associative
Fix https://github.com/ruby/prism/pull/2073

https://github.com/ruby/prism/commit/0f747d9240
2023-12-14 16:39:05 +00:00
Kevin Newton b7e89d4b17 [ruby/prism] Fix hash pattern rest
https://github.com/ruby/prism/commit/43c4232cfc
2023-12-14 02:43:32 +00:00
Alex Koval 36ca99b343 [ruby/prism] fix typo in docs
https://github.com/ruby/prism/commit/d7fbc09345
2023-12-13 12:17:57 +00:00
Ufuk Kayserilioglu e96f6126f2 [ruby/prism] Fix hash deopt based on contents
The previous implementation of hash deopt was based on clearing the static literal flag on a hash node if the element that was being added was an array, hash or range node, or if the element was not a static literal in the first place.

However, this is not correct. First of all, the elements added to a hash node will primarily be assoc nodes, but never array, hash or range nodes. Secondly, the static literal flag is set on assoc nodes, only if the value in an assoc node is a static literal, so the key is never checked. As a result, the static literal flag on a hash node would never be cleared if the key wasn't a static literal.

This commit fixes this by clearing the static literal flag if:
1. the element is not an assoc node,
2. the element is an assoc node, but the key is not a static literal, or
3. the element is an assoc node, the key is a static literal, but assoc node (and thus the value in assoc node) is not a static literal.

https://github.com/ruby/prism/commit/7f67109b36
2023-12-13 00:21:42 +00:00
Kevin Newton f61df27b4c [ruby/prism] Use new flag setters for attribute write
https://github.com/ruby/prism/commit/1e07832778
2023-12-12 18:43:59 +00:00
Ufuk Kayserilioglu 1f22245ed5 [ruby/prism] Start using flag macros/methods exclusively
https://github.com/ruby/prism/commit/5f05a6fe83
2023-12-12 17:35:53 +00:00
Ufuk Kayserilioglu bdb38dd9f2 [ruby/prism] Add methods for setting/unsetting and macros for testing a flags
https://github.com/ruby/prism/commit/e5f37d1407
2023-12-12 17:35:52 +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 43229d531f [ruby/prism] Start `KeywordHashNode`s with `STATIC_KEYS` set, until hit an element that should clear it
https://github.com/ruby/prism/commit/7c7c486507
2023-12-12 13:05:09 +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 4095e7d2be [ruby/prism] Regexp terminator escapes
https://github.com/ruby/prism/commit/42a48a2ba9
2023-12-11 16:34:55 +00:00
Kevin Newton c65de63913 [ruby/prism] Handle a non-interpolated dsym spanning a heredoc
https://github.com/ruby/prism/commit/b23136ebfd
2023-12-11 16:34:41 +00:00
Kevin Newton 261e8f28a0 [ruby/prism] Correct escapes when ctrl+meta+escape
https://github.com/ruby/prism/commit/ee68b17c01
2023-12-11 16:34:27 +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
TSUYUSATO Kitsune 48cb70fee9 [ruby/prism] Fix parsing unterminated empty string `"`
Fix https://github.com/ruby/prism/pull/2034

https://github.com/ruby/prism/commit/8280e577fa
2023-12-11 13:36:37 +00:00
TSUYUSATO Kitsune a860e3605c [ruby/prism] Fix to parse a (endless-)range with binary operators
Fix https://github.com/ruby/prism/pull/2022
Fix https://github.com/ruby/prism/pull/2030

https://github.com/ruby/prism/commit/b78d8b6525
2023-12-11 13:34:48 +00:00
Alex Koval 04eb1b6f26 [ruby/prism] fix: escape newline
https://github.com/ruby/prism/commit/a28b427dcc
2023-12-10 03:06:36 +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 a54eb9c6f9 [ruby/prism] A couple of small dot enhancements
https://github.com/ruby/prism/commit/5642a57f39
2023-12-08 14:40:32 +00:00
Aaron Patterson 0166040939 [ruby/prism] Hashes need to deoptimize based on their contents
If a hash has children that are not "basic" types of objects, then we
can't consider the hash to be a static literal.

Fixes: #2015

https://github.com/ruby/prism/commit/ca2523137d
2023-12-08 14:35:26 +00:00
Kevin Newton 892b5f10d5 [ruby/prism] More closely match CRuby error messages
https://github.com/ruby/prism/commit/1ed07a0c6d
2023-12-08 14:34:34 +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 10bc0bd4ab [ruby/prism] Remove warnings check from parse_success? method
https://github.com/ruby/prism/commit/e30a241fb3
2023-12-07 14:39:11 +00:00
Haldun Bayhantopcu ce094e8556 [ruby/prism] Emit error for constant assignments in defs
https://github.com/ruby/prism/commit/864b06f90e
2023-12-06 22:15:16 +00:00
Kevin Newton c5a4409f20 [ruby/prism] Simplify unterminated string
https://github.com/ruby/prism/commit/ef512ca914
2023-12-06 21:34:48 +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
TSUYUSATO Kitsune cbb941f58a [ruby/prism] Fix closing loc for string literals
Fix https://github.com/ruby/prism/pull/1974

https://github.com/ruby/prism/commit/453d403593
2023-12-06 20:48:11 +00:00
Haldun Bayhantopcu a57186b9d1 [ruby/prism] Fix one potential memory leak and silence one false positive report.
https://github.com/ruby/prism/commit/9608aa386e
2023-12-06 20:38:22 +00:00
Kevin Newton 82072254a0 [ruby/prism] Update documentation for encodings
https://github.com/ruby/prism/commit/18e6df0d4f
2023-12-06 19:26:35 +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
HParker b8b319dd1a Revert "allow enabling Prism via flag or env var"
This reverts commit 9b76c7fc89.
2023-12-06 10:21:12 +09:00
eileencodes a33632e1ca [ruby/prism] Fix defined with new line
It's possible to write the following and have it be valid Ruby:

```
defined?("foo"
)
```

But Prism wasn't taking the new line into account. This adds an
`accept1` for a `PM_TOKEN_NEWLINE` to account for this. I've also
updated the fixtures and snapshots to test this.

https://github.com/ruby/prism/commit/b87f8eedc6
2023-12-05 20:47:22 +00:00
HParker 9b76c7fc89 allow enabling Prism via flag or env var
Enable Prism using either --prism

    ruby --prism test.rb

or via env var

    RUBY_PRISM=1 ruby test.rb
2023-12-05 12:17:14 -05:00
Haldun Bayhantopcu 94bf9f8037 [ruby/prism] Remove unnecessary match
https://github.com/ruby/prism/commit/694d3d7279
2023-12-05 15:25:20 +00:00
TSUYUSATO Kitsune ff6706b08e [ruby/prism] Fix a typo
https://github.com/ruby/prism/pull/1949#discussion_r1412568793

https://github.com/ruby/prism/commit/a00f21d10a
2023-12-05 15:16:42 +00:00
TSUYUSATO Kitsune 975b74a8eb [ruby/prism] Fix argument order
https://github.com/ruby/prism/pull/1949#discussion_r1410733341

https://github.com/ruby/prism/commit/27635da821

Co-Authored-By: Kevin Newton <kddnewton@gmail.com>
2023-12-05 15:16:41 +00:00
TSUYUSATO Kitsune 3d4a4b2529 [ruby/prism] Fix some corner cases
https://github.com/ruby/prism/commit/d5453f168e
2023-12-05 15:16:41 +00:00
TSUYUSATO Kitsune dcd75fd49d [ruby/prism] Fix to parse command-style method calls more correctly
Fix https://github.com/ruby/prism/pull/1468
Fix https://github.com/ruby/prism/pull/1575

To decide command-style method calls are allowed, this introduce a new
parameter `accepts_command_call` to `parse_expression` and some
functions.

Although one think this can be solved by operator precedence, it is
hard or impossible, because the precedence of command-style calls is skewed
(e.g. `! bar 1 ` is accepted, but `foo = ! bar 1` is rejected.)

One of the most complex examples is that:
(1) even though `foo = bar = baz 1` and `foo, bar = baz 1` is accepted,
(2) `foo, bar = baz = fuzz 1` is rejected.
To implement this behavior, this introduces a new binding power
`PM_BINDING_POWER_MULTI_ASSIGNMENT` and uses it for distinguish which single
assignments or multi assignments at their RHS.

https://github.com/ruby/prism/commit/d4dd49ca81
2023-12-05 15:16:40 +00:00