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

74616 Коммитов

Автор SHA1 Сообщение Дата
yui-knk d8601621ed Enhance keep_tokens option for RubyVM::AbstractSyntaxTree parsing methods
Implementation for Language Server Protocol (LSP) sometimes needs token information.
For example both `m(1)` and `m(1, )` has same AST structure other than node locations
then it's impossible to check the existence of `,` from AST. However in later case,
it might be better to suggest variables list for the second argument.
Token information is important for such case.

This commit adds these methods.

* Add `keep_tokens` option for `RubyVM::AbstractSyntaxTree.parse`, `.parse_file` and `.of`
* Add `RubyVM::AbstractSyntaxTree::Node#tokens` which returns tokens for the node including tokens for descendants nodes.
* Add `RubyVM::AbstractSyntaxTree::Node#all_tokens` which returns all tokens for the input script regardless the receiver node.

[Feature #19070]

Impacts on memory usage and performance are below:

Memory usage:

```
$ cat test.rb
root = RubyVM::AbstractSyntaxTree.parse_file(File.expand_path('../test/ruby/test_keyword.rb', __FILE__), keep_tokens: true)

$ /usr/bin/time -f %Mkb /usr/local/bin/ruby -v
ruby 3.2.0dev (2022-11-19T09:41:54Z 19070-keep_tokens d3af1b8057) [x86_64-linux]
11408kb

# keep_tokens :false
$ /usr/bin/time -f %Mkb /usr/local/bin/ruby test.rb
17508kb

# keep_tokens :true
$ /usr/bin/time -f %Mkb /usr/local/bin/ruby test.rb
30960kb
```

Performance:

```
$ cat ../ast_keep_tokens.yml
prelude: |
  src = <<~SRC
    module M
      class C
        def m1(a, b)
          1 + a + b
        end
      end
    end
  SRC
benchmark:
  without_keep_tokens: |
    RubyVM::AbstractSyntaxTree.parse(src, keep_tokens: false)
  with_keep_tokens: |
    RubyVM::AbstractSyntaxTree.parse(src, keep_tokens: true)

$ make benchmark COMPARE_RUBY="./ruby" ARGS=../ast_keep_tokens.yml
/home/kaneko.y/.rbenv/shims/ruby --disable=gems -rrubygems -I../benchmark/lib ../benchmark/benchmark-driver/exe/benchmark-driver \
            --executables="compare-ruby::./ruby -I.ext/common --disable-gem" \
            --executables="built-ruby::./miniruby -I../lib -I. -I.ext/common  ../tool/runruby.rb --extout=.ext  -- --disable-gems --disable-gem" \
            --output=markdown --output-compare -v ../ast_keep_tokens.yml
compare-ruby: ruby 3.2.0dev (2022-11-19T09:41:54Z 19070-keep_tokens d3af1b8057) [x86_64-linux]
built-ruby: ruby 3.2.0dev (2022-11-19T09:41:54Z 19070-keep_tokens d3af1b8057) [x86_64-linux]
warming up..

|                     |compare-ruby|built-ruby|
|:--------------------|-----------:|---------:|
|without_keep_tokens  |     21.659k|   21.303k|
|                     |       1.02x|         -|
|with_keep_tokens     |      6.220k|    5.691k|
|                     |       1.09x|         -|
```
2022-11-21 09:01:34 +09:00
Takashi Kokubun bbc4cf5f76
Revert wrong sync in 5958c305e5 [ci skip]
sync_default_gems.rb sometimes syncs too much.
2022-11-20 14:22:41 -08:00
Nobuyoshi Nakada 701dfe4eb7
[Bug #19016] Handle syntax error in main script like other errors
So that `SyntaxError#detailed_message` will be used also in the case
exiting by such syntax error.
2022-11-20 20:00:40 +09:00
Nobuyoshi Nakada 12b7b85227
Use `enum ruby_tag_type` over `int` 2022-11-20 20:00:40 +09:00
Nobuyoshi Nakada 230c7de252
sync_default_gems.rb: Fix substitution [ci skip]
As there should be no modified files just affter `git cherry-pick`
succeeded in `sync_default_gems_with_commits`, reset to the previous
revision once to pick up the committed files.
2022-11-20 18:51:41 +09:00
Takashi Kokubun 779917fcc0
Avoid a timeout on test_cache_optimization_exponential
The timeout seems too short for some CIs.
http://rubyci.s3.amazonaws.com/debian11-aarch64/ruby-master/log/20221120T012840Z.fail.html.gz
2022-11-19 21:58:22 -08:00
Takashi Kokubun 66ac288ae2 [ruby/irb] Push an accidentally uncommitted diff
https://github.com/ruby/irb/commit/7e9f27afd7
2022-11-20 05:38:43 +00:00
Takashi Kokubun 67034ac7e2 [ruby/irb] Deal with inconsistency with ruby/ruby
https://github.com/ruby/irb/commit/41d5012849
2022-11-20 05:34:51 +00:00
Takashi Kokubun 8512b97d27 [ruby/irb] Require missing EnvUtil
https://github.com/ruby/irb/commit/9bb1757b02
2022-11-20 05:32:11 +00:00
Takashi Kokubun fa2e0cc018 [ruby/irb] Try using a different file name
hoping to address:
https://github.com/ruby/ruby/actions/runs/3506561941/jobs/5873689640

https://github.com/ruby/irb/commit/de9a6b9d00
2022-11-20 05:31:56 +00:00
Takashi Kokubun f47251671d [ruby/irb] Require rubygems for ruby/ruby
You can't take rubygems for granted in a default gem.
https://github.com/ruby/ruby/actions/runs/3506561943/jobs/5873689466

https://github.com/ruby/irb/commit/58bb3954d0
2022-11-20 05:19:50 +00:00
Takashi Kokubun 1284baec12
Skip TestDRbSSLAry on mswin
This doesn't seem to stably work on mswin:
https://github.com/ruby/ruby/actions/runs/3505363753/jobs/5871633211

For CI stability, it generally seems like a bad idea to run druby tests
on Windows, given that it's pretty much unstable on MinGW as well.
2022-11-19 21:14:08 -08:00
Takashi Kokubun e0f0367ab5 [ruby/irb] Fix CI failure on ruby/ruby
https://github.com/ruby/irb/commit/ea8c716922
2022-11-20 05:06:07 +00:00
Stan Lo 180ed611b2 [ruby/irb] Add edit command (https://github.com/ruby/irb/pull/453)
* Add edit command

* Make find_source a public singleton method

* Add document for the edit command

* Make find_end private

* Remove duplicated private

https://github.com/ruby/irb/commit/4321674aa7
Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
2022-11-20 04:47:54 +00:00
Lars Kanis 439990318d Avoid warnings on MINGW:
win32/win32.c: In function 'rtc_error_handler':
win32/win32.c:691:5: warning: function 'rtc_error_handler' might be a candidate for 'gnu_printf' format attribute [-Wsuggest-attribute=format]
  691 |     rb_str_vcatf(str, fmt, ap);
      |     ^~~~~~~~~~~~

and

win32/win32.c:683:1: warning: 'rtc_error_handler' defined but not used [-Wunused-function]
  683 | rtc_error_handler(int e, const char *src, int line, const char *exe, const char *fmt, ...)
      | ^~~~~~~~~~~~~~~~~
2022-11-20 11:06:28 +09:00
Takashi Kokubun 5958c305e5 [ruby/irb] Document a full list of commands
(https://github.com/ruby/irb/pull/451)

* Document a full list of commands

* Document debug as well

* Make it less duplicated
2022-11-19 22:14:44 +00:00
Takashi Kokubun 23750c866a [ruby/irb] Update documentation about Autocompletion
(https://github.com/ruby/irb/pull/452)

https://github.com/ruby/irb/commit/e6b4917750
2022-11-19 22:10:09 +00:00
Nobuyoshi Nakada 01bc2fc514
Update fake.rb for test-spec
spec/ruby/command_line/dash_v_spec.rb needs it.
2022-11-20 01:10:40 +09:00
BurdetteLamar 909ea6b60d [ruby/net-http] About the Examples moved to separate file
https://github.com/ruby/net-http/commit/0512b5bfc9
2022-11-19 15:33:28 +00:00
BurdetteLamar e6162728f6 [ruby/net-http] Enhanced RDoc for Net::HTTP 2022-11-19 10:25:12 -05:00
Burdette Lamar 2047636af8 [ruby/net-http] Update lib/net/http/request.rb
https://github.com/ruby/net-http/commit/e3c9011edb

Co-authored-by: Peter Zhu <peter@peterzhu.ca>
2022-11-19 10:17:54 -05:00
BurdetteLamar dbb902fc91 [ruby/net-http] Enhanced RDoc for Net::HTTP
https://github.com/ruby/net-http/commit/4444e8cea4
2022-11-19 10:17:54 -05:00
BurdetteLamar 951eabdcf2 [ruby/net-http] Enhanced RDoc for Net::HTTP
https://github.com/ruby/net-http/commit/6b30c5310b
2022-11-19 10:17:53 -05:00
Maciek Rząsa 50c6cabadc
[DOC] Change formatting in the exec docs
The last part of the sentence was accidentally put in enumeration, It
made an impression that it's one of the rules, not the result of
applying the rules.
2022-11-19 11:38:16 +09:00
Alan Wu 574d849869 Run skipped minitest tests that now pass
The mentioned PR was merged.
2022-11-19 10:36:51 +09:00
Takashi Kokubun 6dcb7b9216
YJIT: Improve the failure message on enlarging a branch (#6769) 2022-11-18 17:27:07 -08:00
yui-knk 082cfcfd06 Add test cases for args forwarding after rest argument 2022-11-19 10:17:16 +09:00
Alan Wu 5c505f4a48 Rename misleading label
We use this code path when we require the same extension twice, so it's
not necessarily about the feature being statically linked. Removing this
code when there is no statically linked extensions leads to breakage.
2022-11-18 19:42:24 -05:00
Alan Wu 7f269a3c2d Fix io/console test for --with-static-linked-ext
The tests looks for the .so file, which doesn't exist when the extension
is statically linked. In that situation it passes -I to ruby with
nothing after it which ate the -rio/console argument.
2022-11-18 18:50:34 -05:00
Aaron Patterson 2185f0ca77
Update assertion
New T_OBJECT objects will have a T_OBJECT shape
2022-11-18 13:58:13 -08:00
Aaron Patterson 9e067df76b 32 bit comparison on shape id
This commit changes the shape id comparisons to use a 32 bit comparison
rather than 64 bit.  That means we don't need to load the shape id to a
register on x86 machines.

Given the following program:

```ruby
class Foo
  def initialize
    @foo = 1
    @bar = 1
  end

  def read
    [@foo, @bar]
  end
end

foo = Foo.new
foo.read
foo.read
foo.read
foo.read
foo.read

puts RubyVM::YJIT.disasm(Foo.instance_method(:read))
```

The machine code we generated _before_ this change is like this:

```
== BLOCK 1/4, ISEQ RANGE [0,3), 65 bytes ======================
  # getinstancevariable
  0x559a18623023: mov rax, qword ptr [r13 + 0x18]
  # guard object is heap
  0x559a18623027: test al, 7
  0x559a1862302a: jne 0x559a1862502d
  0x559a18623030: cmp rax, 4
  0x559a18623034: jbe 0x559a1862502d
  # guard shape, embedded, and T_OBJECT
  0x559a1862303a: mov rcx, qword ptr [rax]
  0x559a1862303d: movabs r11, 0xffff00000000201f
  0x559a18623047: and rcx, r11
  0x559a1862304a: movabs r11, 0xb000000002001
  0x559a18623054: cmp rcx, r11
  0x559a18623057: jne 0x559a18625046
  0x559a1862305d: mov rax, qword ptr [rax + 0x18]
  0x559a18623061: mov qword ptr [rbx], rax

== BLOCK 2/4, ISEQ RANGE [3,6), 0 bytes =======================
== BLOCK 3/4, ISEQ RANGE [3,6), 47 bytes ======================
  # gen_direct_jmp: fallthrough
  # getinstancevariable
  # regenerate_branch
  # getinstancevariable
  # regenerate_branch
  0x559a18623064: mov rax, qword ptr [r13 + 0x18]
  # guard shape, embedded, and T_OBJECT
  0x559a18623068: mov rcx, qword ptr [rax]
  0x559a1862306b: movabs r11, 0xffff00000000201f
  0x559a18623075: and rcx, r11
  0x559a18623078: movabs r11, 0xb000000002001
  0x559a18623082: cmp rcx, r11
  0x559a18623085: jne 0x559a18625099
  0x559a1862308b: mov rax, qword ptr [rax + 0x20]
  0x559a1862308f: mov qword ptr [rbx + 8], rax
```

After this change, it's like this:

```
== BLOCK 1/4, ISEQ RANGE [0,3), 41 bytes ======================
  # getinstancevariable
  0x5560c986d023: mov rax, qword ptr [r13 + 0x18]
  # guard object is heap
  0x5560c986d027: test al, 7
  0x5560c986d02a: jne 0x5560c986f02d
  0x5560c986d030: cmp rax, 4
  0x5560c986d034: jbe 0x5560c986f02d
  # guard shape
  0x5560c986d03a: cmp word ptr [rax + 6], 0x19
  0x5560c986d03f: jne 0x5560c986f046
  0x5560c986d045: mov rax, qword ptr [rax + 0x10]
  0x5560c986d049: mov qword ptr [rbx], rax

== BLOCK 2/4, ISEQ RANGE [3,6), 0 bytes =======================
== BLOCK 3/4, ISEQ RANGE [3,6), 23 bytes ======================
  # gen_direct_jmp: fallthrough
  # getinstancevariable
  # regenerate_branch
  # getinstancevariable
  # regenerate_branch
  0x5560c986d04c: mov rax, qword ptr [r13 + 0x18]
  # guard shape
  0x5560c986d050: cmp word ptr [rax + 6], 0x19
  0x5560c986d055: jne 0x5560c986f099
  0x5560c986d05b: mov rax, qword ptr [rax + 0x18]
  0x5560c986d05f: mov qword ptr [rbx + 8], rax
```

The first ivar read is a bit more complex, but the second ivar read is
much simpler.  I think eventually we could teach the context about the
shape, then emit only one shape guard.
2022-11-18 12:04:10 -08:00
Aaron Patterson 6582f34831 rename SHAPE_BITS to SHAPE_ID_NUM_BITS 2022-11-18 12:04:10 -08:00
Takashi Kokubun ba3b40a9ae [ruby/irb] Discover and load debug.gem even if it's not in Gemfile
(https://github.com/ruby/irb/pull/448)

* Minor fixes on debug command

* Discover and load debug.gem even if it's not in Gemfile

* Eliminate else for rescue

* Discover the latest one from all gem paths
2022-11-18 18:03:33 +00:00
Takashi Kokubun b1cbc883f2 [ruby/irb] Minor fixes on debug command
(https://github.com/ruby/irb/pull/447)

* Minor fixes on debug command

* Update lib/irb/cmd/debug.rb
2022-11-18 17:34:42 +00:00
Aaron Patterson 10788166e7 Differentiate T_OBJECT shapes from other objects
We would like to differentiate types of objects via their shape.  This
commit adds a special T_OBJECT shape when we allocate an instance of
T_OBJECT.  This allows us to avoid testing whether an object is an
instance of a T_OBJECT or not, we can just check the shape.
2022-11-18 08:31:56 -08:00
yui-knk f0ce118662 Make anonymous rest arg (*) and block arg (&) accessible from ARGS node 2022-11-18 18:25:42 +09:00
Shugo Maeda ddd62fadaf Allow anonymous keyword rest parameter with other keyword parameters
Fixes [Bug #19132]
2022-11-18 18:23:06 +09:00
Stan Lo 00872d120b [ruby/irb] Add debug command (https://github.com/ruby/irb/pull/446)
https://github.com/ruby/irb/commit/30faa13fa3
2022-11-18 09:11:23 +00:00
Hiroshi SHIBATA a80b66e7eb
Added build instructions of psych and fiddle with source files of libyaml and libffi 2022-11-18 17:51:37 +09:00
Yusuke Endoh ca1aa7afea Prevent a "method redefined" warning
http://rubyci.s3.amazonaws.com/ubuntu2004-arm/ruby-master/log/20221118T033003Z.log.html.gz
```
[21350/22024] TestIRB::ExtendCommandTest#test_show_source_end_finder/home/chkbuild/chkbuild/tmp/build/20221118T033003Z/ruby/test/irb/test_cmd.rb:523: warning: method redefined; discarding old show_source_test_method
/home/chkbuild/chkbuild/tmp/build/20221118T033003Z/ruby/test/irb/test_cmd.rb:523: warning: previous definition of show_source_test_method was here
 ```
2022-11-18 15:39:50 +09:00
Yusuke Endoh 417f3cd893 tool/generic_erb.rb: Add a hack to prevent "unused variable" warnings 2022-11-18 14:56:55 +09:00
Yusuke Endoh e19afe36ca Revert "tool/generic_erb.rb: Use ERB#result_with_hash instead of #result"
This reverts commit bd148a2bdd.

ERB#result_with_hash does not work on Ruby 2.2

https://ci.appveyor.com/project/ruby/ruby/builds/45420170
```
../tool/generic_erb.rb:33:in `block (2 levels) in <main>': undefined method `result_with_hash' for #<ERB:0x0000000002516650> (NoMethodError)
```
2022-11-18 14:45:21 +09:00
Yusuke Endoh 096ffebbbf Prevent a "warning: assigned but unused variable - s2" 2022-11-18 14:39:40 +09:00
Yusuke Endoh bd148a2bdd tool/generic_erb.rb: Use ERB#result_with_hash instead of #result
to prevent the warnings:
```
./tool/generic_erb.rb:23: warning: assigned but unused variable - output
./tool/generic_erb.rb:24: warning: assigned but unused variable - vpath
```
2022-11-18 14:38:49 +09:00
Jimmy Miller 98e9165b0a
Fix bug involving .send and overwritten methods. (#6752)
@casperisfine reporting a bug in this gist https://gist.github.com/casperisfine/d59e297fba38eb3905a3d7152b9e9350

After investigating I found it was caused by a combination of send and a c_func that we have overwritten in the JIT. For send calls, we need to do some stack manipulation before making the call. Because of the way exits works, we need to do that stack manipulation at the last possible moment. In this case, we weren't doing that stack manipulation at all. Unfortunately, with how the code is structured there isn't a great place to do that stack manipulation for our overridden C funcs.

Each overridden C func can return a boolean stating that it shouldn't be used. We would need to do the stack manipulation after all of those checks are done. We could pass a lambda(?) or separate out the logic for "can I run this override" from "now generate the code for it". Since we are coming up on a release, I went with the path of least resistence and just decided to not use these overrides if we are in a send call.

We definitely should revist this in the future.
2022-11-17 23:17:40 -05:00
Takashi Kokubun ab4379e086
Refactor RB_SPECIAL_CONST_P (#6759)
Since https://github.com/ruby/ruby/pull/6599, RUBY_IMMEDIATE_MASK also
overlaps RUBY_Qnil. Now RB_SPECIAL_CONST_P seems confusing since both
RB_IMMEDIATE_P and RB_TEST check for RUBY_Qnil while we only need to
check RUBY_Qnil besides RUBY_IMMEDIATE_MASK. I'd like to make this
change to make it less confusing.

I confirmed that this doesn't change the number of instructions used for
the RUBY_Qfalse check on Linux x86_64 GCC and macOS arm64 Clang.
2022-11-17 17:55:24 -08:00
Takashi Kokubun d8202a52a5 [ruby/irb] Add an option to suppress code_around_binding
(https://github.com/ruby/irb/pull/444)

for debug.gem's `irb` command
2022-11-18 00:47:53 +00:00
Samuel Williams cb4c89e08e
Fix quoting of code in `NEWS.md`. 2022-11-17 15:19:21 -08:00
Samuel Williams ea8a7287e2
Add support for `sockaddr_un` on Windows. (#6513)
* Windows: Fix warning about undefined if_indextoname()

* Windows: Fix UNIXSocket on MINGW and make .pair more reliable

* Windows: Use nonblock=true for read tests with scheduler

* Windows: Move socket detection from File.socket? to File.stat

Add S_IFSOCK to Windows and interpret reparse points accordingly.
Enable tests that work now.

* Windows: Use wide-char functions to UNIXSocket

This fixes behaviour with non-ASCII characters.
It also fixes deletion of temporary UNIXSocket.pair files.

* Windows: Add UNIXSocket tests for specifics of Windows impl.

* Windows: fix VC build due to missing _snwprintf

Avoid usage of _snwprintf, since it fails linking ruby.dll like so:

  linking shared-library x64-vcruntime140-ruby320.dll
  x64-vcruntime140-ruby320.def : error LNK2001: unresolved external symbol snwprintf
  x64-vcruntime140-ruby320.def : error LNK2001: unresolved external symbol vsnwprintf_l

whereas linking miniruby.exe succeeds.

This patch uses snprintf on the UTF-8 string instead.

Also remove branch GetWindowsDirectoryW, since it doesn't work.

* Windows: Fix dangling symlink test failures

Co-authored-by: Lars Kanis <kanis@comcard.de>
2022-11-17 14:50:25 -08:00
Takashi Kokubun 4e4b29b1a9
YJIT: Make the code GC test stabler
The first `add_pages` call shouldn't hit Code GC yet; otherwise
`compiles` returns false. With the increased code size in runtime_stats
itself, it sometimes hits Code GC too early, at least in arm64 that has
a large code size.
2022-11-17 14:02:01 -08:00