@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.
Files changed (114) hide show
  1. package/compiler/Maker/ScannedConfig.zig +4 -3
  2. package/compiler/Maker/Step/FindProgram.zig +2 -2
  3. package/compiler/Maker/Watch/FsEvents.zig +3 -2
  4. package/compiler/aro/aro/Attribute.zig +52 -51
  5. package/compiler/aro/aro/Compilation.zig +5 -5
  6. package/compiler/aro/aro/Diagnostics.zig +7 -7
  7. package/compiler/aro/aro/Parser.zig +2 -2
  8. package/compiler/aro/aro/Tree.zig +11 -11
  9. package/compiler/aro/aro/features.zig +4 -4
  10. package/compiler/aro/aro/text_literal.zig +2 -2
  11. package/compiler/aro/backend/Interner.zig +14 -13
  12. package/compiler/configurer.zig +2 -2
  13. package/compiler/resinator/bmp.zig +3 -2
  14. package/compiler/resinator/code_pages.zig +14 -12
  15. package/compiler/resinator/cvtres.zig +11 -10
  16. package/compiler/resinator/errors.zig +18 -22
  17. package/compiler/resinator/lang.zig +7 -7
  18. package/compiler/resinator/parse.zig +1 -1
  19. package/compiler/translate-c/ast.zig +6 -6
  20. package/docs/wasm/markdown/Document.zig +3 -3
  21. package/docs/wasm/markdown/Parser.zig +3 -3
  22. package/package.json +1 -1
  23. package/std/Build/Cache.zig +2 -2
  24. package/std/Build/Configuration.zig +19 -16
  25. package/std/Build/Step/ConfigHeader.zig +3 -2
  26. package/std/Build/Step/Options.zig +28 -22
  27. package/std/Build.zig +52 -53
  28. package/std/Io/Kqueue.zig +2 -2
  29. package/std/Io/Reader.zig +1 -1
  30. package/std/Io/Threaded.zig +18 -15
  31. package/std/Io/Uring.zig +2 -2
  32. package/std/Io/Writer.zig +18 -18
  33. package/std/Io/net.zig +3 -1
  34. package/std/Io.zig +7 -6
  35. package/std/Progress.zig +2 -2
  36. package/std/Target/aarch64.zig +2 -2
  37. package/std/Target/alpha.zig +2 -2
  38. package/std/Target/amdgcn.zig +2 -2
  39. package/std/Target/arc.zig +2 -2
  40. package/std/Target/arm.zig +2 -2
  41. package/std/Target/avr.zig +2 -2
  42. package/std/Target/bpf.zig +2 -2
  43. package/std/Target/csky.zig +2 -2
  44. package/std/Target/hexagon.zig +2 -2
  45. package/std/Target/hppa.zig +2 -2
  46. package/std/Target/kvx.zig +2 -2
  47. package/std/Target/lanai.zig +2 -2
  48. package/std/Target/loongarch.zig +2 -2
  49. package/std/Target/m68k.zig +2 -2
  50. package/std/Target/mips.zig +2 -2
  51. package/std/Target/msp430.zig +2 -2
  52. package/std/Target/nvptx.zig +2 -2
  53. package/std/Target/powerpc.zig +2 -2
  54. package/std/Target/propeller.zig +2 -2
  55. package/std/Target/riscv.zig +2 -2
  56. package/std/Target/s390x.zig +2 -2
  57. package/std/Target/sparc.zig +2 -2
  58. package/std/Target/spirv.zig +2 -2
  59. package/std/Target/ve.zig +2 -2
  60. package/std/Target/wasm.zig +2 -2
  61. package/std/Target/x86.zig +2 -2
  62. package/std/Target/xcore.zig +2 -2
  63. package/std/Target/xtensa.zig +2 -2
  64. package/std/Target.zig +4 -4
  65. package/std/c/darwin.zig +1 -1
  66. package/std/coff.zig +1 -1
  67. package/std/crypto/codecs/asn1/Oid.zig +8 -8
  68. package/std/crypto/codecs/asn1/der/Decoder.zig +7 -7
  69. package/std/crypto/codecs/asn1/der/Encoder.zig +10 -8
  70. package/std/crypto/phc_encoding.zig +23 -20
  71. package/std/crypto/timing_safe.zig +1 -1
  72. package/std/crypto/tls/Client.zig +3 -3
  73. package/std/crypto/tls.zig +1 -1
  74. package/std/debug/Dwarf/Unwind/VirtualMachine.zig +11 -5
  75. package/std/debug/ElfFile.zig +12 -8
  76. package/std/debug/MachOFile.zig +2 -2
  77. package/std/debug/SelfInfo/MachO.zig +2 -2
  78. package/std/debug/SelfInfo/Windows.zig +2 -2
  79. package/std/elf.zig +7 -7
  80. package/std/enums.zig +66 -67
  81. package/std/gpu.zig +1 -1
  82. package/std/hash/auto_hash.zig +8 -8
  83. package/std/hash/verify.zig +3 -3
  84. package/std/http/Client.zig +2 -2
  85. package/std/json/Stringify.zig +14 -14
  86. package/std/json/static.zig +47 -31
  87. package/std/lang.zig +65 -97
  88. package/std/math.zig +2 -2
  89. package/std/mem/Allocator.zig +9 -9
  90. package/std/mem.zig +86 -102
  91. package/std/meta/trailer_flags.zig +26 -19
  92. package/std/meta.zig +131 -171
  93. package/std/multi_array_list.zig +49 -57
  94. package/std/os/uefi/protocol/device_path.zig +8 -7
  95. package/std/os/uefi/tables/boot_services.zig +1 -1
  96. package/std/os/windows.zig +9 -15
  97. package/std/start.zig +6 -6
  98. package/std/testing/Smith.zig +35 -21
  99. package/std/testing.zig +15 -15
  100. package/std/zig/Ast.zig +4 -4
  101. package/std/zig/AstGen.zig +42 -42
  102. package/std/zig/ErrorBundle.zig +16 -13
  103. package/std/zig/LibCInstallation.zig +11 -11
  104. package/std/zig/Parse.zig +6 -6
  105. package/std/zig/Zir.zig +10 -10
  106. package/std/zig/c_translation/helpers.zig +2 -2
  107. package/std/zig/llvm/BitcodeReader.zig +3 -3
  108. package/std/zig/llvm/Builder.zig +124 -93
  109. package/std/zig/llvm/bitcode_writer.zig +4 -4
  110. package/std/zig/system/windows.zig +11 -11
  111. package/std/zig/system.zig +4 -4
  112. package/std/zig.zig +4 -4
  113. package/std/zon/Serializer.zig +28 -23
  114. package/std/zon/parse.zig +58 -61
@@ -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.params.len > 1) {
6
- if (@typeInfo(HashFn.params[0].type.?) == .int) {
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.params.len == 1) {
18
+ if (HashFn.param_types.len == 1) {
19
19
  return Hash.init(@intCast(seed));
20
20
  } else {
21
21
  return Hash.init();
@@ -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".fields.len]bool = b: {
827
- var result: [@typeInfo(http.ContentEncoding).@"enum".fields.len]bool = @splat(false);
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;
@@ -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 (!enum_info.is_exhaustive) {
405
- inline for (enum_info.fields) |field| {
406
- if (v == @field(T, field.name)) {
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.fields) |u_field| {
428
- if (v == @field(UnionTagType, u_field.name)) {
429
- try self.objectField(u_field.name);
430
- if (u_field.type == void) {
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, u_field.name));
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.fields) |Field| {
458
+ inline for (S.field_names, S.field_types) |field_name, field_type| {
459
459
  // don't include void fields
460
- if (Field.type == void) continue;
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(Field.type) == .optional) {
465
+ if (@typeInfo(field_type) == .optional) {
466
466
  if (self.options.emit_null_optional_fields == false) {
467
- if (@field(v, Field.name) == null) {
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(Field.name);
475
+ try self.objectField(field_name);
476
476
  }
477
- try self.write(@field(v, Field.name));
477
+ try self.write(@field(v, field_name));
478
478
  }
479
479
  }
480
480
  if (S.is_tuple) {
@@ -286,20 +286,20 @@ pub fn innerParse(
286
286
  },
287
287
  };
288
288
 
289
- inline for (unionInfo.fields) |u_field| {
290
- if (std.mem.eql(u8, u_field.name, field_name)) {
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 (u_field.type == void) {
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, u_field.name, {});
299
+ result = @unionInit(T, u_field_name, {});
300
300
  } else {
301
301
  // Recurse.
302
- result = @unionInit(T, u_field.name, try innerParse(u_field.type, allocator, source, options));
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..structInfo.fields.len) |i| {
322
- r[i] = try innerParse(structInfo.fields[i].type, allocator, source, options);
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.fields.len]bool = @splat(false);
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 (structInfo.fields, 0..) |field, i| {
352
- if (field.is_comptime) @compileError("comptime fields are not supported: " ++ @typeName(T) ++ "." ++ field.name);
353
- if (std.mem.eql(u8, field.name, field_name)) {
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(field.type, allocator, source, options);
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, field.name) = try innerParse(field.type, allocator, source, options);
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.is_const) {
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.fields) |u_field| {
617
- if (std.mem.eql(u8, u_field.name, field_name)) {
618
- if (u_field.type == void) {
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, u_field.name, {});
627
+ return @unionInit(T, u_field_name, {});
623
628
  }
624
629
  // Recurse.
625
- return @unionInit(T, u_field.name, try innerParseFromValue(u_field.type, allocator, kv.value_ptr.*, options));
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.fields.len) return error.UnexpectedToken;
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.fields.len, source.array.items) |i, item| {
639
- r[i] = try innerParseFromValue(structInfo.fields[i].type, allocator, item, options);
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.fields.len]bool = @splat(false);
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 (structInfo.fields, 0..) |field, i| {
659
- if (field.is_comptime) @compileError("comptime fields are not supported: " ++ @typeName(T) ++ "." ++ field.name);
660
- if (std.mem.eql(u8, field.name, field_name)) {
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, field.name) = try innerParseFromValue(field.type, allocator, kv.value_ptr.*, options);
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".fields.len]bool) !void {
786
- inline for (@typeInfo(T).@"struct".fields, 0..) |field, i| {
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 (field.defaultValue()) |default| {
789
- @field(r, field.name) = default;
804
+ if (field_attrs.defaultValue(field_type)) |default| {
805
+ @field(r, field_name) = default;
790
806
  } else {
791
807
  return error.MissingField;
792
808
  }
package/std/lang.zig CHANGED
@@ -596,13 +596,8 @@ pub const Type = union(enum) {
596
596
  /// therefore must be kept in sync with the compiler implementation.
597
597
  pub const Pointer = struct {
598
598
  size: Size,
599
- is_const: bool,
600
- is_volatile: bool,
601
- /// `null` means implicit alignment, which is equivalent to `@alignOf(child)`.
602
- alignment: ?usize,
603
- address_space: AddressSpace,
599
+ attrs: Attributes,
604
600
  child: type,
605
- is_allowzero: bool,
606
601
 
607
602
  /// The type of the sentinel is the element type of the pointer, which is
608
603
  /// the value of the `child` field in this struct. However there is no way
@@ -667,44 +662,40 @@ pub const Type = union(enum) {
667
662
 
668
663
  /// This data structure is used by the Zig language code generation and
669
664
  /// therefore must be kept in sync with the compiler implementation.
670
- pub const StructField = struct {
671
- name: [:0]const u8,
672
- type: type,
673
- /// The type of the default value is the type of this struct field, which
674
- /// is the value of the `type` field in this struct. However there is no
675
- /// way to refer to that type here, so we use `*const anyopaque`.
676
- /// See also: `defaultValue`.
677
- default_value_ptr: ?*const anyopaque,
678
- is_comptime: bool,
679
- /// `null` means the field alignment was not explicitly specified. The
680
- /// field will still be aligned to at least `@alignOf` its `type`.
681
- alignment: ?usize,
682
-
683
- /// Loads the field's default value from `default_value_ptr`.
684
- /// Returns `null` if the field has no default value.
685
- pub inline fn defaultValue(comptime sf: StructField) ?sf.type {
686
- const dp: *const sf.type = @ptrCast(@alignCast(sf.default_value_ptr orelse return null));
687
- return dp.*;
688
- }
665
+ pub const Struct = struct {
666
+ is_tuple: bool,
667
+ layout: ContainerLayout,
668
+ /// Always `null` if `layout != .@"packed"`.
669
+ backing_integer: ?type,
689
670
 
690
- /// This data structure is used by the Zig language code generation and
691
- /// therefore must be kept in sync with the compiler implementation.
692
- pub const Attributes = struct {
671
+ field_names: []const [:0]const u8,
672
+ /// Guaranteed to have the same length as `field_names`.
673
+ field_types: []const type,
674
+ /// Guaranteed to have the same length as `field_names`.
675
+ field_attrs: []const FieldAttributes,
676
+
677
+ decl_names: []const [:0]const u8,
678
+
679
+ pub const FieldAttributes = struct {
693
680
  @"comptime": bool = false,
681
+ /// `null` means the field alignment is not explicitly specified. The field will still
682
+ /// be aligned to at least `@alignOf` the field type.
694
683
  @"align": ?usize = null,
684
+ /// The type of the default value is the type of this struct field. However, that type
685
+ /// is not known here, so we use a type-erased pointer instead, which must be cast to
686
+ /// a pointer to the field type.
687
+ ///
688
+ /// See also: `defaultValue`.
695
689
  default_value_ptr: ?*const anyopaque = null,
696
- };
697
- };
698
690
 
699
- /// This data structure is used by the Zig language code generation and
700
- /// therefore must be kept in sync with the compiler implementation.
701
- pub const Struct = struct {
702
- layout: ContainerLayout,
703
- /// Only valid if layout is .@"packed"
704
- backing_integer: ?type = null,
705
- fields: []const StructField,
706
- decls: []const Declaration,
707
- is_tuple: bool,
691
+ /// Loads the field's default value from `default_value_ptr`.
692
+ /// `FieldType` must exactly match the corresponding element of `Struct.field_types`.
693
+ /// Returns `null` if the field has no default value.
694
+ pub inline fn defaultValue(comptime attrs: FieldAttributes, comptime FieldType: type) ?FieldType {
695
+ const dp: *const FieldType = @ptrCast(@alignCast(attrs.default_value_ptr orelse return null));
696
+ return dp.*;
697
+ }
698
+ };
708
699
  };
709
700
 
710
701
  /// This data structure is used by the Zig language code generation and
@@ -722,48 +713,25 @@ pub const Type = union(enum) {
722
713
 
723
714
  /// This data structure is used by the Zig language code generation and
724
715
  /// therefore must be kept in sync with the compiler implementation.
725
- pub const Error = struct {
726
- name: [:0]const u8,
727
- };
728
-
729
- /// This data structure is used by the Zig language code generation and
730
- /// therefore must be kept in sync with the compiler implementation.
731
- pub const ErrorSet = ?[]const Error;
732
-
733
- /// This data structure is used by the Zig language code generation and
734
- /// therefore must be kept in sync with the compiler implementation.
735
- pub const EnumField = struct {
736
- name: [:0]const u8,
737
- value: comptime_int,
716
+ pub const ErrorSet = struct {
717
+ error_names: ?[]const [:0]const u8,
738
718
  };
739
719
 
740
720
  /// This data structure is used by the Zig language code generation and
741
721
  /// therefore must be kept in sync with the compiler implementation.
742
722
  pub const Enum = struct {
743
723
  tag_type: type,
744
- fields: []const EnumField,
745
- decls: []const Declaration,
746
- is_exhaustive: bool,
724
+ mode: Mode,
747
725
 
748
- /// This data structure is used by the Zig language code generation and
749
- /// therefore must be kept in sync with the compiler implementation.
750
- pub const Mode = enum { exhaustive, nonexhaustive };
751
- };
726
+ field_names: []const [:0]const u8,
727
+ /// Guaranteed to have the same length as `field_names`.
728
+ field_values: []const comptime_int,
752
729
 
753
- /// This data structure is used by the Zig language code generation and
754
- /// therefore must be kept in sync with the compiler implementation.
755
- pub const UnionField = struct {
756
- name: [:0]const u8,
757
- type: type,
758
- /// `null` means the field alignment was not explicitly specified. The
759
- /// field will still be aligned to at least `@alignOf` its `type`.
760
- alignment: ?usize,
730
+ decl_names: []const [:0]const u8,
761
731
 
762
732
  /// This data structure is used by the Zig language code generation and
763
733
  /// therefore must be kept in sync with the compiler implementation.
764
- pub const Attributes = struct {
765
- @"align": ?usize = null,
766
- };
734
+ pub const Mode = enum { exhaustive, nonexhaustive };
767
735
  };
768
736
 
769
737
  /// This data structure is used by the Zig language code generation and
@@ -771,36 +739,42 @@ pub const Type = union(enum) {
771
739
  pub const Union = struct {
772
740
  layout: ContainerLayout,
773
741
  tag_type: ?type,
774
- fields: []const UnionField,
775
- decls: []const Declaration,
742
+ /// Always `null` if `layout != .@"packed"`.
743
+ backing_integer: ?type,
744
+
745
+ field_names: []const [:0]const u8,
746
+ /// Guaranteed to have the same length as `field_names`.
747
+ field_types: []const type,
748
+ /// Guaranteed to have the same length as `field_names`.
749
+ field_attrs: []const FieldAttributes,
750
+
751
+ decl_names: []const [:0]const u8,
752
+
753
+ pub const FieldAttributes = struct {
754
+ /// `null` means the field alignment is not explicitly specified. The field will still
755
+ /// be aligned to at least `@alignOf` the field type.
756
+ @"align": ?usize = null,
757
+ };
776
758
  };
777
759
 
778
760
  /// This data structure is used by the Zig language code generation and
779
761
  /// therefore must be kept in sync with the compiler implementation.
780
762
  pub const Fn = struct {
781
- calling_convention: CallingConvention,
763
+ attrs: Attributes,
782
764
  is_generic: bool,
783
- is_var_args: bool,
784
- /// TODO change the language spec to make this not optional.
765
+ /// `null` means the return type is generic, i.e. it depends on a function argument.
785
766
  return_type: ?type,
786
- params: []const Param,
787
767
 
788
- /// This data structure is used by the Zig language code generation and
789
- /// therefore must be kept in sync with the compiler implementation.
790
- pub const Param = struct {
791
- is_generic: bool,
792
- is_noalias: bool,
793
- type: ?type,
794
-
795
- /// This data structure is used by the Zig language code generation and
796
- /// therefore must be kept in sync with the compiler implementation.
797
- pub const Attributes = struct {
798
- @"noalias": bool = false,
799
- };
768
+ /// A `null` element represents either an `anytype` parameter, or a parameter with a generic
769
+ /// type, i.e. where the type depends on a previous function argument.
770
+ param_types: []const ?type,
771
+ /// Guaranteed to have the same length as `param_types`.
772
+ param_attrs: []const ParamAttributes,
773
+
774
+ pub const ParamAttributes = struct {
775
+ @"noalias": bool = false,
800
776
  };
801
777
 
802
- /// This data structure is used by the Zig language code generation and
803
- /// therefore must be kept in sync with the compiler implementation.
804
778
  pub const Attributes = struct {
805
779
  @"callconv": CallingConvention = .auto,
806
780
  varargs: bool = false,
@@ -810,7 +784,7 @@ pub const Type = union(enum) {
810
784
  /// This data structure is used by the Zig language code generation and
811
785
  /// therefore must be kept in sync with the compiler implementation.
812
786
  pub const Opaque = struct {
813
- decls: []const Declaration,
787
+ decl_names: []const [:0]const u8,
814
788
  };
815
789
 
816
790
  /// This data structure is used by the Zig language code generation and
@@ -831,12 +805,6 @@ pub const Type = union(enum) {
831
805
  len: comptime_int,
832
806
  child: type,
833
807
  };
834
-
835
- /// This data structure is used by the Zig language code generation and
836
- /// therefore must be kept in sync with the compiler implementation.
837
- pub const Declaration = struct {
838
- name: [:0]const u8,
839
- };
840
808
  };
841
809
 
842
810
  /// This data structure is used by the Zig language code generation and
package/std/math.zig CHANGED
@@ -1648,8 +1648,8 @@ pub const CompareOperator = enum {
1648
1648
  }
1649
1649
 
1650
1650
  test reverse {
1651
- inline for (@typeInfo(CompareOperator).@"enum".fields) |op_field| {
1652
- const op = @as(CompareOperator, @enumFromInt(op_field.value));
1651
+ inline for (@typeInfo(CompareOperator).@"enum".field_values) |op_field_value| {
1652
+ const op = @as(CompareOperator, @enumFromInt(op_field_value));
1653
1653
  try testing.expect(compare(2, op, 3) == compare(3, op.reverse(), 2));
1654
1654
  try testing.expect(compare(3, op, 3) == compare(3, op.reverse(), 3));
1655
1655
  try testing.expect(compare(4, op, 3) == compare(3, op.reverse(), 4));
@@ -183,7 +183,7 @@ pub fn destroy(self: Allocator, ptr: anytype) void {
183
183
  const non_const_ptr = @as([*]u8, @ptrCast(@constCast(ptr)));
184
184
  self.rawFree(
185
185
  non_const_ptr[0..@sizeOf(T)],
186
- .fromByteUnits(info.alignment orelse @alignOf(T)),
186
+ .fromByteUnits(info.attrs.@"align" orelse @alignOf(T)),
187
187
  @returnAddress(),
188
188
  );
189
189
  }
@@ -331,7 +331,7 @@ pub fn resize(self: Allocator, allocation: anytype, new_len: usize) bool {
331
331
  const new_len_bytes = math.mul(usize, @sizeOf(T), new_len) catch return false;
332
332
  return self.rawResize(
333
333
  old_memory,
334
- .fromByteUnits(slice_info.alignment orelse @alignOf(T)),
334
+ .fromByteUnits(slice_info.attrs.@"align" orelse @alignOf(T)),
335
335
  new_len_bytes,
336
336
  @returnAddress(),
337
337
  );
@@ -377,7 +377,7 @@ pub fn remap(self: Allocator, allocation: anytype, new_len: usize) ?@TypeOf(allo
377
377
  const new_len_bytes = math.mul(usize, @sizeOf(T), new_len) catch return null;
378
378
  const new_ptr = self.rawRemap(
379
379
  old_memory,
380
- .fromByteUnits(slice_info.alignment orelse @alignOf(T)),
380
+ .fromByteUnits(slice_info.attrs.@"align" orelse @alignOf(T)),
381
381
  new_len_bytes,
382
382
  @returnAddress(),
383
383
  ) orelse return null;
@@ -412,11 +412,11 @@ pub fn reallocAdvanced(
412
412
  comptime assert(slice_info.size == .slice);
413
413
  const T = slice_info.child;
414
414
  if (old_mem.len == 0) {
415
- return self.allocAdvancedWithRetAddr(T, .fromByteUnitsOptional(slice_info.alignment), new_n, return_address);
415
+ return self.allocAdvancedWithRetAddr(T, .fromByteUnitsOptional(slice_info.attrs.@"align"), new_n, return_address);
416
416
  }
417
417
  if (new_n == 0) {
418
418
  self.free(old_mem);
419
- const alignment = slice_info.alignment orelse @alignOf(T);
419
+ const alignment = slice_info.attrs.@"align" orelse @alignOf(T);
420
420
  const addr = comptime std.mem.alignBackward(usize, math.maxInt(usize), alignment);
421
421
  const ptr: *align(alignment) [0]T = @ptrFromInt(addr);
422
422
  return ptr;
@@ -425,16 +425,16 @@ pub fn reallocAdvanced(
425
425
  const old_byte_slice: []u8 = @ptrCast(@constCast(mem.absorbSentinel(old_mem)));
426
426
  const byte_count = math.mul(usize, @sizeOf(T), new_n) catch return error.OutOfMemory;
427
427
  // Note: can't set shrunk memory to undefined as memory shouldn't be modified on realloc failure
428
- if (self.rawRemap(old_byte_slice, .fromByteUnits(slice_info.alignment orelse @alignOf(T)), byte_count, return_address)) |p| {
428
+ if (self.rawRemap(old_byte_slice, .fromByteUnits(slice_info.attrs.@"align" orelse @alignOf(T)), byte_count, return_address)) |p| {
429
429
  return @ptrCast(@alignCast(p[0..byte_count]));
430
430
  }
431
431
 
432
- const new_mem = self.rawAlloc(byte_count, .fromByteUnits(slice_info.alignment orelse @alignOf(T)), return_address) orelse
432
+ const new_mem = self.rawAlloc(byte_count, .fromByteUnits(slice_info.attrs.@"align" orelse @alignOf(T)), return_address) orelse
433
433
  return error.OutOfMemory;
434
434
  const copy_len = @min(byte_count, old_byte_slice.len);
435
435
  @memcpy(new_mem[0..copy_len], old_byte_slice[0..copy_len]);
436
436
  @memset(old_byte_slice, undefined);
437
- self.rawFree(old_byte_slice, .fromByteUnits(slice_info.alignment orelse @alignOf(T)), return_address);
437
+ self.rawFree(old_byte_slice, .fromByteUnits(slice_info.attrs.@"align" orelse @alignOf(T)), return_address);
438
438
 
439
439
  return @ptrCast(@alignCast(new_mem[0..byte_count]));
440
440
  }
@@ -448,7 +448,7 @@ pub fn free(self: Allocator, memory: anytype) void {
448
448
  const bytes: []u8 = @ptrCast(@constCast(mem.absorbSentinel(memory)));
449
449
  if (bytes.len == 0) return;
450
450
  @memset(bytes, undefined);
451
- self.rawFree(bytes, .fromByteUnits(slice_info.alignment orelse @alignOf(slice_info.child)), @returnAddress());
451
+ self.rawFree(bytes, .fromByteUnits(slice_info.attrs.@"align" orelse @alignOf(slice_info.child)), @returnAddress());
452
452
  }
453
453
 
454
454
  /// Copies `m` to newly allocated memory. Caller owns the memory.