Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions lib/compiler/aro/backend/Interner.zig
Original file line number Diff line number Diff line change
Expand Up @@ -89,36 +89,33 @@ pub const Key = union(enum) {
};

pub fn hash(key: Key) u32 {
var hasher = Hash.init(0);
var hasher: Hash = .init(0);
const tag = std.meta.activeTag(key);
std.hash.autoHash(&hasher, tag);
std.hash.auto(&hasher, tag);
switch (key) {
.bytes => |bytes| {
hasher.update(bytes);
},
.record_ty => |elems| for (elems) |elem| {
std.hash.autoHash(&hasher, elem);
},
.record_ty => |elems| std.hash.autoStrat(&hasher, elems, .deep),
.float => |repr| switch (repr) {
inline else => |data| std.hash.autoHash(
inline else => |data| std.hash.auto(
&hasher,
@as(std.meta.Int(.unsigned, @bitSizeOf(@TypeOf(data))), @bitCast(data)),
),
},
.complex => |repr| switch (repr) {
inline else => |data| std.hash.autoHash(
inline else => |data| std.hash.auto(
&hasher,
@as(std.meta.Int(.unsigned, @bitSizeOf(@TypeOf(data))), @bitCast(data)),
),
},
.int => |repr| {
var space: Tag.Int.BigIntSpace = undefined;
const big = repr.toBigInt(&space);
std.hash.autoHash(&hasher, big.positive);
for (big.limbs) |limb| std.hash.autoHash(&hasher, limb);
std.hash.autoStrat(&hasher, big, .deep);
},
inline else => |info| {
std.hash.autoHash(&hasher, info);
std.hash.auto(&hasher, info);
},
}
return @truncate(hasher.final());
Expand Down
4 changes: 2 additions & 2 deletions lib/std/Build/Watch.zig
Original file line number Diff line number Diff line change
Expand Up @@ -868,8 +868,8 @@ pub const Match = struct {
pub const Context = struct {
pub fn hash(self: Context, a: Match) u32 {
_ = self;
var hasher = Hash.init(0);
std.hash.autoHash(&hasher, a.step);
var hasher: Hash = .init(0);
std.hash.auto(&hasher, a.step);
hasher.update(a.basename);
return @truncate(hasher.final());
}
Expand Down
9 changes: 4 additions & 5 deletions lib/std/array_hash_map.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const assert = debug.assert;
const testing = std.testing;
const math = std.math;
const mem = std.mem;
const autoHash = std.hash.autoHash;
const Wyhash = std.hash.Wyhash;
const Allocator = mem.Allocator;
const hash_map = @This();
Expand Down Expand Up @@ -2641,8 +2640,8 @@ pub fn getAutoHashFn(comptime K: type, comptime Context: type) (fn (Context, K)
if (std.meta.hasUniqueRepresentation(K)) {
return @truncate(Wyhash.hash(0, std.mem.asBytes(&key)));
} else {
var hasher = Wyhash.init(0);
autoHash(&hasher, key);
var hasher: Wyhash = .init(0);
std.hash.auto(&hasher, key);
return @truncate(hasher.final());
}
}
Expand Down Expand Up @@ -2681,8 +2680,8 @@ pub fn getAutoHashStratFn(comptime K: type, comptime Context: type, comptime str
return struct {
fn hash(ctx: Context, key: K) u32 {
_ = ctx;
var hasher = Wyhash.init(0);
std.hash.autoHashStrat(&hasher, key, strategy);
var hasher: Wyhash = .init(0);
std.hash.autoStrat(&hasher, key, strategy);
return @as(u32, @truncate(hasher.final()));
}
}.hash;
Expand Down
17 changes: 13 additions & 4 deletions lib/std/hash.zig
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
pub const Adler32 = @import("hash/Adler32.zig");

const auto_hash = @import("hash/auto_hash.zig");
pub const autoHash = auto_hash.autoHash;
pub const autoHashStrat = auto_hash.hash;
pub const Strategy = auto_hash.HashStrategy;
pub const auto = auto_hash.auto;
pub const autoStrat = auto_hash.autoStrat;
pub const Strategy = auto_hash.Strategy;

/// Deprecated alias for `Strategy`
pub const HashStrategy = Strategy;

/// Deprecated alias for `auto`
pub const autoHash = auto;

/// Deprecated alias for `autoStrat`
pub const autoHashStrat = autoStrat;

// pub for polynomials + generic crc32 construction
pub const crc = @import("hash/crc.zig");
Expand Down Expand Up @@ -44,7 +53,7 @@ pub fn int(input: anytype) @TypeOf(input) {
// Convert input to unsigned integer (easier to deal with)
const Uint = @Type(.{ .int = .{ .bits = bits, .signedness = .unsigned } });
const u_input: Uint = @bitCast(input);
if (bits > 256) @compileError("bit widths > 256 are unsupported, use std.hash.autoHash functionality.");
if (bits > 256) @compileError("bit widths > 256 are unsupported, use std.hash.auto functionality.");
// For bit widths that don't have a dedicated function, use a heuristic
// construction with a multiplier suited to diffusion -
// a mod 2^bits where a^2 - 46 * a + 1 = 0 mod 2^(bits + 4),
Expand Down
Loading