@zigc/lib 0.17.0-dev.633 → 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/PkgConfig.zig +1 -0
- package/compiler/Maker/ScannedConfig.zig +4 -3
- package/compiler/Maker/Step/Compile.zig +1 -3
- package/compiler/Maker/Step/FindProgram.zig +2 -2
- package/compiler/Maker/Step/Run.zig +18 -3
- package/compiler/Maker/Step/TranslateC.zig +5 -4
- 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 +88 -37
- package/std/Build/Step/ConfigHeader.zig +3 -2
- package/std/Build/Step/Options.zig +28 -22
- package/std/Build.zig +85 -56
- 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 +4 -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
package/std/multi_array_list.zig
CHANGED
|
@@ -44,17 +44,7 @@ pub fn MultiArrayList(comptime T: type) type {
|
|
|
44
44
|
const Elem = switch (@typeInfo(T)) {
|
|
45
45
|
.@"struct" => T,
|
|
46
46
|
.@"union" => |u| struct {
|
|
47
|
-
pub const Bare =
|
|
48
|
-
var field_names: [u.fields.len][]const u8 = undefined;
|
|
49
|
-
var field_types: [u.fields.len]type = undefined;
|
|
50
|
-
var field_attrs: [u.fields.len]std.builtin.Type.UnionField.Attributes = undefined;
|
|
51
|
-
for (u.fields, &field_names, &field_types, &field_attrs) |field, *name, *Type, *attrs| {
|
|
52
|
-
name.* = field.name;
|
|
53
|
-
Type.* = field.type;
|
|
54
|
-
attrs.* = .{ .@"align" = field.alignment };
|
|
55
|
-
}
|
|
56
|
-
break :Bare @Union(u.layout, null, &field_names, &field_types, &field_attrs);
|
|
57
|
-
};
|
|
47
|
+
pub const Bare = @Union(u.layout, null, u.field_names, u.field_types[0..], u.field_attrs[0..]);
|
|
58
48
|
pub const Tag =
|
|
59
49
|
u.tag_type orelse @compileError("MultiArrayList does not support untagged unions");
|
|
60
50
|
tags: Tag,
|
|
@@ -87,7 +77,7 @@ pub fn MultiArrayList(comptime T: type) type {
|
|
|
87
77
|
pub const Slice = struct {
|
|
88
78
|
/// This array is indexed by the field index which can be obtained
|
|
89
79
|
/// by using @intFromEnum() on the Field enum
|
|
90
|
-
ptrs: [
|
|
80
|
+
ptrs: [field_names.len][*]u8,
|
|
91
81
|
len: usize,
|
|
92
82
|
capacity: usize,
|
|
93
83
|
|
|
@@ -116,15 +106,15 @@ pub fn MultiArrayList(comptime T: type) type {
|
|
|
116
106
|
.@"union" => Elem.fromT(elem),
|
|
117
107
|
else => unreachable,
|
|
118
108
|
};
|
|
119
|
-
inline for (
|
|
120
|
-
self.items(@as(Field, @enumFromInt(i)))[index] = @field(e,
|
|
109
|
+
inline for (field_names, 0..) |field_name, i| {
|
|
110
|
+
self.items(@as(Field, @enumFromInt(i)))[index] = @field(e, field_name);
|
|
121
111
|
}
|
|
122
112
|
}
|
|
123
113
|
|
|
124
114
|
pub fn get(self: Slice, index: usize) T {
|
|
125
115
|
var result: Elem = undefined;
|
|
126
|
-
inline for (
|
|
127
|
-
@field(result,
|
|
116
|
+
inline for (field_names, 0..) |field_name, i| {
|
|
117
|
+
@field(result, field_name) = self.items(@as(Field, @enumFromInt(i)))[index];
|
|
128
118
|
}
|
|
129
119
|
return switch (@typeInfo(T)) {
|
|
130
120
|
.@"struct" => result,
|
|
@@ -134,9 +124,9 @@ pub fn MultiArrayList(comptime T: type) type {
|
|
|
134
124
|
}
|
|
135
125
|
|
|
136
126
|
pub fn swap(self: Slice, a: usize, b: usize) void {
|
|
137
|
-
inline for (@typeInfo(Field).@"enum".
|
|
138
|
-
const its = self.items(@field(Field,
|
|
139
|
-
std.mem.swap(@FieldType(T,
|
|
127
|
+
inline for (@typeInfo(Field).@"enum".field_names) |field_name| {
|
|
128
|
+
const its = self.items(@field(Field, field_name));
|
|
129
|
+
std.mem.swap(@FieldType(T, field_name), &its[a], &its[b]);
|
|
140
130
|
}
|
|
141
131
|
}
|
|
142
132
|
|
|
@@ -162,9 +152,9 @@ pub fn MultiArrayList(comptime T: type) type {
|
|
|
162
152
|
/// Asserts that `off + len <= s.len`.
|
|
163
153
|
pub fn subslice(s: Slice, off: usize, len: usize) Slice {
|
|
164
154
|
assert(off + len <= s.len);
|
|
165
|
-
var ptrs: [
|
|
166
|
-
inline for (s.ptrs, &ptrs,
|
|
167
|
-
out.* = in + (off * @sizeOf(
|
|
155
|
+
var ptrs: [field_names.len][*]u8 = undefined;
|
|
156
|
+
inline for (s.ptrs, &ptrs, field_types) |in, *out, field_type| {
|
|
157
|
+
out.* = in + (off * @sizeOf(field_type));
|
|
168
158
|
}
|
|
169
159
|
return .{
|
|
170
160
|
.ptrs = ptrs,
|
|
@@ -185,7 +175,9 @@ pub fn MultiArrayList(comptime T: type) type {
|
|
|
185
175
|
|
|
186
176
|
const Self = @This();
|
|
187
177
|
|
|
188
|
-
const
|
|
178
|
+
const field_names = @typeInfo(Elem).@"struct".field_names;
|
|
179
|
+
const field_types = @typeInfo(Elem).@"struct".field_types;
|
|
180
|
+
const field_attrs = @typeInfo(Elem).@"struct".field_attrs;
|
|
189
181
|
/// `sizes.bytes` is an array of @sizeOf each T field. Sorted by alignment, descending.
|
|
190
182
|
/// `sizes.fields` is an array mapping from `sizes.bytes` array index to field index.
|
|
191
183
|
/// `sizes.big_align` is the overall alignment of the allocation, which equals the maximum field alignment.
|
|
@@ -195,13 +187,13 @@ pub fn MultiArrayList(comptime T: type) type {
|
|
|
195
187
|
size_index: usize,
|
|
196
188
|
alignment: usize,
|
|
197
189
|
};
|
|
198
|
-
var data: [
|
|
190
|
+
var data: [field_names.len]Data = undefined;
|
|
199
191
|
var big_align: usize = 1;
|
|
200
|
-
for (
|
|
192
|
+
for (field_types, field_attrs, 0..) |f_type, f_attrs, i| {
|
|
201
193
|
data[i] = .{
|
|
202
|
-
.size = @sizeOf(
|
|
194
|
+
.size = @sizeOf(f_type),
|
|
203
195
|
.size_index = i,
|
|
204
|
-
.alignment =
|
|
196
|
+
.alignment = f_attrs.@"align" orelse @alignOf(f_type),
|
|
205
197
|
};
|
|
206
198
|
big_align = @max(big_align, data[i].alignment);
|
|
207
199
|
}
|
|
@@ -211,10 +203,10 @@ pub fn MultiArrayList(comptime T: type) type {
|
|
|
211
203
|
return lhs.alignment > rhs.alignment;
|
|
212
204
|
}
|
|
213
205
|
};
|
|
214
|
-
@setEvalBranchQuota(3 *
|
|
206
|
+
@setEvalBranchQuota(3 * field_names.len * std.math.log2(field_names.len));
|
|
215
207
|
mem.sort(Data, &data, {}, Sort.lessThan);
|
|
216
|
-
var sizes_bytes: [
|
|
217
|
-
var field_indexes: [
|
|
208
|
+
var sizes_bytes: [field_names.len]usize = undefined;
|
|
209
|
+
var field_indexes: [field_names.len]usize = undefined;
|
|
218
210
|
for (data, 0..) |elem, i| {
|
|
219
211
|
sizes_bytes[i] = elem.size;
|
|
220
212
|
field_indexes[i] = elem.size_index;
|
|
@@ -368,13 +360,13 @@ pub fn MultiArrayList(comptime T: type) type {
|
|
|
368
360
|
else => unreachable,
|
|
369
361
|
};
|
|
370
362
|
const slices = self.slice();
|
|
371
|
-
inline for (
|
|
363
|
+
inline for (field_names, 0..) |field_name, field_index| {
|
|
372
364
|
const field_slice = slices.items(@as(Field, @enumFromInt(field_index)));
|
|
373
365
|
var i: usize = self.len - 1;
|
|
374
366
|
while (i > index) : (i -= 1) {
|
|
375
367
|
field_slice[i] = field_slice[i - 1];
|
|
376
368
|
}
|
|
377
|
-
field_slice[index] = @field(entry,
|
|
369
|
+
field_slice[index] = @field(entry, field_name);
|
|
378
370
|
}
|
|
379
371
|
}
|
|
380
372
|
|
|
@@ -394,7 +386,7 @@ pub fn MultiArrayList(comptime T: type) type {
|
|
|
394
386
|
/// retain list ordering.
|
|
395
387
|
pub fn swapRemove(self: *Self, index: usize) void {
|
|
396
388
|
const slices = self.slice();
|
|
397
|
-
inline for (
|
|
389
|
+
inline for (field_names, 0..) |_, i| {
|
|
398
390
|
const field_slice = slices.items(@as(Field, @enumFromInt(i)));
|
|
399
391
|
field_slice[index] = field_slice[self.len - 1];
|
|
400
392
|
field_slice[self.len - 1] = undefined;
|
|
@@ -406,7 +398,7 @@ pub fn MultiArrayList(comptime T: type) type {
|
|
|
406
398
|
/// after it to preserve order.
|
|
407
399
|
pub fn orderedRemove(self: *Self, index: usize) void {
|
|
408
400
|
const slices = self.slice();
|
|
409
|
-
inline for (
|
|
401
|
+
inline for (field_names, 0..) |_, field_index| {
|
|
410
402
|
const field_slice = slices.items(@as(Field, @enumFromInt(field_index)));
|
|
411
403
|
var i = index;
|
|
412
404
|
while (i < self.len - 1) : (i += 1) {
|
|
@@ -437,7 +429,7 @@ pub fn MultiArrayList(comptime T: type) type {
|
|
|
437
429
|
if (removed == end) continue; // allows duplicates in `sorted_indexes`
|
|
438
430
|
const start = removed + 1;
|
|
439
431
|
const len = end - start; // safety checks `sorted_indexes` are sorted
|
|
440
|
-
inline for (
|
|
432
|
+
inline for (field_names, 0..) |_, field_index| {
|
|
441
433
|
const field_slice = slices.items(@enumFromInt(field_index));
|
|
442
434
|
@memmove(field_slice[start - shift ..][0..len], field_slice[start..][0..len]); // safety checks initial `sorted_indexes` are in range
|
|
443
435
|
}
|
|
@@ -446,7 +438,7 @@ pub fn MultiArrayList(comptime T: type) type {
|
|
|
446
438
|
const start = sorted_indexes[sorted_indexes.len - 1] + 1;
|
|
447
439
|
const end = self.len;
|
|
448
440
|
const len = end - start; // safety checks final `sorted_indexes` are in range
|
|
449
|
-
inline for (
|
|
441
|
+
inline for (field_names, 0..) |_, field_index| {
|
|
450
442
|
const field_slice = slices.items(@enumFromInt(field_index));
|
|
451
443
|
@memmove(field_slice[start - shift ..][0..len], field_slice[start..][0..len]);
|
|
452
444
|
}
|
|
@@ -471,8 +463,8 @@ pub fn MultiArrayList(comptime T: type) type {
|
|
|
471
463
|
|
|
472
464
|
const other_bytes = gpa.alignedAlloc(u8, sizes.big_align, capacityInBytes(new_len)) catch {
|
|
473
465
|
const self_slice = self.slice();
|
|
474
|
-
inline for (
|
|
475
|
-
if (@sizeOf(
|
|
466
|
+
inline for (field_types, 0..) |field_type, i| {
|
|
467
|
+
if (@sizeOf(field_type) != 0) {
|
|
476
468
|
const field = @as(Field, @enumFromInt(i));
|
|
477
469
|
const dest_slice = self_slice.items(field)[new_len..];
|
|
478
470
|
// We use memset here for more efficient codegen in safety-checked,
|
|
@@ -492,8 +484,8 @@ pub fn MultiArrayList(comptime T: type) type {
|
|
|
492
484
|
self.len = new_len;
|
|
493
485
|
const self_slice = self.slice();
|
|
494
486
|
const other_slice = other.slice();
|
|
495
|
-
inline for (
|
|
496
|
-
if (@sizeOf(
|
|
487
|
+
inline for (field_types, 0..) |field_type, i| {
|
|
488
|
+
if (@sizeOf(field_type) != 0) {
|
|
497
489
|
const field = @as(Field, @enumFromInt(i));
|
|
498
490
|
@memcpy(other_slice.items(field), self_slice.items(field));
|
|
499
491
|
}
|
|
@@ -529,7 +521,7 @@ pub fn MultiArrayList(comptime T: type) type {
|
|
|
529
521
|
|
|
530
522
|
const init_capacity: comptime_int = init: {
|
|
531
523
|
var max: comptime_int = 1;
|
|
532
|
-
for (
|
|
524
|
+
for (field_types) |field_type| max = @max(max, @sizeOf(field_type));
|
|
533
525
|
break :init @max(1, std.atomic.cache_line / max);
|
|
534
526
|
};
|
|
535
527
|
|
|
@@ -564,8 +556,8 @@ pub fn MultiArrayList(comptime T: type) type {
|
|
|
564
556
|
};
|
|
565
557
|
const self_slice = self.slice();
|
|
566
558
|
const other_slice = other.slice();
|
|
567
|
-
inline for (
|
|
568
|
-
if (@sizeOf(
|
|
559
|
+
inline for (field_types, 0..) |field_type, i| {
|
|
560
|
+
if (@sizeOf(field_type) != 0) {
|
|
569
561
|
const field = @as(Field, @enumFromInt(i));
|
|
570
562
|
@memcpy(other_slice.items(field), self_slice.items(field));
|
|
571
563
|
}
|
|
@@ -583,8 +575,8 @@ pub fn MultiArrayList(comptime T: type) type {
|
|
|
583
575
|
result.len = self.len;
|
|
584
576
|
const self_slice = self.slice();
|
|
585
577
|
const result_slice = result.slice();
|
|
586
|
-
inline for (
|
|
587
|
-
if (@sizeOf(
|
|
578
|
+
inline for (field_types, 0..) |field_type, i| {
|
|
579
|
+
if (@sizeOf(field_type) != 0) {
|
|
588
580
|
const field = @as(Field, @enumFromInt(i));
|
|
589
581
|
@memcpy(result_slice.items(field), self_slice.items(field));
|
|
590
582
|
}
|
|
@@ -600,11 +592,11 @@ pub fn MultiArrayList(comptime T: type) type {
|
|
|
600
592
|
slice: Slice,
|
|
601
593
|
|
|
602
594
|
pub fn swap(sc: @This(), a_index: usize, b_index: usize) void {
|
|
603
|
-
inline for (
|
|
604
|
-
if (@sizeOf(
|
|
595
|
+
inline for (field_types, 0..) |field_type, i| {
|
|
596
|
+
if (@sizeOf(field_type) != 0) {
|
|
605
597
|
const field: Field = @enumFromInt(i);
|
|
606
598
|
const ptr = sc.slice.items(field);
|
|
607
|
-
mem.swap(
|
|
599
|
+
mem.swap(field_type, &ptr[a_index], &ptr[b_index]);
|
|
608
600
|
}
|
|
609
601
|
}
|
|
610
602
|
}
|
|
@@ -676,18 +668,18 @@ pub fn MultiArrayList(comptime T: type) type {
|
|
|
676
668
|
}
|
|
677
669
|
|
|
678
670
|
const Entry = entry: {
|
|
679
|
-
var
|
|
680
|
-
var
|
|
681
|
-
var
|
|
682
|
-
for (sizes.fields, &
|
|
683
|
-
name.* =
|
|
684
|
-
Type.* = *
|
|
671
|
+
var entry_field_names: [field_names.len][]const u8 = undefined;
|
|
672
|
+
var entry_field_types: [field_names.len]type = undefined;
|
|
673
|
+
var entry_field_attrs: [field_names.len]std.builtin.Type.Struct.FieldAttributes = undefined;
|
|
674
|
+
for (sizes.fields, &entry_field_names, &entry_field_types, &entry_field_attrs) |i, *name, *Type, *attrs| {
|
|
675
|
+
name.* = field_names[i] ++ "_ptr";
|
|
676
|
+
Type.* = *field_types[i];
|
|
685
677
|
attrs.* = .{
|
|
686
|
-
.@"comptime" =
|
|
687
|
-
.@"align" =
|
|
678
|
+
.@"comptime" = field_attrs[i].@"comptime",
|
|
679
|
+
.@"align" = field_attrs[i].@"align",
|
|
688
680
|
};
|
|
689
681
|
}
|
|
690
|
-
break :entry @Struct(.@"extern", null, &
|
|
682
|
+
break :entry @Struct(.@"extern", null, &entry_field_names, &entry_field_types, &entry_field_attrs);
|
|
691
683
|
};
|
|
692
684
|
/// This function is used in the debugger pretty formatters in tools/ to fetch the
|
|
693
685
|
/// child field order and entry type to facilitate fancy debug printing for this type.
|
|
@@ -82,16 +82,17 @@ pub const DevicePath = extern struct {
|
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
pub fn getDevicePath(self: *const DevicePath) ?uefi.DevicePath {
|
|
85
|
-
|
|
86
|
-
|
|
85
|
+
const u_info = @typeInfo(uefi.DevicePath).@"union";
|
|
86
|
+
inline for (u_info.field_names, u_info.field_types) |ufield_name, ufield_type| {
|
|
87
|
+
const enum_value = std.meta.stringToEnum(uefi.DevicePath.Type, ufield_name);
|
|
87
88
|
|
|
88
89
|
// Got the associated union type for self.type, now
|
|
89
90
|
// we need to initialize it and its subtype
|
|
90
91
|
if (self.type == enum_value) {
|
|
91
|
-
const subtype = self.initSubtype(
|
|
92
|
+
const subtype = self.initSubtype(ufield_type);
|
|
92
93
|
if (subtype) |sb| {
|
|
93
94
|
// e.g. return .{ .hardware = .{ .pci = @ptrCast(...) } }
|
|
94
|
-
return @unionInit(uefi.DevicePath,
|
|
95
|
+
return @unionInit(uefi.DevicePath, ufield_name, sb);
|
|
95
96
|
}
|
|
96
97
|
}
|
|
97
98
|
}
|
|
@@ -103,13 +104,13 @@ pub const DevicePath = extern struct {
|
|
|
103
104
|
const type_info = @typeInfo(TUnion).@"union";
|
|
104
105
|
const TTag = type_info.tag_type.?;
|
|
105
106
|
|
|
106
|
-
inline for (type_info.
|
|
107
|
+
inline for (type_info.field_names, type_info.field_types) |subtype_name, subtype_type| {
|
|
107
108
|
// The tag names match the union names, so just grab that off the enum
|
|
108
|
-
const tag_val: u8 = @intFromEnum(@field(TTag,
|
|
109
|
+
const tag_val: u8 = @intFromEnum(@field(TTag, subtype_name));
|
|
109
110
|
|
|
110
111
|
if (self.subtype == tag_val) {
|
|
111
112
|
// e.g. expr = .{ .pci = @ptrCast(...) }
|
|
112
|
-
return @unionInit(TUnion,
|
|
113
|
+
return @unionInit(TUnion, subtype_name, @as(subtype_type, @ptrCast(self)));
|
|
113
114
|
}
|
|
114
115
|
}
|
|
115
116
|
|
|
@@ -1271,7 +1271,7 @@ fn ProtocolInterfaces(HandleType: type, Interfaces: type) type {
|
|
|
1271
1271
|
@compileError("expected tuple of protocol interfaces, got " ++ @typeName(Interfaces));
|
|
1272
1272
|
const interfaces_info = interfaces_type_info.@"struct";
|
|
1273
1273
|
|
|
1274
|
-
var tuple_types: [interfaces_info.
|
|
1274
|
+
var tuple_types: [interfaces_info.field_names.len * 2 + 2]type = undefined;
|
|
1275
1275
|
tuple_types[0] = HandleType;
|
|
1276
1276
|
tuple_types[tuple_types.len - 1] = ?*const Guid;
|
|
1277
1277
|
|
package/std/os/windows.zig
CHANGED
|
@@ -144,7 +144,7 @@ pub const OBJECT = struct {
|
|
|
144
144
|
Session = 5,
|
|
145
145
|
_,
|
|
146
146
|
|
|
147
|
-
pub const Max: @typeInfo(@This()).@"enum".tag_type = @typeInfo(@This()).@"enum".
|
|
147
|
+
pub const Max: @typeInfo(@This()).@"enum".tag_type = @typeInfo(@This()).@"enum".field_names.len;
|
|
148
148
|
};
|
|
149
149
|
|
|
150
150
|
pub const NAME_INFORMATION = extern struct {
|
|
@@ -575,7 +575,7 @@ pub const FILE = struct {
|
|
|
575
575
|
MupProvider = 83,
|
|
576
576
|
_,
|
|
577
577
|
|
|
578
|
-
pub const Maximum: @typeInfo(@This()).@"enum".tag_type = 1 + @typeInfo(@This()).@"enum".
|
|
578
|
+
pub const Maximum: @typeInfo(@This()).@"enum".tag_type = 1 + @typeInfo(@This()).@"enum".field_names.len;
|
|
579
579
|
};
|
|
580
580
|
|
|
581
581
|
pub const BASIC_INFORMATION = extern struct {
|
|
@@ -881,7 +881,7 @@ pub const DIRECTORY = struct {
|
|
|
881
881
|
NotifyFull = 3,
|
|
882
882
|
_,
|
|
883
883
|
|
|
884
|
-
pub const Maximum: @typeInfo(@This()).@"enum".tag_type = 1 + @typeInfo(@This()).@"enum".
|
|
884
|
+
pub const Maximum: @typeInfo(@This()).@"enum".tag_type = 1 + @typeInfo(@This()).@"enum".field_names.len;
|
|
885
885
|
};
|
|
886
886
|
};
|
|
887
887
|
|
|
@@ -930,14 +930,8 @@ pub const CONSOLE = struct {
|
|
|
930
930
|
|
|
931
931
|
pub const Tag = @typeInfo(WITH).@"union".tag_type.?;
|
|
932
932
|
pub const Payload = PAYLOAD: {
|
|
933
|
-
const
|
|
934
|
-
|
|
935
|
-
var field_types: [with_fields.len]type = undefined;
|
|
936
|
-
for (with_fields, &field_names, &field_types) |field, *field_name, *field_type| {
|
|
937
|
-
field_name.* = field.name;
|
|
938
|
-
field_type.* = field.type;
|
|
939
|
-
}
|
|
940
|
-
break :PAYLOAD @Union(.@"extern", null, &field_names, &field_types, &@splat(.{}));
|
|
933
|
+
const with_info = @typeInfo(WITH).@"union";
|
|
934
|
+
break :PAYLOAD @Union(.@"extern", null, with_info.field_names, with_info.field_types[0..], &@splat(.{}));
|
|
941
935
|
};
|
|
942
936
|
};
|
|
943
937
|
};
|
|
@@ -2122,7 +2116,7 @@ pub const HEAP = opaque {
|
|
|
2122
2116
|
Custom,
|
|
2123
2117
|
_,
|
|
2124
2118
|
|
|
2125
|
-
pub const Max: @typeInfo(@This()).@"enum".tag_type = @typeInfo(@This()).@"enum".
|
|
2119
|
+
pub const Max: @typeInfo(@This()).@"enum".tag_type = @typeInfo(@This()).@"enum".field_names.len;
|
|
2126
2120
|
};
|
|
2127
2121
|
|
|
2128
2122
|
pub const VA_CALLBACKS = extern struct {
|
|
@@ -3369,7 +3363,7 @@ pub const FS_INFORMATION_CLASS = enum(c_int) {
|
|
|
3369
3363
|
Guid = 15,
|
|
3370
3364
|
_,
|
|
3371
3365
|
|
|
3372
|
-
pub const Maximum: @typeInfo(@This()).@"enum".tag_type = 1 + @typeInfo(@This()).@"enum".
|
|
3366
|
+
pub const Maximum: @typeInfo(@This()).@"enum".tag_type = 1 + @typeInfo(@This()).@"enum".field_names.len;
|
|
3373
3367
|
};
|
|
3374
3368
|
|
|
3375
3369
|
pub const SECTION_INHERIT = enum(c_int) {
|
|
@@ -3493,7 +3487,7 @@ pub const MEM = struct {
|
|
|
3493
3487
|
ImageMachine,
|
|
3494
3488
|
_,
|
|
3495
3489
|
|
|
3496
|
-
pub const Max: @typeInfo(@This()).@"enum".tag_type = @typeInfo(@This()).@"enum".
|
|
3490
|
+
pub const Max: @typeInfo(@This()).@"enum".tag_type = @typeInfo(@This()).@"enum".field_names.len;
|
|
3497
3491
|
};
|
|
3498
3492
|
};
|
|
3499
3493
|
};
|
|
@@ -4467,7 +4461,7 @@ pub const KEY = struct {
|
|
|
4467
4461
|
Layer = 5,
|
|
4468
4462
|
_,
|
|
4469
4463
|
|
|
4470
|
-
pub const Max: @typeInfo(@This()).@"enum".tag_type = @typeInfo(@This()).@"enum".
|
|
4464
|
+
pub const Max: @typeInfo(@This()).@"enum".tag_type = @typeInfo(@This()).@"enum".field_names.len;
|
|
4471
4465
|
};
|
|
4472
4466
|
|
|
4473
4467
|
pub const PARTIAL_INFORMATION = extern struct {
|
package/std/start.zig
CHANGED
|
@@ -24,7 +24,7 @@ comptime {
|
|
|
24
24
|
if (native_os == .windows and !builtin.link_libc and !@hasDecl(root, dll_main_crt_startup)) {
|
|
25
25
|
@export(&DllMainCRTStartup, .{ .name = dll_main_crt_startup });
|
|
26
26
|
} else if (native_os == .windows and builtin.link_libc and @hasDecl(root, "DllMain")) {
|
|
27
|
-
if (!@typeInfo(@TypeOf(root.DllMain)).@"fn".
|
|
27
|
+
if (!@typeInfo(@TypeOf(root.DllMain)).@"fn".attrs.@"callconv".eql(.winapi)) {
|
|
28
28
|
@export(&DllMain, .{ .name = "DllMain" });
|
|
29
29
|
}
|
|
30
30
|
}
|
|
@@ -32,11 +32,11 @@ comptime {
|
|
|
32
32
|
if (builtin.link_libc and @hasDecl(root, "main")) {
|
|
33
33
|
if (is_wasm) {
|
|
34
34
|
@export(&mainWithoutEnv, .{ .name = "__main_argc_argv" });
|
|
35
|
-
} else if (!@typeInfo(@TypeOf(root.main)).@"fn".
|
|
35
|
+
} else if (!@typeInfo(@TypeOf(root.main)).@"fn".attrs.@"callconv".eql(.c)) {
|
|
36
36
|
@export(&main, .{ .name = "main" });
|
|
37
37
|
}
|
|
38
38
|
} else if (native_os == .windows and builtin.link_libc and @hasDecl(root, "wWinMain")) {
|
|
39
|
-
if (!@typeInfo(@TypeOf(root.wWinMain)).@"fn".
|
|
39
|
+
if (!@typeInfo(@TypeOf(root.wWinMain)).@"fn".attrs.@"callconv".eql(.c)) {
|
|
40
40
|
@export(&wWinMain, .{ .name = "wWinMain" });
|
|
41
41
|
}
|
|
42
42
|
} else if (native_os == .windows) {
|
|
@@ -728,8 +728,8 @@ var safe_allocator: std.heap.SafeAllocator = .init(std.heap.page_allocator, .{})
|
|
|
728
728
|
|
|
729
729
|
inline fn callMain(args: std.process.Args.Vector, environ: std.process.Environ.Block) u8 {
|
|
730
730
|
const fn_info = @typeInfo(@TypeOf(root.main)).@"fn";
|
|
731
|
-
if (fn_info.
|
|
732
|
-
if (fn_info.
|
|
731
|
+
if (fn_info.param_types.len == 0) return wrapMain(root.main());
|
|
732
|
+
if (fn_info.param_types[0].? == std.process.Init.Minimal) return wrapMain(root.main(.{
|
|
733
733
|
.args = .{ .vector = args },
|
|
734
734
|
.environ = .{ .block = environ },
|
|
735
735
|
}));
|
|
@@ -809,7 +809,7 @@ inline fn wrapMain(result: anytype) u8 {
|
|
|
809
809
|
|
|
810
810
|
fn call_wWinMain() std.os.windows.INT {
|
|
811
811
|
const peb = std.os.windows.peb();
|
|
812
|
-
const MAIN_HINSTANCE = @typeInfo(@TypeOf(root.wWinMain)).@"fn".
|
|
812
|
+
const MAIN_HINSTANCE = @typeInfo(@TypeOf(root.wWinMain)).@"fn".param_types[0].?;
|
|
813
813
|
const hInstance: MAIN_HINSTANCE = @ptrCast(peb.ImageBaseAddress);
|
|
814
814
|
const lpCmdLine: [*:0]u16 = @ptrCast(peb.ProcessParameters.CommandLine.Buffer);
|
|
815
815
|
|
package/std/testing/Smith.zig
CHANGED
|
@@ -35,7 +35,12 @@ fn fromExcessK(T: type, x: Backing(T)) T {
|
|
|
35
35
|
return @as(T, @bitCast(x)) +% std.math.minInt(T);
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
const EnumField = struct {
|
|
39
|
+
name: [:0]const u8,
|
|
40
|
+
value: comptime_int,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
fn enumFieldLessThan(_: void, a: EnumField, b: EnumField) bool {
|
|
39
44
|
return a.value < b.value;
|
|
40
45
|
}
|
|
41
46
|
|
|
@@ -67,17 +72,26 @@ pub inline fn baselineWeights(T: type) []const Weight {
|
|
|
67
72
|
baselineWeights(Backing(T))
|
|
68
73
|
else
|
|
69
74
|
@compileError("non-packed unions cannot be weighted"),
|
|
70
|
-
.@"enum" => |e| if (
|
|
75
|
+
.@"enum" => |e| if (e.mode == .nonexhaustive)
|
|
71
76
|
baselineWeights(e.tag_type)
|
|
72
|
-
else if (e.
|
|
77
|
+
else if (e.field_names.len == 0)
|
|
73
78
|
// Cannot be included in below branch due to `log2_int_ceil`
|
|
74
79
|
@compileError("exhaustive zero-field enums cannot be weighted")
|
|
75
80
|
else e: {
|
|
76
|
-
@setEvalBranchQuota(@intCast(4 * e.
|
|
77
|
-
std.math.log2_int_ceil(usize, e.
|
|
78
|
-
|
|
79
|
-
var sorted_fields =
|
|
80
|
-
|
|
81
|
+
@setEvalBranchQuota(@intCast(4 * e.field_names.len *
|
|
82
|
+
std.math.log2_int_ceil(usize, e.field_names.len)));
|
|
83
|
+
|
|
84
|
+
var sorted_fields = blk: {
|
|
85
|
+
var fields: [e.field_names.len]EnumField = undefined;
|
|
86
|
+
for (e.field_names, e.field_values, &fields) |f_name, f_value, *field| {
|
|
87
|
+
field.* = .{
|
|
88
|
+
.name = f_name,
|
|
89
|
+
.value = f_value,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
break :blk fields;
|
|
93
|
+
};
|
|
94
|
+
std.mem.sortUnstable(EnumField, &sorted_fields, {}, enumFieldLessThan);
|
|
81
95
|
|
|
82
96
|
var weights: []const Weight = &.{};
|
|
83
97
|
var seq_first: u64 = sorted_fields[0].value;
|
|
@@ -316,10 +330,10 @@ fn weightsContain(int: u64, weights: []const Weight) bool {
|
|
|
316
330
|
inline fn allBitPatternsValid(T: type) bool {
|
|
317
331
|
return comptime switch (@typeInfo(T)) {
|
|
318
332
|
.void, .bool, .int, .float => true,
|
|
319
|
-
inline .@"struct", .@"union" => |c| c.layout == .@"packed" and for (c.
|
|
320
|
-
if (!allBitPatternsValid(
|
|
333
|
+
inline .@"struct", .@"union" => |c| c.layout == .@"packed" and for (c.field_types) |f_type| {
|
|
334
|
+
if (!allBitPatternsValid(f_type)) break false;
|
|
321
335
|
} else true,
|
|
322
|
-
.@"enum" => |e|
|
|
336
|
+
.@"enum" => |e| e.mode == .nonexhaustive,
|
|
323
337
|
else => unreachable,
|
|
324
338
|
};
|
|
325
339
|
}
|
|
@@ -346,16 +360,16 @@ fn UnionTagWithoutUninitializable(T: type) type {
|
|
|
346
360
|
const u = @typeInfo(T).@"union";
|
|
347
361
|
const Tag = u.tag_type orelse @compileError("union must have tag");
|
|
348
362
|
const e = @typeInfo(Tag).@"enum";
|
|
349
|
-
var field_names: [e.
|
|
350
|
-
var field_values: [e.
|
|
363
|
+
var field_names: [e.field_names.len][]const u8 = undefined;
|
|
364
|
+
var field_values: [e.field_names.len]e.tag_type = undefined;
|
|
351
365
|
var n_fields = 0;
|
|
352
|
-
for (u.
|
|
353
|
-
switch (
|
|
366
|
+
for (u.field_names, u.field_types) |f_name, f_type| {
|
|
367
|
+
switch (f_type) {
|
|
354
368
|
noreturn => continue,
|
|
355
369
|
else => {},
|
|
356
370
|
}
|
|
357
|
-
field_names[n_fields] =
|
|
358
|
-
field_values[n_fields] = @intFromEnum(@field(Tag,
|
|
371
|
+
field_names[n_fields] = f_name;
|
|
372
|
+
field_values[n_fields] = @intFromEnum(@field(Tag, f_name));
|
|
359
373
|
n_fields += 1;
|
|
360
374
|
}
|
|
361
375
|
return @Enum(e.tag_type, .exhaustive, field_names[0..n_fields], field_values[0..n_fields]);
|
|
@@ -381,12 +395,12 @@ pub fn valueWithHash(s: *Smith, T: type, hash: u32) T {
|
|
|
381
395
|
}
|
|
382
396
|
break :full @bitCast(int);
|
|
383
397
|
},
|
|
384
|
-
.@"enum" => |e| if (e.
|
|
398
|
+
.@"enum" => |e| if (e.mode == .exhaustive) v: {
|
|
385
399
|
if (@bitSizeOf(e.tag_type) <= 64) {
|
|
386
400
|
break :v s.valueWeightedWithHash(T, baselineWeights(T), hash);
|
|
387
401
|
}
|
|
388
402
|
break :v std.enums.fromInt(T, s.valueWithHash(e.tag_type, hash)) orelse
|
|
389
|
-
@enumFromInt(e.
|
|
403
|
+
@enumFromInt(e.field_values[0]);
|
|
390
404
|
} else @enumFromInt(s.valueWithHash(e.tag_type, hash)),
|
|
391
405
|
.optional => |o| if (s.valueWithHash(bool, hash))
|
|
392
406
|
null
|
|
@@ -406,11 +420,11 @@ pub fn valueWithHash(s: *Smith, T: type, hash: u32) T {
|
|
|
406
420
|
.@"struct" => |st| if (!allBitPatternsValid(T)) v: {
|
|
407
421
|
var v: T = undefined;
|
|
408
422
|
var rhash = hash;
|
|
409
|
-
inline for (st.
|
|
423
|
+
inline for (st.field_names, st.field_types) |f_name, f_type| {
|
|
410
424
|
// rhash is incremented in the call so our rhash state is not reused (e.g. with
|
|
411
425
|
// two nested structs. note that xor cannot work for this case as the bit would
|
|
412
426
|
// be flipped back here)
|
|
413
|
-
@field(v,
|
|
427
|
+
@field(v, f_name) = s.valueWithHash(f_type, rhash +% 1);
|
|
414
428
|
rhash = std.hash.int(rhash);
|
|
415
429
|
}
|
|
416
430
|
break :v v;
|
package/std/testing.zig
CHANGED
|
@@ -141,16 +141,16 @@ fn expectEqualInner(comptime T: type, expected: T, actual: T) !void {
|
|
|
141
141
|
},
|
|
142
142
|
|
|
143
143
|
.@"struct" => |structType| {
|
|
144
|
-
inline for (structType.
|
|
145
|
-
try expectEqual(@field(expected,
|
|
144
|
+
inline for (structType.field_names) |field_name| {
|
|
145
|
+
try expectEqual(@field(expected, field_name), @field(actual, field_name));
|
|
146
146
|
}
|
|
147
147
|
},
|
|
148
148
|
|
|
149
149
|
.@"union" => |union_info| {
|
|
150
150
|
if (union_info.tag_type == null) {
|
|
151
|
-
const first_size = @bitSizeOf(union_info.
|
|
152
|
-
inline for (union_info.
|
|
153
|
-
if (@bitSizeOf(
|
|
151
|
+
const first_size = @bitSizeOf(union_info.field_types[0]);
|
|
152
|
+
inline for (union_info.field_types) |field_type| {
|
|
153
|
+
if (@bitSizeOf(field_type) != first_size) {
|
|
154
154
|
@compileError("Unable to compare untagged unions with varying field sizes for type " ++ @typeName(@TypeOf(actual)));
|
|
155
155
|
}
|
|
156
156
|
}
|
|
@@ -840,9 +840,9 @@ fn expectEqualDeepInner(comptime T: type, expected: T, actual: T) error{TestExpe
|
|
|
840
840
|
},
|
|
841
841
|
|
|
842
842
|
.@"struct" => |structType| {
|
|
843
|
-
inline for (structType.
|
|
844
|
-
expectEqualDeep(@field(expected,
|
|
845
|
-
print("Field {s} incorrect. expected {any}, found {any}\n", .{
|
|
843
|
+
inline for (structType.field_names) |field_name| {
|
|
844
|
+
expectEqualDeep(@field(expected, field_name), @field(actual, field_name)) catch |e| {
|
|
845
|
+
print("Field {s} incorrect. expected {any}, found {any}\n", .{ field_name, @field(expected, field_name), @field(actual, field_name) });
|
|
846
846
|
return e;
|
|
847
847
|
};
|
|
848
848
|
}
|
|
@@ -1165,14 +1165,14 @@ fn CheckAllAllocationFailuresExtraArgs(comptime TestFn: type) type {
|
|
|
1165
1165
|
|
|
1166
1166
|
const ArgsTuple = std.meta.ArgsTuple(TestFn);
|
|
1167
1167
|
|
|
1168
|
-
const
|
|
1169
|
-
if (
|
|
1168
|
+
const field_types = @typeInfo(ArgsTuple).@"struct".field_types;
|
|
1169
|
+
if (field_types.len == 0 or field_types[0] != std.mem.Allocator) {
|
|
1170
1170
|
@compileError("The provided function must have an " ++ @typeName(std.mem.Allocator) ++ " as its first argument");
|
|
1171
1171
|
}
|
|
1172
1172
|
|
|
1173
|
-
var extra_args: [
|
|
1174
|
-
for (&extra_args,
|
|
1175
|
-
arg.* =
|
|
1173
|
+
var extra_args: [field_types.len - 1]type = undefined;
|
|
1174
|
+
for (&extra_args, field_types[1..]) |*arg, field_type| {
|
|
1175
|
+
arg.* = field_type;
|
|
1176
1176
|
}
|
|
1177
1177
|
|
|
1178
1178
|
return @Tuple(&extra_args);
|
|
@@ -1204,8 +1204,8 @@ test "checkAllAllocationFailures provide result type to 'extra_args' argument" {
|
|
|
1204
1204
|
/// Given a type, references all the declarations inside, so that the semantic analyzer sees them.
|
|
1205
1205
|
pub fn refAllDecls(comptime T: type) void {
|
|
1206
1206
|
if (!builtin.is_test) return;
|
|
1207
|
-
inline for (comptime std.meta.declarations(T)) |
|
|
1208
|
-
_ = &@field(T,
|
|
1207
|
+
inline for (comptime std.meta.declarations(T)) |decl_name| {
|
|
1208
|
+
_ = &@field(T, decl_name);
|
|
1209
1209
|
}
|
|
1210
1210
|
}
|
|
1211
1211
|
|
package/std/zig/Ast.zig
CHANGED
|
@@ -298,17 +298,17 @@ pub fn extraDataSliceWithLen(tree: Ast, start: ExtraIndex, len: u32, comptime T:
|
|
|
298
298
|
}
|
|
299
299
|
|
|
300
300
|
pub fn extraData(tree: Ast, index: ExtraIndex, comptime T: type) T {
|
|
301
|
-
const
|
|
301
|
+
const info = @typeInfo(T).@"struct";
|
|
302
302
|
var result: T = undefined;
|
|
303
|
-
inline for (
|
|
304
|
-
@field(result,
|
|
303
|
+
inline for (info.field_names, info.field_types, 0..) |field_name, field_type, i| {
|
|
304
|
+
@field(result, field_name) = switch (field_type) {
|
|
305
305
|
Node.Index,
|
|
306
306
|
Node.OptionalIndex,
|
|
307
307
|
OptionalTokenIndex,
|
|
308
308
|
ExtraIndex,
|
|
309
309
|
=> @enumFromInt(tree.extra_data[@intFromEnum(index) + i]),
|
|
310
310
|
TokenIndex => tree.extra_data[@intFromEnum(index) + i],
|
|
311
|
-
else => @compileError("unexpected field type: " ++ @typeName(
|
|
311
|
+
else => @compileError("unexpected field type: " ++ @typeName(field_type)),
|
|
312
312
|
};
|
|
313
313
|
}
|
|
314
314
|
return result;
|