Commit graph

20692 commits

Author SHA1 Message Date
Noah Gibbs
e3b9eec349 [ruby/prism] Translation::Parser should process warnings, not just errors
ea7e400f85
2024-02-21 22:38:47 +00:00
Kevin Newton
80ffa3006c [PRISM] Eval frames should not have an absolute path 2024-02-21 17:25:55 -05:00
Samuel Giddins
8bc51a393a [rubygems/rubygems] Check for correct exception on older psych versions
52de6eccf5
2024-02-21 17:45:01 +00:00
Samuel Giddins
466ed0e1ac [rubygems/rubygems] Add a test for safe yaml
148deade0a
2024-02-21 17:45:00 +00:00
Nobuyoshi Nakada
6e704311bb [ruby/pp] Extract pp_hash_pair
The method which prints single pair of a hash, to make extending
pretty printing Hash easier, apart from Hash construct itself.

3fcf2d1142
2024-02-21 16:45:01 +00:00
Nobuyoshi Nakada
37b8fc7477 [ruby/pp] Get rid of hardcoded class name
So that the `pp` method can work in inherited classes with that
class.

f204df3aad
2024-02-21 16:45:00 +00:00
Nobuyoshi Nakada
d9ebb65b79 [ruby/pp] Fix compatibility with 3.3 or earlier
f5cee21a1e
2024-02-21 16:39:17 +00:00
Nobuyoshi Nakada
2e6f8554f8 [ruby/date] Remove the unintentional ability to parse Symbol
It's been 2 years since ruby/date#49, so it's okay.

435dfec6c8
2024-02-21 16:04:52 +00:00
Kevin Newton
96f21e9dd1 Re-enable test now that dump is all ASCII 2024-02-21 10:58:40 -05:00
Samuel Williams
78d9fe6947
Ensure that exiting thread invokes end-of-life behaviour. (#10039) 2024-02-22 00:32:59 +13:00
Nobuyoshi Nakada
6aa5067ab9
Revert rubygems tempdir check
This check was added to check if other tests still remain tempdir, and these tests do on Windows.

* `TestGemCommandsSetupCommand#test_destdir_flag_does_not_try_to_write_to_the_default_gem_home`
* `TestGemInstaller#test_install_build_root_when_gem_home_not_writable_does_not_fallback_to_user_install_inside_build_root`

Also some tests fail due to too long path names.
2024-02-21 10:28:23 +00:00
Nobuyoshi Nakada
6ecb14df2c [rubygems/rubygems] Reset Gem.state_file along with Gem.state_home
As `Gem.state_file` is placed under `Gem.state_home` directory, when
the latter is reset, also the former should be reset.
If left unreset, the file for a previously run test will be re-created
and will not be deleted.

1378d07afd
2024-02-21 08:14:34 +00:00
Nobuyoshi Nakada
c8fb4f308b [rubygems/rubygems] Skip nil-value keys to make metadata reproducible
Nil-value keys in a mapping end with a space or not depending on
libyaml versions, and result metadata are different per platforms.
This commit makes to skip such keys to make metadata reproducible
accross platforms.

74b4db8d30
2024-02-21 06:39:36 +00:00
Koichi Sasada
d578684989 rb_thread_lock_native_thread()
Introduce `rb_thread_lock_native_thread()` to allocate dedicated
native thread to the current Ruby thread for M:N threads.
This C API is similar to Go's `runtime.LockOSThread()`.

Accepted at https://github.com/ruby/dev-meeting-log/blob/master/2023/DevMeeting-2023-08-24.md
(and missed to implement on Ruby 3.3.0)
2024-02-21 15:38:29 +09:00
John Hawthorn
081ee3d355 Add memory leak test for eval kwargs 2024-02-20 18:55:00 -08:00
Alan Wu
2a6917b463 Fix string value in hash literal being forced frozen
We should pass `false` for `hash_key` for value nodes. Credits to
`@kddnewton` for noticing and bisecting.
2024-02-20 21:00:54 -05:00
Koichi Sasada
b3c13de858 skip a test on non-UTF-8 locale
`ruby --parser=prism -W:no-experimental --dump=parsetree -e :hi` prints
non-ASCII char(s) so the following test with non UTF-8 locale fails.

```
$ LANG=C make test-all TESTS='-n /parser/ ruby/rubyoptions' -o encs -o exts
Run options:
  --seed=32323
  "--ruby=./miniruby -I/home/ko1/ruby/src/master/lib -I. -I.ext/common  /home/ko1/ruby/src/master/tool/runruby.rb --extout=.ext  -- --disable-gems"
  --excludes-dir=/home/ko1/ruby/src/master/test/.excludes
  --name=!/memory_leak/
  -n
  /parser/

[1/1] TestRubyOptions#test_parser_flag = 0.04 s
  1) Failure:
TestRubyOptions#test_parser_flag [/home/ko1/ruby/src/master/test/ruby/test_rubyoptions.rb:300]:
pid 135869 exit 0.

1. [1/2] Assertion for "stdout"
   | invalid byte sequence in US-ASCII.

Finished tests in 0.044362s, 22.5416 tests/s, 225.4157 assertions/s.
1 tests, 10 assertions, 1 failures, 0 errors, 0 skips

ruby -v: ruby 3.4.0dev (2024-02-20T17:13:36Z master c0e5de9567) [x86_64-linux]
make: *** [uncommon.mk:945: yes-test-all] Error 1
```

Now simply skip the test if the locale is not UTF-8.
(I'm not familiar with encodings so please fix it if needed)
2024-02-21 03:59:19 +09:00
Jeremy Evans
77c1233f79 Add pushtoarraykwsplat instruction to avoid unnecessary array allocation
This is designed to replace the newarraykwsplat instruction, which is
no longer used in the parse.y compiler after this commit.  This avoids
an unnecessary array allocation in the case where ARGSCAT is followed
by LIST with keyword:

```ruby
a = []
kw = {}
[*a, 1, **kw]
```

Previous Instructions:

```
0000 newarray                               0                         (   1)[Li]
0002 setlocal_WC_0                          a@0
0004 newhash                                0                         (   2)[Li]
0006 setlocal_WC_0                          kw@1
0008 getlocal_WC_0                          a@0                       (   3)[Li]
0010 splatarray                             true
0012 putobject_INT2FIX_1_
0013 putspecialobject                       1
0015 newhash                                0
0017 getlocal_WC_0                          kw@1
0019 opt_send_without_block                 <calldata!mid:core#hash_merge_kwd, argc:2, ARGS_SIMPLE>
0021 newarraykwsplat                        2
0023 concattoarray
0024 leave
```

New Instructions:

```
0000 newarray                               0                         (   1)[Li]
0002 setlocal_WC_0                          a@0
0004 newhash                                0                         (   2)[Li]
0006 setlocal_WC_0                          kw@1
0008 getlocal_WC_0                          a@0                       (   3)[Li]
0010 splatarray                             true
0012 putobject_INT2FIX_1_
0013 pushtoarray                            1
0015 putspecialobject                       1
0017 newhash                                0
0019 getlocal_WC_0                          kw@1
0021 opt_send_without_block                 <calldata!mid:core#hash_merge_kwd, argc:2, ARGS_SIMPLE>
0023 pushtoarraykwsplat
0024 leave
```

pushtoarraykwsplat is designed to be simpler than newarraykwsplat.
It does not take a variable number of arguments from the stack, it
pops the top of the stack, and appends it to the second from the top,
unless the top of the stack is an empty hash.

During this work, I found the ARGSPUSH followed by HASH with keyword
did not compile correctly, as it pushed the generated hash to the
array even if the hash was empty.  This fixes the behavior, to use
pushtoarraykwsplat instead of pushtoarray in that case:

```ruby
a = []
kw = {}
[*a, **kw]

[{}] # Before

[] # After
```

This does not remove the newarraykwsplat instruction, as it is still
referenced in the prism compiler (which should be updated similar
to this), YJIT (only in the bindings, it does not appear to be
implemented), and RJIT (in a couple comments).  After those are
updated, the newarraykwsplat instruction should be removed.
2024-02-20 10:47:44 -08:00
Alan Wu
2e2e3d89af
YJIT: Support **nil for cfuncs
Similar to the iseq call support. Fairly straight forward.
2024-02-20 18:29:02 +00:00
Nobuyoshi Nakada
835fa98a62 Update warning flags before dump 2024-02-20 23:56:07 +09:00
Nobuyoshi Nakada
386b956ad8
Remove never used method 2024-02-20 20:14:37 +09:00
Nobuyoshi Nakada
e3917fc7da
Remove no longer used methods
`find_object_in_recycled_slot` and `memory_location` have not been
used since commit:b99833baec2e567e38758f4fd017c90c7ce57d75.
2024-02-20 20:14:37 +09:00
yui-knk
2a4b6ed37c Workaround for Prism::ParseTest#test_filepath for "unparser/corpus/literal/def.txt"
See the discussion on https://github.com/ruby/ruby/pull/9923
2024-02-20 17:33:58 +09:00
yui-knk
20dbc7a5f4 Skip test_filepath of "unparser/corpus/literal/def.txt"
The previous commit changes Ripper lex state behavior of `tLABEL`.
For example, Ripper lex state for the second `bar` was changed
by the previous commit.

```
def foo(bar: bar())
end
```

Before the commit, Ripper didn’t add label `bar` id to `vtable`
because `formal_argument` function for Ripper didn’t return id
but returned `VALUE lhs`.
Therefore Ripper didn’t `SET_LEX_STATE(EXPR_END|EXPR_LABEL)` for following `bar`
in `parse_ident` because `lvar_defined` for following `bar` was not true.

Currently Ripper does `SET_LEX_STATE(EXPR_END|EXPR_LABEL)` then
the result of this test case is changed like below.

```
Prism::ParseTest#test_filepath_unparser/corpus/literal/def.txt [ruby/test/prism/parse_test.rb:280]:
<[[80, 13], :on_ident, “bar”, END|LABEL]> expected but was
<[[80, 13], :on_ident, “bar”, ARG]>.
```

Parser sets lex state to `END|LABEL` on master branch.
Therefore previous commit makes Ripper’s behavior aligned with parser’s behavior.

```
$ ruby -v -y -e "def foo(bar: bar())" -e "end"
ruby 3.4.0dev (2024-02-11T23:52:05Z master 697ade7bda) [arm64-darwin21]
...
Reading a token
parser_dispatch_scan_event:11210 (1: 12|1|7)
lex_state: ARG|LABELED -> ARG at line 11113
lex_state: ARG -> END|LABEL at line 11128
parser_dispatch_scan_event:11877 (1: 13|3|4)
Next token is token “local variable or method” (1.13-1.16: bar)
Shifting token “local variable or method” (1.13-1.16: bar)
```
2024-02-20 17:33:58 +09:00
yui-knk
89cfc15207 [Feature #20257] Rearchitect Ripper
Introduce another semantic value stack for Ripper so that
Ripper can manage both Node and Ruby Object separately.
This rearchitectutre of Ripper solves these issues.
Therefore adding test cases for them.

* [Bug 10436] https://bugs.ruby-lang.org/issues/10436
* [Bug 18988] https://bugs.ruby-lang.org/issues/18988
* [Bug 20055] https://bugs.ruby-lang.org/issues/20055

Checked the differences of `Ripper.sexp` for files under `/test/ruby`
are only on test_pattern_matching.rb.
The differences comes from the differences between
`new_hash_pattern_tail` functions between parser and Ripper.
Ripper `new_hash_pattern_tail` didn’t call `assignable` then
`kw_rest_arg` wasn’t marked as local variable.
This is also fixed by this commit.

```
--- a/./tmp/before/test_pattern_matching.rb
+++ b/./tmp/after/test_pattern_matching.rb
@@ -3607,7 +3607,7 @@
                  [:in,
                   [:hshptn, nil, [], [:var_field, [:@ident, “a”, [984, 13]]]],
                   [[:binary,
-                    [:vcall, [:@ident, “a”, [985, 10]]],
+                    [:var_ref, [:@ident, “a”, [985, 10]]],
                     :==,
                     [:hash, nil]]],
                   nil]]],
@@ -3662,7 +3662,7 @@
                  [:in,
                   [:hshptn, nil, [], [:var_field, [:@ident, “a”, [993, 13]]]],
                   [[:binary,
-                    [:vcall, [:@ident, “a”, [994, 10]]],
+                    [:var_ref, [:@ident, “a”, [994, 10]]],
                     :==,
                     [:hash,
                      [:assoclist_from_args,
@@ -3813,7 +3813,7 @@
                    [:command,
                     [:@ident, “raise”, [1022, 10]],
                     [:args_add_block,
-                     [[:vcall, [:@ident, “b”, [1022, 16]]]],
+                     [[:var_ref, [:@ident, “b”, [1022, 16]]]],
                      false]]],
                   [:else, [[:var_ref, [:@kw, “true”, [1024, 10]]]]]]]],
                nil,
@@ -3876,7 +3876,7 @@
                      [:@int, “0”, [1033, 15]]],
                     :“&&“,
                     [:binary,
-                     [:vcall, [:@ident, “b”, [1033, 20]]],
+                     [:var_ref, [:@ident, “b”, [1033, 20]]],
                      :==,
                      [:hash, nil]]]],
                   nil]]],
@@ -3946,7 +3946,7 @@
                      [:@int, “0”, [1042, 15]]],
                     :“&&“,
                     [:binary,
-                     [:vcall, [:@ident, “b”, [1042, 20]]],
+                     [:var_ref, [:@ident, “b”, [1042, 20]]],
                      :==,
                      [:hash,
                       [:assoclist_from_args,
@@ -5206,7 +5206,7 @@
                      [[:assoc_new,
                        [:@label, “c:“, [1352, 22]],
                        [:@int, “0”, [1352, 25]]]]]],
-                   [:vcall, [:@ident, “r”, [1352, 29]]]],
+                   [:var_ref, [:@ident, “r”, [1352, 29]]]],
                   false]]],
                [:binary,
                 [:call,
@@ -5299,7 +5299,7 @@
                       [:assoc_new,
                        [:@label, “c:“, [1367, 34]],
                        [:@int, “0”, [1367, 37]]]]]],
-                   [:vcall, [:@ident, “r”, [1367, 41]]]],
+                   [:var_ref, [:@ident, “r”, [1367, 41]]]],
                   false]]],
                [:binary,
                 [:call,
@@ -5931,7 +5931,7 @@
              [:in,
               [:hshptn, nil, [], [:var_field, [:@ident, “r”, [1533, 11]]]],
               [[:binary,
-                [:vcall, [:@ident, “r”, [1534, 8]]],
+                [:var_ref, [:@ident, “r”, [1534, 8]]],
                 :==,
                 [:hash,
                  [:assoclist_from_args,
```
2024-02-20 17:33:58 +09:00
Hiroshi SHIBATA
f2d453347f [rubygems/rubygems] re-order util methods
4b5eb7a02c
2024-02-20 05:33:15 +00:00
Hiroshi SHIBATA
018261eb92 [rubygems/rubygems] Added small tests
08a245bdf8
2024-02-20 05:33:15 +00:00
Hiroshi SHIBATA
a551d93655 [rubygems/rubygems] Now install extension in lib is true
bbcad80772
2024-02-20 05:33:15 +00:00
Hiroshi SHIBATA
27501a5509 [rubygems/rubygems] Restore Gem.configuration during installation test
bf7156968e
2024-02-20 05:33:14 +00:00
dependabot[bot]
4ba76d4847 [rubygems/rubygems] Bump rb-sys
Bumps [rb-sys](https://github.com/oxidize-rb/rb-sys) from 0.9.87 to 0.9.88.
- [Release notes](https://github.com/oxidize-rb/rb-sys/releases)
- [Commits](https://github.com/oxidize-rb/rb-sys/compare/v0.9.87...v0.9.88)

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

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

30d7940714
2024-02-19 23:31:19 +00:00
dependabot[bot]
0501ecddac [rubygems/rubygems] Bump rb-sys
Bumps [rb-sys](https://github.com/oxidize-rb/rb-sys) from 0.9.87 to 0.9.88.
- [Release notes](https://github.com/oxidize-rb/rb-sys/releases)
- [Commits](https://github.com/oxidize-rb/rb-sys/compare/v0.9.87...v0.9.88)

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

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

de1bb744f5
2024-02-19 23:30:44 +00:00
Nobuyoshi Nakada
d9b61e228f
Omit a bizzarre test in IRB 2024-02-19 16:33:27 +09:00
Nobuyoshi Nakada
fcc55dc226
[Bug #20280] Raise SyntaxError on invalid encoding symbol 2024-02-19 16:33:26 +09:00
Hiroshi SHIBATA
3d4f5e7671 [rubygems/rubygems] Suppress warning during test runner.
ruby core repository explicitly removed this test file at
c945a849cb
for avoid to show warning.

ee78e64b50
2024-02-19 04:47:08 +00:00
Hiroshi SHIBATA
1dca87cf53
Load rubygems explicitly for tests of test/irb 2024-02-19 11:34:32 +09:00
Hiroshi SHIBATA
c14d295afd
Fix accidentally changed to rename test method at d95d3484a9 2024-02-19 11:05:13 +09:00
Stan Lo
7e577e150a [ruby/irb] Fix irb:rdbg for ruby head
(https://github.com/ruby/irb/pull/876)

* Update binding.irb check for Ruby head

With https://github.com/ruby/ruby/pull/9605, backtrace in Ruby head
now has a new format. This commit updates the check for binding.irb
to work with Ruby head.

* Do not include a backtick in error messages and backtraces

[Feature #16495]

---------

ebffd3d976

Co-authored-by: Yusuke Endoh <mame@ruby-lang.org>
2024-02-19 11:01:30 +09:00
Stan Lo
9ec9910081 [ruby/irb] Update error message assertions for Ruby 3.4
(https://github.com/ruby/irb/pull/874)

https://github.com/ruby/ruby/pull/9605 changes both quotes and format for
exception messages. So we need to update the assertions in the tests.

9359d4b51d
2024-02-19 10:48:38 +09:00
Hiroshi SHIBATA
11a6bb8195
Revert 25d74b9527 at test/irb 2024-02-19 10:47:42 +09:00
Kevin Newton
ec1eda7b62 [ruby/prism] Account for encoding in regexp named captures
17dc6b6281
2024-02-18 21:42:09 +00:00
Kevin Newton
792804e32f [ruby/prism] Split up comments between leading and trailing
Also make them lazy to allocate the array, and also expose ParseResult#encoding.

08ec7683ae
2024-02-18 20:57:13 +00:00
Stan Lo
07c774e85c [ruby/irb] Revamp help command
(https://github.com/ruby/irb/pull/877)

* Make help command display help for individual commands

Usage: `help [command]`

If the command is not specified, it will display a list of all available commands.

If the command is specified, it will display the banner OR description of the command.

If the command is not found, it will display a message saying that the command is not found.

* Rename test/irb/cmd to test/irb/command

* Add banner to edit and ls commands

* Promote help command in the help message

1. Make `show_cmds` an alias of `help` so it's not displayed in the help message
2. Update description of the help command to reflect `help <command>` syntax

* Rename banner to help_message

43a2c99f3f
2024-02-18 18:21:08 +00:00
Benoit Daloze
13d2a3a88f [ruby/prism] Fix visitor in desugar test
* The #visit method is no longer called for every node since 2e6baa3.
* As a consequence EnsureEveryNodeOnceInAST was only visiting ProgramNode
  for `visitor.visit(ast)` and no nodes at all for `ast.accept(visitor)`.

683513620a
2024-02-17 15:35:51 +00:00
Kevin Newton
170058ca9e [ruby/prism] Ignore incorrect files
d1094ac232
2024-02-16 20:41:53 +00:00
Kevin Newton
13301587cf [ruby/prism] Fix block_pass for []=
bf79206220
2024-02-16 20:41:52 +00:00
Alan Wu
b4327c1158 YJIT: Support empty splat
Previously we rejected empty splat calls to methods with no parameters
as `iseq_arity_error` which didn't work well with delegated calls.
2024-02-16 15:27:49 -05:00
Alan Wu
c4e30d2865 YJIT: Support **nil
This adds YJIT support for VM_CALL_KW_SPLAT with nil, specifically for
when we already know from the context that it's done with a nil. This is
enough to support forwarding with `...` when there no keyword arguments
are present.

Amend the kw_rest support to propagate the type of the parameter to help
with this. Test interactions with splat, since the splat array sits
lower on the stack when a kw_splat argument is present.
2024-02-16 15:27:49 -05:00
Noah Gibbs
e801ccb343 [ruby/prism] More rescue and ensure; constant handling
207f579e70
2024-02-16 17:50:17 +00:00
Kevin Newton
8414c26f0d [PRISM] Make prism compiler warning experimental 2024-02-16 11:56:48 -05:00
Stan Lo
f5801e2bf4 [ruby/irb] Standardize command related names
(https://github.com/ruby/irb/pull/873)

* Replace ExtendCommand with Command and standardize command related names

1. Rename lib/irb/extend-command.rb to lib/irb/command.rb
2. Rename lib/irb/cmd/*.rb to lib/irb/command/*.rb
3. Rename test/irb/test_cmd.rb to test/irb/test_command.rb
4. Rename ExtendCommand to Command

* Alias ExtendCommand to Command and deprecate it

* Rename Command::Nop to Command::Base

* Not deprecate old constants just yet

* Add lib/irb/cmd/nop.rb back

462c1284af
2024-02-16 16:47:36 +00:00