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

2038 Коммитов

Автор SHA1 Сообщение Дата
David Rodríguez 4df7c3946a [rubygems/rubygems] Remove one fallback to full indexes on big gemfiles
If Gemfile has a lot of dependencies, we have an optimization that uses
the full index in that case, assuming it's going to be faster.

I think this is an old optimization that predates compact index API
times, I believe we no longer need it these days.

Also, since a few releases ago we check for circular dependencies when
resolving by looping through all versions of each name and removing
those that have circular dependencies that would trip up the resolver.

This loop becomes actually very slow when full indexes are used because
to find dependencies of a gemspec, we need to explicitly fetch the
marshaled gemspec (`gemspec.rz` endpoint) for it, so the optimization
has the opposite effect of making things very slow.

https://github.com/rubygems/rubygems/commit/2f46289bd3
2023-04-07 13:53:00 +00:00
Nobuyoshi Nakada e13575bb79
[Bug #19584] Register global variables before assignment 2023-04-07 11:53:36 +09:00
Hiroshi SHIBATA 6ca1f3eec4
Load only SyntaxSuggest::VERSION for version check 2023-04-06 16:15:41 +09:00
schneems 7ab640d9dd
v1.0.4 2023-04-06 15:49:26 +09:00
schneems 8d72d6159c
v1.0.3
Fix a CI error and add a test to ensure we're testing the current version:

```
Run bundle exec rake test
bundler: failed to load command: rake (/home/runner/work/syntax_suggest/syntax_suggest/vendor/bundle/ruby/3.2.0/bin/rake)
/opt/hostedtoolcache/Ruby/3.2.1/x64/lib/ruby/gems/3.2.0/gems/bundler-2.3.14/lib/bundler/runtime.rb:309:in `check_for_activated_spec!': You have already activated syntax_suggest 1.0.2, but your Gemfile requires syntax_suggest 1.0.3. Since syntax_suggest is a default gem, you can either remove your dependency on it or try updating to a newer version of bundler that supports syntax_suggest as a default gem. (Gem::LoadError)
	from /opt/hostedtoolcache/Ruby/3.2.1/x64/lib/ruby/gems/3.2.0/gems/bundler-2.3.14/lib/bundler/runtime.rb:25:in `block in setup'
	from /opt/hostedtoolcache/Ruby/3.2.1/x64/lib/ruby/gems/3.2.0/gems/bundler-2.3.14/lib/bundler/spec_set.rb:138:in `each'
	from /opt/hostedtoolcache/Ruby/3.2.1/x64/lib/ruby/gems/3.2.0/gems/bundler-2.3.14/lib/bundler/spec_set.rb:138:in `each'
	from /opt/hostedtoolcache/Ruby/3.2.1/x64/lib/ruby/gems/3.2.0/gems/bundler-2.3.14/lib/bundler/runtime.rb:24:in `map'
	from /opt/hostedtoolcache/Ruby/3.2.1/x64/lib/ruby/gems/3.2.0/gems/bundler-2.3.14/lib/bundler/runtime.rb:24:in `setup'
	from /opt/hostedtoolcache/Ruby/3.2.1/x64/lib/ruby/gems/3.2.0/gems/bundler-2.3.14/lib/bundler.rb:151:in `setup'
	from /opt/hostedtoolcache/Ruby/3.2.1/x64/lib/ruby/gems/3.2.0/gems/bundler-2.3.14/lib/bundler/setup.rb:20:in `block in <top (required)>'
	from /opt/hostedtoolcache/Ruby/3.2.1/x64/lib/ruby/gems/3.2.0/gems/bundler-2.3.14/lib/bundler/ui/shell.rb:136:in `with_level'
	from /opt/hostedtoolcache/Ruby/3.2.1/x64/lib/ruby/gems/3.2.0/gems/bundler-2.3.14/lib/bundler/ui/shell.rb:88:in `silence'
	from /opt/hostedtoolcache/Ruby/3.2.1/x64/lib/ruby/gems/3.2.0/gems/bundler-2.3.14/lib/bundler/setup.rb:20:in `<top (required)>'
	from /opt/hostedtoolcache/Ruby/3.2.1/x64/lib/ruby/gems/3.2.0/gems/bundler-2.3.14/lib/bundler/cli/exec.rb:56:in `require_relative'
	from /opt/hostedtoolcache/Ruby/3.2.1/x64/lib/ruby/gems/3.2.0/gems/bundler-2.3.14/lib/bundler/cli/exec.rb:56:in `kernel_load'
	from /opt/hostedtoolcache/Ruby/3.2.1/x64/lib/ruby/gems/3.2.0/gems/bundler-2.3.14/lib/bundler/cli/exec.rb:23:in `run'
	from /opt/hostedtoolcache/Ruby/3.2.1/x64/lib/ruby/gems/3.2.0/gems/bundler-2.3.14/lib/bundler/cli.rb:483:in `exec'
	from /opt/hostedtoolcache/Ruby/3.2.1/x64/lib/ruby/gems/3.2.0/gems/bundler-2.3.14/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
```
2023-04-06 15:47:04 +09:00
schneems 63ea6b0cf2 [ruby/syntax_suggest] Rollback comment indentation behavior
Originally I fixed https://github.com/ruby/syntax_suggest/pull/177 by making the process of comment removal indentation aware. The next commit is the more general fix and means we don't need to carry that additional logic/overhead.

Also: Update syntax via linter
2023-04-06 15:45:29 +09:00
schneems 2acbcec056 [ruby/syntax_suggest] Add comments and refactor AroundBlockScan methods
https://github.com/ruby/syntax_suggest/commit/cecd12292c
2023-04-06 15:45:29 +09:00
schneems 5487ee4fe8 [ruby/syntax_suggest] Fix sibling bug to #177
While #177 is reported as being caused by a comment, the underlying behavior is a problem due to the newline that we generated (from a comment). The prior commit fixed that problem by preserving whitespace before the comment. That guarantees that a block will form there from the frontier before it will be expanded there via a "neighbors" method. Since empty lines are valid ruby code, it will be hidden and be safe.

## Problem setup

This failure mode is not fixed by the prior commit, because the indentation is 0. To provide good results, we must make the algorithm less greedy. One heuristic/signal to follow is developer added newlines. If a developer puts a newline between code, it's more likely they're unrelated. For example:

```
port = rand(1000...9999)
stub_request(:any, "localhost:#{port}")

query = Cutlass::FunctionQuery.new(
  port: port
).call

expect(WebMock).to have_requested(:post, "localhost:#{port}").
  with(body: "{}")
```

This code is split into three chunks by the developer. Each are likely (but not guaranteed) to be intended to stand on their own (in terms of syntax). This behavior is good for scanning neighbors (same indent or higher) within a method, but bad for parsing neighbors across methods.

## Problem

Code is expanded to capture all neighbors, and then it decreases indent level which allows it to capture surrounding scope (think moving from within the method to also capturing the `def/end` definition. Once the indentation level has been increased, we go back to scanning neighbors, but now neighbors also contain keywords.

For example:

```
  1 def bark
  2
  3 end
  4
  5 def sit
  6 end
```

In this case if lines 4, 5, and 6 are in a block when it tries to expand neighbors it will expand up. If it stops after line 2 or 3 it may cause problems since there's a valid kw/end pair, but the block will be checked without it.

TLDR; It's good to stop scanning code after hitting a newline when you're in a method...it causes a problem scanning code between methods when everything inside of one of the methods is an empty line.

In this case it grabs the end on line 3 and since the problem was an extra end, the program now compiles correctly. It incorrectly assumes that the block it captured was causing the problem.

## Extra bit of context

One other technical detail is that after we've decided to stop scanning code for a new neighbor block expansion, we look around the block and grab any empty newlines. Basically adding empty newlines before of after a code block do not affect the parsing of that block.

## The fix

Since we know that this problem only happens when there's a newline inside of a method and we know this particular failure mode is due to having an invalid block (capturing an extra end, but not it's keyword) we have all the metadata we need to detect this scenario and correct it.

We know that the next line above our block must be code or empty (since we grabbed extra newlines). Same for code below it. We can count all the keywords and ends in the block. If they are balanced, it's likely (but not guaranteed) we formed the block correctly. If they're imbalanced, look above or below (depending on the nature of the imbalance), check to see if adding that line would balance the count.

This concept of balance and "leaning" comes from work in https://github.com/ruby/syntax_suggest/pull/152 and has proven useful, but not been formally introduced into the main branch.

## Outcome

Adding this extra check introduced no regressions and fixed the test case. It might be possible there's a mirror or similar problem that we're not handling. That will come out in time. It might also be possible that this causes a worse case in some code not under test. That too would come out in time.

One other possible concern to adding logic in this area (which is a hot codepath), is performance. This extra count check will be performed for every block. In general the two most helpful performance strategies I've found are reducing total number of blocks (therefore reducing overall N internal iterations) and making better matches (the parser to determine if a close block is valid or not is a major bottleneck. If we can split valid code into valid blocks, then it's only evaluated by the parser once, where as invalid code must be continuously re-checked by the parser until it becomes valid, or is determined to be the cause of the core problem.

This extra logic should very rarely result in a change, but when it does it should tend to produce slightly larger blocks (by one line) and more accurate blocks.

Informally it seems to have no impact on performance:

``
This branch:
DEBUG_DISPLAY=1 bundle exec rspec spec/ --format=failures  3.01s user 1.62s system 113% cpu 4.076 total
```

```
On main:
DEBUG_DISPLAY=1 bundle exec rspec spec/ --format=failures  3.02s user 1.64s system 113% cpu 4.098 total
```

https://github.com/ruby/syntax_suggest/commit/13739c6946
2023-04-06 15:45:28 +09:00
schneems e5236471c3 [ruby/syntax_suggest] Preserve whitespace in front of comments
When removing comments I previously replaced them with a newline. This loses some context and may affect the order of the indent search which in turn affects the final result. By preserving whitespace in front of the comment, we preserve the "natural" indentation order of the line while also allowing the parser/lexer to see and join naturally consecutive (method chain) lines.

close https://github.com/ruby/syntax_suggest/pull/177
2023-04-06 15:45:28 +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.

https://github.com/rubygems/rubygems/commit/4ca72913bb
2023-04-06 13:07:16 +09:00
Aaron Patterson 8525603c72
Revert "Fix transient heap mode"
This reverts commit 87253d047c.

Revert "Implement `Process.warmup`"

This reverts commit ba6ccd8714.
2023-04-04 12:59:14 -07:00
Jean Boussier ba6ccd8714 Implement `Process.warmup`
[Feature #18885]

For now, the optimizations performed are:

  - Run a major GC
  - Compact the heap
  - Promote all surviving objects to oldgen

Other optimizations may follow.
2023-04-04 19:49:08 +02:00
Josef Šimánek 9cfd8330ca [rubygems/rubygems] Onboard Rubocop Naming/MemoizedInstanceVariableName rule to Bundler.
https://github.com/rubygems/rubygems/commit/d768be0c65
2023-03-28 15:25:44 +09:00
David Rodríguez 4d4743f7e3 [rubygems/rubygems] Fix installing plugins in frozen mode
Plugins don't use a lockfile, so ignore frozen related settings.

https://github.com/rubygems/rubygems/commit/f17a3bb81f
2023-03-28 15:25:42 +09:00
David Rodríguez 674c960513 [rubygems/rubygems] Fix incorrect removal of "ruby" platform from lockfile
When dependencies have changed, we'll be re-resolving, and we can't
really know whether the resolution will be valid or invalid for the Ruby
platform, so skip the removal in that case.

The fix worked, but made some other specs fail, and surfaced that the
`@dependencies_changed` attribute was actually being incorrect set when
explicitly unlocking. Fixed that with an early return.

https://github.com/rubygems/rubygems/commit/20d8f5e5d9
2023-03-28 15:25:42 +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.

https://github.com/rubygems/rubygems/commit/7f55ed8302
2023-03-28 15:25:41 +09:00
Michael Siegfried b31bd8b853 [rubygems/rubygems] Rewrite GemVersionPromoter specs
Add tests for pre, move more of the setup into a helper method, and
restructure tests.

There seem to be five considerations for these tests (level, pre, strict,
locked, and whether the current version is a prerelease version, though
the last one overlaps with pre and didn't seem to behave how I expected
under test). Rather than write out the 16 (/32 if the last consideration
is real) combinations, I wrote most with independent tests for each
value. The existing combined tests were maintained (level vs strict)
because these seem the most interrelated.

https://github.com/rubygems/rubygems/commit/74c23a91b2
2023-03-28 01:18:49 +00:00
Jeremy Evans 6c60006de5 Raise ArgumentError if IO.read is provided negative offset
Fixes [Bug #19380]
2023-03-24 12:29:00 -07:00
Jeremy Evans 466ca7ae20 Add Dir.fchdir
This is useful for passing directory file descriptors over UNIX
sockets or to child processes to avoid TOCTOU vulnerabilities.

The implementation follows the Dir.chdir code.

This will raise NotImplementedError on platforms not supporting
both fchdir and dirfd.

Implements [Feature #19347]
2023-03-24 11:18:57 -07:00
Jeremy Evans 5d6579bd91 Change Hash#compact to keep default values and compare_by_identity flag
The documentation states it returns a copy of self with nil value
entries removed.  However, the previous behavior was creating a
plain new hash with non-nil values copied into it.  This change
aligns the behavior with the documentation.

Fixes [Bug #19113]
2023-03-24 10:55:13 -07:00
Jeremy Evans 1b13db25d8 Copy compare_by_identity flag for empty hashes in Hash.ruby2_keywords_hash
This was already copied for non-empty hashes.  As Hash.ruby2_keywords_hash
copies default values, it should also copy the compare_by_identity flag.

Partially Fixes [Bug #19113]
2023-03-24 10:55:13 -07:00
Jeremy Evans d3197def88 Do not copy compare_by_identity flag for non-empty hashes in Hash.[]
It wasn't copied for empty hashes, and Hash.[] doesn't copy the
default value, so copying the compare_by_identity flag does not
make sense.

Partially Fixes [Bug #19113]
2023-03-24 10:55:13 -07:00
David Rodríguez a9146bd81e Don't suggest `--full-index` on API Response mismatch errors
I've never seen this error in real life, and if it was happening, I
think it's either some server side issue that would need to be fixed or
some transient issue. We should move away from the full index, since
it's slow, so let's stop recommending it.
2023-03-23 17:18:49 +09:00
David Rodríguez 164dc58008 Fix logging the fallback to the full index on GemspecError's
The debug message suggests retrying using `--full-index`, but the retry
is happening automatically. Just log that we are falling back to the
full index, like we do with other errors.
2023-03-23 17:18:49 +09:00
David Rodríguez 8e6bbc032c Don't remove RUBY platform when healing a lockfile with missing specs 2023-03-23 17:18:49 +09:00
David Rodríguez 4e7c39f98c Don't remove RUBY platform when healing a lockfile with missing specs 2023-03-23 17:18:49 +09:00
Nobuyoshi Nakada 348412c7fa [rubygems/rubygems] Use indented heredoc
https://github.com/rubygems/rubygems/commit/085d2776d8
2023-03-22 21:21:08 +00:00
Hiroshi SHIBATA 8d1109c03b
Added assertion values for Amazon Linux 2023 2023-03-22 16:10:06 +09:00
David Rodríguez c65d7b4bea When running `bundle lock --update <name>`, checkout locked revision of unrelated git sources directly
Since Bundler 2.4, we will try to checkout any branch specified in the
Gemfile, while until Bundler 2.3 we would directly checkout the locked
revision.

This should not make any difference in most situations, but in some edge
cases, like if the branch specified in the `Gemfile` has been renamed,
but the locked revision still exist, it causes an error now while before
it would update the lockfile without issues.

I debated which behavior was best, since I was not sure. But my
conclusion is that if the situation does not require expiring the
lockfile source in favor of the Gemfile source, we should use the locked
revision directly and proceed happily. So I restored Bundler 2.3
behavior.

I think this is consistent with how yanked gems are handled, for example.

Of course, if explicitly updating the git source itself, or all gems, we
will still get any errors like missing branches related to the git source.
2023-03-17 18:50:55 +09:00
David Rodríguez 0b9e51c429 Don´t consider platform specific candidates when `force_ruby_platform` set
This was working fine for direct dependencies using
`force_ruby_platform` explicitly through Gemfile, but not for indirect
dependencies. In general, indirect dependencies do not have this
property set, but in truffleruby this is different and the default value
is to have it set.
2023-03-17 18:50:55 +09:00
David Rodríguez 12f0be14e2 Don't ignore pre-releases when there's only one candidate
This should be a very rare edge case, however, it does happen when using
a .dev version of Bundler because in that case, that's the only version
that the resolver considers, and it should not be ignored.

We could've special cased this specifically for Bundler, but I think it
does make sense for every gem.
2023-03-17 18:50:55 +09:00
David Rodríguez ddc4fd5644 Normalize git sources
Just like gem sources, a "style-only" change, like adding a trailing
slash, should not expire them.
2023-03-17 18:50:55 +09:00
David Rodríguez 8371c0eac4 [rubygems/rubygems] Fix incorrect error message when multiple platforms are locked
https://github.com/rubygems/rubygems/commit/24d2bf9cb2
2023-03-17 18:50:55 +09:00
David Rodríguez d5121992dc [rubygems/rubygems] Remove unnecessary `specific_local_platform` test helper
https://github.com/rubygems/rubygems/commit/86b574824d
2023-03-17 18:50:55 +09:00
David Rodríguez 2d8b55fcd2 [rubygems/rubygems] Simplify `lockfile_platforms` helper
To make it easier to change the default platforms that get locked later.

https://github.com/rubygems/rubygems/commit/255c4012ec
2023-03-17 18:50:55 +09:00
David Rodríguez 9492efbe71 [rubygems/rubygems] Remove unnecessary `local` helper
https://github.com/rubygems/rubygems/commit/27ed6870ce
2023-03-17 18:50:55 +09:00
David Rodríguez 8a8ade7e5e [rubygems/rubygems] Use more common linux platform for specs
https://github.com/rubygems/rubygems/commit/3841a58095
2023-03-17 18:50:55 +09:00
David Rodríguez f22765f535 [rubygems/rubygems] Use splatted args to `lockfile_platforms_for`
Nicer :)

https://github.com/rubygems/rubygems/commit/c0ab2893c3
2023-03-17 18:50:55 +09:00
Hiroshi SHIBATA f3b129241c [rubygems/rubygems] Applied Layout/SpaceAroundOperators cop
https://github.com/rubygems/rubygems/commit/3139587be9
2023-03-16 01:59:12 +00:00
Hiroshi SHIBATA 56b38fdd69 [rubygems/rubygems] Use OpenSSL::Digest instead of digest stdlib
https://github.com/rubygems/rubygems/commit/69aa007679
2023-03-15 11:21:22 +00:00
Jean Boussier ca437aeb39 rb_ary_sum: don't enter fast path if initial isn't a native numeric type.
[Bug #19530]

If the initial value isn't one of the special cased types, we directly
jump to the slow path.
2023-03-15 09:12:59 +00:00
Ian Ker-Seymer dd47ce10db [rubygems/rubygems] Use `RbSys::ExtensionTask` when creating new rust gems
https://github.com/rubygems/rubygems/commit/125f9fece9
2023-03-10 11:50:06 +00:00
Samuel Williams 86d38b4520
Accept `sleep(nil)` as sleep forever. (#7484) 2023-03-10 16:40:05 +13:00
Nobuyoshi Nakada dc1e6573f2
Fix commit miss 2023-03-09 00:49:11 +09:00
Nobuyoshi Nakada 611a64250a
Disable color mode of test-syntax-suggest when on dumb terminal
The compliation-mode of Emacs sets TERM to "dumb" and does not support
coloring.
2023-03-08 22:57:06 +09:00
Julie Haehn c5296d9396 [rubygems/rubygems] Respect --no-install option for git: sources
Currently, the --no-install option to `bundle package` is totally
ignored for git sources. This can have very strange effects if you have:

- a git-sourced gem,
- with native extensions,
- whose extconf.rb script depends on another gem,
- which is installed from Rubygems in the gemfile.

In that circumstance, `bundle package --no-install --all` will download
the Rubygems dependencies to `vendor/cache` but NOT install them. It
will also check out the git gems to `vendor/cache` (good), and attempt
to build their native extensions (bad!).

The native extension build will fail because the extconf.rb script crashes,
since the dependency it needs is missing.

I implemented a fix for this in `source/git.rb`, since this is analogous
to what's happening in `source/rubygems.rb`. I do admit though the whole
thing is a little strange though - an "install" method that.... proceeds
to look at a global flag to not install anything.

Add test to confirm cache respects the --no-install flag

https://github.com/rubygems/rubygems/commit/5a77d1c397

Co-authored-by: KJ Tsanaktsidis <kj@kjtsanaktsidis.id.au>
2023-03-07 22:36:36 +00:00
David Rodríguez 72591eb73f [rubygems/rubygems] Better suggestion when `bundler/setup` fails due to missing gems
If the original `BUNDLE_GEMFILE` is different from the default, then the
suggestion wouldn't work as is.

Before:

```
$ util/rubocop
Could not find rubocop-1.30.1 in locally installed gems
Run `bundle install` to install missing gems.

$  rubygems git:(better-cmd-suggestion) ✗ bundle install
Could not locate Gemfile
```

After:

```
$ util/rubocop
Could not find rubocop-1.30.1 in locally installed gems
Run `bundle install --gemfile /path/to/rubygems/bundler/tool/bundler/lint_gems.rb` to install missing gems.

$ bundle install --gemfile /path/to/rubygems/bundler/tool/bundler/lint_gems.rb
Fetching gem metadata from https://rubygems.org/.........
Using ast 2.4.2
Using bundler 2.4.7
Using parser 3.1.2.0
Using rainbow 3.1.1
Using parallel 1.22.1
Using regexp_parser 2.5.0
Using rubocop-ast 1.18.0
Using rexml 3.2.5
Using ruby-progressbar 1.11.0
Using unicode-display_width 2.1.0
Fetching rubocop 1.30.1
Installing rubocop 1.30.1
Using rubocop-performance 1.14.2
Bundle complete! 2 Gemfile dependencies, 12 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.

$ util/rubocop
Inspecting 345 files
.........................................................................................................................................................................................................................................................................................................................................................

345 files inspected, no offenses detected
```

https://github.com/rubygems/rubygems/commit/bf1320d805
2023-03-07 16:51:36 +09:00
Takashi Kokubun 23ec248e48 s/mjit/rjit/ 2023-03-06 23:44:01 -08:00
Takashi Kokubun 2e875549a9 s/MJIT/RJIT/ 2023-03-06 23:44:01 -08:00
johnnyshields 79ede4ae99 [rubygems/rubygems] Alias CurrentRuby#mswin?, mswin64?, mingw?, x64_mingw? to #windows?. (This is done instead of logging a deprecation warning.)
https://github.com/rubygems/rubygems/commit/b9fcc7c0ab
2023-03-03 09:50:29 +00:00