summaryrefslogtreecommitdiff
path: root/lib
AgeCommit message (Collapse)Author
4 days[ruby/ipaddr] Added IPAddr#+/-Taketo Takashima
https://github.com/ruby/ipaddr/commit/78b4f53bf5
4 daysImplement Set as a core classJeremy Evans
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 <[email protected]> Co-authored-by: Oliver Nutter <[email protected]>
5 daysInline Class#new.Aaron Patterson
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 <[email protected]>
5 days[rubygems/rubygems] bin/rubocop -a --only Style/StringLiteralsHiroshi SHIBATA
https://github.com/rubygems/rubygems/commit/62e1bf2d37 Notes: Merged: https://github.com/ruby/ruby/pull/13177
5 days[rubygems/rubygems] Remove shellwords autoloadDavid Rodríguez
https://github.com/rubygems/rubygems/commit/2af1646776
6 daysRewrite CGI.parse with URI.decode_www_form_componentHiroshi SHIBATA
Co-authored-by: Nobuyoshi Nakada <[email protected]>
6 daysRemoved unused cgi libraryHiroshi SHIBATA
6 daysUse cgi/util if that uses like CGI.escape methodsHiroshi SHIBATA
7 daysCheck Unicode version of the normalization tableNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/13154
8 days[ruby/pp] Rename EMPTY_HASH to EMPTY_KWHASHJeremy Evans
https://github.com/ruby/pp/commit/efe5bc878f
8 days[ruby/pp] Avoid an array allocation per element in list passed to seplistJeremy Evans
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. https://github.com/ruby/pp/commit/3bf6df0e5c
8 days[rubygems/rubygems] Avoid unnecessary splat allocationJeremy Evans
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. https://github.com/rubygems/rubygems/commit/0473c0cf32
8 days[rubygems/rubygems] Warn if TLS 1.2 is not supportedEdouard CHIN
https://github.com/rubygems/rubygems/commit/e4f70a3e4f
8 days[rubygems/rubygems] Summarize the diagnosticEdouard CHIN
https://github.com/rubygems/rubygems/commit/40cf54d256
8 days[rubygems/rubygems] Diagnose the bare net/http connectionEdouard CHIN
https://github.com/rubygems/rubygems/commit/38a0bdc123
8 days[rubygems/rubygems] Diagnose the RubyGems connectionEdouard CHIN
https://github.com/rubygems/rubygems/commit/bf63859e1e
8 days[rubygems/rubygems] Diagnose the bundler connectionEdouard CHIN
https://github.com/rubygems/rubygems/commit/0aae094c89
8 days[rubygems/rubygems] Diagnose when OpenSSL can't be loaded.Edouard CHIN
https://github.com/rubygems/rubygems/commit/e6aa8aabcd
8 days[rubygems/rubygems] Add the `bundle doctor subcommand` skeleton:Edouard CHIN
- The command can either be run using: 1. `bundle doctor --ssl` 2. `bundle doctor ssl` The later is most useful when you need to specify custom ssl options (such as the verify mode or the TLS version when running the diagnostic). The implementation will follow in the next commits. https://github.com/rubygems/rubygems/commit/993d12874c
8 days[rubygems/rubygems] Define `bundler doctor` as a subcommandEdouard CHIN
- See explanation in previous commit https://github.com/rubygems/rubygems/commit/170890befb4c https://github.com/rubygems/rubygems/commit/8f1b5a4479
8 daysMove the doctor command into a subfolder:Edouard CHIN
- Adding a new `ssl` option to bundle doctor will make the `Doctor` command quite bloated. The "diagnose ssl" option will also have children option to allow passing which host or which tls version you want to diagnose and I feel these options don't belong in the doctor command. So my intention in this commit is to prepare to have a new `Doctor` subcommand and allow for better organisation of the code: The command will be: `bundle doctor` -> Run exactly the same as before. `bundle doctor --ssl` -> Run the doctor command and diagnose SSL with default options (rubygems.org as the host and verify peer as the verify mode) `bundle doctor ssl --host github.com` -> Run the ssl subcommand and pass a specific host. This commit just renames a file in order to avoid big diff chunks.
12 days[Feature #20724] Bump Unicode version to 16.0.0Mari Imaizumi
Notes: Merged: https://github.com/ruby/ruby/pull/13117
12 daysprepare Unicode normalization for Unicode 16.0.0Martin Dürst
2025-04-15[rubygems/rubygems] Let `bundle lock --normalize-platforms` remove invalid ↵David Rodríguez
platforms https://github.com/rubygems/rubygems/commit/c39d2f84fd
2025-04-15[rubygems/rubygems] Raise an error if `bundle lock` target platform is ↵David Rodríguez
incompatible https://github.com/rubygems/rubygems/commit/282e4a8593
2025-04-15[rubygems/rubygems] Rename `resolution_packages` to `resolution_base`David Rodríguez
It handles resolution packages but also other stuff. https://github.com/rubygems/rubygems/commit/4baec92c20
2025-04-15[rubygems/rubygems] Extract some logic to a method and expand commentDavid Rodríguez
https://github.com/rubygems/rubygems/commit/ed31e888fd
2025-04-15[rubygems/rubygems] Clarify commentDavid Rodríguez
https://github.com/rubygems/rubygems/commit/42534e746b
2025-04-15[rubygems/rubygems] Comparing platforms is only needed for dependency validationDavid Rodríguez
If we materialized to a different platform, then the dependencies may actually be different so the validation does not really make sense. https://github.com/rubygems/rubygems/commit/68fad98e6f
2025-04-15[rubygems/rubygems] Only platforms are relevant hereDavid Rodríguez
https://github.com/rubygems/rubygems/commit/4b6f07f634
2025-04-15[rubygems/rubygems] Fix false positive warning about insecurely materialized gemDavid Rodríguez
In frozen mode, the previous logic would not set the platform locked originally in the materialized specification, and that would trigger the warning about insecure materialization incorrectly. https://github.com/rubygems/rubygems/commit/a18001e10c
2025-04-14[rubygems/rubygems] Refine `bundle update --verbose` logsDavid Rodríguez
Don't mention "Found changes from the lockfile" because that's not really true in general. https://github.com/rubygems/rubygems/commit/0181c278e8
2025-04-14[rubygems/rubygems] Fix edge case making `bundle update` behave incorrectlyDavid Rodríguez
If both a native and a generic version are locked, but the native version is incompatible with the running Ruby, Bundler will still keep the native version in the lockfile, since it could be potentially useful when using other rubies. However, when `bundle update` is run, this was not the case because the locked native gems were not using the right source when materializing. They were using the lockfile source instead of the Gemfile source, and that meant they could not be found when materializing, because the lockfile source always uses local mode so does not see them. The effect of this was normally that they were incorrectly removed from the lockfile and a strange "this spec has been possibly yanked" was printed in verbose mode. However, in certain situations (i.e., when the generic gem would bring extra dependencies), it could also make `bundle update` crash. The solution is, when adding this extra locked specs to the result after resolving, maybe sure they inherit the source from the resolved specs, so they can be found when materializing. `bundle install` did not have the issue because it passes locked specs to the resolver, and assigns the right source to them in `Definition#converge_locked_specs`. https://github.com/rubygems/rubygems/commit/91ce881fda
2025-04-14[rubygems/rubygems] Materialize specs just once in installerDavid Rodríguez
`Definition#specs` does the same thing but memoizes the result. https://github.com/rubygems/rubygems/commit/b62bf9fe41
2025-04-14[rubygems/rubygems] Fix `bundle lock --normalize-platforms` regressionDavid Rodríguez
https://github.com/rubygems/rubygems/commit/458fa5dc4c
2025-04-13Fix unnecessary `false` in `CLEANLIBS`Nobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/13107
2025-04-12[ruby/prism] Fix parsing rescued exception via indexed assignmentviralpraxis
Given this code ```ruby begin raise '42' rescue => A[] end ``` Prism fails with this backtrace ``` Error: test_unparser/corpus/literal/rescue.txt(Prism::ParserTest): NoMethodError: undefined method `arguments' for nil prism/lib/prism/translation/parser/compiler.rb:1055:in `visit_index_target_node' prism/lib/prism/node.rb:9636:in `accept' prism/lib/prism/compiler.rb:30:in `visit' prism/lib/prism/translation/parser/compiler.rb:218:in `visit_begin_node' ``` Seems like ```diff - visit_all(node.arguments.arguments), + visit_all(node.arguments&.arguments || []), ``` fixes the problem. https://github.com/ruby/prism/commit/76d01aeb6c
2025-04-10[ruby/resolv] refactoring class-hash to be ractor-safeHoneyryderChuck
mutable constants can't be shared across ractors; this changes that design to define the required variables as constants on the Resource class, which makes them reachable using ractors; the ClassHash is kept in order not to break integrations relying on its existence, but under the hood it's doing the same thing https://github.com/ruby/resolv/commit/639c01dc7f
2025-04-10[ruby/resolv] config read from file should return frozen data!HoneyryderChuck
https://github.com/ruby/resolv/commit/afb57f40a1
2025-04-10Refactor bundled conditionHiroshi SHIBATA
Notes: Merged: https://github.com/ruby/ruby/pull/12847
2025-04-10The current force_activate always fails without GemfileHiroshi SHIBATA
Notes: Merged: https://github.com/ruby/ruby/pull/12847
2025-04-04[rubygems/rubygems] Improve bug report instructionsDavid Rodríguez
* Explicitly recommend copying full command output and not just the bug report template part. * Include quadruple quotes in the "What actually happened section" and tell users to copy full command output inside. Hopefully quadruple quotes will make the error report information (which includes triple quotes itself) render fine by default. * Avoid "actually" as per quality_spec.rb recommendation. https://github.com/rubygems/rubygems/commit/0a3bf2edb1
2025-04-02[ruby/prism] Fix parser translator when splatting in pattern matching pinEarlopain
Because it ends up treating it as a local variable, and `a.x` is not a valid local variable name. I'm not big on pattern matching, but conceptually it makes sense to me to treat anything inside ^() to not be pattern matching syntax? https://github.com/ruby/prism/commit/80dbd85c45
2025-04-02Removed the warning targets for Ruby 3.1 because 3.1 is already EOLHiroshi SHIBATA
Notes: Merged: https://github.com/ruby/ruby/pull/13017
2025-04-01[rubygems/rubygems] Let compact index response parser consistently return a ↵David Rodríguez
mutable dependencies array That restores support for compact index dummy implementations that only lists versions, without checksums or dependencies. This format is undocumented, so we may want to get rid of it in the future. However, some of our tests rely on it, and some implementations did use it (gems.mutant.dev at least). And the way the code was written suggest that support was intentional. So for now, we should restore it. https://github.com/rubygems/rubygems/commit/0427d8c983
2025-04-01Remove compact index response parser from BundlerDavid Rodríguez
It's available in RubyGems since 3.2.3 and we no longer support that old version.
2025-04-01[rubygems/rubygems] Sorting files in metadata for reproducibilityGiacomo Benedetti
https://github.com/rubygems/rubygems/commit/792117980b
2025-03-31[rubygems/rubygems] Allow ruby platform to be remove also when dependencies ↵David Rodríguez
have changed Since we will now add it back if the final resolution is compatible, we can also get this kind of edge case (`bundle add`) working. https://github.com/rubygems/rubygems/commit/cdc5ebec77
2025-03-31[rubygems/rubygems] Remove edge cases for not removing invalid platformsDavid Rodríguez
Instead, remove them anytime we find dependencies don't match the lockfile for a platform, and then add them back after resolution if they ended up being valid. https://github.com/rubygems/rubygems/commit/220bd77887
2025-03-31[rubygems/rubygems] `SpecSet#add_extra_platforms!` doesn't need to return ↵David Rodríguez
anything https://github.com/rubygems/rubygems/commit/9fd92ade54