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(
370370 comptime Context: type,
371371 comptime max_load_percentage: u64,
372372) type {
373 comptime verifyContext(Context, K, K, u64, false);
374373 return struct {
375374 unmanaged: Unmanaged,
376375 allocator: Allocator,
377376 ctx: Context,
378377
378 comptime {
379 verifyContext(Context, K, K, u64, false);
380 }
381
379382 /// The type of the unmanaged hash map underlying this wrapper
380383 pub const Unmanaged = HashMapUnmanaged(K, V, Context, max_load_percentage);
381384 /// An entry, containing pointers to a key and value stored in the map
......@@ -694,11 +697,13 @@ pub fn HashMapUnmanaged(
694697) type {
695698 if (max_load_percentage <= 0 or max_load_percentage >= 100)
696699 @compileError("max_load_percentage must be between 0 and 100.");
697 comptime verifyContext(Context, K, K, u64, false);
698
699700 return struct {
700701 const Self = @This();
701702
703 comptime {
704 verifyContext(Context, K, K, u64, false);
705 }
706
702707 // This is actually a midway pointer to the single buffer containing
703708 // a `Header` field, the `Metadata`s and `Entry`s.
704709 // At `-@sizeOf(Header)` is the Header field.