@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
package/std/mem.zig CHANGED
@@ -297,9 +297,13 @@ pub fn zeroes(comptime T: type) T {
297
297
  return item;
298
298
  } else {
299
299
  var structure: T = undefined;
300
- inline for (struct_info.fields) |field| {
301
- if (!field.is_comptime) {
302
- @field(structure, field.name) = zeroes(field.type);
300
+ inline for (
301
+ struct_info.field_names,
302
+ struct_info.field_types,
303
+ struct_info.field_attrs,
304
+ ) |field_name, field_type, field_attrs| {
305
+ if (!field_attrs.@"comptime") {
306
+ @field(structure, field_name) = zeroes(field_type);
303
307
  }
304
308
  }
305
309
  return structure;
@@ -321,7 +325,7 @@ pub fn zeroes(comptime T: type) T {
321
325
  return null;
322
326
  },
323
327
  .one, .many => {
324
- if (ptr_info.is_allowzero) return @ptrFromInt(0);
328
+ if (ptr_info.attrs.@"allowzero") return @ptrFromInt(0);
325
329
  @compileError("Only nullable and allowzero pointers can be set to zero.");
326
330
  },
327
331
  }
@@ -471,44 +475,49 @@ pub fn zeroInit(comptime T: type, init: anytype) T {
471
475
  switch (@typeInfo(Init)) {
472
476
  .@"struct" => |init_info| {
473
477
  if (init_info.is_tuple) {
474
- if (init_info.fields.len > struct_info.fields.len) {
478
+ if (init_info.field_names.len > struct_info.field_names.len) {
475
479
  @compileError("Tuple initializer has more elements than there are fields in `" ++ @typeName(T) ++ "`");
476
480
  }
477
481
  } else {
478
- inline for (init_info.fields) |field| {
479
- if (!@hasField(T, field.name)) {
480
- @compileError("Encountered an initializer for `" ++ field.name ++ "`, but it is not a field of " ++ @typeName(T));
482
+ inline for (init_info.field_names) |field_name| {
483
+ if (!@hasField(T, field_name)) {
484
+ @compileError("Encountered an initializer for `" ++ field_name ++ "`, but it is not a field of " ++ @typeName(T));
481
485
  }
482
486
  }
483
487
  }
484
488
 
485
489
  var value: T = if (struct_info.layout == .@"extern") zeroes(T) else undefined;
486
490
 
487
- inline for (struct_info.fields, 0..) |field, i| {
488
- if (field.is_comptime) {
491
+ inline for (
492
+ struct_info.field_names,
493
+ struct_info.field_types,
494
+ struct_info.field_attrs,
495
+ 0..,
496
+ ) |f_name, f_type, f_attr, i| {
497
+ if (f_attr.@"comptime") {
489
498
  continue;
490
499
  }
491
500
 
492
- if (init_info.is_tuple and init_info.fields.len > i) {
493
- @field(value, field.name) = @field(init, init_info.fields[i].name);
494
- } else if (@hasField(@TypeOf(init), field.name)) {
495
- switch (@typeInfo(field.type)) {
501
+ if (init_info.is_tuple and init_info.field_names.len > i) {
502
+ @field(value, f_name) = @field(init, init_info.field_names[i]);
503
+ } else if (@hasField(@TypeOf(init), f_name)) {
504
+ switch (@typeInfo(f_type)) {
496
505
  .@"struct" => {
497
- @field(value, field.name) = zeroInit(field.type, @field(init, field.name));
506
+ @field(value, f_name) = zeroInit(f_type, @field(init, f_name));
498
507
  },
499
508
  else => {
500
- @field(value, field.name) = @field(init, field.name);
509
+ @field(value, f_name) = @field(init, f_name);
501
510
  },
502
511
  }
503
- } else if (field.defaultValue()) |val| {
504
- @field(value, field.name) = val;
512
+ } else if (f_attr.defaultValue(f_type)) |val| {
513
+ @field(value, f_name) = val;
505
514
  } else {
506
- switch (@typeInfo(field.type)) {
515
+ switch (@typeInfo(f_type)) {
507
516
  .@"struct" => {
508
- @field(value, field.name) = std.mem.zeroInit(field.type, .{});
517
+ @field(value, f_name) = std.mem.zeroInit(f_type, .{});
509
518
  },
510
519
  else => {
511
- @field(value, field.name) = std.mem.zeroes(@TypeOf(@field(value, field.name)));
520
+ @field(value, f_name) = std.mem.zeroes(@TypeOf(@field(value, f_name)));
512
521
  },
513
522
  }
514
523
  }
@@ -867,13 +876,9 @@ fn Span(comptime T: type) type {
867
876
  .many => ptr_info.sentinel() orelse @compileError("invalid type given to std.mem.span: " ++ @typeName(T)),
868
877
  .c => 0,
869
878
  };
870
- return @Pointer(.slice, .{
871
- .@"const" = ptr_info.is_const,
872
- .@"volatile" = ptr_info.is_volatile,
873
- .@"allowzero" = ptr_info.is_allowzero and ptr_info.size != .c,
874
- .@"align" = ptr_info.alignment,
875
- .@"addrspace" = ptr_info.address_space,
876
- }, ptr_info.child, new_sentinel);
879
+ var attrs = ptr_info.attrs;
880
+ attrs.@"allowzero" = attrs.@"allowzero" and ptr_info.size != .c;
881
+ return @Pointer(.slice, attrs, ptr_info.child, new_sentinel);
877
882
  },
878
883
  else => {},
879
884
  }
@@ -933,13 +938,9 @@ fn SliceTo(comptime T: type, comptime end: std.meta.Elem(T)) type {
933
938
  .many => if (std.meta.sentinel(T)) |s| s == end else true,
934
939
  .c => true,
935
940
  };
936
- return @Pointer(.slice, .{
937
- .@"const" = ptr_info.is_const,
938
- .@"volatile" = ptr_info.is_volatile,
939
- .@"allowzero" = ptr_info.is_allowzero and ptr_info.size != .c,
940
- .@"align" = ptr_info.alignment,
941
- .@"addrspace" = ptr_info.address_space,
942
- }, Elem, if (have_sentinel) end else null);
941
+ var attrs = ptr_info.attrs;
942
+ attrs.@"allowzero" = attrs.@"allowzero" and ptr_info.size != .c;
943
+ return @Pointer(.slice, attrs, Elem, if (have_sentinel) end else null);
943
944
  },
944
945
  else => {},
945
946
  }
@@ -2210,19 +2211,19 @@ pub fn byteSwapAllFieldsAligned(comptime S: type, comptime a: Alignment, ptr: *a
2210
2211
  .@"struct" => |struct_info| {
2211
2212
  if (struct_info.backing_integer) |Int| {
2212
2213
  ptr.* = @bitCast(@byteSwap(@as(Int, @bitCast(ptr.*))));
2213
- } else inline for (std.meta.fields(S)) |f| {
2214
- switch (@typeInfo(f.type)) {
2215
- .@"struct" => byteSwapAllFieldsAligned(f.type, .fromByteUnits(f.alignment orelse @alignOf(f.type)), &@field(ptr, f.name)),
2216
- .@"union", .array => byteSwapAllFieldsAligned(f.type, .fromByteUnits(f.alignment orelse @alignOf(f.type)), &@field(ptr, f.name)),
2214
+ } else inline for (struct_info.field_types, struct_info.field_names, struct_info.field_attrs) |f_type, f_name, f_attr| {
2215
+ switch (@typeInfo(f_type)) {
2216
+ .@"struct" => byteSwapAllFieldsAligned(f_type, .fromByteUnits(f_attr.@"align" orelse @alignOf(f_type)), &@field(ptr, f_name)),
2217
+ .@"union", .array => byteSwapAllFieldsAligned(f_type, .fromByteUnits(f_attr.@"align" orelse @alignOf(f_type)), &@field(ptr, f_name)),
2217
2218
  .@"enum" => {
2218
- @field(ptr, f.name) = @enumFromInt(@byteSwap(@intFromEnum(@field(ptr, f.name))));
2219
+ @field(ptr, f_name) = @enumFromInt(@byteSwap(@intFromEnum(@field(ptr, f_name))));
2219
2220
  },
2220
2221
  .bool => {},
2221
2222
  .float => |float_info| {
2222
- @field(ptr, f.name) = @bitCast(@byteSwap(@as(@Int(.unsigned, float_info.bits), @bitCast(@field(ptr, f.name)))));
2223
+ @field(ptr, f_name) = @bitCast(@byteSwap(@as(@Int(.unsigned, float_info.bits), @bitCast(@field(ptr, f_name)))));
2223
2224
  },
2224
2225
  else => {
2225
- @field(ptr, f.name) = @byteSwap(@field(ptr, f.name));
2226
+ @field(ptr, f_name) = @byteSwap(@field(ptr, f_name));
2226
2227
  },
2227
2228
  }
2228
2229
  }
@@ -2232,9 +2233,9 @@ pub fn byteSwapAllFieldsAligned(comptime S: type, comptime a: Alignment, ptr: *a
2232
2233
  @compileError("byteSwapAllFields expects an untagged union");
2233
2234
  }
2234
2235
 
2235
- const first_size = @bitSizeOf(union_info.fields[0].type);
2236
- inline for (union_info.fields) |field| {
2237
- if (@bitSizeOf(field.type) != first_size) {
2236
+ const first_size = @bitSizeOf(union_info.field_types[0]);
2237
+ inline for (union_info.field_types) |field_type| {
2238
+ if (@bitSizeOf(field_type) != first_size) {
2238
2239
  @compileError("Unable to byte-swap unions with varying field sizes");
2239
2240
  }
2240
2241
  }
@@ -3940,15 +3941,8 @@ pub fn ReverseIterator(comptime T: type) type {
3940
3941
  .many, .c => @compileError("expected slice or pointer to array, found '" ++ @typeName(T) ++ "'"),
3941
3942
  }
3942
3943
  const Element = std.meta.Elem(T);
3943
- const attrs: std.builtin.Type.Pointer.Attributes = .{
3944
- .@"const" = ptr.is_const,
3945
- .@"volatile" = ptr.is_volatile,
3946
- .@"allowzero" = ptr.is_allowzero,
3947
- .@"align" = ptr.alignment,
3948
- .@"addrspace" = ptr.address_space,
3949
- };
3950
- const Pointer = @Pointer(.many, attrs, Element, std.meta.sentinel(T));
3951
- const ElementPointer = @Pointer(.one, attrs, Element, null);
3944
+ const Pointer = @Pointer(.many, ptr.attrs, Element, std.meta.sentinel(T));
3945
+ const ElementPointer = @Pointer(.one, ptr.attrs, Element, null);
3952
3946
  return struct {
3953
3947
  ptr: Pointer,
3954
3948
  index: usize,
@@ -4255,7 +4249,7 @@ pub fn alignPointerOffset(ptr: anytype, align_to: usize) ?usize {
4255
4249
  @compileError("expected many item pointer, got " ++ @typeName(T));
4256
4250
 
4257
4251
  // Do nothing if the pointer is already well-aligned.
4258
- if (align_to <= info.pointer.alignment orelse @alignOf(info.pointer.child))
4252
+ if (align_to <= info.pointer.attrs.@"align" orelse @alignOf(info.pointer.child))
4259
4253
  return 0;
4260
4254
 
4261
4255
  // Calculate the aligned base address with an eye out for overflow.
@@ -4309,17 +4303,14 @@ fn CopyPtrAttrs(
4309
4303
  comptime child: type,
4310
4304
  ) type {
4311
4305
  const ptr = @typeInfo(source).pointer;
4312
- return @Pointer(size, .{
4313
- .@"const" = ptr.is_const,
4314
- .@"volatile" = ptr.is_volatile,
4315
- .@"allowzero" = ptr.is_allowzero,
4316
- .@"align" = ptr.alignment orelse a: {
4317
- // If the new child is aligned differently than the old one, explicitly align the type.
4318
- const want = @alignOf(ptr.child);
4319
- break :a if (@alignOf(child) == want) null else want;
4320
- },
4321
- .@"addrspace" = ptr.address_space,
4322
- }, child, null);
4306
+ var attrs = ptr.attrs;
4307
+ if (attrs.@"align" == null) {
4308
+ const want = @alignOf(ptr.child);
4309
+ if (@alignOf(child) != want) {
4310
+ attrs.@"align" = want;
4311
+ }
4312
+ }
4313
+ return @Pointer(size, attrs, child, null);
4323
4314
  }
4324
4315
 
4325
4316
  fn AsBytesReturnType(comptime P: type) type {
@@ -4383,10 +4374,13 @@ test "asBytes preserves pointer attributes" {
4383
4374
  const in = @typeInfo(@TypeOf(inPtr)).pointer;
4384
4375
  const out = @typeInfo(@TypeOf(outSlice)).pointer;
4385
4376
 
4386
- try testing.expectEqual(in.is_const, out.is_const);
4387
- try testing.expectEqual(in.is_volatile, out.is_volatile);
4388
- try testing.expectEqual(in.is_allowzero, out.is_allowzero);
4389
- try testing.expectEqual(in.alignment, out.alignment);
4377
+ const in_attrs = in.attrs;
4378
+ const out_attrs = out.attrs;
4379
+
4380
+ try testing.expectEqual(in_attrs.@"const", out_attrs.@"const");
4381
+ try testing.expectEqual(in_attrs.@"volatile", out_attrs.@"volatile");
4382
+ try testing.expectEqual(in_attrs.@"allowzero", out_attrs.@"allowzero");
4383
+ try testing.expectEqual(in_attrs.@"align", out_attrs.@"align");
4390
4384
  }
4391
4385
 
4392
4386
  /// Given any value, returns a copy of its bytes in an array.
@@ -4463,13 +4457,13 @@ test "bytesAsValue preserves pointer attributes" {
4463
4457
  const inSlice = @as(*align(16) const volatile [4]u8, @ptrCast(&inArr))[0..];
4464
4458
  const outPtr = bytesAsValue(u32, inSlice);
4465
4459
 
4466
- const in = @typeInfo(@TypeOf(inSlice)).pointer;
4467
- const out = @typeInfo(@TypeOf(outPtr)).pointer;
4460
+ const in_attrs = @typeInfo(@TypeOf(inSlice)).pointer.attrs;
4461
+ const out_attrs = @typeInfo(@TypeOf(outPtr)).pointer.attrs;
4468
4462
 
4469
- try testing.expectEqual(in.is_const, out.is_const);
4470
- try testing.expectEqual(in.is_volatile, out.is_volatile);
4471
- try testing.expectEqual(in.is_allowzero, out.is_allowzero);
4472
- try testing.expectEqual(in.alignment, out.alignment);
4463
+ try testing.expectEqual(in_attrs.@"const", out_attrs.@"const");
4464
+ try testing.expectEqual(in_attrs.@"volatile", out_attrs.@"volatile");
4465
+ try testing.expectEqual(in_attrs.@"allowzero", out_attrs.@"allowzero");
4466
+ try testing.expectEqual(in_attrs.@"align", out_attrs.@"align");
4473
4467
  }
4474
4468
 
4475
4469
  /// Given a pointer to an array of bytes, returns a value of the specified type backed by a
@@ -4566,13 +4560,13 @@ test "bytesAsSlice preserves pointer attributes" {
4566
4560
  const inSlice = @as(*align(16) const volatile [4]u8, @ptrCast(&inArr))[0..];
4567
4561
  const outSlice = bytesAsSlice(u16, inSlice);
4568
4562
 
4569
- const in = @typeInfo(@TypeOf(inSlice)).pointer;
4570
- const out = @typeInfo(@TypeOf(outSlice)).pointer;
4563
+ const in_attrs = @typeInfo(@TypeOf(inSlice)).pointer.attrs;
4564
+ const out_attrs = @typeInfo(@TypeOf(outSlice)).pointer.attrs;
4571
4565
 
4572
- try testing.expectEqual(in.is_const, out.is_const);
4573
- try testing.expectEqual(in.is_volatile, out.is_volatile);
4574
- try testing.expectEqual(in.is_allowzero, out.is_allowzero);
4575
- try testing.expectEqual(in.alignment, out.alignment);
4566
+ try testing.expectEqual(in_attrs.@"const", out_attrs.@"const");
4567
+ try testing.expectEqual(in_attrs.@"volatile", out_attrs.@"volatile");
4568
+ try testing.expectEqual(in_attrs.@"allowzero", out_attrs.@"allowzero");
4569
+ try testing.expectEqual(in_attrs.@"align", out_attrs.@"align");
4576
4570
  }
4577
4571
 
4578
4572
  test "bytesAsSlice with zero-bit element type" {
@@ -4678,25 +4672,19 @@ test "sliceAsBytes preserves pointer attributes" {
4678
4672
  const inSlice = @as(*align(16) const volatile [2]u16, @ptrCast(&inArr))[0..];
4679
4673
  const outSlice = sliceAsBytes(inSlice);
4680
4674
 
4681
- const in = @typeInfo(@TypeOf(inSlice)).pointer;
4682
- const out = @typeInfo(@TypeOf(outSlice)).pointer;
4675
+ const in_attrs = @typeInfo(@TypeOf(inSlice)).pointer.attrs;
4676
+ const out_attrs = @typeInfo(@TypeOf(outSlice)).pointer.attrs;
4683
4677
 
4684
- try testing.expectEqual(in.is_const, out.is_const);
4685
- try testing.expectEqual(in.is_volatile, out.is_volatile);
4686
- try testing.expectEqual(in.is_allowzero, out.is_allowzero);
4687
- try testing.expectEqual(in.alignment, out.alignment);
4678
+ try testing.expectEqual(in_attrs.@"const", out_attrs.@"const");
4679
+ try testing.expectEqual(in_attrs.@"volatile", out_attrs.@"volatile");
4680
+ try testing.expectEqual(in_attrs.@"allowzero", out_attrs.@"allowzero");
4681
+ try testing.expectEqual(in_attrs.@"align", out_attrs.@"align");
4688
4682
  }
4689
4683
 
4690
4684
  fn AbsorbSentinelReturnType(comptime Slice: type) type {
4691
4685
  const info = @typeInfo(Slice).pointer;
4692
4686
  assert(info.size == .slice);
4693
- return @Pointer(.slice, .{
4694
- .@"const" = info.is_const,
4695
- .@"volatile" = info.is_volatile,
4696
- .@"allowzero" = info.is_allowzero,
4697
- .@"addrspace" = info.address_space,
4698
- .@"align" = info.alignment,
4699
- }, info.child, null);
4687
+ return @Pointer(.slice, info.attrs, info.child, null);
4700
4688
  }
4701
4689
 
4702
4690
  /// If the provided slice is not sentinel terminated, do nothing and return that slice.
@@ -4949,13 +4937,9 @@ test "freeing empty string with null-terminated sentinel" {
4949
4937
  /// all other pointer attributes copied from `AttributeSource`.
4950
4938
  fn AlignedSlice(comptime AttributeSource: type, comptime new_alignment: usize) type {
4951
4939
  const ptr = @typeInfo(AttributeSource).pointer;
4952
- return @Pointer(.slice, .{
4953
- .@"const" = ptr.is_const,
4954
- .@"volatile" = ptr.is_volatile,
4955
- .@"allowzero" = ptr.is_allowzero,
4956
- .@"align" = new_alignment,
4957
- .@"addrspace" = ptr.address_space,
4958
- }, ptr.child, null);
4940
+ var attrs = ptr.attrs;
4941
+ attrs.@"align" = new_alignment;
4942
+ return @Pointer(.slice, attrs, ptr.child, null);
4959
4943
  }
4960
4944
 
4961
4945
  /// Returns the largest slice in the given bytes that conforms to the new alignment,
@@ -14,7 +14,7 @@ pub fn TrailerFlags(comptime Fields: type) type {
14
14
  bits: Int,
15
15
 
16
16
  pub const Int = @Int(.unsigned, bit_count);
17
- pub const bit_count = @typeInfo(Fields).@"struct".fields.len;
17
+ pub const bit_count = @typeInfo(Fields).@"struct".field_names.len;
18
18
 
19
19
  pub const FieldEnum = std.meta.FieldEnum(Fields);
20
20
 
@@ -22,11 +22,18 @@ pub fn TrailerFlags(comptime Fields: type) type {
22
22
  pub const FieldValues = blk: {
23
23
  var field_names: [bit_count][]const u8 = undefined;
24
24
  var field_types: [bit_count]type = undefined;
25
- var field_attrs: [bit_count]std.builtin.Type.StructField.Attributes = undefined;
26
- for (@typeInfo(Fields).@"struct".fields, &field_names, &field_types, &field_attrs) |field, *new_name, *NewType, *new_attrs| {
27
- new_name.* = field.name;
28
- NewType.* = ?field.type;
29
- const default: ?field.type = null;
25
+ var field_attrs: [bit_count]std.builtin.Type.Struct.FieldAttributes = undefined;
26
+ const fields_info = @typeInfo(Fields).@"struct";
27
+ for (
28
+ fields_info.field_names,
29
+ fields_info.field_types,
30
+ &field_names,
31
+ &field_types,
32
+ &field_attrs,
33
+ ) |field_name, field_type, *new_name, *NewType, *new_attrs| {
34
+ new_name.* = field_name;
35
+ NewType.* = ?field_type;
36
+ const default: ?field_type = null;
30
37
  new_attrs.* = .{ .default_value_ptr = &default };
31
38
  }
32
39
  break :blk @Struct(.auto, null, &field_names, &field_types, &field_attrs);
@@ -53,8 +60,8 @@ pub fn TrailerFlags(comptime Fields: type) type {
53
60
  /// `fields` is a boolean struct where each active field is set to `true`
54
61
  pub fn init(fields: ActiveFields) Self {
55
62
  var self: Self = .{ .bits = 0 };
56
- inline for (@typeInfo(Fields).@"struct".fields, 0..) |field, i| {
57
- if (@field(fields, field.name))
63
+ inline for (@typeInfo(Fields).@"struct".field_names, 0..) |field_name, i| {
64
+ if (@field(fields, field_name))
58
65
  self.bits |= 1 << i;
59
66
  }
60
67
  return self;
@@ -62,8 +69,8 @@ pub fn TrailerFlags(comptime Fields: type) type {
62
69
 
63
70
  /// `fields` is a struct with each field set to an optional value
64
71
  pub fn setMany(self: Self, p: [*]align(@alignOf(Fields)) u8, fields: FieldValues) void {
65
- inline for (@typeInfo(Fields).@"struct".fields, 0..) |field, i| {
66
- if (@field(fields, field.name)) |value|
72
+ inline for (@typeInfo(Fields).@"struct".field_names, 0..) |field_name, i| {
73
+ if (@field(fields, field_name)) |value|
67
74
  self.set(p, @as(FieldEnum, @enumFromInt(i)), value);
68
75
  }
69
76
  }
@@ -93,30 +100,30 @@ pub fn TrailerFlags(comptime Fields: type) type {
93
100
 
94
101
  pub fn offset(self: Self, comptime field: FieldEnum) usize {
95
102
  var off: usize = 0;
96
- inline for (@typeInfo(Fields).@"struct".fields, 0..) |field_info, i| {
103
+ inline for (@typeInfo(Fields).@"struct".field_types, 0..) |field_type, i| {
97
104
  const active = (self.bits & (1 << i)) != 0;
98
105
  if (i == @intFromEnum(field)) {
99
106
  assert(active);
100
- return mem.alignForward(usize, off, @alignOf(field_info.type));
107
+ return mem.alignForward(usize, off, @alignOf(field_type));
101
108
  } else if (active) {
102
- off = mem.alignForward(usize, off, @alignOf(field_info.type));
103
- off += @sizeOf(field_info.type);
109
+ off = mem.alignForward(usize, off, @alignOf(field_type));
110
+ off += @sizeOf(field_type);
104
111
  }
105
112
  }
106
113
  }
107
114
 
108
115
  pub fn Field(comptime field: FieldEnum) type {
109
- return @typeInfo(Fields).@"struct".fields[@intFromEnum(field)].type;
116
+ return @typeInfo(Fields).@"struct".field_types[@intFromEnum(field)];
110
117
  }
111
118
 
112
119
  pub fn sizeInBytes(self: Self) usize {
113
120
  var off: usize = 0;
114
- inline for (@typeInfo(Fields).@"struct".fields, 0..) |field, i| {
115
- if (@sizeOf(field.type) == 0)
121
+ inline for (@typeInfo(Fields).@"struct".field_types, 0..) |field_type, i| {
122
+ if (@sizeOf(field_type) == 0)
116
123
  continue;
117
124
  if ((self.bits & (1 << i)) != 0) {
118
- off = mem.alignForward(usize, off, @alignOf(field.type));
119
- off += @sizeOf(field.type);
125
+ off = mem.alignForward(usize, off, @alignOf(field_type));
126
+ off += @sizeOf(field_type);
120
127
  }
121
128
  }
122
129
  return off;