authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2025-05-21 12:56:08 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2025-05-21 12:56:08 -07:00
log7026667f5ba4a7489fbdb30979f399e4fff50481
tree21bd5f795a539dc16e9204ec6a5dc54bc4e89189
parent100510135aa7be25b8b465ac32450678de009103

update to Zig 0.14


21 files changed, 52 insertions(+), 52 deletions(-)

src/AnyReader.zig+2-2
...@@ -12,7 +12,7 @@ pub const AnyReader = struct {...@@ -12,7 +12,7 @@ pub const AnyReader = struct {
12 const ctx = reader.context;12 const ctx = reader.context;
13 const Ctx = @TypeOf(ctx);13 const Ctx = @TypeOf(ctx);
14 switch (@typeInfo(Ctx)) {14 switch (@typeInfo(Ctx)) {
15 .Pointer => {15 .pointer => {
16 const S = struct {16 const S = struct {
17 fn foo(s: *anyopaque, buffer: []u8) anyerror!usize {17 fn foo(s: *anyopaque, buffer: []u8) anyerror!usize {
18 const r = R{ .context = @ptrCast(@alignCast(s)) };18 const r = R{ .context = @ptrCast(@alignCast(s)) };
...@@ -24,7 +24,7 @@ pub const AnyReader = struct {...@@ -24,7 +24,7 @@ pub const AnyReader = struct {
24 .state = ctx,24 .state = ctx,
25 };25 };
26 },26 },
27 .Struct => switch (R) {27 .@"struct" => switch (R) {
28 std.fs.File.Reader => {28 std.fs.File.Reader => {
29 const S = struct {29 const S = struct {
30 fn foo(s: *anyopaque, buffer: []u8) anyerror!usize {30 fn foo(s: *anyopaque, buffer: []u8) anyerror!usize {
src/FieldUnion.zig+1-1
...@@ -14,7 +14,7 @@ pub fn FieldUnion(comptime T: type) type {...@@ -14,7 +14,7 @@ pub fn FieldUnion(comptime T: type) type {
14 .alignment = field.alignment,14 .alignment = field.alignment,
15 };15 };
16 }16 }
17 return @Type(std.builtin.Type{ .Union = .{17 return @Type(std.builtin.Type{ .@"union" = .{
18 .layout = .auto,18 .layout = .auto,
19 .tag_type = std.meta.FieldEnum(T),19 .tag_type = std.meta.FieldEnum(T),
20 .fields = &fields,20 .fields = &fields,
src/FlippedInt.zig+1-1
...@@ -4,7 +4,7 @@ const extras = @import("./lib.zig");...@@ -4,7 +4,7 @@ const extras = @import("./lib.zig");
44
5pub fn FlippedInt(comptime T: type) type {5pub fn FlippedInt(comptime T: type) type {
6 var info = @typeInfo(T);6 var info = @typeInfo(T);
7 info.Int.signedness = switch (info.Int.signedness) {7 info.int.signedness = switch (info.int.signedness) {
8 .signed => .unsigned,8 .signed => .unsigned,
9 .unsigned => .signed,9 .unsigned => .signed,
10 };10 };
src/OneBiggerInt.zig+1-1
...@@ -4,7 +4,7 @@ const extras = @import("./lib.zig");...@@ -4,7 +4,7 @@ const extras = @import("./lib.zig");
44
5pub fn OneBiggerInt(comptime T: type) type {5pub fn OneBiggerInt(comptime T: type) type {
6 var info = @typeInfo(T);6 var info = @typeInfo(T);
7 info.Int.bits += 1;7 info.int.bits += 1;
8 return @Type(info);8 return @Type(info);
9}9}
1010
src/OneSmallerInt.zig+1-1
...@@ -4,7 +4,7 @@ const extras = @import("./lib.zig");...@@ -4,7 +4,7 @@ const extras = @import("./lib.zig");
44
5pub fn OneSmallerInt(comptime T: type) type {5pub fn OneSmallerInt(comptime T: type) type {
6 var info = @typeInfo(T);6 var info = @typeInfo(T);
7 info.Int.bits -= 1;7 info.int.bits -= 1;
8 return @Type(info);8 return @Type(info);
9}9}
1010
src/Partial.zig+2-2
...@@ -12,12 +12,12 @@ pub fn Partial(comptime T: type) type {...@@ -12,12 +12,12 @@ pub fn Partial(comptime T: type) type {
12 fields_after[i] = std.builtin.Type.StructField{12 fields_after[i] = std.builtin.Type.StructField{
13 .name = item.name,13 .name = item.name,
14 .type = ?item.type,14 .type = ?item.type,
15 .default_value = &@as(?item.type, null),15 .default_value_ptr = &@as(?item.type, null),
16 .is_comptime = false,16 .is_comptime = false,
17 .alignment = @alignOf(?item.type),17 .alignment = @alignOf(?item.type),
18 };18 };
19 }19 }
20 return @Type(@unionInit(std.builtin.Type, "Struct", .{20 return @Type(@unionInit(std.builtin.Type, "struct", .{
21 .layout = .auto,21 .layout = .auto,
22 .backing_integer = null,22 .backing_integer = null,
23 .fields = &fields_after,23 .fields = &fields_after,
src/ReverseFields.zig+2-2
...@@ -4,14 +4,14 @@ const extras = @import("./lib.zig");...@@ -4,14 +4,14 @@ const extras = @import("./lib.zig");
4const expectSimilarType = extras.expectSimilarType;4const expectSimilarType = extras.expectSimilarType;
55
6pub fn ReverseFields(comptime T: type) type {6pub fn ReverseFields(comptime T: type) type {
7 var info = @typeInfo(T).Struct;7 var info = @typeInfo(T).@"struct";
8 const len = info.fields.len;8 const len = info.fields.len;
9 var fields: [len]std.builtin.Type.StructField = undefined;9 var fields: [len]std.builtin.Type.StructField = undefined;
10 for (0..len) |i| {10 for (0..len) |i| {
11 fields[i] = info.fields[len - 1 - i];11 fields[i] = info.fields[len - 1 - i];
12 }12 }
13 info.fields = &fields;13 info.fields = &fields;
14 return @Type(.{ .Struct = info });14 return @Type(.{ .@"struct" = info });
15}15}
1616
17test {17test {
src/StructOfArrays.zig+2-2
...@@ -10,13 +10,13 @@ pub fn StructOfArrays(len: usize, T: type) type {...@@ -10,13 +10,13 @@ pub fn StructOfArrays(len: usize, T: type) type {
10 new_fields[i] = .{10 new_fields[i] = .{
11 .name = item.name,11 .name = item.name,
12 .type = [len]item.type,12 .type = [len]item.type,
13 .default_value = null,13 .default_value_ptr = null,
14 .is_comptime = false,14 .is_comptime = false,
15 .alignment = @alignOf([len]item.type),15 .alignment = @alignOf([len]item.type),
16 };16 };
17 }17 }
18 const result = new_fields[0..fields.len];18 const result = new_fields[0..fields.len];
19 return @Type(@unionInit(std.builtin.Type, "Struct", .{19 return @Type(@unionInit(std.builtin.Type, "struct", .{
20 .layout = .auto,20 .layout = .auto,
21 .backing_integer = null,21 .backing_integer = null,
22 .fields = result,22 .fields = result,
src/StructOfSlices.zig+2-2
...@@ -10,13 +10,13 @@ pub fn StructOfSlices(T: type) type {...@@ -10,13 +10,13 @@ pub fn StructOfSlices(T: type) type {
10 new_fields[i] = .{10 new_fields[i] = .{
11 .name = item.name,11 .name = item.name,
12 .type = []const item.type,12 .type = []const item.type,
13 .default_value = null,13 .default_value_ptr = null,
14 .is_comptime = false,14 .is_comptime = false,
15 .alignment = @alignOf([]const item.type),15 .alignment = @alignOf([]const item.type),
16 };16 };
17 }17 }
18 const result = new_fields[0..fields.len];18 const result = new_fields[0..fields.len];
19 return @Type(@unionInit(std.builtin.Type, "Struct", .{19 return @Type(@unionInit(std.builtin.Type, "struct", .{
20 .layout = .auto,20 .layout = .auto,
21 .backing_integer = null,21 .backing_integer = null,
22 .fields = result,22 .fields = result,
src/expectSimilarType.zig+9-9
...@@ -7,9 +7,9 @@ pub fn expectSimilarType(comptime A: type, comptime B: type) !void {...@@ -7,9 +7,9 @@ pub fn expectSimilarType(comptime A: type, comptime B: type) !void {
7 const info_b = @typeInfo(B);7 const info_b = @typeInfo(B);
8 try std.testing.expect(std.meta.activeTag(info_a) == std.meta.activeTag(info_b));8 try std.testing.expect(std.meta.activeTag(info_a) == std.meta.activeTag(info_b));
99
10 if (info_a == .Struct) {10 if (info_a == .@"struct") {
11 const info_a_s = info_a.Struct;11 const info_a_s = info_a.@"struct";
12 const info_b_s = info_b.Struct;12 const info_b_s = info_b.@"struct";
1313
14 try std.testing.expect(info_a_s.layout == info_b_s.layout);14 try std.testing.expect(info_a_s.layout == info_b_s.layout);
15 try std.testing.expect(info_a_s.is_tuple == info_b_s.is_tuple);15 try std.testing.expect(info_a_s.is_tuple == info_b_s.is_tuple);
...@@ -24,9 +24,9 @@ pub fn expectSimilarType(comptime A: type, comptime B: type) !void {...@@ -24,9 +24,9 @@ pub fn expectSimilarType(comptime A: type, comptime B: type) !void {
2424
25 return;25 return;
26 }26 }
27 if (info_a == .Union) {27 if (info_a == .@"union") {
28 const info_a_u = info_a.Union;28 const info_a_u = info_a.@"union";
29 const info_b_u = info_b.Union;29 const info_b_u = info_b.@"union";
3030
31 try std.testing.expect(info_a_u.layout == info_b_u.layout);31 try std.testing.expect(info_a_u.layout == info_b_u.layout);
32 try expectSimilarType(info_a_u.tag_type.?, info_b_u.tag_type.?);32 try expectSimilarType(info_a_u.tag_type.?, info_b_u.tag_type.?);
...@@ -39,9 +39,9 @@ pub fn expectSimilarType(comptime A: type, comptime B: type) !void {...@@ -39,9 +39,9 @@ pub fn expectSimilarType(comptime A: type, comptime B: type) !void {
3939
40 return;40 return;
41 }41 }
42 if (info_a == .Enum) {42 if (info_a == .@"enum") {
43 const info_a_e = info_a.Enum;43 const info_a_e = info_a.@"enum";
44 const info_b_e = info_b.Enum;44 const info_b_e = info_b.@"enum";
4545
46 try std.testing.expect(info_a_e.tag_type == info_b_e.tag_type);46 try std.testing.expect(info_a_e.tag_type == info_b_e.tag_type);
47 try std.testing.expect(info_a_e.is_exhaustive == info_b_e.is_exhaustive);47 try std.testing.expect(info_a_e.is_exhaustive == info_b_e.is_exhaustive);
src/hasFn.zig+1-1
...@@ -8,7 +8,7 @@ pub fn hasFn(comptime name: []const u8) fn (type) bool {...@@ -8,7 +8,7 @@ pub fn hasFn(comptime name: []const u8) fn (type) bool {
8 if (!comptime extras.isContainer(T)) return false;8 if (!comptime extras.isContainer(T)) return false;
9 if (!comptime @hasDecl(T, name)) return false;9 if (!comptime @hasDecl(T, name)) return false;
10 const DeclType = @TypeOf(@field(T, name));10 const DeclType = @TypeOf(@field(T, name));
11 return @typeInfo(DeclType) == .Fn;11 return @typeInfo(DeclType) == .@"fn";
12 }12 }
13 };13 };
14 return Closure.trait;14 return Closure.trait;
src/isArrayOf.zig+1-1
...@@ -6,7 +6,7 @@ pub fn isArrayOf(comptime T: type) fn (type) bool {...@@ -6,7 +6,7 @@ pub fn isArrayOf(comptime T: type) fn (type) bool {
6 const Closure = struct {6 const Closure = struct {
7 pub fn trait(comptime C: type) bool {7 pub fn trait(comptime C: type) bool {
8 return switch (@typeInfo(C)) {8 return switch (@typeInfo(C)) {
9 .Array => |ti| ti.child == T,9 .array => |ti| ti.child == T,
10 else => false,10 else => false,
11 };11 };
12 }12 }
src/isContainer.zig+4-4
...@@ -4,10 +4,10 @@ const extras = @import("./lib.zig");...@@ -4,10 +4,10 @@ const extras = @import("./lib.zig");
44
5pub fn isContainer(comptime T: type) bool {5pub fn isContainer(comptime T: type) bool {
6 return switch (@typeInfo(T)) {6 return switch (@typeInfo(T)) {
7 .Struct,7 .@"struct",
8 .Union,8 .@"union",
9 .Enum,9 .@"enum",
10 .Opaque,10 .@"opaque",
11 => true,11 => true,
12 else => false,12 else => false,
13 };13 };
src/isIndexable.zig+5-5
...@@ -3,13 +3,13 @@ const string = []const u8;...@@ -3,13 +3,13 @@ const string = []const u8;
3const extras = @import("./lib.zig");3const extras = @import("./lib.zig");
44
5pub fn isIndexable(comptime T: type) bool {5pub fn isIndexable(comptime T: type) bool {
6 if (comptime is(.Pointer)(T)) {6 if (comptime is(.pointer)(T)) {
7 if (@typeInfo(T).Pointer.size == .One) {7 if (@typeInfo(T).pointer.size == .one) {
8 return (comptime is(.Array)(std.meta.Child(T)));8 return (comptime is(.array)(std.meta.Child(T)));
9 }9 }
10 return true;10 return true;
11 }11 }
12 return comptime is(.Array)(T) or is(.Vector)(T) or isTuple(T);12 return comptime is(.array)(T) or is(.vector)(T) or isTuple(T);
13}13}
14fn is(comptime id: std.builtin.TypeId) fn (type) bool {14fn is(comptime id: std.builtin.TypeId) fn (type) bool {
15 const Closure = struct {15 const Closure = struct {
...@@ -20,7 +20,7 @@ fn is(comptime id: std.builtin.TypeId) fn (type) bool {...@@ -20,7 +20,7 @@ fn is(comptime id: std.builtin.TypeId) fn (type) bool {
20 return Closure.trait;20 return Closure.trait;
21}21}
22fn isTuple(comptime T: type) bool {22fn isTuple(comptime T: type) bool {
23 return is(.Struct)(T) and @typeInfo(T).Struct.is_tuple;23 return is(.@"struct")(T) and @typeInfo(T).@"struct".is_tuple;
24}24}
2525
26test {26test {
src/isSlice.zig+3-3
...@@ -3,9 +3,9 @@ const string = []const u8;...@@ -3,9 +3,9 @@ const string = []const u8;
3const extras = @import("./lib.zig");3const extras = @import("./lib.zig");
44
5pub fn isSlice(comptime T: type) bool {5pub fn isSlice(comptime T: type) bool {
6 if (comptime is(.Pointer)(T)) {6 if (comptime is(.pointer)(T)) {
7 if (@typeInfo(T).Pointer.size == .Slice) return true;7 if (@typeInfo(T).pointer.size == .slice) return true;
8 if (@typeInfo(T).Pointer.size == .One and is(.Array)(std.meta.Child(T))) return true;8 if (@typeInfo(T).pointer.size == .one and is(.array)(std.meta.Child(T))) return true;
9 }9 }
10 return false;10 return false;
11}11}
src/isZigString.zig+6-6
...@@ -18,22 +18,22 @@ pub fn isZigString(comptime T: type) bool {...@@ -18,22 +18,22 @@ pub fn isZigString(comptime T: type) bool {
18 return comptime blk: {18 return comptime blk: {
19 // Only pointer types can be strings, no optionals19 // Only pointer types can be strings, no optionals
20 const info = @typeInfo(T);20 const info = @typeInfo(T);
21 if (info != .Pointer) break :blk false;21 if (info != .pointer) break :blk false;
2222
23 const ptr = &info.Pointer;23 const ptr = &info.pointer;
24 // Check for CV qualifiers that would prevent coerction to []const u824 // Check for CV qualifiers that would prevent coerction to []const u8
25 if (ptr.is_volatile or ptr.is_allowzero) break :blk false;25 if (ptr.is_volatile or ptr.is_allowzero) break :blk false;
2626
27 // If it's already a slice, simple check.27 // If it's already a slice, simple check.
28 if (ptr.size == .Slice) {28 if (ptr.size == .slice) {
29 break :blk ptr.child == u8;29 break :blk ptr.child == u8;
30 }30 }
3131
32 // Otherwise check if it's an array type that coerces to slice.32 // Otherwise check if it's an array type that coerces to slice.
33 if (ptr.size == .One) {33 if (ptr.size == .one) {
34 const child = @typeInfo(ptr.child);34 const child = @typeInfo(ptr.child);
35 if (child == .Array) {35 if (child == .array) {
36 const arr = &child.Array;36 const arr = &child.array;
37 break :blk arr.child == u8;37 break :blk arr.child == u8;
38 }38 }
39 }39 }
src/pipe.zig+1-1
...@@ -3,7 +3,7 @@ const string = []const u8;...@@ -3,7 +3,7 @@ const string = []const u8;
3const extras = @import("./lib.zig");3const extras = @import("./lib.zig");
44
5pub fn pipe(reader_from: anytype, writer_to: anytype) !void {5pub fn pipe(reader_from: anytype, writer_to: anytype) !void {
6 var buf: [std.mem.page_size]u8 = undefined;6 var buf: [std.heap.page_size_min]u8 = undefined;
7 var fifo = std.fifo.LinearFifo(u8, .Slice).init(&buf);7 var fifo = std.fifo.LinearFifo(u8, .Slice).init(&buf);
8 defer fifo.deinit();8 defer fifo.deinit();
9 try fifo.pump(reader_from, writer_to);9 try fifo.pump(reader_from, writer_to);
src/randomSlice.zig+1-1
...@@ -4,7 +4,7 @@ const extras = @import("./lib.zig");...@@ -4,7 +4,7 @@ const extras = @import("./lib.zig");
44
5const alphabet = "0123456789abcdefghijklmnopqrstuvwxyz";5const alphabet = "0123456789abcdefghijklmnopqrstuvwxyz";
66
7pub fn randomSlice(alloc: std.mem.Allocator, rand: std.rand.Random, comptime T: type, len: usize) ![]T {7pub fn randomSlice(alloc: std.mem.Allocator, rand: std.Random, comptime T: type, len: usize) ![]T {
8 var buf = try alloc.alloc(T, len);8 var buf = try alloc.alloc(T, len);
9 var i: usize = 0;9 var i: usize = 0;
10 while (i < len) : (i += 1) {10 while (i < len) : (i += 1) {
src/rawInt.zig+1-1
...@@ -5,7 +5,7 @@ const builtin = @import("builtin");...@@ -5,7 +5,7 @@ const builtin = @import("builtin");
5const native_endian = builtin.target.cpu.arch.endian();5const native_endian = builtin.target.cpu.arch.endian();
66
7pub fn rawInt(comptime T: type, comptime literal: comptime_int) T {7pub fn rawInt(comptime T: type, comptime literal: comptime_int) T {
8 comptime std.debug.assert(@typeInfo(T).Int.bits % 8 == 0);8 comptime std.debug.assert(@typeInfo(T).int.bits % 8 == 0);
9 return switch (native_endian) {9 return switch (native_endian) {
10 .little => @byteSwap(@as(T, literal)),10 .little => @byteSwap(@as(T, literal)),
11 .big => @compileError("unreachable"),11 .big => @compileError("unreachable"),
src/readType.zig+4-4
...@@ -8,7 +8,7 @@ const rawIntBytes = extras.rawIntBytes;...@@ -8,7 +8,7 @@ const rawIntBytes = extras.rawIntBytes;
8pub fn readType(reader: anytype, comptime T: type, endian: std.builtin.Endian) !T {8pub fn readType(reader: anytype, comptime T: type, endian: std.builtin.Endian) !T {
9 if (T == u8) return reader.readByte(); // single bytes dont have an endianness9 if (T == u8) return reader.readByte(); // single bytes dont have an endianness
10 return switch (@typeInfo(T)) {10 return switch (@typeInfo(T)) {
11 .Struct => |t| {11 .@"struct" => |t| {
12 switch (t.layout) {12 switch (t.layout) {
13 .auto, .@"extern" => {13 .auto, .@"extern" => {
14 var s: T = undefined;14 var s: T = undefined;
...@@ -20,15 +20,15 @@ pub fn readType(reader: anytype, comptime T: type, endian: std.builtin.Endian) !...@@ -20,15 +20,15 @@ pub fn readType(reader: anytype, comptime T: type, endian: std.builtin.Endian) !
20 .@"packed" => return @bitCast(try readType(reader, t.backing_integer.?, endian)),20 .@"packed" => return @bitCast(try readType(reader, t.backing_integer.?, endian)),
21 }21 }
22 },22 },
23 .Array => |t| {23 .array => |t| {
24 var s: T = undefined;24 var s: T = undefined;
25 for (0..t.len) |i| {25 for (0..t.len) |i| {
26 s[i] = try readType(reader, t.child, endian);26 s[i] = try readType(reader, t.child, endian);
27 }27 }
28 return s;28 return s;
29 },29 },
30 .Int => try reader.readInt(T, endian),30 .int => try reader.readInt(T, endian),
31 .Enum => |t| @enumFromInt(try readType(reader, t.tag_type, endian)),31 .@"enum" => |t| @enumFromInt(try readType(reader, t.tag_type, endian)),
32 else => |e| @compileError(@tagName(e)),32 else => |e| @compileError(@tagName(e)),
33 };33 };
34}34}
src/sliceToInt.zig+2-2
...@@ -3,8 +3,8 @@ const string = []const u8;...@@ -3,8 +3,8 @@ const string = []const u8;
3const extras = @import("./lib.zig");3const extras = @import("./lib.zig");
44
5pub fn sliceToInt(comptime T: type, comptime E: type, slice: []const E) !T {5pub fn sliceToInt(comptime T: type, comptime E: type, slice: []const E) !T {
6 const a = @typeInfo(T).Int.bits;6 const a = @typeInfo(T).int.bits;
7 const b = @typeInfo(E).Int.bits;7 const b = @typeInfo(E).int.bits;
8 if (a < b * slice.len) return error.Overflow;8 if (a < b * slice.len) return error.Overflow;
99
10 var n: T = 0;10 var n: T = 0;