87158 Commits

Author SHA1 Message Date
Nobuyoshi Nakada
04d57e2c5c
Evaluate macro arguments just once
And fix unclosed parenthesis.
2024-08-11 02:36:11 +09:00
Nobuyoshi Nakada
9416bfb83d
Increase timeout of test-bundler-parallel
Even if it succeeds, it takes almost 40 minutes.
2024-08-11 00:19:20 +09:00
Raed Rizqie
00176cd40f fix ucrt arch 2024-08-11 00:10:28 +09:00
Raed Rizqie
f1224e55fd fix i386-ucrt build 2024-08-11 00:10:28 +09:00
Jean Boussier
b1f4222fc5 Cherry-pick test for [Bug #20668]
The bug didn't impact master because this was largely refactored,
but it's still valuable to add the test for it to prevent future
regressions.
2024-08-10 12:41:35 +02:00
Koichi ITO
ad23bbe574 [ruby/prism] [Doc] Tweak the docs for lex APIs
`Prism.lex` and `Prism.lex_file` return `ParseLexResult` instead of `Array`.
`Prism::parse_lex` and `Prism::parse_lex_file` return `ParseLexResult` instead of `ParseResult`.
This PR updates the documentation to reflect these return values.

https://github.com/ruby/prism/commit/ee331941c0
2024-08-10 08:42:36 +00:00
Jean Boussier
6ee9a08d32 rb_setup_fake_ary: use precomputed flags
Setting up the fake array is a bit more expensive than would be
expected because `rb_ary_freeze` does a lot of checks and lookup
a shape transition.

If we assume fake arrays will always be frozen, we can precompute
the flags state and just assign it.
2024-08-10 10:09:14 +02:00
Peter Zhu
7b7dde37f5 [ruby/psych] Guard from memory leak in Psych::Emitter#start_document
When an exception is raised, it can leak memory in `head`. There are two
places that can leak memory:

1. `Check_Type(tuple, T_ARRAY)` can leak memory if `tuple` is not an
   array.
2. `StringValue(name)` and `StringValue(value)` if they are not strings
   and the call to `to_str` does not return a string.

This commit fixes these memory leaks by wrapping the code around a
rb_ensure so that the memory is freed in all cases.

The following code demonstrates the memory leak:

    emitter = Psych::Emitter.new(StringIO.new)
    nil_to_string_tags = [[nil, "tag:TALOS"]] + ([1] * 1000)
    expected_array_tags = [1] * 1000

    10.times do
      1_000.times do
        # Raises `no implicit conversion of nil into String`
        emitter.start_document([], nil_to_string_tags, 0)
      rescue TypeError
      end

      1_000.times do
        # Raises `wrong argument type Integer (expected Array)`
        emitter.start_document([], expected_array_tags, 0)
      rescue TypeError
      end

      puts `ps -o rss= -p #{$$}`
    end

Before:

    47248
    79728
    111968
    144224
    176480
    208896
    241104
    273280
    305472
    337664

After:

    14832
    15088
    15344
    15344
    15360
    15632
    15632
    15632
    15648
    15648

https://github.com/ruby/psych/commit/053af73818
2024-08-09 20:28:53 +00:00
Jean Boussier
4e85b6b4c4 rb_str_bytesplice: skip encoding check if encodings are the same
If both strings have the same encoding, all this work is useless.
2024-08-09 22:06:44 +02:00
Jean Boussier
3bac5f6af5 string.c: add fastpath in str_ensure_byte_pos
If the string only contain single byte characters we can
skips all the costly checks.
2024-08-09 22:06:44 +02:00
Jean Boussier
a332367dad string.c: Add fastpath to single_byte_optimizable
`rb_enc_from_index` is a costly operation so it is worth avoiding
to call it for the common encodings.

Also in the case of UTF-8, it's more efficient to scan the
coderange if it is unknown that to fallback to the slower
algorithms.
2024-08-09 22:06:44 +02:00
Alan Wu
5a570421a5 [DOC] Regexp.last_match returns $~, not $! 2024-08-09 16:02:36 -04:00
Peter Zhu
ee482f48ee Add psych expand tabs commit to .git-blame-ignore-revs [ci skip] 2024-08-09 15:38:19 -04:00
Peter Zhu
d1474affa8 [ruby/psych] Convert tabs to spaces in test/psych/test_yaml.rb
https://github.com/ruby/psych/commit/64bfc308f8
2024-08-09 19:35:29 +00:00
Peter Zhu
712ac99e4d [ruby/psych] Convert missed tabs to spaces in C files
https://github.com/ruby/psych/commit/74a6b4d226
2024-08-09 19:35:28 +00:00
Peter Zhu
c8708c72c4 Add expand tabs commit in psych to .git-blame-ignore-revs 2024-08-09 14:51:40 -04:00
Peter Zhu
e63a2115f6 [ruby/psych] Convert tabs to spaces in C files
https://github.com/ruby/psych/commit/e7d64c9848
2024-08-09 18:29:46 +00:00
Peter Zhu
c91ec7ba1e Remove rb_gc_impl_objspace_mark
It's not necessary for the GC implementation to call rb_gc_mark_roots
which calls back into the GC implementation's rb_gc_impl_objspace_mark.
2024-08-09 10:27:40 -04:00
Jean Boussier
2bd5dc47ac string.c: str_capacity don't check for immediates
`STR_EMBED_P` uses `FL_TEST_RAW` meaning we already assume `str`
isn't an immediate, so we can use `FL_TEST_RAW` here too.
2024-08-09 15:20:58 +02:00
Jean Boussier
af44af238b str_independent: add a fastpath with a single flag check
If we assume that most strings we modify are not frozen and
are independent, then we can optimize this case by replacing
multiple flag checks by a single mask check.
2024-08-09 15:20:58 +02:00
Naoto Ono
f57167d338 Increase timeout in test_darwin_invalid_call method 2024-08-09 12:16:23 +09:00
Takashi Kokubun
77ffdfe79f
YJIT: Allow tracing fallback counters (#11347)
* YJIT: Allow tracing fallback counters

* Update yjit.md about --yjit-trace-exits=counter
2024-08-08 16:13:16 -07:00
Burdette Lamar
ec5436bc3a
[DOC] Tweaks for Array#[]= (#11329) 2024-08-08 16:09:32 -04:00
BurdetteLamar
e008f0553d [DOC] Add remark about in-brief for method doc 2024-08-08 16:08:47 -04:00
BurdetteLamar
b9a9564c1f [DOC] Tweaks for Array#[] 2024-08-08 16:08:15 -04:00
BurdetteLamar
d657205c58 [DOC] Tweaks for Array#[] 2024-08-08 16:08:15 -04:00
BurdetteLamar
6fee51069c [DOC] Tweaks for Array#== 2024-08-08 16:05:42 -04:00
Stan Lo
64a7b87e1d
Sync rdoc to fix master doc's display issue (#11345)
Sync rdoc

This syncs changes made in https://github.com/ruby/rdoc/pull/1148, which
will fix https://docs.ruby-lang.org/en/master/'s display on certain screens.
2024-08-08 13:02:46 -07:00
Peter Zhu
0bff07644b
Make YJIT a GC root rather than an object (#11343)
YJIT currently uses the YJIT root object to mark objects during GC and
update references during compaction. This object otherwise serves no
purpose.

This commit changes it YJIT to be step when marking the GC root. This
saves some memory from being allocated from the system and the GC.
2024-08-08 12:19:35 -04:00
Peter Zhu
868d63f0a3 Disable GC even during finalizing
We're seeing a crash during shutdown in rb_gc_impl_objspace_free because
it's running lazy sweeping during shutdown. It appears that it's due to
`finalizing` being set, which causes GC to not be aborted and not
disabled which causes it to be in lazy sweeping at shutdown.

The full stack trace is:

    #6  rb_bug (fmt=fmt@entry=0x5643b8ebde78 "lazy sweeping underway when freeing object space") at error.c:1095
    #7  0x00005643b8a3c697 in rb_gc_impl_objspace_free (objspace_ptr=<optimized out>) at gc/default.c:9507
    #8  0x00005643b8c269eb in ruby_vm_destruct (vm=0x7e2fdc84d000) at vm.c:3141
    #9  0x00005643b8a5147b in rb_ec_cleanup (ec=<optimized out>, ex=<optimized out>) at eval.c:263
    #10 0x00005643b8a51c93 in ruby_run_node (n=<optimized out>) at eval.c:319
    #11 0x00005643b8a4c7c7 in rb_main (argv=0x7fffef15e7f8, argc=18) at ./main.c:43
    #12 main (argc=<optimized out>, argv=<optimized out>) at ./main.c:62
2024-08-08 10:11:49 -04:00
Hiroshi SHIBATA
da8cf99cb5
Added test scenario for https://github.com/ruby/ruby/pull/11322 2024-08-08 16:23:49 +09:00
Hiroshi SHIBATA
7e0910a82c
We should use uplevel:2 in another case.
Like the following scenario with bootsnap, that frames are same or smaller than frame_to_skip(=3).

---
"/Users/hsbt/.local/share/rbenv/versions/3.3-dev/lib/ruby/3.3.0/bundled_gems.rb:69:in `block (2 levels) in replace_require'"
"/Users/hsbt/.local/share/gem/gems/bootsnap-1.18.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'"
"test_warn_bootsnap.rb:11:in `<main>'"
---
2024-08-08 16:20:22 +09:00
Jean Boussier
7594a292b1
lib/bundled_gems.rb: more reliable caller detection
The `2` skipped frames went out of sync and now it should be `3`.

Rather than just update the offset, we can implement a way that
is adaptative as long as all require decorators are also called require.

Also we should compute the corresponding `uplevel` otherwise the
warning will still point decorators.

Co-authored-by: "Hiroshi SHIBATA" <hsbt@ruby-lang.org>
2024-08-08 15:50:26 +09:00
Hiroshi SHIBATA
fa443699af
Partly reverted 09638741ba4d9547a0e48af8c767744fb1d7f68d
This change didn't work with Ruby 3.3.

We should revert this to test bundled_gems.rb with Ruby 3.3.
2024-08-08 13:24:27 +09:00
Hiroshi SHIBATA
3da7e440e9 Revert "[ruby/uri] Warn compatibility methods in RFC3986_PARSER"
This reverts commit c3becc3ba6c584fbeabd5182e304e61529235fe6.
2024-08-08 12:04:00 +08:00
Hiroshi SHIBATA
68ebd56a76 [ruby/uri] Use URI::RFC2396_PARSER explicitly in URI
https://github.com/ruby/uri/commit/898b889811
2024-08-08 02:09:27 +00:00
Hiroshi SHIBATA
c3becc3ba6 [ruby/uri] Warn compatibility methods in RFC3986_PARSER
https://github.com/ruby/uri/commit/9997c1acee
2024-08-08 02:09:27 +00:00
tompng
8d39939107 [ruby/rdoc] Use ascii chatacter in HTML file
https://github.com/ruby/rdoc/commit/40a6690010
2024-08-08 08:54:52 +09:00
Alan Wu
057c53f771 Make rb_vm_invoke_bmethod() static 2024-08-07 19:17:31 -04:00
Alan Wu
68a419d749 Delete unused rb_check_funcall_with_hook() 2024-08-07 19:17:31 -04:00
Your Name
34715bdd91 Tune codegen for rb_yield() calls landing in ISeqs
Unlike in older revisions in the year, GCC 11 isn't inlining the call
to vm_push_frame() inside invoke_iseq_block_from_c() anymore. We do
want it to be inlined since rb_yield() speed is fairly important.
Logs from -fopt-info-optimized-inline reveal that GCC was blowing its
code size budget inlining invoke_block_from_c_bh() into its various
callers, leaving suboptimal code for its body.

Take away some uses of the `inline` keyword and merge a common tail
call to vm_exec() for overall better code.

This tweak gives about 18% on a micro benchmark and 1% on the
chunky-png benchmark from yjit-bench. I tested on a Skylake server.

```
$ cat c-to-ruby-call.yml
benchmark:
  - 0.upto(10_000_000) {}

$ benchmark-driver --chruby '+patch;master' c-to-ruby-call.yml
Warming up --------------------------------------
0.upto(10_000_000) {}      2.299 i/s -       3.000 times in 1.304689s (434.90ms/i)
Calculating -------------------------------------
                          +patch      master
0.upto(10_000_000) {}      2.299       1.943 i/s -       6.000 times in 2.609393s 3.088353s

Comparison:
             0.upto(10_000_000) {}
               +patch:         2.3 i/s
               master:         1.9 i/s - 1.18x  slower

$ ruby run_benchmarks.rb --chruby 'master;+patch' chunky-png
<snip>

----------  -----------  ----------  -----------  ----------  --------------  -------------
bench       master (ms)  stddev (%)  +patch (ms)  stddev (%)  +patch 1st itr  master/+patch
chunky-png  1156.1       0.1         1142.2       0.2         1.01            1.01
----------  -----------  ----------  -----------  ----------  --------------  -------------
```
2024-08-07 18:49:20 -04:00
Peter Zhu
e271feb866 Fix memory leak reported with YJIT
The following memory leak gets reported with RUBY_FREE_AT_EXIT and YJIT
enabled because the memory for yjit_root is never freed.

    STACK OF 1 INSTANCE OF 'ROOT LEAK: <calloc in rb_gc_impl_calloc>':
    11  dyld                                  0x18067e0e0 start + 2360
    10  miniruby                              0x1024b67d8 main + 100  main.c:62
    9   miniruby                              0x10256e0ec ruby_options + 156  eval.c:117
    8   miniruby                              0x102681164 ruby_process_options + 5140  ruby.c:3097
    7   miniruby                              0x10256f7dc rb_ensure + 180  eval.c:0
    6   miniruby                              0x102681c64 load_file_internal + 996  ruby.c:2685
    5   miniruby                              0x102682368 ruby_opt_init + 380  ruby.c:1817
    4   miniruby                              0x102848e38 yjit::yjit::yjit_init::h3cea491822b80cef + 360  yjit.rs:84
    3   miniruby                              0x10278f7d4 rb_yjit_init_gc_hooks + 28  yjit.c:1273
    2   miniruby                              0x10258a228 rb_data_typed_object_zalloc + 132  gc.c:989
    1   miniruby                              0x102586d88 rb_gc_impl_calloc + 148  default.c:8517
    0   libsystem_malloc.dylib                0x180840cac _malloc_zone_calloc_instrumented_or_legacy + 128
2024-08-07 16:42:24 -04:00
Burdette Lamar
3719b3d74d
[DOC] Tweaks to Array#- (#11303) 2024-08-07 15:59:57 -04:00
Burdette Lamar
2a31410ebe
[DOC] Tweaks to Array#+ (#11302) 2024-08-07 15:59:01 -04:00
Jun Aruga
53f3036bf9 tool/test-annocheck.sh: Refactor with double-quotes. 2024-08-07 18:51:20 +02:00
Jun Aruga
aed468ae0b CI: Run annocheck for libruby.so
When building with the `--shared` option, most functionality is kept in
`libruby.so`. Therefore also run annocheck for `libruby.so`.

Use `ARG IN_DIR` to propagate multiple files into the container instead of
`ARG FILES` in the `Dockerfile-copy`. Because the `COPY` syntax in Dockerfile
doesn't support copying the multiple files.
https://stackoverflow.com/questions/61599384/specify-multiple-files-in-arg-to-copy-in-dockerfile

Co-authored-by: Vít Ondruch <vondruch@redhat.com>
2024-08-07 18:51:20 +02:00
Peter Zhu
584559d86a Fix leak of token_info when Ripper#warn jumps
For example, the following code leaks:

    class MyRipper < Ripper
      def initialize(src, &blk)
        super(src)
        @blk = blk
      end

      def warn(msg, *args) = @blk.call(msg)
    end

    $VERBOSE = true
    def call_parse = MyRipper.new("if true\n  end\n") { |msg| return msg }.parse

    10.times do
      500_000.times do
        call_parse
      end

      puts `ps -o rss= -p #{$$}`
    end

Before:

    37536
    53744
    70064
    86448
    102576
    119120
    135248
    151216
    167744
    183824

After:

    19280
    19696
    19728
    20336
    20448
    21408
    21616
    21616
    21824
    21840
2024-08-07 09:14:14 -04:00
dependabot[bot]
60bbd9e462 Bump github/codeql-action from 3.25.15 to 3.26.0
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.25.15 to 3.26.0.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](afb54ba388...eb055d739a)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-08-07 12:30:20 +09:00
dependabot[bot]
d5447357b0 Bump actions/upload-artifact from 4.3.5 to 4.3.6
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 4.3.5 to 4.3.6.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](89ef406dd8...834a144ee9)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-08-07 12:29:42 +09:00
Yusuke Endoh
671f6e78b4 Use 20min for parallel test worker timeout 2024-08-07 10:17:43 +09:00