Skip to content
Merged
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
29 changes: 29 additions & 0 deletions lib/std/array_hash_map.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2336,6 +2336,35 @@ test "sort" {
}
}

test "0 sized key" {
var map = AutoArrayHashMap(u0, i32).init(std.testing.allocator);
defer map.deinit();

try testing.expectEqual(map.get(0), null);

try map.put(0, 5);
try testing.expectEqual(map.get(0), 5);

try map.put(0, 10);
try testing.expectEqual(map.get(0), 10);

try testing.expectEqual(map.swapRemove(0), true);
try testing.expectEqual(map.get(0), null);
}

test "0 sized key and 0 sized value" {
var map = AutoArrayHashMap(u0, u0).init(std.testing.allocator);
defer map.deinit();

try testing.expectEqual(map.get(0), null);

try map.put(0, 0);
try testing.expectEqual(map.get(0), 0);

try testing.expectEqual(map.swapRemove(0), true);
try testing.expectEqual(map.get(0), null);
}

pub fn getHashPtrAddrFn(comptime K: type, comptime Context: type) (fn (Context, K) u32) {
return struct {
fn hash(ctx: Context, key: K) u32 {
Expand Down
49 changes: 49 additions & 0 deletions lib/std/multi_array_list.zig
Original file line number Diff line number Diff line change
Expand Up @@ -901,3 +901,52 @@ test "sorting a span" {
c += 1;
}
}

test "0 sized struct field" {
const ally = testing.allocator;

const Foo = struct {
a: u0,
b: f32,
};

var list = MultiArrayList(Foo){};
defer list.deinit(ally);

try testing.expectEqualSlices(u0, &[_]u0{}, list.items(.a));
try testing.expectEqualSlices(f32, &[_]f32{}, list.items(.b));

try list.append(ally, .{ .a = 0, .b = 42.0 });
try testing.expectEqualSlices(u0, &[_]u0{0}, list.items(.a));
try testing.expectEqualSlices(f32, &[_]f32{42.0}, list.items(.b));

try list.insert(ally, 0, .{ .a = 0, .b = -1.0 });
try testing.expectEqualSlices(u0, &[_]u0{ 0, 0 }, list.items(.a));
try testing.expectEqualSlices(f32, &[_]f32{ -1.0, 42.0 }, list.items(.b));

list.swapRemove(list.len - 1);
try testing.expectEqualSlices(u0, &[_]u0{0}, list.items(.a));
try testing.expectEqualSlices(f32, &[_]f32{-1.0}, list.items(.b));
}

test "0 sized struct" {
const ally = testing.allocator;

const Foo = struct {
a: u0,
};

var list = MultiArrayList(Foo){};
defer list.deinit(ally);

try testing.expectEqualSlices(u0, &[_]u0{}, list.items(.a));

try list.append(ally, .{ .a = 0 });
try testing.expectEqualSlices(u0, &[_]u0{0}, list.items(.a));

try list.insert(ally, 0, .{ .a = 0 });
try testing.expectEqualSlices(u0, &[_]u0{ 0, 0 }, list.items(.a));

list.swapRemove(list.len - 1);
try testing.expectEqualSlices(u0, &[_]u0{0}, list.items(.a));
}
4 changes: 1 addition & 3 deletions src/InternPool.zig
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ string_table: std.HashMapUnmanaged(
std.hash_map.default_max_load_percentage,
) = .{},

/// TODO: after https://github.com/ziglang/zig/issues/10618 is solved,
/// change store_hash to false.
const FieldMap = std.ArrayHashMapUnmanaged(void, void, std.array_hash_map.AutoContext(void), true);
const FieldMap = std.ArrayHashMapUnmanaged(void, void, std.array_hash_map.AutoContext(void), false);

const builtin = @import("builtin");
const std = @import("std");
Expand Down
3 changes: 3 additions & 0 deletions stage1/zig.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,13 @@ typedef char bool;

#if zig_has_attribute(weak) || defined(zig_gnuc)
#define zig_weak_linkage __attribute__((weak))
#define zig_weak_linkage_fn __attribute__((weak))
#elif _MSC_VER
#define zig_weak_linkage __declspec(selectany)
#define zig_weak_linkage_fn
#else
#define zig_weak_linkage zig_weak_linkage_unavailable
#define zig_weak_linkage_fn zig_weak_linkage_unavailable
#endif

#if zig_has_builtin(trap)
Expand Down
Binary file modified stage1/zig1.wasm
Binary file not shown.