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

hashlib: merge hash_ops with hash_top_ops for plugin compat #4849

Merged
merged 3 commits into from
Jan 21, 2025

Conversation

widlarizer
Copy link
Collaborator

When writing #4524 I made it so that a type can have an implementation for how to hash a single instance (hash_top_ops) distinct from one for how to hash an instance in the context of an on-going context (hash_ops). This PR implements @povik's idea to merge them together so that plugin code can still explicitly pass hash_ptr_ops into associative data structures like dict.

  • adjust docs/source/yosys_internals/hashing.rst to match

@widlarizer widlarizer requested a review from povik January 14, 2025 20:46
};
// Boilerplate compressor for trivially implementing
// top-level hash method with hash_into
#define HASH_TOP_LOOP_FST [[nodiscard]] static inline Hasher hash
Copy link
Member

Choose a reason for hiding this comment

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

Why not put all of the function into one macro, so that you would write e.g. DEFAULT_HASH_TOP(std::pair<P, Q> a) to use it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I tried doing this the simplest possible way I could think of, passing a type into a macro argument, and it wasn't valid preprocessor code for some reason. We can change this later

kernel/hashlib.h Outdated
@@ -245,6 +239,11 @@ struct hash_cstr_ops {
h.hash32(*(a++));
return h;
}
[[nodiscard]] static inline Hasher hash(const char *a) {
Copy link
Member

Choose a reason for hiding this comment

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

Why can't we use the macro here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

instead of calling the polymorphic h.eat(...) we explicitly call the hash_into method of self

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

as for why we do that, it's because I'm paranoid about pointer conversions

Copy link
Member

Choose a reason for hiding this comment

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

Can't we use hash_into in the macro helper?

@nakengelhardt nakengelhardt added the merge-before-release Merge: PR should be included in the next release label Jan 20, 2025
@povik povik self-requested a review January 20, 2025 15:22
@widlarizer widlarizer merged commit da5c20d into main Jan 21, 2025
37 checks passed
@mmicko mmicko deleted the emil/hashlib-merge-top-ops branch February 10, 2025 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge-before-release Merge: PR should be included in the next release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants