Commit graph

20692 commits

Author SHA1 Message Date
Kevin Newton
52b862398d [ruby/prism] Syntax error for block argument on yield
9feeafbc67
2024-04-12 17:30:37 +00:00
Kevin Newton
0424c1fa7b [ruby/prism] Fix up embdoc lexing on EOF
8ee43be26d
2024-04-12 16:50:34 +00:00
Peter Zhu
edec690e03 Refactor how object IDs work for special consts
We don't need to treat static symbols in any special way since they
can't be confused with other special consts or GC managed objects.
2024-04-12 11:27:08 -04:00
Kevin Newton
3629d4df66 [PRISM] Enable passing tests for prism 2024-04-12 11:07:04 -04:00
Kevin Newton
c41ecf3f47 [ruby/prism] Create the warning for unreachable statements
e17c86b886
2024-04-12 14:58:03 +00:00
Kevin Newton
5f2bcbb6d4
[PRISM] Ensure no void warnings in rubyoptions test 2024-04-12 10:29:39 -04:00
Kevin Newton
4fc457e2b7 [ruby/prism] Implement the void statement warning
802ff71cd4
2024-04-12 14:10:20 +00:00
Stan Lo
0924ff2d39 [ruby/prism] Fix parser translation's heredoc whitespace calculation
Given this example:

```rb
<<~HEREDOC
  #{x}
HEREDOC
```

Both the parser gem and Prism's translation layer would generate the following AST:

```
s(:dstr,
  s(:begin,
    s(:int, 1)),
  s(:str, " a\n"))
```

However, the parser gem inserts a empty string node into this node's location, like:

```
<Parser::Source::Map::Heredoc:0x0000000104ce73b8
 @expression=#<Parser::Source::Range (string) 0...10>,
 @heredoc_body=#<Parser::Source::Range (string) 11...20>,
 @heredoc_end=#<Parser::Source::Range (string) 20...27>,
 @node=s(:dstr,
  s(:str, ""),
  s(:begin,
    s(:int, 1)),
  s(:str, " a\n"))>
```

This is required to calculate the correct whitespace for the heredoc body.

We need to adjust the translation layer to account for this.

With this fix, we also won't need to ignore the tilde heredoc fixture anymore.

e7372e3ba5
2024-04-12 13:55:35 +00:00
Kevin Newton
abd05c848f
Sync latest prism 2024-04-12 09:52:29 -04:00
Stan Lo
f1d9e895b9 [ruby/irb] Pass statements to Context#evaluate
(https://github.com/ruby/irb/pull/920)

This has a few benefits:

- We can keep hiding the evaluation logic inside the Context level, which
  has always been the convention until #824 was merged recently.
- Although not an official API, gems like `debug` and `mission_control-jobs`
  patch `Context#evaluate` to wrap their own logic around it. This implicit
  contract was broken after #824, and this change restores it.

In addition to the refactor, I also converted some context-level evaluation
tests into integration tests, which are more robust and easier to maintain.

b32aee4068
2024-04-12 12:01:03 +00:00
Nobuyoshi Nakada
e36988450e
[Bug #20423] Disallow anonymous block within argument forwarding 2024-04-12 16:07:49 +09:00
Kevin Newton
842f151d79 [PRISM] Enable more passing tests 2024-04-11 15:47:30 -04:00
Kevin Newton
cd516ebd20 [ruby/prism] Add Location#chop
5dd57f4b84
2024-04-11 18:53:30 +00:00
Jean Boussier
1b830740ba compile.c: use rb_enc_interned_str to reduce allocations
The `rb_fstring(rb_enc_str_new())` pattern is inneficient because:

- It passes a mutable string to `rb_fstring` so if it has to be interned
  it will first be duped.
- It an equivalent interned string already exists, we allocated the string
  for nothing.

With `rb_enc_interned_str` we either directly get the pre-existing string
with 0 allocations, or efficiently directly intern the one we create
without first duping it.
2024-04-11 09:04:31 +02:00
Nobuyoshi Nakada
207788466e
[Bug #20417] Block local variables do not need to warn about unused 2024-04-11 12:03:55 +09:00
yui-knk
39be11a17a Fix segv when parsing command by ripper
89cfc15207 made this event dispatch to pass `Qundef`
to user defined callback method by mistake.
This commit fix it to be `nil`.
2024-04-11 10:28:58 +09:00
tomoya ishida
6a505d1b59 [ruby/irb] Command implementation not by method
(https://github.com/ruby/irb/pull/824)

* Command is not a method

* Fix command test

* Implement non-method command name completion

* Add test for ExtendCommandBundle.def_extend_command

* Add helper method install test

* Remove spaces in command input parse

* Remove command arg unquote in help command

* Simplify Statement and handle execution in IRB::Irb

* Tweak require, const name

* Always install CommandBundle module to main object

* Remove considering local variable in command or expression check

* Remove unused method, tweak

* Remove outdated comment for help command arg

Co-authored-by: Stan Lo <stan001212@gmail.com>

---------

8fb776e379

Co-authored-by: Stan Lo <stan001212@gmail.com>
2024-04-10 16:52:53 +00:00
Kouhei Yanagita
9f6deaa688 [Misc #18984] Raise TypeError from Range#size if the range is not iterable 2024-04-10 07:28:07 -07:00
Taketo Takashima
f9f25d0ed0 [ruby/ipaddr] Added IPAddr#wildcard_mask
2093cebc1d
2024-04-10 10:30:53 +00:00
Nobuyoshi Nakada
13f04e5beb [ruby/io-console] Load the built extension library in noctty tests
74c78afc24
2024-04-10 09:10:50 +00:00
Kevin Newton
0107954f25 [ruby/prism] Fix up invalid global variable error message
8ce9ae487f
2024-04-09 16:29:01 +00:00
Kevin Newton
d101ec65e9 [ruby/prism] Reduce locals variables per CRuby
3e6830c3a5
2024-04-09 15:55:57 +00:00
dependabot[bot]
c924322162 [rubygems/rubygems] Bump rb-sys
Bumps [rb-sys](https://github.com/oxidize-rb/rb-sys) from 0.9.90 to 0.9.91.
- [Release notes](https://github.com/oxidize-rb/rb-sys/releases)
- [Commits](https://github.com/oxidize-rb/rb-sys/compare/v0.9.90...v0.9.91)

---
updated-dependencies:
- dependency-name: rb-sys
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

a84b94b9ec
2024-04-08 23:47:51 +00:00
dependabot[bot]
186374279e [rubygems/rubygems] Bump rb-sys
Bumps [rb-sys](https://github.com/oxidize-rb/rb-sys) from 0.9.90 to 0.9.91.
- [Release notes](https://github.com/oxidize-rb/rb-sys/releases)
- [Commits](https://github.com/oxidize-rb/rb-sys/compare/v0.9.90...v0.9.91)

---
updated-dependencies:
- dependency-name: rb-sys
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

f0af491002
2024-04-08 23:47:42 +00:00
Kevin Newton
b09604e1fd [ruby/prism] Simplify locals test now that all fixtures are valid
0d32af5719
2024-04-08 16:54:25 +00:00
Samuel Williams
5d1702e01a
Enumerator should use a non-blocking fiber, change rb_fiber_new to be non-blocking by default. (#10481) 2024-04-08 00:49:01 +12:00
Samuel Williams
b473d304d4
Revert "Enumerator should use a non-blocking fiber. (#10478)" (#10480)
This reverts commit dfa0897de8.

This commit accidentally included some change in `parse.h`. Reverting
and re-applying the relevant changes.
2024-04-07 10:20:22 +00:00
Samuel Williams
bdb1fc1e5b
Prefer to use Fiber#transfer in scheduler implementation. (#10479) 2024-04-07 19:57:15 +12:00
Samuel Williams
dfa0897de8
Enumerator should use a non-blocking fiber. (#10478) 2024-04-07 19:18:09 +12:00
yui-knk
7767db2379 Fix ripper to dispatch warning event for duplicated when clause
Need to separate `check_literal_when` function for parser and
ripper otherwise warning event is not dispatched because
parser `rb_warning1` is used in ripper.
2024-04-07 11:15:09 +09:00
Nobuyoshi Nakada
df8f1f78f0
[Feature #20329] Separate additional flags from main dump options
Additional flags are comma separated list preceeded by `-` or `+`.

Before:
```sh
$ ruby --dump=insns+without_opt
```

After:
```sh
$ ruby --dump=insns-opt,-optimize
```

At the same time, `parsetree_with_comment` is split to `parsetree`
option and additional `comment` flag.

Before:
```sh
$ ruby --dump=parsetree_with_comment
```

After:
```sh
$ ruby --dump=parsetree,+comment
```

Also flags can be separate `--dump`.
```sh
$ ruby --dump=parsetree --dump=+comment --dump=+error_tolerant
```

Ineffective flags are ignored silently.
```sh
$ ruby --dump=parsetree --dump=+comment --dump=+error_tolerant
```
2024-04-06 20:27:02 +09:00
Mari Imaizumi
c2d02a6ac2 [ruby/reline] Continue processing even if terminfo database couldn't
be found
(https://github.com/ruby/reline/pull/673)

Fix https://github.com/ruby/reline/issues/447 https://github.com/ruby/reline/issues/543

This problem occurs when Fiddle can be loaded, curses can be loaded, and TERM is not registered in Terminfo.
It should also occur at hardcopy terminals and when Terminfo information is low, but no such reports have been received.

Reline should not abort the process because of missing Terminfo.
Reline proceeds with `Reline::Terminfo.enabled? == false` when fiddle or curses cannot be loaded.
And does the same when Terminfo is present but TERM is not.
ebab2875f1/lib/reline/terminfo.rb (L156-L160)

You can check the operation with `TERM=foo bundle exec bin/console`.

4ce247ce2b
2024-04-06 09:24:53 +00:00
Kevin Newton
dcec1e0dc6 [ruby/prism] Replace old circular parameter definition detection
c739f8e194
2024-04-05 19:24:00 +00:00
Kevin Newton
831b06ea3d [PRISM] Enable test_argument_forwarding_with_anon_rest_kwrest_and_block 2024-04-05 09:06:59 -04:00
tomoya ishida
4e48d2724e
[ruby/reline] Thread safe readline
(https://github.com/ruby/reline/pull/669)

Block until other Reline.readline or Reline.readmultiline finish

ebab2875f1
2024-04-05 09:34:28 +09:00
Kevin Newton
440c63df31 [ruby/prism] Change forwarding error messages to match CRuby
6a15e475c9
2024-04-04 20:59:08 +00:00
Kevin Newton
2ecf269e68 [ruby/prism] Eliminate character class duplicated range warning
da939bbd4e
2024-04-04 15:29:14 -04:00
Kevin Newton
0aa1d61ab9 [PRISM] Ensure unfrozen when interpolation is present in string literal 2024-04-04 15:27:51 -04:00
Kevin Newton
48c2ffe980 [PRISM] Enable SCRIPT_COMPILED tracepoint event 2024-04-04 15:27:51 -04:00
Kevin Newton
3efc1c36f2 [PRISM] Add CLASS and END tracepoint events 2024-04-04 15:27:51 -04:00
Nobuyoshi Nakada
58918788ab [Bug #20342] Consider wrapped load in main methods 2024-04-05 01:33:08 +09:00
Nobuyoshi Nakada
184db1fd6a Update ARGF.write interface 2024-04-04 18:54:54 +09:00
Nobuyoshi Nakada
64b0f4303e Refine test_argf.rb
- Make `make_tempfile` to take data to write, `binmode:` flag, and a
  block.
- Use `make_tempfile` instead of `make_tempfile0`.
- Use `File.binwrite`.
2024-04-04 18:54:54 +09:00
HASUMI Hitoshi
f5e387a300 Separate SCRIPT_LINES__ from ast.c
This patch suggests relocating the code dealing with `SCRIPT_LINES__` from ast.c to ruby_parser.c.

## Background

- I guess `AbstractSyntaxTree.of` method used to use `SCRIPT_LINES__` internally for some reason before
- However, now it appears `SCRIPT_LINES__` is no longer used meaningfully by the method
- As evidence of this, (and as my patch shows,) removing the function call of `rb_script_lines_for()` from `ast_s_of()` does not affect the result of `test/ruby/test_ast.rb`

Given the above, I think two possibilities can be considered:

- (A) `AbstractSyntaxTree.of` has not needed `SCRIPT_LINES__` already (I pick this)
- (B) We lack a test case of `AbstractSyntaxTree.of` that needs to use `SCRIPT_LINES__`

## Besides,

The current implementation causes strange behavior:

```console
ruby -e"SCRIPT_LINES__ = {__FILE__ => []}; puts RubyVM::AbstractSyntaxTree.of(->{ 1 + 2 }, keep_script_lines: true).script_lines"
=> `-e:1:in '<main>': undefined method 'script_lines' for nil (NoMethodError)`
```

I think this is a bug because `AbstractSyntaxTree.of` is not supposed to return `nil` even in this case.
This happens due to the ast.c's dependence on `SCRIPT_LINES__`.
And at the end of the `ast_s_of()`, `node_find()` can not find the target child node obviously because it doesn't make sense to look for a corresponding node made from the parameter of `AbstractSyntaxTree.of` in the AST tree made from the value of `{__FILE__ => []}`

## Solution

Since I think it's good enough `SCRIPT_LINES__` to be only referred by ruby.c, I chose the possibility "(A)" and wrote this patch which moves `rb_script_lines_for()` from ast.c to ruby_parser.c.

So as the result:

- `ast_s_of()` function no longer look up `SCRIPT_LINES__`
- Even so, this patched code passes the existing tests
- The strange behavior above no longer happens (I also added a test for it)

Please correct me if I miss something🙏
2024-04-04 18:29:16 +09:00
tomoya ishida
8088c88d01
[ruby/reline] Handle INT signal correctly, remove handle_cleared
because clear(C-l) is not a signal
(https://github.com/ruby/reline/pull/646)

3debb0ae2f
2024-04-04 17:18:47 +09:00
tomoya ishida
80e31663f3
[ruby/reline] Fix audoindent including "\v", escape "\v" for
rendering
(https://github.com/ruby/reline/pull/648)

9c51c577ca
2024-04-04 17:18:47 +09:00
Yusuke Endoh
6d82be499b Prevent a warning
```
[19889/25837] TestArgf#test_puts-e:1: warning: ARGF.class#write is outdated interface which accepts just one argument
 = 0.06 s
```
20240404T033003Z.log.html.gz
2024-04-04 14:10:53 +09:00
Yusuke Endoh
d910d64ed9 Prevent "method redefined" warnings 2024-04-04 13:29:41 +09:00
Yusuke Endoh
cb30c3d2b3 Prevent "assigned but unused variable" warnings 2024-04-04 13:29:41 +09:00
Yusuke Endoh
fc67091fc8 Prevent "ambiguous first argument" warnings 2024-04-04 13:29:41 +09:00