-
Notifications
You must be signed in to change notification settings - Fork 906
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
Conversation
}; | ||
// Boilerplate compressor for trivially implementing | ||
// top-level hash method with hash_into | ||
#define HASH_TOP_LOOP_FST [[nodiscard]] static inline Hasher hash |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
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 passhash_ptr_ops
into associative data structures likedict
.docs/source/yosys_internals/hashing.rst
to match