Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore structural equality/hash code of the Type hierarchy #261

Merged
merged 2 commits into from
Sep 16, 2022

Conversation

Ladicek
Copy link
Contributor

@Ladicek Ladicek commented Sep 16, 2022

Fixes #258

This commit adds an internal `Interned` interface to be implemented by Jandex
classes that require non-standard equality and hash code for interning. This
is the case for the `Type` hierarchy, as well as for classes that embed some
`Type` (that is, the `Method/Field/RecordComponentInternal` classes).

The reason why the `Type` hierarchy needs a different equality and hash code
for intering is the existence of type variable references. To maintain
structural equality/hash code for external users (that is, the common `equals`
and `hashCode` methods), type variable references equality/hash code must
only consider the type variable name (and annotations). This is not suitable
for the interning purpose, because two type variable references may have
the same name and annotations, yet point to different type variables
(e.g. because those type variables have different annotations).

We could possibly implement a "deep" structural equality and hash code
for type variable references that would take into account the type variable
the reference points to, but that still wouldn't be enough. When interning,
types must be interned "from the inside", which means that when a type variable
reference is being interned, the "target" type variable is not interned yet
(possibly even not yet set) and can change later. This is one of the reasons
why type variable references are mutable, and that in turn requires that their
equality and hash code for interning purposes are based on identity.

Note that type variable references are only mutated during indexing. After
an `Index` is complete, type variable references must be considered "frozen".
@Ladicek Ladicek added this to the 3.0.1 milestone Sep 16, 2022
@Ladicek Ladicek merged commit c770f78 into smallrye:main Sep 16, 2022
@Ladicek Ladicek deleted the type-variable-reference-equality branch September 16, 2022 09:06
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.

Restore structural equality of the Type hierarchy
1 participant