authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-03-21 19:33:43-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-03-21 19:40:56-07:00
logebec7336e23404ab091d34303055cd3b8a0088a5
tree712d01c4b0ad18e99b19029a0aa13b51882aa361
parent1e46e36eac8cbaf1c011d9753830eb807c386e67

std.array_hash_map: remove meta context verification

The zig way is to let the compiler provide errors, rather than trying to implement the compiler in the standard library. I played around with this and found the compile errors to be easier to comprehend without this logic.

1 files changed, 5 insertions(+), 20 deletions(-)

lib/std/array_hash_map.zig+5-20
...@@ -529,10 +529,6 @@ pub fn ArrayHashMapUnmanaged(...@@ -529,10 +529,6 @@ pub fn ArrayHashMapUnmanaged(
529 /// Used to detect memory safety violations.529 /// Used to detect memory safety violations.
530 pointer_stability: std.debug.SafetyLock = .{},530 pointer_stability: std.debug.SafetyLock = .{},
531531
532 comptime {
533 std.hash_map.verifyContext(Context, K, K, u32, true);
534 }
535
536 /// Modifying the key is allowed only if it does not change the hash.532 /// Modifying the key is allowed only if it does not change the hash.
537 /// Modifying the value is allowed.533 /// Modifying the value is allowed.
538 /// Entry pointers become invalid whenever this ArrayHashMap is modified,534 /// Entry pointers become invalid whenever this ArrayHashMap is modified,
...@@ -1847,27 +1843,16 @@ pub fn ArrayHashMapUnmanaged(...@@ -1847,27 +1843,16 @@ pub fn ArrayHashMapUnmanaged(
1847 }1843 }
1848 }1844 }
18491845
1850 inline fn checkedHash(ctx: anytype, key: anytype) u32 {1846 fn checkedHash(ctx: anytype, key: anytype) u32 {
1851 comptime std.hash_map.verifyContext(@TypeOf(ctx), @TypeOf(key), K, u32, true);
1852 // If you get a compile error on the next line, it means that your1847 // If you get a compile error on the next line, it means that your
1853 // generic hash function doesn't accept your key.1848 // generic hash function doesn't accept your key.
1854 const hash = ctx.hash(key);1849 return ctx.hash(key);
1855 if (@TypeOf(hash) != u32) {
1856 @compileError("Context " ++ @typeName(@TypeOf(ctx)) ++ " has a generic hash function that returns the wrong type!\n" ++
1857 @typeName(u32) ++ " was expected, but found " ++ @typeName(@TypeOf(hash)));
1858 }
1859 return hash;
1860 }1850 }
1861 inline fn checkedEql(ctx: anytype, a: anytype, b: K, b_index: usize) bool {1851
1862 comptime std.hash_map.verifyContext(@TypeOf(ctx), @TypeOf(a), K, u32, true);1852 fn checkedEql(ctx: anytype, a: anytype, b: K, b_index: usize) bool {
1863 // If you get a compile error on the next line, it means that your1853 // If you get a compile error on the next line, it means that your
1864 // generic eql function doesn't accept (self, adapt key, K, index).1854 // generic eql function doesn't accept (self, adapt key, K, index).
1865 const eql = ctx.eql(a, b, b_index);1855 return ctx.eql(a, b, b_index);
1866 if (@TypeOf(eql) != bool) {
1867 @compileError("Context " ++ @typeName(@TypeOf(ctx)) ++ " has a generic eql function that returns the wrong type!\n" ++
1868 @typeName(bool) ++ " was expected, but found " ++ @typeName(@TypeOf(eql)));
1869 }
1870 return eql;
1871 }1856 }
18721857
1873 fn dumpState(self: Self, comptime keyFmt: []const u8, comptime valueFmt: []const u8) void {1858 fn dumpState(self: Self, comptime keyFmt: []const u8, comptime valueFmt: []const u8) void {