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

86646 Коммитов

Автор SHA1 Сообщение Дата
David Rodríguez 5b931d9de6 [rubygems/rubygems] Extract a `rake_path` helper
https://github.com/rubygems/rubygems/commit/0f2db73619
2024-07-23 19:40:08 +00:00
David Rodríguez b0a0eda231 [rubygems/rubygems] Normalize a few specs using sources
Use the standard sources to avoid having to explictly pass ENV with the repo.

https://github.com/rubygems/rubygems/commit/95055dba57
2024-07-23 19:40:08 +00:00
David Rodríguez 1758d436e7 [rubygems/rubygems] Enforce passing a block to `simulate_platform`
https://github.com/rubygems/rubygems/commit/0658903e25
2024-07-23 19:40:07 +00:00
Peter Zhu 6770bb4a8c Fix running GC in finalizer when RUBY_FREE_AT_EXIT
The following code crashes because the GC ran during finalizers will
cause T_ZOMBIE objects to be on the heap, which crashes when we call
rb_gc_obj_free on it:

    raise_proc = proc do |id|
      GC.start
    end
    1000.times do
      ObjectSpace.define_finalizer(Object.new, raise_proc)
    end
2024-07-23 14:45:45 -04:00
Kevin Newton cb863907d8 [ruby/prism] Single line method bodies should not be marked as newline
https://github.com/ruby/prism/commit/18a8597276
2024-07-23 18:44:31 +00:00
Peter Zhu 47c0df9c4a [DOC] Allow linking to File#path in Tempfile.create 2024-07-23 14:26:34 -04:00
Peter Zhu c00990869f [DOC] Fix code formatting for Tempfile.create 2024-07-23 14:25:15 -04:00
Kevin Newton b6800515e8 [PRISM] Fix up ensure compilation, match compile.c 2024-07-23 12:48:48 -04:00
Burdette Lamar e9ae939021
[DOC] Doc for BasicObject (#11139) 2024-07-23 11:06:19 -04:00
Kevin Newton 744cf0549e [ruby/prism] Recurse upward to detect invalid returns
https://github.com/ruby/prism/commit/3d39b7961f
2024-07-23 14:54:01 +00:00
Peter Zhu f0d8a0a2bf Fix memory leak in parser when loading non-ASCII file
When loading a non-ASCII compatible file, an error is raised which
causes memory leak.

For example:

    require "tempfile"

    Tempfile.create do |f|
      f.write("# -*- coding: UTF-16BE -*-")
      f.flush

      10.times do
        20_000.times do
          begin
            load(f.path)
          rescue
          end
        end

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

Before:

    33904
    49072
    64528
    79216
    94576
    109504
    124768
    139536
    154928
    170256

After:

    19568
    21296
    21664
    21728
    22192
    22256
    22416
    22272
    22272
    22272
2024-07-23 08:50:53 -04:00
yui-knk 57b11be15a Implement UNLESS NODE keyword locations 2024-07-23 14:35:23 +09:00
yui-knk f23485a8d6 [Feature #20624] Enhance `RubyVM::AbstractSyntaxTree::Node#locations`
This commit introduce `RubyVM::AbstractSyntaxTree::Node#locations` method
and `RubyVM::AbstractSyntaxTree::Location` class.

Ruby AST node will hold multiple locations information.
`RubyVM::AbstractSyntaxTree::Node#locations` provides a way to access
these locations information.

`RubyVM::AbstractSyntaxTree::Location` is a class which holds these location information:

* `#first_lineno`
* `#first_column`
* `#last_lineno`
* `#last_column`
2024-07-23 12:36:00 +09:00
Alan Wu 5617fec1f8 newobj_of(): Use parameter instead of GET_RACTOR()
No point repeating the work callers to this function already do.
2024-07-22 20:00:59 -04:00
Kevin Newton 959c95a01e [ruby/prism] Ignore shebangs in evals
https://github.com/ruby/prism/commit/4c55409794
2024-07-22 19:46:26 +00:00
Kevin Newton 2effa98b6f [ruby/prism] Implement mismatched indentation warning
https://github.com/ruby/prism/commit/5d5bf92be8
2024-07-22 18:57:10 +00:00
Peter Zhu ec6f40e8f1 [PRISM] Use xcalloc for constants instead of calloc 2024-07-22 14:22:47 -04:00
Peter Zhu 5299672a5b [PRISM] Fix memory leak in constants
For example, the following code leaks:

    code = 1000.times.map { |i| "var#{i} = 1" }.join("\n")

    10.times do
      1000.times do
        RubyVM::InstructionSequence.compile_prism(code)
      end

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

Before:

    70384
    88032
    103856
    115712
    125584
    132768
    144784
    152624
    165296
    180608

After:

    62368
    78784
    74512
    87712
    85072
    77728
    69424
    74992
    71264
    81440
2024-07-22 14:22:47 -04:00
Jean Boussier 34adc07372 Document the reasoning behind the fix for [Bug #20641] 2024-07-22 18:07:18 +02:00
Peter Zhu 5e3b8010ed Add newline when printing dlopen error message 2024-07-22 10:25:44 -04:00
Jean Boussier 82aee1a946 bundled_gems.rb: Add a fast path
[Bug #20641] `Gem::BUNDLED_GEMS.warning?` adds a lot of extra
work on top of `require`. When the call end up atually loading code
the overhead is somewhat marginal.

However it's not uncommon for code to go some late `require` in some
paths, so it's expected that calling `require` with something already
required is somewhat fast, and `bundled_gems.rb` breaks this assumption.

To avoid this, we can have a fast path that in most case allow to
short-circuit all the heavy computations. If we extract the feature
basename and it doesn't match any of the bundled gems we care about
we can return very early.

With this change `require 'date'` is now only 1.33x slower on Ruby
3.3.3, than it was on Ruby 3.2.2, whereas before this change it
was at least 100x slower.
2024-07-22 10:33:07 +02:00
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 730e3b2ce0
("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
0ee3960685 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