Commit graph

14676 commits

Author SHA1 Message Date
Samuel Giddins
485ee6d7a3
[rubygems/rubygems] Remove backport of LATEST_RUBY_WITHOUT_PATCH_VERSIONS
Signed-off-by: Samuel Giddins <segiddins@segiddins.me>

24c8073b24
2025-05-26 11:46:12 +09:00
Samuel Giddins
d8d0da5713
[rubygems/rubygems] Remove platform backports from bundler
Signed-off-by: Samuel Giddins <segiddins@segiddins.me>

9336d3811c
2025-05-26 11:46:12 +09:00
Samuel Giddins
af27688697
[rubygems/rubygems] Remove reference to validate_rust_builder_rubygems_version
Signed-off-by: Samuel Giddins <segiddins@segiddins.me>

f8baf13ab0
2025-05-26 11:46:12 +09:00
Samuel Giddins
c9ba3d0bac
[rubygems/rubygems] Bump required_ruby_version to 3.2
Ruby 3.1 was EOL March 2025

Signed-off-by: Samuel Giddins <segiddins@segiddins.me>

29c21b1e78
2025-05-26 11:46:12 +09:00
Nathan Ladd
3ac239f790 [rubygems/rubygems] Copy prerelease attribute to dependency resolver sets
5956e7f8e5
2025-05-21 11:33:32 +09:00
Earlopain
a82e7132df Fix uplevel for cgi under bundler
Since there is `bundled_gems.rb` it is not always one. Fixes the following:
```sh
$ ruby -w -rbundler/inline -e "gemfile {}; require 'cgi'"
/home/earlopain/.rbenv/versions/ruby-dev/lib/ruby/3.5.0+0/bundled_gems.rb:59: warning: CGI library is removed from Ruby 3.5. Please use cgi/escape instead for CGI.escape and CGI.unescape features.
If you need to use the full features of CGI library, Please install cgi gem.
```

into:

```sh
$ ruby -w -rbundler/inline -e "gemfile {}; require 'cgi'"
-e:1: warning: CGI library is removed from Ruby 3.5. Please use cgi/escape instead for CGI.escape and CGI.unescape features.
If you need to use the full features of CGI library, Please install cgi gem.
```
2025-05-20 18:22:41 +09:00
Jeremy Evans
c52f4eea56 Remove SortedSet autoload and set/sorted_set
Implements [Feature #21287]
2025-05-20 13:34:31 +09:00
David Rodríguez
aea603615f [rubygems/rubygems] Missing tweak
407c1cbcfe
2025-05-19 11:15:30 +09:00
Samuel Giddins
4be199e435 [rubygems/rubygems] Simplify Gem::Platform#initialize
Based on PR feedback

Signed-off-by: Samuel Giddins <segiddins@segiddins.me>

562d7aa087
2025-05-19 11:15:29 +09:00
Samuel Giddins
8f61e17556 [rubygems/rubygems] RuboCop
Signed-off-by: Samuel Giddins <segiddins@segiddins.me>

768784910b
2025-05-19 11:15:29 +09:00
Samuel Giddins
eb48418b40 [rubygems/rubygems] Ensure that Gem::Platform parses strings to a fix point
The issue was that the property that

```ruby
platform = Gem::Platform.new $string
platform == Gem::Platform.new(platform.to_s)
```

was not always true.

This property (of acchieving a fix point) is important,
since `Gem::Platform` gets serialized to a string and
then deserialized back to a `Gem::Platform` object.
If it doesn't deserialize to the same object, then
different platforms are used for the initial serialization
than subsequent runs.

I used https://github.com/segiddins/Scratch/blob/main/2025/03/rubygems-platform.rb
to find the failing cases and then fixed them.
With this patch, the prop check test now passes.

313fb4bcec
2025-05-19 11:15:28 +09:00
Daisuke Aritomo
aa0f689bf4 [ruby/net-http] Freeze some constants to improve Ractor compatibility
Freeze `Net::HTTP::SSL_IVNAMES`, `Net::HTTPResponse::CODE_CLASS_TO_OBJ`
and `Net::HTTPResponse::CODE_TO_OBJ` to improve Ractor compatibility.

This change allows the following code to work:

    Ractor.new {
      uri = URI.parse('http://example.com')
      http = Net::HTTP.new(uri.host, uri.port)
      http.open_timeout = nil
      http.read_timeout = nil
      http.get('/index.html')
    }

9f0f5e4b4d
2025-05-17 00:42:12 +00:00
Takashi Kokubun
57f8dde0f2 [ruby/erb] Version 5.0.1
42f389dc45
2025-05-14 17:10:04 +00:00
Hiroshi SHIBATA
f855bcc6b2
Applied rake vendor:install 2025-05-14 15:13:45 +09:00
Takashi Kokubun
1d3221ad28 [ruby/erb] Give up on using resolve_feature_path
Apparently `$LOAD_PATH.resolve_feature_path('erb/escape')` returns true
for miniruby but `require 'erb/escape'` fails on it.

I still don't want to check it and rescue LoadError at the same time
because the code looks too complicated. Let me just rescue LoadError for
platforms that don't build native extensions.

3081c6b20f
2025-05-13 23:54:02 +00:00
Takashi Kokubun
e8e7daa71a [ruby/erb] Reapply "Refactor the logic of require 'erb/escape'
(https://github.com/ruby/erb/pull/61)"

This reverts commit 1c9200aab0.

Now that we've bumped BASERUBY, we shouldn't need to rescue the
LoadError.

846b20fe0e
2025-05-13 23:31:02 +00:00
Takashi Kokubun
cbaf85cb32 [ruby/erb] Update the reason why we need to rescue LoadError
c2d1f82817
2025-05-13 18:23:04 +00:00
Takashi Kokubun
c71f9b8aee [ruby/erb] Revert "Refactor the logic of require 'erb/escape'
(https://github.com/ruby/erb/pull/61)"

This reverts commit 1c393aa738.

1c9200aab0
2025-05-13 18:23:04 +00:00
Takashi Kokubun
9db0704e67 [ruby/erb] Version 5.0.0
08b544cdb8
2025-05-13 18:09:08 +00:00
Takashi Kokubun
8982bbcbee [ruby/erb] Publish constant ERB::VERSION
Even cgi.gem publicly defines CGI::VERSION today. It's just weird that
ERB::VERSION is kept private at this point.

46801cbd47
2025-05-13 18:07:17 +00:00
Takashi Kokubun
4a9d46ce07 [ruby/erb] Refactor the logic of require 'erb/escape'
(https://github.com/ruby/erb/pull/61)

1c393aa738
2025-05-13 18:00:07 +00:00
Takashi Kokubun
735f28388c [ruby/erb] Support all cgi.gem versions
(https://github.com/ruby/erb/pull/60)

de9bb8c3cc
2025-05-13 17:50:05 +00:00
Hiroshi SHIBATA
e46fbe624a Psych and SafeYAML was loaded Gem.load_yml, these changes is unnecessary 2025-05-13 15:49:20 +09:00
Hiroshi SHIBATA
4d9a1d5b6f Handle to look up CGI::EscapeExt instead of using LoadError. cgi/escape is provided snce Ruby 2.3 2025-05-13 14:37:24 +09:00
Nobuyoshi Nakada
c6528548d0 [ruby/erb] Use cgi/escape instead of deprecated cgi/util 2025-05-12 09:59:58 -07:00
Nobuyoshi Nakada
311b9352a1 [ruby/erb] [DOC] Make documentation 100%
9152ce8db4
2025-05-12 13:57:24 +00:00
Randy Stauner
4464cbe5cd [rubygems/rubygems] Fix doctor command parsing of otool output
I have several gem dylibs that have a line matching "(compatibility "
with no file path preceding it.

de9dc2bdc4
2025-05-12 11:09:22 +09:00
Nobuyoshi Nakada
2fe8b9cd3d Copy to path with the base name 2025-05-12 02:50:25 +09:00
Satoshi Tagomori
382645d440 namespace on read 2025-05-11 23:32:50 +09:00
Hiroshi SHIBATA
d3c472781d Replaced CGI.parse with URI.decode_www_form 2025-05-09 14:27:28 +09:00
Hiroshi SHIBATA
5aade8a84a Added migration wrapper for cgi.rb and cgi/util.rb 2025-05-09 14:27:28 +09:00
Hiroshi SHIBATA
600c616507 Removed CGI library without CGI::Escape features 2025-05-09 14:27:28 +09:00
Hiroshi SHIBATA
a61f51f66d Use cgi/escape instead of cgi/util 2025-05-09 14:27:28 +09:00
Hiroshi SHIBATA
8a1d45144b Support require 'cgi/escape' with extracting CGI::Escape from CGI::Util 2025-05-09 14:27:28 +09:00
Yusuke Nakamura
819ecd115d
[rubygems/rubygems] Add mtime to Gem::Package::TarWriter#add_file argument
Since 9e21dd9, Gem::Package::TarWriter#add_file adds the file to
the tar with Gem.source_date_epoch for its mtime.
This behavior breaks the code depending on the previous add_file
behavior.
Therefore, add_file accepts mtime as an argument, and uses
Gem.source_date_epoch if not specified.

7020ea98a0
2025-05-08 18:03:04 +09:00
Mike Perham
5d0708378e
[rubygems/rubygems] Smoother authentication experience
Copying the URL is painful here because the URL is embedded within a paragraph of text. I presume we don't want to automatically open the browser.

Instead, move the URL to its own line so that "triple click" will automatically select the whole thing.

21532a69ae
2025-05-02 09:49:15 +09:00
Taketo Takashima
687bd83724 [ruby/ipaddr] Added IPAddr#+/-
78b4f53bf5
2025-04-26 11:56:42 +00:00
Jeremy Evans
e4f85bfc31 Implement Set as a core class
Set has been an autoloaded standard library since Ruby 3.2.
The standard library Set is less efficient than it could be, as it
uses Hash for storage, which stores unnecessary values for each key.

Implementation details:

* Core Set uses a modified version of `st_table`, named `set_table`.
  than `s/st_/set_/`, the main difference is that the stored records
  do not have values, making them 1/3 smaller. `st_table_entry` stores
  `hash`, `key`, and `record` (value), while `set_table_entry` only
  stores `hash` and `key`.  This results in large sets using ~33% less
  memory compared to stdlib Set.  For small sets, core Set uses 12% more
  memory (160 byte object slot and 64 malloc bytes, while stdlib set
  uses 40 for Set and 160 for Hash).  More memory is used because
  the set_table is embedded and 72 bytes in the object slot are
  currently wasted. Hopefully we can make this more efficient and have
  it stored in an 80 byte object slot in the future.

* All methods are implemented as cfuncs, except the pretty_print
  methods, which were moved to `lib/pp.rb` (which is where the
  pretty_print methods for other core classes are defined).  As is
  typical for core classes, internal calls call C functions and
  not Ruby methods.  For example, to check if something is a Set,
  `rb_obj_is_kind_of` is used, instead of calling `is_a?(Set)` on the
  related object.

* Almost all methods use the same algorithm that the pure-Ruby
  implementation used.  The exception is when calling `Set#divide` with a
  block with 2-arity.  The pure-Ruby method used tsort to implement this.
  I developed an algorithm that only allocates a single intermediate
  hash and does not need tsort.

* The `flatten_merge` protected method is no longer necessary, so it
  is not implemented (it could be).

* Similar to Hash/Array, subclasses of Set are no longer reflected in
  `inspect` output.

* RDoc from stdlib Set was moved to core Set, with minor updates.

This includes a comprehensive benchmark suite for all public Set
methods.  As you would expect, the native version is faster in the
vast majority of cases, and multiple times faster in many cases.
There are a few cases where it is significantly slower:

* Set.new with no arguments (~1.6x)
* Set#compare_by_identity for small sets (~1.3x)
* Set#clone for small sets (~1.5x)
* Set#dup for small sets (~1.7x)

These are slower as Set does not currently use the AR table
optimization that Hash does, so a new set_table is initialized for
each call.  I'm not sure it's worth the complexity to have an AR
table-like optimization for small sets (for hashes it makes sense,
as small hashes are used everywhere in Ruby).

The rbs and repl_type_completor bundled gems will need updates to
support core Set.  The pull request marks them as allowed failures.

This passes all set tests with no changes.  The following specs
needed modification:

* Modifying frozen set error message (changed for the better)
* `Set#divide` when passed a 2-arity block no longer yields the same
  object as both the first and second argument (this seems like an issue
  with the previous implementation).
* Set-like objects that override `is_a?` such that `is_a?(Set)` return
  `true` are no longer treated as Set instances.
* `Set.allocate.hash` is no longer the same as `nil.hash`
* `Set#join` no longer calls `Set#to_a` (it calls the underlying C
   function).
* `Set#flatten_merge` protected method is not implemented.

Previously, `set.rb` added a `SortedSet` autoload, which loads
`set/sorted_set.rb`.  This replaces the `Set` autoload in `prelude.rb`
with a `SortedSet` autoload, but I recommend removing it and
`set/sorted_set.rb`.

This moves `test/set/test_set.rb` to `test/ruby/test_set.rb`,
reflecting that switch to a core class.  This does not move the spec
files, as I'm not sure how they should be handled.

Internally, this uses the st_* types and functions as much as
possible, and only adds set_* types and functions as needed.
The underlying set_table implementation is stored in st.c, but
there is no public C-API for it, nor is there one planned, in
order to keep the ability to change the internals going forward.

For internal uses of st_table with Qtrue values, those can
probably be replaced with set_table.  To do that, include
internal/set_table.h.  To handle symbol visibility (rb_ prefix),
internal/set_table.h uses the same macro approach that
include/ruby/st.h uses.

The Set class (rb_cSet) and all methods are defined in set.c.
There isn't currently a C-API for the Set class, though C-API
functions can be added as needed going forward.

Implements [Feature #21216]

Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
Co-authored-by: Oliver Nutter <mrnoname1000@riseup.net>
2025-04-26 10:31:11 +09:00
Aaron Patterson
8ac8225c50 Inline Class#new.
This commit inlines instructions for Class#new.  To make this work, we
added a new YARV instructions, `opt_new`.  `opt_new` checks whether or
not the `new` method is the default allocator method.  If it is, it
allocates the object, and pushes the instance on the stack.  If not, the
instruction jumps to the "slow path" method call instructions.

Old instructions:

```
> ruby --dump=insns -e'Object.new'
== disasm: #<ISeq:<main>@-e:1 (1,0)-(1,10)>
0000 opt_getconstant_path                   <ic:0 Object>             (   1)[Li]
0002 opt_send_without_block                 <calldata!mid:new, argc:0, ARGS_SIMPLE>
0004 leave
```

New instructions:

```
> ./miniruby --dump=insns -e'Object.new'
== disasm: #<ISeq:<main>@-e:1 (1,0)-(1,10)>
0000 opt_getconstant_path                   <ic:0 Object>             (   1)[Li]
0002 putnil
0003 swap
0004 opt_new                                <calldata!mid:new, argc:0, ARGS_SIMPLE>, 11
0007 opt_send_without_block                 <calldata!mid:initialize, argc:0, FCALL|ARGS_SIMPLE>
0009 jump                                   14
0011 opt_send_without_block                 <calldata!mid:new, argc:0, ARGS_SIMPLE>
0013 swap
0014 pop
0015 leave
```

This commit speeds up basic object allocation (`Foo.new`) by 60%, but
classes that take keyword parameters see an even bigger benefit because
no hash is allocated when instantiating the object (3x to 6x faster).

Here is an example that uses `Hash.new(capacity: 0)`:

```
> hyperfine "ruby --disable-gems -e'i = 0; while i < 10_000_000; Hash.new(capacity: 0); i += 1; end'" "./ruby --disable-gems -e'i = 0; while i < 10_000_000; Hash.new(capacity: 0); i += 1; end'"
Benchmark 1: ruby --disable-gems -e'i = 0; while i < 10_000_000; Hash.new(capacity: 0); i += 1; end'
  Time (mean ± σ):      1.082 s ±  0.004 s    [User: 1.074 s, System: 0.008 s]
  Range (min … max):    1.076 s …  1.088 s    10 runs

Benchmark 2: ./ruby --disable-gems -e'i = 0; while i < 10_000_000; Hash.new(capacity: 0); i += 1; end'
  Time (mean ± σ):     627.9 ms ±   3.5 ms    [User: 622.7 ms, System: 4.8 ms]
  Range (min … max):   622.7 ms … 633.2 ms    10 runs

Summary
  ./ruby --disable-gems -e'i = 0; while i < 10_000_000; Hash.new(capacity: 0); i += 1; end' ran
    1.72 ± 0.01 times faster than ruby --disable-gems -e'i = 0; while i < 10_000_000; Hash.new(capacity: 0); i += 1; end'
```

This commit changes the backtrace for `initialize`:

```
aaron@tc ~/g/ruby (inline-new)> cat test.rb
class Foo
  def initialize
    puts caller
  end
end

def hello
  Foo.new
end

hello
aaron@tc ~/g/ruby (inline-new)> ruby -v test.rb
ruby 3.4.2 (2025-02-15 revision d2930f8e7a) +PRISM [arm64-darwin24]
test.rb:8:in 'Class#new'
test.rb:8:in 'Object#hello'
test.rb:11:in '<main>'
aaron@tc ~/g/ruby (inline-new)> ./miniruby -v test.rb
ruby 3.5.0dev (2025-03-28T23:59:40Z inline-new c4157884e4) +PRISM [arm64-darwin24]
test.rb:8:in 'Object#hello'
test.rb:11:in '<main>'
```

It also increases memory usage for calls to `new` by 122 bytes:

```
aaron@tc ~/g/ruby (inline-new)> cat test.rb
require "objspace"

class Foo
  def initialize
    puts caller
  end
end

def hello
  Foo.new
end

puts ObjectSpace.memsize_of(RubyVM::InstructionSequence.of(method(:hello)))
aaron@tc ~/g/ruby (inline-new)> make runruby
RUBY_ON_BUG='gdb -x ./.gdbinit -p' ./miniruby -I./lib -I. -I.ext/common  ./tool/runruby.rb --extout=.ext  -- --disable-gems  ./test.rb
656
aaron@tc ~/g/ruby (inline-new)> ruby -v test.rb
ruby 3.4.2 (2025-02-15 revision d2930f8e7a) +PRISM [arm64-darwin24]
544
```

Thanks to @ko1 for coming up with this idea!

Co-Authored-By: John Hawthorn <john@hawthorn.email>
2025-04-25 13:46:05 -07:00
Hiroshi SHIBATA
b3566e9ef2 [rubygems/rubygems] bin/rubocop -a --only Style/StringLiterals
62e1bf2d37
2025-04-25 16:25:21 +09:00
David Rodríguez
6f336d1b15
[rubygems/rubygems] Remove shellwords autoload
2af1646776
2025-04-25 11:12:03 +09:00
Hiroshi SHIBATA
f0dda0534b Rewrite CGI.parse with URI.decode_www_form_component
Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
2025-04-24 12:15:11 +09:00
Hiroshi SHIBATA
a23ce6d3a5 Removed unused cgi library 2025-04-24 12:15:11 +09:00
Hiroshi SHIBATA
a88c5b501c Use cgi/util if that uses like CGI.escape methods 2025-04-24 12:15:11 +09:00
Nobuyoshi Nakada
59c7b3840d Check Unicode version of the normalization table 2025-04-23 14:14:36 +09:00
Jeremy Evans
00b1a9cde6 [ruby/pp] Rename EMPTY_HASH to EMPTY_KWHASH
efe5bc878f
2025-04-22 15:21:07 +00:00
Jeremy Evans
3ce5d89c20 [ruby/pp] Avoid an array allocation per element in list passed to seplist
The array allocation was because the keyword splat expression is
not recognized as safe by the compiler.  Also avoid unnecessary
>= method call per element.  This uses a private constant to
avoid unnecessary work at runtime.

I assume the only reason this code is needed is because v may
end with a ruby2_keywords hash that we do not want to treat as
keywords.

This issue was found by the performance warning in Ruby feature
21274.

3bf6df0e5c
2025-04-22 15:21:07 +00:00
Jeremy Evans
51d0e58772
[rubygems/rubygems] Avoid unnecessary splat allocation
Because get_push_scope is a method call, Ruby will allocate an array
for *args even though it is not necessary to do so. Using a local
variable avoids the allocation.

Found by the performance warning in Ruby feature 21274.

0473c0cf32
2025-04-22 11:27:24 +09:00
Edouard CHIN
56c1a15eb7
[rubygems/rubygems] Warn if TLS 1.2 is not supported
e4f70a3e4f
2025-04-22 11:27:24 +09:00
Edouard CHIN
ff2e0e4173
[rubygems/rubygems] Summarize the diagnostic
40cf54d256
2025-04-22 11:27:24 +09:00