From fd758f18e21f0781e5fee8ea43c660b02df13982 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Tue, 2 Apr 2024 03:34:03 -0700 Subject: [PATCH 1/4] std.{ArrayList,ArrayHashMap,MultiArrayList}: popOrNull() -> pop() --- lib/compiler/aro/aro/Preprocessor.zig | 4 +- lib/compiler/aro/aro/pragmas/gcc.zig | 2 +- lib/compiler/aro/aro/pragmas/pack.zig | 2 +- lib/compiler/build_runner.zig | 2 +- lib/docs/wasm/markdown.zig | 2 +- lib/docs/wasm/markdown/Parser.zig | 2 +- lib/std/Build/Cache.zig | 10 +- lib/std/Build/Step/ConfigHeader.zig | 2 +- lib/std/Build/Step/Options.zig | 4 +- lib/std/array_hash_map.zig | 45 +------ lib/std/array_list.zig | 46 +++---- lib/std/bounded_array.zig | 23 ++-- lib/std/dwarf/call_frame.zig | 2 +- lib/std/dwarf/expressions.zig | 140 ++++++++++----------- lib/std/fs/Dir.zig | 4 +- lib/std/heap.zig | 2 +- lib/std/heap/general_purpose_allocator.zig | 6 +- lib/std/json/dynamic.zig | 6 +- lib/std/linked_list.zig | 2 +- lib/std/multi_array_list.zig | 25 ++-- lib/std/segmented_list.zig | 1 - lib/std/zig/AstGen.zig | 2 +- lib/std/zig/WindowsSdk.zig | 12 +- src/Compilation.zig | 2 +- src/InternPool.zig | 42 +++---- src/Module.zig | 10 +- src/Package/Fetch.zig | 2 +- src/Sema.zig | 4 +- src/arch/aarch64/CodeGen.zig | 18 +-- src/arch/arm/CodeGen.zig | 18 +-- src/arch/riscv64/CodeGen.zig | 2 +- src/arch/sparc64/CodeGen.zig | 10 +- src/arch/wasm/CodeGen.zig | 22 ++-- src/codegen/c.zig | 2 +- src/codegen/spirv.zig | 2 +- src/link/Coff.zig | 10 +- src/link/Coff/ImportTable.zig | 2 +- src/link/Dwarf.zig | 6 +- src/link/Elf.zig | 2 +- src/link/Elf/ZigObject.zig | 2 +- src/link/MachO/ZigObject.zig | 2 +- src/link/Plan9.zig | 6 +- src/link/Wasm/ZigObject.zig | 8 +- src/link/table_section.zig | 2 +- tools/process_headers.zig | 6 +- tools/update-linux-headers.zig | 6 +- 46 files changed, 236 insertions(+), 296 deletions(-) diff --git a/lib/compiler/aro/aro/Preprocessor.zig b/lib/compiler/aro/aro/Preprocessor.zig index dc7be1ffc5ea..9b39e34075ba 100644 --- a/lib/compiler/aro/aro/Preprocessor.zig +++ b/lib/compiler/aro/aro/Preprocessor.zig @@ -2407,7 +2407,7 @@ pub fn expandedSlice(pp: *const Preprocessor, tok: anytype) []const u8 { /// Concat two tokens and add the result to pp.generated fn pasteTokens(pp: *Preprocessor, lhs_toks: *ExpandBuf, rhs_toks: []const TokenWithExpansionLocs) Error!void { - const lhs = while (lhs_toks.popOrNull()) |lhs| { + const lhs = while (lhs_toks.pop()) |lhs| { if ((pp.comp.langopts.preserve_comments_in_macros and lhs.id == .comment) or (lhs.id != .macro_ws and lhs.id != .comment)) break lhs; @@ -2634,7 +2634,7 @@ fn defineFn(pp: *Preprocessor, tokenizer: *Tokenizer, macro_name: RawToken, l_pa tok = tokenizer.nextNoWS(); if (tok.id == .ellipsis) { try pp.err(tok, .gnu_va_macro); - gnu_var_args = params.pop(); + gnu_var_args = params.pop().?; const r_paren = tokenizer.nextNoWS(); if (r_paren.id != .r_paren) { try pp.err(r_paren, .missing_paren_param_list); diff --git a/lib/compiler/aro/aro/pragmas/gcc.zig b/lib/compiler/aro/aro/pragmas/gcc.zig index 91ab750b4c81..779bfc8181cb 100644 --- a/lib/compiler/aro/aro/pragmas/gcc.zig +++ b/lib/compiler/aro/aro/pragmas/gcc.zig @@ -103,7 +103,7 @@ fn diagnosticHandler(self: *GCC, pp: *Preprocessor, start_idx: TokenIndex) Pragm try pp.comp.diagnostics.set(str[2..], new_kind); }, .push => try self.options_stack.append(pp.comp.gpa, pp.comp.diagnostics.options), - .pop => pp.comp.diagnostics.options = self.options_stack.popOrNull() orelse self.original_options, + .pop => pp.comp.diagnostics.options = self.options_stack.pop() orelse self.original_options, } } diff --git a/lib/compiler/aro/aro/pragmas/pack.zig b/lib/compiler/aro/aro/pragmas/pack.zig index 81d1dbc59a1c..b674baa26bd6 100644 --- a/lib/compiler/aro/aro/pragmas/pack.zig +++ b/lib/compiler/aro/aro/pragmas/pack.zig @@ -149,7 +149,7 @@ fn pop(pack: *Pack, p: *Parser, maybe_label: ?[]const u8) void { } } } else { - const prev = pack.stack.popOrNull() orelse { + const prev = pack.stack.pop() orelse { p.pragma_pack = 2; return; }; diff --git a/lib/compiler/build_runner.zig b/lib/compiler/build_runner.zig index f19713776916..c275f4ea075b 100644 --- a/lib/compiler/build_runner.zig +++ b/lib/compiler/build_runner.zig @@ -1043,7 +1043,7 @@ fn printErrorMessages(b: *std.Build, failing_step: *Step, run: *const Run) !void // Now, `step_stack` has the subtree that we want to print, in reverse order. try ttyconf.setColor(stderr, .dim); var indent: usize = 0; - while (step_stack.popOrNull()) |s| : (indent += 1) { + while (step_stack.pop()) |s| : (indent += 1) { if (indent > 0) { try stderr.writer().writeByteNTimes(' ', (indent - 1) * 3); try printChildNodePrefix(stderr, ttyconf); diff --git a/lib/docs/wasm/markdown.zig b/lib/docs/wasm/markdown.zig index e0bf4bbaaca1..e74282fb2f84 100644 --- a/lib/docs/wasm/markdown.zig +++ b/lib/docs/wasm/markdown.zig @@ -149,7 +149,7 @@ fn mainImpl() !void { var line_buf = std.ArrayList(u8).init(gpa); defer line_buf.deinit(); while (stdin_buf.reader().streamUntilDelimiter(line_buf.writer(), '\n', null)) { - if (line_buf.getLastOrNull() == '\r') _ = line_buf.pop(); + if (line_buf.getLastOrNull() == '\r') _ = line_buf.pop().?; try parser.feedLine(line_buf.items); line_buf.clearRetainingCapacity(); } else |err| switch (err) { diff --git a/lib/docs/wasm/markdown/Parser.zig b/lib/docs/wasm/markdown/Parser.zig index 9b377dce3403..13987b65cb4d 100644 --- a/lib/docs/wasm/markdown/Parser.zig +++ b/lib/docs/wasm/markdown/Parser.zig @@ -816,7 +816,7 @@ fn isThematicBreak(line: []const u8) bool { } fn closeLastBlock(p: *Parser) !void { - const b = p.pending_blocks.pop(); + const b = p.pending_blocks.pop().?; const node = switch (b.tag) { .list => list: { assert(b.string_start == p.scratch_string.items.len); diff --git a/lib/std/Build/Cache.zig b/lib/std/Build/Cache.zig index 463fb911acea..5e7b03c96fdc 100644 --- a/lib/std/Build/Cache.zig +++ b/lib/std/Build/Cache.zig @@ -526,7 +526,7 @@ pub const Manifest = struct { break :f file; } const gop = try self.files.getOrPutAdapted(gpa, prefixed_path, FilesAdapter{}); - errdefer _ = self.files.pop(); + errdefer _ = self.files.pop().?; if (!gop.found_existing) { gop.key_ptr.* = .{ .prefixed_path = .{ @@ -634,7 +634,7 @@ pub const Manifest = struct { // Remove files not in the initial hash. while (self.files.count() != input_file_count) { - var file = self.files.pop(); + var file = self.files.pop().?; file.key.deinit(self.cache.gpa); } @@ -737,7 +737,7 @@ pub const Manifest = struct { errdefer gpa.free(prefixed_path.sub_path); const gop = try self.files.getOrPutAdapted(gpa, prefixed_path, FilesAdapter{}); - errdefer _ = self.files.pop(); + errdefer _ = self.files.pop().?; if (gop.found_existing) { gpa.free(prefixed_path.sub_path); @@ -773,7 +773,7 @@ pub const Manifest = struct { errdefer gpa.free(prefixed_path.sub_path); const gop = try self.files.getOrPutAdapted(gpa, prefixed_path, FilesAdapter{}); - errdefer _ = self.files.pop(); + errdefer _ = self.files.pop().?; if (gop.found_existing) { gpa.free(prefixed_path.sub_path); @@ -809,7 +809,7 @@ pub const Manifest = struct { errdefer gpa.free(prefixed_path.sub_path); const gop = try self.files.getOrPutAdapted(gpa, prefixed_path, FilesAdapter{}); - errdefer _ = self.files.pop(); + errdefer _ = self.files.pop().?; if (gop.found_existing) { gpa.free(prefixed_path.sub_path); diff --git a/lib/std/Build/Step/ConfigHeader.zig b/lib/std/Build/Step/ConfigHeader.zig index 46631cac24a4..619cd0a37a37 100644 --- a/lib/std/Build/Step/ConfigHeader.zig +++ b/lib/std/Build/Step/ConfigHeader.zig @@ -606,7 +606,7 @@ fn expand_variables_cmake( // no open bracket, preserve as a literal break :blk; } - const open_pos = var_stack.pop(); + const open_pos = var_stack.pop().?; if (source_offset == open_pos.source) { source_offset += open_var.len; } diff --git a/lib/std/Build/Step/Options.zig b/lib/std/Build/Step/Options.zig index 1d0e34a254b7..0d29c7a90cc6 100644 --- a/lib/std/Build/Step/Options.zig +++ b/lib/std/Build/Step/Options.zig @@ -203,8 +203,8 @@ fn printType(self: *Options, out: anytype, comptime T: type, value: T, indent: u if (value) |inner| { try printType(self, out, @TypeOf(inner), inner, indent + 4, null); // Pop the '\n' and ',' chars - _ = self.contents.pop(); - _ = self.contents.pop(); + _ = self.contents.pop().?; + _ = self.contents.pop().?; } else { try out.writeAll("null"); } diff --git a/lib/std/array_hash_map.zig b/lib/std/array_hash_map.zig index ba086f876446..4ee269c459aa 100644 --- a/lib/std/array_hash_map.zig +++ b/lib/std/array_hash_map.zig @@ -466,15 +466,10 @@ pub fn ArrayHashMap( return self.unmanaged.shrinkAndFreeContext(self.allocator, new_len, self.ctx); } - /// Removes the last inserted `Entry` in the hash map and returns it. - pub fn pop(self: *Self) KV { - return self.unmanaged.popContext(self.ctx); - } - /// Removes the last inserted `Entry` in the hash map and returns it if count is nonzero. /// Otherwise returns null. - pub fn popOrNull(self: *Self) ?KV { - return self.unmanaged.popOrNullContext(self.ctx); + pub fn pop(self: *Self) ?KV { + return self.unmanaged.popContext(self.ctx); } }; } @@ -1403,8 +1398,9 @@ pub fn ArrayHashMapUnmanaged( self.entries.shrinkAndFree(allocator, new_len); } - /// Removes the last inserted `Entry` in the hash map and returns it. - pub fn pop(self: *Self) KV { + /// Removes the last inserted `Entry` in the hash map and returns it if count is nonzero. + /// Otherwise returns null. + pub fn pop(self: *Self) ?KV { if (@sizeOf(ByIndexContext) != 0) @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call popContext instead."); return self.popContext(undefined); @@ -1423,17 +1419,6 @@ pub fn ArrayHashMapUnmanaged( }; } - /// Removes the last inserted `Entry` in the hash map and returns it if count is nonzero. - /// Otherwise returns null. - pub fn popOrNull(self: *Self) ?KV { - if (@sizeOf(ByIndexContext) != 0) - @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call popContext instead."); - return self.popOrNullContext(undefined); - } - pub fn popOrNullContext(self: *Self, ctx: Context) ?KV { - return if (self.entries.len == 0) null else self.popContext(ctx); - } - fn fetchRemoveByKey( self: *Self, key: anytype, @@ -2373,25 +2358,7 @@ test "pop" { try testing.expect((try map.fetchPut(i, i)) == null); } - while (i > 0) : (i -= 1) { - const pop = map.pop(); - try testing.expect(pop.key == i - 1 and pop.value == i - 1); - } -} - -test "popOrNull" { - var map = AutoArrayHashMap(i32, i32).init(std.testing.allocator); - defer map.deinit(); - - // Insert just enough entries so that the map expands. Afterwards, - // pop all entries out of the map. - - var i: i32 = 0; - while (i < 9) : (i += 1) { - try testing.expect((try map.fetchPut(i, i)) == null); - } - - while (map.popOrNull()) |pop| { + while (map.pop()) |pop| { try testing.expect(pop.key == i - 1 and pop.value == i - 1); i -= 1; } diff --git a/lib/std/array_list.zig b/lib/std/array_list.zig index ff2307e8124d..ed6185306817 100644 --- a/lib/std/array_list.zig +++ b/lib/std/array_list.zig @@ -291,10 +291,10 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type { /// Asserts that the list is not empty. /// Asserts that the index is in bounds. pub fn swapRemove(self: *Self, i: usize) T { - if (self.items.len - 1 == i) return self.pop(); + if (self.items.len - 1 == i) return self.pop().?; const old_item = self.items[i]; - self.items[i] = self.pop(); + self.items[i] = self.pop().?; return old_item; } @@ -538,21 +538,14 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type { return self.items[prev_len..][0..n]; } - /// Remove and return the last element from the list. - /// Invalidates element pointers to the removed element. - /// Asserts that the list is not empty. - pub fn pop(self: *Self) T { - const val = self.items[self.items.len - 1]; - self.items.len -= 1; - return val; - } - /// Remove and return the last element from the list, or /// return `null` if list is empty. /// Invalidates element pointers to the removed element, if any. - pub fn popOrNull(self: *Self) ?T { + pub fn pop(self: *Self) ?T { if (self.items.len == 0) return null; - return self.pop(); + const val = self.items[self.items.len - 1]; + self.items.len -= 1; + return val; } /// Returns a slice of all the items plus the extra capacity, whose memory @@ -875,10 +868,10 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ /// Asserts that the list is not empty. /// Asserts that the index is in bounds. pub fn swapRemove(self: *Self, i: usize) T { - if (self.items.len - 1 == i) return self.pop(); + if (self.items.len - 1 == i) return self.pop().?; const old_item = self.items[i]; - self.items[i] = self.pop(); + self.items[i] = self.pop().?; return old_item; } @@ -1167,22 +1160,15 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ } /// Remove and return the last element from the list. + /// If the list is empty, returns `null`. /// Invalidates pointers to last element. - /// Asserts that the list is not empty. - pub fn pop(self: *Self) T { + pub fn pop(self: *Self) ?T { + if (self.items.len == 0) return null; const val = self.items[self.items.len - 1]; self.items.len -= 1; return val; } - /// Remove and return the last element from the list. - /// If the list is empty, returns `null`. - /// Invalidates pointers to last element. - pub fn popOrNull(self: *Self) ?T { - if (self.items.len == 0) return null; - return self.pop(); - } - /// Returns a slice of all the items plus the extra capacity, whose memory /// contents are `undefined`. pub fn allocatedSlice(self: Self) Slice { @@ -2057,7 +2043,7 @@ test "ArrayList(u0)" { try testing.expectEqual(count, 3); } -test "ArrayList(?u32).popOrNull()" { +test "ArrayList(?u32).pop()" { const a = testing.allocator; var list = ArrayList(?u32).init(a); @@ -2068,10 +2054,10 @@ test "ArrayList(?u32).popOrNull()" { try list.append(2); try testing.expectEqual(list.items.len, 3); - try testing.expect(list.popOrNull().? == @as(u32, 2)); - try testing.expect(list.popOrNull().? == @as(u32, 1)); - try testing.expect(list.popOrNull().? == null); - try testing.expect(list.popOrNull() == null); + try testing.expect(list.pop().? == @as(u32, 2)); + try testing.expect(list.pop().? == @as(u32, 1)); + try testing.expect(list.pop().? == null); + try testing.expect(list.pop() == null); } test "ArrayList(u32).getLast()" { diff --git a/lib/std/bounded_array.zig b/lib/std/bounded_array.zig index d41857013c60..5171f0634423 100644 --- a/lib/std/bounded_array.zig +++ b/lib/std/bounded_array.zig @@ -123,20 +123,15 @@ pub fn BoundedArrayAligned( return self.slice()[prev_len..][0..n]; } - /// Remove and return the last element from the slice. - /// Asserts the slice has at least one item. - pub fn pop(self: *Self) T { + /// Remove and return the last element from the slice, or + /// return `null` if the slice is empty. + pub fn pop(self: *Self) ?T { + if (self.len == 0) return null; const item = self.get(self.len - 1); self.len -= 1; return item; } - /// Remove and return the last element from the slice, or - /// return `null` if the slice is empty. - pub fn popOrNull(self: *Self) ?T { - return if (self.len == 0) null else self.pop(); - } - /// Return a slice of only the extra capacity after items. /// This can be useful for writing directly into it. /// Note that such an operation must be followed up with a @@ -218,7 +213,7 @@ pub fn BoundedArrayAligned( /// This operation is O(N). pub fn orderedRemove(self: *Self, i: usize) T { const newlen = self.len - 1; - if (newlen == i) return self.pop(); + if (newlen == i) return self.pop().?; const old_item = self.get(i); for (self.slice()[i..newlen], 0..) |*b, j| b.* = self.get(i + 1 + j); self.set(newlen, undefined); @@ -230,7 +225,7 @@ pub fn BoundedArrayAligned( /// The empty slot is filled from the end of the slice. /// This operation is O(1). pub fn swapRemove(self: *Self, i: usize) T { - if (self.len - 1 == i) return self.pop(); + if (self.len - 1 == i) return self.pop().?; const old_item = self.get(i); self.set(i, self.pop()); return old_item; @@ -328,8 +323,8 @@ test BoundedArray { try testing.expectEqual(a.pop(), 0xff); try a.resize(1); - try testing.expectEqual(a.popOrNull(), 0); - try testing.expectEqual(a.popOrNull(), null); + try testing.expectEqual(a.pop(), 0); + try testing.expectEqual(a.pop(), null); var unused = a.unusedCapacitySlice(); @memset(unused[0..8], 2); unused[8] = 3; @@ -382,7 +377,7 @@ test BoundedArray { try testing.expectEqual(swapped, 0xdd); try testing.expectEqual(a.get(0), 0xee); - while (a.popOrNull()) |_| {} + while (a.pop()) |_| {} const w = a.writer(); const s = "hello, this is a test string"; try w.writeAll(s); diff --git a/lib/std/dwarf/call_frame.zig b/lib/std/dwarf/call_frame.zig index 3b9c940aed6e..53e4b1830a2f 100644 --- a/lib/std/dwarf/call_frame.zig +++ b/lib/std/dwarf/call_frame.zig @@ -603,7 +603,7 @@ pub const VirtualMachine = struct { self.current_row.copy_on_write = true; }, .restore_state => { - const restored_columns = self.stack.popOrNull() orelse return error.InvalidOperation; + const restored_columns = self.stack.pop() orelse return error.InvalidOperation; self.columns.shrinkRetainingCapacity(self.columns.items.len - self.current_row.columns.len); try self.columns.ensureUnusedCapacity(allocator, restored_columns.len); diff --git a/lib/std/dwarf/expressions.zig b/lib/std/dwarf/expressions.zig index 4582ec717e13..f6c19d2a5791 100644 --- a/lib/std/dwarf/expressions.zig +++ b/lib/std/dwarf/expressions.zig @@ -417,7 +417,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type { try self.stack.append(allocator, self.stack.items[self.stack.items.len - 1]); }, OP.drop => { - _ = self.stack.pop(); + _ = self.stack.pop().?; }, OP.pick, OP.over => { const stack_index = if (opcode == OP.over) 1 else operand.?.generic; @@ -449,7 +449,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type { OP.xderef_size, OP.xderef_type, => blk: { - _ = self.stack.pop(); + _ = self.stack.pop().?; if (self.stack.items.len == 0) return error.InvalidExpression; break :blk try self.stack.items[self.stack.items.len - 1].asIntegral(); }, @@ -526,14 +526,14 @@ pub fn StackMachine(comptime options: ExpressionOptions) type { }, OP.@"and" => { if (self.stack.items.len < 2) return error.InvalidExpression; - const a = try self.stack.pop().asIntegral(); + const a = try self.stack.pop().?.asIntegral(); self.stack.items[self.stack.items.len - 1] = .{ .generic = a & try self.stack.items[self.stack.items.len - 1].asIntegral(), }; }, OP.div => { if (self.stack.items.len < 2) return error.InvalidExpression; - const a: isize = @bitCast(try self.stack.pop().asIntegral()); + const a: isize = @bitCast(try self.stack.pop().?.asIntegral()); const b: isize = @bitCast(try self.stack.items[self.stack.items.len - 1].asIntegral()); self.stack.items[self.stack.items.len - 1] = .{ .generic = @bitCast(try std.math.divTrunc(isize, b, a)), @@ -541,14 +541,14 @@ pub fn StackMachine(comptime options: ExpressionOptions) type { }, OP.minus => { if (self.stack.items.len < 2) return error.InvalidExpression; - const b = try self.stack.pop().asIntegral(); + const b = try self.stack.pop().?.asIntegral(); self.stack.items[self.stack.items.len - 1] = .{ .generic = try std.math.sub(addr_type, try self.stack.items[self.stack.items.len - 1].asIntegral(), b), }; }, OP.mod => { if (self.stack.items.len < 2) return error.InvalidExpression; - const a: isize = @bitCast(try self.stack.pop().asIntegral()); + const a: isize = @bitCast(try self.stack.pop().?.asIntegral()); const b: isize = @bitCast(try self.stack.items[self.stack.items.len - 1].asIntegral()); self.stack.items[self.stack.items.len - 1] = .{ .generic = @bitCast(@mod(b, a)), @@ -556,7 +556,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type { }, OP.mul => { if (self.stack.items.len < 2) return error.InvalidExpression; - const a: isize = @bitCast(try self.stack.pop().asIntegral()); + const a: isize = @bitCast(try self.stack.pop().?.asIntegral()); const b: isize = @bitCast(try self.stack.items[self.stack.items.len - 1].asIntegral()); self.stack.items[self.stack.items.len - 1] = .{ .generic = @bitCast(@mulWithOverflow(a, b)[0]), @@ -580,14 +580,14 @@ pub fn StackMachine(comptime options: ExpressionOptions) type { }, OP.@"or" => { if (self.stack.items.len < 2) return error.InvalidExpression; - const a = try self.stack.pop().asIntegral(); + const a = try self.stack.pop().?.asIntegral(); self.stack.items[self.stack.items.len - 1] = .{ .generic = a | try self.stack.items[self.stack.items.len - 1].asIntegral(), }; }, OP.plus => { if (self.stack.items.len < 2) return error.InvalidExpression; - const b = try self.stack.pop().asIntegral(); + const b = try self.stack.pop().?.asIntegral(); self.stack.items[self.stack.items.len - 1] = .{ .generic = try std.math.add(addr_type, try self.stack.items[self.stack.items.len - 1].asIntegral(), b), }; @@ -601,7 +601,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type { }, OP.shl => { if (self.stack.items.len < 2) return error.InvalidExpression; - const a = try self.stack.pop().asIntegral(); + const a = try self.stack.pop().?.asIntegral(); const b = try self.stack.items[self.stack.items.len - 1].asIntegral(); self.stack.items[self.stack.items.len - 1] = .{ .generic = std.math.shl(usize, b, a), @@ -609,7 +609,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type { }, OP.shr => { if (self.stack.items.len < 2) return error.InvalidExpression; - const a = try self.stack.pop().asIntegral(); + const a = try self.stack.pop().?.asIntegral(); const b = try self.stack.items[self.stack.items.len - 1].asIntegral(); self.stack.items[self.stack.items.len - 1] = .{ .generic = std.math.shr(usize, b, a), @@ -617,7 +617,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type { }, OP.shra => { if (self.stack.items.len < 2) return error.InvalidExpression; - const a = try self.stack.pop().asIntegral(); + const a = try self.stack.pop().?.asIntegral(); const b: isize = @bitCast(try self.stack.items[self.stack.items.len - 1].asIntegral()); self.stack.items[self.stack.items.len - 1] = .{ .generic = @bitCast(std.math.shr(isize, b, a)), @@ -625,7 +625,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type { }, OP.xor => { if (self.stack.items.len < 2) return error.InvalidExpression; - const a = try self.stack.pop().asIntegral(); + const a = try self.stack.pop().?.asIntegral(); self.stack.items[self.stack.items.len - 1] = .{ .generic = a ^ try self.stack.items[self.stack.items.len - 1].asIntegral(), }; @@ -640,7 +640,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type { OP.ne, => { if (self.stack.items.len < 2) return error.InvalidExpression; - const a = self.stack.pop(); + const a = self.stack.pop().?; const b = self.stack.items[self.stack.items.len - 1]; if (a == .generic and b == .generic) { @@ -666,7 +666,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type { const branch_offset = operand.?.branch_offset; const condition = if (opcode == OP.bra) blk: { if (self.stack.items.len == 0) return error.InvalidExpression; - break :blk try self.stack.pop().asIntegral() != 0; + break :blk try self.stack.pop().?.asIntegral() != 0; } else true; if (condition) { @@ -1079,7 +1079,7 @@ test "DWARF expressions" { for (0..32) |i| { const expected = 31 - i; - try testing.expectEqual(expected, stack_machine.stack.popOrNull().?.generic); + try testing.expectEqual(expected, stack_machine.stack.pop().?.generic); } } @@ -1140,7 +1140,7 @@ test "DWARF expressions" { _ = try stack_machine.run(program.items, allocator, context, 0); - const const_type = stack_machine.stack.popOrNull().?.const_type; + const const_type = stack_machine.stack.pop().?.const_type; try testing.expectEqual(die_offset, const_type.type_offset); try testing.expectEqualSlices(u8, type_bytes, const_type.value_bytes); @@ -1161,7 +1161,7 @@ test "DWARF expressions" { }; inline for (expected) |e| { - try testing.expectEqual(@as(e[0], e[1]), @as(e[2], @bitCast(stack_machine.stack.popOrNull().?.generic))); + try testing.expectEqual(@as(e[0], e[1]), @as(e[2], @bitCast(stack_machine.stack.pop().?.generic))); } } @@ -1198,14 +1198,14 @@ test "DWARF expressions" { _ = try stack_machine.run(program.items, allocator, context, 0); - const regval_type = stack_machine.stack.popOrNull().?.regval_type; + const regval_type = stack_machine.stack.pop().?.regval_type; try testing.expectEqual(@as(usize, 400), regval_type.type_offset); try testing.expectEqual(@as(u8, @sizeOf(usize)), regval_type.type_size); try testing.expectEqual(@as(usize, 0xee), regval_type.value); - try testing.expectEqual(@as(usize, 303), stack_machine.stack.popOrNull().?.generic); - try testing.expectEqual(@as(usize, 202), stack_machine.stack.popOrNull().?.generic); - try testing.expectEqual(@as(usize, 101), stack_machine.stack.popOrNull().?.generic); + try testing.expectEqual(@as(usize, 303), stack_machine.stack.pop().?.generic); + try testing.expectEqual(@as(usize, 202), stack_machine.stack.pop().?.generic); + try testing.expectEqual(@as(usize, 101), stack_machine.stack.pop().?.generic); } else |err| { switch (err) { error.UnimplementedArch, @@ -1226,15 +1226,15 @@ test "DWARF expressions" { try b.writeConst(writer, u8, 1); try b.writeOpcode(writer, OP.dup); _ = try stack_machine.run(program.items, allocator, context, null); - try testing.expectEqual(@as(usize, 1), stack_machine.stack.popOrNull().?.generic); - try testing.expectEqual(@as(usize, 1), stack_machine.stack.popOrNull().?.generic); + try testing.expectEqual(@as(usize, 1), stack_machine.stack.pop().?.generic); + try testing.expectEqual(@as(usize, 1), stack_machine.stack.pop().?.generic); stack_machine.reset(); program.clearRetainingCapacity(); try b.writeConst(writer, u8, 1); try b.writeOpcode(writer, OP.drop); _ = try stack_machine.run(program.items, allocator, context, null); - try testing.expect(stack_machine.stack.popOrNull() == null); + try testing.expect(stack_machine.stack.pop() == null); stack_machine.reset(); program.clearRetainingCapacity(); @@ -1243,7 +1243,7 @@ test "DWARF expressions" { try b.writeConst(writer, u8, 6); try b.writePick(writer, 2); _ = try stack_machine.run(program.items, allocator, context, null); - try testing.expectEqual(@as(usize, 4), stack_machine.stack.popOrNull().?.generic); + try testing.expectEqual(@as(usize, 4), stack_machine.stack.pop().?.generic); stack_machine.reset(); program.clearRetainingCapacity(); @@ -1252,7 +1252,7 @@ test "DWARF expressions" { try b.writeConst(writer, u8, 6); try b.writeOpcode(writer, OP.over); _ = try stack_machine.run(program.items, allocator, context, null); - try testing.expectEqual(@as(usize, 5), stack_machine.stack.popOrNull().?.generic); + try testing.expectEqual(@as(usize, 5), stack_machine.stack.pop().?.generic); stack_machine.reset(); program.clearRetainingCapacity(); @@ -1260,8 +1260,8 @@ test "DWARF expressions" { try b.writeConst(writer, u8, 6); try b.writeOpcode(writer, OP.swap); _ = try stack_machine.run(program.items, allocator, context, null); - try testing.expectEqual(@as(usize, 5), stack_machine.stack.popOrNull().?.generic); - try testing.expectEqual(@as(usize, 6), stack_machine.stack.popOrNull().?.generic); + try testing.expectEqual(@as(usize, 5), stack_machine.stack.pop().?.generic); + try testing.expectEqual(@as(usize, 6), stack_machine.stack.pop().?.generic); stack_machine.reset(); program.clearRetainingCapacity(); @@ -1270,9 +1270,9 @@ test "DWARF expressions" { try b.writeConst(writer, u8, 6); try b.writeOpcode(writer, OP.rot); _ = try stack_machine.run(program.items, allocator, context, null); - try testing.expectEqual(@as(usize, 5), stack_machine.stack.popOrNull().?.generic); - try testing.expectEqual(@as(usize, 4), stack_machine.stack.popOrNull().?.generic); - try testing.expectEqual(@as(usize, 6), stack_machine.stack.popOrNull().?.generic); + try testing.expectEqual(@as(usize, 5), stack_machine.stack.pop().?.generic); + try testing.expectEqual(@as(usize, 4), stack_machine.stack.pop().?.generic); + try testing.expectEqual(@as(usize, 6), stack_machine.stack.pop().?.generic); const deref_target: usize = @truncate(0xffeeffee_ffeeffee); @@ -1281,7 +1281,7 @@ test "DWARF expressions" { try b.writeAddr(writer, @intFromPtr(&deref_target)); try b.writeOpcode(writer, OP.deref); _ = try stack_machine.run(program.items, allocator, context, null); - try testing.expectEqual(deref_target, stack_machine.stack.popOrNull().?.generic); + try testing.expectEqual(deref_target, stack_machine.stack.pop().?.generic); stack_machine.reset(); program.clearRetainingCapacity(); @@ -1289,14 +1289,14 @@ test "DWARF expressions" { try b.writeAddr(writer, @intFromPtr(&deref_target)); try b.writeOpcode(writer, OP.xderef); _ = try stack_machine.run(program.items, allocator, context, null); - try testing.expectEqual(deref_target, stack_machine.stack.popOrNull().?.generic); + try testing.expectEqual(deref_target, stack_machine.stack.pop().?.generic); stack_machine.reset(); program.clearRetainingCapacity(); try b.writeAddr(writer, @intFromPtr(&deref_target)); try b.writeDerefSize(writer, 1); _ = try stack_machine.run(program.items, allocator, context, null); - try testing.expectEqual(@as(usize, @as(*const u8, @ptrCast(&deref_target)).*), stack_machine.stack.popOrNull().?.generic); + try testing.expectEqual(@as(usize, @as(*const u8, @ptrCast(&deref_target)).*), stack_machine.stack.pop().?.generic); stack_machine.reset(); program.clearRetainingCapacity(); @@ -1304,7 +1304,7 @@ test "DWARF expressions" { try b.writeAddr(writer, @intFromPtr(&deref_target)); try b.writeXDerefSize(writer, 1); _ = try stack_machine.run(program.items, allocator, context, null); - try testing.expectEqual(@as(usize, @as(*const u8, @ptrCast(&deref_target)).*), stack_machine.stack.popOrNull().?.generic); + try testing.expectEqual(@as(usize, @as(*const u8, @ptrCast(&deref_target)).*), stack_machine.stack.pop().?.generic); const type_offset: usize = @truncate(0xaabbaabb_aabbaabb); @@ -1313,7 +1313,7 @@ test "DWARF expressions" { try b.writeAddr(writer, @intFromPtr(&deref_target)); try b.writeDerefType(writer, 1, type_offset); _ = try stack_machine.run(program.items, allocator, context, null); - const deref_type = stack_machine.stack.popOrNull().?.regval_type; + const deref_type = stack_machine.stack.pop().?.regval_type; try testing.expectEqual(type_offset, deref_type.type_offset); try testing.expectEqual(@as(u8, 1), deref_type.type_size); try testing.expectEqual(@as(usize, @as(*const u8, @ptrCast(&deref_target)).*), deref_type.value); @@ -1324,7 +1324,7 @@ test "DWARF expressions" { try b.writeAddr(writer, @intFromPtr(&deref_target)); try b.writeXDerefType(writer, 1, type_offset); _ = try stack_machine.run(program.items, allocator, context, null); - const xderef_type = stack_machine.stack.popOrNull().?.regval_type; + const xderef_type = stack_machine.stack.pop().?.regval_type; try testing.expectEqual(type_offset, xderef_type.type_offset); try testing.expectEqual(@as(u8, 1), xderef_type.type_size); try testing.expectEqual(@as(usize, @as(*const u8, @ptrCast(&deref_target)).*), xderef_type.value); @@ -1335,7 +1335,7 @@ test "DWARF expressions" { program.clearRetainingCapacity(); try b.writeOpcode(writer, OP.push_object_address); _ = try stack_machine.run(program.items, allocator, context, null); - try testing.expectEqual(@as(usize, @intFromPtr(context.object_address.?)), stack_machine.stack.popOrNull().?.generic); + try testing.expectEqual(@as(usize, @intFromPtr(context.object_address.?)), stack_machine.stack.pop().?.generic); // TODO: Test OP.form_tls_address @@ -1345,7 +1345,7 @@ test "DWARF expressions" { program.clearRetainingCapacity(); try b.writeOpcode(writer, OP.call_frame_cfa); _ = try stack_machine.run(program.items, allocator, context, null); - try testing.expectEqual(context.cfa.?, stack_machine.stack.popOrNull().?.generic); + try testing.expectEqual(context.cfa.?, stack_machine.stack.pop().?.generic); } // Arithmetic and Logical Operations @@ -1357,7 +1357,7 @@ test "DWARF expressions" { try b.writeConst(writer, i16, -4096); try b.writeOpcode(writer, OP.abs); _ = try stack_machine.run(program.items, allocator, context, null); - try testing.expectEqual(@as(usize, 4096), stack_machine.stack.popOrNull().?.generic); + try testing.expectEqual(@as(usize, 4096), stack_machine.stack.pop().?.generic); stack_machine.reset(); program.clearRetainingCapacity(); @@ -1365,7 +1365,7 @@ test "DWARF expressions" { try b.writeConst(writer, u16, 0xf0ff); try b.writeOpcode(writer, OP.@"and"); _ = try stack_machine.run(program.items, allocator, context, null); - try testing.expectEqual(@as(usize, 0xf00f), stack_machine.stack.popOrNull().?.generic); + try testing.expectEqual(@as(usize, 0xf00f), stack_machine.stack.pop().?.generic); stack_machine.reset(); program.clearRetainingCapacity(); @@ -1373,7 +1373,7 @@ test "DWARF expressions" { try b.writeConst(writer, i16, 100); try b.writeOpcode(writer, OP.div); _ = try stack_machine.run(program.items, allocator, context, null); - try testing.expectEqual(@as(isize, -404 / 100), @as(isize, @bitCast(stack_machine.stack.popOrNull().?.generic))); + try testing.expectEqual(@as(isize, -404 / 100), @as(isize, @bitCast(stack_machine.stack.pop().?.generic))); stack_machine.reset(); program.clearRetainingCapacity(); @@ -1381,7 +1381,7 @@ test "DWARF expressions" { try b.writeConst(writer, u16, 50); try b.writeOpcode(writer, OP.minus); _ = try stack_machine.run(program.items, allocator, context, null); - try testing.expectEqual(@as(usize, 150), stack_machine.stack.popOrNull().?.generic); + try testing.expectEqual(@as(usize, 150), stack_machine.stack.pop().?.generic); stack_machine.reset(); program.clearRetainingCapacity(); @@ -1389,7 +1389,7 @@ test "DWARF expressions" { try b.writeConst(writer, u16, 100); try b.writeOpcode(writer, OP.mod); _ = try stack_machine.run(program.items, allocator, context, null); - try testing.expectEqual(@as(usize, 23), stack_machine.stack.popOrNull().?.generic); + try testing.expectEqual(@as(usize, 23), stack_machine.stack.pop().?.generic); stack_machine.reset(); program.clearRetainingCapacity(); @@ -1397,7 +1397,7 @@ test "DWARF expressions" { try b.writeConst(writer, u16, 0xee); try b.writeOpcode(writer, OP.mul); _ = try stack_machine.run(program.items, allocator, context, null); - try testing.expectEqual(@as(usize, 0xed12), stack_machine.stack.popOrNull().?.generic); + try testing.expectEqual(@as(usize, 0xed12), stack_machine.stack.pop().?.generic); stack_machine.reset(); program.clearRetainingCapacity(); @@ -1406,15 +1406,15 @@ test "DWARF expressions" { try b.writeConst(writer, i16, -6); try b.writeOpcode(writer, OP.neg); _ = try stack_machine.run(program.items, allocator, context, null); - try testing.expectEqual(@as(usize, 6), stack_machine.stack.popOrNull().?.generic); - try testing.expectEqual(@as(isize, -5), @as(isize, @bitCast(stack_machine.stack.popOrNull().?.generic))); + try testing.expectEqual(@as(usize, 6), stack_machine.stack.pop().?.generic); + try testing.expectEqual(@as(isize, -5), @as(isize, @bitCast(stack_machine.stack.pop().?.generic))); stack_machine.reset(); program.clearRetainingCapacity(); try b.writeConst(writer, u16, 0xff0f); try b.writeOpcode(writer, OP.not); _ = try stack_machine.run(program.items, allocator, context, null); - try testing.expectEqual(~@as(usize, 0xff0f), stack_machine.stack.popOrNull().?.generic); + try testing.expectEqual(~@as(usize, 0xff0f), stack_machine.stack.pop().?.generic); stack_machine.reset(); program.clearRetainingCapacity(); @@ -1422,7 +1422,7 @@ test "DWARF expressions" { try b.writeConst(writer, u16, 0xf0ff); try b.writeOpcode(writer, OP.@"or"); _ = try stack_machine.run(program.items, allocator, context, null); - try testing.expectEqual(@as(usize, 0xffff), stack_machine.stack.popOrNull().?.generic); + try testing.expectEqual(@as(usize, 0xffff), stack_machine.stack.pop().?.generic); stack_machine.reset(); program.clearRetainingCapacity(); @@ -1430,14 +1430,14 @@ test "DWARF expressions" { try b.writeConst(writer, i16, 100); try b.writeOpcode(writer, OP.plus); _ = try stack_machine.run(program.items, allocator, context, null); - try testing.expectEqual(@as(usize, 502), stack_machine.stack.popOrNull().?.generic); + try testing.expectEqual(@as(usize, 502), stack_machine.stack.pop().?.generic); stack_machine.reset(); program.clearRetainingCapacity(); try b.writeConst(writer, u16, 4096); try b.writePlusUconst(writer, @as(usize, 8192)); _ = try stack_machine.run(program.items, allocator, context, null); - try testing.expectEqual(@as(usize, 4096 + 8192), stack_machine.stack.popOrNull().?.generic); + try testing.expectEqual(@as(usize, 4096 + 8192), stack_machine.stack.pop().?.generic); stack_machine.reset(); program.clearRetainingCapacity(); @@ -1445,7 +1445,7 @@ test "DWARF expressions" { try b.writeConst(writer, u16, 1); try b.writeOpcode(writer, OP.shl); _ = try stack_machine.run(program.items, allocator, context, null); - try testing.expectEqual(@as(usize, 0xfff << 1), stack_machine.stack.popOrNull().?.generic); + try testing.expectEqual(@as(usize, 0xfff << 1), stack_machine.stack.pop().?.generic); stack_machine.reset(); program.clearRetainingCapacity(); @@ -1453,7 +1453,7 @@ test "DWARF expressions" { try b.writeConst(writer, u16, 1); try b.writeOpcode(writer, OP.shr); _ = try stack_machine.run(program.items, allocator, context, null); - try testing.expectEqual(@as(usize, 0xfff >> 1), stack_machine.stack.popOrNull().?.generic); + try testing.expectEqual(@as(usize, 0xfff >> 1), stack_machine.stack.pop().?.generic); stack_machine.reset(); program.clearRetainingCapacity(); @@ -1461,7 +1461,7 @@ test "DWARF expressions" { try b.writeConst(writer, u16, 1); try b.writeOpcode(writer, OP.shr); _ = try stack_machine.run(program.items, allocator, context, null); - try testing.expectEqual(@as(usize, @bitCast(@as(isize, 0xfff) >> 1)), stack_machine.stack.popOrNull().?.generic); + try testing.expectEqual(@as(usize, @bitCast(@as(isize, 0xfff) >> 1)), stack_machine.stack.pop().?.generic); stack_machine.reset(); program.clearRetainingCapacity(); @@ -1469,7 +1469,7 @@ test "DWARF expressions" { try b.writeConst(writer, u16, 0xff0f); try b.writeOpcode(writer, OP.xor); _ = try stack_machine.run(program.items, allocator, context, null); - try testing.expectEqual(@as(usize, 0x0ff0), stack_machine.stack.popOrNull().?.generic); + try testing.expectEqual(@as(usize, 0x0ff0), stack_machine.stack.pop().?.generic); } // Control Flow Operations @@ -1498,9 +1498,9 @@ test "DWARF expressions" { try b.writeConst(writer, u16, 0); try b.writeOpcode(writer, e[0]); _ = try stack_machine.run(program.items, allocator, context, null); - try testing.expectEqual(@as(usize, e[3]), stack_machine.stack.popOrNull().?.generic); - try testing.expectEqual(@as(usize, e[2]), stack_machine.stack.popOrNull().?.generic); - try testing.expectEqual(@as(usize, e[1]), stack_machine.stack.popOrNull().?.generic); + try testing.expectEqual(@as(usize, e[3]), stack_machine.stack.pop().?.generic); + try testing.expectEqual(@as(usize, e[2]), stack_machine.stack.pop().?.generic); + try testing.expectEqual(@as(usize, e[1]), stack_machine.stack.pop().?.generic); } stack_machine.reset(); @@ -1509,7 +1509,7 @@ test "DWARF expressions" { try b.writeSkip(writer, 1); try b.writeLiteral(writer, 3); _ = try stack_machine.run(program.items, allocator, context, null); - try testing.expectEqual(@as(usize, 2), stack_machine.stack.popOrNull().?.generic); + try testing.expectEqual(@as(usize, 2), stack_machine.stack.pop().?.generic); stack_machine.reset(); program.clearRetainingCapacity(); @@ -1521,9 +1521,9 @@ test "DWARF expressions" { try b.writeLiteral(writer, 4); try b.writeLiteral(writer, 5); _ = try stack_machine.run(program.items, allocator, context, null); - try testing.expectEqual(@as(usize, 5), stack_machine.stack.popOrNull().?.generic); - try testing.expectEqual(@as(usize, 4), stack_machine.stack.popOrNull().?.generic); - try testing.expect(stack_machine.stack.popOrNull() == null); + try testing.expectEqual(@as(usize, 5), stack_machine.stack.pop().?.generic); + try testing.expectEqual(@as(usize, 4), stack_machine.stack.pop().?.generic); + try testing.expect(stack_machine.stack.pop() == null); // TODO: Test call2, call4, call_ref once implemented @@ -1547,7 +1547,7 @@ test "DWARF expressions" { try b.writeConstType(writer, @as(usize, 0), &value_bytes); try b.writeConvert(writer, @as(usize, 0)); _ = try stack_machine.run(program.items, allocator, context, null); - try testing.expectEqual(value, stack_machine.stack.popOrNull().?.generic); + try testing.expectEqual(value, stack_machine.stack.pop().?.generic); // Reinterpret to generic type stack_machine.reset(); @@ -1555,7 +1555,7 @@ test "DWARF expressions" { try b.writeConstType(writer, @as(usize, 0), &value_bytes); try b.writeReinterpret(writer, @as(usize, 0)); _ = try stack_machine.run(program.items, allocator, context, null); - try testing.expectEqual(value, stack_machine.stack.popOrNull().?.generic); + try testing.expectEqual(value, stack_machine.stack.pop().?.generic); // Reinterpret to new type const die_offset: usize = 0xffee; @@ -1565,7 +1565,7 @@ test "DWARF expressions" { try b.writeConstType(writer, @as(usize, 0), &value_bytes); try b.writeReinterpret(writer, die_offset); _ = try stack_machine.run(program.items, allocator, context, null); - const const_type = stack_machine.stack.popOrNull().?.const_type; + const const_type = stack_machine.stack.pop().?.const_type; try testing.expectEqual(die_offset, const_type.type_offset); stack_machine.reset(); @@ -1573,7 +1573,7 @@ test "DWARF expressions" { try b.writeLiteral(writer, 0); try b.writeReinterpret(writer, die_offset); _ = try stack_machine.run(program.items, allocator, context, null); - const regval_type = stack_machine.stack.popOrNull().?.regval_type; + const regval_type = stack_machine.stack.pop().?.regval_type; try testing.expectEqual(die_offset, regval_type.type_offset); } @@ -1585,7 +1585,7 @@ test "DWARF expressions" { program.clearRetainingCapacity(); try b.writeOpcode(writer, OP.nop); _ = try stack_machine.run(program.items, allocator, context, null); - try testing.expect(stack_machine.stack.popOrNull() == null); + try testing.expect(stack_machine.stack.pop() == null); // Sub-expression { @@ -1598,7 +1598,7 @@ test "DWARF expressions" { program.clearRetainingCapacity(); try b.writeEntryValue(writer, sub_program.items); _ = try stack_machine.run(program.items, allocator, context, null); - try testing.expectEqual(@as(usize, 3), stack_machine.stack.popOrNull().?.generic); + try testing.expectEqual(@as(usize, 3), stack_machine.stack.pop().?.generic); } // Register location description @@ -1625,7 +1625,7 @@ test "DWARF expressions" { program.clearRetainingCapacity(); try b.writeEntryValue(writer, sub_program.items); _ = try stack_machine.run(program.items, allocator, context, null); - try testing.expectEqual(@as(usize, 0xee), stack_machine.stack.popOrNull().?.generic); + try testing.expectEqual(@as(usize, 0xee), stack_machine.stack.pop().?.generic); } else |err| { switch (err) { error.UnimplementedArch, diff --git a/lib/std/fs/Dir.zig b/lib/std/fs/Dir.zig index 74d91239f810..fa3415733c9c 100644 --- a/lib/std/fs/Dir.zig +++ b/lib/std/fs/Dir.zig @@ -658,7 +658,7 @@ pub const Walker = struct { // walking if they want, which means that we need to pop the directory // that errored from the stack. Otherwise, all future `next` calls would // likely just fail with the same error. - var item = self.stack.pop(); + var item = self.stack.pop().?; if (self.stack.items.len != 0) { item.iter.dir.close(); } @@ -692,7 +692,7 @@ pub const Walker = struct { .kind = base.kind, }; } else { - var item = self.stack.pop(); + var item = self.stack.pop().?; if (self.stack.items.len != 0) { item.iter.dir.close(); } diff --git a/lib/std/heap.zig b/lib/std/heap.zig index 9b99f7e1d9af..e829fcf33335 100644 --- a/lib/std/heap.zig +++ b/lib/std/heap.zig @@ -871,7 +871,7 @@ pub fn testAllocatorAlignedShrink(base_allocator: mem.Allocator) !void { try stuff_to_free.append(slice); slice = try allocator.alignedAlloc(u8, 16, alloc_size); } - while (stuff_to_free.popOrNull()) |item| { + while (stuff_to_free.pop()) |item| { allocator.free(item); } slice[0] = 0x12; diff --git a/lib/std/heap/general_purpose_allocator.zig b/lib/std/heap/general_purpose_allocator.zig index 278c2bc26479..7568c7c95535 100644 --- a/lib/std/heap/general_purpose_allocator.zig +++ b/lib/std/heap/general_purpose_allocator.zig @@ -1075,7 +1075,7 @@ test "small allocations - free in reverse order" { try list.append(ptr); } - while (list.popOrNull()) |ptr| { + while (list.pop()) |ptr| { allocator.destroy(ptr); } } @@ -1233,7 +1233,7 @@ test "shrink large object to large object with larger alignment" { try stuff_to_free.append(slice); slice = try allocator.alignedAlloc(u8, 16, alloc_size); } - while (stuff_to_free.popOrNull()) |item| { + while (stuff_to_free.pop()) |item| { allocator.free(item); } slice[0] = 0x12; @@ -1302,7 +1302,7 @@ test "realloc large object to larger alignment" { try stuff_to_free.append(slice); slice = try allocator.alignedAlloc(u8, 16, page_size * 2 + 50); } - while (stuff_to_free.popOrNull()) |item| { + while (stuff_to_free.pop()) |item| { allocator.free(item); } slice[0] = 0x12; diff --git a/lib/std/json/dynamic.zig b/lib/std/json/dynamic.zig index a56d37bf0ba5..1abd1072c681 100644 --- a/lib/std/json/dynamic.zig +++ b/lib/std/json/dynamic.zig @@ -119,7 +119,7 @@ pub const Value = union(enum) { .array_begin => { try stack.append(Value{ .array = Array.init(allocator) }); }, - .array_end => return try handleCompleteValue(&stack, allocator, source, stack.pop(), options) orelse continue, + .array_end => return try handleCompleteValue(&stack, allocator, source, stack.pop().?, options) orelse continue, else => unreachable, } @@ -143,7 +143,7 @@ fn handleCompleteValue(stack: *Array, allocator: Allocator, source: anytype, val switch (stack.items[stack.items.len - 1]) { .string => |key| { // stack: [..., .object, .string] - _ = stack.pop(); + _ = stack.pop().?; // stack: [..., .object] var object = &stack.items[stack.items.len - 1].object; @@ -154,7 +154,7 @@ fn handleCompleteValue(stack: *Array, allocator: Allocator, source: anytype, val switch (try source.nextAllocMax(allocator, .alloc_always, options.max_value_len.?)) { .object_end => { // This object is complete. - value = stack.pop(); + value = stack.pop().?; // Effectively recurse now that we have a complete value. if (stack.items.len == 0) return value; continue; diff --git a/lib/std/linked_list.zig b/lib/std/linked_list.zig index 07c5f5d4df6c..507d1bd0eb54 100644 --- a/lib/std/linked_list.zig +++ b/lib/std/linked_list.zig @@ -377,7 +377,7 @@ test "basic DoublyLinkedList test" { } _ = list.popFirst(); // {2, 3, 4, 5} - _ = list.pop(); // {2, 3, 4} + _ = list.pop().?; // {2, 3, 4} list.remove(&three); // {2, 4} try testing.expect(list.first.?.data == 2); diff --git a/lib/std/multi_array_list.zig b/lib/std/multi_array_list.zig index d7327f8bee96..87a1170214f9 100644 --- a/lib/std/multi_array_list.zig +++ b/lib/std/multi_array_list.zig @@ -252,21 +252,14 @@ pub fn MultiArrayList(comptime T: type) type { return index; } - /// Remove and return the last element from the list. - /// Asserts the list has at least one item. - /// Invalidates pointers to fields of the removed element. - pub fn pop(self: *Self) T { - const val = self.get(self.len - 1); - self.len -= 1; - return val; - } - /// Remove and return the last element from the list, or /// return `null` if list is empty. /// Invalidates pointers to fields of the removed element, if any. - pub fn popOrNull(self: *Self) ?T { + pub fn pop(self: *Self) ?T { if (self.len == 0) return null; - return self.pop(); + const val = self.get(self.len - 1); + self.len -= 1; + return val; } /// Inserts an item into an ordered list. Shifts all elements @@ -667,11 +660,11 @@ test "basic usage" { .b = "xnopyt", .c = 'd', }); - try testing.expectEqualStrings("xnopyt", list.pop().b); - try testing.expectEqual(@as(?u8, 'c'), if (list.popOrNull()) |elem| elem.c else null); - try testing.expectEqual(@as(u32, 2), list.pop().a); - try testing.expectEqual(@as(u8, 'a'), list.pop().c); - try testing.expectEqual(@as(?Foo, null), list.popOrNull()); + try testing.expectEqualStrings("xnopyt", list.pop().?.b); + try testing.expectEqual(@as(?u8, 'c'), if (list.pop()) |elem| elem.c else null); + try testing.expectEqual(@as(u32, 2), list.pop().?.a); + try testing.expectEqual(@as(u8, 'a'), list.pop().?.c); + try testing.expectEqual(@as(?Foo, null), list.pop()); } // This was observed to fail on aarch64 with LLVM 11, when the capacityInBytes diff --git a/lib/std/segmented_list.zig b/lib/std/segmented_list.zig index a729c368edf2..0f8a090fa735 100644 --- a/lib/std/segmented_list.zig +++ b/lib/std/segmented_list.zig @@ -134,7 +134,6 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type pub fn pop(self: *Self) ?T { if (self.len == 0) return null; - const index = self.len - 1; const result = uncheckedAt(self, index).*; self.len = index; diff --git a/lib/std/zig/AstGen.zig b/lib/std/zig/AstGen.zig index a52007eabf24..f2f497e436bd 100644 --- a/lib/std/zig/AstGen.zig +++ b/lib/std/zig/AstGen.zig @@ -6861,7 +6861,7 @@ fn forExpr( // We need to finish loop_scope later once we have the deferred refs from then_scope. However, the // load must be removed from instructions in the meantime or it appears to be part of parent_gz. const index = try loop_scope.addUnNode(.load, index_ptr, node); - _ = loop_scope.instructions.pop(); + _ = loop_scope.instructions.pop().?; var cond_scope = parent_gz.makeSubBlock(&loop_scope.base); defer cond_scope.unstack(); diff --git a/lib/std/zig/WindowsSdk.zig b/lib/std/zig/WindowsSdk.zig index 3b9b788a7b36..feb966eb3d22 100644 --- a/lib/std/zig/WindowsSdk.zig +++ b/lib/std/zig/WindowsSdk.zig @@ -143,7 +143,7 @@ fn iterateAndFilterBySemVer( const dirs_filtered_slice = try dirs_filtered_list.toOwnedSlice(); // Keep in mind that order of these names is not guaranteed by Windows, - // so we cannot just reverse or "while (popOrNull())" this ArrayList. + // so we cannot just reverse or "while (pop())" this ArrayList. std.mem.sortUnstable([]const u8, dirs_filtered_slice, {}, struct { fn desc(_: void, lhs: []const u8, rhs: []const u8) bool { return std.mem.order(u8, lhs, rhs) == .gt; @@ -440,7 +440,7 @@ pub const Windows10Sdk = struct { errdefer path.deinit(); // String might contain trailing slash, so trim it here - if (path.items.len > "C:\\".len and path.getLast() == '\\') _ = path.pop(); + if (path.items.len > "C:\\".len and path.getLast() == '\\') _ = path.pop().?; const path_without_trailing_slash = try path.toOwnedSlice(); break :path10 path_without_trailing_slash; @@ -530,7 +530,7 @@ pub const Windows81Sdk = struct { errdefer path.deinit(); // String might contain trailing slash, so trim it here - if (path.items.len > "C:\\".len and path.getLast() == '\\') _ = path.pop(); + if (path.items.len > "C:\\".len and path.getLast() == '\\') _ = path.pop().?; const path_without_trailing_slash = try path.toOwnedSlice(); break :path81 path_without_trailing_slash; @@ -839,7 +839,7 @@ const MsvcLibDir = struct { errdefer msvc_dir.deinit(); // String might contain trailing slash, so trim it here - if (msvc_dir.items.len > "C:\\".len and msvc_dir.getLast() == '\\') _ = msvc_dir.pop(); + if (msvc_dir.items.len > "C:\\".len and msvc_dir.getLast() == '\\') _ = msvc_dir.pop().?; // Remove `\include` at the end of path if (std.mem.endsWith(u8, msvc_dir.items, "\\include")) { @@ -884,7 +884,7 @@ const MsvcLibDir = struct { try list.appendSlice(VS140COMNTOOLS); // C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools // String might contain trailing slash, so trim it here - if (list.items.len > "C:\\".len and list.getLast() == '\\') _ = list.pop(); + if (list.items.len > "C:\\".len and list.getLast() == '\\') _ = list.pop().?; list.shrinkRetainingCapacity(list.items.len - "\\Common7\\Tools".len); // C:\Program Files (x86)\Microsoft Visual Studio 14.0 break :base_path list; } @@ -907,7 +907,7 @@ const MsvcLibDir = struct { errdefer path.deinit(); // String might contain trailing slash, so trim it here - if (path.items.len > "C:\\".len and path.getLast() == '\\') _ = path.pop(); + if (path.items.len > "C:\\".len and path.getLast() == '\\') _ = path.pop().?; break :base_path path; } return error.PathNotFound; diff --git a/src/Compilation.zig b/src/Compilation.zig index c533f2fae79d..428a2749626b 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -596,7 +596,7 @@ pub const CObject = struct { .end_block => |block| switch (@as(BlockId, @enumFromInt(block.id))) { .Meta => {}, .Diag => { - var wip_diag = stack.pop(); + var wip_diag = stack.pop().?; errdefer wip_diag.deinit(gpa); const src_ranges = try wip_diag.src_ranges.toOwnedSlice(gpa); diff --git a/src/InternPool.zig b/src/InternPool.zig index 4edc32e86c1f..5f9df1c2400b 100644 --- a/src/InternPool.zig +++ b/src/InternPool.zig @@ -268,7 +268,7 @@ pub fn addDependency(ip: *InternPool, gpa: Allocator, depender: Depender, depend } // Prepend a new dependency. - const new_index: DepEntry.Index, const ptr = if (ip.free_dep_entries.popOrNull()) |new_index| new: { + const new_index: DepEntry.Index, const ptr = if (ip.free_dep_entries.pop()) |new_index| new: { break :new .{ new_index, &ip.dep_entries.items[@intFromEnum(new_index)] }; } else .{ @enumFromInt(ip.dep_entries.items.len), ip.dep_entries.addOneAssumeCapacity() }; ptr.next = if (gop.found_existing) gop.value_ptr.*.toOptional() else .none; @@ -4993,7 +4993,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { assert(ptr_type.sentinel == .none or ip.typeOf(ptr_type.sentinel) == ptr_type.child); if (ptr_type.flags.size == .Slice) { - _ = ip.map.pop(); + _ = ip.map.pop().?; var new_key = key; new_key.ptr_type.flags.size = .Many; const ptr_type_index = try ip.get(gpa, new_key); @@ -5265,7 +5265,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { }, else => unreachable, } - _ = ip.map.pop(); + _ = ip.map.pop().?; const index_index = try ip.get(gpa, .{ .int = .{ .ty = .usize_type, .storage = .{ .u64 = base_index.index }, @@ -5678,7 +5678,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { } const elem = switch (aggregate.storage) { .bytes => |bytes| elem: { - _ = ip.map.pop(); + _ = ip.map.pop().?; const elem = try ip.get(gpa, .{ .int = .{ .ty = .u8_type, .storage = .{ .u64 = bytes[0] }, @@ -5835,7 +5835,7 @@ pub fn getUnionType(ip: *InternPool, gpa: Allocator, ini: UnionTypeInit) Allocat } }, } }, adapter); if (gop.found_existing) return .{ .existing = @enumFromInt(gop.index) }; - errdefer _ = ip.map.pop(); + errdefer _ = ip.map.pop().?; const align_elements_len = if (ini.flags.any_aligned_fields) (ini.fields_len + 3) / 4 else 0; const align_element: u32 = @bitCast([1]u8{@intFromEnum(Alignment.none)} ** 4); @@ -5984,10 +5984,10 @@ pub fn getStructType( } }; const gop = try ip.map.getOrPutAdapted(gpa, key, adapter); if (gop.found_existing) return .{ .existing = @enumFromInt(gop.index) }; - errdefer _ = ip.map.pop(); + errdefer _ = ip.map.pop().?; const names_map = try ip.addMap(gpa, ini.fields_len); - errdefer _ = ip.maps.pop(); + errdefer _ = ip.maps.pop().?; const zir_index = switch (ini.key) { inline else => |x| x.zir_index, @@ -6255,7 +6255,7 @@ pub fn getExternFunc(ip: *InternPool, gpa: Allocator, key: Key.ExternFunc) Alloc const adapter: KeyAdapter = .{ .intern_pool = ip }; const gop = try ip.map.getOrPutAdapted(gpa, Key{ .extern_func = key }, adapter); if (gop.found_existing) return @enumFromInt(gop.index); - errdefer _ = ip.map.pop(); + errdefer _ = ip.map.pop().?; const prev_extra_len = ip.extra.items.len; const extra_index = try ip.addExtra(gpa, @as(Tag.ExternFunc, key)); errdefer ip.extra.items.len = prev_extra_len; @@ -6479,7 +6479,7 @@ pub fn getErrorSetType( const gop = try ip.map.getOrPutAdapted(gpa, Key{ .error_set_type = extraErrorSet(ip, error_set_extra_index), }, adapter); - errdefer _ = ip.map.pop(); + errdefer _ = ip.map.pop().?; if (gop.found_existing) { ip.extra.items.len = prev_extra_len; @@ -6494,7 +6494,7 @@ pub fn getErrorSetType( const names_map = try ip.addMap(gpa, names.len); assert(names_map == predicted_names_map); - errdefer _ = ip.maps.pop(); + errdefer _ = ip.maps.pop().?; addStringsToMap(ip, names_map, names); @@ -6560,7 +6560,7 @@ pub fn getFuncInstance(ip: *InternPool, gpa: Allocator, arg: GetFuncInstanceKey) const gop = try ip.map.getOrPutAdapted(gpa, Key{ .func = extraFuncInstance(ip, func_extra_index), }, KeyAdapter{ .intern_pool = ip }); - errdefer _ = ip.map.pop(); + errdefer _ = ip.map.pop().?; if (gop.found_existing) { ip.extra.items.len = prev_extra_len; @@ -6861,12 +6861,12 @@ pub fn getEnumType( } }, adapter); if (gop.found_existing) return .{ .existing = @enumFromInt(gop.index) }; assert(gop.index == ip.items.len); - errdefer _ = ip.map.pop(); + errdefer _ = ip.map.pop().?; try ip.items.ensureUnusedCapacity(gpa, 1); const names_map = try ip.addMap(gpa, ini.fields_len); - errdefer _ = ip.maps.pop(); + errdefer _ = ip.maps.pop().?; switch (ini.tag_mode) { .auto => { @@ -6922,7 +6922,7 @@ pub fn getEnumType( break :m values_map.toOptional(); }; errdefer if (ini.has_values) { - _ = ip.map.pop(); + _ = ip.map.pop().?; }; try ip.extra.ensureUnusedCapacity(gpa, @typeInfo(EnumExplicit).Struct.fields.len + @@ -7004,7 +7004,7 @@ pub fn getGeneratedTagEnumType(ip: *InternPool, gpa: Allocator, ini: GeneratedTa try ip.items.ensureUnusedCapacity(gpa, 1); const names_map = try ip.addMap(gpa, ini.names.len); - errdefer _ = ip.maps.pop(); + errdefer _ = ip.maps.pop().?; ip.addStringsToMap(names_map, ini.names); const fields_len: u32 = @intCast(ini.names.len); @@ -7105,7 +7105,7 @@ pub fn getOpaqueType(ip: *InternPool, gpa: Allocator, ini: OpaqueTypeInit) Alloc } }, } }, adapter); if (gop.found_existing) return .{ .existing = @enumFromInt(gop.index) }; - errdefer _ = ip.map.pop(); + errdefer _ = ip.map.pop().?; try ip.items.ensureUnusedCapacity(gpa, 1); try ip.extra.ensureUnusedCapacity(gpa, @typeInfo(Tag.TypeOpaque).Struct.fields.len + switch (ini.key) { .declared => |d| d.captures.len, @@ -7178,7 +7178,7 @@ fn addIndexesToMap( fn addMap(ip: *InternPool, gpa: Allocator, cap: usize) Allocator.Error!MapIndex { const ptr = try ip.maps.addOne(gpa); - errdefer _ = ip.maps.pop(); + errdefer _ = ip.maps.pop().?; ptr.* = .{}; try ptr.ensureTotalCapacity(gpa, cap); return @enumFromInt(ip.maps.items.len - 1); @@ -7206,7 +7206,7 @@ pub fn remove(ip: *InternPool, index: Index) void { if (@intFromEnum(index) == ip.items.len - 1) { // Happy case - we can just drop the item without affecting any other indices. ip.items.len -= 1; - _ = ip.map.pop(); + _ = ip.map.pop().?; } else { // We must preserve the item so that indices following it remain valid. // Thus, we will rewrite the tag to `removed`, leaking the item until @@ -8391,7 +8391,7 @@ pub fn createDecl( gpa: Allocator, initialization: Module.Decl, ) Allocator.Error!DeclIndex { - if (ip.decls_free_list.popOrNull()) |index| { + if (ip.decls_free_list.pop()) |index| { ip.allocated_decls.at(@intFromEnum(index)).* = initialization; return index; } @@ -8413,7 +8413,7 @@ pub fn createNamespace( gpa: Allocator, initialization: Module.Namespace, ) Allocator.Error!NamespaceIndex { - if (ip.namespaces_free_list.popOrNull()) |index| { + if (ip.namespaces_free_list.pop()) |index| { ip.allocated_namespaces.at(@intFromEnum(index)).* = initialization; return index; } @@ -8478,7 +8478,7 @@ pub fn getOrPutTrailingString( const string_bytes = &ip.string_bytes; const str_index: u32 = @intCast(string_bytes.items.len - len); if (len > 0 and string_bytes.getLast() == 0) { - _ = string_bytes.pop(); + _ = string_bytes.pop().?; } else { try string_bytes.ensureUnusedCapacity(gpa, 1); } diff --git a/src/Module.zig b/src/Module.zig index 0399a2f85b53..191098ba3281 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -2826,7 +2826,7 @@ pub fn mapOldZirToNew( var new_decls = std.ArrayList(Zir.Inst.Index).init(gpa); defer new_decls.deinit(); - while (match_stack.popOrNull()) |match_item| { + while (match_stack.pop()) |match_item| { // Match the namespace declaration itself try inst_map.put(gpa, match_item.old_inst, match_item.new_inst); @@ -3844,7 +3844,7 @@ pub fn importPkg(zcu: *Zcu, mod: *Package.Module) !ImportFileResult { defer if (!keep_resolved_path) gpa.free(resolved_path); const gop = try zcu.import_table.getOrPut(gpa, resolved_path); - errdefer _ = zcu.import_table.pop(); + errdefer _ = zcu.import_table.pop().?; if (gop.found_existing) { try gop.value_ptr.*.addReference(zcu.*, .{ .root = mod }); return ImportFileResult{ @@ -3928,7 +3928,7 @@ pub fn importFile( defer if (!keep_resolved_path) gpa.free(resolved_path); const gop = try mod.import_table.getOrPut(gpa, resolved_path); - errdefer _ = mod.import_table.pop(); + errdefer _ = mod.import_table.pop().?; if (gop.found_existing) return ImportFileResult{ .file = gop.value_ptr.*, .is_new = false, @@ -4000,7 +4000,7 @@ pub fn embedFile( const gop = try mod.embed_table.getOrPut(gpa, resolved_path); errdefer { - assert(std.mem.eql(u8, mod.embed_table.pop().key, resolved_path)); + assert(std.mem.eql(u8, mod.embed_table.pop().?.key, resolved_path)); keep_resolved_path = false; } if (gop.found_existing) return gop.value_ptr.*.val; @@ -4027,7 +4027,7 @@ pub fn embedFile( const gop = try mod.embed_table.getOrPut(gpa, resolved_path); errdefer { - assert(std.mem.eql(u8, mod.embed_table.pop().key, resolved_path)); + assert(std.mem.eql(u8, mod.embed_table.pop().?.key, resolved_path)); keep_resolved_path = false; } if (gop.found_existing) return gop.value_ptr.*.val; diff --git a/src/Package/Fetch.zig b/src/Package/Fetch.zig index d0cfd5ab9491..2e414b747f1b 100644 --- a/src/Package/Fetch.zig +++ b/src/Package/Fetch.zig @@ -121,7 +121,7 @@ pub const JobQueue = struct { // `Fetch` instances are allocated in prior ones' arenas. // Sorry, I know it's a bit weird, but it slightly simplifies the // critical section. - while (jq.all_fetches.popOrNull()) |f| f.deinit(); + while (jq.all_fetches.pop()) |f| f.deinit(); jq.all_fetches.deinit(gpa); jq.* = undefined; } diff --git a/src/Sema.zig b/src/Sema.zig index 3c999e507e8d..f49bbe76d2ad 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -3868,7 +3868,7 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref, const tmp_air = sema.getTmpAir(); - while (to_map.popOrNull()) |air_ptr| { + while (to_map.pop()) |air_ptr| { if (ptr_mapping.contains(air_ptr)) continue; const PointerMethod = union(enum) { same_addr, @@ -6484,7 +6484,7 @@ fn addExport(mod: *Module, export_init: Module.Export) error{OutOfMemory}!void { const eo_gop = mod.export_owners.getOrPutAssumeCapacity(export_init.owner_decl); if (!eo_gop.found_existing) eo_gop.value_ptr.* = .{}; try eo_gop.value_ptr.append(gpa, new_export); - errdefer _ = eo_gop.value_ptr.pop(); + errdefer _ = eo_gop.value_ptr.pop().?; switch (export_init.exported) { .decl_index => |decl_index| { diff --git a/src/arch/aarch64/CodeGen.zig b/src/arch/aarch64/CodeGen.zig index b9f8259c05dc..4d8cea09568b 100644 --- a/src/arch/aarch64/CodeGen.zig +++ b/src/arch/aarch64/CodeGen.zig @@ -591,7 +591,7 @@ fn gen(self: *Self) !void { // dbg_epilogue_begin) is the last exitlude jump // relocation (which would just jump one instruction // further), it can be safely removed - self.mir_instructions.orderedRemove(self.exitlude_jump_relocs.pop()); + self.mir_instructions.orderedRemove(self.exitlude_jump_relocs.pop().?); } for (self.exitlude_jump_relocs.items) |jmp_reloc| { @@ -4707,7 +4707,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void { try self.branch_stack.append(.{}); errdefer { - _ = self.branch_stack.pop(); + _ = self.branch_stack.pop().?; } try self.ensureProcessDeathCapacity(liveness_condbr.then_deaths.len); @@ -4718,7 +4718,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void { // Revert to the previous register and stack allocation state. - var saved_then_branch = self.branch_stack.pop(); + var saved_then_branch = self.branch_stack.pop().?; defer saved_then_branch.deinit(self.gpa); self.register_manager.registers = parent_registers; @@ -4813,7 +4813,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void { } { - var item = self.branch_stack.pop(); + var item = self.branch_stack.pop().?; item.deinit(self.gpa); } @@ -5066,7 +5066,7 @@ fn lowerBlock(self: *Self, inst: Air.Inst.Index, body: []const Air.Inst.Index) ! // If the last Mir instruction is the last relocation (which // would just jump one instruction further), it can be safely // removed - self.mir_instructions.orderedRemove(relocs.pop()); + self.mir_instructions.orderedRemove(relocs.pop().?); } for (relocs.items) |reloc| { try self.performReloc(reloc); @@ -5138,7 +5138,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void { try self.branch_stack.append(.{}); errdefer { - _ = self.branch_stack.pop(); + _ = self.branch_stack.pop().?; } try self.ensureProcessDeathCapacity(liveness.deaths[case_i].len); @@ -5148,7 +5148,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void { try self.genBody(case_body); // Revert to the previous register and stack allocation state. - var saved_case_branch = self.branch_stack.pop(); + var saved_case_branch = self.branch_stack.pop().?; defer saved_case_branch.deinit(self.gpa); self.register_manager.registers = parent_registers; @@ -5176,7 +5176,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void { try self.branch_stack.append(.{}); errdefer { - _ = self.branch_stack.pop(); + _ = self.branch_stack.pop().?; } const else_deaths = liveness.deaths.len - 1; @@ -5187,7 +5187,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void { try self.genBody(else_body); // Revert to the previous register and stack allocation state. - var saved_case_branch = self.branch_stack.pop(); + var saved_case_branch = self.branch_stack.pop().?; defer saved_case_branch.deinit(self.gpa); self.register_manager.registers = parent_registers; diff --git a/src/arch/arm/CodeGen.zig b/src/arch/arm/CodeGen.zig index 86d4e8f7fdd6..37c2fb0cc30d 100644 --- a/src/arch/arm/CodeGen.zig +++ b/src/arch/arm/CodeGen.zig @@ -584,7 +584,7 @@ fn gen(self: *Self) !void { // dbg_epilogue_begin) is the last exitlude jump // relocation (which would just jump one instruction // further), it can be safely removed - self.mir_instructions.orderedRemove(self.exitlude_jump_relocs.pop()); + self.mir_instructions.orderedRemove(self.exitlude_jump_relocs.pop().?); } for (self.exitlude_jump_relocs.items) |jmp_reloc| { @@ -4663,7 +4663,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void { try self.branch_stack.append(.{}); errdefer { - _ = self.branch_stack.pop(); + _ = self.branch_stack.pop().?; } try self.ensureProcessDeathCapacity(liveness_condbr.then_deaths.len); @@ -4674,7 +4674,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void { // Revert to the previous register and stack allocation state. - var saved_then_branch = self.branch_stack.pop(); + var saved_then_branch = self.branch_stack.pop().?; defer saved_then_branch.deinit(self.gpa); self.register_manager.registers = parent_registers; @@ -4769,7 +4769,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void { } { - var item = self.branch_stack.pop(); + var item = self.branch_stack.pop().?; item.deinit(self.gpa); } @@ -4997,7 +4997,7 @@ fn lowerBlock(self: *Self, inst: Air.Inst.Index, body: []const Air.Inst.Index) ! // If the last Mir instruction is the last relocation (which // would just jump one instruction further), it can be safely // removed - self.mir_instructions.orderedRemove(relocs.pop()); + self.mir_instructions.orderedRemove(relocs.pop().?); } for (relocs.items) |reloc| { try self.performReloc(reloc); @@ -5069,7 +5069,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void { try self.branch_stack.append(.{}); errdefer { - _ = self.branch_stack.pop(); + _ = self.branch_stack.pop().?; } try self.ensureProcessDeathCapacity(liveness.deaths[case_i].len); @@ -5079,7 +5079,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void { try self.genBody(case_body); // Revert to the previous register and stack allocation state. - var saved_case_branch = self.branch_stack.pop(); + var saved_case_branch = self.branch_stack.pop().?; defer saved_case_branch.deinit(self.gpa); self.register_manager.registers = parent_registers; @@ -5107,7 +5107,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void { try self.branch_stack.append(.{}); errdefer { - _ = self.branch_stack.pop(); + _ = self.branch_stack.pop().?; } const else_deaths = liveness.deaths.len - 1; @@ -5118,7 +5118,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void { try self.genBody(else_body); // Revert to the previous register and stack allocation state. - var saved_case_branch = self.branch_stack.pop(); + var saved_case_branch = self.branch_stack.pop().?; defer saved_case_branch.deinit(self.gpa); self.register_manager.registers = parent_registers; diff --git a/src/arch/riscv64/CodeGen.zig b/src/arch/riscv64/CodeGen.zig index 5abe3afcfd2a..5a1a1f4a0639 100644 --- a/src/arch/riscv64/CodeGen.zig +++ b/src/arch/riscv64/CodeGen.zig @@ -404,7 +404,7 @@ fn gen(self: *Self) !void { // dbg_epilogue_begin) is the last exitlude jump // relocation (which would just jump one instruction // further), it can be safely removed - self.mir_instructions.orderedRemove(self.exitlude_jump_relocs.pop()); + self.mir_instructions.orderedRemove(self.exitlude_jump_relocs.pop().?); } for (self.exitlude_jump_relocs.items) |jmp_reloc| { diff --git a/src/arch/sparc64/CodeGen.zig b/src/arch/sparc64/CodeGen.zig index 19c18ec4a6b0..43ea40ed481e 100644 --- a/src/arch/sparc64/CodeGen.zig +++ b/src/arch/sparc64/CodeGen.zig @@ -401,7 +401,7 @@ fn gen(self: *Self) !void { // dbg_epilogue_begin) is the last exitlude jump // relocation (which would just jump two instructions // further), it can be safely removed - const index = self.exitlude_jump_relocs.pop(); + const index = self.exitlude_jump_relocs.pop().?; // First, remove the delay slot, then remove // the branch instruction itself. @@ -1151,7 +1151,7 @@ fn lowerBlock(self: *Self, inst: Air.Inst.Index, body: []const Air.Inst.Index) ! // If the last Mir instruction is the last relocation (which // would just jump two instruction further), it can be safely // removed - const index = relocs.pop(); + const index = relocs.pop().?; // First, remove the delay slot, then remove // the branch instruction itself. @@ -1530,7 +1530,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void { try self.branch_stack.append(.{}); errdefer { - _ = self.branch_stack.pop(); + _ = self.branch_stack.pop().?; } try self.ensureProcessDeathCapacity(liveness_condbr.then_deaths.len); @@ -1541,7 +1541,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void { // Revert to the previous register and stack allocation state. - var saved_then_branch = self.branch_stack.pop(); + var saved_then_branch = self.branch_stack.pop().?; defer saved_then_branch.deinit(self.gpa); self.register_manager.registers = parent_registers; @@ -1637,7 +1637,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void { } { - var item = self.branch_stack.pop(); + var item = self.branch_stack.pop().?; item.deinit(self.gpa); } diff --git a/src/arch/wasm/CodeGen.zig b/src/arch/wasm/CodeGen.zig index 022f2f9bee7e..55ec5ad24b4a 100644 --- a/src/arch/wasm/CodeGen.zig +++ b/src/arch/wasm/CodeGen.zig @@ -1102,23 +1102,23 @@ fn allocLocal(func: *CodeGen, ty: Type) InnerError!WValue { const mod = func.bin_file.base.comp.module.?; const valtype = typeToValtype(ty, mod); switch (valtype) { - .i32 => if (func.free_locals_i32.popOrNull()) |index| { + .i32 => if (func.free_locals_i32.pop()) |index| { log.debug("reusing local ({d}) of type {}", .{ index, valtype }); return WValue{ .local = .{ .value = index, .references = 1 } }; }, - .i64 => if (func.free_locals_i64.popOrNull()) |index| { + .i64 => if (func.free_locals_i64.pop()) |index| { log.debug("reusing local ({d}) of type {}", .{ index, valtype }); return WValue{ .local = .{ .value = index, .references = 1 } }; }, - .f32 => if (func.free_locals_f32.popOrNull()) |index| { + .f32 => if (func.free_locals_f32.pop()) |index| { log.debug("reusing local ({d}) of type {}", .{ index, valtype }); return WValue{ .local = .{ .value = index, .references = 1 } }; }, - .f64 => if (func.free_locals_f64.popOrNull()) |index| { + .f64 => if (func.free_locals_f64.pop()) |index| { log.debug("reusing local ({d}) of type {}", .{ index, valtype }); return WValue{ .local = .{ .value = index, .references = 1 } }; }, - .v128 => if (func.free_locals_v128.popOrNull()) |index| { + .v128 => if (func.free_locals_v128.pop()) |index| { log.debug("reusing local ({d}) of type {}", .{ index, valtype }); return WValue{ .local = .{ .value = index, .references = 1 } }; }, @@ -1258,7 +1258,7 @@ fn genFunc(func: *CodeGen) InnerError!void { try func.branches.append(func.gpa, .{}); // clean up outer branch defer { - var outer_branch = func.branches.pop(); + var outer_branch = func.branches.pop().?; outer_branch.deinit(func.gpa); assert(func.branches.items.len == 0); // missing branch merge } @@ -3549,7 +3549,7 @@ fn airCondBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { func.branches.appendAssumeCapacity(.{}); try func.currentBranch().values.ensureUnusedCapacity(func.gpa, @as(u32, @intCast(liveness_condbr.else_deaths.len))); defer { - var else_stack = func.branches.pop(); + var else_stack = func.branches.pop().?; else_stack.deinit(func.gpa); } try func.genBody(else_body); @@ -3561,7 +3561,7 @@ fn airCondBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { func.branches.appendAssumeCapacity(.{}); try func.currentBranch().values.ensureUnusedCapacity(func.gpa, @as(u32, @intCast(liveness_condbr.then_deaths.len))); defer { - var then_stack = func.branches.pop(); + var then_stack = func.branches.pop().?; then_stack.deinit(func.gpa); } try func.genBody(then_body); @@ -4163,7 +4163,7 @@ fn airSwitchBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { func.branches.appendAssumeCapacity(.{}); try func.currentBranch().values.ensureUnusedCapacity(func.gpa, liveness.deaths[index].len); defer { - var case_branch = func.branches.pop(); + var case_branch = func.branches.pop().?; case_branch.deinit(func.gpa); } try func.genBody(case.body); @@ -4175,7 +4175,7 @@ fn airSwitchBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { const else_deaths = liveness.deaths.len - 1; try func.currentBranch().values.ensureUnusedCapacity(func.gpa, liveness.deaths[else_deaths].len); defer { - var else_branch = func.branches.pop(); + var else_branch = func.branches.pop().?; else_branch.deinit(func.gpa); } try func.genBody(else_body); @@ -6562,7 +6562,7 @@ fn lowerTry( try func.branches.append(func.gpa, .{}); try func.currentBranch().values.ensureUnusedCapacity(func.gpa, liveness.else_deaths.len + liveness.then_deaths.len); defer { - var branch = func.branches.pop(); + var branch = func.branches.pop().?; branch.deinit(func.gpa); } try func.genBody(body); diff --git a/src/codegen/c.zig b/src/codegen/c.zig index 883f3f7c7765..e253ab4a6dd5 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -496,7 +496,7 @@ pub const Function = struct { const gop = try f.lazy_fns.getOrPut(gpa, key); if (!gop.found_existing) { - errdefer _ = f.lazy_fns.pop(); + errdefer _ = f.lazy_fns.pop().?; gop.value_ptr.* = .{ .fn_name = switch (key) { diff --git a/src/codegen/spirv.zig b/src/codegen/spirv.zig index 9113d72d927d..b60c69b0d60d 100644 --- a/src/codegen/spirv.zig +++ b/src/codegen/spirv.zig @@ -4479,7 +4479,7 @@ const DeclGen = struct { { try self.control_flow.structured.block_stack.append(self.gpa, &sblock); - defer _ = self.control_flow.structured.block_stack.pop(); + defer _ = self.control_flow.structured.block_stack.pop().?; try self.genBody(body); } diff --git a/src/link/Coff.zig b/src/link/Coff.zig index aaf840e02ccf..d7de57ea0f0a 100644 --- a/src/link/Coff.zig +++ b/src/link/Coff.zig @@ -734,7 +734,7 @@ pub fn allocateSymbol(self: *Coff) !u32 { try self.locals.ensureUnusedCapacity(gpa, 1); const index = blk: { - if (self.locals_free_list.popOrNull()) |index| { + if (self.locals_free_list.pop()) |index| { log.debug(" (reusing symbol index {d})", .{index}); break :blk index; } else { @@ -762,7 +762,7 @@ fn allocateGlobal(self: *Coff) !u32 { try self.globals.ensureUnusedCapacity(gpa, 1); const index = blk: { - if (self.globals_free_list.popOrNull()) |index| { + if (self.globals_free_list.pop()) |index| { log.debug(" (reusing global index {d})", .{index}); break :blk index; } else { @@ -888,7 +888,7 @@ fn writeAtom(self: *Coff, atom_index: Atom.Index, code: []u8) !void { try self.base.file.?.pwriteAll(code, file_offset); // Now we can mark the relocs as resolved. - while (relocs.popOrNull()) |reloc| { + while (relocs.pop()) |reloc| { reloc.dirty = false; } } @@ -1361,7 +1361,7 @@ pub fn getOrCreateAtomForLazySymbol(self: *Coff, sym: link.File.LazySymbol) !Ato const gpa = self.base.comp.gpa; const mod = self.base.comp.module.?; const gop = try self.lazy_syms.getOrPut(gpa, sym.getDecl(mod)); - errdefer _ = if (!gop.found_existing) self.lazy_syms.pop(); + errdefer _ = if (!gop.found_existing) self.lazy_syms.pop().?; if (!gop.found_existing) gop.value_ptr.* = .{}; const metadata: struct { atom: *Atom.Index, state: *LazySymbolMetadata.State } = switch (sym.kind) { .code => .{ .atom = &gop.value_ptr.text_atom, .state = &gop.value_ptr.text_state }, @@ -1767,7 +1767,7 @@ pub fn flushModule(self: *Coff, arena: Allocator, prog_node: *std.Progress.Node) } } - while (self.unresolved.popOrNull()) |entry| { + while (self.unresolved.pop()) |entry| { assert(entry.value); const global = self.globals.items[entry.key]; const sym = self.getSymbol(global); diff --git a/src/link/Coff/ImportTable.zig b/src/link/Coff/ImportTable.zig index c25851fe72c3..8626243fffd4 100644 --- a/src/link/Coff/ImportTable.zig +++ b/src/link/Coff/ImportTable.zig @@ -44,7 +44,7 @@ pub fn size(itab: ImportTable) u32 { pub fn addImport(itab: *ImportTable, allocator: Allocator, target: SymbolWithLoc) !ImportIndex { try itab.entries.ensureUnusedCapacity(allocator, 1); const index: u32 = blk: { - if (itab.free_list.popOrNull()) |index| { + if (itab.free_list.pop()) |index| { log.debug(" (reusing import entry index {d})", .{index}); break :blk index; } else { diff --git a/src/link/Dwarf.zig b/src/link/Dwarf.zig index 6a41bb37934a..737262744680 100644 --- a/src/link/Dwarf.zig +++ b/src/link/Dwarf.zig @@ -1440,7 +1440,7 @@ pub fn commitDeclState( try self.updateDeclDebugInfoAllocation(di_atom_index, @intCast(dbg_info_buffer.items.len)); - while (decl_state.abbrev_relocs.popOrNull()) |reloc| { + while (decl_state.abbrev_relocs.pop()) |reloc| { if (reloc.target) |reloc_target| { const symbol = decl_state.abbrev_table.items[reloc_target]; const ty = symbol.type; @@ -1479,7 +1479,7 @@ pub fn commitDeclState( } } - while (decl_state.exprloc_relocs.popOrNull()) |reloc| { + while (decl_state.exprloc_relocs.pop()) |reloc| { switch (self.bin_file.tag) { .macho => { const macho_file = self.bin_file.cast(File.MachO).?; @@ -2734,7 +2734,7 @@ pub fn flushModule(self: *Dwarf, module: *Module) !void { var buf: [@sizeOf(u32)]u8 = undefined; mem.writeInt(u32, &buf, self.getAtom(.di_atom, di_atom_index).off, target.cpu.arch.endian()); - while (self.global_abbrev_relocs.popOrNull()) |reloc| { + while (self.global_abbrev_relocs.pop()) |reloc| { const atom = self.getAtom(.di_atom, reloc.atom_index); switch (self.bin_file.tag) { .elf => { diff --git a/src/link/Elf.zig b/src/link/Elf.zig index c20a4b6afa48..902155a1d954 100644 --- a/src/link/Elf.zig +++ b/src/link/Elf.zig @@ -5490,7 +5490,7 @@ pub fn addSymbol(self: *Elf) !Symbol.Index { const gpa = self.base.comp.gpa; try self.symbols.ensureUnusedCapacity(gpa, 1); const index = blk: { - if (self.symbols_free_list.popOrNull()) |index| { + if (self.symbols_free_list.pop()) |index| { log.debug(" (reusing symbol index {d})", .{index}); break :blk index; } else { diff --git a/src/link/Elf/ZigObject.zig b/src/link/Elf/ZigObject.zig index 6aede441c885..e0c852cd42d0 100644 --- a/src/link/Elf/ZigObject.zig +++ b/src/link/Elf/ZigObject.zig @@ -738,7 +738,7 @@ pub fn getOrCreateMetadataForLazySymbol( const gpa = elf_file.base.comp.gpa; const mod = elf_file.base.comp.module.?; const gop = try self.lazy_syms.getOrPut(gpa, lazy_sym.getDecl(mod)); - errdefer _ = if (!gop.found_existing) self.lazy_syms.pop(); + errdefer _ = if (!gop.found_existing) self.lazy_syms.pop().?; if (!gop.found_existing) gop.value_ptr.* = .{}; const metadata: struct { symbol_index: *Symbol.Index, diff --git a/src/link/MachO/ZigObject.zig b/src/link/MachO/ZigObject.zig index fb27c965252e..41c6dcb0b6fb 100644 --- a/src/link/MachO/ZigObject.zig +++ b/src/link/MachO/ZigObject.zig @@ -1423,7 +1423,7 @@ pub fn getOrCreateMetadataForLazySymbol( const gpa = macho_file.base.comp.gpa; const mod = macho_file.base.comp.module.?; const gop = try self.lazy_syms.getOrPut(gpa, lazy_sym.getDecl(mod)); - errdefer _ = if (!gop.found_existing) self.lazy_syms.pop(); + errdefer _ = if (!gop.found_existing) self.lazy_syms.pop().?; if (!gop.found_existing) gop.value_ptr.* = .{}; const metadata: struct { symbol_index: *Symbol.Index, diff --git a/src/link/Plan9.zig b/src/link/Plan9.zig index d5900d2b16a1..8448d2b0fdc6 100644 --- a/src/link/Plan9.zig +++ b/src/link/Plan9.zig @@ -587,7 +587,7 @@ fn updateFinish(self: *Plan9, decl_index: InternPool.DeclIndex) !void { fn allocateSymbolIndex(self: *Plan9) !usize { const gpa = self.base.comp.gpa; - if (self.syms_index_free_list.popOrNull()) |i| { + if (self.syms_index_free_list.pop()) |i| { return i; } else { _ = try self.syms.addOne(gpa); @@ -596,7 +596,7 @@ fn allocateSymbolIndex(self: *Plan9) !usize { } fn allocateGotIndex(self: *Plan9) usize { - if (self.got_index_free_list.popOrNull()) |i| { + if (self.got_index_free_list.pop()) |i| { return i; } else { self.got_len += 1; @@ -1163,7 +1163,7 @@ pub fn updateExports( pub fn getOrCreateAtomForLazySymbol(self: *Plan9, sym: File.LazySymbol) !Atom.Index { const gpa = self.base.comp.gpa; const gop = try self.lazy_syms.getOrPut(gpa, sym.getDecl(self.base.comp.module.?)); - errdefer _ = if (!gop.found_existing) self.lazy_syms.pop(); + errdefer _ = if (!gop.found_existing) self.lazy_syms.pop().?; if (!gop.found_existing) gop.value_ptr.* = .{}; diff --git a/src/link/Wasm/ZigObject.zig b/src/link/Wasm/ZigObject.zig index 9bf7718d2b35..784f362845e9 100644 --- a/src/link/Wasm/ZigObject.zig +++ b/src/link/Wasm/ZigObject.zig @@ -227,7 +227,7 @@ pub fn allocateSymbol(zig_object: *ZigObject, gpa: std.mem.Allocator) !Symbol.In .index = std.math.maxInt(u32), // will be set during atom parsing .virtual_address = std.math.maxInt(u32), // will be set during atom allocation }; - if (zig_object.symbols_free_list.popOrNull()) |index| { + if (zig_object.symbols_free_list.pop()) |index| { zig_object.symbols.items[@intFromEnum(index)] = sym; return index; } @@ -401,7 +401,7 @@ fn createDataSegment( name: []const u8, alignment: InternPool.Alignment, ) !u32 { - const segment_index: u32 = if (zig_object.segment_free_list.popOrNull()) |index| + const segment_index: u32 = if (zig_object.segment_free_list.pop()) |index| index else index: { const idx: u32 = @intCast(zig_object.segment_info.items.len); @@ -732,7 +732,7 @@ pub fn getGlobalSymbol(zig_object: *ZigObject, gpa: std.mem.Allocator, name: []c sym.setGlobal(true); sym.setUndefined(true); - const sym_index = if (zig_object.symbols_free_list.popOrNull()) |index| index else blk: { + const sym_index = if (zig_object.symbols_free_list.pop()) |index| index else blk: { const index: Symbol.Index = @enumFromInt(zig_object.symbols.items.len); try zig_object.symbols.ensureUnusedCapacity(gpa, 1); zig_object.symbols.items.len += 1; @@ -1206,7 +1206,7 @@ pub fn createFunction( /// Appends a new `std.wasm.Func` to the list of functions and returns its index. fn appendFunction(zig_object: *ZigObject, gpa: std.mem.Allocator, func: std.wasm.Func) !u32 { - const index: u32 = if (zig_object.functions_free_list.popOrNull()) |idx| + const index: u32 = if (zig_object.functions_free_list.pop()) |idx| idx else idx: { const len: u32 = @intCast(zig_object.functions.items.len); diff --git a/src/link/table_section.zig b/src/link/table_section.zig index 2c70b03f4290..d79c13267a25 100644 --- a/src/link/table_section.zig +++ b/src/link/table_section.zig @@ -13,7 +13,7 @@ pub fn TableSection(comptime Entry: type) type { pub fn allocateEntry(self: *Self, allocator: Allocator, entry: Entry) Allocator.Error!Index { try self.entries.ensureUnusedCapacity(allocator, 1); const index = blk: { - if (self.free_list.popOrNull()) |index| { + if (self.free_list.pop()) |index| { log.debug(" (reusing entry index {d})", .{index}); break :blk index; } else { diff --git a/tools/process_headers.zig b/tools/process_headers.zig index 576e894f9876..2daba54f0947 100644 --- a/tools/process_headers.zig +++ b/tools/process_headers.zig @@ -381,7 +381,7 @@ pub fn main() !void { var dir_stack = std.ArrayList([]const u8).init(allocator); try dir_stack.append(target_include_dir); - while (dir_stack.popOrNull()) |full_dir_name| { + while (dir_stack.pop()) |full_dir_name| { var dir = std.fs.cwd().openDir(full_dir_name, .{ .iterate = true }) catch |err| switch (err) { error.FileNotFound => continue :search, error.AccessDenied => continue :search, @@ -462,14 +462,14 @@ pub fn main() !void { } } std.mem.sort(*Contents, contents_list.items, {}, Contents.hitCountLessThan); - const best_contents = contents_list.popOrNull().?; + const best_contents = contents_list.pop().?; if (best_contents.hit_count > 1) { // worth it to make it generic const full_path = try std.fs.path.join(allocator, &[_][]const u8{ out_dir, generic_name, path_kv.key_ptr.* }); try std.fs.cwd().makePath(std.fs.path.dirname(full_path).?); try std.fs.cwd().writeFile(full_path, best_contents.bytes); best_contents.is_generic = true; - while (contents_list.popOrNull()) |contender| { + while (contents_list.pop()) |contender| { if (contender.hit_count > 1) { const this_missed_bytes = contender.hit_count * contender.bytes.len; missed_opportunity_bytes += this_missed_bytes; diff --git a/tools/update-linux-headers.zig b/tools/update-linux-headers.zig index 91032618c977..f46c44320aa9 100644 --- a/tools/update-linux-headers.zig +++ b/tools/update-linux-headers.zig @@ -189,7 +189,7 @@ pub fn main() !void { var dir_stack = std.ArrayList([]const u8).init(arena); try dir_stack.append(target_include_dir); - while (dir_stack.popOrNull()) |full_dir_name| { + while (dir_stack.pop()) |full_dir_name| { var dir = std.fs.cwd().openDir(full_dir_name, .{ .iterate = true }) catch |err| switch (err) { error.FileNotFound => continue :search, error.AccessDenied => continue :search, @@ -270,14 +270,14 @@ pub fn main() !void { } } std.mem.sort(*Contents, contents_list.items, {}, Contents.hitCountLessThan); - const best_contents = contents_list.popOrNull().?; + const best_contents = contents_list.pop().?; if (best_contents.hit_count > 1) { // worth it to make it generic const full_path = try std.fs.path.join(arena, &[_][]const u8{ out_dir, generic_name, path_kv.key_ptr.* }); try std.fs.cwd().makePath(std.fs.path.dirname(full_path).?); try std.fs.cwd().writeFile(full_path, best_contents.bytes); best_contents.is_generic = true; - while (contents_list.popOrNull()) |contender| { + while (contents_list.pop()) |contender| { if (contender.hit_count > 1) { const this_missed_bytes = contender.hit_count * contender.bytes.len; missed_opportunity_bytes += this_missed_bytes; From d24b25e59367e9830d53490212af7926358502ac Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Tue, 2 Apr 2024 04:36:03 -0700 Subject: [PATCH 2/4] fix rebase error --- lib/std/bounded_array.zig | 2 +- src/codegen/c.zig | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/std/bounded_array.zig b/lib/std/bounded_array.zig index 5171f0634423..ebe4d7644abe 100644 --- a/lib/std/bounded_array.zig +++ b/lib/std/bounded_array.zig @@ -227,7 +227,7 @@ pub fn BoundedArrayAligned( pub fn swapRemove(self: *Self, i: usize) T { if (self.len - 1 == i) return self.pop().?; const old_item = self.get(i); - self.set(i, self.pop()); + self.set(i, self.pop().?); return old_item; } diff --git a/src/codegen/c.zig b/src/codegen/c.zig index e253ab4a6dd5..07970d2ae934 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -359,7 +359,7 @@ pub const Function = struct { fn allocAlignedLocal(f: *Function, inst: ?Air.Inst.Index, local_type: LocalType) !CValue { const result: CValue = result: { if (f.free_locals_map.getPtr(local_type)) |locals_list| { - if (locals_list.popOrNull()) |local_entry| { + if (locals_list.pop()) |local_entry| { break :result .{ .new_local = local_entry.key }; } } From 640ca5d7f7b367b9c8ff682c76a425b7866a84c9 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Tue, 2 Apr 2024 16:13:06 -0700 Subject: [PATCH 3/4] add back check from popOrNullContext in ArrayHashMap --- lib/std/array_hash_map.zig | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/std/array_hash_map.zig b/lib/std/array_hash_map.zig index 4ee269c459aa..88398ca57228 100644 --- a/lib/std/array_hash_map.zig +++ b/lib/std/array_hash_map.zig @@ -1406,6 +1406,7 @@ pub fn ArrayHashMapUnmanaged( return self.popContext(undefined); } pub fn popContext(self: *Self, ctx: Context) KV { + if (self.entries.len == 0) return null; self.pointer_stability.lock(); defer self.pointer_stability.unlock(); From 15c78d5608d01e25ff18ae148e81bb54a8582f75 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Wed, 3 Apr 2024 04:07:57 -0700 Subject: [PATCH 4/4] oops --- lib/std/array_hash_map.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/std/array_hash_map.zig b/lib/std/array_hash_map.zig index 88398ca57228..240e4181a48d 100644 --- a/lib/std/array_hash_map.zig +++ b/lib/std/array_hash_map.zig @@ -1405,7 +1405,7 @@ pub fn ArrayHashMapUnmanaged( @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call popContext instead."); return self.popContext(undefined); } - pub fn popContext(self: *Self, ctx: Context) KV { + pub fn popContext(self: *Self, ctx: Context) ?KV { if (self.entries.len == 0) return null; self.pointer_stability.lock(); defer self.pointer_stability.unlock();