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

81867 Коммитов

Автор SHA1 Сообщение Дата
Alan Wu 9cb0ad863c YJIT: Fix missing arity check for splat calls to methods with optionals
Previously, for splat callsites that land in methods with optional
parameters, we didn't reject the case where the caller supplies too many
arguments. Accepting those calls previously caused YJIT to construct
corrupted control frames, which leads to crashes if the callee uses
certain stack walking methods such as Kernel#raise and String#gsub (for
setting up the frame-local `$~`).

Example crash in a debug build:

    Assertion Failed: ../vm_core.h:1375:VM_ENV_FLAGS:FIXNUM_P(flags)
2023-12-11 19:21:08 -05:00
Alan Wu 4755309474 YJIT: Rename helper function and correct counter name
Counter::guard_send_iseq_has_rest_and_splat_not_equal was using
jump-if-lesser-than, so wasn't checking for equality. Rename function
because moving is destructive in Rust, which is confusing for this function
which doesn't modify the array.
2023-12-11 19:21:08 -05:00
Kazuhiro NISHIYAMA 9765ada69c Fix NoMethodError on fail
```
.../tool/lib/colorize.rb:56:in `resolve_color': undefined method `gsub' for an instance of Symbol (NoMethodError)

    color.gsub(/\b[a-z][\w ]+/) do |n|
	 ^^^^^
	from .../tool/lib/colorize.rb:47:in `decorate'
	from .../tool/lib/test/unit.rb:1012:in `block in failed'
```
2023-12-12 09:14:11 +09:00
Samuel Giddins 505715ddf1 [rubygems/rubygems] Fewer allocations in gem installation
For now, on a small rails app I have hanging around:

```
==> memprof.after.txt <==
Total allocated: 872.51 MB (465330 objects)
Total retained:  40.48 kB (326 objects)

==> memprof.before.txt <==
Total allocated: 890.79 MB (1494026 objects)
Total retained:  40.40 kB (328 objects)
```

Not a huge difference in memory usage, but it's a drastic improvement
in total number of allocations.

Additionally, this will pay huge dividends once
https://github.com/ruby/zlib/pull/61 is merged, as it will allow us to
completely avoid allocations in the repeated calls to readpartial,
which currently accounts for most of the memory usage shown above.

https://github.com/rubygems/rubygems/commit/f78d45d927
2023-12-11 23:14:58 +00:00
hogelog 4a94ce8569
[DOC] Fix RDoc to match actual Kenrel.require behavior (#9180) 2023-12-12 07:13:54 +09:00
Jemma Issroff 69d60cc67b [PRISM] Properly compile MultiTargetNodes within parameters
If there are MultiTargetNodes within parameters, we need to
iterate over them and compile them individually correctly, once
the locals are all in the correct spaces. We need to add one
getlocal for the hidden variable, and then can recurse into the
MultiTargetNodes themselves
2023-12-11 17:04:46 -05:00
Jemma Issroff 5c8e1911ca [PRISM] Fixed rest in MultiTargetNodes 2023-12-11 17:04:46 -05:00
Jemma Issroff aaeccc2924 [PRISM] Correctly implemented forwarding parameters in methods 2023-12-11 17:04:46 -05:00
Jemma Issroff 85ad5be9ee [PRISM] Restructure parameters on ScopeNodes
This commit completely restructures how we handle parameters. The
motivation for this commit was the fix compilation of MultiTargetNodes
within parameters, including nested MultiTargetNodes. A subsequent
commit will actually do the compilation for the MultiTargetNodes.

This commit's main accomplishment is restructuring the locals table
and how we account for it on the ScopeNode, specifically with regards
to hidden variables.

It has multiple steps, all commented within the code, to calculate
the locals table correctly and compile the parameters:
- Step 1: Caculate the table size for the locals
- Step 2: Populate iv index table and local table
- Step 3: Fill in parameter names of MultiTargetNodes on local table
- Step 4: Fill in method body locals on local table
- Step 5: Compile any locals
2023-12-11 17:04:46 -05:00
Burdette Lamar e1d995a96c
[DOC] Complex doc (#9185) 2023-12-11 15:38:16 -05:00
Koichi Sasada 687d29f93c try modified tests.
debug.gem 1.9.0 has a test issue so try modified one.
ref: d4feeae32b
2023-12-12 02:59:10 +09:00
Jemma Issroff fb93535070 [PRISM] Define and use a pm_add_ensure_iseq
Prior to this commit, we were using `add_ensure_iseq` which compiled
a node as if it was a CRuby node. This commit defines
`pm_add_ensure_iseq` which compiles the Prism node appropriately.
2023-12-11 12:53:47 -05:00
Maxime Chevalier-Boisvert 3f25c08fa5
YJIT: implement call fuzzer script (#9129)
* YJIT: implement call fuzzer script

Attempt to detect bugs in YJIT call implementation.

* Add basic checks for rest, kwrest. Impprove formatting.

* Refactor call fuzzer to make it more powerful and maintainable

Compute checksum of arguments

* Fix checksum computation. Add useless locals as sussged by Alan.

* Add some useless if statements

* Add arguments of different types

* Pass object arguments as well. Force different shapes.

* Compute fuzzing time/speed

* Make use of block param
2023-12-11 12:52:47 -05:00
Kevin Newton 4095e7d2be [ruby/prism] Regexp terminator escapes
https://github.com/ruby/prism/commit/42a48a2ba9
2023-12-11 16:34:55 +00:00
Kevin Newton c65de63913 [ruby/prism] Handle a non-interpolated dsym spanning a heredoc
https://github.com/ruby/prism/commit/b23136ebfd
2023-12-11 16:34:41 +00:00
Kevin Newton 261e8f28a0 [ruby/prism] Correct escapes when ctrl+meta+escape
https://github.com/ruby/prism/commit/ee68b17c01
2023-12-11 16:34:27 +00:00
Martin Emde e186cebe42 [rubygems/rubygems] Override initialize in bundle rubygems_ext for NameTuple
https://github.com/rubygems/rubygems/commit/f63ce682d2
2023-12-11 15:40:08 +00:00
Kevin Newton b673b5b432 [ruby/prism] Split up CallNode in target position
In this commit we're splitting up the call nodes that were in target
positions (that is, for loop indices, rescue error captures, and
multi assign targets).

Previously, we would simply leave the call nodes in place. This had
the benefit of keeping the AST relatively simple, but had the
downside of not being very explicit. If a static analysis tool wanted
to only look at call nodes, it could easily be confused because the
method would have 1 fewer argument than it would actually be called
with.

This also brings some consistency to the AST. All of the nodes in
a target position are now *TargetNode nodes. These should all be
treated the same, and the call nodes can now be treated the same.

Finally, there is benefit to memory. Because being in a target
position ensures we don't have some fields, we can strip down the
number of fields on these nodes.

So this commit introduces two new nodes: CallTargetNode and
IndexTargetNode. For CallTargetNode we get to drop the opening_loc,
closing_loc, arguments, and block. Those can never be present. We
also get to mark their fields as non-null, so they will always be
seen as present.

The IndexTargetNode keeps around most of its fields but gets to
drop both the name (because it will always be []=) and the
message_loc (which was always super confusing because it included
the arguments by virtue of being inside the []).

Overall, this adds complexity to the AST at the expense of memory
savings and explicitness. I believe this tradeoff is worth it in
this case, especially because these are very much not common nodes
in the first place.

https://github.com/ruby/prism/commit/3ef71cdb45
2023-12-11 15:32:31 +00:00
Jemma Issroff c69d1367a7 [PRISM] Fix ElseNode within CaseNode
The logic within the consequent for the CaseNodes in popped cases
was incorrect as it wouldn't emit consequent instructions for a
popped CaseNode. This commit fixes that.
2023-12-11 09:47:59 -05:00
Ufuk Kayserilioglu 0562c246eb Add handling of implicit hash arguments
Arguments that are passed as a hash need special consideration since in certain case they are not treated as keyword arguments. For example, if a call is passing `"a" => 1` as an argument, this will be turned into an implicit hash argument and not a keyword argument.

The existing compiler checks to see if all hash nodes can be treated as keyword arguments. If they can, then it will treat them as keyword arguments. If not, then it will treat them as implicit hash arguments.

This commit implements the same logic inside the Prism compiler.
2023-12-11 09:47:33 -05:00
TSUYUSATO Kitsune 48cb70fee9 [ruby/prism] Fix parsing unterminated empty string `"`
Fix https://github.com/ruby/prism/pull/2034

https://github.com/ruby/prism/commit/8280e577fa
2023-12-11 13:36:37 +00:00
TSUYUSATO Kitsune a860e3605c [ruby/prism] Fix to parse a (endless-)range with binary operators
Fix https://github.com/ruby/prism/pull/2022
Fix https://github.com/ruby/prism/pull/2030

https://github.com/ruby/prism/commit/b78d8b6525
2023-12-11 13:34:48 +00:00
Daisuke Aritomo 1ab91b12fa [rubygems/rubygems] Stream output from ext builds when --verbose
Uses Open3.popen2e in place of Open3.capture2e in Gem::Ext::Builder.
This change aims to stream stdout/stderr of ext builds when in verbose
mode, instead of printing everything at once when the build completes.

Nice for debugging gem builds that consumes longer times.

https://github.com/rubygems/rubygems/commit/dcdcb5adda
2023-12-11 11:07:36 +00:00
Nobuyoshi Nakada 655aacc43a Use dedicated functions to check terminators 2023-12-11 16:51:46 +09:00
git 980255cb7b Update bundled gems list as of 2023-12-10 2023-12-11 06:58:43 +00:00
Hsing-Hui Hsu e5e53ee173 docs(compar.c): change class name in example 2023-12-11 08:56:37 +09:00
Burdette Lamar 91b0d5fa38
[DOC] RDoc for Complex (#9181) 2023-12-10 10:22:22 -05:00
Nobuyoshi Nakada d9dbcd848f
Add bright colors and multiple attributes [ci skip]
Not only:
```
$ ruby colorize.rb fail foo
```

Also:
```
$ ruby colorize.rb 'bright_blue;bold' foo
```
2023-12-10 20:43:47 +09:00
Nobuyoshi Nakada 0096d6a809
Extract configuration and lookup methods [ci skip] 2023-12-10 20:43:44 +09:00
Koichi Sasada c4c39082af add `flags` to `rb_postponed_job_preregister`
for future extensions.
2023-12-10 15:39:06 +09:00
KJ Tsanaktsidis f8effa209a Change the semantics of rb_postponed_job_register
Our current implementation of rb_postponed_job_register suffers from
some safety issues that can lead to interpreter crashes (see bug #1991).
Essentially, the issue is that jobs can be called with the wrong
arguments.

We made two attempts to fix this whilst keeping the promised semantics,
but:
  * The first one involved masking/unmasking when flushing jobs, which
    was believed to be too expensive
  * The second one involved a lock-free, multi-producer, single-consumer
    ringbuffer, which was too complex

The critical insight behind this third solution is that essentially the
only user of these APIs are a) internal, or b) profiling gems.

For a), none of the usages actually require variable data; they will
work just fine with the preregistration interface.

For b), generally profiling gems only call a single callback with a
single piece of data (which is actually usually just zero) for the life
of the program. The ringbuffer is complex because it needs to support
multi-word inserts of job & data (which can't be atomic); but nobody
actually even needs that functionality, really.

So, this comit:
  * Introduces a pre-registration API for jobs, with a GVL-requiring
    rb_postponed_job_prereigster, which returns a handle which can be
    used with an async-signal-safe rb_postponed_job_trigger.
  * Deprecates rb_postponed_job_register (and re-implements it on top of
    the preregister function for compatability)
  * Moves all the internal usages of postponed job register
    pre-registration
2023-12-10 15:00:37 +09:00
KJ Tsanaktsidis aecbd66742 Add RUBY_ATOMIC_{PTR_,}FETCH macros for atomic loads
This can already be emulated by doing an atomic fetch_add of zero, but
this is more explicit.

[Bug #19994]
2023-12-10 15:00:37 +09:00
Nobuyoshi Nakada 6e8ad7497e
Move `DOT_WAIT` before including Makefile that is using it [ci skip] 2023-12-10 13:55:19 +09:00
Stan Lo 130268e264 [ruby/irb] Simplify show_source's super calculation
(https://github.com/ruby/irb/pull/807)

https://github.com/ruby/irb/commit/2cccc448de
2023-12-10 04:21:46 +00:00
Alex Koval 04eb1b6f26 [ruby/prism] fix: escape newline
https://github.com/ruby/prism/commit/a28b427dcc
2023-12-10 03:06:36 +00:00
Jeremy Evans f64357540e Ensure super(**kw, &block) calls kw.to_hash before block.to_proc
Similar as previous commit, but handles the super case with
explicit arguments.
2023-12-09 13:15:47 -08:00
Jeremy Evans a950f23078 Ensure f(**kw, &block) calls kw.to_hash before block.to_proc
Previously, block.to_proc was called first, by vm_caller_setup_arg_block.
kw.to_hash was called later inside CALLER_SETUP_ARG or setup_parameters_complex.

This adds a splatkw instruction that is inserted before sends with
ARGS_BLOCKARG and KW_SPLAT and without KW_SPLAT_MUT. This is not needed in the
KW_SPLAT_MUT case, because then you know the value is a hash, and you don't
need to call to_hash on it.

The splatkw instruction checks whether the second to top block is a hash,
and if not, replaces it with the value of calling to_hash on it (using
rb_to_hash_type).  As it is always before a send with ARGS_BLOCKARG and
KW_SPLAT, second to top is the keyword splat, and top is the passed block.
2023-12-09 13:15:47 -08:00
KJ Tsanaktsidis c0b6ea7c8b Add a fudge factor to the GC compaction move up/down tests
There seems to be another manifestation of bug #20021, where some of the
compaction tests are failing on i686 for unrelated PR's because of fake
"live" references to moved objects on the machine stack.

We _could_ solve this by counting how many objects are pinned during
compaction, but doing that involves pushing down the mark & pin bitset
merge into gc_compact_plane and out of gc_compact_page, which I thought
was pretty ugly.

Now that we've solved bug #20022 though, we're able to compact
arbitrarily many objects with GC.verify_compaction_references, so the
number of objects we're moving is now 50,000 instead of 500. Since
that's now much larger than the number of objects likely to be pinned, I
think it's safe enough to just add a fudge-factor to the tests.

Any _other_ change in GC.verify_compaction_references that breaks
compaction is now highly likely to break the assertion by more than 10
objects, since it's operating on so many more in the first place.

[Bug #20021]
2023-12-09 12:49:51 -08:00
John Hawthorn 9e09e5aa3a Fix test of GVL instrumentation on Ractor sleeping
It seems that the Ractor sleep GVL event arrives very slightly after the
value becomes available and other threads wake (which makes sense) so we
need a little additional time to ensure we end up in a consisteny state.
2023-12-09 12:01:29 -08:00
John Hawthorn b2ad4fec1a Add missing GVL hooks for M:N threads and ractors 2023-12-09 09:31:41 -08:00
git 88d9a4d58a Update default gems list at edb8fc24d4 [ci skip] 2023-12-09 08:35:02 +00:00
Yusuke Endoh edb8fc24d4 [ruby/error_highlight] Bump version
https://github.com/ruby/error_highlight/commit/942a723d32
2023-12-09 08:34:08 +00:00
Victor Shepelev 07734b51c6
[DOC] Small fixes for documentation rendering
Mostly just fixing RDoc's incorrect treatment of `+`
2023-12-09 13:54:33 +09:00
eileencodes 1cbe114d1c [PRISM] Fix `PM_CALL_NODE` assignment
This PR fixes ruby/prism#1963. Array and variable assignment was broken
for call nodes. The change checks if the `method_id` is related to
assignment and if is adds a `putnil`, `setn` and a `pop`.

The incorrect instructions meant that in some cases (demonstrated in
tests) the wrong value would be returned.

I verified that this fixes the test mentioned in the issue
(run: `RUBY_ISEQ_DUMP_DEBUG=prism make test/-ext-/st/test_numhash.rb`)

Incorrect instructions:

```
"********* Ruby *************"
== disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(4,10)>
0000 putnil                                                           (   4)[Li]
0001 putself
0002 send                                   <calldata!mid:tbl, argc:0, FCALL|VCALL|ARGS_SIMPLE>, nil
0005 putself
0006 send                                   <calldata!mid:i, argc:0, FCALL|VCALL|ARGS_SIMPLE>, nil
0009 putself
0010 send                                   <calldata!mid:j, argc:0, FCALL|VCALL|ARGS_SIMPLE>, nil
0013 setn                                   3
0015 send                                   <calldata!mid:[]=, argc:2, ARGS_SIMPLE>, nil
0018 pop
0019 leave

"********* PRISM *************"
== disasm: #<ISeq:<compiled>@<compiled>:3 (3,0)-(3,10)>
0000 putself                                                          (   3)[Li]
0001 send                                   <calldata!mid:tbl, argc:0, FCALL|VCALL|ARGS_SIMPLE>, nil
0004 putself
0005 send                                   <calldata!mid:i, argc:0, FCALL|VCALL|ARGS_SIMPLE>, nil
0008 putself
0009 send                                   <calldata!mid:j, argc:0, FCALL|VCALL|ARGS_SIMPLE>, nil
0012 send                                   <calldata!mid:[]=, argc:2, ARGS_SIMPLE>, nil
0015 leave
```

Fixed instructions:

```
"********* Ruby *************"
== disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(4,10)>
0000 putnil                                                           (   4)[Li]
0001 putself
0002 send                                   <calldata!mid:tbl, argc:0, FCALL|VCALL|ARGS_SIMPLE>, nil
0005 putself
0006 send                                   <calldata!mid:i, argc:0, FCALL|VCALL|ARGS_SIMPLE>, nil
0009 putself
0010 send                                   <calldata!mid:j, argc:0, FCALL|VCALL|ARGS_SIMPLE>, nil
0013 setn                                   3
0015 send                                   <calldata!mid:[]=, argc:2, ARGS_SIMPLE>, nil
0018 pop
0019 leave

"********* PRISM *************"
== disasm: #<ISeq:<compiled>@<compiled>:3 (3,0)-(3,10)>
0000 putnil                                                           (   3)[Li]
0001 putself
0002 send                                   <calldata!mid:tbl, argc:0, FCALL|VCALL|ARGS_SIMPLE>, nil
0005 putself
0006 send                                   <calldata!mid:i, argc:0, FCALL|VCALL|ARGS_SIMPLE>, nil
0009 putself
0010 send                                   <calldata!mid:j, argc:0, FCALL|VCALL|ARGS_SIMPLE>, nil
0013 setn                                   3
0015 send                                   <calldata!mid:[]=, argc:2, ARGS_SIMPLE>, nil
0018 pop
0019 leave
```

Fixes ruby/prism#1963
2023-12-08 12:45:40 -08:00
BurdetteLamar 9e7ca2c3c9 RDoc for Complex 2023-12-08 15:13:11 -05:00
Kevin Newton 98e3552cfb [ruby/prism] Add necessary encoding flags for symbols and regex
This doesn't actually fix the encodings for symbols and regex,
unfortunately. But I wanted to get this change in because it is
the last AST change we're going to make before 3.3 is released.

So, if consumers want, they can start to check these flags to
determine the encoding, even though it will be wrong. Then once we
actually set them correctly, everything should work.

https://github.com/ruby/prism/commit/9b35f7e891
2023-12-08 18:59:52 +00:00
Benoit Daloze a94a2eea34 [rubygems/rubygems] Upstream RubyGems changes from TruffleRuby
https://github.com/rubygems/rubygems/commit/749a508968
2023-12-08 17:01:23 +00:00
git 365c6cc226 Update default gems list at f2c13ff9e8 [ci skip] 2023-12-08 16:50:31 +00:00
Schneems f2c13ff9e8 [ruby/syntax_suggest] v2.0.0
https://github.com/ruby/syntax_suggest/commit/53b2a1b03c
2023-12-08 16:49:33 +00:00
Kevin Newton a54eb9c6f9 [ruby/prism] A couple of small dot enhancements
https://github.com/ruby/prism/commit/5642a57f39
2023-12-08 14:40:32 +00:00