Skip to content

Update hash-map.dd #4246

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Update hash-map.dd #4246

wants to merge 2 commits into from

Conversation

fieldvoid
Copy link
Contributor

This update is in reference to #4245.

The spec currently says that for classes to be used as keys in associative arrays, they must override toHash and opEquals. This is untrue because the default implementations use the address of the class instance for computing the hash and for comparisons.

This update is in reference to <dlang#4245>.

The spec currently says that for classes to be used as keys in associative arrays, they *must* override toHash and opEquals. This is untrue because the default implementations use the address of the class instance for computing the hash and for comparisons.
@dlang-bot
Copy link
Contributor

Thanks for your pull request and interest in making D better, @fieldvoid! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

spec/hash-map.dd Outdated
@@ -109,6 +108,8 @@ $(H2 $(LNAME2 using_classes_as_key, Using Classes as the KeyType))
}
}
---
The default implementations of $(D toHash) and $(D opEquals) for classes use $(D is)
semantics (the address of the class instance is used to compute the hash, and the address of the class instance is used for comparisons).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

opEquals uses is semantics, toHash doesn't.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The more accurate thing to say is that the default opEquals compares the addresses of the objects and that toHash hashes the address of the object (so both ignore the value of the object itself). opEquals does use is to do that, but AFAIK, the spec doesn't use the term "is semantics" anywhere, and is doesn't need to be explicitly mentioned to make the behavior clear.

Edited based on jmdavis' (https://github.com/jmdavis) input to more accurately reflect what takes place.
@fieldvoid
Copy link
Contributor Author

I've edited it, thanks

@fieldvoid fieldvoid requested a review from ntrel June 4, 2025 21:00
@jmdavis jmdavis added the 72h no objection -> merge The PR will be merged if there are no objections raised. label Jun 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
72h no objection -> merge The PR will be merged if there are no objections raised.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants