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

879 Коммитов

Автор SHA1 Сообщение Дата
Kevin Newton 9f4954559b [PRISM] Handle nth reference ERANGE with warning 2024-08-29 15:24:55 -04:00
Kevin Newton d25833b81a [ruby/prism] Multi-splat flag for arguments
https://github.com/ruby/prism/commit/21cb9b78ae
2024-08-28 21:10:39 +00:00
Kevin Newton ad737a8d0f
[PRISM] Sync version update 2024-08-28 15:43:32 -04:00
Kevin Newton 417bb8d4fd [PRISM] Field renaming
Rename some fields that do not quite make sense.

* CaseMatchNode#consequent -> CaseMatchNode#else_clause
* CaseNode#consequent -> CaseNode#else_clause
* IfNode#consequent -> IfNode#subsequent
* RescueNode#consequent -> RescueNode#subsequent
* UnlessNode#consequent -> UnlessNode#else_clause
2024-08-28 15:06:53 -04:00
Benoit Daloze d6764076a1 [ruby/prism] Review config.yml: documentation, types and field names
https://github.com/ruby/prism/commit/d43333539e
2024-08-28 17:42:56 +00:00
Kevin Newton ccef391140 [ruby/prism] Swap around order of predicates for assoc static literal
https://github.com/ruby/prism/commit/ec181a3b68
2024-08-28 15:35:23 +00:00
Kevin Newton 4c5a1dad0a [PRISM] Check length of line for shebang 2024-08-28 10:50:46 -04:00
eileencodes 2157dcb568 [ruby/prism] Add `contains_splat` flag
If we have a splat, add a flag for it named `contains_splat`.

https://github.com/ruby/prism/commit/5be97a75c8
2024-08-27 20:53:11 +00:00
eileencodes 7462cc7743 [PRISM] Fix allocations for keyword splat params
Fixes the following allocations tests:

* `test_keyword_and_keyword_splat_parameter`
* `test_keyword_parameter`
* `test_keyword_splat_parameter`
* `test_no_array_allocation_with_splat_and_nonstatic_keywords`
* `test_no_parameters`
* `test_positional_splat_and_keyword_splat_parameter`
* `test_ruby2_keywords`

* Checks for `first_chunk` and if `stack_length == 0` to match the
upstream parser. Otherwise, this optimization is skipped.
* Subtracts the index, otherwise it will skip the hash allocation for
the following: `keyword(*empty_array, a: 2, **empty_hash)`.
* Sets `dup_rest` in order to determine when to set the correct flags
* Doesn't set `VM_CALL_KW_SPLAT_MUT` flag unless `dup_rest` doesn't
match `initial_dup_rest`.

Given the following code:

```ruby
keyword(*empty_array, a: 2)
```

Instructions before:

```
== disasm: #<ISeq:test@test.rb:4 (4,0)-(8,3)>
local table (size: 2, argc: 1 [opts: 0, rest: -1, post: 0, block: -1, kw: -1@-1, kwrest: -1])
[ 2] empty_hash@0<Arg>[ 1] empty_array@1
0000 newarray                               0                         (   5)[LiCa]
0002 setlocal_WC_0                          empty_array@1
0004 putself                                                          (   7)[Li]
0005 getlocal_WC_0                          empty_array@1
0007 splatarray                             true
0009 putobject                              :a
0011 putobject                              2
0013 newhash                                2
0015 opt_send_without_block                 <calldata!mid:keyword, argc:2, ARGS_SPLAT|ARGS_SPLAT_MUT|FCALL|KW_SPLAT>
0017 leave                                                            (   8)[Re]
```

Instructions after:

```
== disasm: #<ISeq:test@test.rb:4 (4,0)-(8,3)>
local table (size: 2, argc: 1 [opts: 0, rest: -1, post: 0, block: -1, kw: -1@-1, kwrest: -1])
[ 2] empty_hash@0<Arg>[ 1] empty_array@1
0000 newarray                               0                         (   5)[LiCa]
0002 setlocal_WC_0                          empty_array@1
0004 putself                                                          (   7)[Li]
0005 getlocal_WC_0                          empty_array@1
0007 splatarray                             false
0009 putobject                              {:a=>2}
0011 opt_send_without_block                 <calldata!mid:keyword, argc:2, ARGS_SPLAT|FCALL|KW_SPLAT>
0013 leave                                                            (   8)[Re]
```

Differences:

* `splatarray` is `false` not `true
* `putobject`, `putobject`, `newhash` is simply `putobject` with
optimizations on
* Remove `ARGS_SPLAT_MUT` flag

Related: ruby/prism#2994

Co-authored-by: Kevin Newton <kddnewton@gmail.com>
2024-08-27 16:01:46 -04:00
Alexander Momchilov 2fbaff5351 [ruby/prism] Fix warning when `#!` ends with carriage return
https://github.com/ruby/prism/commit/5753fb6260
2024-08-27 16:46:44 +00:00
Alexander Momchilov 83e72fde83 Optimize Array allocations
… by allocating them with the correct capacity.
2024-08-27 16:23:50 +00:00
Kevin Newton 4ede15fb53 [PRISM] Fix up nested string flags inside string concatenation 2024-08-26 10:49:35 -04:00
Alexander Momchilov 2b0b68fa46 Shrink `pm_integer_t` (32 bytes → 24) 2024-08-26 12:38:58 +00:00
Nobuyoshi Nakada 620ce3807b
[Bug #20680] `ensure` block is always void context 2024-08-25 08:16:54 +09:00
Kevin Newton 3eb42054d9 [ruby/prism] Pass Unicode escapes on to onigmo
When we encounter an invalid unicode escape within a regular
expression, we now pass that error on to Onigmo as if it didn't
exist in the parser (which matches the upstream parser's behavior).

We do this because there are tests that specify that you are
allowed to have invalid Unicode escapes if they are within the
context of a regular expression comment for a regular expression
in extended mode. That looks like:

    /# \u /x

Note that this _only_ applies to Unicode escapes (as opposed to
applying to hex or meta/control escapes as well). Importantly it
also only applies if the regular expression is terminated. An
unterminated regular expression will still get error handling done
in the parser. That would look like:

    /# \u

that would result in the same error handling we have today.

https://github.com/ruby/prism/commit/fb98034806
2024-08-23 19:18:14 +00:00
Kevin Newton 3f30c4df8c [ruby/prism] Update templates/include/prism/ast.h.erb
https://github.com/ruby/prism/commit/7f7620b6d5
2024-08-22 15:23:33 +00:00
Alexander Momchilov 0ef703b91c [ruby/prism] Render node comments into their `ast.h`
https://github.com/ruby/prism/commit/b17c3241d3
2024-08-22 15:23:32 +00:00
Kevin Newton d57486cb10 [ruby/prism] Turn off extended mode when parsing extended group
https://github.com/ruby/prism/commit/098b3f08bc
2024-08-22 14:43:35 +00:00
Kevin Newton 5cb6954baa [ruby/prism] Fix up lex result constants
https://github.com/ruby/prism/commit/084baca463
2024-08-15 16:50:00 +00:00
Kevin Newton cbf508da58 [ruby/prism] Special error for too short unicode errors
https://github.com/ruby/prism/commit/9f1f7d08bd
2024-08-15 16:40:05 +00:00
Kevin Newton a952ea243f [ruby/prism] Callback on shebang switches
Add the ability to receive a callback when the parser encounters a
shebang that contains additional switches after the Ruby engine.
This is necessary because some command-line flags may be present
there that will alter the parse.

https://github.com/ruby/prism/commit/afc5000331
2024-08-14 17:40:43 +00:00
Kevin Newton a6581114b0 [ruby/prism] Fix up spacing in generated node.rb
https://github.com/ruby/prism/commit/50d79b734b
2024-08-13 12:41:07 +00:00
Koichi ITO ad23bbe574 [ruby/prism] [Doc] Tweak the docs for lex APIs
`Prism.lex` and `Prism.lex_file` return `ParseLexResult` instead of `Array`.
`Prism::parse_lex` and `Prism::parse_lex_file` return `ParseLexResult` instead of `ParseResult`.
This PR updates the documentation to reflect these return values.

https://github.com/ruby/prism/commit/ee331941c0
2024-08-10 08:42:36 +00:00
Yuta Saito a65c205a1b [ruby/prism] Add explicit check for PRISM_HAS_NO_FILESYSTEM
https://github.com/ruby/prism/commit/89c22f0e6c
2024-07-26 17:07:50 +00:00
Yuta Saito 1992bd31a5 [ruby/prism] Fallback to pm_string_file_init on platforms without memory-mapped files
> ..., and on other POSIX systems we'll use `read`.

As `pm_string_mapped_init`'s doc comment says, it should fall back to
`read(2)`-based implementation on platforms without memory-mapped files
like WASI, but it didn't. This commit fixes it by calling `pm_string_file_init`
in the fallback case.
Also `defined(_POSIX_MAPPED_FILES)` check for `read(2)`-based path is
unnecessary, and it prevents the fallback from being executed, so this
change removes it.

https://github.com/ruby/prism/commit/b3d9064b71
2024-07-26 17:07:50 +00:00
Benoit Daloze 53f0d3b1f7 [ruby/prism] Do not serialize common flags when PRISM_SERIALIZE_ONLY_SEMANTICS_FIELDS is set
* Note that we could shift the flags by 2 on serialize & deserialize
  but it does not seems worth it as it does not save serialized size
  in any significant amount, i.e. average was 0.799 before #2924.
* $ bundle exec rake serialized_size:topgems
Before:
Total sizes for top 100 gems:
total source size:      90207647
total serialized size:  69477115
total serialized/total source: 0.770

Stats of ratio serialized/source per file:
average: 0.844
median:  0.825
1st quartile: 0.597
3rd quartile: 1.064
min - max: 0.078 - 3.792

After:
Total sizes for top 100 gems:
total source size:      90207647
total serialized size:  66150209
total serialized/total source: 0.733

Stats of ratio serialized/source per file:
average: 0.800
median:  0.779
1st quartile: 0.568
3rd quartile: 1.007
min - max: 0.076 - 3.675

https://github.com/ruby/prism/commit/e012072f70
2024-07-25 11:39:05 +00:00
Benoit Daloze 9cc2747ebb [ruby/prism] Do not serialize node_id when PRISM_SERIALIZE_ONLY_SEMANTICS_FIELDS is set
* $ bundle exec rake serialized_size:topgems
Before:
Total sizes for top 100 gems:
total source size:      90207647
total serialized size:  86284647
total serialized/total source: 0.957

Stats of ratio serialized/source per file:
average: 0.952
median:  0.937
1st quartile: 0.669
3rd quartile: 1.206
min - max: 0.080 - 4.065

After:
Total sizes for top 100 gems:
total source size:      90207647
total serialized size:  69477115
total serialized/total source: 0.770

Stats of ratio serialized/source per file:
average: 0.844
median:  0.825
1st quartile: 0.597
3rd quartile: 1.064
min - max: 0.078 - 3.792

https://github.com/ruby/prism/commit/cf90fe5759
2024-07-25 11:39:04 +00:00
Kevin Newton 575fe63e20 [ruby/prism] Inherit ractor state for child scopes
https://github.com/ruby/prism/commit/4576cb1d96
2024-07-24 16:24:21 +00:00
Nobuyoshi Nakada e642ddf7ae
[Bug #20647] Disallow `return` directly within a singleton class 2024-07-24 14:44:32 +09:00
Kevin Newton cb863907d8 [ruby/prism] Single line method bodies should not be marked as newline
https://github.com/ruby/prism/commit/18a8597276
2024-07-23 18:44:31 +00:00
Kevin Newton 744cf0549e [ruby/prism] Recurse upward to detect invalid returns
https://github.com/ruby/prism/commit/3d39b7961f
2024-07-23 14:54:01 +00:00
Kevin Newton 959c95a01e [ruby/prism] Ignore shebangs in evals
https://github.com/ruby/prism/commit/4c55409794
2024-07-22 19:46:26 +00:00
Kevin Newton 2effa98b6f [ruby/prism] Implement mismatched indentation warning
https://github.com/ruby/prism/commit/5d5bf92be8
2024-07-22 18:57:10 +00:00
Kevin Newton 1e4c4fe478 [ruby/prism] Fix parsing parentheses in hash patterns
https://github.com/ruby/prism/commit/22c3b559cd
2024-07-19 12:55:49 +00:00
Kevin Newton 059535bd65 [ruby/prism] Mark local variable writes in value positions as being read
https://github.com/ruby/prism/commit/f5149870ab
2024-07-18 19:38:53 +00:00
Kevin Newton 8e5ac5a87d [PRISM] Ensure not opening directories 2024-07-18 13:03:25 -04:00
Kevin Newton e77e4aa608 [ruby/prism] Have parse_stream handle NUL bytes
https://github.com/ruby/prism/commit/4a41d298c8
2024-07-17 19:44:32 +00:00
Koichi ITO 0fe816f380 [ruby/prism] [Doc] Tweak example of `Prism::Dispatcher`
This PR tweaked the documentation to correct an error encountered
when running the example code of `Prism::Dispatcher`.
This aims to make understanding the example smoother.

https://github.com/ruby/prism/commit/165a1a0e78
2024-07-17 18:17:59 +00:00
Nobuyoshi Nakada 644424941a [Bug #20457] [Prism] Remove redundant return flag 2024-07-17 14:06:11 -04:00
Kevin Newton c06f79c575 [ruby/prism] Fix up implicit flags
https://github.com/ruby/prism/commit/f4152c1f50
2024-07-15 18:12:37 +00:00
Kevin Newton 6298667ff5 [ruby/prism] When parsing an invalid write, still add to the local table
https://github.com/ruby/prism/commit/a54abc4d1b
2024-07-12 13:50:00 +00:00
Kevin Newton cfaa3e9311 [ruby/prism] Bump typecheck dependencies to fix CI
https://github.com/ruby/prism/commit/c7a4a90ee8
2024-07-11 19:46:51 +00:00
Kevin Newton ac093f5a06 [PRISM] Fix up shareable constant casting 2024-07-11 14:25:54 -04:00
Kevin Newton c1df15c3e6 [PRISM] Use node ids for error highlight 2024-07-11 14:25:54 -04:00
Stan Lo be4589df80 [ruby/prism] Prevent optional block parameter from accepting certain prefixed values
This commit prevents the following unary operators from being accepted
as the value prefix of a block's optional parameter:

- `+`
- `-`
- `~`
- `!`

For example, `f { |a = +b| }` will now raise a syntax error.

https://github.com/ruby/prism/commit/3024bee60c

Co-authored-by: Kevin Newton <kddnewton@gmail.com>
2024-07-11 14:25:54 -04:00
Kevin Newton aa473489a2 [ruby/prism] Various cleanup for initializers and typechecks
https://github.com/ruby/prism/commit/86cf82794a
2024-07-11 14:25:54 -04:00
Kevin Newton 2bf9ae3fa1 [ruby/prism] Add node ids to nodes
https://github.com/ruby/prism/commit/bf16ade7f9
2024-07-11 14:25:54 -04:00
Kevin Newton 39dcfe26ee [ruby/prism] Move Node#type and Node::type documentation
https://github.com/ruby/prism/commit/08a71f6259
2024-07-11 14:25:54 -04:00
Kevin Newton 32090e2b8d [ruby/prism] Add Node#breadth_first_search
https://github.com/ruby/prism/commit/1ffb141199
2024-07-11 14:25:54 -04:00
Kevin Newton aca42a2478 [ruby/prism] Expose common flags in inspect output
https://github.com/ruby/prism/commit/d0143865c2
2024-07-11 14:25:54 -04:00