-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Refactor auto_hash.zig
#25722
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
base: master
Are you sure you want to change the base?
Refactor auto_hash.zig
#25722
Conversation
* Applied Zig-style naming conventions to functions and values
* Remove redundant namespacing
* `std.hash.autoHash` -> `std.hash.auto`
* `std.hash.autoHashStrat` -> `std.hash.autoStrat`
* `std.hash.HashStrategy` -> `std.hash.Strategy`
* Correct capitalization
* `std.hash.HashStrategy.Shallow` -> `std.hash.Strategy.Shallow`
* `std.hash.HashStrategy.Deep` -> `std.hash.Strategy.Deep`
* `std.hash.HashStrategy.DeepRecursive` -> `std.hash.Strategy.deep_recursive`
* All of the old identifiers are still available as deprecated aliases.
* Bug fix: Slices are now detected when nested within error unions, optionals,
and arrays. As a consequence of this, `std.hash.auto` may result in
a compile error in places where it previously did not. The previous
behavior was a bug, but this change is still technically breaking.
* Optimization: In general, `auto_hash.zig` avoids copying large values,
preferring to hash them in place. Moreover, `auto_hash.zig` is
generally smarter about directly using calling `hasher.update` on
values which have a unique representation. For instance, slices and
arrays of values with unique representations will undergo a direct
`@ptrCast` into a slice of bytes and hash all elements at once rather
than doing this individually for every element in the span.
* Cleaned up the implementation and tests, applying more current style
and language features where appropriate
This file made use of an auto hash map of SemanticVersions. Due to the recent fixes in `auto_hash.zig`, this is now a compile error, as `SemanticVersion` contains slices. This oversight previously went undetected, and simply hashed the slice slices by value if they were present. With this fix, the slices are explicitly hashed deeply.
For example, in |
Apologies for not not testing these changes locally, I have been unable to build Zig with LLVM, and thus have to rely on the CI to test building the compiler with LLVM enabled.
…nto auto-hash-refactor
|
Upon closer inspection, it looks like the CI is failing due to the bug which will be addressed in #25713. A |
|
I kept the logic for how values are hashed mostly the same, but there are a few details that we may want to address in follow up issues:
|
std.hash.autoHash->std.hash.autostd.hash.autoHashStrat->std.hash.autoStratstd.hash.HashStrategy->std.hash.Strategystd.hash.HashStrategy.Shallow->std.hash.Strategy.shallowstd.hash.HashStrategy.Deep->std.hash.Strategy.deepstd.hash.HashStrategy.DeepRecursive->std.hash.Strategy.deep_recursivestd.hash.automay result in a compile error in places where it previously did not. The previous behavior was a bug, but this change is still technically breaking.auto_hash.zigavoids copying large values, preferring to hash them in place. Moreover,auto_hash.zigis generally smarter about directly using callinghasher.updateon values which have a unique representation. For instance, slices and arrays of values with unique representations will undergo a direct@ptrCastinto a slice of bytes and hash all elements at once rather than doing this individually for every element in the span.