authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-03-31 19:05:24-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-04-01 00:17:02-07:00
logb45c6c757cb4a16f5021c8bf057d14183036f14c
tree1fd085e2222c1e760cf617112b955c1d4afef632
parent26253acf1ddcc2007804a3fbf538f3120e048547

std.hash_map: workaround for circular dependency

See #11367 It's debatable whether this ends up being a legitimate compile error or whether the lang spec allows this test case. For now this workaround seems very reasonable; delaying comptime execution of `verifyContext` until the struct is instantiated.

1 files changed, 8 insertions(+), 3 deletions(-)

lib/std/hash_map.zig+8-3
...@@ -370,12 +370,15 @@ pub fn HashMap(...@@ -370,12 +370,15 @@ pub fn HashMap(
370 comptime Context: type,370 comptime Context: type,
371 comptime max_load_percentage: u64,371 comptime max_load_percentage: u64,
372) type {372) type {
373 comptime verifyContext(Context, K, K, u64, false);
374 return struct {373 return struct {
375 unmanaged: Unmanaged,374 unmanaged: Unmanaged,
376 allocator: Allocator,375 allocator: Allocator,
377 ctx: Context,376 ctx: Context,
378377
378 comptime {
379 verifyContext(Context, K, K, u64, false);
380 }
381
379 /// The type of the unmanaged hash map underlying this wrapper382 /// The type of the unmanaged hash map underlying this wrapper
380 pub const Unmanaged = HashMapUnmanaged(K, V, Context, max_load_percentage);383 pub const Unmanaged = HashMapUnmanaged(K, V, Context, max_load_percentage);
381 /// An entry, containing pointers to a key and value stored in the map384 /// An entry, containing pointers to a key and value stored in the map
...@@ -694,11 +697,13 @@ pub fn HashMapUnmanaged(...@@ -694,11 +697,13 @@ pub fn HashMapUnmanaged(
694) type {697) type {
695 if (max_load_percentage <= 0 or max_load_percentage >= 100)698 if (max_load_percentage <= 0 or max_load_percentage >= 100)
696 @compileError("max_load_percentage must be between 0 and 100.");699 @compileError("max_load_percentage must be between 0 and 100.");
697 comptime verifyContext(Context, K, K, u64, false);
698
699 return struct {700 return struct {
700 const Self = @This();701 const Self = @This();
701702
703 comptime {
704 verifyContext(Context, K, K, u64, false);
705 }
706
702 // This is actually a midway pointer to the single buffer containing707 // This is actually a midway pointer to the single buffer containing
703 // a `Header` field, the `Metadata`s and `Entry`s.708 // a `Header` field, the `Metadata`s and `Entry`s.
704 // At `-@sizeOf(Header)` is the Header field.709 // At `-@sizeOf(Header)` is the Header field.