Fix SortedSet initialization and equality on Ruby 4.0 - #20
Open
joshuay03 wants to merge 1 commit into
Open
Conversation
Author
|
Bump 🙏🏽 |
joshuay03
force-pushed
the
fix-initialize-with-sorted-set
branch
from
May 14, 2026 00:53
0053dd7 to
3bfb949
Compare
Author
|
Bumping again 🙏🏽 |
Author
|
Bumping once more 🙏🏽 |
joshuay03
force-pushed
the
fix-initialize-with-sorted-set
branch
from
August 18, 2026 03:23
3bfb949 to
66cca55
Compare
SortedSet.new(sorted_set) on Ruby 4.0SortedSet.new(sorted_set) and hash-key lookups on Ruby 4.0
|
Tick the box to add this pull request to the merge queue (same as
|
joshuay03
force-pushed
the
fix-initialize-with-sorted-set
branch
from
August 18, 2026 04:39
66cca55 to
4b5231c
Compare
|
Tick the box to add this pull request to the merge queue (same as
|
SortedSet.new(sorted_set) and hash-key lookups on Ruby 4.0SortedSet.new(sorted_set) and Hash lookups on Ruby 4.0
joshuay03
force-pushed
the
fix-initialize-with-sorted-set
branch
from
August 19, 2026 22:40
4b5231c to
fa614bf
Compare
|
Tick the box to add this pull request to the merge queue (same as
|
1 similar comment
|
Tick the box to add this pull request to the merge queue (same as
|
joshuay03
force-pushed
the
fix-initialize-with-sorted-set
branch
3 times, most recently
from
August 25, 2026 04:54
f8b4cde to
7c3dcb6
Compare
SortedSet.new(sorted_set) and Hash lookups on Ruby 4.0|
Tick the box to add this pull request to the merge queue (same as
|
joshuay03
force-pushed
the
fix-initialize-with-sorted-set
branch
from
August 25, 2026 20:47
7c3dcb6 to
1e03cc5
Compare
Ruby 4.0's Set initializer can bypass SortedSet's Ruby-level overrides when copying another SortedSet, leaving its separate backing tree empty. Copy the backing tree directly when no transformation block is given, while preserving normal enumeration for transforming initializers. Set's built-in equality also compares inherited storage that SortedSet does not use. Restore SortedSet content and comparator semantics, Set-receiver comparisons, and strict eql? behavior for Hash keys. Apply equivalent behavior to JRuby, including a comparator fallback when Java rejects mixed numeric lookups.
|
Tick the box to add this pull request to the merge queue (same as
|
joshuay03
force-pushed
the
fix-initialize-with-sorted-set
branch
from
September 2, 2026 04:01
1e03cc5 to
3d15f57
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Ruby 4 stores
Setelements in C, whileSortedSetkeeps its contents in a separate backing tree. The built-inSetfast paths therefore cannot seeSortedSet's logical contents: copying anotherSortedSetproduces an empty set, and equality can compare the wrong storage.Fix
Copy construction now duplicates the backing tree when the source has the same class and no transformation block. Transforming initializers continue to enumerate the source, and copies remain independent and mutable.
SortedSet#==now compares sorted sets by backing-tree semantics and ordinary sets through comparator-based membership.#eql?remains exact-class and element-eql?based to preserve correctHashbehavior. A narrowSetoverride restores comparisons when an ordinarySetis the receiver without changing comparisons between ordinary sets. JRuby receives equivalent behavior, including a comparator fallback whenTreeSetrejects otherwise Ruby-comparable values.Tested on Ruby 2.7.8, 3.4.10, 4.0.6, and JRuby 10.1.1.0.