@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.
- package/compiler/build_runner.zig +1 -1
- package/compiler/reduce/Walk.zig +1 -6
- package/compiler/resinator/cvtres.zig +4 -4
- package/compiler/resinator/ico.zig +4 -4
- package/compiler/resinator/parse.zig +2 -2
- package/compiler/resinator/res.zig +1 -1
- package/compiler/std-docs.zig +1 -1
- package/compiler/translate-c/ast.zig +11 -21
- package/compiler_rt/atomics.zig +1 -1
- package/compiler_rt/ssp.zig +2 -2
- package/docs/wasm/Walk.zig +1 -3
- package/docs/wasm/html_render.zig +1 -2
- package/package.json +1 -1
- package/std/Io/Reader.zig +0 -5
- package/std/Io/Threaded.zig +4 -4
- package/std/Io/Writer.zig +1 -2
- package/std/Io/net/HostName.zig +11 -6
- package/std/Random/ChaCha.zig +2 -2
- package/std/Random/benchmark.zig +2 -2
- package/std/Thread.zig +2 -2
- package/std/base64.zig +5 -5
- package/std/bit_set.zig +7 -7
- package/std/c.zig +17 -17
- package/std/compress/flate/Decompress.zig +1 -1
- package/std/crypto/25519/curve25519.zig +2 -2
- package/std/crypto/25519/edwards25519.zig +3 -3
- package/std/crypto/25519/ristretto255.zig +2 -2
- package/std/crypto/25519/scalar.zig +6 -6
- package/std/crypto/25519/x25519.zig +1 -1
- package/std/crypto/Certificate.zig +1 -1
- package/std/crypto/Sha1.zig +1 -1
- package/std/crypto/aegis.zig +45 -39
- package/std/crypto/aes_ccm.zig +20 -20
- package/std/crypto/aes_gcm.zig +10 -12
- package/std/crypto/aes_ocb.zig +9 -9
- package/std/crypto/argon2.zig +15 -15
- package/std/crypto/bcrypt.zig +20 -10
- package/std/crypto/benchmark.zig +7 -7
- package/std/crypto/blake2.zig +100 -64
- package/std/crypto/cbc_mac.zig +1 -1
- package/std/crypto/chacha20.zig +10 -10
- package/std/crypto/cmac.zig +2 -2
- package/std/crypto/codecs/asn1.zig +1 -1
- package/std/crypto/ecdsa.zig +9 -9
- package/std/crypto/ff.zig +2 -2
- package/std/crypto/ghash_polyval.zig +4 -4
- package/std/crypto/hkdf.zig +1 -1
- package/std/crypto/isap.zig +3 -3
- package/std/crypto/kangarootwelve.zig +1 -1
- package/std/crypto/keccak_p.zig +7 -7
- package/std/crypto/md5.zig +1 -1
- package/std/crypto/ml_dsa.zig +33 -33
- package/std/crypto/ml_kem.zig +4 -4
- package/std/crypto/modes.zig +1 -1
- package/std/crypto/pbkdf2.zig +1 -1
- package/std/crypto/pcurves/p256/scalar.zig +3 -3
- package/std/crypto/pcurves/p384/scalar.zig +2 -2
- package/std/crypto/pcurves/secp256k1/scalar.zig +3 -3
- package/std/crypto/pcurves/tests/p256.zig +5 -5
- package/std/crypto/pcurves/tests/p384.zig +5 -5
- package/std/crypto/pcurves/tests/secp256k1.zig +3 -3
- package/std/crypto/salsa20.zig +8 -8
- package/std/crypto/sha2.zig +2 -2
- package/std/crypto/sha3.zig +2 -2
- package/std/crypto/siphash.zig +1 -1
- package/std/crypto/timing_safe.zig +5 -4
- package/std/crypto/tls/Client.zig +10 -9
- package/std/crypto.zig +3 -3
- package/std/debug/Dwarf.zig +1 -1
- package/std/debug.zig +6 -4
- package/std/elf.zig +1 -1
- package/std/enums.zig +1 -1
- package/std/fmt/parse_float/decimal.zig +1 -1
- package/std/fmt.zig +5 -1
- package/std/hash/Adler32.zig +3 -3
- package/std/hash/benchmark.zig +2 -2
- package/std/hash/wyhash.zig +1 -1
- package/std/heap/debug_allocator.zig +1 -1
- package/std/heap/memory_pool.zig +34 -197
- package/std/heap.zig +0 -7
- package/std/http.zig +1 -1
- package/std/json/static.zig +2 -2
- package/std/math/big/int.zig +3 -3
- package/std/math/nextafter.zig +1 -2
- package/std/math/powi.zig +2 -3
- package/std/math/signbit.zig +0 -1
- package/std/math.zig +12 -18
- package/std/mem.zig +9 -8
- package/std/meta.zig +1 -1
- package/std/multi_array_list.zig +24 -0
- package/std/os/emscripten.zig +2 -2
- package/std/os/linux.zig +4 -4
- package/std/os/uefi/hii.zig +1 -1
- package/std/tar/Writer.zig +39 -33
- package/std/tar.zig +8 -4
- package/std/unicode.zig +13 -8
- package/std/zig/Ast/Render.zig +1 -25
- package/std/zig/Ast.zig +5 -28
- package/std/zig/AstGen.zig +75 -184
- package/std/zig/AstRlAnnotate.zig +1 -11
- package/std/zig/AstSmith.zig +5 -11
- package/std/zig/LibCInstallation.zig +1 -1
- package/std/zig/Parse.zig +4 -69
- package/std/zig/TokenSmith.zig +0 -6
- package/std/zig/WindowsSdk.zig +1 -1
- package/std/zig/Zir.zig +0 -54
- package/std/zig/ZonGen.zig +0 -1
- package/std/zig/llvm/Builder.zig +5 -9
- package/std/zig/tokenizer.zig +4 -43
- package/std/zig.zig +0 -2
package/std/heap/memory_pool.zig
CHANGED
|
@@ -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
|
-
//
|
|
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
|
-
|
|
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
|
-
|
|
253
|
-
|
|
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
|
-
|
|
261
|
-
|
|
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
|
-
|
|
264
|
-
|
|
265
|
-
const p3 = try pool.create();
|
|
156
|
+
pool.destroy(p2);
|
|
157
|
+
const p4 = try pool.create(a);
|
|
266
158
|
|
|
267
|
-
|
|
268
|
-
|
|
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
|
-
|
|
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
|
-
|
|
297
|
-
|
|
298
|
-
|
|
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
|
-
|
|
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
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
185
|
+
_ = try pool.create(a);
|
|
186
|
+
_ = try pool.create(a);
|
|
187
|
+
_ = try pool.create(a);
|
|
188
|
+
_ = try pool.create(a);
|
|
331
189
|
|
|
332
|
-
|
|
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
|
-
|
|
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
|
-
|
|
355
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 = (
|
|
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));
|
package/std/json/static.zig
CHANGED
|
@@ -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
|
|
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
|
|
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| {
|
package/std/math/big/int.zig
CHANGED
|
@@ -29,8 +29,8 @@ const Constants = struct {
|
|
|
29
29
|
};
|
|
30
30
|
const constants: Constants = blk: {
|
|
31
31
|
@setEvalBranchQuota(2000);
|
|
32
|
-
var digits_per_limb
|
|
33
|
-
var bases
|
|
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 =
|
|
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;
|
package/std/math/nextafter.zig
CHANGED
|
@@ -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 `
|
|
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,
|
|
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,
|
|
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));
|
package/std/math/signbit.zig
CHANGED
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
|
-
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
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
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
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
|
|
1714
|
-
@compileError("boolMask cannot convert to u0
|
|
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
|
-
|
|
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 = [
|
|
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 } ++ [
|
|
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
|
|
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([
|
|
4869
|
-
doNotOptimizeAway([
|
|
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{
|
|
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
|
}
|
package/std/multi_array_list.zig
CHANGED
|
@@ -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]);
|
package/std/os/emscripten.zig
CHANGED
|
@@ -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 =
|
|
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
|
|
484
|
+
return @splat(0);
|
|
485
485
|
}
|
|
486
486
|
pub const siginfo_t = extern struct {
|
|
487
487
|
signo: i32,
|