Commit graph

55 commits

Author SHA1 Message Date
David Rodríguez
e42f1aaa5a [rubygems/rubygems] Fix truffleruby failing to install sorbet-static when there's no lockfile
The generic Ruby platform was getting unconditionally added in
truffleruby, preventing resolution in situations where there's no
generic ruby version (sorbet-static). Instead, the generic platform
should be considered per dependency, not globally.

a96afc5351
2025-07-30 11:19:26 +09:00
Samuel Giddins
c0a1e877b3
Move most of Bundler::GemHelpers to Gem::Platform
This will help centralize wheel platform selection logic eventually

Signed-off-by: Samuel Giddins <segiddins@segiddins.me>
2025-06-06 10:22:18 +09:00
Hartley McGuire
752a1d7854 [rubygems/rubygems] Implement pub_grub strategy interface
My application spends more than 30% of time during `bundle update`
comparing versions due to versions being sorted inside
next_package_to_try. This has been addressed in pub_grub by defining a
strategy interface (a `#next_package_and_version` method) which allows
consumers to have finer control over the heuristic to select the next
package to try.

This commit implements the new strategy interface to remove extraneous
version sorting (previously in next_package_to_try) since only the final
count of versions is used.

Combined with a previous change to pub_grub (already applied to
Bundler), this commit results in `bundle update` taking only half the
time it did on 2.6.5.

62f69e27f0
2025-03-27 13:57:26 +09:00
David Rodríguez
bb1b5877a7 [rubygems/rubygems] Consistently use "lockfile" over "lock file"
e891be9197
2025-03-24 13:25:07 +09:00
Hartley McGuire
8cc85dc00f [rubygems/rubygems] Remove array allocation from Candidate#<=>
In a large application I profiled allocations while running `bundle
update` and found that this method was ~60% of allocations while
resolving (and Candidate#<=> is almost half of the total runtime).

This commit removes the array allocation in Candidate#<=> (and similar
methods since the implementations are so simple). The array is always
the same two elements so they can just be compared directly.

6a7c411ba7
2025-03-13 10:24:21 +09:00
David Rodríguez
c77354157f [rubygems/rubygems] Fix locked gems being upgraded when locked dependencies are incorrect
Resolver had internal logic to prioritize locked versions when sorting
versions, however part of it was not being actually hit because of how
unlocking worked in the resolver: a package was allow to be unlocked
when that was explicit requested or when the list of unlocks was empty.
That did not make a lot of sense and other cases were working because
the explicit list of unlocks was getting "artificially filled".

Now we consider a package unlocked when explicitly requested (`bundle
update <package>`), or when everything is being unlocked (`bundle
install` with no lockfile or `bundle update`).

This makes things simpler and gets the edge case added as a test case
working as expected.

b8e55087f0
2025-02-18 12:12:51 +09:00
David Rodríguez
a1716e2365 [rubygems/rubygems] Move expanding dependencies with metadata to specification classes
7f921aa46e
2025-02-06 15:57:57 +09:00
David Rodríguez
24f5e3010f [rubygems/rubygems] Metadata dependencies can be Gem::Dependency instances
They use less memory that way.

When resolving from scratch a Gemfile including only `"gem "rails", "~>
8.0.1"`, I get the following results:

### Before

Total allocated: 265.06 MB (3186053 objects)
Total retained:  116.98 MB (1302280 objects)

### After

Total allocated: 262.99 MB (3177437 objects)
Total retained:  115.91 MB (1297821 objects)

a4ef9c5f56
2025-02-06 15:57:56 +09:00
David Rodríguez
7fed6c887d [rubygems/rubygems] Remove unnecessary remapping of dependencies
Sometimes we'll resolve using bare `Gem::Dependency` instances rather
than `Bundler::Dependency` instances, which is fine, simpler, and saves
some memory.

When resolving from scratch a Gemfile including only `"gem "rails", "~>
8.0.1"`, I get the following results:

### Before

Total allocated: 277.48 MB (3384318 objects)
Total retained:  117.53 MB (1338657 objects)

### After

Total allocated: 265.06 MB (3186053 objects)
Total retained:  116.98 MB (1302280 objects)

c6dc2966c5
2025-02-06 15:57:55 +09:00
David Rodríguez
0b1b8bc3ec [rubygems/rubygems] Don't remove platform specific variants from the lockfile unless necessary
Even if they don't match the current Ruby version, they could still work
in other rubies. So it's better to keep them.

9a3e583b0c
2025-01-14 12:24:37 +09:00
David Rodríguez
ae75c8877a [rubygems/rubygems] Extract SpecSet#version_for
a76fd6d3bf
2025-01-14 12:24:37 +09:00
David Rodríguez
2b91a56d40 [rubygems/rubygems] Remove no longer necessary code
9ea1539b08
2024-11-26 15:11:05 +09:00
David Rodríguez
e15921c694 [rubygems/rubygems] Create LazySpecifications directly with most_specific_locked_platform
So there's no need to pass it around in so many places.

784ab7481b
2024-11-26 15:11:05 +09:00
David Rodríguez
963f98a94f [rubygems/rubygems] Enable Performance/MapCompact cop
0c3a65871a
2024-11-26 15:11:05 +09:00
David Rodríguez
4addaaf4df [rubygems/rubygems] More aggressive Performance/FlatMap cop configuration
d8d68cc00e
2024-11-26 15:11:05 +09:00
David Rodríguez
def5fdf82a [rubygems/rubygems] Delay and refactor verification of changed sources
d5dce93167
2024-10-16 21:57:51 +00:00
David Rodríguez
2569413b1c [rubygems/rubygems] Fix --prefer-local flag
The original implementation of this flag was too naive and all it did
was restricting gems to locally installed versions if there are any
local versions installed.

However, it should be much smarter. For example:

* It should fallback to remote versions if locally installed version
  don't satisfy the requirements.
* It should pick locally installed versions even for subdependencies not
  yet discovered.

This commit fixes both issues by using a smarter approach similar to how
we resolve prereleases:

* First resolve optimistically using only locally installed gems.
* If any conflicts are found, scan those conflicts, allow remote
  versions for the specific gems that run into conflicts, and
  re-resolve.

607a3bf479

Co-authored-by: Gourav Khunger <gouravkhunger18@gmail.com>
2024-08-22 11:48:32 +00:00
David Rodríguez
140d8318db [rubygems/rubygems] Fix generic platform gems getting incorrectly removed when locked for a specific platform
If they are already in the lockfile as the most specific variant for a
platform, we shouldn't change that unless explicitly unlocking.

a901660498
2024-07-09 16:34:09 +00:00
David Rodríguez
dd05191bc3 [rubygems/rubygems] Resolve all platforms directly
Instead of having to do a complete pass after resolve.

To do this, we add to the ruby group all the platform specs with the
same dependencies as the ruby specs.

e50415f2a6
2024-07-09 16:34:08 +00:00
David Rodríguez
00acc70348 [rubygems/rubygems] Don't memoize sorted_spec_names
It's just for debugging and a simple method, so no need.

3230425a9a
2024-07-09 16:34:08 +00:00
David Rodríguez
086cde1651 [rubygems/rubygems] Instantiate Resolver::SpecGroup with explicit priority
e2c1bc1b6c
2024-07-09 16:34:07 +00:00
David Rodriguez
3ca0683529 [rubygems/rubygems] Fix typo
0ddf25e5aa
2024-04-01 15:03:23 +00:00
David Rodríguez
2755cb1b2f [rubygems/rubygems] Use modern hashes consistently
bb66253f2c
2023-12-07 22:29:33 +00:00
David Rodríguez
f273132bc0 [rubygems/rubygems] Extract builder to create a LazySpecification from full spec
957d3d9a7f
2023-11-13 11:06:10 +09:00
David Rodríguez
636b70d2a6 [rubygems/rubygems] Allow setting metadata on LazySpecification
This is a step forward towards eventually including metadata in the
lockfile.

56fc02b251
2023-11-13 11:06:10 +09:00
David Rodríguez
ea7cde64fb [rubygems/rubygems] Set LazySpecification dependencies directly
2462c8e04d
2023-11-13 11:06:10 +09:00
David Rodríguez
77ffa1a7c3 [rubygems/rubygems] Raise an error when top level dependency does not resolve under all locked platforms
25304f3e8d
2023-10-16 13:52:57 +09:00
David Rodríguez
f3d69bed62
[rubygems/rubygems] Fix resolver hangs when dealing with an incomplete lockfile
While working on locking multiple platforms by default, I got an
infinite resolution loop in one of our resolver specs.

The culprit ended up being that when dealing with lockfile specs with
incomplete dependencies (spec appears in lockfile, but its dependencies
don't), those specs were not being properly expired and that tripped up
resolution.

The issue for some reason only manifests when dealing with multiple
lockfile platforms, that's why it only manifested when working on
locking multiple platforms by default.

4ca72913bb
2023-04-06 13:07:16 +09:00
David Rodríguez
c257380965
Revert "Refactor incomplete specs handling"
This reverts commit 69580f8b72f41c58cae57d1ada4db909922b3891.
2023-04-06 13:07:16 +09:00
David Rodríguez
ed868f9a71 [rubygems/rubygems] Fix unnecessary downgrade of top level dependency when unlocking
Bundler is very conservative by default, trying to preserve versions
from the lockfile as possible, and never downgrading them. However, when
it runs into a resolution error, it still tries to find a valid
resolution.

This fallback behavior was too "brute-force" though, completely
unrestricting any gem found in the resolution conflict, and that could
lead to direct dependencies being downgraded in some edge cases.

Instead, unlock things a bit more carefully:

* First try unlocking fully pinned indirect dependencies, but leave a
  lower bound requirement in place to prevent downgrades.
* Then try unlocking any fully pinned dependency, also leaving a lower
  bound requirement in place.
* Finally completely unrestrict dependencies if nothing else worked.

7f55ed8302
2023-03-28 15:25:41 +09:00
David Rodríguez
ebebc90ec2 Refactor incomplete specs handling
Recent bugs fixed made me realize we were relying on state too much
here. We only need to keep incomplete specs to be able to expire them
and retry resolution without them locked. If we use a separate class, we
can do that more transparently and handle them just like we handle
"missing specs".
2023-03-23 17:18:49 +09:00
Hiroshi SHIBATA
d3822c9a8a Merge RubyGems/Bundler master.
Pick from 5ace20dbec
2023-01-31 10:49:08 +09:00
Hiroshi SHIBATA
a43f1d90c2 Merge RubyGems and Bundler master
from 0635c1423d
2023-01-10 15:53:07 +09:00
Hiroshi SHIBATA
a4e14b9d9d Merge RubyGems/Bundler master
Pick from 823c776d95
2022-12-09 16:36:22 +09:00
Hiroshi SHIBATA
0a9d51ee9d Migrate our resolver engine to PubGrub
https://github.com/rubygems/rubygems/pull/5960

  Co-authored-by: David Rodríguez <deivid.rodriguez@riseup.net>
2022-11-12 07:40:31 +09:00
Hiroshi SHIBATA
f5df47d1f3 Merge RubyGems/Bundler master
6214d00b23
2022-10-18 16:33:15 +09:00
David Rodríguez
56ad79694b [rubygems/rubygems] Simplify fetching spec group dependencies
62c2edd255
2022-10-18 16:33:15 +09:00
David Rodríguez
804ae4ea12 [rubygems/rubygems] Simplify SpecGroup creation
788e46e152
2022-10-18 16:33:15 +09:00
Hiroshi SHIBATA
3eca1e438d Merge 16c3535413 2022-09-05 14:37:12 +09:00
Hiroshi SHIBATA
f69244cee8 Merge rubygems/bundler HEAD
Pick from 6b3a5a9ab0
2022-08-23 10:45:57 +09:00
David Rodríguez
c21c9a29ee [rubygems/rubygems] Refactor building metadata dependencies
fa60f1fe43
2022-08-23 10:45:57 +09:00
Hiroshi SHIBATA
437a5ae9d6 Merge RubyGems and Bundler master 2022-07-13 14:11:55 +09:00
Hiroshi SHIBATA
1056489ea3 Merge 3f7d0352e8 2022-04-28 19:08:49 +09:00
Hiroshi SHIBATA
d22511fd75 Merge rubygems/rubygems HEAD.
Picked at 12aeef6ba9a3be0022be9934c1a3e4c46a03ed3a
2022-01-19 15:01:44 +09:00
David Rodríguez
5b0abba931 Sync bundler & rubygems 2021-05-11 11:29:41 +09:00
David Rodríguez
53468cc111 Sync latest development version of bundler & rubygems 2021-03-08 13:47:35 +09:00
Hiroshi SHIBATA
339227363c Merge RubyGems 3.2.3 and Bundler 2.2.3 2020-12-23 10:17:41 +09:00
Hiroshi SHIBATA
2fa9f3c032 Prepare to release rubygems-3.2.1 and bundler-2.2.1 2020-12-15 10:54:09 +09:00
Hiroshi SHIBATA
d386a58f6f Merge bundler-2.2.0.rc.2 2020-10-15 17:19:02 +09:00
Hiroshi SHIBATA
0e60b59d58 Update the bundler version with master branch 2020-05-13 07:54:37 +09:00