@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
package/std/meta.zig
CHANGED
|
@@ -8,7 +8,7 @@ const root = @import("root");
|
|
|
8
8
|
|
|
9
9
|
pub const TrailerFlags = @import("meta/trailer_flags.zig").TrailerFlags;
|
|
10
10
|
|
|
11
|
-
const Type = std.
|
|
11
|
+
const Type = std.lang.Type;
|
|
12
12
|
|
|
13
13
|
test {
|
|
14
14
|
_ = TrailerFlags;
|
|
@@ -22,21 +22,21 @@ pub fn stringToEnum(comptime T: type, str: []const u8) ?T {
|
|
|
22
22
|
// TODO The '100' here is arbitrary and should be increased when possible:
|
|
23
23
|
// - https://github.com/ziglang/zig/issues/4055
|
|
24
24
|
// - https://github.com/ziglang/zig/issues/3863
|
|
25
|
-
if (@typeInfo(T).@"enum".
|
|
25
|
+
if (@typeInfo(T).@"enum".field_names.len <= 100) {
|
|
26
26
|
const kvs = comptime build_kvs: {
|
|
27
27
|
const EnumKV = struct { []const u8, T };
|
|
28
|
-
var kvs_array: [@typeInfo(T).@"enum".
|
|
29
|
-
for (@typeInfo(T).@"enum".
|
|
30
|
-
kvs_array[i] = .{
|
|
28
|
+
var kvs_array: [@typeInfo(T).@"enum".field_names.len]EnumKV = undefined;
|
|
29
|
+
for (@typeInfo(T).@"enum".field_names, 0..) |name, i| {
|
|
30
|
+
kvs_array[i] = .{ name, @field(T, name) };
|
|
31
31
|
}
|
|
32
32
|
break :build_kvs kvs_array[0..];
|
|
33
33
|
};
|
|
34
34
|
const map = std.StaticStringMap(T).initComptime(kvs);
|
|
35
35
|
return map.get(str);
|
|
36
36
|
} else {
|
|
37
|
-
inline for (@typeInfo(T).@"enum".
|
|
38
|
-
if (mem.eql(u8, str,
|
|
39
|
-
return @field(T,
|
|
37
|
+
inline for (@typeInfo(T).@"enum".field_names) |name| {
|
|
38
|
+
if (mem.eql(u8, str, name)) {
|
|
39
|
+
return @field(T, name);
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
return null;
|
|
@@ -63,7 +63,7 @@ pub fn alignment(comptime T: type) comptime_int {
|
|
|
63
63
|
.pointer, .@"fn" => alignment(info.child),
|
|
64
64
|
else => @alignOf(T),
|
|
65
65
|
},
|
|
66
|
-
.pointer => |info| info.
|
|
66
|
+
.pointer => |info| info.attrs.@"align" orelse @alignOf(info.child),
|
|
67
67
|
else => @alignOf(T),
|
|
68
68
|
};
|
|
69
69
|
}
|
|
@@ -171,34 +171,20 @@ pub fn Sentinel(comptime T: type, comptime sentinel_val: Elem(T)) type {
|
|
|
171
171
|
switch (@typeInfo(T)) {
|
|
172
172
|
.pointer => |info| switch (info.size) {
|
|
173
173
|
.one => switch (@typeInfo(info.child)) {
|
|
174
|
-
.array => |array_info| return @Pointer(
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}, [array_info.len:sentinel_val]array_info.child, null),
|
|
174
|
+
.array => |array_info| return @Pointer(
|
|
175
|
+
.one,
|
|
176
|
+
info.attrs,
|
|
177
|
+
[array_info.len:sentinel_val]array_info.child,
|
|
178
|
+
null,
|
|
179
|
+
),
|
|
181
180
|
else => {},
|
|
182
181
|
},
|
|
183
|
-
.many, .slice => |size| return @Pointer(size, .
|
|
184
|
-
.@"const" = info.is_const,
|
|
185
|
-
.@"volatile" = info.is_volatile,
|
|
186
|
-
.@"allowzero" = info.is_allowzero,
|
|
187
|
-
.@"align" = info.alignment,
|
|
188
|
-
.@"addrspace" = info.address_space,
|
|
189
|
-
}, info.child, sentinel_val),
|
|
182
|
+
.many, .slice => |size| return @Pointer(size, info.attrs, info.child, sentinel_val),
|
|
190
183
|
else => {},
|
|
191
184
|
},
|
|
192
185
|
.optional => |info| switch (@typeInfo(info.child)) {
|
|
193
186
|
.pointer => |ptr_info| switch (ptr_info.size) {
|
|
194
|
-
.many => return ?@Pointer(.many, .
|
|
195
|
-
.@"const" = ptr_info.is_const,
|
|
196
|
-
.@"volatile" = ptr_info.is_volatile,
|
|
197
|
-
.@"allowzero" = ptr_info.is_allowzero,
|
|
198
|
-
.@"align" = ptr_info.alignment,
|
|
199
|
-
.@"addrspace" = ptr_info.address_space,
|
|
200
|
-
.child = ptr_info.child,
|
|
201
|
-
}, ptr_info.child, sentinel_val),
|
|
187
|
+
.many => return ?@Pointer(.many, ptr_info.attrs, ptr_info.child, sentinel_val),
|
|
202
188
|
else => {},
|
|
203
189
|
},
|
|
204
190
|
else => {},
|
|
@@ -238,14 +224,14 @@ test containerLayout {
|
|
|
238
224
|
try testing.expect(containerLayout(U3) == .@"extern");
|
|
239
225
|
}
|
|
240
226
|
|
|
241
|
-
/// Instead of this function, prefer to use e.g. `@typeInfo(foo).@"struct".
|
|
227
|
+
/// Instead of this function, prefer to use e.g. `@typeInfo(foo).@"struct".decl_names`
|
|
242
228
|
/// directly when you know what kind of type it is.
|
|
243
|
-
pub fn declarations(comptime T: type) []const
|
|
229
|
+
pub fn declarations(comptime T: type) []const [:0]const u8 {
|
|
244
230
|
return switch (@typeInfo(T)) {
|
|
245
|
-
.@"struct" => |info| info.
|
|
246
|
-
.@"enum" => |info| info.
|
|
247
|
-
.@"union" => |info| info.
|
|
248
|
-
.@"opaque" => |info| info.
|
|
231
|
+
.@"struct" => |info| info.decl_names,
|
|
232
|
+
.@"enum" => |info| info.decl_names,
|
|
233
|
+
.@"union" => |info| info.decl_names,
|
|
234
|
+
.@"opaque" => |info| info.decl_names,
|
|
249
235
|
else => @compileError("Expected struct, enum, union, or opaque type, found '" ++ @typeName(T) ++ "'"),
|
|
250
236
|
};
|
|
251
237
|
}
|
|
@@ -268,7 +254,7 @@ test declarations {
|
|
|
268
254
|
pub fn a() void {}
|
|
269
255
|
};
|
|
270
256
|
|
|
271
|
-
const decls = comptime [_][]const
|
|
257
|
+
const decls = comptime [_][]const [:0]const u8{
|
|
272
258
|
declarations(E1),
|
|
273
259
|
declarations(S1),
|
|
274
260
|
declarations(U1),
|
|
@@ -277,99 +263,43 @@ test declarations {
|
|
|
277
263
|
|
|
278
264
|
inline for (decls) |decl| {
|
|
279
265
|
try testing.expect(decl.len == 1);
|
|
280
|
-
try testing.expect(comptime mem.eql(u8, decl[0]
|
|
266
|
+
try testing.expect(comptime mem.eql(u8, decl[0], "a"));
|
|
281
267
|
}
|
|
282
268
|
}
|
|
283
269
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
@compileError("'" ++ @typeName(T) ++ "' has no declaration '" ++ decl_name ++ "'");
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
test declarationInfo {
|
|
294
|
-
const E1 = enum {
|
|
295
|
-
A,
|
|
296
|
-
|
|
297
|
-
pub fn a() void {}
|
|
298
|
-
};
|
|
299
|
-
const S1 = struct {
|
|
300
|
-
pub fn a() void {}
|
|
301
|
-
};
|
|
302
|
-
const U1 = union {
|
|
303
|
-
b: u8,
|
|
304
|
-
|
|
305
|
-
pub fn a() void {}
|
|
306
|
-
};
|
|
307
|
-
|
|
308
|
-
const infos = comptime [_]Type.Declaration{
|
|
309
|
-
declarationInfo(E1, "a"),
|
|
310
|
-
declarationInfo(S1, "a"),
|
|
311
|
-
declarationInfo(U1, "a"),
|
|
312
|
-
};
|
|
270
|
+
/// To be removed after Zig 0.17.0 is tagged.
|
|
271
|
+
pub const declarationInfo = @compileError("Deprecated; use '@hasDecl' instead");
|
|
272
|
+
/// To be removed after Zig 0.17.0 is tagged.
|
|
273
|
+
pub const fields = @compileError("Deprecated; use 'fieldNames' and 'fieldTypes' instead");
|
|
313
274
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
.@"struct" => []const Type.StructField,
|
|
320
|
-
.@"union" => []const Type.UnionField,
|
|
321
|
-
.@"enum" => []const Type.EnumField,
|
|
322
|
-
.error_set => []const Type.Error,
|
|
275
|
+
pub fn fieldInfo(comptime T: type, comptime field: FieldEnum(T)) switch (@typeInfo(T)) {
|
|
276
|
+
.@"struct" => struct { name: [:0]const u8, type: type, attrs: Type.Struct.FieldAttributes },
|
|
277
|
+
.@"union" => struct { name: [:0]const u8, type: type, attrs: Type.Union.FieldAttributes },
|
|
278
|
+
.@"enum" => struct { name: [:0]const u8, value: comptime_int },
|
|
279
|
+
.error_set => struct { name: [:0]const u8 },
|
|
323
280
|
else => @compileError("Expected struct, union, error set or enum type, found '" ++ @typeName(T) ++ "'"),
|
|
324
281
|
} {
|
|
282
|
+
const idx = @intFromEnum(field);
|
|
325
283
|
return switch (@typeInfo(T)) {
|
|
326
|
-
.@"struct" => |info|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
284
|
+
.@"struct" => |info| .{
|
|
285
|
+
.name = info.field_names[idx],
|
|
286
|
+
.type = info.field_types[idx],
|
|
287
|
+
.attrs = info.field_attrs[idx],
|
|
288
|
+
},
|
|
289
|
+
.@"union" => |info| .{
|
|
290
|
+
.name = info.field_names[idx],
|
|
291
|
+
.type = info.field_types[idx],
|
|
292
|
+
.attrs = info.field_attrs[idx],
|
|
293
|
+
},
|
|
294
|
+
.@"enum" => |info| .{
|
|
295
|
+
.name = info.field_names[idx],
|
|
296
|
+
.value = info.field_values[idx],
|
|
297
|
+
},
|
|
298
|
+
.error_set => |info| .{ .name = info.error_names.?[idx] },
|
|
330
299
|
else => @compileError("Expected struct, union, error set or enum type, found '" ++ @typeName(T) ++ "'"),
|
|
331
300
|
};
|
|
332
301
|
}
|
|
333
302
|
|
|
334
|
-
test fields {
|
|
335
|
-
const E1 = enum {
|
|
336
|
-
A,
|
|
337
|
-
};
|
|
338
|
-
const E2 = error{A};
|
|
339
|
-
const S1 = struct {
|
|
340
|
-
a: u8,
|
|
341
|
-
};
|
|
342
|
-
const U1 = union {
|
|
343
|
-
a: u8,
|
|
344
|
-
};
|
|
345
|
-
|
|
346
|
-
const e1f = comptime fields(E1);
|
|
347
|
-
const e2f = comptime fields(E2);
|
|
348
|
-
const sf = comptime fields(S1);
|
|
349
|
-
const uf = comptime fields(U1);
|
|
350
|
-
|
|
351
|
-
try testing.expect(e1f.len == 1);
|
|
352
|
-
try testing.expect(e2f.len == 1);
|
|
353
|
-
try testing.expect(sf.len == 1);
|
|
354
|
-
try testing.expect(uf.len == 1);
|
|
355
|
-
try testing.expect(mem.eql(u8, e1f[0].name, "A"));
|
|
356
|
-
try testing.expect(mem.eql(u8, e2f[0].name, "A"));
|
|
357
|
-
try testing.expect(mem.eql(u8, sf[0].name, "a"));
|
|
358
|
-
try testing.expect(mem.eql(u8, uf[0].name, "a"));
|
|
359
|
-
try testing.expect(comptime sf[0].type == u8);
|
|
360
|
-
try testing.expect(comptime uf[0].type == u8);
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
pub fn fieldInfo(comptime T: type, comptime field: FieldEnum(T)) switch (@typeInfo(T)) {
|
|
364
|
-
.@"struct" => Type.StructField,
|
|
365
|
-
.@"union" => Type.UnionField,
|
|
366
|
-
.@"enum" => Type.EnumField,
|
|
367
|
-
.error_set => Type.Error,
|
|
368
|
-
else => @compileError("Expected struct, union, error set or enum type, found '" ++ @typeName(T) ++ "'"),
|
|
369
|
-
} {
|
|
370
|
-
return fields(T)[@intFromEnum(field)];
|
|
371
|
-
}
|
|
372
|
-
|
|
373
303
|
test fieldInfo {
|
|
374
304
|
const E1 = enum {
|
|
375
305
|
A,
|
|
@@ -395,13 +325,13 @@ test fieldInfo {
|
|
|
395
325
|
try testing.expect(comptime uf.type == u8);
|
|
396
326
|
}
|
|
397
327
|
|
|
398
|
-
pub fn fieldNames(comptime T: type)
|
|
399
|
-
return
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
328
|
+
pub fn fieldNames(comptime T: type) []const [:0]const u8 {
|
|
329
|
+
return switch (@typeInfo(T)) {
|
|
330
|
+
.@"struct" => |s| s.field_names,
|
|
331
|
+
.@"union" => |u| u.field_names,
|
|
332
|
+
.@"enum" => |e| e.field_names,
|
|
333
|
+
.error_set => |es| es.error_names.?,
|
|
334
|
+
else => @compileError("Expected struct, union, error set or enum type, found '" ++ @typeName(T) ++ "'"),
|
|
405
335
|
};
|
|
406
336
|
}
|
|
407
337
|
|
|
@@ -433,14 +363,41 @@ test fieldNames {
|
|
|
433
363
|
try testing.expectEqualSlices(u8, u1names[1], "b");
|
|
434
364
|
}
|
|
435
365
|
|
|
366
|
+
pub fn fieldTypes(comptime T: type) []const type {
|
|
367
|
+
return switch (@typeInfo(T)) {
|
|
368
|
+
.@"struct" => |s| s.field_types,
|
|
369
|
+
.@"union" => |u| u.field_types,
|
|
370
|
+
else => @compileError("Expected struct or union type, found '" ++ @typeName(T) ++ "'"),
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
test fieldTypes {
|
|
375
|
+
const S1 = struct {
|
|
376
|
+
a: u8,
|
|
377
|
+
};
|
|
378
|
+
const U1 = union {
|
|
379
|
+
a: u8,
|
|
380
|
+
b: void,
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
const s1types = comptime fieldTypes(S1);
|
|
384
|
+
const u1types = comptime fieldTypes(U1);
|
|
385
|
+
|
|
386
|
+
try testing.expect(s1types.len == 1);
|
|
387
|
+
try testing.expect(s1types[0] == u8);
|
|
388
|
+
try testing.expect(u1types.len == 2);
|
|
389
|
+
try testing.expect(u1types[0] == u8);
|
|
390
|
+
try testing.expect(u1types[1] == void);
|
|
391
|
+
}
|
|
392
|
+
|
|
436
393
|
/// Given an enum or error set type, returns a pointer to an array containing all tags for that
|
|
437
394
|
/// enum or error set.
|
|
438
|
-
pub fn tags(comptime T: type) *const [
|
|
395
|
+
pub fn tags(comptime T: type) *const [fieldNames(T).len]T {
|
|
439
396
|
return comptime blk: {
|
|
440
|
-
const
|
|
441
|
-
var res: [
|
|
442
|
-
for (
|
|
443
|
-
res[i] = @field(T,
|
|
397
|
+
const field_names = fieldNames(T);
|
|
398
|
+
var res: [field_names.len]T = undefined;
|
|
399
|
+
for (field_names, 0..) |field_name, i| {
|
|
400
|
+
res[i] = @field(T, field_name);
|
|
444
401
|
}
|
|
445
402
|
const final = res;
|
|
446
403
|
break :blk &final;
|
|
@@ -491,27 +448,30 @@ fn expectEqualEnum(expected: anytype, actual: @TypeOf(expected)) !void {
|
|
|
491
448
|
// because the language does not guarantee that the slice pointers for field names
|
|
492
449
|
// and decl names will be the same.
|
|
493
450
|
comptime {
|
|
494
|
-
const
|
|
495
|
-
const
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
451
|
+
const expected_field_names = @typeInfo(expected).@"enum".field_names;
|
|
452
|
+
const expected_field_values = @typeInfo(expected).@"enum".field_values;
|
|
453
|
+
const actual_field_names = @typeInfo(actual).@"enum".field_names;
|
|
454
|
+
const actual_field_values = @typeInfo(actual).@"enum".field_values;
|
|
455
|
+
if (expected_field_names.len != actual_field_names.len) return error.FailedTest;
|
|
456
|
+
for (expected_field_names, expected_field_values, 0..) |expected_field_name, expected_field_value, i| {
|
|
457
|
+
const actual_field_name = actual_field_names[i];
|
|
458
|
+
const actual_field_value = actual_field_values[i];
|
|
459
|
+
try testing.expectEqual(expected_field_value, actual_field_value);
|
|
460
|
+
try testing.expectEqualStrings(expected_field_name, actual_field_name);
|
|
501
461
|
}
|
|
502
462
|
}
|
|
503
463
|
comptime {
|
|
504
|
-
const
|
|
505
|
-
const
|
|
506
|
-
if (
|
|
507
|
-
for (
|
|
508
|
-
const
|
|
509
|
-
try testing.expectEqualStrings(
|
|
464
|
+
const expected_decl_names = @typeInfo(expected).@"enum".decl_names;
|
|
465
|
+
const actual_decl_names = @typeInfo(actual).@"enum".decl_names;
|
|
466
|
+
if (expected_decl_names.len != actual_decl_names.len) return error.FailedTest;
|
|
467
|
+
for (expected_decl_names, 0..) |expected_decl_name, i| {
|
|
468
|
+
const actual_decl_name = actual_decl_names[i];
|
|
469
|
+
try testing.expectEqualStrings(expected_decl_name, actual_decl_name);
|
|
510
470
|
}
|
|
511
471
|
}
|
|
512
472
|
try testing.expectEqual(
|
|
513
|
-
@typeInfo(expected).@"enum".
|
|
514
|
-
@typeInfo(actual).@"enum".
|
|
473
|
+
@typeInfo(expected).@"enum".mode,
|
|
474
|
+
@typeInfo(actual).@"enum".mode,
|
|
515
475
|
);
|
|
516
476
|
}
|
|
517
477
|
|
|
@@ -534,11 +494,9 @@ test FieldEnum {
|
|
|
534
494
|
}
|
|
535
495
|
|
|
536
496
|
pub fn DeclEnum(comptime T: type) type {
|
|
537
|
-
const
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
const IntTag = std.math.IntFittingRange(0, decls.len -| 1);
|
|
541
|
-
return @Enum(IntTag, .exhaustive, &names, &std.simd.iota(IntTag, decls.len));
|
|
497
|
+
const decl_names = declarations(T);
|
|
498
|
+
const IntTag = std.math.IntFittingRange(0, decl_names.len -| 1);
|
|
499
|
+
return @Enum(IntTag, .exhaustive, decl_names, &std.simd.iota(IntTag, decl_names.len));
|
|
542
500
|
}
|
|
543
501
|
|
|
544
502
|
test DeclEnum {
|
|
@@ -622,8 +580,8 @@ pub fn eql(a: anytype, b: @TypeOf(a)) bool {
|
|
|
622
580
|
.@"struct" => |info| {
|
|
623
581
|
if (info.layout == .@"packed") return a == b;
|
|
624
582
|
|
|
625
|
-
inline for (info.
|
|
626
|
-
if (!eql(@field(a,
|
|
583
|
+
inline for (info.field_names) |field_name| {
|
|
584
|
+
if (!eql(@field(a, field_name), @field(b, field_name))) return false;
|
|
627
585
|
}
|
|
628
586
|
return true;
|
|
629
587
|
},
|
|
@@ -744,8 +702,8 @@ test eql {
|
|
|
744
702
|
/// Given a type and a name, return the field index according to source order.
|
|
745
703
|
/// Returns `null` if the field is not found.
|
|
746
704
|
pub fn fieldIndex(comptime T: type, comptime name: []const u8) ?comptime_int {
|
|
747
|
-
inline for (
|
|
748
|
-
if (mem.eql(u8,
|
|
705
|
+
inline for (fieldNames(T), 0..) |field_name, i| {
|
|
706
|
+
if (mem.eql(u8, field_name, name))
|
|
749
707
|
return i;
|
|
750
708
|
}
|
|
751
709
|
return null;
|
|
@@ -782,12 +740,12 @@ pub fn ArgsTuple(comptime Function: type) type {
|
|
|
782
740
|
@compileError("ArgsTuple expects a function type");
|
|
783
741
|
|
|
784
742
|
const function_info = info.@"fn";
|
|
785
|
-
if (function_info.
|
|
743
|
+
if (function_info.attrs.varargs)
|
|
786
744
|
@compileError("Cannot create ArgsTuple for variadic function");
|
|
787
745
|
|
|
788
|
-
var argument_field_list: [function_info.
|
|
789
|
-
inline for (function_info.
|
|
790
|
-
const T =
|
|
746
|
+
var argument_field_list: [function_info.param_types.len]type = undefined;
|
|
747
|
+
inline for (function_info.param_types, 0..) |arg_type, i| {
|
|
748
|
+
const T = arg_type orelse @compileError("cannot create ArgsTuple for function with an 'anytype' parameter");
|
|
791
749
|
argument_field_list[i] = T;
|
|
792
750
|
}
|
|
793
751
|
|
|
@@ -807,13 +765,15 @@ const TupleTester = struct {
|
|
|
807
765
|
if (!info.@"struct".is_tuple)
|
|
808
766
|
@compileError("Struct type must be a tuple type");
|
|
809
767
|
|
|
810
|
-
const
|
|
811
|
-
if (expected.len !=
|
|
812
|
-
|
|
768
|
+
const field_names = info.@"struct".field_names;
|
|
769
|
+
if (expected.len != field_names.len) {
|
|
770
|
+
const msg = std.fmt.comptimePrint("Argument count mismatch: expected {d}, got {d}", .{ expected.len, field_names.len });
|
|
771
|
+
@compileError(msg);
|
|
772
|
+
}
|
|
813
773
|
|
|
814
|
-
inline for (
|
|
815
|
-
if (expected[i] !=
|
|
816
|
-
@compileError("Field " ++
|
|
774
|
+
inline for (field_names, info.@"struct".field_types, 0..) |fld_name, fld_type, i| {
|
|
775
|
+
if (expected[i] != fld_type) {
|
|
776
|
+
@compileError("Field " ++ fld_name ++ " expected to be type " ++ @typeName(expected[i]) ++ ", but was type " ++ @typeName(fld_type));
|
|
817
777
|
}
|
|
818
778
|
}
|
|
819
779
|
}
|
|
@@ -943,7 +903,7 @@ pub inline fn hasUniqueRepresentation(comptime T: type) bool {
|
|
|
943
903
|
.pointer => |info| info.size != .slice,
|
|
944
904
|
|
|
945
905
|
.optional => |info| switch (@typeInfo(info.child)) {
|
|
946
|
-
.pointer => |ptr| !ptr.
|
|
906
|
+
.pointer => |ptr| !ptr.attrs.@"allowzero" and switch (ptr.size) {
|
|
947
907
|
.slice, .c => false,
|
|
948
908
|
.one, .many => true,
|
|
949
909
|
},
|
|
@@ -957,10 +917,10 @@ pub inline fn hasUniqueRepresentation(comptime T: type) bool {
|
|
|
957
917
|
|
|
958
918
|
var sum_size = @as(usize, 0);
|
|
959
919
|
|
|
960
|
-
inline for (info.
|
|
961
|
-
if (
|
|
962
|
-
if (!hasUniqueRepresentation(
|
|
963
|
-
sum_size += @sizeOf(
|
|
920
|
+
inline for (info.field_attrs, info.field_types) |field_attr, field_type| {
|
|
921
|
+
if (field_attr.@"comptime") continue;
|
|
922
|
+
if (!hasUniqueRepresentation(field_type)) return false;
|
|
923
|
+
sum_size += @sizeOf(field_type);
|
|
964
924
|
}
|
|
965
925
|
|
|
966
926
|
return @sizeOf(T) == sum_size;
|