-
Notifications
You must be signed in to change notification settings - Fork 375
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
Make portable implementation const
#439
base: master
Are you sure you want to change the base?
Conversation
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.
FYI: I'm not a maintainer of this library, but I do like to keep up to date with some of the going-ons.
@@ -120,7 +119,7 @@ pub fn compress_xof( | |||
crate::platform::le_bytes_from_words_64(&state) | |||
} | |||
|
|||
pub fn hash1<const N: usize>( | |||
const fn hash1<const N: usize>( |
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.
Removal of pub
intended?
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.
Not really, but since there are a few other backends with the same function and in all cases it is internal implementation without pub
(here too), I decided to remove it for consistency too. Happy to restore if maintainers have strong opinion on this one.
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.
Thanks for review, appreciate it!
@@ -120,7 +119,7 @@ pub fn compress_xof( | |||
crate::platform::le_bytes_from_words_64(&state) | |||
} | |||
|
|||
pub fn hash1<const N: usize>( | |||
const fn hash1<const N: usize>( |
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.
Not really, but since there are a few other backends with the same function and in all cases it is internal implementation without pub
(here too), I decided to remove it for consistency too. Happy to restore if maintainers have strong opinion on this one.
b3eb262
to
d80acb3
Compare
@oconnor663 it'd be great to get your attention here, especially since the changes are fairly simple |
Ping 🙂 |
I have implemented public const functions too and added them to tests against reference implementation, everything passes. Just rebased against @oconnor663 would be great if you can find time to look at this, especially since all tests are passing. |
Hm... I see a31e519 says that true MSRV is 1.66.0, if that is the case I can put new features behind feature flag or maybe MSRV can be increased (1.77.0 is what is needed here I believe, which was released almost a year ago). UPD: 1.83.0 is needed actually. |
Apologies for not reviewing this more promptly. You might already have noticed that I just pushed the CI-tested MSRV to 1.78 (for the |
Just discovered 1.83.0 is what is needed for |
Okay, so |
I'm leaning against taking these changes. It looks like a lot of complicated logic has to be duplicated, and much of that logic (like That said, my gut level, haven't-spent-much-time-with-the-feature impression of const generics is that it's still too early to rely heavily on them. Errors like this feel silly to me:
Another minimim-viable-feature for me would be basic arithmetic in const parameters, which doesn't work today: struct Hasher<const LEN: usize> {
state: [u8; LEN * 2], // error: generic parameters may not be used in const operations
} Does all that sound reasonable? |
The bigger problem is not SIMD, but rather lack of generics support, which means there is no way to avoid duplication. This is also the reason why you can't use basic iterators with
It works on Nightly, this is one ofthe many features I enjoy on Nightly for a long time. But it is not really required here. While code duplication is unfortunate and undesirable, there is a substantial benefit for having the same functions available in the official crate with In the latest revision I have feature-gates most of the new code, so it is easier to review and I understand if you're not going to accept this, but I am hopeful that there is a way to get it in. Raising MSRV to 1.85.0 and bumping major version would immediately remove the feature flag and all conditional compilation, but I'm not sure if you want everyone to be able to use older Rust versions with the latest versions of the crate. |
I was going to use BLAKE3 in
const
environment, but it doesn't support such use case yet.This relatively small PR refactors portable implementation to make it work in
const
environment.There is a bit of trivially verifiable
unsafe
due to nicer APIs not yet available inconst
environment, but these all work on stable.arrayref
were hard to read and used slicing that is not compatible withconst
, so I replaced it with a couple simple macros where it was necessary and left other usages as is.UPD: I decided to implement the whole thing, added
const_hash
,const_keyed_hash
andconst_derive_key
functions by copying the originals and modifying them to useconst fn
portable implementation.I didn't add
ConstHasher
, though it is possible too if someone needs it.Resolves #440