@zigc/lib 0.17.0-dev.228 → 0.17.0-dev.248

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 (110) hide show
  1. package/compiler/build_runner.zig +1 -1
  2. package/compiler/reduce/Walk.zig +1 -6
  3. package/compiler/resinator/cvtres.zig +4 -4
  4. package/compiler/resinator/ico.zig +4 -4
  5. package/compiler/resinator/parse.zig +2 -2
  6. package/compiler/resinator/res.zig +1 -1
  7. package/compiler/std-docs.zig +1 -1
  8. package/compiler/translate-c/ast.zig +11 -21
  9. package/compiler_rt/atomics.zig +1 -1
  10. package/compiler_rt/ssp.zig +2 -2
  11. package/docs/wasm/Walk.zig +1 -3
  12. package/docs/wasm/html_render.zig +1 -2
  13. package/package.json +1 -1
  14. package/std/Io/Reader.zig +0 -5
  15. package/std/Io/Threaded.zig +4 -4
  16. package/std/Io/Writer.zig +1 -2
  17. package/std/Io/net/HostName.zig +11 -6
  18. package/std/Random/ChaCha.zig +2 -2
  19. package/std/Random/benchmark.zig +2 -2
  20. package/std/Thread.zig +2 -2
  21. package/std/base64.zig +5 -5
  22. package/std/bit_set.zig +7 -7
  23. package/std/c.zig +17 -17
  24. package/std/compress/flate/Decompress.zig +1 -1
  25. package/std/crypto/25519/curve25519.zig +2 -2
  26. package/std/crypto/25519/edwards25519.zig +3 -3
  27. package/std/crypto/25519/ristretto255.zig +2 -2
  28. package/std/crypto/25519/scalar.zig +6 -6
  29. package/std/crypto/25519/x25519.zig +1 -1
  30. package/std/crypto/Certificate.zig +1 -1
  31. package/std/crypto/Sha1.zig +1 -1
  32. package/std/crypto/aegis.zig +45 -39
  33. package/std/crypto/aes_ccm.zig +20 -20
  34. package/std/crypto/aes_gcm.zig +10 -12
  35. package/std/crypto/aes_ocb.zig +9 -9
  36. package/std/crypto/argon2.zig +15 -15
  37. package/std/crypto/bcrypt.zig +20 -10
  38. package/std/crypto/benchmark.zig +7 -7
  39. package/std/crypto/blake2.zig +100 -64
  40. package/std/crypto/cbc_mac.zig +1 -1
  41. package/std/crypto/chacha20.zig +10 -10
  42. package/std/crypto/cmac.zig +2 -2
  43. package/std/crypto/codecs/asn1.zig +1 -1
  44. package/std/crypto/ecdsa.zig +9 -9
  45. package/std/crypto/ff.zig +2 -2
  46. package/std/crypto/ghash_polyval.zig +4 -4
  47. package/std/crypto/hkdf.zig +1 -1
  48. package/std/crypto/isap.zig +3 -3
  49. package/std/crypto/kangarootwelve.zig +1 -1
  50. package/std/crypto/keccak_p.zig +7 -7
  51. package/std/crypto/md5.zig +1 -1
  52. package/std/crypto/ml_dsa.zig +33 -33
  53. package/std/crypto/ml_kem.zig +4 -4
  54. package/std/crypto/modes.zig +1 -1
  55. package/std/crypto/pbkdf2.zig +1 -1
  56. package/std/crypto/pcurves/p256/scalar.zig +3 -3
  57. package/std/crypto/pcurves/p384/scalar.zig +2 -2
  58. package/std/crypto/pcurves/secp256k1/scalar.zig +3 -3
  59. package/std/crypto/pcurves/tests/p256.zig +5 -5
  60. package/std/crypto/pcurves/tests/p384.zig +5 -5
  61. package/std/crypto/pcurves/tests/secp256k1.zig +3 -3
  62. package/std/crypto/salsa20.zig +8 -8
  63. package/std/crypto/sha2.zig +2 -2
  64. package/std/crypto/sha3.zig +2 -2
  65. package/std/crypto/siphash.zig +1 -1
  66. package/std/crypto/timing_safe.zig +5 -4
  67. package/std/crypto/tls/Client.zig +10 -9
  68. package/std/crypto.zig +3 -3
  69. package/std/debug/Dwarf.zig +1 -1
  70. package/std/debug.zig +6 -4
  71. package/std/elf.zig +1 -1
  72. package/std/enums.zig +1 -1
  73. package/std/fmt/parse_float/decimal.zig +1 -1
  74. package/std/fmt.zig +5 -1
  75. package/std/hash/Adler32.zig +3 -3
  76. package/std/hash/benchmark.zig +2 -2
  77. package/std/hash/wyhash.zig +1 -1
  78. package/std/heap/debug_allocator.zig +1 -1
  79. package/std/heap/memory_pool.zig +34 -197
  80. package/std/heap.zig +0 -7
  81. package/std/http.zig +1 -1
  82. package/std/json/static.zig +2 -2
  83. package/std/math/big/int.zig +3 -3
  84. package/std/math/nextafter.zig +1 -2
  85. package/std/math/powi.zig +2 -3
  86. package/std/math/signbit.zig +0 -1
  87. package/std/math.zig +12 -18
  88. package/std/mem.zig +9 -8
  89. package/std/meta.zig +1 -1
  90. package/std/multi_array_list.zig +24 -0
  91. package/std/os/emscripten.zig +2 -2
  92. package/std/os/linux.zig +4 -4
  93. package/std/os/uefi/hii.zig +1 -1
  94. package/std/tar/Writer.zig +39 -33
  95. package/std/tar.zig +8 -4
  96. package/std/unicode.zig +13 -8
  97. package/std/zig/Ast/Render.zig +1 -25
  98. package/std/zig/Ast.zig +5 -28
  99. package/std/zig/AstGen.zig +75 -184
  100. package/std/zig/AstRlAnnotate.zig +1 -11
  101. package/std/zig/AstSmith.zig +5 -11
  102. package/std/zig/LibCInstallation.zig +1 -1
  103. package/std/zig/Parse.zig +4 -69
  104. package/std/zig/TokenSmith.zig +0 -6
  105. package/std/zig/WindowsSdk.zig +1 -1
  106. package/std/zig/Zir.zig +0 -54
  107. package/std/zig/ZonGen.zig +0 -1
  108. package/std/zig/llvm/Builder.zig +5 -9
  109. package/std/zig/tokenizer.zig +4 -43
  110. package/std/zig.zig +0 -2
@@ -3,11 +3,6 @@ const Allocator = std.mem.Allocator;
3
3
  const Alignment = std.mem.Alignment;
4
4
  const MemoryPool = std.heap.MemoryPool;
5
5
 
6
- /// Deprecated.
7
- pub fn Managed(comptime Item: type) type {
8
- return ExtraManaged(Item, .{ .alignment = null });
9
- }
10
-
11
6
  /// A memory pool that can allocate objects of a single type very quickly.
12
7
  /// Use this when you need to allocate a lot of objects of the same type,
13
8
  /// because it outperforms general purpose allocators.
@@ -18,11 +13,6 @@ pub fn Aligned(comptime Item: type, comptime alignment: Alignment) type {
18
13
  return Extra(Item, .{ .alignment = alignment });
19
14
  }
20
15
 
21
- /// Deprecated.
22
- pub fn AlignedManaged(comptime Item: type, comptime alignment: Alignment) type {
23
- return ExtraManaged(Item, .{ .alignment = alignment });
24
- }
25
-
26
16
  pub const Options = struct {
27
17
  /// The alignment of the memory pool items. Use `null` for natural alignment.
28
18
  alignment: ?Alignment = null,
@@ -83,13 +73,6 @@ pub fn Extra(comptime Item: type, comptime pool_options: Options) type {
83
73
  pool.* = undefined;
84
74
  }
85
75
 
86
- pub fn toManaged(pool: Pool, allocator: Allocator) ExtraManaged(Item, pool_options) {
87
- return .{
88
- .allocator = allocator,
89
- .unmanaged = pool,
90
- };
91
- }
92
-
93
76
  /// Pre-allocates `num` items and adds them to the memory pool.
94
77
  /// This allows at least `num` active allocations before an
95
78
  /// `OutOfMemory` error might happen when calling `create()`.
@@ -114,7 +97,7 @@ pub fn Extra(comptime Item: type, comptime pool_options: Options) type {
114
97
  /// NOTE: If `mode` is `free_all`, the function will always return `true`.
115
98
  pub fn reset(pool: *Pool, allocator: Allocator, mode: ResetMode) bool {
116
99
  // TODO: Potentially store all allocated objects in a list as well, allowing to
117
- // just move them into the free list instead of actually releasing the memory.
100
+ // just move them into the free list instead of actually releasing the memory.
118
101
 
119
102
  var arena = pool.arena_state.promote(allocator);
120
103
  defer pool.arena_state = arena.state;
@@ -155,182 +138,56 @@ pub fn Extra(comptime Item: type, comptime pool_options: Options) type {
155
138
  };
156
139
  }
157
140
 
158
- /// Deprecated.
159
- pub fn ExtraManaged(comptime Item: type, comptime pool_options: Options) type {
160
- if (pool_options.alignment) |a| {
161
- if (a.compare(.eq, .of(Item))) {
162
- var new_options = pool_options;
163
- new_options.alignment = null;
164
- return ExtraManaged(Item, new_options);
165
- }
166
- }
167
- return struct {
168
- const Pool = @This();
169
-
170
- allocator: Allocator,
171
- unmanaged: Unmanaged,
172
-
173
- pub const Unmanaged = Extra(Item, pool_options);
174
- pub const item_size = Unmanaged.item_size;
175
- pub const item_alignment = Unmanaged.item_alignment;
176
-
177
- const ItemPtr = Unmanaged.ItemPtr;
178
-
179
- /// Creates a new memory pool.
180
- pub fn init(allocator: Allocator) Pool {
181
- return Unmanaged.empty.toManaged(allocator);
182
- }
183
-
184
- /// Creates a new memory pool and pre-allocates `num` items.
185
- /// This allows up to `num` active allocations before an
186
- /// `OutOfMemory` error might happen when calling `create()`.
187
- pub fn initCapacity(allocator: Allocator, num: usize) Allocator.Error!Pool {
188
- return (try Unmanaged.initCapacity(allocator, num)).toManaged(allocator);
189
- }
190
-
191
- /// Destroys the memory pool and frees all allocated memory.
192
- pub fn deinit(pool: *Pool) void {
193
- pool.unmanaged.deinit(pool.allocator);
194
- pool.* = undefined;
195
- }
196
-
197
- /// Pre-allocates `num` items and adds them to the memory pool.
198
- /// This allows at least `num` active allocations before an
199
- /// `OutOfMemory` error might happen when calling `create()`.
200
- pub fn addCapacity(pool: *Pool, num: usize) Allocator.Error!void {
201
- return pool.unmanaged.addCapacity(pool.allocator, num);
202
- }
203
-
204
- pub const ResetMode = Unmanaged.ResetMode;
205
-
206
- /// Resets the memory pool and destroys all allocated items.
207
- /// This can be used to batch-destroy all objects without invalidating the memory pool.
208
- ///
209
- /// The function will return whether the reset operation was successful or not.
210
- /// If the reallocation failed `false` is returned. The pool will still be fully
211
- /// functional in that case, all memory is released. Future allocations just might
212
- /// be slower.
213
- ///
214
- /// NOTE: If `mode` is `free_all`, the function will always return `true`.
215
- pub fn reset(pool: *Pool, mode: ResetMode) bool {
216
- return pool.unmanaged.reset(pool.allocator, mode);
217
- }
218
-
219
- /// Creates a new item and adds it to the memory pool.
220
- pub fn create(pool: *Pool) Allocator.Error!ItemPtr {
221
- return pool.unmanaged.create(pool.allocator);
222
- }
223
-
224
- /// Destroys a previously created item.
225
- /// Only pass items to `ptr` that were previously created with `create()` of the same memory pool!
226
- pub fn destroy(pool: *Pool, ptr: ItemPtr) void {
227
- return pool.unmanaged.destroy(ptr);
228
- }
229
-
230
- fn allocNew(pool: *Pool) Allocator.Error!*align(item_alignment) [item_size]u8 {
231
- return pool.unmanaged.allocNew(pool.allocator);
232
- }
233
- };
234
- }
235
-
236
141
  test "basic" {
237
142
  const a = std.testing.allocator;
238
143
 
239
- {
240
- var pool: MemoryPool(u32) = .empty;
241
- defer pool.deinit(a);
242
-
243
- const p1 = try pool.create(a);
244
- const p2 = try pool.create(a);
245
- const p3 = try pool.create(a);
246
-
247
- // Assert uniqueness
248
- try std.testing.expect(p1 != p2);
249
- try std.testing.expect(p1 != p3);
250
- try std.testing.expect(p2 != p3);
144
+ var pool: MemoryPool(u32) = .empty;
145
+ defer pool.deinit(a);
251
146
 
252
- pool.destroy(p2);
253
- const p4 = try pool.create(a);
254
-
255
- // Assert memory reuse
256
- try std.testing.expect(p2 == p4);
257
- }
147
+ const p1 = try pool.create(a);
148
+ const p2 = try pool.create(a);
149
+ const p3 = try pool.create(a);
258
150
 
259
- {
260
- var pool: Managed(u32) = .init(std.testing.allocator);
261
- defer pool.deinit();
151
+ // Assert uniqueness
152
+ try std.testing.expect(p1 != p2);
153
+ try std.testing.expect(p1 != p3);
154
+ try std.testing.expect(p2 != p3);
262
155
 
263
- const p1 = try pool.create();
264
- const p2 = try pool.create();
265
- const p3 = try pool.create();
156
+ pool.destroy(p2);
157
+ const p4 = try pool.create(a);
266
158
 
267
- // Assert uniqueness
268
- try std.testing.expect(p1 != p2);
269
- try std.testing.expect(p1 != p3);
270
- try std.testing.expect(p2 != p3);
271
-
272
- pool.destroy(p2);
273
- const p4 = try pool.create();
274
-
275
- // Assert memory reuse
276
- try std.testing.expect(p2 == p4);
277
- }
159
+ // Assert memory reuse
160
+ try std.testing.expect(p2 == p4);
278
161
  }
279
162
 
280
163
  test "initCapacity (success)" {
281
164
  const a = std.testing.allocator;
282
165
 
283
- {
284
- var pool: MemoryPool(u32) = try .initCapacity(a, 4);
285
- defer pool.deinit(a);
286
-
287
- _ = try pool.create(a);
288
- _ = try pool.create(a);
289
- _ = try pool.create(a);
290
- }
291
-
292
- {
293
- var pool: Managed(u32) = try .initCapacity(a, 4);
294
- defer pool.deinit();
166
+ var pool: MemoryPool(u32) = try .initCapacity(a, 4);
167
+ defer pool.deinit(a);
295
168
 
296
- _ = try pool.create();
297
- _ = try pool.create();
298
- _ = try pool.create();
299
- }
169
+ _ = try pool.create(a);
170
+ _ = try pool.create(a);
171
+ _ = try pool.create(a);
300
172
  }
301
173
 
302
174
  test "initCapacity (failure)" {
303
175
  const failer = std.testing.failing_allocator;
304
176
  try std.testing.expectError(error.OutOfMemory, MemoryPool(u32).initCapacity(failer, 5));
305
- try std.testing.expectError(error.OutOfMemory, Managed(u32).initCapacity(failer, 5));
306
177
  }
307
178
 
308
179
  test "growable" {
309
180
  const a = std.testing.allocator;
310
181
 
311
- {
312
- var pool: Extra(u32, .{ .growable = false }) = try .initCapacity(a, 4);
313
- defer pool.deinit(a);
314
-
315
- _ = try pool.create(a);
316
- _ = try pool.create(a);
317
- _ = try pool.create(a);
318
- _ = try pool.create(a);
319
-
320
- try std.testing.expectError(error.OutOfMemory, pool.create(a));
321
- }
322
-
323
- {
324
- var pool: ExtraManaged(u32, .{ .growable = false }) = try .initCapacity(a, 4);
325
- defer pool.deinit();
182
+ var pool: Extra(u32, .{ .growable = false }) = try .initCapacity(a, 4);
183
+ defer pool.deinit(a);
326
184
 
327
- _ = try pool.create();
328
- _ = try pool.create();
329
- _ = try pool.create();
330
- _ = try pool.create();
185
+ _ = try pool.create(a);
186
+ _ = try pool.create(a);
187
+ _ = try pool.create(a);
188
+ _ = try pool.create(a);
331
189
 
332
- try std.testing.expectError(error.OutOfMemory, pool.create());
333
- }
190
+ try std.testing.expectError(error.OutOfMemory, pool.create(a));
334
191
  }
335
192
 
336
193
  test "greater than pointer default alignment" {
@@ -339,21 +196,11 @@ test "greater than pointer default alignment" {
339
196
  };
340
197
  const a = std.testing.allocator;
341
198
 
342
- {
343
- var pool: MemoryPool(Foo) = .empty;
344
- defer pool.deinit(a);
345
-
346
- const foo: *Foo = try pool.create(a);
347
- pool.destroy(foo);
348
- }
349
-
350
- {
351
- var pool: Managed(Foo) = .init(a);
352
- defer pool.deinit();
199
+ var pool: MemoryPool(Foo) = .empty;
200
+ defer pool.deinit(a);
353
201
 
354
- const foo: *Foo = try pool.create();
355
- pool.destroy(foo);
356
- }
202
+ const foo: *Foo = try pool.create(a);
203
+ pool.destroy(foo);
357
204
  }
358
205
 
359
206
  test "greater than pointer manual alignment" {
@@ -362,19 +209,9 @@ test "greater than pointer manual alignment" {
362
209
  };
363
210
  const a = std.testing.allocator;
364
211
 
365
- {
366
- var pool: Aligned(Foo, .@"16") = .empty;
367
- defer pool.deinit(a);
368
-
369
- const foo: *align(16) Foo = try pool.create(a);
370
- pool.destroy(foo);
371
- }
212
+ var pool: Aligned(Foo, .@"16") = .empty;
213
+ defer pool.deinit(a);
372
214
 
373
- {
374
- var pool: AlignedManaged(Foo, .@"16") = .init(a);
375
- defer pool.deinit();
376
-
377
- const foo: *align(16) Foo = try pool.create();
378
- pool.destroy(foo);
379
- }
215
+ const foo: *align(16) Foo = try pool.create(a);
216
+ pool.destroy(foo);
380
217
  }
package/std/heap.zig CHANGED
@@ -30,13 +30,6 @@ pub fn MemoryPool(comptime Item: type) type {
30
30
  }
31
31
  pub const memory_pool = @import("heap/memory_pool.zig");
32
32
 
33
- /// Deprecated; use `memory_pool.Aligned`.
34
- pub const MemoryPoolAligned = memory_pool.Aligned;
35
- /// Deprecated; use `memory_pool.Extra`.
36
- pub const MemoryPoolExtra = memory_pool.Extra;
37
- /// Deprecated; use `memory_pool.Options`.
38
- pub const MemoryPoolOptions = memory_pool.Options;
39
-
40
33
  /// comptime-known minimum page size of the target.
41
34
  ///
42
35
  /// All pointers from `mmap` or `NtAllocateVirtualMemory` are aligned to at least
package/std/http.zig CHANGED
@@ -749,7 +749,7 @@ pub const BodyWriter = struct {
749
749
  /// How many zeroes to reserve for hex-encoded chunk length.
750
750
  const chunk_len_digits = 8;
751
751
  const max_chunk_len: usize = std.math.pow(u64, 16, chunk_len_digits) - 1;
752
- const chunk_header_template = ("0" ** chunk_len_digits) ++ "\r\n";
752
+ const chunk_header_template = @as([chunk_len_digits]u8, @splat('0')) ++ "\r\n";
753
753
 
754
754
  comptime {
755
755
  assert(max_chunk_len == std.math.maxInt(u32));
@@ -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 = [_]bool{false} ** structInfo.fields.len;
337
+ var fields_seen: [structInfo.fields.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.?);
@@ -649,7 +649,7 @@ pub fn innerParseFromValue(
649
649
  if (source != .object) return error.UnexpectedToken;
650
650
 
651
651
  var r: T = undefined;
652
- var fields_seen = [_]bool{false} ** structInfo.fields.len;
652
+ var fields_seen: [structInfo.fields.len]bool = @splat(false);
653
653
 
654
654
  var it = source.object.iterator();
655
655
  while (it.next()) |kv| {
@@ -29,8 +29,8 @@ const Constants = struct {
29
29
  };
30
30
  const constants: Constants = blk: {
31
31
  @setEvalBranchQuota(2000);
32
- var digits_per_limb = [_]u8{0} ** 37;
33
- var bases = [_]Limb{0} ** 37;
32
+ var digits_per_limb: [37]u8 = @splat(0);
33
+ var bases: [37]Limb = @splat(0);
34
34
  for (2..37) |base| {
35
35
  digits_per_limb[base] = @intCast(math.log(Limb, base, math.maxInt(Limb)));
36
36
  bases[base] = std.math.pow(Limb, base, digits_per_limb[base]);
@@ -2391,7 +2391,7 @@ pub const Const = struct {
2391
2391
  var limbs: [calcToStringLimbsBufferLen(available_len, 10)]Limb = undefined;
2392
2392
 
2393
2393
  const biggest: Const = .{
2394
- .limbs = &([1]Limb{comptime math.maxInt(Limb)} ** available_len),
2394
+ .limbs = &@as([available_len]Limb, @splat(comptime math.maxInt(Limb))),
2395
2395
  .positive = false,
2396
2396
  };
2397
2397
  var buf: [biggest.sizeInBaseUpperBound(2)]u8 = undefined;
@@ -23,7 +23,7 @@ pub fn nextAfter(comptime T: type, x: T, y: T) T {
23
23
  fn nextAfterInt(comptime T: type, x: T, y: T) T {
24
24
  comptime assert(@typeInfo(T) == .int or @typeInfo(T) == .comptime_int);
25
25
  return if (@typeInfo(T) == .int and @bitSizeOf(T) < 2)
26
- // Special case for `i0`, `u0`, `i1`, and `u1`.
26
+ // Special case for `u0`, `i1`, and `u1`.
27
27
  y
28
28
  else if (y > x)
29
29
  x + 1
@@ -102,7 +102,6 @@ fn nextAfterFloat(comptime T: type, x: T, y: T) T {
102
102
  }
103
103
 
104
104
  test "int" {
105
- try expect(nextAfter(i0, 0, 0) == 0);
106
105
  try expect(nextAfter(u0, 0, 0) == 0);
107
106
  try expect(nextAfter(i1, 0, 0) == 0);
108
107
  try expect(nextAfter(i1, 0, -1) == -1);
package/std/math/powi.zig CHANGED
@@ -15,12 +15,12 @@ const testing = std.testing;
15
15
  /// - Underflow: Absolute value of result smaller than 1
16
16
  ///
17
17
  /// Edge case rules ordered by precedence:
18
- /// - powi(T, x, 0) = 1 unless T is i1, i0, u0
18
+ /// - powi(T, x, 0) = 1 unless T is i1, u0
19
19
  /// - powi(T, 0, x) = 0 when x > 0
20
20
  /// - powi(T, 0, x) = Overflow
21
21
  /// - powi(T, 1, y) = 1
22
22
  /// - powi(T, -1, y) = -1 for y an odd integer
23
- /// - powi(T, -1, y) = 1 unless T is i1, i0, u0
23
+ /// - powi(T, -1, y) = 1 unless T is i1, u0
24
24
  /// - powi(T, -1, y) = Overflow
25
25
  /// - powi(T, x, y) = Overflow when y >= @bitSizeOf(x)
26
26
  /// - powi(T, x, y) = Underflow when y < 0
@@ -189,7 +189,6 @@ test "powi.special" {
189
189
 
190
190
  test "powi.narrow" {
191
191
  try testing.expectError(error.Overflow, powi(u0, 0, 0));
192
- try testing.expectError(error.Overflow, powi(i0, 0, 0));
193
192
  try testing.expectError(error.Overflow, powi(i1, 0, 0));
194
193
  try testing.expectError(error.Overflow, powi(i1, -1, 0));
195
194
  try testing.expectError(error.Overflow, powi(i1, 0, -1));
@@ -13,7 +13,6 @@ pub fn signbit(x: anytype) bool {
13
13
  }
14
14
 
15
15
  test signbit {
16
- try testInts(i0);
17
16
  try testInts(u0);
18
17
  try testInts(i1);
19
18
  try testInts(u1);
package/std/math.zig CHANGED
@@ -1141,13 +1141,11 @@ test isPowerOfTwo {
1141
1141
  pub fn ByteAlignedInt(comptime T: type) type {
1142
1142
  const info = @typeInfo(T).int;
1143
1143
  const bits = (info.bits + 7) / 8 * 8;
1144
- const extended_type = std.meta.Int(info.signedness, bits);
1145
- return extended_type;
1144
+ return @Int(info.signedness, bits);
1146
1145
  }
1147
1146
 
1148
1147
  test ByteAlignedInt {
1149
1148
  try testing.expect(ByteAlignedInt(u0) == u0);
1150
- try testing.expect(ByteAlignedInt(i0) == i0);
1151
1149
  try testing.expect(ByteAlignedInt(u3) == u8);
1152
1150
  try testing.expect(ByteAlignedInt(u8) == u8);
1153
1151
  try testing.expect(ByteAlignedInt(i111) == i112);
@@ -1218,7 +1216,7 @@ pub fn ceilPowerOfTwoPromote(comptime T: type, value: T) std.meta.Int(@typeInfo(
1218
1216
  comptime assert(@typeInfo(T) == .int);
1219
1217
  comptime assert(@typeInfo(T).int.signedness == .unsigned);
1220
1218
  assert(value != 0);
1221
- const PromotedType = std.meta.Int(@typeInfo(T).int.signedness, @typeInfo(T).int.bits + 1);
1219
+ const PromotedType = @Int(@typeInfo(T).int.signedness, @typeInfo(T).int.bits + 1);
1222
1220
  const ShiftType = std.math.Log2Int(PromotedType);
1223
1221
  return @as(PromotedType, 1) << @as(ShiftType, @intCast(@typeInfo(T).int.bits - @clz(value - 1)));
1224
1222
  }
@@ -1230,7 +1228,7 @@ pub fn ceilPowerOfTwo(comptime T: type, value: T) (error{Overflow}!T) {
1230
1228
  comptime assert(@typeInfo(T) == .int);
1231
1229
  const info = @typeInfo(T).int;
1232
1230
  comptime assert(info.signedness == .unsigned);
1233
- const PromotedType = std.meta.Int(info.signedness, info.bits + 1);
1231
+ const PromotedType = @Int(info.signedness, info.bits + 1);
1234
1232
  const overflowBit = @as(PromotedType, 1) << info.bits;
1235
1233
  const x = ceilPowerOfTwoPromote(T, value);
1236
1234
  if (overflowBit & x != 0) {
@@ -1442,19 +1440,17 @@ test lerp {
1442
1440
 
1443
1441
  /// Returns the maximum value of integer type T.
1444
1442
  pub fn maxInt(comptime T: type) comptime_int {
1445
- const info = @typeInfo(T);
1446
- const bit_count = info.int.bits;
1447
- if (bit_count == 0) return 0;
1448
- return (1 << (bit_count - @intFromBool(info.int.signedness == .signed))) - 1;
1443
+ const info = @typeInfo(T).int;
1444
+ return (1 << (info.bits - @intFromBool(info.signedness == .signed))) - 1;
1449
1445
  }
1450
1446
 
1451
1447
  /// Returns the minimum value of integer type T.
1452
1448
  pub fn minInt(comptime T: type) comptime_int {
1453
- const info = @typeInfo(T);
1454
- const bit_count = info.int.bits;
1455
- if (info.int.signedness == .unsigned) return 0;
1456
- if (bit_count == 0) return 0;
1457
- return -(1 << (bit_count - 1));
1449
+ const info = @typeInfo(T).int;
1450
+ return switch (info.signedness) {
1451
+ .unsigned => 0,
1452
+ .signed => -(1 << (info.bits - 1)),
1453
+ };
1458
1454
  }
1459
1455
 
1460
1456
  test maxInt {
@@ -1466,7 +1462,6 @@ test maxInt {
1466
1462
  try testing.expect(maxInt(u64) == 18446744073709551615);
1467
1463
  try testing.expect(maxInt(u128) == 340282366920938463463374607431768211455);
1468
1464
 
1469
- try testing.expect(maxInt(i0) == 0);
1470
1465
  try testing.expect(maxInt(i1) == 0);
1471
1466
  try testing.expect(maxInt(i8) == 127);
1472
1467
  try testing.expect(maxInt(i16) == 32767);
@@ -1486,7 +1481,6 @@ test minInt {
1486
1481
  try testing.expect(minInt(u64) == 0);
1487
1482
  try testing.expect(minInt(u128) == 0);
1488
1483
 
1489
- try testing.expect(minInt(i0) == 0);
1490
1484
  try testing.expect(minInt(i1) == -1);
1491
1485
  try testing.expect(minInt(i8) == -128);
1492
1486
  try testing.expect(minInt(i16) == -32768);
@@ -1710,8 +1704,8 @@ pub inline fn boolMask(comptime MaskInt: type, value: bool) MaskInt {
1710
1704
  if (@typeInfo(MaskInt) != .int)
1711
1705
  @compileError("boolMask requires an integer mask type.");
1712
1706
 
1713
- if (MaskInt == u0 or MaskInt == i0)
1714
- @compileError("boolMask cannot convert to u0 or i0, they are too small.");
1707
+ if (MaskInt == u0)
1708
+ @compileError("boolMask cannot convert to u0, it is too small.");
1715
1709
 
1716
1710
  // The u1 and i1 cases tend to overflow,
1717
1711
  // so we special case them here.
package/std/mem.zig CHANGED
@@ -359,7 +359,10 @@ test zeroes {
359
359
  var a = zeroes(C_struct);
360
360
 
361
361
  // Extern structs should have padding zeroed out.
362
- try testing.expectEqualSlices(u8, &[_]u8{0} ** @sizeOf(@TypeOf(a)), asBytes(&a));
362
+ {
363
+ const num_bytes = @sizeOf(@TypeOf(a));
364
+ try testing.expectEqualSlices(u8, &@as([num_bytes]u8, @splat(0)), @ptrCast(&a));
365
+ }
363
366
 
364
367
  a.y += 10;
365
368
 
@@ -370,7 +373,6 @@ test zeroes {
370
373
  comptime comptime_field: u8 = 5,
371
374
 
372
375
  integral_types: struct {
373
- integer_0: i0,
374
376
  integer_8: i8,
375
377
  integer_16: i16,
376
378
  integer_32: i32,
@@ -405,7 +407,6 @@ test zeroes {
405
407
 
406
408
  const b = zeroes(ZigStruct);
407
409
  try testing.expectEqual(@as(u8, 5), b.comptime_field);
408
- try testing.expectEqual(@as(i8, 0), b.integral_types.integer_0);
409
410
  try testing.expectEqual(@as(i8, 0), b.integral_types.integer_8);
410
411
  try testing.expectEqual(@as(i16, 0), b.integral_types.integer_16);
411
412
  try testing.expectEqual(@as(i32, 0), b.integral_types.integer_32);
@@ -1589,7 +1590,7 @@ test find {
1589
1590
  test "find multibyte" {
1590
1591
  {
1591
1592
  // make haystack and needle long enough to trigger Boyer-Moore-Horspool algorithm
1592
- const haystack = [1]u16{0} ** 100 ++ [_]u16{ 0xbbaa, 0xccbb, 0xddcc, 0xeedd, 0xffee, 0x00ff };
1593
+ const haystack = @as([100]u16, @splat(0)) ++ [_]u16{ 0xbbaa, 0xccbb, 0xddcc, 0xeedd, 0xffee, 0x00ff };
1593
1594
  const needle = [_]u16{ 0xbbaa, 0xccbb, 0xddcc, 0xeedd, 0xffee };
1594
1595
  try testing.expectEqual(findPos(u16, &haystack, 0, &needle), 100);
1595
1596
 
@@ -1602,7 +1603,7 @@ test "find multibyte" {
1602
1603
 
1603
1604
  {
1604
1605
  // make haystack and needle long enough to trigger Boyer-Moore-Horspool algorithm
1605
- const haystack = [_]u16{ 0xbbaa, 0xccbb, 0xddcc, 0xeedd, 0xffee, 0x00ff } ++ [1]u16{0} ** 100;
1606
+ const haystack = [_]u16{ 0xbbaa, 0xccbb, 0xddcc, 0xeedd, 0xffee, 0x00ff } ++ @as([100]u16, @splat(0));
1606
1607
  const needle = [_]u16{ 0xbbaa, 0xccbb, 0xddcc, 0xeedd, 0xffee };
1607
1608
  try testing.expectEqual(lastIndexOf(u16, &haystack, &needle), 0);
1608
1609
 
@@ -4647,7 +4648,7 @@ test "sliceAsBytes with sentinel slice" {
4647
4648
  }
4648
4649
 
4649
4650
  test "sliceAsBytes with zero-bit element type" {
4650
- const lots_of_nothing = [1]void{{}} ** 10_000;
4651
+ const lots_of_nothing: [10_000]void = @splat({});
4651
4652
  const bytes = sliceAsBytes(&lots_of_nothing);
4652
4653
  try testing.expect(bytes.len == 0);
4653
4654
  }
@@ -4865,8 +4866,8 @@ test doNotOptimizeAway {
4865
4866
  doNotOptimizeAway(@as(u200, 0));
4866
4867
  doNotOptimizeAway(@as(f32, 0.0));
4867
4868
  doNotOptimizeAway(@as(f64, 0.0));
4868
- doNotOptimizeAway([_]u8{0} ** 4);
4869
- doNotOptimizeAway([_]u8{0} ** 100);
4869
+ doNotOptimizeAway(@as([4]u8, @splat(0)));
4870
+ doNotOptimizeAway(@as([100]u8, @splat(0)));
4870
4871
  doNotOptimizeAway(@as(std.builtin.Endian, .little));
4871
4872
  }
4872
4873
 
package/std/meta.zig CHANGED
@@ -1067,7 +1067,7 @@ test hasUniqueRepresentation {
1067
1067
 
1068
1068
  try testing.expect(!hasUniqueRepresentation(TestUnion4));
1069
1069
 
1070
- inline for ([_]type{ i0, u8, i16, u32, i64 }) |T| {
1070
+ inline for ([_]type{ u8, i16, u32, i64 }) |T| {
1071
1071
  try testing.expect(hasUniqueRepresentation(T));
1072
1072
  try testing.expect(hasUniqueRepresentation(enum(T) { _ }));
1073
1073
  }
@@ -133,6 +133,13 @@ pub fn MultiArrayList(comptime T: type) type {
133
133
  };
134
134
  }
135
135
 
136
+ pub fn swap(self: Slice, a: usize, b: usize) void {
137
+ inline for (@typeInfo(Field).@"enum".fields) |field| {
138
+ const its = self.items(@field(Field, field.name));
139
+ std.mem.swap(@FieldType(T, field.name), &its[a], &its[b]);
140
+ }
141
+ }
142
+
136
143
  pub fn toMultiArrayList(self: Slice) Self {
137
144
  if (self.ptrs.len == 0 or self.capacity == 0) {
138
145
  return .{};
@@ -267,6 +274,10 @@ pub fn MultiArrayList(comptime T: type) type {
267
274
  return self.slice().get(index);
268
275
  }
269
276
 
277
+ pub fn swap(self: Self, a: usize, b: usize) void {
278
+ return self.slice().swap(a, b);
279
+ }
280
+
270
281
  /// Extend the list by 1 element.
271
282
  ///
272
283
  /// Allocates more memory as necessary.
@@ -771,6 +782,19 @@ test "basic usage" {
771
782
  try testing.expectEqualSlices(u32, list.items(.a), &[_]u32{ 1, 2, 3 });
772
783
  try testing.expectEqualSlices(u8, list.items(.c), &[_]u8{ 'a', 'b', 'c' });
773
784
 
785
+ list.swap(0, 2);
786
+ try testing.expectEqualSlices(u32, list.items(.a), &[_]u32{ 3, 2, 1 });
787
+ try testing.expectEqualSlices(u8, list.items(.c), &[_]u8{ 'c', 'b', 'a' });
788
+ list.swap(2, 1);
789
+ try testing.expectEqualSlices(u32, list.items(.a), &[_]u32{ 3, 1, 2 });
790
+ try testing.expectEqualSlices(u8, list.items(.c), &[_]u8{ 'c', 'a', 'b' });
791
+ list.swap(2, 0);
792
+ try testing.expectEqualSlices(u32, list.items(.a), &[_]u32{ 2, 1, 3 });
793
+ try testing.expectEqualSlices(u8, list.items(.c), &[_]u8{ 'b', 'a', 'c' });
794
+ list.swap(0, 1);
795
+ try testing.expectEqualSlices(u32, list.items(.a), &[_]u32{ 1, 2, 3 });
796
+ try testing.expectEqualSlices(u8, list.items(.c), &[_]u8{ 'a', 'b', 'c' });
797
+
774
798
  try testing.expectEqual(@as(usize, 3), list.items(.b).len);
775
799
  try testing.expectEqualStrings("foobar", list.items(.b)[0]);
776
800
  try testing.expectEqualStrings("zigzag", list.items(.b)[1]);
@@ -373,7 +373,7 @@ pub const rusage = extern struct {
373
373
  nsignals: isize,
374
374
  nvcsw: isize,
375
375
  nivcsw: isize,
376
- __reserved: [16]isize = [1]isize{0} ** 16,
376
+ __reserved: [16]isize = @splat(0),
377
377
 
378
378
  pub const SELF = 0;
379
379
  pub const CHILDREN = -1;
@@ -481,7 +481,7 @@ pub const Sigaction = extern struct {
481
481
 
482
482
  pub const sigset_t = [1024 / 32]u32;
483
483
  pub fn sigemptyset() sigset_t {
484
- return [_]u32{0} ** @typeInfo(sigset_t).array.len;
484
+ return @splat(0);
485
485
  }
486
486
  pub const siginfo_t = extern struct {
487
487
  signo: i32,