Skip to content

Conversation

headius
Copy link
Member

@headius headius commented Feb 5, 2025

This change makes compare_by_identity Hash instances know about our JavaProxy wrapper type and treat as identical two wrappers that contain the same object. This will add overhead to all identity hashes in order to type check the incoming keys:

  • It must know to calculate the identity hash based on the contained object and not the wrapper (affects all identity Hash).
  • It must also try to unwrap proxies and compare contents when traversing existing entries (only affects identity Hash when a key does not already exist).

This fixes the identity Hash portion of #8612.

This change makes compare_by_identity Hash instances know about
our JavaProxy wrapper type and treat as identical two wrappers
that contain the same object. This will add overhead to all
identity hashes in order to type check the incoming keys:

* It must know to calculate the identity hash based on the
  contained object and not the wrapper (affects all identity Hash).
* It must also try to unwrap proxies and compare contents when
  traversing existing entries (only affects identity Hash when a
  key does not already exist).

This fixes the identity Hash portion of jruby#8612.
@headius headius marked this pull request as draft February 5, 2025 22:58
@headius headius added this to the JRuby 9.4.12.0 milestone Feb 7, 2025
@headius
Copy link
Member Author

headius commented Feb 7, 2025

This needs tests but I think we are pretty safe including it in an upcoming release. It does not appear to be necessary to fix issues in @kalenp's application, so there's no rush to include it in 9.4.12.0.

After discussion we decided that we could not think of a case where someone would not want two equivalent Java object wrappers to appear identical to an identity Hash, and lots of reasons why that behavior is almost certainly unexpected. Since currently it's just broken, as illustrated by my example in #8612, this is a net positive functionality fix.

Note I have not done any benchmarking to see how the additional type-checking affects identity Hash performance, so that should happen before merge as well.

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