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

2461 Коммитов

Автор SHA1 Сообщение Дата
Yusuke Endoh 25d74b9527 Do not include a backtick in error messages and backtraces
[Feature #16495]
2024-02-15 18:42:31 +09:00
Nobuyoshi Nakada c57880e68d
Show the invalid source encoding in messages 2024-02-15 13:39:33 +09:00
Peter Zhu a71d1ed838 Fix memory leak when parsing invalid hash symbol
For example:

    10.times do
      100_000.times do
        eval('{"\xC3": 1}')
      rescue EncodingError
      end

      puts `ps -o rss= -p #{$$}`
    end

Before:

    32032
    48464
    66112
    84192
    100592
    117520
    134096
    150656
    167168
    183760

After:

    17120
    17120
    17120
    17120
    18560
    18560
    18560
    18560
    18560
    18560
2024-02-13 11:05:56 -05:00
yui-knk 038189b61f Use dedicated parser_string hash function
Define and use `rb_parser_str_hash` for `rb_parser_string_t`
instead of `rb_str_hash` to remove dependency on `rb_str_hash`.
2024-02-13 10:56:32 +09:00
yui-knk 8a345860d3 Warn duplication of `__ENCODING__` on the hash
```
$ ruby -e 'h = { __ENCODING__ => 1, __ENCODING__ => 2 }'
-e:1: warning: key #<Encoding:UTF-8> is duplicated and overwritten on line 1
```
2024-02-13 08:40:14 +09:00
yui-knk 7fc89a9262 Use Node for `warn_duplicate_keys` st_table keys 2024-02-12 17:46:22 +09:00
yui-knk fdd92c2d61 Fix the variable to be checked
It should check the result of `rb_parser_search_nonascii`.
2024-02-10 18:58:42 +09:00
yui-knk 33c1e082d0 Remove ruby object from string nodes
String nodes holds ruby string object on `VALUE nd_lit`.
This commit changes it to `struct rb_parser_string *string`
to reduce dependency on ruby object.
Sometimes these strings are concatenated with other string
therefore string concatenate functions are needed.
2024-02-09 14:20:17 +09:00
Peter Zhu b2392c6be4 Fix memory leak when parsing invalid pattern matching
If the pattern matching is invalid, then the pvtbl would get leaked. For
example:

    10.times do
      100_000.times do
        eval(<<~RUBY)
          case {a: 1}
          in {"a" => 1}
          end
        RUBY
      rescue SyntaxError
      end

      puts `ps -o rss= -p #{$$}`
    end

Before:

    28096
    44768
    61472
    78512
    94992
    111504
    128096
    144528
    161008
    177472

After:

    14096
    14112
    14112
    14176
    14208
    14240
    14240
    14240
    14240
    14240
2024-02-07 12:15:33 -05:00
yui-knk 68b57ceb46 Use bool to check ascii only in parse_ident
No need to use ENC_CODERANGE to record ascii only or not.
2024-02-03 09:15:41 +09:00
S.H f3df218f48
Introduced `rb_node_const_decl_val` function
Introduce `rb_node_const_decl_val` function to allow `rb_ary_join` and
`rb_ary_reverse` functions to be removed from Universal Parser.
2024-01-31 13:31:38 +09:00
Nobuyoshi Nakada 23b8337cd1
[Bug #20219] `gettable` returns NULL on error 2024-01-28 19:15:31 +09:00
Nobuyoshi Nakada 5f733a1ae7
[Bug #20217] `rescue` block is void only if all children are void 2024-01-28 18:44:09 +09:00
Nobuyoshi Nakada fed877c791
[Bug #20217] `return` with `ensure` is a void value expression 2024-01-28 18:44:09 +09:00
Nobuyoshi Nakada e018036d89
Rename `nd_head` in `RNode_RESBODY` as `nd_next` 2024-01-28 11:12:22 +09:00
Nobuyoshi Nakada 0f98d284f3
Remove unused `nd_resq` from `RNode_ENSURE` 2024-01-28 11:11:13 +09:00
S.H 9b40f42c22
Introduce `NODE_ENCODING`
`__ENCODING__ `was managed by `NODE_LIT` with Encoding object. 

Introduce `NODE_ENCODING` for
1. `__ENCODING__` is detectable from AST Node.
2. Reduce dependency Ruby object for parse.y
2024-01-27 08:11:10 +00:00
yui-knk 68b9a32a62 bvar is not NODE but ID
Before this commit `ruby -y -e 'tap {|;x, y|}'` failed with SEGV.
This change fixes it.
2024-01-27 16:50:35 +09:00
Nobuyoshi Nakada ff55d6b8e1
Use `token_seen` and simplify `comment_at_top`
Instead of scanning before the current comment.
2024-01-25 15:06:14 +09:00
Jeremy Evans 4f77d8d328 Do not use ruby2_keywords for ... argument forwarding
This allows ... argument forwarding to benefit from Allocationless
Anonymous Splat Forwarding, allowing the `f` call below to not
allocate an array or a hash.

```ruby
a = [1]
kw = {b: 2}

def c(a, b:)
end

def f(...)
  c(...)
end

f(*a, **kw)
```

This temporarily skips prism locals tests until prism is changed
to use * and ** for ..., instead of using ruby2_keywords.

Ignore failures in rbs bundled gems tests, since they fail due
to this change.
2024-01-24 18:25:55 -08:00
yui-knk ee7f63ebba Make lastline and nextline to be rb_parser_string
This commit changes `struct parser_params` lastline and nextline
from `VALUE` (String object) to `rb_parser_string_t *` so that
dependency on Ruby Object is reduced.
`parser_string_buffer_t string_buffer` is added to `struct parser_params`
to manage `rb_parser_string_t` pointers of each line. All allocated line
strings are freed in `rb_ruby_parser_free`.
2024-01-23 08:58:16 +09:00
yui-knk 3d19409637 Use index for referring to symbols in `args` rule instead of named references
In `args: args ',' arg_splat`, `args` is not unique name.
Currently the associated rule is interpreted as
`$$ = rest_arg_append(p, $$, $3, &@$);`.
The action works as expected because `$$` is initialized with
`$1` before each action is executed.
However it's misleading then change to use index.
2024-01-22 16:05:43 +09:00
Nobuyoshi Nakada 0610f555ea
Constify `rb_global_parser_config` 2024-01-14 17:55:11 +09:00
yui-knk ccd45a1399 Stop using Array to manage dummy `end` token locations
Before this commit, Array is used to store token locations
which expect `end` token, e.g. `class` and `module`.
This commit introduces dedicated struct to manage them
so that dependency on Ruby Object is reduced.
2024-01-13 20:41:22 +09:00
S-H-GAMELINKS 524770d3dc Suppress warnings in parser_set_encode function 2024-01-12 22:46:07 +09:00
yui-knk b35e21b388 Remove reference counter from rb_parser_config
It's allocated outside of parser then no need to track
reference count in rb_parser_config.
2024-01-12 21:17:41 +09:00
yui-knk 52d9e55903 Statically allocate parser config 2024-01-12 21:17:41 +09:00
yui-knk c3b2436154 `set_yylval_literal` is not used 2024-01-12 21:11:00 +09:00
Nobuyoshi Nakada 3d3bc029c5
Reject encodings determined at runtime as source code encodings
The encodings determined at runtime are affected by the runtime
environment, such as the OS and locale, while the file contents are
not.
2024-01-11 18:46:51 +09:00
Nobuyoshi Nakada 7cc8d58cc9
Remove duplicate function `nd_st_key_val` 2024-01-11 17:46:09 +09:00
S-H-GAMELINKS a971229462 Fixed return values for some node types in nd_st_key function 2024-01-11 12:26:30 +09:00
Nobuyoshi Nakada e59a730477
`st_index_t` is not `VALUE` 2024-01-10 14:06:33 +09:00
Peter Zhu 02d8bad6e1 Fix memory leak in parser for invalid syntax
The strterm is leaked when there is invalid syntax.

For example:

    10.times do
      100_000.times do
        begin
          RubyVM::InstructionSequence.compile('private def foo = puts "Hello"')
        rescue SyntaxError
        end
      end

      puts `ps -o rss= -p #{$$}`
    end

Before:

    20384
    26256
    32592
    36720
    42016
    47888
    53248
    57456
    62928
    65936

After:

    16720
    17488
    17616
    17616
    17616
    17616
    17616
    17616
    17616
    16032

Co-Authored-By: Kevin Newton <kddnewton@gmail.com>
2024-01-09 09:41:02 -05:00
Nobuyoshi Nakada 38bc107f0b
Convert a series of `else if` lines to a `switch` 2024-01-09 18:47:15 +09:00
yui-knk db476cc71c Introduce NODE_SYM to manage symbol literal
`:sym` was managed by `NODE_LIT` with `Symbol` object.
This commit introduces `NODE_SYM` so that

1. Symbol literal is detectable from AST Node
2. Reduce dependency on ruby object
2024-01-09 16:07:19 +09:00
Nobuyoshi Nakada 4b01983bf8
Simplify empty hahs with DSTAR 2024-01-09 13:05:34 +09:00
Nobuyoshi Nakada a4406bc89a
Extract repeating NODE references as a local variable 2024-01-09 13:04:26 +09:00
yui-knk 5ecf2d2880 Use `strcmp` to compare strings 2024-01-09 07:42:44 +09:00
yui-knk 41e2d180a3 Do not convert NODE_STR to NODE_LIT when the string is hash key
parse.y converted NODE_STR when the string is hash key like

```
h1 = {"str1" => 1}
m1("str2" => 2)
m2({"str3" => 3})
```

This commit stop the conversion.
`static_literal_node_p` needs to know the node is for hash key or not
for the optimization.
2024-01-08 18:48:24 +09:00
yui-knk 7ffff3e043 Change numeric node value functions argument to `NODE *`
Change the argument to align with other node value functions
like `rb_node_line_lineno_val`.
2024-01-08 14:02:48 +09:00
yui-knk 9527093759 Fix numeric node print by `-y` option
These nodes are not NOTE_LIT, so need to treat separately.
2024-01-08 11:57:30 +09:00
Nobuyoshi Nakada 8b86d6f0c1
Suppress unused-but-set-variable warning in ripper
`set_yylval_node` in ripper does not use the argument at all.
2024-01-08 01:23:58 +09:00
Nobuyoshi Nakada c30b8ae947
Adjust styles and indents [ci skip] 2024-01-08 00:50:41 +09:00
S-H-GAMELINKS ad7aee35e4 Remove unneeded rb_parser_config_struct struct properties for Universal Parser 2024-01-07 21:16:31 +09:00
yui-knk 83c98ead4e Do not remove hash duplicated keys in parse.y
When hash keys are duplicated, e.g. `h = {k: 1, l: 2, k: 3}`,
parser changes node structure for correct compilation.
This generates tricky AST. This commit removes AST manipulation
from parser to keep AST structure simple.
2024-01-07 16:18:16 +09:00
yui-knk 9d3dcb86d1 Check hash key duplication for `__LINE__` and `__FILE__` 2024-01-07 14:32:10 +09:00
S-H-GAMELINKS 1b8d01136c Introduce Numeric Node's 2024-01-07 09:24:34 +09:00
yui-knk 7a050638b1 Introduce NODE_FILE
`__FILE__` was managed by `NODE_STR` with `String` object.
This commit introduces `NODE_FILE` and `struct rb_parser_string` so that

1. `__FILE__` is detectable from AST Node
2. Reduce dependency ruby object
2024-01-02 14:19:42 +09:00
yui-knk 6ec4d203f7 Warn "literal in condition" for `__LINE__`
Print warning for a code like

```ruby
if __LINE__
end

# => warning: literal in condition
```
2024-01-02 09:50:32 +09:00
yui-knk 1ade170a6c Introduce NODE_LINE
`__LINE__` was managed by `NODE_LIT` with `Integer` object.
This commit introduces `NODE_LINE` so that

1. `__LINE__` is detectable from AST Node
2. Reduce dependency ruby object
2023-12-29 18:32:27 +09:00