86825 Commits

Author SHA1 Message Date
dependabot[bot]
3a16971c06 Bump github/codeql-action from 3.25.12 to 3.25.13
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.25.12 to 3.25.13.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](4fa2a79536...2d790406f5)

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

Signed-off-by: dependabot[bot] <support@github.com>
2024-07-22 11:49:19 +09:00
Randy Stauner
da49bee04b [ruby/uri] Restrict constant checks to current namespace to avoid conflicts with globals
https://github.com/ruby/uri/commit/7a64e0245f
2024-07-21 16:57:32 +00:00
Nobuyoshi Nakada
c544f26726
Fix a typo in setup of block-after-blockcall tests
Unparenthesize the argument and make `command_call` when calling with
`do`-block.
2024-07-21 13:00:38 +09:00
Nobuyoshi Nakada
3c4dc3e7ac
Remove unneeded local variable
`$5`, `brace_block` is no longer assigned in this action.
2024-07-21 12:10:33 +09:00
yui-knk
11e5ebaba7 Fix SEGV on method call with empty args and brace block for do block command call 2024-07-21 11:02:38 +09:00
Jeremy Evans
e7dda08617 Do not set Enumerator::Lazy#zip to use packed format
Enumerator#zip yields a single array, not multiple arguments,
so Enumerator::Lazy#zip should do the same.

Fixes [#20623]
2024-07-20 18:16:42 -07:00
yui-knk
84680dc255 Include undef keyword into UNDEF NODE location
For example:

```
undef a, b
```

Before:

```
@ NODE_UNDEF (id: 1, line: 1, location: (1,6)-(1,10))*
```

After:

```
@ NODE_UNDEF (id: 1, line: 1, location: (1,0)-(1,10))*
```
2024-07-20 13:04:48 +09:00
yui-knk
6be539aab5 Change UNDEF Node structure
Change UNDEF Node to hold their items to keep the original grammar
structure.

For example:

```
undef a, b
```

Before:

```
@ NODE_BLOCK (id: 4, line: 1, location: (1,6)-(1,10))*
+- nd_head (1):
|   @ NODE_UNDEF (id: 1, line: 1, location: (1,6)-(1,7))
|   +- nd_undef:
|       @ NODE_SYM (id: 0, line: 1, location: (1,6)-(1,7))
|       +- string: :a
+- nd_head (2):
    @ NODE_UNDEF (id: 3, line: 1, location: (1,9)-(1,10))
    +- nd_undef:
        @ NODE_SYM (id: 2, line: 1, location: (1,9)-(1,10))
        +- string: :b
```

After:

```
@ NODE_UNDEF (id: 1, line: 1, location: (1,6)-(1,10))*
+- nd_undefs:
    +- length: 2
    +- element (0):
    |   @ NODE_SYM (id: 0, line: 1, location: (1,6)-(1,7))
    |   +- string: :a
    +- element (1):
        @ NODE_SYM (id: 2, line: 1, location: (1,9)-(1,10))
        +- string: :b
```
2024-07-20 11:25:26 +09:00
Takashi Kokubun
174c01b80e
Remove redundant :use_block with yield (#11203) 2024-07-19 18:36:14 -07:00
Alan Wu
8cf708d7b4 Make rb_check_frozen_inline() static inline again
Since 730e3b2ce01915c4a98b79bb281b2c38a9ff1131
("Stop exposing `rb_str_chilled_p`"), we noticed a speed loss on a few
benchmarks that are string operations heavy. This is partially due to
routines no longer having the options to inline rb_check_frozen_inline()
in non-LTO builds. Make it an inlining candidate again to recover speed.

Testing this patch on my machine, the fannkuchredux benchmark gets a
1.15 speed-up with YJIT and 1.03 without YJIT.
2024-07-19 17:47:12 -04:00
Jean Boussier
30f2d69825 Don't call Kernel#require in hot loop
Ref: https://bugs.ruby-lang.org/issues/20641

Even without the reference bug, `require 'date'` isn't cheap.

```ruby

require "benchmark/ips"
require "yaml"
require "date"

100.times do |i|
  $LOAD_PATH.unshift("/tmp/does/not/exist/#{i}")
end
payload = 100.times.map { Date.today }.to_yaml

Benchmark.ips do |x|
  x.report("100 dates") { YAML.unsafe_load(payload) }
end
```

Before:
```
$ ruby /tmp/bench-yaml.rb
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin22]
Warming up --------------------------------------
           100 dates   416.000 i/100ms
Calculating -------------------------------------
           100 dates      4.309k (± 1.2%) i/s -     21.632k in   5.021003s
```

After:
```
$ ruby -Ilib /tmp/bench-yaml.rb
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin22]
Warming up --------------------------------------
           100 dates   601.000 i/100ms
Calculating -------------------------------------
           100 dates      5.993k (± 1.8%) i/s -     30.050k in   5.016079s
```
2024-07-19 20:37:20 +00:00
Peter Zhu
e801fa5ce8 [PRISM] Fix compiler warning for min_tmp_array_size
prism_compile.c:5770:40: warning: comparison of integer expressions of different signedness: ‘size_t’ {aka ‘long unsigned int’} and ‘int’ [-Wsign-compare]
 5770 |                     if (tmp_array_size >= min_tmp_array_size) {
      |                                        ^~
2024-07-19 11:45:31 -04:00
Peter Zhu
b226c3407e [PRISM] Fix compiler warning for min_tmp_hash_length
prism_compile.c:1406:27: warning: comparison of integer expressions of different signedness: ‘size_t’ {aka ‘long unsigned int’} and ‘int’ [-Wsign-compare]
 1406 |                 if (count >= min_tmp_hash_length) {
      |                           ^~
2024-07-19 11:45:31 -04:00
Kevin Newton
49cf042cd2 [PRISM] Define DATA constant when parsing stdin and __END__ 2024-07-19 10:17:50 -04:00
Kevin Newton
1e4c4fe478 [ruby/prism] Fix parsing parentheses in hash patterns
https://github.com/ruby/prism/commit/22c3b559cd
2024-07-19 12:55:49 +00:00
Peter Zhu
51505f70e3 Move frozen check out of rb_gc_impl_undefine_finalizer 2024-07-19 08:53:32 -04:00
Peter Zhu
4b05d2dbb0 Make rb_gc_impl_undefine_finalizer return void 2024-07-19 08:53:32 -04:00
Peter Zhu
57d9b8ee07 Assert that object is not frozen in rb_gc_impl_define_finalizer 2024-07-19 08:53:32 -04:00
Peter Zhu
e8aa9daa5b Move return value of rb_define_finalizer out
Moves return value logic of rb_define_finalizer out from
rb_gc_impl_define_finalizer.
2024-07-19 08:53:32 -04:00
Peter Zhu
0936e3d545 Make define_final call rb_define_finalizer 2024-07-19 08:53:32 -04:00
Naoto Ono
d9bff41637 Rename a variable name 2024-07-19 16:39:21 +09:00
Naoto Ono
09dd9a0457 Launchable: Aggregate test results based on file level 2024-07-19 16:39:21 +09:00
Jeremy Evans
6428ce80f0 Avoid array allocation for f(*r2k_ary) when def f(x)
When calling a method that does not accept a positional splat
parameter with a splatted array with a ruby2_keywords flagged hash,
there is no need to duplicate the splatted array.  Previously,
Ruby would duplicate the splatted array and potentially modify
it before flattening it to the VM stack

Use a similar approach as the f(*ary, **hash) optimization,
flattening the splatted array to the VM stack without modifying
it, and make any modifications needed to the VM stack.
2024-07-18 22:17:21 -07:00
Jeremy Evans
1cc5a64dd8 Avoid hash allocation for f(*r2k_ary) when def f(kw: 1)
When calling a method that accepts keywords but not a keyword
splat with a splatted array with a ruby2_keywords flagged hash,
there is no need to duplicate the ruby2_keywords flagged hash,
since it will be accessed to get the keyword values, but it will
not be modified.
2024-07-18 22:17:21 -07:00
Jeremy Evans
4a49b060ae Check for and remove duplicate checks in test_allocation 2024-07-18 22:17:21 -07:00
Jeremy Evans
94e7d26643 Avoid array allocation for f(*empty_ary, **hash) when def f(x)
This avoids an array allocation when calling a method that does
not accept a positional splat or keywords with both a positional
splat and keywords.  Previously, Ruby would dup the positional
splat to append the keyword splat to it. Then it would flatten
the dupped positional splat array to the VM stack.

This flattens the given positional splat to the VM stack, then
adds the keyword splat hash after the last positional splat
element on the VM stack, avoiding the need to modify
the positional splat array.
2024-07-18 22:17:21 -07:00
Jeremy Evans
2c79a7641f Remove splatarray true -> splatarray false peephole optimization
The compiler now uses splatarray false for all cases that would
previously have been optimized, so this is all dead code.
2024-07-18 22:17:21 -07:00
Jeremy Evans
3de20efc30 Avoid unnecessary array allocations for f(arg, *arg, **arg, **arg), f(*arg, a: lvar), and other calls
The `f(arg, *arg, **arg, **arg)` case was previously not optimized.
The optimizer didn't optimize this case because of the multiple
keyword splats, and the compiler didn't optimize it because the
`f(*arg, **arg, **arg)` optimization added in
0ee3960685e283d8e75149a8777eb0109d41509a didn't apply.

I found it difficult to apply this optimization without changing
the `setup_args_core` API, since by the time you get to the ARGSCAT
case, you don't know whether you were called recursively or directly,
so I'm not sure if it was possible to know at that point whether the
array allocation could be avoided.

This changes the dup_rest argument in `setup_args_core` from an int
to a pointer to int.  This allows us to track whether we have allocated
a caller side array for multiple splats or splat+post across
recursive calls. Check the pointed value (*dup_rest) to determine the
`splatarray` argument. If dup_rest is 1, then use `splatarray true`
(caller-side array allocation), then set *dup_rest back to 0, ensuring
only a single `splatarray true` per method call.

Before calling `setup_args_core`, check whether the array allocation
can be avoided safely using `splatarray false`.  Optimizable cases are:

```
// f(*arg)
SPLAT

// f(1, *arg)
ARGSCAT
 LIST

// f(*arg, **arg)
ARGSPUSH
 SPLAT
 HASH nd_brace=0

// f(1, *arg, **arg)
ARGSPUSH
  ARGSCAT
   LIST
  HASH nd_brace=0
```

If so, dup_rest is set to 0 instead of 1 to avoid the allocation.

After calling `setup_args_core`, check the flag. If the flag
includes `VM_CALL_ARGS_SPLAT`, and the pointed value has changed,
indicating `splatarray true` was used, then also set
`VM_CALL_ARGS_SPLAT_MUT` in the flag.

My initial attempt at this broke the `f(*ary, &ary.pop)` test,
because we were not duplicating the ary in the splat even though
it was modified later (evaluation order issue). The initial attempt
would also break `f(*ary, **ary.pop)` or `f(*ary, kw: ary.pop)` cases
for the same reason. I added test cases for those evaluation
order issues.

Add setup_args_dup_rest_p static function that checks that a given
node is safe.  Call that on the block pass node to determine if
the block pass node is safe.  Also call it on each of the hash
key/value nodes to test that they are safe.  If any are not safe,
then set dup_rest = 1 so that `splatarray true` will be used to
avoid the evaluation order issue.

This new approach has the affect of optimizing most cases of
literal keywords after positional splats.  Previously, only
static keyword hashes after positional splats avoided array
allocation for the splat.  Now, most dynamic keyword hashes
after positional splats also avoid array allocation.

Add allocation tests for dynamic keyword keyword hashes after
positional splats.

setup_args_dup_rest_p is currently fairly conservative. It
could definitely be expanded to handle additional node types
to reduce allocations in additional cases.
2024-07-18 22:17:21 -07:00
KJ Tsanaktsidis
ca0dae25ed Don't crash if madvise(MADV_FREE or MADV_DONTNEED) fails
The M:N threading stack cleanup machinery tries to call MADV_FREE on the native
thread's stack, and calls rb_bug if it fails. Unfortunately, there's no way to
distinguish between "You passed bad parameters to madvise" and "MADV_FREE is
not supported on the kernel you are running on"; both cases just return EINVAL.
This means that if you have a Ruby on a system that was built on a system with
MADV_FREE and run it on a system without it, you get a crash in nt_free_stack.

I ran into this because rr actually emulates MADV_FREE by just returning EINVAL
and pretending it's not supported (since it can otherwise introduce
nondeterministic behaviour). So if you run bootstraptest/test_ractor.rb under
rr, you get this crash.

I think we should just get rid of the error handling here; freeing memory like
this is strictly optional anyway.

[Bug #20632]
2024-07-19 13:44:01 +10:00
Hiroshi SHIBATA
e5c06005f1 mustermann depends on URI::RFC2396_PARSER behavior
It's part of dependencies for Sinatra. we should fix mustermann before final release of Ruby 3.4
2024-07-19 12:40:56 +09:00
alpha0x00
3222c67262 [rubygems/rubygems] Fix line comment issue for map
https://github.com/rubygems/rubygems/commit/7ca06e139b
2024-07-19 03:03:16 +00:00
Kevin Newton
1c81d1a69d [PRISM] Refactor parser support into its own module 2024-07-18 21:15:54 -04:00
eileencodes
69e65b9b5a Fix interpolated sybmol node instructions
If the symbol node is interpolated like this `:"#{foo}"` the instruction
sequence should be `putstring` followed by `intern`. In this case it was
a `putobject` causing the `test_yjit` tests to fail. Note that yjit is
not required to reproduce - the instructions are `putstring` and
`intern` for yjit and non-yjit with the original parser.

To fix I moved `pm_interpolated_node_compile` out of the else, and
entirely removed the conditional. `pm_interpolated_node_compile` knows
how / when to use `putstring` over `putobject` already. The `intern` is
then added by removing the conditional.

Before:

```
== disasm: #<ISeq:<main>@test2.rb:1 (1,0)-(1,11)>
0000 putobject                              :foo                      (   1)[Li]
0002 leave
```

After:

```
== disasm: #<ISeq:<main>@test2.rb:1 (1,0)-(1,11)>
0000 putstring                              "foo"                     (   1)[Li]
0002 intern
0003 leave
```

Fixes the test `TestYJIT#test_compile_dynamic_symbol`. Related to ruby/prism#2935
2024-07-18 21:15:43 -04:00
Hiroshi SHIBATA
8db2325a11 [ruby/uri] Also support URI::PATTERN with switch-back
https://github.com/ruby/uri/commit/823697edb4
2024-07-19 00:50:38 +00:00
Hiroshi SHIBATA
082335494b [ruby/uri] Added test for constant definition and remove URI::REGEXP when using RFC3986_PARSER
https://github.com/ruby/uri/commit/6f616d97fc
2024-07-19 00:50:37 +00:00
Hiroshi SHIBATA
2a56c1841d [ruby/uri] URI.extract needs to pass block
If given block to URI.extract, it returns nil.

https://github.com/ruby/uri/commit/984145c407
2024-07-19 00:50:37 +00:00
Hiroshi SHIBATA
862041d054 [ruby/uri] Rename and switch RFC2396_PARSER test
https://github.com/ruby/uri/commit/2e0f73f05e
2024-07-19 00:50:36 +00:00
Hiroshi SHIBATA
ce4da88a57 [ruby/uri] Switch to inspect with default parser
https://github.com/ruby/uri/commit/0ab9abbf08
2024-07-19 00:50:36 +00:00
Hiroshi SHIBATA
6452cf5cb5 [ruby/uri] Added compatibility methods for RFC2396 parser
https://github.com/ruby/uri/commit/bbb8a40eae
2024-07-19 00:50:36 +00:00
Hiroshi SHIBATA
08e449d89b [ruby/uri] Added URI.parser= method for switch back to RFC2396_Parser
https://github.com/ruby/uri/commit/d7dc19ad3f
2024-07-19 00:50:35 +00:00
Takashi Kokubun
8df74deab1 YJIT: Tweak a comment a little [ci skip] 2024-07-18 13:03:17 -07:00
Takashi Kokubun
2de8b5b805
YJIT: Allow dev_nodebug to disasm release-mode code (#11198)
* YJIT: Allow dev_nodebug to disasm release-mode code

* Revert "YJIT: Squash canary before falling back"

This reverts commit f05ad373d84909da7541bd6d6ace38b48eaf24a1.
The stray canary issue should have been solved by
def7023ee4a3fc6eeba9d3a34c31a5bcff315fac, alleviating this codegen
accommodation.

* s/runtime_assertions/runtime_checks/

---------

Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>
2024-07-18 13:01:47 -07:00
Kevin Newton
059535bd65 [ruby/prism] Mark local variable writes in value positions as being read
https://github.com/ruby/prism/commit/f5149870ab
2024-07-18 19:38:53 +00:00
Kevin Newton
1fd1fb2aa5 [PRISM] Use KW_SPLAT_MUT when possible for method calls 2024-07-18 15:30:45 -04:00
Kevin Newton
53710be557 [PRISM] Use concattoarray instead of splatarray+concatarray 2024-07-18 15:30:45 -04:00
David Rodríguez
50e7c8f051 [rubygems/rubygems] Fix unused variable warning when running RubyGems tests
https://github.com/rubygems/rubygems/commit/155d8fd051
2024-07-18 19:23:06 +00:00
David Rodríguez
104dad3dd0 [rubygems/rubygems] Small tweak to avoid making the same mistake again
We checking completeness of a SpecSet, we should always ignore
dependencies not relevant for the current platform, since the resolver
and the lockfile ignore those too.

https://github.com/rubygems/rubygems/commit/c4b0c6d84e
2024-07-18 18:08:37 +00:00
David Rodríguez
d62af8e513 [rubygems/rubygems] Fix another removal issue
I failed to ignore (again) specs only considered for resolution under
some platforms that are not the current one.

https://github.com/rubygems/rubygems/commit/b72deec57e
2024-07-18 18:08:37 +00:00
David Rodríguez
b07c77730b [rubygems/rubygems] Simplify spec assertion
All that we expect here is no changes.

https://github.com/rubygems/rubygems/commit/ff984b6133
2024-07-18 18:08:36 +00:00
David Rodríguez
c9d2343f5c [rubygems/rubygems] Fix incorrect standalone script when default gems with extensions are used
https://github.com/rubygems/rubygems/commit/55649cd09b
2024-07-18 18:07:09 +00:00