Commit graph

84976 commits

Author SHA1 Message Date
Jean Boussier
07ff4aa19b Include more debug information in test_uplus_minus 2024-04-15 14:56:33 +02:00
HASUMI Hitoshi
9b1e97b211 [Universal parser] DeVALUE of p->debug_lines and ast->body.script_lines
This patch is part of universal parser work.

## Summary
- Decouple VALUE from members below:
  - `(struct parser_params *)->debug_lines`
  - `(rb_ast_t *)->body.script_lines`
- Instead, they are now `rb_parser_ary_t *`
  - They can also be a `(VALUE)FIXNUM` as before to hold line count
- `ISEQ_BODY(iseq)->variable.script_lines` remains VALUE
  - In order to do this,
  - Add `VALUE script_lines` param to `rb_iseq_new_with_opt()`
  - Introduce `rb_parser_build_script_lines_from()` to convert `rb_parser_ary_t *` into `VALUE`

## Other details
- Extend `rb_parser_ary_t *`. It previously could only store `rb_parser_ast_token *`, now can store script_lines, too
- Change tactics of building the top-level `SCRIPT_LINES__` in `yycompile0()`
  - Before: While parsing, each line of the script is added to `SCRIPT_LINES__[path]`
  - After: After `yyparse(p)`, `SCRIPT_LINES__[path]` will be built from `p->debug_lines`
- Remove the second parameter of `rb_parser_set_script_lines()` to make it simple
- Introduce `script_lines_free()` to be called from `rb_ast_free()` because the GC no longer takes care of the script_lines
- Introduce `rb_parser_string_deep_copy()` in parse.y to maintain script_lines when `rb_ruby_parser_free()` called
  - With regard to this, please see *Future tasks* below

## Future tasks
- Decouple IMEMO from `rb_ast_t *`
  - This lifts the five-members-restriction of Ruby object,
  - So we will be able to move the ownership of the `lex.string_buffer` from parser to AST
  - Then we remove `rb_parser_string_deep_copy()` to make the whole thing simple
2024-04-15 20:51:54 +09:00
Jean Boussier
bb1c3418d0 Add more assertions in test_uplus_minus
Not along after 1b830740ba CI
started to rarely fail this test:

```
TestString#test_uplus_minus: Test::Unit::AssertionFailedError: uminus deduplicates [Feature #13077].
  1) Failure:
TestString#test_uplus_minus [/tmp/ruby/src/trunk/test/ruby/test_string.rb:3368]:
```

It's unclear what is going on, but one possibility is that
`"bar".freeze` might no longer compile correctly.

Another possibility is that another test redefine `String#freeze`,
causing `opt_str_freeze` to no longer return an `fstring`.
2024-04-15 11:06:54 +02:00
Koichi Sasada
9a57b04703 super{} doesn't use block
`super(){}`, `super{}` and `super(&b)` doesn't use the given
block so warn unused block warning when calling a method which
doesn't use block with above `super` expressions.

e.g.: `def f = super{B1}` (warn on `f{B2}` because `B2` is not used.
2024-04-15 17:56:49 +09:00
Koichi Sasada
145cced9bc fix incorrect warning.
`super()` (not zsuper) passes the passed block and
it can be used.

```ruby
class C0
  def foo; yield; end
end

class C1 < C0
  def foo; super(); end
end

C1.new.foo{p :block} #=> :block
```
2024-04-15 14:53:41 +09:00
git
b6a10a1518 Update default gems list at fc363944b4 [ci skip] 2024-04-15 05:07:51 +00:00
Nobuyoshi Nakada
fc363944b4 [ruby/optparse] bump up to 0.5.0
f5018a8b1c
2024-04-15 05:06:46 +00:00
Koichi Sasada
9180e33ca3 show warning for unused block
With verbopse mode (-w), the interpreter shows a warning if
a block is passed to a method which does not use the given block.

Warning on:

* the invoked method is written in C
* the invoked method is not `initialize`
* not invoked with `super`
* the first time on the call-site with the invoked method
  (`obj.foo{}` will be warned once if `foo` is same method)

[Feature #15554]

`Primitive.attr! :use_block` is introduced to declare that primitive
functions (written in C) will use passed block.

For minitest, test needs some tweak, so use
ea9caafc07
for `test-bundled-gems`.
2024-04-15 12:08:07 +09:00
yui-knk
515e52a0b1 Emit warn event for duplicated hash keys on ripper
Need to use `rb_warn` macro instead of calling `rb_compile_warn`
directly to emit `warn` event on ripper.
2024-04-15 06:29:25 +09:00
Mari Imaizumi
339128b190 [ruby/reline] Refactored Default Key Bindings
(https://github.com/ruby/reline/pull/678)

* Reduce duplicate method

* Configured default key mapping with Readline when the method exists

* Remove undefined methods

155f7047bb
2024-04-14 17:33:51 +00:00
tomoya ishida
1648c4436e [ruby/reline] Refactor waiting_proc and waiting_operator_proc
(https://github.com/ruby/reline/pull/649)

* Fix waiting_proc precedence

* Fix waiting_operator bugs

* Add waiting_proc and vi_waiting_operator test

* Fix vi waiting operator arg number

vi_arg and vi_waiting_operator_arg should be multiplied

* Implement `yy` copies whole line in vi_command mode

* Simplify incremental search cancel test

* Add complex vi test with waiting_proc and vi_waiting_operator, split test input

777dffae1c
2024-04-14 14:28:15 +00:00
Nobuyoshi Nakada
8d5d6ec6e7
[pty] Fix missing or 2024-04-14 20:35:34 +09:00
Nobuyoshi Nakada
3368913be3 [pty] Fix ptsname_r fallback
If `posix_openpt` is available, also `ptsname` should be available.
2024-04-14 20:27:05 +09:00
Stan Lo
04ba96e619 [ruby/irb] Allow defining custom commands in IRB
(https://github.com/ruby/irb/pull/886)

This is a feature that has been requested for a long time. It is now
possible to define custom commands in IRB.

Example usage:

```ruby
require "irb/command"

class HelloCommand < IRB::Command::Base
  description "Prints hello world"
  category "My commands"
  help_message "It doesn't do more than printing hello world."

  def execute
    puts "Hello world"
  end
end

IRB::Command.register(:hello, HelloCommand)
```

888643467c
2024-04-14 11:01:43 +00:00
Michael J. Giarlo
76b10f2ee1 [ruby/reline] Support menu-complete-backward command for upward
navigation
(https://github.com/ruby/reline/pull/677)

Fixes https://github.com/ruby/reline/pull/675

This commit extracts the upward navigation condition in `LineEditor#input_key` to a new private method, and adds a new alias. This change allows Reline to support upward navigation in when a user has configured `inputrc` to map Shift-Tab to `menu-complete-backward`, a common setting in Bash (>= 4.x).

Instead of special-casing upward navigation in `LineEditor#input_key`, we now allow it to be processed by the branch that calls `process_key`. The extracted method no longer includes the editing mode check since this check is already made by `#wrap_method_call` by the time `#completion_journey_up` (or `#menu_complete_backward`) is called. Since upward navigation is happening in a method other than `#input_key` now, the `completion_occurs` variable that used to be local to `#input_key` is changed to an instance variable so that the new method can change its value. (I see many examples of mutating such instance variables in `LineEditor`, so I assumed this would be an uncontroversial change consistent with the coding practices already in place.)

Test coverage of this change has been added to the emacs and vi `KeyActor` tests.

Many thanks to @ima1zumi for their very helpful comments on #675 which encouraged me to contribute this work!

2ccdb374a4
2024-04-14 09:13:20 +00:00
yui-knk
38b8bdb8ea Remove undefined function's prototype declaration
89cfc15207 removed the definition of these functions.
2024-04-14 10:51:16 +09:00
yui-knk
924b928e35 Remove unused functions from struct rb_parser_config_struct 2024-04-14 09:08:19 +09:00
yui-knk
5970386a2e Use rb_parser_string_t * for delayed.token 2024-04-14 09:08:19 +09:00
Zack Deveau
c479492a67 Resize ary when Array#sort! block modifies embedded ary
In cases where `rb_ary_sort_bang` is called with a block and
tmp is an embedded array, we need to account for the block
potentially impacting the capacity of ary.

ex:
```
var_0 = (1..70).to_a
var_0.sort! do |var_0_block_129, var_1_block_129|
  var_0.pop
  var_1_block_129 <=> var_0_block_129
end.shift(3)
```

The above example can put the array into a corrupted state
resulting in a heap buffer overflow and possible segfault:
```
ERROR: AddressSanitizer: heap-buffer-overflow on address [...]
WRITE of size 560 at 0x60b0000034f0 thread T0 [...]
```

This commit adds a conditional to determine when the capacity
of ary has been modified by the provided block. If this is
the case, ensure that the capacity of ary is adjusted to
handle at minimum the len of tmp.
2024-04-14 08:41:47 +09:00
Kevin Newton
43a6690d21
[PRISM] Enable passing test_parenthesised_statement_argument 2024-04-12 19:47:04 -04:00
Kevin Newton
3c0756752c [ruby/prism] Better error message on statement inside argument list
3b1a99526a
2024-04-12 21:46:42 +00:00
Kevin Newton
10d0abb437 [PRISM] Enable passing tests from latest prism 2024-04-12 17:46:31 -04:00
Kevin Newton
7baecc2e36 [PRISM] Emit parse warnings before raising syntax errors 2024-04-12 17:46:31 -04:00
Kevin Newton
650b5e5aa2 [PRISM] Enable more passing tests 2024-04-12 17:46:31 -04:00
Kevin Newton
1521af3259 [ruby/prism] Better error message on invalid def
d398e7d22c
2024-04-12 17:49:17 +00:00
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
9bab179ca3 Don't treat flonum specially in object ID
flonum is just a special constant, so we don't need to treat it in any
special way.
2024-04-12 11:27:08 -04: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
c553d34835 [ruby/prism] Warn void regardless of eval
48ba434fa4
2024-04-12 14:30:57 +00:00
Kevin Newton
5f2bcbb6d4
[PRISM] Ensure no void warnings in rubyoptions test 2024-04-12 10:29:39 -04:00
Kevin Newton
8e514bedf9 [ruby/prism] Remove outdated comment
9adc88ddf8
2024-04-12 14:10:21 +00: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
David Marshall
a64a42ae38 [rubygems/rubygems] bundle add --glob continued- quote glob value invocation in specs, add banner text for CLI recommending single quotes
6d2cf955f9
2024-04-12 13:31:43 +00:00
David Marshall
c4b5f3f142 [rubygems/rubygems] bundler CLI option for add gem --glob=
Bundler online documentation says that if the gem is located within a subdirectory of a git repository,
you can use the `:glob` option to specify the location of its .gemspec

`gem 'cf-copilot', git: 'https://github.com/cloudfoundry/copilot', glob: 'sdk/ruby/*.gemspec'`

This change allows for equivalent functionality from the bundler CLI

`bundle add cf-copilot --git=https://github.com/cloudfoundry/copilot --glob=sdk/ruby/*.gemspec`

91052e5868
2024-04-12 13:31:43 +00: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
Satoshi Tagomori
7b8b936f4a
[DOC] Fix the wrong comment
This function checks the CL's superclasses containing the class C at
the end of it. That means C is a superclass of CL, not a subclass.
2024-04-12 18:31:22 +09:00
Nobuyoshi Nakada
91c457e091
Parenthesized SVN IDs in .mailmap look too verbose [ci skip] 2024-04-12 18:22:04 +09:00
Nobuyoshi Nakada
69823b97b5
[Bug #20423] Fix error message of prism 2024-04-12 17:02:46 +09:00
Nobuyoshi Nakada
e36988450e
[Bug #20423] Disallow anonymous block within argument forwarding 2024-04-12 16:07:49 +09:00
Takashi Kokubun
971b552735 [PRISM] Suppress compiler warnings
../prism_compile.c: In function ‘pm_compile_node’:
../compile.c:583:24: warning: ‘retry_end_l’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  583 |     anchor->last->next = elem;
      |     ~~~~~~~~~~~~~~~~~~~^~~~~~
In file included from ../compile.c:14256:
../prism_compile.c:5796:16: note: ‘retry_end_l’ was declared here
 5796 |         LABEL *retry_end_l;
      |                ^~~~~~~~~~~
../compile.c:255:42: warning: ‘retry_label’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  255 | #define LABEL_REF(label) ((label)->refcnt++)
      |                                          ^~
In file included from ../compile.c:14256:
../prism_compile.c:5795:16: note: ‘retry_label’ was declared here
 5795 |         LABEL *retry_label;
      |                ^~~~~~~~~~~
../prism_compile.c:5919:52: warning: ‘previous_block’ may be used uninitialized in this function [-Wmaybe-uninitialized]
 5919 |             ISEQ_COMPILE_DATA(iseq)->current_block = previous_block;
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
2024-04-11 17:31:28 -07:00
Kevin Newton
842f151d79 [PRISM] Enable more passing tests 2024-04-11 15:47:30 -04:00
Cody Cutrer
c5e661b1d7 [rubygems/rubygems] Fix installing plugins via relative paths
This affected both CLI and Gemfile installs

a0d101a8df
2024-04-11 19:35:28 +00:00
Kevin Newton
cd516ebd20 [ruby/prism] Add Location#chop
5dd57f4b84
2024-04-11 18:53:30 +00:00
Kevin Newton
58f93eec18 [PRISM] Fix break in super block 2024-04-11 14:39:04 -04:00
Kevin Newton
bb5ed8b3df [PRISM] Fix flags on local variable operator write nodes 2024-04-11 12:18:51 -04:00