Commit graph

20692 commits

Author SHA1 Message Date
Stan Lo
4349c7909f [ruby/irb] Memoize helper method instances with Singleton module
(https://github.com/ruby/irb/pull/931)

Some helpers, like Rails console's `app`, requires memoization of the
helper's ivars. To support it IRB needs to memoize helper method instances
as well.

a96c7a6668
2024-04-24 18:32:55 +00:00
tomoya ishida
cf24a0483e [ruby/reline] Long line performance
(https://github.com/ruby/reline/pull/688)

* Improve C-e (ed_move_to_end) performance for long line

* Reline::Unicode.split_by_width optimization for RESET_SGR

0c8d3c827a
2024-04-24 17:33:40 +00:00
Stan Lo
9bba999be7 [ruby/irb] Revert "Memoize helper method instances with Singleton module"
This reverts commit 169a9a2c30.

221b0a4928
2024-04-24 16:01:23 +00:00
Stan Lo
e5ca3d072f [ruby/irb] Memoize helper method instances with Singleton module
Some helpers, like Rails console's `app`, requires memoization of the
helper's ivars. To support it IRB needs to memoize helper method instances
as well.

169a9a2c30
2024-04-24 16:01:02 +00:00
Stan Lo
e11237904c
Sync IRB f9347b1 (#10611) 2024-04-23 21:00:56 +00:00
Takashi Kokubun
87396dbe5d Skip test_inspect_under_gc_compact_stress w/ RJIT too 2024-04-23 09:51:51 -07:00
Philip Mueller
f7d1699f67 [ruby/prism] Implement case equality on nodes
dc121e4fdf
2024-04-23 13:53:23 +00:00
dependabot[bot]
ed9834efbd [rubygems/rubygems] Bump rb-sys
Bumps [rb-sys](https://github.com/oxidize-rb/rb-sys) from 0.9.94 to 0.9.97.
- [Release notes](https://github.com/oxidize-rb/rb-sys/releases)
- [Commits](https://github.com/oxidize-rb/rb-sys/compare/v0.9.94...v0.9.97)

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

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

05901be5db
2024-04-22 19:15:53 +00:00
dependabot[bot]
9eeb86df0e [rubygems/rubygems] Bump rb-sys
Bumps [rb-sys](https://github.com/oxidize-rb/rb-sys) from 0.9.94 to 0.9.97.
- [Release notes](https://github.com/oxidize-rb/rb-sys/releases)
- [Commits](https://github.com/oxidize-rb/rb-sys/compare/v0.9.94...v0.9.97)

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

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

e3069f2fd4
2024-04-22 19:13:00 +00:00
Stan Lo
f16c6ac4fd [ruby/irb] Stop using ExtendCommandBundle internally
(https://github.com/ruby/irb/pull/925)

This module was used to extend both commands and helpers when they're not
separated. Now that they are, and we have a Command module, we should move
command-related logic to the Command module and update related references.

This will make the code easier to understand and refactor in the future.

f74ec97236
2024-04-20 18:55:54 +00:00
Nobuyoshi Nakada
2b11bcb84e [ruby/zlib] Clear temporary directory
1bed54dcf7
2024-04-20 10:53:41 +00:00
tomoya ishida
125e1ed5f7 [ruby/irb] Remove exit command workaround, handle IRB_EXIT in
debug_readline
(https://github.com/ruby/irb/pull/923)

* Remove exit and exti! command workaround when executed outside of IRB

Command was a method. It could be executed outside of IRB.
Workaround for it is no longer needed.

* Handle IRB_EXIT in debug mode

* Add exit and exit! command in rdbg mode

0b5dd6afd0
2024-04-20 07:45:41 +00:00
Zack Deveau
9555a997ac ensure ibf_load_setup is only passed String params
In cases where RubyVM::InstructionSequence.load_from_binary() is
passed a param other than a String, we attempt to call the
RSTRING_LENINT macro on it which can cause a segfault.

ex:
```
var_0 = 0
RubyVM::InstructionSequence.load_from_binary(var_0)
```

This commit adds a type check to raise unless we are provided
a String.
2024-04-20 10:41:01 +09:00
Kuniaki Igarashi
6cfd929034 [ruby/irb] Add MultiIRB commands test
(https://github.com/ruby/irb/pull/929)

c6bbc424c3
2024-04-19 15:01:36 +00:00
Mari Imaizumi
604c29e8a2 [ruby/reline] Implement show-all-if-ambiguous feature
(https://github.com/ruby/reline/pull/683)

0fe4fdc794
2024-04-19 12:08:22 +00:00
tomoya ishida
ff599aea7c [ruby/irb] Fix % escape in prompt format
(https://github.com/ruby/irb/pull/927)

08eee25d28
2024-04-18 14:46:55 +00:00
tomoya ishida
57a262e325 [ruby/irb] Accept " " for colorizing "\t" test
(https://github.com/ruby/irb/pull/924)

c8182fa490
2024-04-18 11:48:13 +00:00
Jean Boussier
3a7846b1aa Add a hint of ASCII-8BIT being BINARY
[Feature #18576]

Since outright renaming `ASCII-8BIT` is deemed to backward incompatible,
the next best thing would be to only change its `#inspect`, particularly
in exception messages.
2024-04-18 10:17:26 +02:00
Ben Fritsch
6ac8f6a10e
[ruby/ipaddr] Add IPAddr.cidr to return ip address in cidr notation
f5b006741f
2024-04-18 10:27:19 +09:00
Kevin Newton
d186eb36a4 [ruby/prism] Add a reflection API for determining the fields of a node
f3f9950a74
2024-04-17 13:54:29 -04:00
tomoya ishida
15b659ca93 [ruby/reline] Refactor nomultiline and multiline mode difference
(https://github.com/ruby/reline/pull/653)

* Support multiline input in Reline.readline internally, reduce multiline-singleline branch

* Add readline(singleline) prompt test with force inserting multiline text

97846095d7
2024-04-17 16:12:20 +00:00
Koichi Sasada
e9d7478ded relax unused block warning for duck typing
if a method `foo` uses a block, other (unrelated) method `foo`
can receives a block. So try to relax the unused block warning
condition.

```ruby
      class C0
        def f = yield
      end

      class C1 < C0
        def f = nil
      end

      [C0, C1].f{ block } # do not warn
```
2024-04-17 20:26:49 +09:00
Nobuyoshi Nakada
09638741ba [Feature #20335] Thread.each_caller_location arguments
Accecpt the same arguments as `caller` and `caller_locations`.
2024-04-17 18:47:07 +09:00
Koichi Sasada
7bc66a366d skip on Prism generated iseq 2024-04-17 17:40:20 +09:00
Jean Boussier
eac3dee9cd test_uplus_minus: Use a different string literal
This test fail relatively frequently and it's unclear what is
happening.

```
str: {"address":"0x7fbdeb26d4e0", "type":"STRING", "shape_id":1, "slot_size":40, "class":"0x7fbdd1e0ec50", "frozen":true, "embedded":true, "fstring":true, "bytesize":3, "value":"bar", "encoding":"UTF-8", "coderange":"7bit", "memsize":40, "flags":{"wb_protected":true, "old":true, "uncollectible":true, "marked":true}}
bar: {"address":"0x7fbdd0a8b138", "type":"STRING", "shape_id":1, "slot_size":40, "class":"0x7fbdd1e0ec50", "frozen":true, "embedded":true, "fstring":true, "bytesize":3, "value":"bar", "encoding":"UTF-8", "coderange":"7bit", "memsize":40, "flags":{"wb_protected":true}}
```

The `"bar".freeze` literal correctly put an old-gen fstring on the stack.
But `-%w(b a r).join('')` returns a young-gen fstring, which suggest it
somehow failed to find the old one in the `frozen_strings` table.

This could be caused by another test corrupting the table, or corrupting
the `"bar"` fstring.

By using a different literal value we can learn whether the bug is specific
to `"bar"` (used in many tests) or more general.
2024-04-17 10:35:14 +02:00
Koichi Sasada
f9f3018001 ISeq#to_a respects use_block status
```ruby
b = RubyVM::InstructionSequence.compile('def f = yield; def g = nil').to_a
pp b

 #=>
 ...
 {:use_block=>true},
 ...
```
2024-04-17 17:03:46 +09:00
Jean byroot Boussier
75154dec73 [ruby/stringio] strio_read: preserve buffer encoding on partial
reads
(https://github.com/ruby/stringio/pull/95)

[[Bug #20418]](https://bugs.ruby-lang.org/issues/20418)

Ruby IO#read preserves the encoding on partial read, but change it when
reading the whole IO

from commit 0ca7036682:
> * io.c (read_all): should associate default external encoding.
> * io.c (io_read): should NOT associate default external encoding.

073172da31

Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
2024-04-17 01:29:18 +00:00
Mari Imaizumi
639449fe8d [ruby/reline] Implement changing editing mode
(https://github.com/ruby/reline/pull/681)

501b9a6c5f
2024-04-16 11:58:49 +00:00
Nobuyoshi Nakada
54d472d91f [rubygems/rubygems] Honor a specified path as the temporary diretory if given
## The problem

Currently the tests are executed in the fixed name directory "tmp"
under the top source directory.  However it makes the tests fail when
the source path contains symlinks.  Or unable to even start if the top
source directory is read-only, e.g., remote-mounting in read-only mode
from virtual machines.

Also, with the fixed directory, there is no way to avoid `pend` in
`TestGemPackage#test_extract_symlink_parent_doesnt_delete_user_dir`.

## The fix

Instead of creating the fixed name directory, this PR allows to use a
different path given with the environment variable "GEM_TEST_TMPDIR".
The default path is, as well as the current behavior, "tmp" from the
top source directory.

### Caveat

It is the caller's responsibility to make the directory safe (owned,
world unwritable, or sticky) when setting the environment variable.

bf00850656
2024-04-16 10:24:49 +00:00
Nobuyoshi Nakada
29110fe18d
[Bug #20325] Enumerator.product.size is 0 if any size is 0 2024-04-16 16:13:19 +09:00
dependabot[bot]
fc8099aea9 [rubygems/rubygems] Bump rb-sys
Bumps [rb-sys](https://github.com/oxidize-rb/rb-sys) from 0.9.91 to 0.9.94.
- [Release notes](https://github.com/oxidize-rb/rb-sys/releases)
- [Commits](https://github.com/oxidize-rb/rb-sys/compare/v0.9.91...v0.9.94)

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

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

04cf565ebe
2024-04-15 23:33:39 +00:00
dependabot[bot]
0118f5425e [rubygems/rubygems] Bump rb-sys
Bumps [rb-sys](https://github.com/oxidize-rb/rb-sys) from 0.9.91 to 0.9.94.
- [Release notes](https://github.com/oxidize-rb/rb-sys/releases)
- [Commits](https://github.com/oxidize-rb/rb-sys/compare/v0.9.91...v0.9.94)

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

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

ac952f030b
2024-04-15 23:33:29 +00:00
Jean Boussier
d019b3baec Emit a performance warning when redefining specially optimized methods
This makes it easier to notice a dependency is causing interpreter or
JIT deoptimization.

```ruby
Warning[:performance] = true

class String
  def freeze
    super
  end
end
```

```
./test.rb:4: warning: Redefining 'String#freeze' disable multiple interpreter and JIT optimizations
```
2024-04-15 18:21:41 +02:00
tomoya ishida
43f4da3ebf [ruby/reline] Fix vi_to_column which was broken
(https://github.com/ruby/reline/pull/679)

9e93ad52e7
2024-04-15 13:15:58 +00:00
Jean Boussier
07ff4aa19b Include more debug information in test_uplus_minus 2024-04-15 14:56:33 +02: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
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
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
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
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