mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
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.
This commit is contained in:
parent
26253acf1d
commit
b45c6c757c
1 changed files with 8 additions and 3 deletions
|
|
@ -370,12 +370,15 @@ pub fn HashMap(
|
||||||
comptime Context: type,
|
comptime Context: type,
|
||||||
comptime max_load_percentage: u64,
|
comptime max_load_percentage: u64,
|
||||||
) type {
|
) type {
|
||||||
comptime verifyContext(Context, K, K, u64, false);
|
|
||||||
return struct {
|
return struct {
|
||||||
unmanaged: Unmanaged,
|
unmanaged: Unmanaged,
|
||||||
allocator: Allocator,
|
allocator: Allocator,
|
||||||
ctx: Context,
|
ctx: Context,
|
||||||
|
|
||||||
|
comptime {
|
||||||
|
verifyContext(Context, K, K, u64, false);
|
||||||
|
}
|
||||||
|
|
||||||
/// The type of the unmanaged hash map underlying this wrapper
|
/// The type of the unmanaged hash map underlying this wrapper
|
||||||
pub const Unmanaged = HashMapUnmanaged(K, V, Context, max_load_percentage);
|
pub const Unmanaged = HashMapUnmanaged(K, V, Context, max_load_percentage);
|
||||||
/// An entry, containing pointers to a key and value stored in the map
|
/// An entry, containing pointers to a key and value stored in the map
|
||||||
|
|
@ -694,11 +697,13 @@ pub fn HashMapUnmanaged(
|
||||||
) type {
|
) type {
|
||||||
if (max_load_percentage <= 0 or max_load_percentage >= 100)
|
if (max_load_percentage <= 0 or max_load_percentage >= 100)
|
||||||
@compileError("max_load_percentage must be between 0 and 100.");
|
@compileError("max_load_percentage must be between 0 and 100.");
|
||||||
comptime verifyContext(Context, K, K, u64, false);
|
|
||||||
|
|
||||||
return struct {
|
return struct {
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
|
|
||||||
|
comptime {
|
||||||
|
verifyContext(Context, K, K, u64, false);
|
||||||
|
}
|
||||||
|
|
||||||
// This is actually a midway pointer to the single buffer containing
|
// This is actually a midway pointer to the single buffer containing
|
||||||
// a `Header` field, the `Metadata`s and `Entry`s.
|
// a `Header` field, the `Metadata`s and `Entry`s.
|
||||||
// At `-@sizeOf(Header)` is the Header field.
|
// At `-@sizeOf(Header)` is the Header field.
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue