summaryrefslogtreecommitdiff
path: root/spec/ruby/library
AgeCommit message (Collapse)Author
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 daysupdate allocation location testsAaron Patterson
12 days[Feature #20724] Bump Unicode version to 16.0.0Mari Imaizumi
Notes: Merged: https://github.com/ruby/ruby/pull/13117
2025-04-02Removed Solaris conditions from library directoryHiroshi SHIBATA
Notes: Merged: https://github.com/ruby/ruby/pull/13037
2025-03-27Update to ruby/spec@5e579e2Andrew Konchin
Notes: Merged: https://github.com/ruby/ruby/pull/12984
2025-03-18[Feature #19908] Update Unicode headers to 15.1.0Mari Imaizumi
Notes: Merged: https://github.com/ruby/ruby/pull/12798
2025-02-07Retry on IO::EAGAINWaitReadable when a closed socket is still not available ↵Andrew Konchin
for reading Notes: Merged: https://github.com/ruby/ruby/pull/12710
2025-01-31Prefer `platform_is_not :windows`.Samuel Williams
Notes: Merged: https://github.com/ruby/ruby/pull/12682
2025-01-30Update to ruby/spec@affef93Andrew Konchin
Notes: Merged: https://github.com/ruby/ruby/pull/12679
2025-01-30Handle environment where GEM_HOME is not availableHiroshi SHIBATA
Notes: Merged: https://github.com/ruby/ruby/pull/12675
2025-01-30bin_path_spec.rb relied to available Ruby environment with after `make install`Hiroshi SHIBATA
But we stub-out GEM_HOME variable for test-bundled-gems and others on ruby/ruby. It means the installation path mismatched with GEM_HOME variable always. We can't test this example collectly. ``` 1) Gem.bin_path finds executables of default gems, which are the only files shipped for default gems FAILED Expected File.exist? "/Users/hsbt/Documents/github.com/ruby/ruby/.bundle/gems/bundler-2.7.0.dev/exe/bundle" to be truthy but was false ```
2025-01-29Add fallback for `hostname` if `uname` isn't available. (#12655)Samuel Williams
Notes: Merged-By: ioquatix <[email protected]>
2025-01-28Prefer `uname -n` over `hostname`. (#12647)Samuel Williams
Notes: Merged-By: ioquatix <[email protected]>
2025-01-24Restructured irb related example at spec/rubyHiroshi SHIBATA
Notes: Merged: https://github.com/ruby/ruby/pull/12624
2025-01-08Skip examples related with OpenStruct in ruby/specHiroshi SHIBATA
Notes: Merged: https://github.com/ruby/ruby/pull/12531
2025-01-08Reapply "Suppress WIN32OLE deprecation warnings for the time being"Nobuyoshi Nakada
Revert the part of commit 10917c5cc026f839a3dcd072b6e274eed211d0f7, "Update to ruby/spec@18032a7", that discarded the previous commit.
2025-01-07Update to ruby/spec@18032a7Andrew Konchin
Notes: Merged: https://github.com/ruby/ruby/pull/12517
2024-12-31Fix leak in Socket#connect specBenoit Daloze
* Found by https://github.com/ruby/ruby/actions/runs/12560692556/job/35018412527?pr=12492 Notes: Merged: https://github.com/ruby/ruby/pull/12492
2024-12-28BigDecimal('0.') with bigdecimal-3.1.9 returns 0.0Hiroshi SHIBATA
Notes: Merged: https://github.com/ruby/ruby/pull/12480
2024-12-28Abandon connection test if off lineNobuyoshi Nakada
2024-12-22Suppress WIN32OLE deprecation warnings for the time beingNobuyoshi Nakada
2024-12-10Update to ruby/spec@9f10222Andrew Konchin
Notes: Merged: https://github.com/ruby/ruby/pull/12297
2024-12-03Socket#connect may be raise ECONNREFUSEDKazuhiro NISHIYAMA
On my environment with `sudo ufw default reject outgoing`, outgoing packets are filtered without allow rules. Notes: Merged: https://github.com/ruby/ruby/pull/12238
2024-11-21Omit flaky example with Windows platformHiroshi SHIBATA
https://github.com/ruby/ruby/actions/runs/11948300522/job/33305664284?pr=12139 ``` IO#wait [events, timeout] passed changes thread status to 'sleep' when waits for WRITABLE event FAILED Expected false == "sleep" to be truthy but was false D:/a/ruby/ruby/src/spec/ruby/library/io-wait/wait_spec.rb:99:in 'block (3 levels) in <top (required)>' D:/a/ruby/ruby/src/spec/ruby/library/io-wait/wait_spec.rb:8:in '<top (required)>' ``` Notes: Merged: https://github.com/ruby/ruby/pull/12140
2024-11-06Update to ruby/spec@54c391eBenoit Daloze
2024-10-23Harden the ObjectSpace.memsize_of specJean Boussier
[Bug #20803] `abc` is used a lot across the ruby spec suite, if another test runs before this spec is loaded and create this symbol dynamically (`"abc".to_sym`) the spec will fail. So it's preferable to use a symbol name that is very unlikely to be used elsewhere to avoid flakes. Notes: Merged: https://github.com/ruby/ruby/pull/11942
2024-10-12Support `IO#timeout` for `rsock_connect`. (#11880)Samuel Williams
Notes: Merged-By: ioquatix <[email protected]>
2024-10-03Update spec/ruby/ for colon-style hash inspecttompng
Notes: Merged: https://github.com/ruby/ruby/pull/10924
2024-09-17Skip failing examples related with ↵Hiroshi SHIBATA
https://github.com/ruby/ruby/commit/d81b0588bb3c97167d1f7e2d2a74185e0c19b68c
2024-09-05Move Time#xmlschema in core and optimize itJean Boussier
[Feature #20707] Converting Time into RFC3339 / ISO8601 representation is an significant hotspot for applications that serialize data in JSON, XML or other formats. By moving it into core we can optimize it much further than what `strftime` will allow. ``` compare-ruby: ruby 3.4.0dev (2024-08-29T13:11:40Z master 6b08a50a62) +YJIT [arm64-darwin23] built-ruby: ruby 3.4.0dev (2024-08-30T13:17:32Z native-xmlschema 34041ff71f) +YJIT [arm64-darwin23] warming up...... | |compare-ruby|built-ruby| |:-----------------------|-----------:|---------:| |time.xmlschema | 1.087M| 5.190M| | | -| 4.78x| |utc_time.xmlschema | 1.464M| 6.848M| | | -| 4.68x| |time.xmlschema(6) | 859.960k| 4.646M| | | -| 5.40x| |utc_time.xmlschema(6) | 1.080M| 5.917M| | | -| 5.48x| |time.xmlschema(9) | 893.909k| 4.668M| | | -| 5.22x| |utc_time.xmlschema(9) | 1.056M| 5.707M| | | -| 5.40x| ``` Notes: Merged: https://github.com/ruby/ruby/pull/11510
2024-07-24Add "c_long_size" guard, supplanting "wordsize" and stop using Integer#sizeAlan Wu
What a "word" is when talking about sizes is confusing because it's a highly overloaded term. Intel, Microsoft, and GDB are just a few vendors that have their own definition of what a "word" is. Specs that used the "wordsize" guard actually were mostly testing for the size of the C `long` fundamental type, so rename the guard for clarity. Also, get the size of `long` directly from RbConfig instead of guessing using Integer#size. Integer#size is not guaranteed to have anything to do with the `long` type. Notes: Merged: https://github.com/ruby/ruby/pull/11130
2024-07-18Split URI::Parser examples with RFC2396 and RFC3986Hiroshi SHIBATA
Prepare for https://github.com/ruby/uri/pull/107
2024-07-02Update to ruby/spec@f8987acAndrew Konchin
2024-06-18net-ftp-0.3.6 always return response with put/puttextfile.Hiroshi SHIBATA
* https://github.com/ruby/net-ftp/pull/34 * https://github.com/ruby/net-ftp/issues/36
2024-06-12'SPEC_TEMP_DIR` should not be world-writableKoichi Sasada
`SPEC_TEMP_DIR` is not present until `tmp()` method is called on parallel run. In this case `tmp()` is called with `File.umask = 0`. This patch makes `SPEC_TEMP_DIR` before `File.umask = 0`. To solve the issue essentially, I think `SPEC_TEMP_DIR` should be prepared at the beginning of parallel process.
2024-06-10Fix CI when YJIT is enabledAndrew Konchin
2024-06-10Update to ruby/spec@517f06fAndrew Konchin
2024-05-19Update to ruby/spec@6b04c1dAndrew Konchin
2024-04-02Update to ruby/spec@573cf97Andrew Konchin
2024-03-28Suppress warning at literal stringNobuyoshi Nakada
2024-03-16Prefer the simple read/write `File` singleton methodsNobuyoshi Nakada
2024-03-14Update to ruby/spec@89175b2Benoit Daloze
2024-03-05[DOC] fix some commentscui fliter
Signed-off-by: cui fliter <[email protected]>
2024-02-26Update to ruby/spec@3a510bbBenoit Daloze
2024-02-15Skip failing examples at Ruby 3.2+Hiroshi SHIBATA
2024-02-15Re-enabled old bundled gemsHiroshi SHIBATA
2024-02-15ruby-spec: Accept the receiver in backtracesYusuke Endoh
2024-02-15Rename and restructured net/ftp and net/http examplesHiroshi SHIBATA
2024-02-15Move examples related core extension feature by Bigdecimal to under the ↵Hiroshi SHIBATA
library/bigdecimal
2024-02-15ruby-spec: Accept both a backtick and a single quote in error messagesYusuke Endoh