@zigc/lib 0.17.0-dev.644 → 0.17.0-dev.657
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/compiler/Maker/ScannedConfig.zig +4 -3
- package/compiler/Maker/Step/FindProgram.zig +2 -2
- package/compiler/Maker/Watch/FsEvents.zig +3 -2
- package/compiler/aro/aro/Attribute.zig +52 -51
- package/compiler/aro/aro/Compilation.zig +5 -5
- package/compiler/aro/aro/Diagnostics.zig +7 -7
- package/compiler/aro/aro/Parser.zig +2 -2
- package/compiler/aro/aro/Tree.zig +11 -11
- package/compiler/aro/aro/features.zig +4 -4
- package/compiler/aro/aro/text_literal.zig +2 -2
- package/compiler/aro/backend/Interner.zig +14 -13
- package/compiler/configurer.zig +2 -2
- package/compiler/resinator/bmp.zig +3 -2
- package/compiler/resinator/code_pages.zig +14 -12
- package/compiler/resinator/cvtres.zig +11 -10
- package/compiler/resinator/errors.zig +18 -22
- package/compiler/resinator/lang.zig +7 -7
- package/compiler/resinator/parse.zig +1 -1
- package/compiler/translate-c/ast.zig +6 -6
- package/docs/wasm/markdown/Document.zig +3 -3
- package/docs/wasm/markdown/Parser.zig +3 -3
- package/package.json +1 -1
- package/std/Build/Cache.zig +2 -2
- package/std/Build/Configuration.zig +19 -16
- package/std/Build/Step/ConfigHeader.zig +3 -2
- package/std/Build/Step/Options.zig +28 -22
- package/std/Build.zig +52 -53
- package/std/Io/Kqueue.zig +2 -2
- package/std/Io/Reader.zig +1 -1
- package/std/Io/Threaded.zig +18 -15
- package/std/Io/Uring.zig +2 -2
- package/std/Io/Writer.zig +18 -18
- package/std/Io/net.zig +3 -1
- package/std/Io.zig +7 -6
- package/std/Progress.zig +2 -2
- package/std/Target/aarch64.zig +2 -2
- package/std/Target/alpha.zig +2 -2
- package/std/Target/amdgcn.zig +2 -2
- package/std/Target/arc.zig +2 -2
- package/std/Target/arm.zig +2 -2
- package/std/Target/avr.zig +2 -2
- package/std/Target/bpf.zig +2 -2
- package/std/Target/csky.zig +2 -2
- package/std/Target/hexagon.zig +2 -2
- package/std/Target/hppa.zig +2 -2
- package/std/Target/kvx.zig +2 -2
- package/std/Target/lanai.zig +2 -2
- package/std/Target/loongarch.zig +2 -2
- package/std/Target/m68k.zig +2 -2
- package/std/Target/mips.zig +2 -2
- package/std/Target/msp430.zig +2 -2
- package/std/Target/nvptx.zig +2 -2
- package/std/Target/powerpc.zig +2 -2
- package/std/Target/propeller.zig +2 -2
- package/std/Target/riscv.zig +2 -2
- package/std/Target/s390x.zig +2 -2
- package/std/Target/sparc.zig +2 -2
- package/std/Target/spirv.zig +2 -2
- package/std/Target/ve.zig +2 -2
- package/std/Target/wasm.zig +2 -2
- package/std/Target/x86.zig +2 -2
- package/std/Target/xcore.zig +2 -2
- package/std/Target/xtensa.zig +2 -2
- package/std/Target.zig +4 -4
- package/std/c/darwin.zig +1 -1
- package/std/coff.zig +1 -1
- package/std/crypto/codecs/asn1/Oid.zig +8 -8
- package/std/crypto/codecs/asn1/der/Decoder.zig +7 -7
- package/std/crypto/codecs/asn1/der/Encoder.zig +10 -8
- package/std/crypto/phc_encoding.zig +23 -20
- package/std/crypto/timing_safe.zig +1 -1
- package/std/crypto/tls/Client.zig +3 -3
- package/std/crypto/tls.zig +1 -1
- package/std/debug/Dwarf/Unwind/VirtualMachine.zig +11 -5
- package/std/debug/ElfFile.zig +12 -8
- package/std/debug/MachOFile.zig +2 -2
- package/std/debug/SelfInfo/MachO.zig +2 -2
- package/std/debug/SelfInfo/Windows.zig +2 -2
- package/std/elf.zig +7 -7
- package/std/enums.zig +66 -67
- package/std/gpu.zig +1 -1
- package/std/hash/auto_hash.zig +8 -8
- package/std/hash/verify.zig +3 -3
- package/std/http/Client.zig +2 -2
- package/std/json/Stringify.zig +14 -14
- package/std/json/static.zig +47 -31
- package/std/lang.zig +65 -97
- package/std/math.zig +2 -2
- package/std/mem/Allocator.zig +9 -9
- package/std/mem.zig +86 -102
- package/std/meta/trailer_flags.zig +26 -19
- package/std/meta.zig +131 -171
- package/std/multi_array_list.zig +49 -57
- package/std/os/uefi/protocol/device_path.zig +8 -7
- package/std/os/uefi/tables/boot_services.zig +1 -1
- package/std/os/windows.zig +9 -15
- package/std/start.zig +6 -6
- package/std/testing/Smith.zig +35 -21
- package/std/testing.zig +15 -15
- package/std/zig/Ast.zig +4 -4
- package/std/zig/AstGen.zig +42 -42
- package/std/zig/ErrorBundle.zig +16 -13
- package/std/zig/LibCInstallation.zig +11 -11
- package/std/zig/Parse.zig +6 -6
- package/std/zig/Zir.zig +10 -10
- package/std/zig/c_translation/helpers.zig +2 -2
- package/std/zig/llvm/BitcodeReader.zig +3 -3
- package/std/zig/llvm/Builder.zig +124 -93
- package/std/zig/llvm/bitcode_writer.zig +4 -4
- package/std/zig/system/windows.zig +11 -11
- package/std/zig/system.zig +4 -4
- package/std/zig.zig +4 -4
- package/std/zon/Serializer.zig +28 -23
- package/std/zon/parse.zig +58 -61
|
@@ -115,22 +115,23 @@ pub fn deserialize(comptime HashResult: type, str: []const u8) Error!HashResult
|
|
|
115
115
|
while (it_params.next()) |params| {
|
|
116
116
|
const param = kvSplit(params) catch break;
|
|
117
117
|
var found = false;
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
118
|
+
const info = @typeInfo(HashResult).@"struct";
|
|
119
|
+
inline for (info.field_names, info.field_types) |p_name, p_type| {
|
|
120
|
+
if (mem.eql(u8, p_name, param.key)) {
|
|
121
|
+
switch (@typeInfo(p_type)) {
|
|
122
|
+
.int => @field(out, p_name) = fmt.parseUnsigned(
|
|
123
|
+
p_type,
|
|
123
124
|
param.value,
|
|
124
125
|
10,
|
|
125
126
|
) catch return Error.InvalidEncoding,
|
|
126
127
|
.pointer => |ptr| {
|
|
127
|
-
if (!ptr.
|
|
128
|
-
@field(out,
|
|
128
|
+
if (!ptr.attrs.@"const") @compileError("Value slice must be constant");
|
|
129
|
+
@field(out, p_name) = param.value;
|
|
129
130
|
},
|
|
130
|
-
.@"struct" => try @field(out,
|
|
131
|
+
.@"struct" => try @field(out, p_name).fromB64(param.value),
|
|
131
132
|
else => std.debug.panic(
|
|
132
133
|
"Value for [{s}] must be an integer, a constant slice or a BinValue",
|
|
133
|
-
.{
|
|
134
|
+
.{p_name},
|
|
134
135
|
),
|
|
135
136
|
}
|
|
136
137
|
set_fields += 1;
|
|
@@ -167,8 +168,9 @@ pub fn deserialize(comptime HashResult: type, str: []const u8) Error!HashResult
|
|
|
167
168
|
// Check that all the required fields have been set, excluding optional values and parameters
|
|
168
169
|
// with default values
|
|
169
170
|
var expected_fields: usize = 0;
|
|
170
|
-
|
|
171
|
-
|
|
171
|
+
const info = @typeInfo(HashResult).@"struct";
|
|
172
|
+
inline for (info.field_types, info.field_attrs) |p_type, p_attrs| {
|
|
173
|
+
if (@typeInfo(p_type) != .optional and p_attrs.default_value_ptr == null) {
|
|
172
174
|
expected_fields += 1;
|
|
173
175
|
}
|
|
174
176
|
}
|
|
@@ -228,21 +230,22 @@ fn serializeTo(params: anytype, out: *std.Io.Writer) !void {
|
|
|
228
230
|
}
|
|
229
231
|
|
|
230
232
|
var has_params = false;
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
mem.eql(u8,
|
|
235
|
-
mem.eql(u8,
|
|
233
|
+
const info = @typeInfo(HashResult).@"struct";
|
|
234
|
+
inline for (info.field_names, info.field_types) |p_name, p_type| {
|
|
235
|
+
if (comptime !(mem.eql(u8, p_name, "alg_id") or
|
|
236
|
+
mem.eql(u8, p_name, "alg_version") or
|
|
237
|
+
mem.eql(u8, p_name, "hash") or
|
|
238
|
+
mem.eql(u8, p_name, "salt")))
|
|
236
239
|
{
|
|
237
|
-
const value = @field(params,
|
|
240
|
+
const value = @field(params, p_name);
|
|
238
241
|
try out.writeAll(if (has_params) params_delimiter else fields_delimiter);
|
|
239
|
-
if (@typeInfo(
|
|
242
|
+
if (@typeInfo(p_type) == .@"struct") {
|
|
240
243
|
var buf: [@TypeOf(value).max_encoded_length]u8 = undefined;
|
|
241
|
-
try out.print("{s}{s}{s}", .{
|
|
244
|
+
try out.print("{s}{s}{s}", .{ p_name, kv_delimiter, try value.toB64(&buf) });
|
|
242
245
|
} else {
|
|
243
246
|
try out.print(
|
|
244
247
|
if (@typeInfo(@TypeOf(value)) == .pointer) "{s}{s}{s}" else "{s}{s}{}",
|
|
245
|
-
.{
|
|
248
|
+
.{ p_name, kv_delimiter, value },
|
|
246
249
|
);
|
|
247
250
|
}
|
|
248
251
|
has_params = true;
|
|
@@ -135,7 +135,7 @@ fn markSecret(ptr: anytype, comptime action: enum { classify, declassify }) void
|
|
|
135
135
|
const t = @typeInfo(@TypeOf(ptr));
|
|
136
136
|
if (t != .pointer) @compileError("Pointer expected - Found: " ++ @typeName(@TypeOf(ptr)));
|
|
137
137
|
const p = t.pointer;
|
|
138
|
-
if (p.
|
|
138
|
+
if (p.attrs.@"allowzero") @compileError("A nullable pointer is always assumed to leak information via side channels");
|
|
139
139
|
const child = @typeInfo(p.child);
|
|
140
140
|
|
|
141
141
|
switch (child) {
|
|
@@ -1338,11 +1338,11 @@ fn failRead(c: *Client, err: ReadError) error{ReadFailed} {
|
|
|
1338
1338
|
}
|
|
1339
1339
|
|
|
1340
1340
|
fn logSecrets(w: *Writer, context: anytype, secrets: anytype) void {
|
|
1341
|
-
inline for (@typeInfo(@TypeOf(secrets)).@"struct".
|
|
1342
|
-
(if (@hasField(@TypeOf(context), "counter")) "_{d}" else "") ++ " {x} {x}\n", .{
|
|
1341
|
+
inline for (@typeInfo(@TypeOf(secrets)).@"struct".field_names) |field_name| w.print("{s}" ++
|
|
1342
|
+
(if (@hasField(@TypeOf(context), "counter")) "_{d}" else "") ++ " {x} {x}\n", .{field_name} ++
|
|
1343
1343
|
(if (@hasField(@TypeOf(context), "counter")) .{context.counter} else .{}) ++ .{
|
|
1344
1344
|
context.client_random,
|
|
1345
|
-
@field(secrets,
|
|
1345
|
+
@field(secrets, field_name),
|
|
1346
1346
|
}) catch {};
|
|
1347
1347
|
}
|
|
1348
1348
|
|
package/std/crypto/tls.zig
CHANGED
|
@@ -710,7 +710,7 @@ pub const Decoder = struct {
|
|
|
710
710
|
else => @compileError("unsupported int type: " ++ @typeName(T)),
|
|
711
711
|
},
|
|
712
712
|
.@"enum" => |info| {
|
|
713
|
-
if (info.
|
|
713
|
+
if (info.mode == .exhaustive) @compileError("exhaustive enum cannot be used");
|
|
714
714
|
return @enumFromInt(d.decode(info.tag_type));
|
|
715
715
|
},
|
|
716
716
|
else => @compileError("unsupported type: " ++ @typeName(T)),
|
|
@@ -247,10 +247,15 @@ fn evalInstructions(
|
|
|
247
247
|
.val_expr => |len| .{ .val_expression = try takeExprBlock(&fr, len) },
|
|
248
248
|
};
|
|
249
249
|
},
|
|
250
|
-
.def_cfa => |cfa| vm.current_row.cfa = .{
|
|
251
|
-
.
|
|
252
|
-
|
|
253
|
-
|
|
250
|
+
.def_cfa => |cfa| vm.current_row.cfa = .{
|
|
251
|
+
.reg_off = .{
|
|
252
|
+
.register = cfa.register,
|
|
253
|
+
// Unfortunately, LLVM emits negative CFI directives as their unsigned variants
|
|
254
|
+
// rather than the signed variants that DWARF has for exactly that purpose, hence
|
|
255
|
+
// `@bitCast` instead of `@intCast`.
|
|
256
|
+
.offset = @bitCast(cfa.offset),
|
|
257
|
+
},
|
|
258
|
+
},
|
|
254
259
|
.def_cfa_sf => |cfa| vm.current_row.cfa = .{ .reg_off = .{
|
|
255
260
|
.register = cfa.register,
|
|
256
261
|
.offset = cfa.offset_sf * cie.data_alignment_factor,
|
|
@@ -272,7 +277,8 @@ fn evalInstructions(
|
|
|
272
277
|
},
|
|
273
278
|
.def_cfa_offset => |offset| switch (vm.current_row.cfa) {
|
|
274
279
|
.none, .expression => return error.InvalidOperation,
|
|
275
|
-
|
|
280
|
+
// See the comment for `def_cfa` above.
|
|
281
|
+
.reg_off => |*ro| ro.offset = @bitCast(offset),
|
|
276
282
|
},
|
|
277
283
|
.def_cfa_offset_sf => |offset_sf| switch (vm.current_row.cfa) {
|
|
278
284
|
.none, .expression => return error.InvalidOperation,
|
package/std/debug/ElfFile.zig
CHANGED
|
@@ -219,9 +219,10 @@ pub fn load(
|
|
|
219
219
|
break :dwarf null; // debug info not present
|
|
220
220
|
}
|
|
221
221
|
var sections: Dwarf.SectionArray = @splat(null);
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
222
|
+
const info = @typeInfo(Dwarf.Section.Id).@"enum";
|
|
223
|
+
inline for (info.field_names, info.field_values) |f_name, f_value| {
|
|
224
|
+
if (result.sections.get(@field(Section.Id, f_name))) |s| {
|
|
225
|
+
sections[f_value] = .{ .data = s.bytes, .owned = false };
|
|
225
226
|
}
|
|
226
227
|
}
|
|
227
228
|
break :dwarf .{ .sections = sections };
|
|
@@ -408,8 +409,8 @@ fn loadSeparateDebugFile(
|
|
|
408
409
|
return null;
|
|
409
410
|
}
|
|
410
411
|
|
|
411
|
-
inline for (@typeInfo(Dwarf.Section.Id).@"enum".
|
|
412
|
-
const id = @field(Section.Id,
|
|
412
|
+
inline for (@typeInfo(Dwarf.Section.Id).@"enum".field_names) |f_name| {
|
|
413
|
+
const id = @field(Section.Id, f_name);
|
|
413
414
|
if (main_loaded.sections.get(id) == null) {
|
|
414
415
|
main_loaded.sections.set(id, result.sections.get(id));
|
|
415
416
|
}
|
|
@@ -498,9 +499,12 @@ fn loadInner(
|
|
|
498
499
|
if (shdr.sh_name > shstrtab.len) return error.TruncatedElfFile;
|
|
499
500
|
const name = std.mem.sliceTo(shstrtab[@intCast(shdr.sh_name)..], 0);
|
|
500
501
|
|
|
501
|
-
const section_id: Section.Id = inline for (
|
|
502
|
-
|
|
503
|
-
|
|
502
|
+
const section_id: Section.Id = inline for (
|
|
503
|
+
@typeInfo(Section.Id).@"enum".field_names,
|
|
504
|
+
@typeInfo(Section.Id).@"enum".field_values,
|
|
505
|
+
) |s_name, s_value| {
|
|
506
|
+
if (std.mem.eql(u8, "." ++ s_name, name)) {
|
|
507
|
+
break @enumFromInt(s_value);
|
|
504
508
|
}
|
|
505
509
|
} else continue;
|
|
506
510
|
|
package/std/debug/MachOFile.zig
CHANGED
|
@@ -504,8 +504,8 @@ fn loadOFile(gpa: Allocator, io: Io, o_file_name: []const u8) !OFile {
|
|
|
504
504
|
|
|
505
505
|
if (!std.mem.eql(u8, "__DWARF", sect.segName())) continue;
|
|
506
506
|
|
|
507
|
-
const section_index: usize = inline for (@typeInfo(Dwarf.Section.Id).@"enum".
|
|
508
|
-
if (mem.eql(u8, "__" ++
|
|
507
|
+
const section_index: usize = inline for (@typeInfo(Dwarf.Section.Id).@"enum".field_names, 0..) |section_name, i| {
|
|
508
|
+
if (mem.eql(u8, "__" ++ section_name, sect.sectName())) break i;
|
|
509
509
|
} else continue;
|
|
510
510
|
|
|
511
511
|
if (mapped_ofile.len < sect.offset + sect.size) return error.InvalidMachO;
|
|
@@ -408,8 +408,8 @@ fn unwindFrameInner(si: *SelfInfo, io: Io, context: *UnwindContext) !usize {
|
|
|
408
408
|
const ip_ptr = fp + @sizeOf(usize);
|
|
409
409
|
|
|
410
410
|
var reg_addr = fp - @sizeOf(usize);
|
|
411
|
-
inline for (@typeInfo(@TypeOf(frame.x_reg_pairs)).@"struct".
|
|
412
|
-
if (@field(frame.x_reg_pairs,
|
|
411
|
+
inline for (@typeInfo(@TypeOf(frame.x_reg_pairs)).@"struct".field_names, 0..) |field_name, i| {
|
|
412
|
+
if (@field(frame.x_reg_pairs, field_name) != 0) {
|
|
413
413
|
(try dwarfRegNative(&context.cpu_state, 19 + i)).* = @as(*const usize, @ptrFromInt(reg_addr)).*;
|
|
414
414
|
reg_addr += @sizeOf(usize);
|
|
415
415
|
(try dwarfRegNative(&context.cpu_state, 20 + i)).* = @as(*const usize, @ptrFromInt(reg_addr)).*;
|
|
@@ -513,8 +513,8 @@ const Module = struct {
|
|
|
513
513
|
if (coff_obj.getSectionByName(".debug_info") == null) break :dwarf null;
|
|
514
514
|
|
|
515
515
|
var sections: Dwarf.SectionArray = undefined;
|
|
516
|
-
inline for (@typeInfo(Dwarf.Section.Id).@"enum".
|
|
517
|
-
sections[i] = if (coff_obj.getSectionByName("." ++
|
|
516
|
+
inline for (@typeInfo(Dwarf.Section.Id).@"enum".field_names, 0..) |section_name, i| {
|
|
517
|
+
sections[i] = if (coff_obj.getSectionByName("." ++ section_name)) |section_header| .{
|
|
518
518
|
.data = try coff_obj.getSectionDataAlloc(section_header, arena),
|
|
519
519
|
.owned = false,
|
|
520
520
|
} else null;
|
package/std/elf.zig
CHANGED
|
@@ -484,7 +484,7 @@ pub const PT = enum(Word) {
|
|
|
484
484
|
_,
|
|
485
485
|
|
|
486
486
|
/// Number of defined types
|
|
487
|
-
pub const NUM = @typeInfo(PT).@"enum".
|
|
487
|
+
pub const NUM = @typeInfo(PT).@"enum".field_names.len;
|
|
488
488
|
|
|
489
489
|
/// Start of OS-specific
|
|
490
490
|
pub const LOOS: PT = @enumFromInt(0x60000000);
|
|
@@ -552,7 +552,7 @@ pub const SHT = enum(Word) {
|
|
|
552
552
|
_,
|
|
553
553
|
|
|
554
554
|
/// Number of defined types
|
|
555
|
-
pub const NUM = @typeInfo(SHT).@"enum".
|
|
555
|
+
pub const NUM = @typeInfo(SHT).@"enum".field_names.len;
|
|
556
556
|
|
|
557
557
|
/// Start of OS-specific
|
|
558
558
|
pub const LOOS: SHT = @enumFromInt(0x60000000);
|
|
@@ -595,7 +595,7 @@ pub const STB = enum(u4) {
|
|
|
595
595
|
_,
|
|
596
596
|
|
|
597
597
|
/// Number of defined types
|
|
598
|
-
pub const NUM = @typeInfo(STB).@"enum".
|
|
598
|
+
pub const NUM = @typeInfo(STB).@"enum".field_names.len;
|
|
599
599
|
|
|
600
600
|
/// Start of OS-specific
|
|
601
601
|
pub const LOOS: STB = @enumFromInt(10);
|
|
@@ -631,7 +631,7 @@ pub const STT = enum(u4) {
|
|
|
631
631
|
_,
|
|
632
632
|
|
|
633
633
|
/// Number of defined types
|
|
634
|
-
pub const NUM = @typeInfo(STT).@"enum".
|
|
634
|
+
pub const NUM = @typeInfo(STT).@"enum".field_names.len;
|
|
635
635
|
|
|
636
636
|
/// Start of OS-specific
|
|
637
637
|
pub const LOOS: STT = @enumFromInt(10);
|
|
@@ -815,7 +815,7 @@ pub const Header = struct {
|
|
|
815
815
|
|
|
816
816
|
pub fn init(hdr: anytype, endian: Endian) Header {
|
|
817
817
|
// Converting integers to exhaustive enums using `@enumFromInt` could cause a panic.
|
|
818
|
-
comptime assert(
|
|
818
|
+
comptime assert(@typeInfo(OSABI).@"enum".mode == .nonexhaustive);
|
|
819
819
|
return .{
|
|
820
820
|
.is_64 = switch (@TypeOf(hdr)) {
|
|
821
821
|
Elf32_Ehdr => false,
|
|
@@ -1642,7 +1642,7 @@ pub const CLASS = enum(u8) {
|
|
|
1642
1642
|
@"64" = 2,
|
|
1643
1643
|
_,
|
|
1644
1644
|
|
|
1645
|
-
pub const NUM = @typeInfo(CLASS).@"enum".
|
|
1645
|
+
pub const NUM = @typeInfo(CLASS).@"enum".field_names.len;
|
|
1646
1646
|
|
|
1647
1647
|
pub fn ElfN(comptime class: CLASS) type {
|
|
1648
1648
|
return switch (class) {
|
|
@@ -1667,7 +1667,7 @@ pub const DATA = enum(u8) {
|
|
|
1667
1667
|
@"2MSB" = 2,
|
|
1668
1668
|
_,
|
|
1669
1669
|
|
|
1670
|
-
pub const NUM = @typeInfo(DATA).@"enum".
|
|
1670
|
+
pub const NUM = @typeInfo(DATA).@"enum".field_names.len;
|
|
1671
1671
|
};
|
|
1672
1672
|
|
|
1673
1673
|
pub const OSABI = enum(u8) {
|
package/std/enums.zig
CHANGED
|
@@ -3,14 +3,13 @@
|
|
|
3
3
|
const std = @import("std");
|
|
4
4
|
const assert = std.debug.assert;
|
|
5
5
|
const testing = std.testing;
|
|
6
|
-
const EnumField = std.builtin.Type.EnumField;
|
|
7
6
|
|
|
8
7
|
/// Increment this value when adding APIs that add single backwards branches.
|
|
9
8
|
const eval_branch_quota_cushion = 10;
|
|
10
9
|
|
|
11
10
|
pub fn fromInt(comptime E: type, integer: anytype) ?E {
|
|
12
11
|
const enum_info = @typeInfo(E).@"enum";
|
|
13
|
-
if (
|
|
12
|
+
if (enum_info.mode == .nonexhaustive) {
|
|
14
13
|
if (std.math.cast(enum_info.tag_type, integer)) |tag| {
|
|
15
14
|
return @enumFromInt(tag);
|
|
16
15
|
}
|
|
@@ -32,20 +31,19 @@ pub fn fromInt(comptime E: type, integer: anytype) ?E {
|
|
|
32
31
|
/// the first name is used. Each field is of type Data and has the provided
|
|
33
32
|
/// default, which may be undefined.
|
|
34
33
|
pub fn EnumFieldStruct(comptime E: type, comptime Data: type, comptime field_default: ?Data) type {
|
|
35
|
-
@setEvalBranchQuota(@typeInfo(E).@"enum".
|
|
34
|
+
@setEvalBranchQuota(@typeInfo(E).@"enum".field_names.len + eval_branch_quota_cushion);
|
|
36
35
|
const default_ptr: ?*const anyopaque = if (field_default) |d| @ptrCast(&d) else null;
|
|
37
36
|
return @Struct(.auto, null, std.meta.fieldNames(E), &@splat(Data), &@splat(.{ .default_value_ptr = default_ptr }));
|
|
38
37
|
}
|
|
39
38
|
|
|
40
|
-
/// Looks up the supplied
|
|
41
|
-
/// Uses only the field names, field values are ignored.
|
|
39
|
+
/// Looks up the supplied field values in the given enum type.
|
|
42
40
|
/// The result array is in the same order as the input.
|
|
43
|
-
pub inline fn valuesFromFields(comptime E: type, comptime
|
|
41
|
+
pub inline fn valuesFromFields(comptime E: type, comptime field_values: []const comptime_int) []const E {
|
|
44
42
|
comptime {
|
|
45
|
-
@setEvalBranchQuota(@typeInfo(E).@"enum".
|
|
46
|
-
var result: [
|
|
47
|
-
for (&result,
|
|
48
|
-
r.* = @enumFromInt(
|
|
43
|
+
@setEvalBranchQuota(@typeInfo(E).@"enum".field_names.len + eval_branch_quota_cushion);
|
|
44
|
+
var result: [field_values.len]E = undefined;
|
|
45
|
+
for (&result, field_values) |*r, f_value| {
|
|
46
|
+
r.* = @enumFromInt(f_value);
|
|
49
47
|
}
|
|
50
48
|
const final = result;
|
|
51
49
|
return &final;
|
|
@@ -55,17 +53,18 @@ pub inline fn valuesFromFields(comptime E: type, comptime fields: []const EnumFi
|
|
|
55
53
|
/// Returns the set of all named values in the given enum, in
|
|
56
54
|
/// declaration order.
|
|
57
55
|
pub inline fn values(comptime E: type) []const E {
|
|
58
|
-
return comptime valuesFromFields(E, @typeInfo(E).@"enum".
|
|
56
|
+
return comptime valuesFromFields(E, @typeInfo(E).@"enum".field_values);
|
|
59
57
|
}
|
|
60
58
|
|
|
61
59
|
/// A safe alternative to @tagName() for non-exhaustive enums that doesn't
|
|
62
60
|
/// panic when `e` has no tagged value.
|
|
63
61
|
/// Returns the tag name for `e` or null if no tag exists.
|
|
64
62
|
pub fn tagName(comptime E: type, e: E) ?[:0]const u8 {
|
|
65
|
-
const
|
|
66
|
-
@
|
|
67
|
-
|
|
68
|
-
|
|
63
|
+
const field_names = @typeInfo(E).@"enum".field_names;
|
|
64
|
+
const field_values = @typeInfo(E).@"enum".field_values;
|
|
65
|
+
@setEvalBranchQuota(field_names.len);
|
|
66
|
+
return inline for (field_names, field_values) |f_name, f_value| {
|
|
67
|
+
if (@intFromEnum(e) == f_value) break f_name;
|
|
69
68
|
} else null;
|
|
70
69
|
}
|
|
71
70
|
|
|
@@ -88,20 +87,20 @@ test tagName {
|
|
|
88
87
|
pub fn directEnumArrayLen(comptime E: type, comptime max_unused_slots: comptime_int) comptime_int {
|
|
89
88
|
var max_value: comptime_int = -1;
|
|
90
89
|
const max_usize: comptime_int = ~@as(usize, 0);
|
|
91
|
-
const
|
|
92
|
-
for (
|
|
93
|
-
if (
|
|
94
|
-
@compileError("Cannot create a direct enum array for " ++ @typeName(E) ++ ", field ." ++
|
|
95
|
-
}
|
|
96
|
-
if (
|
|
97
|
-
if (
|
|
98
|
-
@compileError("Cannot create a direct enum array for " ++ @typeName(E) ++ ", field ." ++
|
|
90
|
+
const info = @typeInfo(E).@"enum";
|
|
91
|
+
for (info.field_names, info.field_values) |f_name, f_value| {
|
|
92
|
+
if (f_value < 0) {
|
|
93
|
+
@compileError("Cannot create a direct enum array for " ++ @typeName(E) ++ ", field ." ++ f_name ++ " has a negative value.");
|
|
94
|
+
}
|
|
95
|
+
if (f_value > max_value) {
|
|
96
|
+
if (f_value > max_usize) {
|
|
97
|
+
@compileError("Cannot create a direct enum array for " ++ @typeName(E) ++ ", field ." ++ f_name ++ " is larger than the max value of usize.");
|
|
99
98
|
}
|
|
100
|
-
max_value =
|
|
99
|
+
max_value = f_value;
|
|
101
100
|
}
|
|
102
101
|
}
|
|
103
102
|
|
|
104
|
-
const unused_slots = max_value + 1 -
|
|
103
|
+
const unused_slots = max_value + 1 - info.field_names.len;
|
|
105
104
|
if (unused_slots > max_unused_slots) {
|
|
106
105
|
const unused_str = std.fmt.comptimePrint("{d}", .{unused_slots});
|
|
107
106
|
const allowed_str = std.fmt.comptimePrint("{d}", .{max_unused_slots});
|
|
@@ -167,10 +166,10 @@ pub fn directEnumArrayDefault(
|
|
|
167
166
|
) [directEnumArrayLen(E, max_unused_slots)]Data {
|
|
168
167
|
const len = comptime directEnumArrayLen(E, max_unused_slots);
|
|
169
168
|
var result: [len]Data = @splat(default orelse undefined);
|
|
170
|
-
inline for (@typeInfo(@TypeOf(init_values)).@"struct".
|
|
171
|
-
const enum_value = @field(E,
|
|
169
|
+
inline for (@typeInfo(@TypeOf(init_values)).@"struct".field_names) |f_name| {
|
|
170
|
+
const enum_value = @field(E, f_name);
|
|
172
171
|
const index = @as(usize, @intCast(@intFromEnum(enum_value)));
|
|
173
|
-
result[index] = @field(init_values,
|
|
172
|
+
result[index] = @field(init_values, f_name);
|
|
174
173
|
}
|
|
175
174
|
return result;
|
|
176
175
|
}
|
|
@@ -256,9 +255,9 @@ pub fn EnumSet(comptime E: type) type {
|
|
|
256
255
|
|
|
257
256
|
/// Initializes the set using a struct of bools
|
|
258
257
|
pub fn init(init_values: EnumFieldStruct(E, bool, false)) Self {
|
|
259
|
-
@setEvalBranchQuota(2 * @typeInfo(E).@"enum".
|
|
258
|
+
@setEvalBranchQuota(2 * @typeInfo(E).@"enum".field_names.len);
|
|
260
259
|
var result: Self = .{};
|
|
261
|
-
if (@typeInfo(E).@"enum".
|
|
260
|
+
if (@typeInfo(E).@"enum".mode == .exhaustive) {
|
|
262
261
|
inline for (0..Self.len) |i| {
|
|
263
262
|
const key = comptime Indexer.keyForIndex(i);
|
|
264
263
|
const tag = @tagName(key);
|
|
@@ -267,9 +266,9 @@ pub fn EnumSet(comptime E: type) type {
|
|
|
267
266
|
}
|
|
268
267
|
}
|
|
269
268
|
} else {
|
|
270
|
-
inline for (
|
|
271
|
-
const key = @field(E,
|
|
272
|
-
if (@field(init_values,
|
|
269
|
+
inline for (@typeInfo(E).@"enum".field_names) |field_name| {
|
|
270
|
+
const key = @field(E, field_name);
|
|
271
|
+
if (@field(init_values, field_name)) {
|
|
273
272
|
const i = comptime Indexer.indexOf(key);
|
|
274
273
|
result.bits.set(i);
|
|
275
274
|
}
|
|
@@ -443,9 +442,9 @@ pub fn EnumMap(comptime E: type, comptime V: type) type {
|
|
|
443
442
|
|
|
444
443
|
/// Initializes the map using a sparse struct of optionals
|
|
445
444
|
pub fn init(init_values: EnumFieldStruct(E, ?Value, @as(?Value, null))) Self {
|
|
446
|
-
@setEvalBranchQuota(2 * @typeInfo(E).@"enum".
|
|
445
|
+
@setEvalBranchQuota(2 * @typeInfo(E).@"enum".field_names.len);
|
|
447
446
|
var result: Self = .{};
|
|
448
|
-
if (@typeInfo(E).@"enum".
|
|
447
|
+
if (@typeInfo(E).@"enum".mode == .exhaustive) {
|
|
449
448
|
inline for (0..Self.len) |i| {
|
|
450
449
|
const key = comptime Indexer.keyForIndex(i);
|
|
451
450
|
const tag = @tagName(key);
|
|
@@ -455,9 +454,9 @@ pub fn EnumMap(comptime E: type, comptime V: type) type {
|
|
|
455
454
|
}
|
|
456
455
|
}
|
|
457
456
|
} else {
|
|
458
|
-
inline for (std.meta.
|
|
459
|
-
const key = @field(E,
|
|
460
|
-
if (@field(init_values,
|
|
457
|
+
inline for (std.meta.fieldNames(E)) |field_name| {
|
|
458
|
+
const key = @field(E, field_name);
|
|
459
|
+
if (@field(init_values, field_name)) |*v| {
|
|
461
460
|
const i = comptime Indexer.indexOf(key);
|
|
462
461
|
result.bits.set(i);
|
|
463
462
|
result.values[i] = v.*;
|
|
@@ -487,7 +486,7 @@ pub fn EnumMap(comptime E: type, comptime V: type) type {
|
|
|
487
486
|
/// Initializes a full mapping with a provided default.
|
|
488
487
|
/// Consider using EnumArray instead if the map will remain full.
|
|
489
488
|
pub fn initFullWithDefault(comptime default: ?Value, init_values: EnumFieldStruct(E, Value, default)) Self {
|
|
490
|
-
@setEvalBranchQuota(2 * @typeInfo(E).@"enum".
|
|
489
|
+
@setEvalBranchQuota(2 * @typeInfo(E).@"enum".field_names.len);
|
|
491
490
|
var result: Self = .{
|
|
492
491
|
.bits = .full,
|
|
493
492
|
.values = undefined,
|
|
@@ -673,11 +672,12 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type {
|
|
|
673
672
|
|
|
674
673
|
/// Initializes the multiset using a struct of counts.
|
|
675
674
|
pub fn init(init_counts: EnumFieldStruct(E, CountSize, 0)) Self {
|
|
676
|
-
@setEvalBranchQuota(2 * @typeInfo(E).@"enum".
|
|
675
|
+
@setEvalBranchQuota(2 * @typeInfo(E).@"enum".field_names.len);
|
|
677
676
|
var self = initWithCount(0);
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
const
|
|
677
|
+
const info = @typeInfo(E).@"enum";
|
|
678
|
+
inline for (info.field_names, info.field_values) |field_name, field_value| {
|
|
679
|
+
const c = @field(init_counts, field_name);
|
|
680
|
+
const key: E = @enumFromInt(field_value);
|
|
681
681
|
self.counts.set(key, c);
|
|
682
682
|
}
|
|
683
683
|
return self;
|
|
@@ -745,16 +745,16 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type {
|
|
|
745
745
|
/// Increases the all key counts by given multiset. Caller
|
|
746
746
|
/// asserts operation will not overflow any key.
|
|
747
747
|
pub fn addSetAssertSafe(self: *Self, other: Self) void {
|
|
748
|
-
inline for (@typeInfo(E).@"enum".
|
|
749
|
-
const key = @as(E, @enumFromInt(
|
|
748
|
+
inline for (@typeInfo(E).@"enum".field_values) |field_value| {
|
|
749
|
+
const key = @as(E, @enumFromInt(field_value));
|
|
750
750
|
self.addAssertSafe(key, other.getCount(key));
|
|
751
751
|
}
|
|
752
752
|
}
|
|
753
753
|
|
|
754
754
|
/// Increases the all key counts by given multiset.
|
|
755
755
|
pub fn addSet(self: *Self, other: Self) error{Overflow}!void {
|
|
756
|
-
inline for (@typeInfo(E).@"enum".
|
|
757
|
-
const key = @as(E, @enumFromInt(
|
|
756
|
+
inline for (@typeInfo(E).@"enum".field_values) |field_value| {
|
|
757
|
+
const key = @as(E, @enumFromInt(field_value));
|
|
758
758
|
try self.add(key, other.getCount(key));
|
|
759
759
|
}
|
|
760
760
|
}
|
|
@@ -763,8 +763,8 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type {
|
|
|
763
763
|
/// the given multiset has more key counts than this,
|
|
764
764
|
/// then that key will have a key count of zero.
|
|
765
765
|
pub fn removeSet(self: *Self, other: Self) void {
|
|
766
|
-
inline for (@typeInfo(E).@"enum".
|
|
767
|
-
const key = @as(E, @enumFromInt(
|
|
766
|
+
inline for (@typeInfo(E).@"enum".field_values) |field_value| {
|
|
767
|
+
const key = @as(E, @enumFromInt(field_value));
|
|
768
768
|
self.remove(key, other.getCount(key));
|
|
769
769
|
}
|
|
770
770
|
}
|
|
@@ -772,8 +772,8 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type {
|
|
|
772
772
|
/// Returns true iff all key counts are the same as
|
|
773
773
|
/// given multiset.
|
|
774
774
|
pub fn eql(self: Self, other: Self) bool {
|
|
775
|
-
inline for (@typeInfo(E).@"enum".
|
|
776
|
-
const key = @as(E, @enumFromInt(
|
|
775
|
+
inline for (@typeInfo(E).@"enum".field_values) |field_value| {
|
|
776
|
+
const key = @as(E, @enumFromInt(field_value));
|
|
777
777
|
if (self.getCount(key) != other.getCount(key)) {
|
|
778
778
|
return false;
|
|
779
779
|
}
|
|
@@ -784,8 +784,8 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type {
|
|
|
784
784
|
/// Returns true iff all key counts less than or
|
|
785
785
|
/// equal to the given multiset.
|
|
786
786
|
pub fn subsetOf(self: Self, other: Self) bool {
|
|
787
|
-
inline for (@typeInfo(E).@"enum".
|
|
788
|
-
const key = @as(E, @enumFromInt(
|
|
787
|
+
inline for (@typeInfo(E).@"enum".field_values) |field_value| {
|
|
788
|
+
const key = @as(E, @enumFromInt(field_value));
|
|
789
789
|
if (self.getCount(key) > other.getCount(key)) {
|
|
790
790
|
return false;
|
|
791
791
|
}
|
|
@@ -796,8 +796,8 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type {
|
|
|
796
796
|
/// Returns true iff all key counts greater than or
|
|
797
797
|
/// equal to the given multiset.
|
|
798
798
|
pub fn supersetOf(self: Self, other: Self) bool {
|
|
799
|
-
inline for (@typeInfo(E).@"enum".
|
|
800
|
-
const key = @as(E, @enumFromInt(
|
|
799
|
+
inline for (@typeInfo(E).@"enum".field_values) |field_value| {
|
|
800
|
+
const key = @as(E, @enumFromInt(field_value));
|
|
801
801
|
if (self.getCount(key) < other.getCount(key)) {
|
|
802
802
|
return false;
|
|
803
803
|
}
|
|
@@ -1075,7 +1075,7 @@ pub fn EnumArray(comptime E: type, comptime V: type) type {
|
|
|
1075
1075
|
|
|
1076
1076
|
/// Initializes values in the enum array, with the specified default.
|
|
1077
1077
|
pub fn initDefault(comptime default: ?Value, init_values: EnumFieldStruct(E, Value, default)) Self {
|
|
1078
|
-
@setEvalBranchQuota(2 * @typeInfo(E).@"enum".
|
|
1078
|
+
@setEvalBranchQuota(2 * @typeInfo(E).@"enum".field_names.len);
|
|
1079
1079
|
var result: Self = .{ .values = undefined };
|
|
1080
1080
|
inline for (0..Self.len) |i| {
|
|
1081
1081
|
const key = comptime Indexer.keyForIndex(i);
|
|
@@ -1264,10 +1264,10 @@ test "EnumSet non-exhaustive" {
|
|
|
1264
1264
|
|
|
1265
1265
|
pub fn EnumIndexer(comptime E: type) type {
|
|
1266
1266
|
// n log n for `std.mem.sortUnstable` call below.
|
|
1267
|
-
const fields_len = @typeInfo(E).@"enum".
|
|
1267
|
+
const fields_len = @typeInfo(E).@"enum".field_names.len;
|
|
1268
1268
|
@setEvalBranchQuota(3 * fields_len * std.math.log2(@max(fields_len, 1)) + eval_branch_quota_cushion);
|
|
1269
1269
|
|
|
1270
|
-
if (
|
|
1270
|
+
if (@typeInfo(E).@"enum".mode == .nonexhaustive) {
|
|
1271
1271
|
const BackingInt = @typeInfo(E).@"enum".tag_type;
|
|
1272
1272
|
if (@bitSizeOf(BackingInt) > @bitSizeOf(usize))
|
|
1273
1273
|
@compileError("Cannot create an enum indexer for a given non-exhaustive enum, tag_type is larger than usize.");
|
|
@@ -1315,18 +1315,17 @@ pub fn EnumIndexer(comptime E: type) type {
|
|
|
1315
1315
|
};
|
|
1316
1316
|
}
|
|
1317
1317
|
|
|
1318
|
-
var
|
|
1318
|
+
var field_values = @typeInfo(E).@"enum".field_values[0..fields_len].*;
|
|
1319
1319
|
|
|
1320
|
-
std.mem.sortUnstable(
|
|
1321
|
-
fn lessThan(
|
|
1322
|
-
|
|
1323
|
-
return lhs.value < rhs.value;
|
|
1320
|
+
std.mem.sortUnstable(comptime_int, &field_values, {}, struct {
|
|
1321
|
+
fn lessThan(_: void, a: comptime_int, b: comptime_int) bool {
|
|
1322
|
+
return a < b;
|
|
1324
1323
|
}
|
|
1325
1324
|
}.lessThan);
|
|
1326
1325
|
|
|
1327
|
-
const min =
|
|
1328
|
-
const max =
|
|
1329
|
-
if (max - min ==
|
|
1326
|
+
const min = field_values[0];
|
|
1327
|
+
const max = field_values[fields_len - 1];
|
|
1328
|
+
if (max - min == field_values.len - 1) {
|
|
1330
1329
|
return struct {
|
|
1331
1330
|
pub const Key = E;
|
|
1332
1331
|
pub const count: comptime_int = fields_len;
|
|
@@ -1343,7 +1342,7 @@ pub fn EnumIndexer(comptime E: type) type {
|
|
|
1343
1342
|
};
|
|
1344
1343
|
}
|
|
1345
1344
|
|
|
1346
|
-
const keys = valuesFromFields(E, &
|
|
1345
|
+
const keys = valuesFromFields(E, &field_values);
|
|
1347
1346
|
|
|
1348
1347
|
return struct {
|
|
1349
1348
|
pub const Key = E;
|
package/std/gpu.zig
CHANGED
|
@@ -58,7 +58,7 @@ pub const ExecutionMode = union(Tag) {
|
|
|
58
58
|
|
|
59
59
|
/// Declare the mode entry point executes in.
|
|
60
60
|
pub fn executionMode(comptime entry_point: anytype, comptime mode: ExecutionMode) void {
|
|
61
|
-
const cc = @typeInfo(@TypeOf(entry_point)).@"fn".
|
|
61
|
+
const cc = @typeInfo(@TypeOf(entry_point)).@"fn".attrs.@"callconv";
|
|
62
62
|
switch (mode) {
|
|
63
63
|
.origin_upper_left,
|
|
64
64
|
.origin_lower_left,
|
package/std/hash/auto_hash.zig
CHANGED
|
@@ -127,10 +127,10 @@ pub fn hash(hasher: anytype, key: anytype, comptime strat: HashStrategy) void {
|
|
|
127
127
|
},
|
|
128
128
|
|
|
129
129
|
.@"struct" => |info| {
|
|
130
|
-
inline for (info.
|
|
130
|
+
inline for (info.field_names) |field_name| {
|
|
131
131
|
// We reuse the hash of the previous field as the seed for the
|
|
132
132
|
// next one so that they're dependant.
|
|
133
|
-
hash(hasher, @field(key,
|
|
133
|
+
hash(hasher, @field(key, field_name), strat);
|
|
134
134
|
}
|
|
135
135
|
},
|
|
136
136
|
|
|
@@ -138,10 +138,10 @@ pub fn hash(hasher: anytype, key: anytype, comptime strat: HashStrategy) void {
|
|
|
138
138
|
if (info.tag_type) |tag_type| {
|
|
139
139
|
const tag = std.meta.activeTag(key);
|
|
140
140
|
hash(hasher, tag, strat);
|
|
141
|
-
inline for (info.
|
|
142
|
-
if (@field(tag_type,
|
|
143
|
-
if (
|
|
144
|
-
hash(hasher, @field(key,
|
|
141
|
+
inline for (info.field_names, info.field_types) |field_name, field_type| {
|
|
142
|
+
if (@field(tag_type, field_name) == tag) {
|
|
143
|
+
if (field_type != void) {
|
|
144
|
+
hash(hasher, @field(key, field_name), strat);
|
|
145
145
|
}
|
|
146
146
|
break :blk;
|
|
147
147
|
}
|
|
@@ -165,8 +165,8 @@ inline fn typeContainsSlice(comptime K: type) bool {
|
|
|
165
165
|
.pointer => |info| info.size == .slice,
|
|
166
166
|
|
|
167
167
|
inline .@"struct", .@"union" => |info| {
|
|
168
|
-
inline for (info.
|
|
169
|
-
if (typeContainsSlice(
|
|
168
|
+
inline for (info.field_types) |field_type| {
|
|
169
|
+
if (typeContainsSlice(field_type)) {
|
|
170
170
|
return true;
|
|
171
171
|
}
|
|
172
172
|
}
|