Commit graph

14675 commits

Author SHA1 Message Date
David Rodríguez
0610302a8f [rubygems/rubygems] Don't validate local gemspec twice
Calling `remote!` or `cached!` on the source was expiring local specs
for now reason. It's unnecessary to override these methods for path
sources since they only deal with local specifications.

aa93b196a2
2024-06-20 15:22:13 +09:00
David Rodríguez
758e01d39d [rubygems/rubygems] Make sure to not re-resolve when a not fully specific local platform is locked
36a02c6128
2024-06-20 15:21:08 +09:00
David Rodríguez
c6a28b02c9 [rubygems/rubygems] Always resolve against the local platform
If RUBY is the only platform in the lockfile, we were skipping adding
the local platform to the list of resolution platforms. This generally
works anyways, because we had some code to still add it if the RUBY
platform is not valid for the set of locked gems.

However, sometimes it can happen that "RUBY" is valid for the current
set of locked gems, but when adding a new dependency, it becomes
invalid. For example, when adding sorbet to a Gemfile, that will
introduce `sorbet-static` as an indirect dependency which does not have
a generic "RUBY" variant. This will cause resolution to take a long time
continuously backtracking trying to find solutions that don't introduce
`sorbet-static` as a dependency and will eventually fail.

Instead, we can always add the local platform to the set of resolution
platforms before resolving, and remove it as necessary after resolution
so that we lock the correct set of platforms.

6ed1fe6050
2024-06-20 15:20:57 +09:00
David Rodríguez
9e713f0e8c [rubygems/rubygems] Remove no longer needed condition
The `force-ruby-platform` settings is properly respected when
materializing since e17d7e9efb.

c4ba54eb96
2024-06-20 15:20:47 +09:00
Martin Emde
af304ad952 [rubygems/rubygems] Revert to splitting parser due to performance regression
* The string search parser was more memory efficient but
  in some cases, much slower. Reverting until a better
  solution is found.
* Handle the situation where the line might be blank (Artifactory bug)

222d38737d
2024-06-20 15:18:56 +09:00
Yuri Kanivetsky
84c9f2a240 [rubygems/rubygems] Make "bundler? update --bundler" behave identically
30dce3f87d
2024-06-20 00:12:31 +00:00
Kevin Newton
24f48382bc [ruby/prism] (parser) Fix up tokens for empty symbol
5985ab7687
2024-06-18 21:18:39 -04:00
Earlopain
b8a592fe6e [rubygems/rubygems] Fix bundle fund when the gemfile contains optional groups
`current_dependencies` doesn't return gems in optional groups, while `specs` would

Closes https://github.com/rubygems/rubygems/pull/7757

c797e95636
2024-06-18 17:53:59 +00:00
Aaron Patterson
cdf33ed5f3 Optimized forwarding callers and callees
This patch optimizes forwarding callers and callees. It only optimizes methods that only take `...` as their parameter, and then pass `...` to other calls.

Calls it optimizes look like this:

```ruby
def bar(a) = a
def foo(...) = bar(...) # optimized
foo(123)
```

```ruby
def bar(a) = a
def foo(...) = bar(1, 2, ...) # optimized
foo(123)
```

```ruby
def bar(*a) = a

def foo(...)
  list = [1, 2]
  bar(*list, ...) # optimized
end
foo(123)
```

All variants of the above but using `super` are also optimized, including a bare super like this:

```ruby
def foo(...)
  super
end
```

This patch eliminates intermediate allocations made when calling methods that accept `...`.
We can observe allocation elimination like this:

```ruby
def m
  x = GC.stat(:total_allocated_objects)
  yield
  GC.stat(:total_allocated_objects) - x
end

def bar(a) = a
def foo(...) = bar(...)

def test
  m { foo(123) }
end

test
p test # allocates 1 object on master, but 0 objects with this patch
```

```ruby
def bar(a, b:) = a + b
def foo(...) = bar(...)

def test
  m { foo(1, b: 2) }
end

test
p test # allocates 2 objects on master, but 0 objects with this patch
```

How does it work?
-----------------

This patch works by using a dynamic stack size when passing forwarded parameters to callees.
The caller's info object (known as the "CI") contains the stack size of the
parameters, so we pass the CI object itself as a parameter to the callee.
When forwarding parameters, the forwarding ISeq uses the caller's CI to determine how much stack to copy, then copies the caller's stack before calling the callee.
The CI at the forwarded call site is adjusted using information from the caller's CI.

I think this description is kind of confusing, so let's walk through an example with code.

```ruby
def delegatee(a, b) = a + b

def delegator(...)
  delegatee(...)  # CI2 (FORWARDING)
end

def caller
  delegator(1, 2) # CI1 (argc: 2)
end
```

Before we call the delegator method, the stack looks like this:

```
Executing Line | Code                                  | Stack
---------------+---------------------------------------+--------
              1| def delegatee(a, b) = a + b           | self
              2|                                       | 1
              3| def delegator(...)                    | 2
              4|   #                                   |
              5|   delegatee(...)  # CI2 (FORWARDING)  |
              6| end                                   |
              7|                                       |
              8| def caller                            |
          ->  9|   delegator(1, 2) # CI1 (argc: 2)     |
             10| end                                   |
```

The ISeq for `delegator` is tagged as "forwardable", so when `caller` calls in
to `delegator`, it writes `CI1` on to the stack as a local variable for the
`delegator` method.  The `delegator` method has a special local called `...`
that holds the caller's CI object.

Here is the ISeq disasm fo `delegator`:

```
== disasm: #<ISeq:delegator@-e:1 (1,0)-(1,39)>
local table (size: 1, argc: 0 [opts: 0, rest: -1, post: 0, block: -1, kw: -1@-1, kwrest: -1])
[ 1] "..."@0
0000 putself                                                          (   1)[LiCa]
0001 getlocal_WC_0                          "..."@0
0003 send                                   <calldata!mid:delegatee, argc:0, FCALL|FORWARDING>, nil
0006 leave                                  [Re]
```

The local called `...` will contain the caller's CI: CI1.

Here is the stack when we enter `delegator`:

```
Executing Line | Code                                  | Stack
---------------+---------------------------------------+--------
              1| def delegatee(a, b) = a + b           | self
              2|                                       | 1
              3| def delegator(...)                    | 2
           -> 4|   #                                   | CI1 (argc: 2)
              5|   delegatee(...)  # CI2 (FORWARDING)  | cref_or_me
              6| end                                   | specval
              7|                                       | type
              8| def caller                            |
              9|   delegator(1, 2) # CI1 (argc: 2)     |
             10| end                                   |
```

The CI at `delegatee` on line 5 is tagged as "FORWARDING", so it knows to
memcopy the caller's stack before calling `delegatee`.  In this case, it will
memcopy self, 1, and 2 to the stack before calling `delegatee`.  It knows how much
memory to copy from the caller because `CI1` contains stack size information
(argc: 2).

Before executing the `send` instruction, we push `...` on the stack.  The
`send` instruction pops `...`, and because it is tagged with `FORWARDING`, it
knows to memcopy (using the information in the CI it just popped):

```
== disasm: #<ISeq:delegator@-e:1 (1,0)-(1,39)>
local table (size: 1, argc: 0 [opts: 0, rest: -1, post: 0, block: -1, kw: -1@-1, kwrest: -1])
[ 1] "..."@0
0000 putself                                                          (   1)[LiCa]
0001 getlocal_WC_0                          "..."@0
0003 send                                   <calldata!mid:delegatee, argc:0, FCALL|FORWARDING>, nil
0006 leave                                  [Re]
```

Instruction 001 puts the caller's CI on the stack.  `send` is tagged with
FORWARDING, so it reads the CI and _copies_ the callers stack to this stack:

```
Executing Line | Code                                  | Stack
---------------+---------------------------------------+--------
              1| def delegatee(a, b) = a + b           | self
              2|                                       | 1
              3| def delegator(...)                    | 2
              4|   #                                   | CI1 (argc: 2)
           -> 5|   delegatee(...)  # CI2 (FORWARDING)  | cref_or_me
              6| end                                   | specval
              7|                                       | type
              8| def caller                            | self
              9|   delegator(1, 2) # CI1 (argc: 2)     | 1
             10| end                                   | 2
```

The "FORWARDING" call site combines information from CI1 with CI2 in order
to support passing other values in addition to the `...` value, as well as
perfectly forward splat args, kwargs, etc.

Since we're able to copy the stack from `caller` in to `delegator`'s stack, we
can avoid allocating objects.

I want to do this to eliminate object allocations for delegate methods.
My long term goal is to implement `Class#new` in Ruby and it uses `...`.

I was able to implement `Class#new` in Ruby
[here](https://github.com/ruby/ruby/pull/9289).
If we adopt the technique in this patch, then we can optimize allocating
objects that take keyword parameters for `initialize`.

For example, this code will allocate 2 objects: one for `SomeObject`, and one
for the kwargs:

```ruby
SomeObject.new(foo: 1)
```

If we combine this technique, plus implement `Class#new` in Ruby, then we can
reduce allocations for this common operation.

Co-Authored-By: John Hawthorn <john@hawthorn.email>
Co-Authored-By: Alan Wu <XrXr@users.noreply.github.com>
2024-06-18 09:28:25 -07:00
Stan Lo
921f22e563 [ruby/irb] Improve how command calls' return value is handled
(https://github.com/ruby/irb/pull/972)

In #934, we changed command calls to return nil only. This PR improves
the behaviour even further by:

- Not echoing the `nil` returned by command calls
- Not overriding previous return value stored in `_` with the
  `nil` from commands

c844176842
2024-06-18 15:15:23 +00:00
tomoya ishida
c2e2c5975d [ruby/reline] Fix vi_yank or vi_delete_meta copies nil bug
(https://github.com/ruby/reline/pull/726)

46b30b07c9
2024-06-18 14:57:19 +00:00
Alexey Schepin
a3930db275 [rubygems/rubygems] Delete extra spaces left after rubocop autofix
a552732bed
2024-06-18 01:52:04 +00:00
Yuta Saito
d914192012 [rubygems/rubygems] Use symbol for option key in Bundler::CLI::Install
07a5faeb89
2024-06-18 00:59:37 +00:00
Yuta Saito
97a23db5ac [rubygems/rubygems] Disable install_extension_in_lib when cross-compiling
643e154f32
2024-06-18 00:59:36 +00:00
Yuta Saito
3e4b694565 [rubygems/rubygems] Bundler integration for --target-rbconfig option
f9fb413a19
2024-06-18 00:59:36 +00:00
Yuta Saito
273d41b9e3 [rubygems/rubygems] Add --target-rbconfig option to gem install and gem update commands
This patch adds `--target-rbconfig` option to specify the rbconfig.rb file
for the deployment target platform. This is useful when cross-compiling
gems. At the moment, this option is only available for `extconf.rb`-based
extensions.

cf2843f7a2
2024-06-18 00:59:35 +00:00
Stan Lo
ce6a1ba9a1 [ruby/irb] Bump version to v1.13.2
(https://github.com/ruby/irb/pull/970)

35de7dacd4
2024-06-15 20:14:01 +00:00
David Rodríguez
4d73f3f9eb [rubygems/rubygems] Fix funding metadata not being printed in some situations
Namely, when a gem has not previously been installed, and Bundler is
using the compact index API, fund metadata was not getting printed
because the proper delegation was not implemented in the specification
class used by the compact index.

9ef5139f60
2024-06-14 14:27:02 +00:00
David Rodríguez
6a474ef266 [rubygems/rubygems] Don't print bug report template when bin dir is not writable
f4ce3aae71
2024-06-14 10:05:20 +00:00
David Rodríguez
62fc473224 [rubygems/rubygems] Never remove executables that may belong to a default gem
ed585f2fca
2024-06-14 08:02:38 +00:00
Dmitry Ukolov
8ddb4de0ac
Fixed indents in recently RJIT patch (#11001) 2024-06-14 00:05:21 -07:00
Dmitry Ukolov
b988ae3a06
RJIT: Fixed and/or reg+disp32 operations (#10856)
Fixed RJIT `and reg+disp32` and `or reg+disp32` operation.
2024-06-13 15:55:01 -07:00
David Rodríguez
c2f8e91815 [rubygems/rubygems] Also disambiguate gems not in the first Gem.path position
7e6e7ccc58
2024-06-13 14:25:14 +00:00
David Rodríguez
5c573b7652 [rubygems/rubygems] Fix default gem priority when sorting specs
8dbe1dbdc7

Co-authored-by: MSP-Greg <Greg.mpls@gmail.com>
2024-06-13 14:25:14 +00:00
Mari Imaizumi
006ff5e29f [ruby/reline] Bump version to 0.5.9
(https://github.com/ruby/reline/pull/724)

aff1d852bb
2024-06-12 14:23:18 +00:00
David Rodríguez
6b6fd16219 [rubygems/rubygems] Fix typo
19a0e3730c
2024-06-12 12:46:06 +00:00
David Rodríguez
568132af16 [rubygems/rubygems] Keep credentials in lockfile if they are already there
So that those lockfiles still work with older Bundler versions.

880275bb66
2024-06-11 16:27:44 +00:00
David Rodríguez
3e84da0970 [rubygems/rubygems] Auto switch to locked bundler version even when using binstubs
076aba8b1c
2024-06-11 13:30:50 +00:00
Kevin Newton
d827d32527 [ruby/prism] Provide ability to lock encoding while parsing
f7faedfb3f
2024-06-10 17:21:32 -04:00
tomoya ishida
1d0d8a89d4 [ruby/reline] Add more fallbacks when terminfo is not available
(https://github.com/ruby/reline/pull/722)

Add xterm key bindings to comprehensive list
Add fallback escape sequence of cursor hide/show

e3c73bbe26
2024-06-10 15:31:33 +00:00
tomoya ishida
e8bd745c17 [ruby/reline] Suppress warning(Ruby 3.4) requiring fiddle from
terminfo.rb
(https://github.com/ruby/reline/pull/721)

9da2cbcd82
2024-06-10 13:57:28 +00:00
Kevin Newton
c90b5303a2
Sync prism version to latest 2024-06-07 15:54:06 -04:00
Kevin Newton
41a36b6853 [ruby/prism] Handle chomped bytesize with lines without newlines
1528d3c019
2024-06-07 19:46:27 +00:00
Kevin Newton
79e9dea8de [ruby/prism] Ensure inner heredoc nodes have the correct location
100340bc6b
2024-06-07 19:46:20 +00:00
Kevin Newton
ce0a352e34 [ruby/prism] Use correct newlines for heredoc inner lines
4a9a7a62af

Co-authored-by: Jason Kim <jasonkim@github.com>
Co-authored-by: Adam Hess <HParker@github.com>
2024-06-07 19:46:16 +00:00
Kevin Newton
51bb5dcd2e [ruby/error_highlight] Trim trailing spaces in base.rb
8ce3f6f145
2024-06-07 13:28:23 +00:00
Kevin Newton
40ec860de7 [ruby/error_highlight] Support for the prism compiler
69fbacfd49
2024-06-07 13:15:14 +00:00
David Rodríguez
0fb73a8eda [rubygems/rubygems] Avoid appending a final "/" when fallback_timeout is used in config
a0af1baa2b
2024-06-06 18:53:31 +00:00
David Rodríguez
765d61593a [rubygems/rubygems] Remove per uri options constant
I don't think we should add more of these.

9eee9948cc
2024-06-06 18:53:30 +00:00
David Rodríguez
82b68bc358 [rubygems/rubygems] Move Bundler settings specific logic to Bundler
7d1e8be2ce
2024-06-06 18:53:29 +00:00
David Rodríguez
da10d1ddea [rubygems/rubygems] Avoid is_a? check before using normalize_uri
31cb15d03f
2024-06-06 18:53:28 +00:00
David Rodríguez
60620509f4 [rubygems/rubygems] Remove unnecessary .to_s
The `normalize_uri` method always gives back a String.

246953010c
2024-06-06 18:53:27 +00:00
David Rodríguez
61a80bd10d [rubygems/rubygems] Truly ignore commented out settings
e31df2d6ef
2024-06-06 18:53:25 +00:00
David Rodríguez
c8161a4eae [rubygems/rubygems] Autoload pathname at the top level
Otherwise Ruby >= 3.2 gives a warning which makes several specs fail,
and truffleruby rejects it at all.

ae2878484f
2024-06-06 18:44:35 +00:00
tomoya ishida
f465045dd6 [ruby/reline] Remove instance variable @first_char
(https://github.com/ruby/reline/pull/717)

When Reline reads EOF, Reline.readline should return nil if and only if input is empty

cc74b3686a
2024-06-06 11:20:29 +00:00
Baron Bloomer
d4aff75a45 [ruby/logger] Add support for symbols in #shift_age
Resolves issue: https://github.com/ruby/logger/issues/46

83502c2107
2024-06-06 09:07:49 +00:00
Kevin Newton
ac70dd07e6 [ruby/prism] Remove unused string list struct
36c6851c85
2024-06-05 14:40:03 -04:00
Stan Lo
aa61d4237d [ruby/irb] Add accidentally dropped disable_irb command back
(https://github.com/ruby/irb/pull/964)

* Add accidentally dropped disable_irb command back

* Sort command files require by name

1d627cebca
2024-06-05 16:29:29 +00:00
Hiroshi SHIBATA
d7e558e3c4
Mark to warn logger as bundled gems for Ruby 3.5 2024-06-05 17:26:50 +09:00
Jean Boussier
f8abd24b1f Improve YJIT performance warning regression test
[Bug #20522]
2024-06-05 09:22:15 +02:00