@zigc/lib 0.17.0-dev.242 → 0.17.0-dev.256
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/std-docs.zig +1 -1
- package/compiler/translate-c/MacroTranslator.zig +1 -1
- package/docs/wasm/markdown/Parser.zig +11 -11
- package/package.json +1 -1
- package/std/array_list.zig +10 -31
- package/std/deque.zig +1 -1
- package/std/heap/memory_pool.zig +34 -197
- package/std/heap.zig +0 -7
- package/std/multi_array_list.zig +24 -0
- package/std/start.zig +13 -1
- package/std/std.zig +2 -1
- package/std/zig/Ast/Render.zig +2 -2
- package/std/zig/WindowsSdk.zig +4 -4
- package/std/zig/llvm/Builder.zig +6 -6
|
@@ -1397,7 +1397,7 @@ fn makeStep(
|
|
|
1397
1397
|
defer run.max_rss_mutex.unlock(io);
|
|
1398
1398
|
run.available_rss += s.max_rss;
|
|
1399
1399
|
dispatch_set.ensureUnusedCapacity(gpa, run.memory_blocked_steps.items.len) catch @panic("OOM");
|
|
1400
|
-
while (run.memory_blocked_steps.
|
|
1400
|
+
while (run.memory_blocked_steps.getLast()) |candidate| {
|
|
1401
1401
|
if (run.available_rss < candidate.max_rss) break;
|
|
1402
1402
|
assert(run.memory_blocked_steps.pop() == candidate);
|
|
1403
1403
|
dispatch_set.appendAssumeCapacity(candidate);
|
package/compiler/std-docs.zig
CHANGED
|
@@ -361,7 +361,7 @@ fn parseCNumLit(mt: *MacroTranslator) ParseError!ZigNode {
|
|
|
361
361
|
return error.ParseError;
|
|
362
362
|
},
|
|
363
363
|
});
|
|
364
|
-
if (bytes.getLast() == '.') {
|
|
364
|
+
if (bytes.getLast().? == '.') {
|
|
365
365
|
bytes.appendAssumeCapacity('0');
|
|
366
366
|
} else if (mem.findAny(u8, bytes.items, ".eEpP") == null) {
|
|
367
367
|
bytes.appendSliceAssumeCapacity(".0");
|
|
@@ -209,7 +209,7 @@ pub fn feedLine(p: *Parser, line: []const u8) Allocator.Error!void {
|
|
|
209
209
|
} else p.pending_blocks.items.len;
|
|
210
210
|
|
|
211
211
|
const in_code_block = p.pending_blocks.items.len > 0 and
|
|
212
|
-
p.pending_blocks.getLast()
|
|
212
|
+
p.pending_blocks.getLast().?.tag == .code_block;
|
|
213
213
|
const code_block_end = in_code_block and
|
|
214
214
|
first_unmatched + 1 == p.pending_blocks.items.len;
|
|
215
215
|
// New blocks cannot be started if we are actively inside a code block or
|
|
@@ -225,7 +225,7 @@ pub fn feedLine(p: *Parser, line: []const u8) Allocator.Error!void {
|
|
|
225
225
|
if (maybe_block_start == null and
|
|
226
226
|
!isBlank(rest_line) and
|
|
227
227
|
p.pending_blocks.items.len > 0 and
|
|
228
|
-
p.pending_blocks.getLast()
|
|
228
|
+
p.pending_blocks.getLast().?.tag == .paragraph)
|
|
229
229
|
{
|
|
230
230
|
try p.addScratchStringLine(mem.trimStart(u8, rest_line, " \t"));
|
|
231
231
|
return;
|
|
@@ -236,7 +236,7 @@ pub fn feedLine(p: *Parser, line: []const u8) Allocator.Error!void {
|
|
|
236
236
|
// paragraphs.
|
|
237
237
|
if (maybe_block_start != null and
|
|
238
238
|
p.pending_blocks.items.len > 0 and
|
|
239
|
-
p.pending_blocks.getLast()
|
|
239
|
+
p.pending_blocks.getLast().?.tag == .paragraph)
|
|
240
240
|
{
|
|
241
241
|
try p.closeLastBlock();
|
|
242
242
|
}
|
|
@@ -259,7 +259,7 @@ pub fn feedLine(p: *Parser, line: []const u8) Allocator.Error!void {
|
|
|
259
259
|
// Do not append the end of a code block (```) as textual content.
|
|
260
260
|
if (code_block_end) return;
|
|
261
261
|
|
|
262
|
-
const can_accept = if (p.pending_blocks.
|
|
262
|
+
const can_accept = if (p.pending_blocks.getLast()) |last_pending_block|
|
|
263
263
|
last_pending_block.canAccept()
|
|
264
264
|
else
|
|
265
265
|
.blocks;
|
|
@@ -273,7 +273,7 @@ pub fn feedLine(p: *Parser, line: []const u8) Allocator.Error!void {
|
|
|
273
273
|
// loose, since we might just be looking at a blank line after the
|
|
274
274
|
// end of the last item in the list. The final determination will be
|
|
275
275
|
// made when appending the next child of the list or list item.
|
|
276
|
-
const maybe_containing_list_index = if (p.pending_blocks.items.len > 0 and p.pending_blocks.getLast()
|
|
276
|
+
const maybe_containing_list_index = if (p.pending_blocks.items.len > 0 and p.pending_blocks.getLast().?.tag == .list_item)
|
|
277
277
|
p.pending_blocks.items.len - 2
|
|
278
278
|
else
|
|
279
279
|
null;
|
|
@@ -368,7 +368,7 @@ const BlockStart = struct {
|
|
|
368
368
|
};
|
|
369
369
|
|
|
370
370
|
fn appendBlockStart(p: *Parser, block_start: BlockStart) !void {
|
|
371
|
-
if (p.pending_blocks.
|
|
371
|
+
if (p.pending_blocks.getLast()) |last_pending_block| {
|
|
372
372
|
// Close the last block if it is a list and the new block is not a list item
|
|
373
373
|
// or not of the same marker type.
|
|
374
374
|
const should_close_list = last_pending_block.tag == .list and
|
|
@@ -383,7 +383,7 @@ fn appendBlockStart(p: *Parser, block_start: BlockStart) !void {
|
|
|
383
383
|
}
|
|
384
384
|
}
|
|
385
385
|
|
|
386
|
-
if (p.pending_blocks.
|
|
386
|
+
if (p.pending_blocks.getLast()) |last_pending_block| {
|
|
387
387
|
// If the last block is a list or list item, check for tightness based
|
|
388
388
|
// on the last line.
|
|
389
389
|
const maybe_containing_list = switch (last_pending_block.tag) {
|
|
@@ -401,7 +401,7 @@ fn appendBlockStart(p: *Parser, block_start: BlockStart) !void {
|
|
|
401
401
|
// Start a new list if the new block is a list item and there is no
|
|
402
402
|
// containing list yet.
|
|
403
403
|
if (block_start.tag == .list_item and
|
|
404
|
-
(p.pending_blocks.items.len == 0 or p.pending_blocks.getLast()
|
|
404
|
+
(p.pending_blocks.items.len == 0 or p.pending_blocks.getLast().?.tag != .list))
|
|
405
405
|
{
|
|
406
406
|
try p.pending_blocks.append(p.allocator, .{
|
|
407
407
|
.tag = .list,
|
|
@@ -417,7 +417,7 @@ fn appendBlockStart(p: *Parser, block_start: BlockStart) !void {
|
|
|
417
417
|
|
|
418
418
|
if (block_start.tag == .table_row) {
|
|
419
419
|
// Likewise, table rows start a table implicitly.
|
|
420
|
-
if (p.pending_blocks.items.len == 0 or p.pending_blocks.getLast()
|
|
420
|
+
if (p.pending_blocks.items.len == 0 or p.pending_blocks.getLast().?.tag != .table) {
|
|
421
421
|
try p.pending_blocks.append(p.allocator, .{
|
|
422
422
|
.tag = .table,
|
|
423
423
|
.data = .{ .table = .{
|
|
@@ -429,7 +429,7 @@ fn appendBlockStart(p: *Parser, block_start: BlockStart) !void {
|
|
|
429
429
|
});
|
|
430
430
|
}
|
|
431
431
|
|
|
432
|
-
const current_row = p.scratch_extra.items.len - p.pending_blocks.getLast()
|
|
432
|
+
const current_row = p.scratch_extra.items.len - p.pending_blocks.getLast().?.extra_start;
|
|
433
433
|
if (current_row <= 1) {
|
|
434
434
|
var buffer: [max_table_columns]Node.TableCellAlignment = undefined;
|
|
435
435
|
const table_row = &block_start.data.table_row;
|
|
@@ -441,7 +441,7 @@ fn appendBlockStart(p: *Parser, block_start: BlockStart) !void {
|
|
|
441
441
|
// We need to go back and mark the header row and its column
|
|
442
442
|
// alignments.
|
|
443
443
|
const datas = p.nodes.items(.data);
|
|
444
|
-
const header_data = datas[p.scratch_extra.getLast()];
|
|
444
|
+
const header_data = datas[p.scratch_extra.getLast().?];
|
|
445
445
|
for (p.extraChildren(header_data.container.children), 0..) |header_cell, i| {
|
|
446
446
|
const alignment = if (i < alignments.len) alignments[i] else .unset;
|
|
447
447
|
const cell_data = &datas[@intFromEnum(header_cell)].table_cell;
|
package/package.json
CHANGED
package/std/array_list.zig
CHANGED
|
@@ -544,16 +544,13 @@ pub fn AlignedManaged(comptime T: type, comptime alignment: ?mem.Alignment) type
|
|
|
544
544
|
return self.allocatedSlice()[self.items.len..];
|
|
545
545
|
}
|
|
546
546
|
|
|
547
|
-
///
|
|
548
|
-
|
|
549
|
-
pub fn getLast(self: Self) T {
|
|
550
|
-
return self.items[self.items.len - 1];
|
|
551
|
-
}
|
|
547
|
+
/// Deprecated in favor of `getLast`
|
|
548
|
+
pub const getLastOrNull = getLast;
|
|
552
549
|
|
|
553
|
-
/// Returns the last element from the list, or `null` if list is empty.
|
|
554
|
-
pub fn
|
|
550
|
+
/// Returns the last element from the list, or `null` if the list is empty.
|
|
551
|
+
pub fn getLast(self: Self) ?T {
|
|
555
552
|
if (self.items.len == 0) return null;
|
|
556
|
-
return self.
|
|
553
|
+
return self.items[self.items.len - 1];
|
|
557
554
|
}
|
|
558
555
|
};
|
|
559
556
|
}
|
|
@@ -1394,17 +1391,10 @@ pub fn Aligned(comptime T: type, comptime alignment: ?mem.Alignment) type {
|
|
|
1394
1391
|
return self.allocatedSlice()[self.items.len..];
|
|
1395
1392
|
}
|
|
1396
1393
|
|
|
1397
|
-
///
|
|
1398
|
-
|
|
1399
|
-
pub fn getLast(self: Self) T {
|
|
1400
|
-
return self.items[self.items.len - 1];
|
|
1401
|
-
}
|
|
1402
|
-
|
|
1403
|
-
/// Return the last element from the list, or
|
|
1404
|
-
/// return `null` if list is empty.
|
|
1405
|
-
pub fn getLastOrNull(self: Self) ?T {
|
|
1394
|
+
/// Returns the last element from the list, or `null` if the list is empty.
|
|
1395
|
+
pub fn getLast(self: Self) ?T {
|
|
1406
1396
|
if (self.items.len == 0) return null;
|
|
1407
|
-
return self.
|
|
1397
|
+
return self.items[self.items.len - 1];
|
|
1408
1398
|
}
|
|
1409
1399
|
|
|
1410
1400
|
/// Called when memory growth is necessary. Returns a capacity larger than
|
|
@@ -2394,22 +2384,11 @@ test "Managed(u32).getLast()" {
|
|
|
2394
2384
|
var list = Managed(u32).init(a);
|
|
2395
2385
|
defer list.deinit();
|
|
2396
2386
|
|
|
2397
|
-
try list.
|
|
2398
|
-
const const_list = list;
|
|
2399
|
-
try testing.expectEqual(const_list.getLast(), 2);
|
|
2400
|
-
}
|
|
2401
|
-
|
|
2402
|
-
test "Managed(u32).getLastOrNull()" {
|
|
2403
|
-
const a = testing.allocator;
|
|
2404
|
-
|
|
2405
|
-
var list = Managed(u32).init(a);
|
|
2406
|
-
defer list.deinit();
|
|
2407
|
-
|
|
2408
|
-
try testing.expectEqual(list.getLastOrNull(), null);
|
|
2387
|
+
try testing.expectEqual(list.getLast(), null);
|
|
2409
2388
|
|
|
2410
2389
|
try list.append(2);
|
|
2411
2390
|
const const_list = list;
|
|
2412
|
-
try testing.expectEqual(const_list.
|
|
2391
|
+
try testing.expectEqual(const_list.getLast().?, 2);
|
|
2413
2392
|
}
|
|
2414
2393
|
|
|
2415
2394
|
test "return OutOfMemory when capacity would exceed maximum usize integer value" {
|
package/std/deque.zig
CHANGED
|
@@ -696,7 +696,7 @@ fn fuzzAgainstArrayList(_: void, smith: *std.testing.Smith) anyerror!void {
|
|
|
696
696
|
try q.ensureTotalCapacityPrecise(q_gpa, q.len + growth);
|
|
697
697
|
},
|
|
698
698
|
}
|
|
699
|
-
try testing.expectEqual(l.
|
|
699
|
+
try testing.expectEqual(l.getLast(), q.back());
|
|
700
700
|
try testing.expectEqual(
|
|
701
701
|
if (l.items.len > 0) l.items[0] else null,
|
|
702
702
|
q.front(),
|
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/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/start.zig
CHANGED
|
@@ -23,6 +23,10 @@ comptime {
|
|
|
23
23
|
const dll_main_crt_startup = if (builtin.abi.isGnu()) "DllMainCRTStartup" else "_DllMainCRTStartup";
|
|
24
24
|
if (native_os == .windows and !builtin.link_libc and !@hasDecl(root, dll_main_crt_startup)) {
|
|
25
25
|
@export(&DllMainCRTStartup, .{ .name = dll_main_crt_startup });
|
|
26
|
+
} else if (native_os == .windows and builtin.link_libc and @hasDecl(root, "DllMain")) {
|
|
27
|
+
if (!@typeInfo(@TypeOf(root.DllMain)).@"fn".calling_convention.eql(.winapi)) {
|
|
28
|
+
@export(&DllMain, .{ .name = "DllMain" });
|
|
29
|
+
}
|
|
26
30
|
}
|
|
27
31
|
} else if (builtin.output_mode == .Exe or @hasDecl(root, "main")) {
|
|
28
32
|
if (builtin.link_libc and @hasDecl(root, "main")) {
|
|
@@ -82,12 +86,20 @@ fn DllMainCRTStartup(
|
|
|
82
86
|
}
|
|
83
87
|
|
|
84
88
|
if (@hasDecl(root, "DllMain")) {
|
|
85
|
-
return root.DllMain(hinstDLL, fdwReason, lpReserved);
|
|
89
|
+
return root.DllMain(@ptrCast(hinstDLL), fdwReason, lpReserved);
|
|
86
90
|
}
|
|
87
91
|
|
|
88
92
|
return .TRUE;
|
|
89
93
|
}
|
|
90
94
|
|
|
95
|
+
fn DllMain(
|
|
96
|
+
hinstDLL: std.os.windows.HINSTANCE,
|
|
97
|
+
fdwReason: std.os.windows.DWORD,
|
|
98
|
+
lpReserved: std.os.windows.LPVOID,
|
|
99
|
+
) callconv(.winapi) std.os.windows.BOOL {
|
|
100
|
+
return root.DllMain(@ptrCast(hinstDLL), fdwReason, lpReserved);
|
|
101
|
+
}
|
|
102
|
+
|
|
91
103
|
fn wasm_freestanding_start() callconv(.c) void {
|
|
92
104
|
// This is marked inline because for some reason LLVM in
|
|
93
105
|
// release mode fails to inline it, and we want fewer call frames in stack traces.
|
package/std/std.zig
CHANGED
|
@@ -65,7 +65,8 @@ pub const array_hash_map = @import("array_hash_map.zig");
|
|
|
65
65
|
pub const atomic = @import("atomic.zig");
|
|
66
66
|
pub const base64 = @import("base64.zig");
|
|
67
67
|
pub const bit_set = @import("bit_set.zig");
|
|
68
|
-
pub const builtin =
|
|
68
|
+
pub const builtin = lang;
|
|
69
|
+
pub const lang = @import("builtin.zig");
|
|
69
70
|
pub const c = @import("c.zig");
|
|
70
71
|
pub const coff = @import("coff.zig");
|
|
71
72
|
pub const compress = @import("compress.zig");
|
package/std/zig/Ast/Render.zig
CHANGED
|
@@ -3442,7 +3442,7 @@ const AutoIndentingStream = struct {
|
|
|
3442
3442
|
/// Sets current indentation level to be the same as that of the last pushSpace.
|
|
3443
3443
|
pub fn enableSpaceMode(ais: *AutoIndentingStream, space: Space) void {
|
|
3444
3444
|
if (ais.space_stack.items.len == 0) return;
|
|
3445
|
-
const curr = ais.space_stack.getLast()
|
|
3445
|
+
const curr = ais.space_stack.getLast().?;
|
|
3446
3446
|
if (curr.space != space) return;
|
|
3447
3447
|
ais.space_mode = curr.indent_count;
|
|
3448
3448
|
}
|
|
@@ -3453,7 +3453,7 @@ const AutoIndentingStream = struct {
|
|
|
3453
3453
|
|
|
3454
3454
|
pub fn lastSpaceModeIndent(ais: *AutoIndentingStream) usize {
|
|
3455
3455
|
if (ais.space_stack.items.len == 0) return 0;
|
|
3456
|
-
return ais.space_stack.getLast()
|
|
3456
|
+
return ais.space_stack.getLast().?.indent_count * ais.indent_delta;
|
|
3457
3457
|
}
|
|
3458
3458
|
|
|
3459
3459
|
/// Push default indentation
|
package/std/zig/WindowsSdk.zig
CHANGED
|
@@ -891,7 +891,7 @@ const MsvcLibDir = struct {
|
|
|
891
891
|
|
|
892
892
|
lib_dir_buf.appendSliceAssumeCapacity(installation_path);
|
|
893
893
|
|
|
894
|
-
if (!Dir.path.isSep(lib_dir_buf.getLast())) {
|
|
894
|
+
if (!Dir.path.isSep(lib_dir_buf.getLast().?)) {
|
|
895
895
|
try lib_dir_buf.append('\\');
|
|
896
896
|
}
|
|
897
897
|
const installation_path_with_trailing_sep_len = lib_dir_buf.items.len;
|
|
@@ -1064,7 +1064,7 @@ const MsvcLibDir = struct {
|
|
|
1064
1064
|
errdefer msvc_dir.deinit();
|
|
1065
1065
|
|
|
1066
1066
|
// String might contain trailing slash, so trim it here
|
|
1067
|
-
if (msvc_dir.items.len > "C:\\".len and msvc_dir.getLast() == '\\') _ = msvc_dir.pop();
|
|
1067
|
+
if (msvc_dir.items.len > "C:\\".len and msvc_dir.getLast().? == '\\') _ = msvc_dir.pop();
|
|
1068
1068
|
|
|
1069
1069
|
// Remove `\include` at the end of path
|
|
1070
1070
|
if (std.mem.endsWith(u8, msvc_dir.items, "\\include")) {
|
|
@@ -1108,7 +1108,7 @@ const MsvcLibDir = struct {
|
|
|
1108
1108
|
|
|
1109
1109
|
try list.appendSlice(VS140COMNTOOLS); // C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools
|
|
1110
1110
|
// String might contain trailing slash, so trim it here
|
|
1111
|
-
if (list.items.len > "C:\\".len and list.getLast() == '\\') _ = list.pop();
|
|
1111
|
+
if (list.items.len > "C:\\".len and list.getLast().? == '\\') _ = list.pop();
|
|
1112
1112
|
list.shrinkRetainingCapacity(list.items.len - "\\Common7\\Tools".len); // C:\Program Files (x86)\Microsoft Visual Studio 14.0
|
|
1113
1113
|
break :base_path list;
|
|
1114
1114
|
}
|
|
@@ -1131,7 +1131,7 @@ const MsvcLibDir = struct {
|
|
|
1131
1131
|
errdefer path.deinit();
|
|
1132
1132
|
|
|
1133
1133
|
// String might contain trailing slash, so trim it here
|
|
1134
|
-
if (path.items.len > "C:\\".len and path.getLast() == '\\') _ = path.pop();
|
|
1134
|
+
if (path.items.len > "C:\\".len and path.getLast().? == '\\') _ = path.pop();
|
|
1135
1135
|
break :base_path path;
|
|
1136
1136
|
}
|
|
1137
1137
|
return error.PathNotFound;
|
package/std/zig/llvm/Builder.zig
CHANGED
|
@@ -2310,7 +2310,7 @@ pub fn trailingStrtabString(self: *Builder) Allocator.Error!StrtabString {
|
|
|
2310
2310
|
}
|
|
2311
2311
|
|
|
2312
2312
|
pub fn trailingStrtabStringAssumeCapacity(self: *Builder) StrtabString {
|
|
2313
|
-
const start = self.strtab_string_indices.getLast()
|
|
2313
|
+
const start = self.strtab_string_indices.getLast().?;
|
|
2314
2314
|
const bytes: []const u8 = self.strtab_string_bytes.items[start..];
|
|
2315
2315
|
const gop = self.strtab_string_map.getOrPutAssumeCapacityAdapted(bytes, StrtabString.Adapter{ .builder = self });
|
|
2316
2316
|
if (gop.found_existing) {
|
|
@@ -8905,7 +8905,7 @@ pub fn deinit(self: *Builder) void {
|
|
|
8905
8905
|
|
|
8906
8906
|
pub fn finishModuleAsm(self: *Builder, aw: *Writer.Allocating) Allocator.Error!void {
|
|
8907
8907
|
self.module_asm = aw.toArrayList();
|
|
8908
|
-
if (self.module_asm.
|
|
8908
|
+
if (self.module_asm.getLast()) |last| if (last != '\n')
|
|
8909
8909
|
try self.module_asm.append(self.gpa, '\n');
|
|
8910
8910
|
}
|
|
8911
8911
|
|
|
@@ -8951,7 +8951,7 @@ pub fn trailingString(self: *Builder) Allocator.Error!String {
|
|
|
8951
8951
|
}
|
|
8952
8952
|
|
|
8953
8953
|
pub fn trailingStringAssumeCapacity(self: *Builder) String {
|
|
8954
|
-
const start = self.string_indices.getLast()
|
|
8954
|
+
const start = self.string_indices.getLast().?;
|
|
8955
8955
|
const bytes: []const u8 = self.string_bytes.items[start..];
|
|
8956
8956
|
const gop = self.string_map.getOrPutAssumeCapacityAdapted(bytes, String.Adapter{ .builder = self });
|
|
8957
8957
|
if (gop.found_existing) {
|
|
@@ -10022,9 +10022,9 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void
|
|
|
10022
10022
|
defer metadata_formatter.need_comma = undefined;
|
|
10023
10023
|
switch (extra.weights) {
|
|
10024
10024
|
.none => {},
|
|
10025
|
-
.unpredictable => try w.writeAll("!unpredictable !{}"),
|
|
10025
|
+
.unpredictable => try w.writeAll(", !unpredictable !{}"),
|
|
10026
10026
|
_ => try w.print("{f}", .{
|
|
10027
|
-
try metadata_formatter.fmt("!prof ", extra.weights.toMetadata(), null),
|
|
10027
|
+
try metadata_formatter.fmt(", !prof ", extra.weights.toMetadata(), null),
|
|
10028
10028
|
}),
|
|
10029
10029
|
}
|
|
10030
10030
|
},
|
|
@@ -12150,7 +12150,7 @@ pub fn trailingMetadataString(self: *Builder) Allocator.Error!Metadata.String {
|
|
|
12150
12150
|
}
|
|
12151
12151
|
|
|
12152
12152
|
pub fn trailingMetadataStringAssumeCapacity(self: *Builder) Metadata.String {
|
|
12153
|
-
const start = self.metadata_string_indices.getLast()
|
|
12153
|
+
const start = self.metadata_string_indices.getLast().?;
|
|
12154
12154
|
const bytes: []const u8 = self.metadata_string_bytes.items[start..];
|
|
12155
12155
|
assert(bytes.len > 0);
|
|
12156
12156
|
const gop = self.metadata_string_map.getOrPutAssumeCapacityAdapted(bytes, Metadata.String.Adapter{ .builder = self });
|