Skip to content

Move Set to a core class [Ruby 4.0]#9066

Merged
headius merged 18 commits intojruby:ruby-4.0from
headius:core_set
Nov 17, 2025
Merged

Move Set to a core class [Ruby 4.0]#9066
headius merged 18 commits intojruby:ruby-4.0from
headius:core_set

Conversation

@headius
Copy link
Member

@headius headius commented Nov 5, 2025

Ruby 4.0 will include Set as a core class, minus some old encumbrances. This PR will do the same for JRuby.

TODO:

  • Move existing Set to core
  • Delete SortedSet
  • Pass new CRuby tests for some updated behaviors.
  • Eliminate the @hash instance variable
  • The implementation is an efficient, dedicated data structure.
  • Pass all remaining test suites.

@headius headius force-pushed the core_set branch 2 times, most recently from 27ee8ab to d7618b7 Compare November 5, 2025 09:06
@headius headius marked this pull request as draft November 5, 2025 09:09
@headius
Copy link
Member Author

headius commented Nov 5, 2025

Do not merge until we have decided what to do with Ruby 3.5 features.

@headius headius changed the title Move Set to a core class Move Set to a core class [Ruby 3.5] Nov 5, 2025
@headius headius mentioned this pull request Nov 5, 2025
@headius headius changed the base branch from master to ruby-4.0 November 11, 2025 23:13
@headius headius changed the title Move Set to a core class [Ruby 3.5] Move Set to a core class [Ruby 4.0] Nov 11, 2025
@headius
Copy link
Member Author

headius commented Nov 12, 2025

This can merge into ruby-4.0 any time, but it would be good to finish the listed tasks (they just aren't critical for functionality).

* Removed SortedSet and related files (gem TBD).
* Removed stdlib .rb stub.
* Fixed inspect output, intersect? with Array, and infinite
  enumerables for new tests.
* Moved @hash variable to a bound Java field.
* Fix inspect output expectations.
* Guard SortedSet tests behind a require, since that collection is
  now in a separate library (knu/sorted_set). These tests probably
  should move to the external library once we work out the details
  (see knu/sorted_set#7)
Based on code from CRuby by Tomoya Ishida:

ruby/ruby#13680
When the incoming block's signature is important to the iteration
method being called, the previous logic would hide that signature.
The change here propagates it through the CallBlock.
This does not exactly match the new native Set impl, but it passes
specs and tests related to initialize.
This updates some logic related to the new native Set.
Only fails are now related to us not tracking iteration-in-progress
for either Set or Hash.
Paths that will immmediately initialize the wrapped Hash do not
need to pre-allocate. This fixes issues with Set.allocate returning
an object that has a null Hash and can't be used for anything.
@headius
Copy link
Member Author

headius commented Nov 17, 2025

Most of this is now implemented, except for the efficient storage format. That will require additional Java hacking to come up with a representation of Set internals that has the following characteristics:

  • Preserves insertion order
  • Can be switched to compare-by-identity (possibly by replacing the collection)
  • More compact than RubyHash (chained bucket impl)
  • Concurrency-safe (as part of a general move to make core types safe)

I'll file a separate issue to track that work and we'll hopefully get around to it at some point.

@headius headius marked this pull request as ready for review November 17, 2025 21:56
@headius headius added this to the JRuby 10.1.0.0 milestone Nov 17, 2025
@headius headius merged commit 641afcf into jruby:ruby-4.0 Nov 17, 2025
59 of 76 checks passed
@headius headius deleted the core_set branch November 17, 2025 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant