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

Implements both the Hasher and Write trait for any HighwayHash #30

Merged

Conversation

jRimbault
Copy link
Contributor

@jRimbault jRimbault commented Sep 23, 2020

I'm opening this PR not really to merge that as it is (I don't think this is good), but to open the discussion about how to best implement core::hash::Hasher on the different highway hasher structs.

This is a design proof of concept, but it changes a lot of things, both in HighwayHash trait API, and at runtime the Clone-ing of hasher structs. And I'm not too happy about these changes.

Edit:

Using macros instead of trait objects allows the same thing but without changing any of the API. I think this is better. Though, if you want those features is still up to you of course.

I feel like every hasher struct should implement the standard Hasher trait,
as it allows for more direct interoperability.

The Write implemented on top is more a general convenience for simple
hash function on objects implementing Read and Write:

  let mut reader = ...; // a file for example, anything Read-able
  let mut writer = ...; // any HighwayHash implementation
  std::io::copy(&mut reader, &mut writer)?;
  let hash = writer.finish();

There is surely a much better way to achieve both goals by refactoring
even more heavily the HighwayHash trait.
I think this is a better design, it doesn't change the current API.
Pinned primitive were in 1.43 ? I think ?
Anyhow, not really important I didn't even use it in the parameter
just above.
@nickbabcock
Copy link
Owner

(I'm moving to a new city so my responses have been slow and may continue to be slow for the next few days)

This PR looks good. I'll take a closer look when I can, but the only thing I'd like to see are tests demonstrating the the traits in action (preferably a test per trait per implementation so that we can be extra paranoid against any possible regressions).

@nickbabcock
Copy link
Owner

I can't play with the code right now, so let me know if core::hash:Hasher makes the current std::hash::Hasher redundant (and thus it can be removed)

@jRimbault
Copy link
Contributor Author

jRimbault commented Sep 25, 2020

Will do. Take all the time you need.

std::hash is an alias for core::hash, the distinction is mostly useful in no_std context. And I was wondering if you'd take a PR to make the crate no_std (via feature flag) ? Just looking around there doesn't seem to be anything blocking that.

@nickbabcock
Copy link
Owner

Yes, no_std would be lovely!

I don't understand why it failed on macos.
I hope to gain a bit of insight by seeing the results of the tests
in the other runners.
@jRimbault
Copy link
Contributor Author

jRimbault commented Sep 25, 2020

I'm a bit stumped on why the demo test fails on MacOS. I hoped it would fail on another runner with a more useful output, but no luck.

      Running `/Users/runner/work/highway-rs/highway-rs/target/debug/deps/traits-6e480f7ed0e55e51`

running 1 test
error: test failed, to rerun pass '--test traits'

Caused by:
  process didn't exit successfully: `/Users/runner/work/highway-rs/highway-rs/target/debug/deps/traits-6e480f7ed0e55e51` (signal: 4, SIGILL: illegal instruction)

@nickbabcock
Copy link
Owner

I believe it is because the macOS CI environment doesn't support avx instructions. You may need to explicitly test for hardware support before invoking, ie:

if is_x86_feature_detected!("avx2") {
  // run avx test
}

if is_x86_feature_detected!("sse4.1") {
  // run sse test
}

@nickbabcock
Copy link
Owner

Nice, looks like you've got it under control.

Another task: copy the docs written in the readme to lib.rs so that docs in the readme and on docs.rs remain in sync. Then unless you have anything else, I think this would be ready to be merged.

@jRimbault
Copy link
Contributor Author

jRimbault commented Oct 5, 2020

I think this PR is done.

I have another branch with no_std support for the PortableHash. I pulled it from my own branch so I'll have to trim it back from master.

@nickbabcock
Copy link
Owner

I have another branch with no_std support for the PortableHash

Nice! One thing to note is that SIMD instructions should still be available on core, afaik. What's not available is is_x86_feature_detected so it seems possible that one can continue using AvxHash::force_new on no_std (and have AvxHash::new return None). But we can talk about this more on the PR when you have it situated.

Thanks again! I'll cut a release once we have these features integrated.

@nickbabcock nickbabcock merged commit e069357 into nickbabcock:master Oct 5, 2020
@nickbabcock nickbabcock mentioned this pull request Oct 24, 2020
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.

2 participants