@zigc/lib 0.17.0-dev.644 → 0.17.0-dev.667
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/Maker.zig +2 -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/libc/include/powerpc-linux-gnu/bits/struct_mutex.h +2 -2
- package/libc/include/s390x-linux-gnu/bits/fenv.h +2 -2
- package/libc/include/s390x-linux-gnu/bits/struct_mutex.h +2 -2
- package/libc/include/x86-linux-gnu/bits/struct_mutex.h +2 -2
- 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/aes/aesni.zig +1 -1
- package/std/crypto/aes/armcrypto.zig +4 -4
- package/std/crypto/aes/soft.zig +4 -4
- package/std/crypto/aes.zig +12 -0
- 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 +44 -17
- 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/sort/pdq.zig +22 -5
- 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 +83 -61
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
|
}
|
package/std/hash/verify.zig
CHANGED
|
@@ -2,8 +2,8 @@ const std = @import("std");
|
|
|
2
2
|
|
|
3
3
|
fn hashMaybeSeed(comptime hash_fn: anytype, seed: anytype, buf: []const u8) @typeInfo(@TypeOf(hash_fn)).@"fn".return_type.? {
|
|
4
4
|
const HashFn = @typeInfo(@TypeOf(hash_fn)).@"fn";
|
|
5
|
-
if (HashFn.
|
|
6
|
-
if (@typeInfo(HashFn.
|
|
5
|
+
if (HashFn.param_types.len > 1) {
|
|
6
|
+
if (@typeInfo(HashFn.param_types[0].?) == .int) {
|
|
7
7
|
return hash_fn(@intCast(seed), buf);
|
|
8
8
|
} else {
|
|
9
9
|
return hash_fn(buf, @intCast(seed));
|
|
@@ -15,7 +15,7 @@ fn hashMaybeSeed(comptime hash_fn: anytype, seed: anytype, buf: []const u8) @typ
|
|
|
15
15
|
|
|
16
16
|
fn initMaybeSeed(comptime Hash: anytype, seed: anytype) Hash {
|
|
17
17
|
const HashFn = @typeInfo(@TypeOf(Hash.init)).@"fn";
|
|
18
|
-
if (HashFn.
|
|
18
|
+
if (HashFn.param_types.len == 1) {
|
|
19
19
|
return Hash.init(@intCast(seed));
|
|
20
20
|
} else {
|
|
21
21
|
return Hash.init();
|
package/std/http/Client.zig
CHANGED
|
@@ -823,8 +823,8 @@ pub const Request = struct {
|
|
|
823
823
|
/// Externally-owned; must outlive the Request.
|
|
824
824
|
privileged_headers: []const http.Header,
|
|
825
825
|
|
|
826
|
-
pub const default_accept_encoding: [@typeInfo(http.ContentEncoding).@"enum".
|
|
827
|
-
var result: [@typeInfo(http.ContentEncoding).@"enum".
|
|
826
|
+
pub const default_accept_encoding: [@typeInfo(http.ContentEncoding).@"enum".field_names.len]bool = b: {
|
|
827
|
+
var result: [@typeInfo(http.ContentEncoding).@"enum".field_names.len]bool = @splat(false);
|
|
828
828
|
result[@intFromEnum(http.ContentEncoding.gzip)] = true;
|
|
829
829
|
result[@intFromEnum(http.ContentEncoding.deflate)] = true;
|
|
830
830
|
result[@intFromEnum(http.ContentEncoding.identity)] = true;
|
package/std/json/Stringify.zig
CHANGED
|
@@ -401,9 +401,9 @@ pub fn write(self: *Stringify, v: anytype) Error!void {
|
|
|
401
401
|
return v.jsonStringify(self);
|
|
402
402
|
}
|
|
403
403
|
|
|
404
|
-
if (
|
|
405
|
-
inline for (enum_info.
|
|
406
|
-
if (v == @field(T,
|
|
404
|
+
if (enum_info.mode == .nonexhaustive) {
|
|
405
|
+
inline for (enum_info.field_names) |field_name| {
|
|
406
|
+
if (v == @field(T, field_name)) {
|
|
407
407
|
break;
|
|
408
408
|
}
|
|
409
409
|
} else {
|
|
@@ -424,15 +424,15 @@ pub fn write(self: *Stringify, v: anytype) Error!void {
|
|
|
424
424
|
const info = @typeInfo(T).@"union";
|
|
425
425
|
if (info.tag_type) |UnionTagType| {
|
|
426
426
|
try self.beginObject();
|
|
427
|
-
inline for (info.
|
|
428
|
-
if (v == @field(UnionTagType,
|
|
429
|
-
try self.objectField(
|
|
430
|
-
if (
|
|
427
|
+
inline for (info.field_names, info.field_types) |u_field_name, u_field_type| {
|
|
428
|
+
if (v == @field(UnionTagType, u_field_name)) {
|
|
429
|
+
try self.objectField(u_field_name);
|
|
430
|
+
if (u_field_type == void) {
|
|
431
431
|
// void v is {}
|
|
432
432
|
try self.beginObject();
|
|
433
433
|
try self.endObject();
|
|
434
434
|
} else {
|
|
435
|
-
try self.write(@field(v,
|
|
435
|
+
try self.write(@field(v, u_field_name));
|
|
436
436
|
}
|
|
437
437
|
break;
|
|
438
438
|
}
|
|
@@ -455,16 +455,16 @@ pub fn write(self: *Stringify, v: anytype) Error!void {
|
|
|
455
455
|
} else {
|
|
456
456
|
try self.beginObject();
|
|
457
457
|
}
|
|
458
|
-
inline for (S.
|
|
458
|
+
inline for (S.field_names, S.field_types) |field_name, field_type| {
|
|
459
459
|
// don't include void fields
|
|
460
|
-
if (
|
|
460
|
+
if (field_type == void) continue;
|
|
461
461
|
|
|
462
462
|
var emit_field = true;
|
|
463
463
|
|
|
464
464
|
// don't include optional fields that are null when emit_null_optional_fields is set to false
|
|
465
|
-
if (@typeInfo(
|
|
465
|
+
if (@typeInfo(field_type) == .optional) {
|
|
466
466
|
if (self.options.emit_null_optional_fields == false) {
|
|
467
|
-
if (@field(v,
|
|
467
|
+
if (@field(v, field_name) == null) {
|
|
468
468
|
emit_field = false;
|
|
469
469
|
}
|
|
470
470
|
}
|
|
@@ -472,9 +472,9 @@ pub fn write(self: *Stringify, v: anytype) Error!void {
|
|
|
472
472
|
|
|
473
473
|
if (emit_field) {
|
|
474
474
|
if (!S.is_tuple) {
|
|
475
|
-
try self.objectField(
|
|
475
|
+
try self.objectField(field_name);
|
|
476
476
|
}
|
|
477
|
-
try self.write(@field(v,
|
|
477
|
+
try self.write(@field(v, field_name));
|
|
478
478
|
}
|
|
479
479
|
}
|
|
480
480
|
if (S.is_tuple) {
|
package/std/json/static.zig
CHANGED
|
@@ -286,20 +286,20 @@ pub fn innerParse(
|
|
|
286
286
|
},
|
|
287
287
|
};
|
|
288
288
|
|
|
289
|
-
inline for (unionInfo.
|
|
290
|
-
if (std.mem.eql(u8,
|
|
289
|
+
inline for (unionInfo.field_names, unionInfo.field_types) |u_field_name, u_field_type| {
|
|
290
|
+
if (std.mem.eql(u8, u_field_name, field_name)) {
|
|
291
291
|
// Free the name token now in case we're using an allocator that optimizes freeing the last allocated object.
|
|
292
292
|
// (Recursing into innerParse() might trigger more allocations.)
|
|
293
293
|
freeAllocated(allocator, name_token.?);
|
|
294
294
|
name_token = null;
|
|
295
|
-
if (
|
|
295
|
+
if (u_field_type == void) {
|
|
296
296
|
// void isn't really a json type, but we can support void payload union tags with {} as a value.
|
|
297
297
|
if (.object_begin != try source.next()) return error.UnexpectedToken;
|
|
298
298
|
if (.object_end != try source.next()) return error.UnexpectedToken;
|
|
299
|
-
result = @unionInit(T,
|
|
299
|
+
result = @unionInit(T, u_field_name, {});
|
|
300
300
|
} else {
|
|
301
301
|
// Recurse.
|
|
302
|
-
result = @unionInit(T,
|
|
302
|
+
result = @unionInit(T, u_field_name, try innerParse(u_field_type, allocator, source, options));
|
|
303
303
|
}
|
|
304
304
|
break;
|
|
305
305
|
}
|
|
@@ -318,8 +318,8 @@ pub fn innerParse(
|
|
|
318
318
|
if (.array_begin != try source.next()) return error.UnexpectedToken;
|
|
319
319
|
|
|
320
320
|
var r: T = undefined;
|
|
321
|
-
inline for (0..
|
|
322
|
-
r[i] = try innerParse(
|
|
321
|
+
inline for (structInfo.field_types, 0..) |field_type, i| {
|
|
322
|
+
r[i] = try innerParse(field_type, allocator, source, options);
|
|
323
323
|
}
|
|
324
324
|
|
|
325
325
|
if (.array_end != try source.next()) return error.UnexpectedToken;
|
|
@@ -334,7 +334,7 @@ pub fn innerParse(
|
|
|
334
334
|
if (.object_begin != try source.next()) return error.UnexpectedToken;
|
|
335
335
|
|
|
336
336
|
var r: T = undefined;
|
|
337
|
-
var fields_seen: [structInfo.
|
|
337
|
+
var fields_seen: [structInfo.field_names.len]bool = @splat(false);
|
|
338
338
|
|
|
339
339
|
while (true) {
|
|
340
340
|
var name_token: ?Token = try source.nextAllocMax(allocator, .alloc_if_needed, options.max_value_len.?);
|
|
@@ -348,9 +348,14 @@ pub fn innerParse(
|
|
|
348
348
|
},
|
|
349
349
|
};
|
|
350
350
|
|
|
351
|
-
inline for (
|
|
352
|
-
|
|
353
|
-
|
|
351
|
+
inline for (
|
|
352
|
+
structInfo.field_names,
|
|
353
|
+
structInfo.field_types,
|
|
354
|
+
structInfo.field_attrs,
|
|
355
|
+
0..,
|
|
356
|
+
) |f_name, f_type, f_attrs, i| {
|
|
357
|
+
if (f_attrs.@"comptime") @compileError("comptime fields are not supported: " ++ @typeName(T) ++ "." ++ f_name);
|
|
358
|
+
if (std.mem.eql(u8, f_name, field_name)) {
|
|
354
359
|
// Free the name token now in case we're using an allocator that optimizes freeing the last allocated object.
|
|
355
360
|
// (Recursing into innerParse() might trigger more allocations.)
|
|
356
361
|
freeAllocated(allocator, name_token.?);
|
|
@@ -360,14 +365,14 @@ pub fn innerParse(
|
|
|
360
365
|
.use_first => {
|
|
361
366
|
// Parse and ignore the redundant value.
|
|
362
367
|
// We don't want to skip the value, because we want type checking.
|
|
363
|
-
_ = try innerParse(
|
|
368
|
+
_ = try innerParse(f_type, allocator, source, options);
|
|
364
369
|
break;
|
|
365
370
|
},
|
|
366
371
|
.@"error" => return error.DuplicateField,
|
|
367
372
|
.use_last => {},
|
|
368
373
|
}
|
|
369
374
|
}
|
|
370
|
-
@field(r,
|
|
375
|
+
@field(r, f_name) = try innerParse(f_type, allocator, source, options);
|
|
371
376
|
fields_seen[i] = true;
|
|
372
377
|
break;
|
|
373
378
|
}
|
|
@@ -493,7 +498,7 @@ pub fn innerParse(
|
|
|
493
498
|
_ = try source.allocNextIntoArrayList(&value_list, .alloc_always);
|
|
494
499
|
return try value_list.toOwnedSliceSentinel(s);
|
|
495
500
|
}
|
|
496
|
-
if (ptrInfo.
|
|
501
|
+
if (ptrInfo.attrs.@"const") {
|
|
497
502
|
switch (try source.nextAllocMax(allocator, options.allocate.?, options.max_value_len.?)) {
|
|
498
503
|
inline .string, .allocated_string => |slice| return slice,
|
|
499
504
|
else => unreachable,
|
|
@@ -613,16 +618,16 @@ pub fn innerParseFromValue(
|
|
|
613
618
|
const kv = it.next().?;
|
|
614
619
|
const field_name = kv.key_ptr.*;
|
|
615
620
|
|
|
616
|
-
inline for (unionInfo.
|
|
617
|
-
if (std.mem.eql(u8,
|
|
618
|
-
if (
|
|
621
|
+
inline for (unionInfo.field_names, unionInfo.field_types) |u_field_name, u_field_type| {
|
|
622
|
+
if (std.mem.eql(u8, u_field_name, field_name)) {
|
|
623
|
+
if (u_field_type == void) {
|
|
619
624
|
// void isn't really a json type, but we can support void payload union tags with {} as a value.
|
|
620
625
|
if (kv.value_ptr.* != .object) return error.UnexpectedToken;
|
|
621
626
|
if (kv.value_ptr.*.object.count() != 0) return error.UnexpectedToken;
|
|
622
|
-
return @unionInit(T,
|
|
627
|
+
return @unionInit(T, u_field_name, {});
|
|
623
628
|
}
|
|
624
629
|
// Recurse.
|
|
625
|
-
return @unionInit(T,
|
|
630
|
+
return @unionInit(T, u_field_name, try innerParseFromValue(u_field_type, allocator, kv.value_ptr.*, options));
|
|
626
631
|
}
|
|
627
632
|
}
|
|
628
633
|
// Didn't match anything.
|
|
@@ -632,11 +637,11 @@ pub fn innerParseFromValue(
|
|
|
632
637
|
.@"struct" => |structInfo| {
|
|
633
638
|
if (structInfo.is_tuple) {
|
|
634
639
|
if (source != .array) return error.UnexpectedToken;
|
|
635
|
-
if (source.array.items.len != structInfo.
|
|
640
|
+
if (source.array.items.len != structInfo.field_names.len) return error.UnexpectedToken;
|
|
636
641
|
|
|
637
642
|
var r: T = undefined;
|
|
638
|
-
inline for (0..structInfo.
|
|
639
|
-
r[i] = try innerParseFromValue(structInfo.
|
|
643
|
+
inline for (0..structInfo.field_names.len, source.array.items) |i, item| {
|
|
644
|
+
r[i] = try innerParseFromValue(structInfo.field_types[i], allocator, item, options);
|
|
640
645
|
}
|
|
641
646
|
|
|
642
647
|
return r;
|
|
@@ -649,17 +654,22 @@ pub fn innerParseFromValue(
|
|
|
649
654
|
if (source != .object) return error.UnexpectedToken;
|
|
650
655
|
|
|
651
656
|
var r: T = undefined;
|
|
652
|
-
var fields_seen: [structInfo.
|
|
657
|
+
var fields_seen: [structInfo.field_names.len]bool = @splat(false);
|
|
653
658
|
|
|
654
659
|
var it = source.object.iterator();
|
|
655
660
|
while (it.next()) |kv| {
|
|
656
661
|
const field_name = kv.key_ptr.*;
|
|
657
662
|
|
|
658
|
-
inline for (
|
|
659
|
-
|
|
660
|
-
|
|
663
|
+
inline for (
|
|
664
|
+
structInfo.field_names,
|
|
665
|
+
structInfo.field_types,
|
|
666
|
+
structInfo.field_attrs,
|
|
667
|
+
0..,
|
|
668
|
+
) |f_name, f_type, f_attrs, i| {
|
|
669
|
+
if (f_attrs.@"comptime") @compileError("comptime fields are not supported: " ++ @typeName(T) ++ "." ++ f_name);
|
|
670
|
+
if (std.mem.eql(u8, f_name, field_name)) {
|
|
661
671
|
assert(!fields_seen[i]); // Can't have duplicate keys in a Value.object.
|
|
662
|
-
@field(r,
|
|
672
|
+
@field(r, f_name) = try innerParseFromValue(f_type, allocator, kv.value_ptr.*, options);
|
|
663
673
|
fields_seen[i] = true;
|
|
664
674
|
break;
|
|
665
675
|
}
|
|
@@ -782,11 +792,17 @@ fn sliceToEnum(comptime T: type, slice: []const u8) !T {
|
|
|
782
792
|
return std.enums.fromInt(T, n) orelse return error.InvalidEnumTag;
|
|
783
793
|
}
|
|
784
794
|
|
|
785
|
-
fn fillDefaultStructValues(comptime T: type, r: *T, fields_seen: *[@typeInfo(T).@"struct".
|
|
786
|
-
|
|
795
|
+
fn fillDefaultStructValues(comptime T: type, r: *T, fields_seen: *[@typeInfo(T).@"struct".field_names.len]bool) !void {
|
|
796
|
+
const info = @typeInfo(T).@"struct";
|
|
797
|
+
inline for (
|
|
798
|
+
info.field_names,
|
|
799
|
+
info.field_types,
|
|
800
|
+
info.field_attrs,
|
|
801
|
+
0..,
|
|
802
|
+
) |field_name, field_type, field_attrs, i| {
|
|
787
803
|
if (!fields_seen[i]) {
|
|
788
|
-
if (
|
|
789
|
-
@field(r,
|
|
804
|
+
if (field_attrs.defaultValue(field_type)) |default| {
|
|
805
|
+
@field(r, field_name) = default;
|
|
790
806
|
} else {
|
|
791
807
|
return error.MissingField;
|
|
792
808
|
}
|