Abstract RubyHash#9262
Merged
headius merged 3 commits intojruby:masterfrom Feb 25, 2026
Merged
Conversation
Member
Author
|
Given the immediate problem of jruby-openssl calling one of the RubyHash constructors, I have devised a way to allow it to still be constructed.
This allows constructing RubyHash directly (via deprecated constructors) while still allowing all of our internal uses to construct one of the available subclasses. After some time (perhaps 10.2) and all users of the RubyHash constructors have been fixed, the state field should be moved down into each implementation and the RubyHash class and delegated methods returned to abstract. |
dd79404 to
8c27a3c
Compare
This commit moves RubyHash to RubyHashLinkedBuckets to provide a better history during abstractification.
2dd6841 to
2165c5a
Compare
This patch shifts RubyHash to a pseudo-abstract form to allow new subclass implementations for specific uses. The original implementation, based on pre-direct-addressing CRuby logic, now lives in RubyHashLinkedBuckets. In order to preserve the ability to construct RubyHash directly, all methods intended to be abstract instead delegate to a wrapped instance of RubyHashLinkedBuckets, only used this way when constructed directly through deprecated constructor paths. All internal constructions of Hash use the blessed RubyHashLinkedBuckets constructors and do not use the delegated logic. All RubyHash construction should in the future proceed through factory methods. The factory-first approach ensures that: * The formerly public constructors are all now deprecated and used only by legacy code. * All constructors in RubyHashLinkedBuckets pass through a new non- delegating constructor in RubyHash. * All unprotected constructors in RubyHashLinkedBuckets are only reachable through factory methods. This avoids us exposing new constructors that would prevent us from easily swapping the implementation in the future. The `state` field is used to either hold the delegated hash or to hold the actual state for the real implementation. This allows all proper uses of the RubyHashLinkedBuckets to avoid excessive object size. Other implementations can wrap this field in the same way until we can move it down into those implementations. This implementation passes all tests that do not specifically depend on Hash instances being RubyHash objects.
Hash is now primarily implemented by RubyHashLinkedBuckets and may have other implementations in the future. Tests that expect to see RubyHash as the object's class must be modified to expect the correct class or some wildcarded version of it.
2165c5a to
06a2ac6
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.
This PR is a first pass at making RubyHash abstract to allow new subclass implementations for specific uses. The original implementation, based on pre-direct-addressing CRuby logic, now lives in RubyHashLinkedBuckets.
The impact to consumers of the public RubyHash API should be minimal, except for the now non-functional constructors.
The goal here is to allow RubyHash API-compatible subclasses that either wrap other Hash-like data structures or which implement specific variations like an associative array or a direct- addressing hash. We may also use this to implement thread-safe Hash variants.
At least one external library has already run afoul of the inoperable constructors: jruby-openssl