authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2025-02-09 20:21:31-08:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2025-02-10 04:21:31+00:00
log91424823724de866776c8b6a999ea45f1ca9d374
tree43c794431c7e5d83dc434117cca5884d8e01c672
parent75df7e502c05e7e6a9b00a5a28854ae4a1aa8ea6
signaturebadge-check Signed by PGP key B5690EEEBB952194

std.ArrayList: popOrNull() -> pop() [v2] (#22720)


29 files changed, 162 insertions(+), 177 deletions(-)

lib/compiler/aro/aro/Preprocessor.zig+2-2
...@@ -2446,7 +2446,7 @@ pub fn expandedSlice(pp: *const Preprocessor, tok: anytype) []const u8 {...@@ -2446,7 +2446,7 @@ pub fn expandedSlice(pp: *const Preprocessor, tok: anytype) []const u8 {
24462446
2447/// Concat two tokens and add the result to pp.generated2447/// Concat two tokens and add the result to pp.generated
2448fn pasteTokens(pp: *Preprocessor, lhs_toks: *ExpandBuf, rhs_toks: []const TokenWithExpansionLocs) Error!void {2448fn pasteTokens(pp: *Preprocessor, lhs_toks: *ExpandBuf, rhs_toks: []const TokenWithExpansionLocs) Error!void {
2449 const lhs = while (lhs_toks.popOrNull()) |lhs| {2449 const lhs = while (lhs_toks.pop()) |lhs| {
2450 if ((pp.comp.langopts.preserve_comments_in_macros and lhs.id == .comment) or2450 if ((pp.comp.langopts.preserve_comments_in_macros and lhs.id == .comment) or
2451 (lhs.id != .macro_ws and lhs.id != .comment))2451 (lhs.id != .macro_ws and lhs.id != .comment))
2452 break lhs;2452 break lhs;
...@@ -2676,7 +2676,7 @@ fn defineFn(pp: *Preprocessor, tokenizer: *Tokenizer, define_tok: RawToken, macr...@@ -2676,7 +2676,7 @@ fn defineFn(pp: *Preprocessor, tokenizer: *Tokenizer, define_tok: RawToken, macr
2676 tok = tokenizer.nextNoWS();2676 tok = tokenizer.nextNoWS();
2677 if (tok.id == .ellipsis) {2677 if (tok.id == .ellipsis) {
2678 try pp.err(tok, .gnu_va_macro);2678 try pp.err(tok, .gnu_va_macro);
2679 gnu_var_args = params.pop();2679 gnu_var_args = params.pop().?;
2680 const r_paren = tokenizer.nextNoWS();2680 const r_paren = tokenizer.nextNoWS();
2681 if (r_paren.id != .r_paren) {2681 if (r_paren.id != .r_paren) {
2682 try pp.err(r_paren, .missing_paren_param_list);2682 try pp.err(r_paren, .missing_paren_param_list);
lib/compiler/aro/aro/pragmas/gcc.zig+1-1
...@@ -103,7 +103,7 @@ fn diagnosticHandler(self: *GCC, pp: *Preprocessor, start_idx: TokenIndex) Pragm...@@ -103,7 +103,7 @@ fn diagnosticHandler(self: *GCC, pp: *Preprocessor, start_idx: TokenIndex) Pragm
103 try pp.comp.diagnostics.set(str[2..], new_kind);103 try pp.comp.diagnostics.set(str[2..], new_kind);
104 },104 },
105 .push => try self.options_stack.append(pp.comp.gpa, pp.comp.diagnostics.options),105 .push => try self.options_stack.append(pp.comp.gpa, pp.comp.diagnostics.options),
106 .pop => pp.comp.diagnostics.options = self.options_stack.popOrNull() orelse self.original_options,106 .pop => pp.comp.diagnostics.options = self.options_stack.pop() orelse self.original_options,
107 }107 }
108}108}
109109
lib/compiler/aro/aro/pragmas/pack.zig+1-1
...@@ -149,7 +149,7 @@ fn pop(pack: *Pack, p: *Parser, maybe_label: ?[]const u8) void {...@@ -149,7 +149,7 @@ fn pop(pack: *Pack, p: *Parser, maybe_label: ?[]const u8) void {
149 }149 }
150 }150 }
151 } else {151 } else {
152 const prev = pack.stack.popOrNull() orelse {152 const prev = pack.stack.pop() orelse {
153 p.pragma_pack = 2;153 p.pragma_pack = 2;
154 return;154 return;
155 };155 };
lib/compiler/build_runner.zig+1-1
...@@ -1190,7 +1190,7 @@ pub fn printErrorMessages(...@@ -1190,7 +1190,7 @@ pub fn printErrorMessages(
1190 const ttyconf = options.ttyconf;1190 const ttyconf = options.ttyconf;
1191 try ttyconf.setColor(stderr, .dim);1191 try ttyconf.setColor(stderr, .dim);
1192 var indent: usize = 0;1192 var indent: usize = 0;
1193 while (step_stack.popOrNull()) |s| : (indent += 1) {1193 while (step_stack.pop()) |s| : (indent += 1) {
1194 if (indent > 0) {1194 if (indent > 0) {
1195 try stderr.writer().writeByteNTimes(' ', (indent - 1) * 3);1195 try stderr.writer().writeByteNTimes(' ', (indent - 1) * 3);
1196 try printChildNodePrefix(stderr, ttyconf);1196 try printChildNodePrefix(stderr, ttyconf);
lib/docs/wasm/markdown/Parser.zig+1-1
...@@ -816,7 +816,7 @@ fn isThematicBreak(line: []const u8) bool {...@@ -816,7 +816,7 @@ fn isThematicBreak(line: []const u8) bool {
816}816}
817817
818fn closeLastBlock(p: *Parser) !void {818fn closeLastBlock(p: *Parser) !void {
819 const b = p.pending_blocks.pop();819 const b = p.pending_blocks.pop().?;
820 const node = switch (b.tag) {820 const node = switch (b.tag) {
821 .list => list: {821 .list => list: {
822 assert(b.string_start == p.scratch_string.items.len);822 assert(b.string_start == p.scratch_string.items.len);
lib/std/Build/Step/ConfigHeader.zig+1-1
...@@ -616,7 +616,7 @@ fn expand_variables_cmake(...@@ -616,7 +616,7 @@ fn expand_variables_cmake(
616 // no open bracket, preserve as a literal616 // no open bracket, preserve as a literal
617 break :blk;617 break :blk;
618 }618 }
619 const open_pos = var_stack.pop();619 const open_pos = var_stack.pop().?;
620 if (source_offset == open_pos.source) {620 if (source_offset == open_pos.source) {
621 source_offset += open_var.len;621 source_offset += open_var.len;
622 }622 }
lib/std/array_list.zig+16-31
...@@ -289,10 +289,10 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -289,10 +289,10 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
289 /// Asserts that the list is not empty.289 /// Asserts that the list is not empty.
290 /// Asserts that the index is in bounds.290 /// Asserts that the index is in bounds.
291 pub fn swapRemove(self: *Self, i: usize) T {291 pub fn swapRemove(self: *Self, i: usize) T {
292 if (self.items.len - 1 == i) return self.pop();292 if (self.items.len - 1 == i) return self.pop().?;
293293
294 const old_item = self.items[i];294 const old_item = self.items[i];
295 self.items[i] = self.pop();295 self.items[i] = self.pop().?;
296 return old_item;296 return old_item;
297 }297 }
298298
...@@ -555,23 +555,15 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -555,23 +555,15 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
555 return self.items[prev_len..][0..n];555 return self.items[prev_len..][0..n];
556 }556 }
557557
558 /// Remove and return the last element from the list.558 /// Remove and return the last element from the list, or return `null` if list is empty.
559 /// Invalidates element pointers to the removed element.559 /// Invalidates element pointers to the removed element, if any.
560 /// Asserts that the list is not empty.560 pub fn pop(self: *Self) ?T {
561 pub fn pop(self: *Self) T {561 if (self.items.len == 0) return null;
562 const val = self.items[self.items.len - 1];562 const val = self.items[self.items.len - 1];
563 self.items.len -= 1;563 self.items.len -= 1;
564 return val;564 return val;
565 }565 }
566566
567 /// Remove and return the last element from the list, or
568 /// return `null` if list is empty.
569 /// Invalidates element pointers to the removed element, if any.
570 pub fn popOrNull(self: *Self) ?T {
571 if (self.items.len == 0) return null;
572 return self.pop();
573 }
574
575 /// Returns a slice of all the items plus the extra capacity, whose memory567 /// Returns a slice of all the items plus the extra capacity, whose memory
576 /// contents are `undefined`.568 /// contents are `undefined`.
577 pub fn allocatedSlice(self: Self) Slice {569 pub fn allocatedSlice(self: Self) Slice {
...@@ -897,10 +889,10 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ...@@ -897,10 +889,10 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
897 /// Asserts that the list is not empty.889 /// Asserts that the list is not empty.
898 /// Asserts that the index is in bounds.890 /// Asserts that the index is in bounds.
899 pub fn swapRemove(self: *Self, i: usize) T {891 pub fn swapRemove(self: *Self, i: usize) T {
900 if (self.items.len - 1 == i) return self.pop();892 if (self.items.len - 1 == i) return self.pop().?;
901893
902 const old_item = self.items[i];894 const old_item = self.items[i];
903 self.items[i] = self.pop();895 self.items[i] = self.pop().?;
904 return old_item;896 return old_item;
905 }897 }
906898
...@@ -1190,22 +1182,15 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ...@@ -1190,22 +1182,15 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
1190 }1182 }
11911183
1192 /// Remove and return the last element from the list.1184 /// Remove and return the last element from the list.
1185 /// If the list is empty, returns `null`.
1193 /// Invalidates pointers to last element.1186 /// Invalidates pointers to last element.
1194 /// Asserts that the list is not empty.1187 pub fn pop(self: *Self) ?T {
1195 pub fn pop(self: *Self) T {1188 if (self.items.len == 0) return null;
1196 const val = self.items[self.items.len - 1];1189 const val = self.items[self.items.len - 1];
1197 self.items.len -= 1;1190 self.items.len -= 1;
1198 return val;1191 return val;
1199 }1192 }
12001193
1201 /// Remove and return the last element from the list.
1202 /// If the list is empty, returns `null`.
1203 /// Invalidates pointers to last element.
1204 pub fn popOrNull(self: *Self) ?T {
1205 if (self.items.len == 0) return null;
1206 return self.pop();
1207 }
1208
1209 /// Returns a slice of all the items plus the extra capacity, whose memory1194 /// Returns a slice of all the items plus the extra capacity, whose memory
1210 /// contents are `undefined`.1195 /// contents are `undefined`.
1211 pub fn allocatedSlice(self: Self) Slice {1196 pub fn allocatedSlice(self: Self) Slice {
...@@ -2184,7 +2169,7 @@ test "ArrayList(u0)" {...@@ -2184,7 +2169,7 @@ test "ArrayList(u0)" {
2184 try testing.expectEqual(count, 3);2169 try testing.expectEqual(count, 3);
2185}2170}
21862171
2187test "ArrayList(?u32).popOrNull()" {2172test "ArrayList(?u32).pop()" {
2188 const a = testing.allocator;2173 const a = testing.allocator;
21892174
2190 var list = ArrayList(?u32).init(a);2175 var list = ArrayList(?u32).init(a);
...@@ -2195,10 +2180,10 @@ test "ArrayList(?u32).popOrNull()" {...@@ -2195,10 +2180,10 @@ test "ArrayList(?u32).popOrNull()" {
2195 try list.append(2);2180 try list.append(2);
2196 try testing.expectEqual(list.items.len, 3);2181 try testing.expectEqual(list.items.len, 3);
21972182
2198 try testing.expect(list.popOrNull().? == @as(u32, 2));2183 try testing.expect(list.pop().? == @as(u32, 2));
2199 try testing.expect(list.popOrNull().? == @as(u32, 1));2184 try testing.expect(list.pop().? == @as(u32, 1));
2200 try testing.expect(list.popOrNull().? == null);2185 try testing.expect(list.pop().? == null);
2201 try testing.expect(list.popOrNull() == null);2186 try testing.expect(list.pop() == null);
2202}2187}
22032188
2204test "ArrayList(u32).getLast()" {2189test "ArrayList(u32).getLast()" {
lib/std/debug/Dwarf/expression.zig+68-68
...@@ -527,14 +527,14 @@ pub fn StackMachine(comptime options: Options) type {...@@ -527,14 +527,14 @@ pub fn StackMachine(comptime options: Options) type {
527 },527 },
528 OP.@"and" => {528 OP.@"and" => {
529 if (self.stack.items.len < 2) return error.InvalidExpression;529 if (self.stack.items.len < 2) return error.InvalidExpression;
530 const a = try self.stack.pop().asIntegral();530 const a = try self.stack.pop().?.asIntegral();
531 self.stack.items[self.stack.items.len - 1] = .{531 self.stack.items[self.stack.items.len - 1] = .{
532 .generic = a & try self.stack.items[self.stack.items.len - 1].asIntegral(),532 .generic = a & try self.stack.items[self.stack.items.len - 1].asIntegral(),
533 };533 };
534 },534 },
535 OP.div => {535 OP.div => {
536 if (self.stack.items.len < 2) return error.InvalidExpression;536 if (self.stack.items.len < 2) return error.InvalidExpression;
537 const a: isize = @bitCast(try self.stack.pop().asIntegral());537 const a: isize = @bitCast(try self.stack.pop().?.asIntegral());
538 const b: isize = @bitCast(try self.stack.items[self.stack.items.len - 1].asIntegral());538 const b: isize = @bitCast(try self.stack.items[self.stack.items.len - 1].asIntegral());
539 self.stack.items[self.stack.items.len - 1] = .{539 self.stack.items[self.stack.items.len - 1] = .{
540 .generic = @bitCast(try std.math.divTrunc(isize, b, a)),540 .generic = @bitCast(try std.math.divTrunc(isize, b, a)),
...@@ -542,14 +542,14 @@ pub fn StackMachine(comptime options: Options) type {...@@ -542,14 +542,14 @@ pub fn StackMachine(comptime options: Options) type {
542 },542 },
543 OP.minus => {543 OP.minus => {
544 if (self.stack.items.len < 2) return error.InvalidExpression;544 if (self.stack.items.len < 2) return error.InvalidExpression;
545 const b = try self.stack.pop().asIntegral();545 const b = try self.stack.pop().?.asIntegral();
546 self.stack.items[self.stack.items.len - 1] = .{546 self.stack.items[self.stack.items.len - 1] = .{
547 .generic = try std.math.sub(addr_type, try self.stack.items[self.stack.items.len - 1].asIntegral(), b),547 .generic = try std.math.sub(addr_type, try self.stack.items[self.stack.items.len - 1].asIntegral(), b),
548 };548 };
549 },549 },
550 OP.mod => {550 OP.mod => {
551 if (self.stack.items.len < 2) return error.InvalidExpression;551 if (self.stack.items.len < 2) return error.InvalidExpression;
552 const a: isize = @bitCast(try self.stack.pop().asIntegral());552 const a: isize = @bitCast(try self.stack.pop().?.asIntegral());
553 const b: isize = @bitCast(try self.stack.items[self.stack.items.len - 1].asIntegral());553 const b: isize = @bitCast(try self.stack.items[self.stack.items.len - 1].asIntegral());
554 self.stack.items[self.stack.items.len - 1] = .{554 self.stack.items[self.stack.items.len - 1] = .{
555 .generic = @bitCast(@mod(b, a)),555 .generic = @bitCast(@mod(b, a)),
...@@ -557,7 +557,7 @@ pub fn StackMachine(comptime options: Options) type {...@@ -557,7 +557,7 @@ pub fn StackMachine(comptime options: Options) type {
557 },557 },
558 OP.mul => {558 OP.mul => {
559 if (self.stack.items.len < 2) return error.InvalidExpression;559 if (self.stack.items.len < 2) return error.InvalidExpression;
560 const a: isize = @bitCast(try self.stack.pop().asIntegral());560 const a: isize = @bitCast(try self.stack.pop().?.asIntegral());
561 const b: isize = @bitCast(try self.stack.items[self.stack.items.len - 1].asIntegral());561 const b: isize = @bitCast(try self.stack.items[self.stack.items.len - 1].asIntegral());
562 self.stack.items[self.stack.items.len - 1] = .{562 self.stack.items[self.stack.items.len - 1] = .{
563 .generic = @bitCast(@mulWithOverflow(a, b)[0]),563 .generic = @bitCast(@mulWithOverflow(a, b)[0]),
...@@ -581,14 +581,14 @@ pub fn StackMachine(comptime options: Options) type {...@@ -581,14 +581,14 @@ pub fn StackMachine(comptime options: Options) type {
581 },581 },
582 OP.@"or" => {582 OP.@"or" => {
583 if (self.stack.items.len < 2) return error.InvalidExpression;583 if (self.stack.items.len < 2) return error.InvalidExpression;
584 const a = try self.stack.pop().asIntegral();584 const a = try self.stack.pop().?.asIntegral();
585 self.stack.items[self.stack.items.len - 1] = .{585 self.stack.items[self.stack.items.len - 1] = .{
586 .generic = a | try self.stack.items[self.stack.items.len - 1].asIntegral(),586 .generic = a | try self.stack.items[self.stack.items.len - 1].asIntegral(),
587 };587 };
588 },588 },
589 OP.plus => {589 OP.plus => {
590 if (self.stack.items.len < 2) return error.InvalidExpression;590 if (self.stack.items.len < 2) return error.InvalidExpression;
591 const b = try self.stack.pop().asIntegral();591 const b = try self.stack.pop().?.asIntegral();
592 self.stack.items[self.stack.items.len - 1] = .{592 self.stack.items[self.stack.items.len - 1] = .{
593 .generic = try std.math.add(addr_type, try self.stack.items[self.stack.items.len - 1].asIntegral(), b),593 .generic = try std.math.add(addr_type, try self.stack.items[self.stack.items.len - 1].asIntegral(), b),
594 };594 };
...@@ -602,7 +602,7 @@ pub fn StackMachine(comptime options: Options) type {...@@ -602,7 +602,7 @@ pub fn StackMachine(comptime options: Options) type {
602 },602 },
603 OP.shl => {603 OP.shl => {
604 if (self.stack.items.len < 2) return error.InvalidExpression;604 if (self.stack.items.len < 2) return error.InvalidExpression;
605 const a = try self.stack.pop().asIntegral();605 const a = try self.stack.pop().?.asIntegral();
606 const b = try self.stack.items[self.stack.items.len - 1].asIntegral();606 const b = try self.stack.items[self.stack.items.len - 1].asIntegral();
607 self.stack.items[self.stack.items.len - 1] = .{607 self.stack.items[self.stack.items.len - 1] = .{
608 .generic = std.math.shl(usize, b, a),608 .generic = std.math.shl(usize, b, a),
...@@ -610,7 +610,7 @@ pub fn StackMachine(comptime options: Options) type {...@@ -610,7 +610,7 @@ pub fn StackMachine(comptime options: Options) type {
610 },610 },
611 OP.shr => {611 OP.shr => {
612 if (self.stack.items.len < 2) return error.InvalidExpression;612 if (self.stack.items.len < 2) return error.InvalidExpression;
613 const a = try self.stack.pop().asIntegral();613 const a = try self.stack.pop().?.asIntegral();
614 const b = try self.stack.items[self.stack.items.len - 1].asIntegral();614 const b = try self.stack.items[self.stack.items.len - 1].asIntegral();
615 self.stack.items[self.stack.items.len - 1] = .{615 self.stack.items[self.stack.items.len - 1] = .{
616 .generic = std.math.shr(usize, b, a),616 .generic = std.math.shr(usize, b, a),
...@@ -618,7 +618,7 @@ pub fn StackMachine(comptime options: Options) type {...@@ -618,7 +618,7 @@ pub fn StackMachine(comptime options: Options) type {
618 },618 },
619 OP.shra => {619 OP.shra => {
620 if (self.stack.items.len < 2) return error.InvalidExpression;620 if (self.stack.items.len < 2) return error.InvalidExpression;
621 const a = try self.stack.pop().asIntegral();621 const a = try self.stack.pop().?.asIntegral();
622 const b: isize = @bitCast(try self.stack.items[self.stack.items.len - 1].asIntegral());622 const b: isize = @bitCast(try self.stack.items[self.stack.items.len - 1].asIntegral());
623 self.stack.items[self.stack.items.len - 1] = .{623 self.stack.items[self.stack.items.len - 1] = .{
624 .generic = @bitCast(std.math.shr(isize, b, a)),624 .generic = @bitCast(std.math.shr(isize, b, a)),
...@@ -626,7 +626,7 @@ pub fn StackMachine(comptime options: Options) type {...@@ -626,7 +626,7 @@ pub fn StackMachine(comptime options: Options) type {
626 },626 },
627 OP.xor => {627 OP.xor => {
628 if (self.stack.items.len < 2) return error.InvalidExpression;628 if (self.stack.items.len < 2) return error.InvalidExpression;
629 const a = try self.stack.pop().asIntegral();629 const a = try self.stack.pop().?.asIntegral();
630 self.stack.items[self.stack.items.len - 1] = .{630 self.stack.items[self.stack.items.len - 1] = .{
631 .generic = a ^ try self.stack.items[self.stack.items.len - 1].asIntegral(),631 .generic = a ^ try self.stack.items[self.stack.items.len - 1].asIntegral(),
632 };632 };
...@@ -641,7 +641,7 @@ pub fn StackMachine(comptime options: Options) type {...@@ -641,7 +641,7 @@ pub fn StackMachine(comptime options: Options) type {
641 OP.ne,641 OP.ne,
642 => {642 => {
643 if (self.stack.items.len < 2) return error.InvalidExpression;643 if (self.stack.items.len < 2) return error.InvalidExpression;
644 const a = self.stack.pop();644 const a = self.stack.pop().?;
645 const b = self.stack.items[self.stack.items.len - 1];645 const b = self.stack.items[self.stack.items.len - 1];
646646
647 if (a == .generic and b == .generic) {647 if (a == .generic and b == .generic) {
...@@ -667,7 +667,7 @@ pub fn StackMachine(comptime options: Options) type {...@@ -667,7 +667,7 @@ pub fn StackMachine(comptime options: Options) type {
667 const branch_offset = operand.?.branch_offset;667 const branch_offset = operand.?.branch_offset;
668 const condition = if (opcode == OP.bra) blk: {668 const condition = if (opcode == OP.bra) blk: {
669 if (self.stack.items.len == 0) return error.InvalidExpression;669 if (self.stack.items.len == 0) return error.InvalidExpression;
670 break :blk try self.stack.pop().asIntegral() != 0;670 break :blk try self.stack.pop().?.asIntegral() != 0;
671 } else true;671 } else true;
672672
673 if (condition) {673 if (condition) {
...@@ -1080,7 +1080,7 @@ test "DWARF expressions" {...@@ -1080,7 +1080,7 @@ test "DWARF expressions" {
10801080
1081 for (0..32) |i| {1081 for (0..32) |i| {
1082 const expected = 31 - i;1082 const expected = 31 - i;
1083 try testing.expectEqual(expected, stack_machine.stack.popOrNull().?.generic);1083 try testing.expectEqual(expected, stack_machine.stack.pop().?.generic);
1084 }1084 }
1085 }1085 }
10861086
...@@ -1141,7 +1141,7 @@ test "DWARF expressions" {...@@ -1141,7 +1141,7 @@ test "DWARF expressions" {
11411141
1142 _ = try stack_machine.run(program.items, allocator, context, 0);1142 _ = try stack_machine.run(program.items, allocator, context, 0);
11431143
1144 const const_type = stack_machine.stack.popOrNull().?.const_type;1144 const const_type = stack_machine.stack.pop().?.const_type;
1145 try testing.expectEqual(die_offset, const_type.type_offset);1145 try testing.expectEqual(die_offset, const_type.type_offset);
1146 try testing.expectEqualSlices(u8, type_bytes, const_type.value_bytes);1146 try testing.expectEqualSlices(u8, type_bytes, const_type.value_bytes);
11471147
...@@ -1162,7 +1162,7 @@ test "DWARF expressions" {...@@ -1162,7 +1162,7 @@ test "DWARF expressions" {
1162 };1162 };
11631163
1164 inline for (expected) |e| {1164 inline for (expected) |e| {
1165 try testing.expectEqual(@as(e[0], e[1]), @as(e[2], @bitCast(stack_machine.stack.popOrNull().?.generic)));1165 try testing.expectEqual(@as(e[0], e[1]), @as(e[2], @bitCast(stack_machine.stack.pop().?.generic)));
1166 }1166 }
1167 }1167 }
11681168
...@@ -1199,14 +1199,14 @@ test "DWARF expressions" {...@@ -1199,14 +1199,14 @@ test "DWARF expressions" {
11991199
1200 _ = try stack_machine.run(program.items, allocator, context, 0);1200 _ = try stack_machine.run(program.items, allocator, context, 0);
12011201
1202 const regval_type = stack_machine.stack.popOrNull().?.regval_type;1202 const regval_type = stack_machine.stack.pop().?.regval_type;
1203 try testing.expectEqual(@as(usize, 400), regval_type.type_offset);1203 try testing.expectEqual(@as(usize, 400), regval_type.type_offset);
1204 try testing.expectEqual(@as(u8, @sizeOf(usize)), regval_type.type_size);1204 try testing.expectEqual(@as(u8, @sizeOf(usize)), regval_type.type_size);
1205 try testing.expectEqual(@as(usize, 0xee), regval_type.value);1205 try testing.expectEqual(@as(usize, 0xee), regval_type.value);
12061206
1207 try testing.expectEqual(@as(usize, 303), stack_machine.stack.popOrNull().?.generic);1207 try testing.expectEqual(@as(usize, 303), stack_machine.stack.pop().?.generic);
1208 try testing.expectEqual(@as(usize, 202), stack_machine.stack.popOrNull().?.generic);1208 try testing.expectEqual(@as(usize, 202), stack_machine.stack.pop().?.generic);
1209 try testing.expectEqual(@as(usize, 101), stack_machine.stack.popOrNull().?.generic);1209 try testing.expectEqual(@as(usize, 101), stack_machine.stack.pop().?.generic);
1210 } else |err| {1210 } else |err| {
1211 switch (err) {1211 switch (err) {
1212 error.UnimplementedArch,1212 error.UnimplementedArch,
...@@ -1227,15 +1227,15 @@ test "DWARF expressions" {...@@ -1227,15 +1227,15 @@ test "DWARF expressions" {
1227 try b.writeConst(writer, u8, 1);1227 try b.writeConst(writer, u8, 1);
1228 try b.writeOpcode(writer, OP.dup);1228 try b.writeOpcode(writer, OP.dup);
1229 _ = try stack_machine.run(program.items, allocator, context, null);1229 _ = try stack_machine.run(program.items, allocator, context, null);
1230 try testing.expectEqual(@as(usize, 1), stack_machine.stack.popOrNull().?.generic);1230 try testing.expectEqual(@as(usize, 1), stack_machine.stack.pop().?.generic);
1231 try testing.expectEqual(@as(usize, 1), stack_machine.stack.popOrNull().?.generic);1231 try testing.expectEqual(@as(usize, 1), stack_machine.stack.pop().?.generic);
12321232
1233 stack_machine.reset();1233 stack_machine.reset();
1234 program.clearRetainingCapacity();1234 program.clearRetainingCapacity();
1235 try b.writeConst(writer, u8, 1);1235 try b.writeConst(writer, u8, 1);
1236 try b.writeOpcode(writer, OP.drop);1236 try b.writeOpcode(writer, OP.drop);
1237 _ = try stack_machine.run(program.items, allocator, context, null);1237 _ = try stack_machine.run(program.items, allocator, context, null);
1238 try testing.expect(stack_machine.stack.popOrNull() == null);1238 try testing.expect(stack_machine.stack.pop() == null);
12391239
1240 stack_machine.reset();1240 stack_machine.reset();
1241 program.clearRetainingCapacity();1241 program.clearRetainingCapacity();
...@@ -1244,7 +1244,7 @@ test "DWARF expressions" {...@@ -1244,7 +1244,7 @@ test "DWARF expressions" {
1244 try b.writeConst(writer, u8, 6);1244 try b.writeConst(writer, u8, 6);
1245 try b.writePick(writer, 2);1245 try b.writePick(writer, 2);
1246 _ = try stack_machine.run(program.items, allocator, context, null);1246 _ = try stack_machine.run(program.items, allocator, context, null);
1247 try testing.expectEqual(@as(usize, 4), stack_machine.stack.popOrNull().?.generic);1247 try testing.expectEqual(@as(usize, 4), stack_machine.stack.pop().?.generic);
12481248
1249 stack_machine.reset();1249 stack_machine.reset();
1250 program.clearRetainingCapacity();1250 program.clearRetainingCapacity();
...@@ -1253,7 +1253,7 @@ test "DWARF expressions" {...@@ -1253,7 +1253,7 @@ test "DWARF expressions" {
1253 try b.writeConst(writer, u8, 6);1253 try b.writeConst(writer, u8, 6);
1254 try b.writeOpcode(writer, OP.over);1254 try b.writeOpcode(writer, OP.over);
1255 _ = try stack_machine.run(program.items, allocator, context, null);1255 _ = try stack_machine.run(program.items, allocator, context, null);
1256 try testing.expectEqual(@as(usize, 5), stack_machine.stack.popOrNull().?.generic);1256 try testing.expectEqual(@as(usize, 5), stack_machine.stack.pop().?.generic);
12571257
1258 stack_machine.reset();1258 stack_machine.reset();
1259 program.clearRetainingCapacity();1259 program.clearRetainingCapacity();
...@@ -1261,8 +1261,8 @@ test "DWARF expressions" {...@@ -1261,8 +1261,8 @@ test "DWARF expressions" {
1261 try b.writeConst(writer, u8, 6);1261 try b.writeConst(writer, u8, 6);
1262 try b.writeOpcode(writer, OP.swap);1262 try b.writeOpcode(writer, OP.swap);
1263 _ = try stack_machine.run(program.items, allocator, context, null);1263 _ = try stack_machine.run(program.items, allocator, context, null);
1264 try testing.expectEqual(@as(usize, 5), stack_machine.stack.popOrNull().?.generic);1264 try testing.expectEqual(@as(usize, 5), stack_machine.stack.pop().?.generic);
1265 try testing.expectEqual(@as(usize, 6), stack_machine.stack.popOrNull().?.generic);1265 try testing.expectEqual(@as(usize, 6), stack_machine.stack.pop().?.generic);
12661266
1267 stack_machine.reset();1267 stack_machine.reset();
1268 program.clearRetainingCapacity();1268 program.clearRetainingCapacity();
...@@ -1271,9 +1271,9 @@ test "DWARF expressions" {...@@ -1271,9 +1271,9 @@ test "DWARF expressions" {
1271 try b.writeConst(writer, u8, 6);1271 try b.writeConst(writer, u8, 6);
1272 try b.writeOpcode(writer, OP.rot);1272 try b.writeOpcode(writer, OP.rot);
1273 _ = try stack_machine.run(program.items, allocator, context, null);1273 _ = try stack_machine.run(program.items, allocator, context, null);
1274 try testing.expectEqual(@as(usize, 5), stack_machine.stack.popOrNull().?.generic);1274 try testing.expectEqual(@as(usize, 5), stack_machine.stack.pop().?.generic);
1275 try testing.expectEqual(@as(usize, 4), stack_machine.stack.popOrNull().?.generic);1275 try testing.expectEqual(@as(usize, 4), stack_machine.stack.pop().?.generic);
1276 try testing.expectEqual(@as(usize, 6), stack_machine.stack.popOrNull().?.generic);1276 try testing.expectEqual(@as(usize, 6), stack_machine.stack.pop().?.generic);
12771277
1278 const deref_target: usize = @truncate(0xffeeffee_ffeeffee);1278 const deref_target: usize = @truncate(0xffeeffee_ffeeffee);
12791279
...@@ -1282,7 +1282,7 @@ test "DWARF expressions" {...@@ -1282,7 +1282,7 @@ test "DWARF expressions" {
1282 try b.writeAddr(writer, @intFromPtr(&deref_target));1282 try b.writeAddr(writer, @intFromPtr(&deref_target));
1283 try b.writeOpcode(writer, OP.deref);1283 try b.writeOpcode(writer, OP.deref);
1284 _ = try stack_machine.run(program.items, allocator, context, null);1284 _ = try stack_machine.run(program.items, allocator, context, null);
1285 try testing.expectEqual(deref_target, stack_machine.stack.popOrNull().?.generic);1285 try testing.expectEqual(deref_target, stack_machine.stack.pop().?.generic);
12861286
1287 stack_machine.reset();1287 stack_machine.reset();
1288 program.clearRetainingCapacity();1288 program.clearRetainingCapacity();
...@@ -1290,14 +1290,14 @@ test "DWARF expressions" {...@@ -1290,14 +1290,14 @@ test "DWARF expressions" {
1290 try b.writeAddr(writer, @intFromPtr(&deref_target));1290 try b.writeAddr(writer, @intFromPtr(&deref_target));
1291 try b.writeOpcode(writer, OP.xderef);1291 try b.writeOpcode(writer, OP.xderef);
1292 _ = try stack_machine.run(program.items, allocator, context, null);1292 _ = try stack_machine.run(program.items, allocator, context, null);
1293 try testing.expectEqual(deref_target, stack_machine.stack.popOrNull().?.generic);1293 try testing.expectEqual(deref_target, stack_machine.stack.pop().?.generic);
12941294
1295 stack_machine.reset();1295 stack_machine.reset();
1296 program.clearRetainingCapacity();1296 program.clearRetainingCapacity();
1297 try b.writeAddr(writer, @intFromPtr(&deref_target));1297 try b.writeAddr(writer, @intFromPtr(&deref_target));
1298 try b.writeDerefSize(writer, 1);1298 try b.writeDerefSize(writer, 1);
1299 _ = try stack_machine.run(program.items, allocator, context, null);1299 _ = try stack_machine.run(program.items, allocator, context, null);
1300 try testing.expectEqual(@as(usize, @as(*const u8, @ptrCast(&deref_target)).*), stack_machine.stack.popOrNull().?.generic);1300 try testing.expectEqual(@as(usize, @as(*const u8, @ptrCast(&deref_target)).*), stack_machine.stack.pop().?.generic);
13011301
1302 stack_machine.reset();1302 stack_machine.reset();
1303 program.clearRetainingCapacity();1303 program.clearRetainingCapacity();
...@@ -1305,7 +1305,7 @@ test "DWARF expressions" {...@@ -1305,7 +1305,7 @@ test "DWARF expressions" {
1305 try b.writeAddr(writer, @intFromPtr(&deref_target));1305 try b.writeAddr(writer, @intFromPtr(&deref_target));
1306 try b.writeXDerefSize(writer, 1);1306 try b.writeXDerefSize(writer, 1);
1307 _ = try stack_machine.run(program.items, allocator, context, null);1307 _ = try stack_machine.run(program.items, allocator, context, null);
1308 try testing.expectEqual(@as(usize, @as(*const u8, @ptrCast(&deref_target)).*), stack_machine.stack.popOrNull().?.generic);1308 try testing.expectEqual(@as(usize, @as(*const u8, @ptrCast(&deref_target)).*), stack_machine.stack.pop().?.generic);
13091309
1310 const type_offset: usize = @truncate(0xaabbaabb_aabbaabb);1310 const type_offset: usize = @truncate(0xaabbaabb_aabbaabb);
13111311
...@@ -1314,7 +1314,7 @@ test "DWARF expressions" {...@@ -1314,7 +1314,7 @@ test "DWARF expressions" {
1314 try b.writeAddr(writer, @intFromPtr(&deref_target));1314 try b.writeAddr(writer, @intFromPtr(&deref_target));
1315 try b.writeDerefType(writer, 1, type_offset);1315 try b.writeDerefType(writer, 1, type_offset);
1316 _ = try stack_machine.run(program.items, allocator, context, null);1316 _ = try stack_machine.run(program.items, allocator, context, null);
1317 const deref_type = stack_machine.stack.popOrNull().?.regval_type;1317 const deref_type = stack_machine.stack.pop().?.regval_type;
1318 try testing.expectEqual(type_offset, deref_type.type_offset);1318 try testing.expectEqual(type_offset, deref_type.type_offset);
1319 try testing.expectEqual(@as(u8, 1), deref_type.type_size);1319 try testing.expectEqual(@as(u8, 1), deref_type.type_size);
1320 try testing.expectEqual(@as(usize, @as(*const u8, @ptrCast(&deref_target)).*), deref_type.value);1320 try testing.expectEqual(@as(usize, @as(*const u8, @ptrCast(&deref_target)).*), deref_type.value);
...@@ -1325,7 +1325,7 @@ test "DWARF expressions" {...@@ -1325,7 +1325,7 @@ test "DWARF expressions" {
1325 try b.writeAddr(writer, @intFromPtr(&deref_target));1325 try b.writeAddr(writer, @intFromPtr(&deref_target));
1326 try b.writeXDerefType(writer, 1, type_offset);1326 try b.writeXDerefType(writer, 1, type_offset);
1327 _ = try stack_machine.run(program.items, allocator, context, null);1327 _ = try stack_machine.run(program.items, allocator, context, null);
1328 const xderef_type = stack_machine.stack.popOrNull().?.regval_type;1328 const xderef_type = stack_machine.stack.pop().?.regval_type;
1329 try testing.expectEqual(type_offset, xderef_type.type_offset);1329 try testing.expectEqual(type_offset, xderef_type.type_offset);
1330 try testing.expectEqual(@as(u8, 1), xderef_type.type_size);1330 try testing.expectEqual(@as(u8, 1), xderef_type.type_size);
1331 try testing.expectEqual(@as(usize, @as(*const u8, @ptrCast(&deref_target)).*), xderef_type.value);1331 try testing.expectEqual(@as(usize, @as(*const u8, @ptrCast(&deref_target)).*), xderef_type.value);
...@@ -1336,7 +1336,7 @@ test "DWARF expressions" {...@@ -1336,7 +1336,7 @@ test "DWARF expressions" {
1336 program.clearRetainingCapacity();1336 program.clearRetainingCapacity();
1337 try b.writeOpcode(writer, OP.push_object_address);1337 try b.writeOpcode(writer, OP.push_object_address);
1338 _ = try stack_machine.run(program.items, allocator, context, null);1338 _ = try stack_machine.run(program.items, allocator, context, null);
1339 try testing.expectEqual(@as(usize, @intFromPtr(context.object_address.?)), stack_machine.stack.popOrNull().?.generic);1339 try testing.expectEqual(@as(usize, @intFromPtr(context.object_address.?)), stack_machine.stack.pop().?.generic);
13401340
1341 // TODO: Test OP.form_tls_address1341 // TODO: Test OP.form_tls_address
13421342
...@@ -1346,7 +1346,7 @@ test "DWARF expressions" {...@@ -1346,7 +1346,7 @@ test "DWARF expressions" {
1346 program.clearRetainingCapacity();1346 program.clearRetainingCapacity();
1347 try b.writeOpcode(writer, OP.call_frame_cfa);1347 try b.writeOpcode(writer, OP.call_frame_cfa);
1348 _ = try stack_machine.run(program.items, allocator, context, null);1348 _ = try stack_machine.run(program.items, allocator, context, null);
1349 try testing.expectEqual(context.cfa.?, stack_machine.stack.popOrNull().?.generic);1349 try testing.expectEqual(context.cfa.?, stack_machine.stack.pop().?.generic);
1350 }1350 }
13511351
1352 // Arithmetic and Logical Operations1352 // Arithmetic and Logical Operations
...@@ -1358,7 +1358,7 @@ test "DWARF expressions" {...@@ -1358,7 +1358,7 @@ test "DWARF expressions" {
1358 try b.writeConst(writer, i16, -4096);1358 try b.writeConst(writer, i16, -4096);
1359 try b.writeOpcode(writer, OP.abs);1359 try b.writeOpcode(writer, OP.abs);
1360 _ = try stack_machine.run(program.items, allocator, context, null);1360 _ = try stack_machine.run(program.items, allocator, context, null);
1361 try testing.expectEqual(@as(usize, 4096), stack_machine.stack.popOrNull().?.generic);1361 try testing.expectEqual(@as(usize, 4096), stack_machine.stack.pop().?.generic);
13621362
1363 stack_machine.reset();1363 stack_machine.reset();
1364 program.clearRetainingCapacity();1364 program.clearRetainingCapacity();
...@@ -1366,7 +1366,7 @@ test "DWARF expressions" {...@@ -1366,7 +1366,7 @@ test "DWARF expressions" {
1366 try b.writeConst(writer, u16, 0xf0ff);1366 try b.writeConst(writer, u16, 0xf0ff);
1367 try b.writeOpcode(writer, OP.@"and");1367 try b.writeOpcode(writer, OP.@"and");
1368 _ = try stack_machine.run(program.items, allocator, context, null);1368 _ = try stack_machine.run(program.items, allocator, context, null);
1369 try testing.expectEqual(@as(usize, 0xf00f), stack_machine.stack.popOrNull().?.generic);1369 try testing.expectEqual(@as(usize, 0xf00f), stack_machine.stack.pop().?.generic);
13701370
1371 stack_machine.reset();1371 stack_machine.reset();
1372 program.clearRetainingCapacity();1372 program.clearRetainingCapacity();
...@@ -1374,7 +1374,7 @@ test "DWARF expressions" {...@@ -1374,7 +1374,7 @@ test "DWARF expressions" {
1374 try b.writeConst(writer, i16, 100);1374 try b.writeConst(writer, i16, 100);
1375 try b.writeOpcode(writer, OP.div);1375 try b.writeOpcode(writer, OP.div);
1376 _ = try stack_machine.run(program.items, allocator, context, null);1376 _ = try stack_machine.run(program.items, allocator, context, null);
1377 try testing.expectEqual(@as(isize, -404 / 100), @as(isize, @bitCast(stack_machine.stack.popOrNull().?.generic)));1377 try testing.expectEqual(@as(isize, -404 / 100), @as(isize, @bitCast(stack_machine.stack.pop().?.generic)));
13781378
1379 stack_machine.reset();1379 stack_machine.reset();
1380 program.clearRetainingCapacity();1380 program.clearRetainingCapacity();
...@@ -1382,7 +1382,7 @@ test "DWARF expressions" {...@@ -1382,7 +1382,7 @@ test "DWARF expressions" {
1382 try b.writeConst(writer, u16, 50);1382 try b.writeConst(writer, u16, 50);
1383 try b.writeOpcode(writer, OP.minus);1383 try b.writeOpcode(writer, OP.minus);
1384 _ = try stack_machine.run(program.items, allocator, context, null);1384 _ = try stack_machine.run(program.items, allocator, context, null);
1385 try testing.expectEqual(@as(usize, 150), stack_machine.stack.popOrNull().?.generic);1385 try testing.expectEqual(@as(usize, 150), stack_machine.stack.pop().?.generic);
13861386
1387 stack_machine.reset();1387 stack_machine.reset();
1388 program.clearRetainingCapacity();1388 program.clearRetainingCapacity();
...@@ -1390,7 +1390,7 @@ test "DWARF expressions" {...@@ -1390,7 +1390,7 @@ test "DWARF expressions" {
1390 try b.writeConst(writer, u16, 100);1390 try b.writeConst(writer, u16, 100);
1391 try b.writeOpcode(writer, OP.mod);1391 try b.writeOpcode(writer, OP.mod);
1392 _ = try stack_machine.run(program.items, allocator, context, null);1392 _ = try stack_machine.run(program.items, allocator, context, null);
1393 try testing.expectEqual(@as(usize, 23), stack_machine.stack.popOrNull().?.generic);1393 try testing.expectEqual(@as(usize, 23), stack_machine.stack.pop().?.generic);
13941394
1395 stack_machine.reset();1395 stack_machine.reset();
1396 program.clearRetainingCapacity();1396 program.clearRetainingCapacity();
...@@ -1398,7 +1398,7 @@ test "DWARF expressions" {...@@ -1398,7 +1398,7 @@ test "DWARF expressions" {
1398 try b.writeConst(writer, u16, 0xee);1398 try b.writeConst(writer, u16, 0xee);
1399 try b.writeOpcode(writer, OP.mul);1399 try b.writeOpcode(writer, OP.mul);
1400 _ = try stack_machine.run(program.items, allocator, context, null);1400 _ = try stack_machine.run(program.items, allocator, context, null);
1401 try testing.expectEqual(@as(usize, 0xed12), stack_machine.stack.popOrNull().?.generic);1401 try testing.expectEqual(@as(usize, 0xed12), stack_machine.stack.pop().?.generic);
14021402
1403 stack_machine.reset();1403 stack_machine.reset();
1404 program.clearRetainingCapacity();1404 program.clearRetainingCapacity();
...@@ -1407,15 +1407,15 @@ test "DWARF expressions" {...@@ -1407,15 +1407,15 @@ test "DWARF expressions" {
1407 try b.writeConst(writer, i16, -6);1407 try b.writeConst(writer, i16, -6);
1408 try b.writeOpcode(writer, OP.neg);1408 try b.writeOpcode(writer, OP.neg);
1409 _ = try stack_machine.run(program.items, allocator, context, null);1409 _ = try stack_machine.run(program.items, allocator, context, null);
1410 try testing.expectEqual(@as(usize, 6), stack_machine.stack.popOrNull().?.generic);1410 try testing.expectEqual(@as(usize, 6), stack_machine.stack.pop().?.generic);
1411 try testing.expectEqual(@as(isize, -5), @as(isize, @bitCast(stack_machine.stack.popOrNull().?.generic)));1411 try testing.expectEqual(@as(isize, -5), @as(isize, @bitCast(stack_machine.stack.pop().?.generic)));
14121412
1413 stack_machine.reset();1413 stack_machine.reset();
1414 program.clearRetainingCapacity();1414 program.clearRetainingCapacity();
1415 try b.writeConst(writer, u16, 0xff0f);1415 try b.writeConst(writer, u16, 0xff0f);
1416 try b.writeOpcode(writer, OP.not);1416 try b.writeOpcode(writer, OP.not);
1417 _ = try stack_machine.run(program.items, allocator, context, null);1417 _ = try stack_machine.run(program.items, allocator, context, null);
1418 try testing.expectEqual(~@as(usize, 0xff0f), stack_machine.stack.popOrNull().?.generic);1418 try testing.expectEqual(~@as(usize, 0xff0f), stack_machine.stack.pop().?.generic);
14191419
1420 stack_machine.reset();1420 stack_machine.reset();
1421 program.clearRetainingCapacity();1421 program.clearRetainingCapacity();
...@@ -1423,7 +1423,7 @@ test "DWARF expressions" {...@@ -1423,7 +1423,7 @@ test "DWARF expressions" {
1423 try b.writeConst(writer, u16, 0xf0ff);1423 try b.writeConst(writer, u16, 0xf0ff);
1424 try b.writeOpcode(writer, OP.@"or");1424 try b.writeOpcode(writer, OP.@"or");
1425 _ = try stack_machine.run(program.items, allocator, context, null);1425 _ = try stack_machine.run(program.items, allocator, context, null);
1426 try testing.expectEqual(@as(usize, 0xffff), stack_machine.stack.popOrNull().?.generic);1426 try testing.expectEqual(@as(usize, 0xffff), stack_machine.stack.pop().?.generic);
14271427
1428 stack_machine.reset();1428 stack_machine.reset();
1429 program.clearRetainingCapacity();1429 program.clearRetainingCapacity();
...@@ -1431,14 +1431,14 @@ test "DWARF expressions" {...@@ -1431,14 +1431,14 @@ test "DWARF expressions" {
1431 try b.writeConst(writer, i16, 100);1431 try b.writeConst(writer, i16, 100);
1432 try b.writeOpcode(writer, OP.plus);1432 try b.writeOpcode(writer, OP.plus);
1433 _ = try stack_machine.run(program.items, allocator, context, null);1433 _ = try stack_machine.run(program.items, allocator, context, null);
1434 try testing.expectEqual(@as(usize, 502), stack_machine.stack.popOrNull().?.generic);1434 try testing.expectEqual(@as(usize, 502), stack_machine.stack.pop().?.generic);
14351435
1436 stack_machine.reset();1436 stack_machine.reset();
1437 program.clearRetainingCapacity();1437 program.clearRetainingCapacity();
1438 try b.writeConst(writer, u16, 4096);1438 try b.writeConst(writer, u16, 4096);
1439 try b.writePlusUconst(writer, @as(usize, 8192));1439 try b.writePlusUconst(writer, @as(usize, 8192));
1440 _ = try stack_machine.run(program.items, allocator, context, null);1440 _ = try stack_machine.run(program.items, allocator, context, null);
1441 try testing.expectEqual(@as(usize, 4096 + 8192), stack_machine.stack.popOrNull().?.generic);1441 try testing.expectEqual(@as(usize, 4096 + 8192), stack_machine.stack.pop().?.generic);
14421442
1443 stack_machine.reset();1443 stack_machine.reset();
1444 program.clearRetainingCapacity();1444 program.clearRetainingCapacity();
...@@ -1446,7 +1446,7 @@ test "DWARF expressions" {...@@ -1446,7 +1446,7 @@ test "DWARF expressions" {
1446 try b.writeConst(writer, u16, 1);1446 try b.writeConst(writer, u16, 1);
1447 try b.writeOpcode(writer, OP.shl);1447 try b.writeOpcode(writer, OP.shl);
1448 _ = try stack_machine.run(program.items, allocator, context, null);1448 _ = try stack_machine.run(program.items, allocator, context, null);
1449 try testing.expectEqual(@as(usize, 0xfff << 1), stack_machine.stack.popOrNull().?.generic);1449 try testing.expectEqual(@as(usize, 0xfff << 1), stack_machine.stack.pop().?.generic);
14501450
1451 stack_machine.reset();1451 stack_machine.reset();
1452 program.clearRetainingCapacity();1452 program.clearRetainingCapacity();
...@@ -1454,7 +1454,7 @@ test "DWARF expressions" {...@@ -1454,7 +1454,7 @@ test "DWARF expressions" {
1454 try b.writeConst(writer, u16, 1);1454 try b.writeConst(writer, u16, 1);
1455 try b.writeOpcode(writer, OP.shr);1455 try b.writeOpcode(writer, OP.shr);
1456 _ = try stack_machine.run(program.items, allocator, context, null);1456 _ = try stack_machine.run(program.items, allocator, context, null);
1457 try testing.expectEqual(@as(usize, 0xfff >> 1), stack_machine.stack.popOrNull().?.generic);1457 try testing.expectEqual(@as(usize, 0xfff >> 1), stack_machine.stack.pop().?.generic);
14581458
1459 stack_machine.reset();1459 stack_machine.reset();
1460 program.clearRetainingCapacity();1460 program.clearRetainingCapacity();
...@@ -1462,7 +1462,7 @@ test "DWARF expressions" {...@@ -1462,7 +1462,7 @@ test "DWARF expressions" {
1462 try b.writeConst(writer, u16, 1);1462 try b.writeConst(writer, u16, 1);
1463 try b.writeOpcode(writer, OP.shr);1463 try b.writeOpcode(writer, OP.shr);
1464 _ = try stack_machine.run(program.items, allocator, context, null);1464 _ = try stack_machine.run(program.items, allocator, context, null);
1465 try testing.expectEqual(@as(usize, @bitCast(@as(isize, 0xfff) >> 1)), stack_machine.stack.popOrNull().?.generic);1465 try testing.expectEqual(@as(usize, @bitCast(@as(isize, 0xfff) >> 1)), stack_machine.stack.pop().?.generic);
14661466
1467 stack_machine.reset();1467 stack_machine.reset();
1468 program.clearRetainingCapacity();1468 program.clearRetainingCapacity();
...@@ -1470,7 +1470,7 @@ test "DWARF expressions" {...@@ -1470,7 +1470,7 @@ test "DWARF expressions" {
1470 try b.writeConst(writer, u16, 0xff0f);1470 try b.writeConst(writer, u16, 0xff0f);
1471 try b.writeOpcode(writer, OP.xor);1471 try b.writeOpcode(writer, OP.xor);
1472 _ = try stack_machine.run(program.items, allocator, context, null);1472 _ = try stack_machine.run(program.items, allocator, context, null);
1473 try testing.expectEqual(@as(usize, 0x0ff0), stack_machine.stack.popOrNull().?.generic);1473 try testing.expectEqual(@as(usize, 0x0ff0), stack_machine.stack.pop().?.generic);
1474 }1474 }
14751475
1476 // Control Flow Operations1476 // Control Flow Operations
...@@ -1499,9 +1499,9 @@ test "DWARF expressions" {...@@ -1499,9 +1499,9 @@ test "DWARF expressions" {
1499 try b.writeConst(writer, u16, 0);1499 try b.writeConst(writer, u16, 0);
1500 try b.writeOpcode(writer, e[0]);1500 try b.writeOpcode(writer, e[0]);
1501 _ = try stack_machine.run(program.items, allocator, context, null);1501 _ = try stack_machine.run(program.items, allocator, context, null);
1502 try testing.expectEqual(@as(usize, e[3]), stack_machine.stack.popOrNull().?.generic);1502 try testing.expectEqual(@as(usize, e[3]), stack_machine.stack.pop().?.generic);
1503 try testing.expectEqual(@as(usize, e[2]), stack_machine.stack.popOrNull().?.generic);1503 try testing.expectEqual(@as(usize, e[2]), stack_machine.stack.pop().?.generic);
1504 try testing.expectEqual(@as(usize, e[1]), stack_machine.stack.popOrNull().?.generic);1504 try testing.expectEqual(@as(usize, e[1]), stack_machine.stack.pop().?.generic);
1505 }1505 }
15061506
1507 stack_machine.reset();1507 stack_machine.reset();
...@@ -1510,7 +1510,7 @@ test "DWARF expressions" {...@@ -1510,7 +1510,7 @@ test "DWARF expressions" {
1510 try b.writeSkip(writer, 1);1510 try b.writeSkip(writer, 1);
1511 try b.writeLiteral(writer, 3);1511 try b.writeLiteral(writer, 3);
1512 _ = try stack_machine.run(program.items, allocator, context, null);1512 _ = try stack_machine.run(program.items, allocator, context, null);
1513 try testing.expectEqual(@as(usize, 2), stack_machine.stack.popOrNull().?.generic);1513 try testing.expectEqual(@as(usize, 2), stack_machine.stack.pop().?.generic);
15141514
1515 stack_machine.reset();1515 stack_machine.reset();
1516 program.clearRetainingCapacity();1516 program.clearRetainingCapacity();
...@@ -1522,9 +1522,9 @@ test "DWARF expressions" {...@@ -1522,9 +1522,9 @@ test "DWARF expressions" {
1522 try b.writeLiteral(writer, 4);1522 try b.writeLiteral(writer, 4);
1523 try b.writeLiteral(writer, 5);1523 try b.writeLiteral(writer, 5);
1524 _ = try stack_machine.run(program.items, allocator, context, null);1524 _ = try stack_machine.run(program.items, allocator, context, null);
1525 try testing.expectEqual(@as(usize, 5), stack_machine.stack.popOrNull().?.generic);1525 try testing.expectEqual(@as(usize, 5), stack_machine.stack.pop().?.generic);
1526 try testing.expectEqual(@as(usize, 4), stack_machine.stack.popOrNull().?.generic);1526 try testing.expectEqual(@as(usize, 4), stack_machine.stack.pop().?.generic);
1527 try testing.expect(stack_machine.stack.popOrNull() == null);1527 try testing.expect(stack_machine.stack.pop() == null);
15281528
1529 // TODO: Test call2, call4, call_ref once implemented1529 // TODO: Test call2, call4, call_ref once implemented
15301530
...@@ -1548,7 +1548,7 @@ test "DWARF expressions" {...@@ -1548,7 +1548,7 @@ test "DWARF expressions" {
1548 try b.writeConstType(writer, @as(usize, 0), &value_bytes);1548 try b.writeConstType(writer, @as(usize, 0), &value_bytes);
1549 try b.writeConvert(writer, @as(usize, 0));1549 try b.writeConvert(writer, @as(usize, 0));
1550 _ = try stack_machine.run(program.items, allocator, context, null);1550 _ = try stack_machine.run(program.items, allocator, context, null);
1551 try testing.expectEqual(value, stack_machine.stack.popOrNull().?.generic);1551 try testing.expectEqual(value, stack_machine.stack.pop().?.generic);
15521552
1553 // Reinterpret to generic type1553 // Reinterpret to generic type
1554 stack_machine.reset();1554 stack_machine.reset();
...@@ -1556,7 +1556,7 @@ test "DWARF expressions" {...@@ -1556,7 +1556,7 @@ test "DWARF expressions" {
1556 try b.writeConstType(writer, @as(usize, 0), &value_bytes);1556 try b.writeConstType(writer, @as(usize, 0), &value_bytes);
1557 try b.writeReinterpret(writer, @as(usize, 0));1557 try b.writeReinterpret(writer, @as(usize, 0));
1558 _ = try stack_machine.run(program.items, allocator, context, null);1558 _ = try stack_machine.run(program.items, allocator, context, null);
1559 try testing.expectEqual(value, stack_machine.stack.popOrNull().?.generic);1559 try testing.expectEqual(value, stack_machine.stack.pop().?.generic);
15601560
1561 // Reinterpret to new type1561 // Reinterpret to new type
1562 const die_offset: usize = 0xffee;1562 const die_offset: usize = 0xffee;
...@@ -1566,7 +1566,7 @@ test "DWARF expressions" {...@@ -1566,7 +1566,7 @@ test "DWARF expressions" {
1566 try b.writeConstType(writer, @as(usize, 0), &value_bytes);1566 try b.writeConstType(writer, @as(usize, 0), &value_bytes);
1567 try b.writeReinterpret(writer, die_offset);1567 try b.writeReinterpret(writer, die_offset);
1568 _ = try stack_machine.run(program.items, allocator, context, null);1568 _ = try stack_machine.run(program.items, allocator, context, null);
1569 const const_type = stack_machine.stack.popOrNull().?.const_type;1569 const const_type = stack_machine.stack.pop().?.const_type;
1570 try testing.expectEqual(die_offset, const_type.type_offset);1570 try testing.expectEqual(die_offset, const_type.type_offset);
15711571
1572 stack_machine.reset();1572 stack_machine.reset();
...@@ -1574,7 +1574,7 @@ test "DWARF expressions" {...@@ -1574,7 +1574,7 @@ test "DWARF expressions" {
1574 try b.writeLiteral(writer, 0);1574 try b.writeLiteral(writer, 0);
1575 try b.writeReinterpret(writer, die_offset);1575 try b.writeReinterpret(writer, die_offset);
1576 _ = try stack_machine.run(program.items, allocator, context, null);1576 _ = try stack_machine.run(program.items, allocator, context, null);
1577 const regval_type = stack_machine.stack.popOrNull().?.regval_type;1577 const regval_type = stack_machine.stack.pop().?.regval_type;
1578 try testing.expectEqual(die_offset, regval_type.type_offset);1578 try testing.expectEqual(die_offset, regval_type.type_offset);
1579 }1579 }
15801580
...@@ -1586,7 +1586,7 @@ test "DWARF expressions" {...@@ -1586,7 +1586,7 @@ test "DWARF expressions" {
1586 program.clearRetainingCapacity();1586 program.clearRetainingCapacity();
1587 try b.writeOpcode(writer, OP.nop);1587 try b.writeOpcode(writer, OP.nop);
1588 _ = try stack_machine.run(program.items, allocator, context, null);1588 _ = try stack_machine.run(program.items, allocator, context, null);
1589 try testing.expect(stack_machine.stack.popOrNull() == null);1589 try testing.expect(stack_machine.stack.pop() == null);
15901590
1591 // Sub-expression1591 // Sub-expression
1592 {1592 {
...@@ -1599,7 +1599,7 @@ test "DWARF expressions" {...@@ -1599,7 +1599,7 @@ test "DWARF expressions" {
1599 program.clearRetainingCapacity();1599 program.clearRetainingCapacity();
1600 try b.writeEntryValue(writer, sub_program.items);1600 try b.writeEntryValue(writer, sub_program.items);
1601 _ = try stack_machine.run(program.items, allocator, context, null);1601 _ = try stack_machine.run(program.items, allocator, context, null);
1602 try testing.expectEqual(@as(usize, 3), stack_machine.stack.popOrNull().?.generic);1602 try testing.expectEqual(@as(usize, 3), stack_machine.stack.pop().?.generic);
1603 }1603 }
16041604
1605 // Register location description1605 // Register location description
...@@ -1626,7 +1626,7 @@ test "DWARF expressions" {...@@ -1626,7 +1626,7 @@ test "DWARF expressions" {
1626 program.clearRetainingCapacity();1626 program.clearRetainingCapacity();
1627 try b.writeEntryValue(writer, sub_program.items);1627 try b.writeEntryValue(writer, sub_program.items);
1628 _ = try stack_machine.run(program.items, allocator, context, null);1628 _ = try stack_machine.run(program.items, allocator, context, null);
1629 try testing.expectEqual(@as(usize, 0xee), stack_machine.stack.popOrNull().?.generic);1629 try testing.expectEqual(@as(usize, 0xee), stack_machine.stack.pop().?.generic);
1630 } else |err| {1630 } else |err| {
1631 switch (err) {1631 switch (err) {
1632 error.UnimplementedArch,1632 error.UnimplementedArch,
lib/std/debug/SelfInfo.zig+1-1
...@@ -2138,7 +2138,7 @@ pub const VirtualMachine = struct {...@@ -2138,7 +2138,7 @@ pub const VirtualMachine = struct {
2138 self.current_row.copy_on_write = true;2138 self.current_row.copy_on_write = true;
2139 },2139 },
2140 .restore_state => {2140 .restore_state => {
2141 const restored_columns = self.stack.popOrNull() orelse return error.InvalidOperation;2141 const restored_columns = self.stack.pop() orelse return error.InvalidOperation;
2142 self.columns.shrinkRetainingCapacity(self.columns.items.len - self.current_row.columns.len);2142 self.columns.shrinkRetainingCapacity(self.columns.items.len - self.current_row.columns.len);
2143 try self.columns.ensureUnusedCapacity(allocator, restored_columns.len);2143 try self.columns.ensureUnusedCapacity(allocator, restored_columns.len);
21442144
lib/std/fs/Dir.zig+2-2
...@@ -682,7 +682,7 @@ pub const Walker = struct {...@@ -682,7 +682,7 @@ pub const Walker = struct {
682 // walking if they want, which means that we need to pop the directory682 // walking if they want, which means that we need to pop the directory
683 // that errored from the stack. Otherwise, all future `next` calls would683 // that errored from the stack. Otherwise, all future `next` calls would
684 // likely just fail with the same error.684 // likely just fail with the same error.
685 var item = self.stack.pop();685 var item = self.stack.pop().?;
686 if (self.stack.items.len != 0) {686 if (self.stack.items.len != 0) {
687 item.iter.dir.close();687 item.iter.dir.close();
688 }688 }
...@@ -718,7 +718,7 @@ pub const Walker = struct {...@@ -718,7 +718,7 @@ pub const Walker = struct {
718 .kind = base.kind,718 .kind = base.kind,
719 };719 };
720 } else {720 } else {
721 var item = self.stack.pop();721 var item = self.stack.pop().?;
722 if (self.stack.items.len != 0) {722 if (self.stack.items.len != 0) {
723 item.iter.dir.close();723 item.iter.dir.close();
724 }724 }
lib/std/heap.zig+1-1
...@@ -681,7 +681,7 @@ pub fn testAllocatorAlignedShrink(base_allocator: mem.Allocator) !void {...@@ -681,7 +681,7 @@ pub fn testAllocatorAlignedShrink(base_allocator: mem.Allocator) !void {
681 try stuff_to_free.append(slice);681 try stuff_to_free.append(slice);
682 slice = try allocator.alignedAlloc(u8, 16, alloc_size);682 slice = try allocator.alignedAlloc(u8, 16, alloc_size);
683 }683 }
684 while (stuff_to_free.popOrNull()) |item| {684 while (stuff_to_free.pop()) |item| {
685 allocator.free(item);685 allocator.free(item);
686 }686 }
687 slice[0] = 0x12;687 slice[0] = 0x12;
lib/std/heap/debug_allocator.zig+3-3
...@@ -1070,7 +1070,7 @@ test "small allocations - free in reverse order" {...@@ -1070,7 +1070,7 @@ test "small allocations - free in reverse order" {
1070 try list.append(ptr);1070 try list.append(ptr);
1071 }1071 }
10721072
1073 while (list.popOrNull()) |ptr| {1073 while (list.pop()) |ptr| {
1074 allocator.destroy(ptr);1074 allocator.destroy(ptr);
1075 }1075 }
1076}1076}
...@@ -1227,7 +1227,7 @@ test "shrink large object to large object with larger alignment" {...@@ -1227,7 +1227,7 @@ test "shrink large object to large object with larger alignment" {
1227 try stuff_to_free.append(slice);1227 try stuff_to_free.append(slice);
1228 slice = try allocator.alignedAlloc(u8, 16, alloc_size);1228 slice = try allocator.alignedAlloc(u8, 16, alloc_size);
1229 }1229 }
1230 while (stuff_to_free.popOrNull()) |item| {1230 while (stuff_to_free.pop()) |item| {
1231 allocator.free(item);1231 allocator.free(item);
1232 }1232 }
1233 slice[0] = 0x12;1233 slice[0] = 0x12;
...@@ -1299,7 +1299,7 @@ test "realloc large object to larger alignment" {...@@ -1299,7 +1299,7 @@ test "realloc large object to larger alignment" {
1299 try stuff_to_free.append(slice);1299 try stuff_to_free.append(slice);
1300 slice = try allocator.alignedAlloc(u8, 16, default_page_size * 2 + 50);1300 slice = try allocator.alignedAlloc(u8, 16, default_page_size * 2 + 50);
1301 }1301 }
1302 while (stuff_to_free.popOrNull()) |item| {1302 while (stuff_to_free.pop()) |item| {
1303 allocator.free(item);1303 allocator.free(item);
1304 }1304 }
1305 slice[0] = 0x12;1305 slice[0] = 0x12;
lib/std/json/dynamic.zig+2-2
...@@ -124,7 +124,7 @@ pub const Value = union(enum) {...@@ -124,7 +124,7 @@ pub const Value = union(enum) {
124 .array_begin => {124 .array_begin => {
125 try stack.append(Value{ .array = Array.init(allocator) });125 try stack.append(Value{ .array = Array.init(allocator) });
126 },126 },
127 .array_end => return try handleCompleteValue(&stack, allocator, source, stack.pop(), options) orelse continue,127 .array_end => return try handleCompleteValue(&stack, allocator, source, stack.pop().?, options) orelse continue,
128128
129 else => unreachable,129 else => unreachable,
130 }130 }
...@@ -171,7 +171,7 @@ fn handleCompleteValue(stack: *Array, allocator: Allocator, source: anytype, val...@@ -171,7 +171,7 @@ fn handleCompleteValue(stack: *Array, allocator: Allocator, source: anytype, val
171 switch (try source.nextAllocMax(allocator, .alloc_always, options.max_value_len.?)) {171 switch (try source.nextAllocMax(allocator, .alloc_always, options.max_value_len.?)) {
172 .object_end => {172 .object_end => {
173 // This object is complete.173 // This object is complete.
174 value = stack.pop();174 value = stack.pop().?;
175 // Effectively recurse now that we have a complete value.175 // Effectively recurse now that we have a complete value.
176 if (stack.items.len == 0) return value;176 if (stack.items.len == 0) return value;
177 continue;177 continue;
src/Compilation.zig+2-2
...@@ -657,7 +657,7 @@ pub const CObject = struct {...@@ -657,7 +657,7 @@ pub const CObject = struct {
657 .end_block => |block| switch (@as(BlockId, @enumFromInt(block.id))) {657 .end_block => |block| switch (@as(BlockId, @enumFromInt(block.id))) {
658 .Meta => {},658 .Meta => {},
659 .Diag => {659 .Diag => {
660 var wip_diag = stack.pop();660 var wip_diag = stack.pop().?;
661 errdefer wip_diag.deinit(gpa);661 errdefer wip_diag.deinit(gpa);
662662
663 const src_ranges = try wip_diag.src_ranges.toOwnedSlice(gpa);663 const src_ranges = try wip_diag.src_ranges.toOwnedSlice(gpa);
...@@ -5915,7 +5915,7 @@ pub fn addCCArgs(...@@ -5915,7 +5915,7 @@ pub fn addCCArgs(
5915 try san_arg.appendSlice(arena, "fuzzer-no-link,");5915 try san_arg.appendSlice(arena, "fuzzer-no-link,");
5916 }5916 }
5917 // Chop off the trailing comma and append to argv.5917 // Chop off the trailing comma and append to argv.
5918 if (san_arg.popOrNull()) |_| {5918 if (san_arg.pop()) |_| {
5919 try argv.append(san_arg.items);5919 try argv.append(san_arg.items);
59205920
5921 // These args have to be added after the `-fsanitize` arg or5921 // These args have to be added after the `-fsanitize` arg or
src/InternPool.zig+2-2
...@@ -929,7 +929,7 @@ pub fn addDependency(ip: *InternPool, gpa: Allocator, depender: AnalUnit, depend...@@ -929,7 +929,7 @@ pub fn addDependency(ip: *InternPool, gpa: Allocator, depender: AnalUnit, depend
929 }929 }
930930
931 // Prepend a new dependency.931 // Prepend a new dependency.
932 const new_index: DepEntry.Index, const ptr = if (ip.free_dep_entries.popOrNull()) |new_index| new: {932 const new_index: DepEntry.Index, const ptr = if (ip.free_dep_entries.pop()) |new_index| new: {
933 break :new .{ new_index, &ip.dep_entries.items[@intFromEnum(new_index)] };933 break :new .{ new_index, &ip.dep_entries.items[@intFromEnum(new_index)] };
934 } else .{ @enumFromInt(ip.dep_entries.items.len), ip.dep_entries.addOneAssumeCapacity() };934 } else .{ @enumFromInt(ip.dep_entries.items.len), ip.dep_entries.addOneAssumeCapacity() };
935 if (deps.unwrap()) |old_first| {935 if (deps.unwrap()) |old_first| {
...@@ -960,7 +960,7 @@ pub fn addDependency(ip: *InternPool, gpa: Allocator, depender: AnalUnit, depend...@@ -960,7 +960,7 @@ pub fn addDependency(ip: *InternPool, gpa: Allocator, depender: AnalUnit, depend
960 }960 }
961961
962 // Prepend a new dependency.962 // Prepend a new dependency.
963 const new_index: DepEntry.Index, const ptr = if (ip.free_dep_entries.popOrNull()) |new_index| new: {963 const new_index: DepEntry.Index, const ptr = if (ip.free_dep_entries.pop()) |new_index| new: {
964 break :new .{ new_index, &ip.dep_entries.items[@intFromEnum(new_index)] };964 break :new .{ new_index, &ip.dep_entries.items[@intFromEnum(new_index)] };
965 } else .{ @enumFromInt(ip.dep_entries.items.len), ip.dep_entries.addOneAssumeCapacity() };965 } else .{ @enumFromInt(ip.dep_entries.items.len), ip.dep_entries.addOneAssumeCapacity() };
966 if (gop.found_existing) {966 if (gop.found_existing) {
src/Package/Fetch.zig+1-1
...@@ -127,7 +127,7 @@ pub const JobQueue = struct {...@@ -127,7 +127,7 @@ pub const JobQueue = struct {
127 // `Fetch` instances are allocated in prior ones' arenas.127 // `Fetch` instances are allocated in prior ones' arenas.
128 // Sorry, I know it's a bit weird, but it slightly simplifies the128 // Sorry, I know it's a bit weird, but it slightly simplifies the
129 // critical section.129 // critical section.
130 while (jq.all_fetches.popOrNull()) |f| f.deinit();130 while (jq.all_fetches.pop()) |f| f.deinit();
131 jq.all_fetches.deinit(gpa);131 jq.all_fetches.deinit(gpa);
132 jq.* = undefined;132 jq.* = undefined;
133 }133 }
src/Sema.zig+2-2
...@@ -3912,7 +3912,7 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref,...@@ -3912,7 +3912,7 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref,
39123912
3913 const tmp_air = sema.getTmpAir();3913 const tmp_air = sema.getTmpAir();
39143914
3915 while (to_map.popOrNull()) |air_ptr| {3915 while (to_map.pop()) |air_ptr| {
3916 if (ptr_mapping.contains(air_ptr)) continue;3916 if (ptr_mapping.contains(air_ptr)) continue;
3917 const PointerMethod = union(enum) {3917 const PointerMethod = union(enum) {
3918 same_addr,3918 same_addr,
...@@ -38422,7 +38422,7 @@ pub fn flushExports(sema: *Sema) !void {...@@ -38422,7 +38422,7 @@ pub fn flushExports(sema: *Sema) !void {
38422 // `sema.exports` is completed; store the data into the `Zcu`.38422 // `sema.exports` is completed; store the data into the `Zcu`.
38423 if (sema.exports.items.len == 1) {38423 if (sema.exports.items.len == 1) {
38424 try zcu.single_exports.ensureUnusedCapacity(gpa, 1);38424 try zcu.single_exports.ensureUnusedCapacity(gpa, 1);
38425 const export_idx: Zcu.Export.Index = zcu.free_exports.popOrNull() orelse idx: {38425 const export_idx: Zcu.Export.Index = zcu.free_exports.pop() orelse idx: {
38426 _ = try zcu.all_exports.addOne(gpa);38426 _ = try zcu.all_exports.addOne(gpa);
38427 break :idx @enumFromInt(zcu.all_exports.items.len - 1);38427 break :idx @enumFromInt(zcu.all_exports.items.len - 1);
38428 };38428 };
src/Zcu.zig+3-3
...@@ -3130,7 +3130,7 @@ pub fn mapOldZirToNew(...@@ -3130,7 +3130,7 @@ pub fn mapOldZirToNew(
3130 }3130 }
3131 }3131 }
31323132
3133 while (match_stack.popOrNull()) |match_item| {3133 while (match_stack.pop()) |match_item| {
3134 // First, a check: if the number of captures of this type has changed, we can't map it, because3134 // First, a check: if the number of captures of this type has changed, we can't map it, because
3135 // we wouldn't know how to correlate type information with the last update.3135 // we wouldn't know how to correlate type information with the last update.
3136 // Synchronizes with logic in `Zcu.PerThread.recreateStructType` etc.3136 // Synchronizes with logic in `Zcu.PerThread.recreateStructType` etc.
...@@ -3412,7 +3412,7 @@ pub fn addUnitReference(zcu: *Zcu, src_unit: AnalUnit, referenced_unit: AnalUnit...@@ -3412,7 +3412,7 @@ pub fn addUnitReference(zcu: *Zcu, src_unit: AnalUnit, referenced_unit: AnalUnit
34123412
3413 try zcu.reference_table.ensureUnusedCapacity(gpa, 1);3413 try zcu.reference_table.ensureUnusedCapacity(gpa, 1);
34143414
3415 const ref_idx = zcu.free_references.popOrNull() orelse idx: {3415 const ref_idx = zcu.free_references.pop() orelse idx: {
3416 _ = try zcu.all_references.addOne(gpa);3416 _ = try zcu.all_references.addOne(gpa);
3417 break :idx zcu.all_references.items.len - 1;3417 break :idx zcu.all_references.items.len - 1;
3418 };3418 };
...@@ -3437,7 +3437,7 @@ pub fn addTypeReference(zcu: *Zcu, src_unit: AnalUnit, referenced_type: InternPo...@@ -3437,7 +3437,7 @@ pub fn addTypeReference(zcu: *Zcu, src_unit: AnalUnit, referenced_type: InternPo
34373437
3438 try zcu.type_reference_table.ensureUnusedCapacity(gpa, 1);3438 try zcu.type_reference_table.ensureUnusedCapacity(gpa, 1);
34393439
3440 const ref_idx = zcu.free_type_references.popOrNull() orelse idx: {3440 const ref_idx = zcu.free_type_references.pop() orelse idx: {
3441 _ = try zcu.all_type_references.addOne(gpa);3441 _ = try zcu.all_type_references.addOne(gpa);
3442 break :idx zcu.all_type_references.items.len - 1;3442 break :idx zcu.all_type_references.items.len - 1;
3443 };3443 };
src/arch/aarch64/CodeGen.zig+9-9
...@@ -572,7 +572,7 @@ fn gen(self: *Self) !void {...@@ -572,7 +572,7 @@ fn gen(self: *Self) !void {
572 // dbg_epilogue_begin) is the last exitlude jump572 // dbg_epilogue_begin) is the last exitlude jump
573 // relocation (which would just jump one instruction573 // relocation (which would just jump one instruction
574 // further), it can be safely removed574 // further), it can be safely removed
575 self.mir_instructions.orderedRemove(self.exitlude_jump_relocs.pop());575 self.mir_instructions.orderedRemove(self.exitlude_jump_relocs.pop().?);
576 }576 }
577577
578 for (self.exitlude_jump_relocs.items) |jmp_reloc| {578 for (self.exitlude_jump_relocs.items) |jmp_reloc| {
...@@ -4694,7 +4694,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) InnerError!void {...@@ -4694,7 +4694,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) InnerError!void {
46944694
4695 try self.branch_stack.append(.{});4695 try self.branch_stack.append(.{});
4696 errdefer {4696 errdefer {
4697 _ = self.branch_stack.pop();4697 _ = self.branch_stack.pop().?;
4698 }4698 }
46994699
4700 try self.ensureProcessDeathCapacity(liveness_condbr.then_deaths.len);4700 try self.ensureProcessDeathCapacity(liveness_condbr.then_deaths.len);
...@@ -4705,7 +4705,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) InnerError!void {...@@ -4705,7 +4705,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) InnerError!void {
47054705
4706 // Revert to the previous register and stack allocation state.4706 // Revert to the previous register and stack allocation state.
47074707
4708 var saved_then_branch = self.branch_stack.pop();4708 var saved_then_branch = self.branch_stack.pop().?;
4709 defer saved_then_branch.deinit(self.gpa);4709 defer saved_then_branch.deinit(self.gpa);
47104710
4711 self.register_manager.registers = parent_registers;4711 self.register_manager.registers = parent_registers;
...@@ -4800,7 +4800,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) InnerError!void {...@@ -4800,7 +4800,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) InnerError!void {
4800 }4800 }
48014801
4802 {4802 {
4803 var item = self.branch_stack.pop();4803 var item = self.branch_stack.pop().?;
4804 item.deinit(self.gpa);4804 item.deinit(self.gpa);
4805 }4805 }
48064806
...@@ -5059,7 +5059,7 @@ fn lowerBlock(self: *Self, inst: Air.Inst.Index, body: []const Air.Inst.Index) !...@@ -5059,7 +5059,7 @@ fn lowerBlock(self: *Self, inst: Air.Inst.Index, body: []const Air.Inst.Index) !
5059 // If the last Mir instruction is the last relocation (which5059 // If the last Mir instruction is the last relocation (which
5060 // would just jump one instruction further), it can be safely5060 // would just jump one instruction further), it can be safely
5061 // removed5061 // removed
5062 self.mir_instructions.orderedRemove(relocs.pop());5062 self.mir_instructions.orderedRemove(relocs.pop().?);
5063 }5063 }
5064 for (relocs.items) |reloc| {5064 for (relocs.items) |reloc| {
5065 try self.performReloc(reloc);5065 try self.performReloc(reloc);
...@@ -5125,7 +5125,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) InnerError!void {...@@ -5125,7 +5125,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) InnerError!void {
51255125
5126 try self.branch_stack.append(.{});5126 try self.branch_stack.append(.{});
5127 errdefer {5127 errdefer {
5128 _ = self.branch_stack.pop();5128 _ = self.branch_stack.pop().?;
5129 }5129 }
51305130
5131 try self.ensureProcessDeathCapacity(liveness.deaths[case.idx].len);5131 try self.ensureProcessDeathCapacity(liveness.deaths[case.idx].len);
...@@ -5135,7 +5135,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) InnerError!void {...@@ -5135,7 +5135,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) InnerError!void {
5135 try self.genBody(case.body);5135 try self.genBody(case.body);
51365136
5137 // Revert to the previous register and stack allocation state.5137 // Revert to the previous register and stack allocation state.
5138 var saved_case_branch = self.branch_stack.pop();5138 var saved_case_branch = self.branch_stack.pop().?;
5139 defer saved_case_branch.deinit(self.gpa);5139 defer saved_case_branch.deinit(self.gpa);
51405140
5141 self.register_manager.registers = parent_registers;5141 self.register_manager.registers = parent_registers;
...@@ -5163,7 +5163,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) InnerError!void {...@@ -5163,7 +5163,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) InnerError!void {
51635163
5164 try self.branch_stack.append(.{});5164 try self.branch_stack.append(.{});
5165 errdefer {5165 errdefer {
5166 _ = self.branch_stack.pop();5166 _ = self.branch_stack.pop().?;
5167 }5167 }
51685168
5169 const else_deaths = liveness.deaths.len - 1;5169 const else_deaths = liveness.deaths.len - 1;
...@@ -5174,7 +5174,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) InnerError!void {...@@ -5174,7 +5174,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) InnerError!void {
5174 try self.genBody(else_body);5174 try self.genBody(else_body);
51755175
5176 // Revert to the previous register and stack allocation state.5176 // Revert to the previous register and stack allocation state.
5177 var saved_case_branch = self.branch_stack.pop();5177 var saved_case_branch = self.branch_stack.pop().?;
5178 defer saved_case_branch.deinit(self.gpa);5178 defer saved_case_branch.deinit(self.gpa);
51795179
5180 self.register_manager.registers = parent_registers;5180 self.register_manager.registers = parent_registers;
src/arch/arm/CodeGen.zig+9-9
...@@ -568,7 +568,7 @@ fn gen(self: *Self) !void {...@@ -568,7 +568,7 @@ fn gen(self: *Self) !void {
568 // dbg_epilogue_begin) is the last exitlude jump568 // dbg_epilogue_begin) is the last exitlude jump
569 // relocation (which would just jump one instruction569 // relocation (which would just jump one instruction
570 // further), it can be safely removed570 // further), it can be safely removed
571 self.mir_instructions.orderedRemove(self.exitlude_jump_relocs.pop());571 self.mir_instructions.orderedRemove(self.exitlude_jump_relocs.pop().?);
572 }572 }
573573
574 for (self.exitlude_jump_relocs.items) |jmp_reloc| {574 for (self.exitlude_jump_relocs.items) |jmp_reloc| {
...@@ -4669,7 +4669,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {...@@ -4669,7 +4669,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {
46694669
4670 try self.branch_stack.append(.{});4670 try self.branch_stack.append(.{});
4671 errdefer {4671 errdefer {
4672 _ = self.branch_stack.pop();4672 _ = self.branch_stack.pop().?;
4673 }4673 }
46744674
4675 try self.ensureProcessDeathCapacity(liveness_condbr.then_deaths.len);4675 try self.ensureProcessDeathCapacity(liveness_condbr.then_deaths.len);
...@@ -4680,7 +4680,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {...@@ -4680,7 +4680,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {
46804680
4681 // Revert to the previous register and stack allocation state.4681 // Revert to the previous register and stack allocation state.
46824682
4683 var saved_then_branch = self.branch_stack.pop();4683 var saved_then_branch = self.branch_stack.pop().?;
4684 defer saved_then_branch.deinit(self.gpa);4684 defer saved_then_branch.deinit(self.gpa);
46854685
4686 self.register_manager.registers = parent_registers;4686 self.register_manager.registers = parent_registers;
...@@ -4775,7 +4775,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {...@@ -4775,7 +4775,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {
4775 }4775 }
47764776
4777 {4777 {
4778 var item = self.branch_stack.pop();4778 var item = self.branch_stack.pop().?;
4779 item.deinit(self.gpa);4779 item.deinit(self.gpa);
4780 }4780 }
47814781
...@@ -5009,7 +5009,7 @@ fn lowerBlock(self: *Self, inst: Air.Inst.Index, body: []const Air.Inst.Index) !...@@ -5009,7 +5009,7 @@ fn lowerBlock(self: *Self, inst: Air.Inst.Index, body: []const Air.Inst.Index) !
5009 // If the last Mir instruction is the last relocation (which5009 // If the last Mir instruction is the last relocation (which
5010 // would just jump one instruction further), it can be safely5010 // would just jump one instruction further), it can be safely
5011 // removed5011 // removed
5012 self.mir_instructions.orderedRemove(relocs.pop());5012 self.mir_instructions.orderedRemove(relocs.pop().?);
5013 }5013 }
5014 for (relocs.items) |reloc| {5014 for (relocs.items) |reloc| {
5015 try self.performReloc(reloc);5015 try self.performReloc(reloc);
...@@ -5074,7 +5074,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {...@@ -5074,7 +5074,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {
50745074
5075 try self.branch_stack.append(.{});5075 try self.branch_stack.append(.{});
5076 errdefer {5076 errdefer {
5077 _ = self.branch_stack.pop();5077 _ = self.branch_stack.pop().?;
5078 }5078 }
50795079
5080 try self.ensureProcessDeathCapacity(liveness.deaths[case.idx].len);5080 try self.ensureProcessDeathCapacity(liveness.deaths[case.idx].len);
...@@ -5084,7 +5084,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {...@@ -5084,7 +5084,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {
5084 try self.genBody(case.body);5084 try self.genBody(case.body);
50855085
5086 // Revert to the previous register and stack allocation state.5086 // Revert to the previous register and stack allocation state.
5087 var saved_case_branch = self.branch_stack.pop();5087 var saved_case_branch = self.branch_stack.pop().?;
5088 defer saved_case_branch.deinit(self.gpa);5088 defer saved_case_branch.deinit(self.gpa);
50895089
5090 self.register_manager.registers = parent_registers;5090 self.register_manager.registers = parent_registers;
...@@ -5112,7 +5112,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {...@@ -5112,7 +5112,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {
51125112
5113 try self.branch_stack.append(.{});5113 try self.branch_stack.append(.{});
5114 errdefer {5114 errdefer {
5115 _ = self.branch_stack.pop();5115 _ = self.branch_stack.pop().?;
5116 }5116 }
51175117
5118 const else_deaths = liveness.deaths.len - 1;5118 const else_deaths = liveness.deaths.len - 1;
...@@ -5123,7 +5123,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {...@@ -5123,7 +5123,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {
5123 try self.genBody(else_body);5123 try self.genBody(else_body);
51245124
5125 // Revert to the previous register and stack allocation state.5125 // Revert to the previous register and stack allocation state.
5126 var saved_case_branch = self.branch_stack.pop();5126 var saved_case_branch = self.branch_stack.pop().?;
5127 defer saved_case_branch.deinit(self.gpa);5127 defer saved_case_branch.deinit(self.gpa);
51285128
5129 self.register_manager.registers = parent_registers;5129 self.register_manager.registers = parent_registers;
src/arch/sparc64/CodeGen.zig+5-5
...@@ -392,7 +392,7 @@ fn gen(self: *Self) !void {...@@ -392,7 +392,7 @@ fn gen(self: *Self) !void {
392 // dbg_epilogue_begin) is the last exitlude jump392 // dbg_epilogue_begin) is the last exitlude jump
393 // relocation (which would just jump two instructions393 // relocation (which would just jump two instructions
394 // further), it can be safely removed394 // further), it can be safely removed
395 const index = self.exitlude_jump_relocs.pop();395 const index = self.exitlude_jump_relocs.pop().?;
396396
397 // First, remove the delay slot, then remove397 // First, remove the delay slot, then remove
398 // the branch instruction itself.398 // the branch instruction itself.
...@@ -1147,7 +1147,7 @@ fn lowerBlock(self: *Self, inst: Air.Inst.Index, body: []const Air.Inst.Index) !...@@ -1147,7 +1147,7 @@ fn lowerBlock(self: *Self, inst: Air.Inst.Index, body: []const Air.Inst.Index) !
1147 // If the last Mir instruction is the last relocation (which1147 // If the last Mir instruction is the last relocation (which
1148 // would just jump two instruction further), it can be safely1148 // would just jump two instruction further), it can be safely
1149 // removed1149 // removed
1150 const index = relocs.pop();1150 const index = relocs.pop().?;
11511151
1152 // First, remove the delay slot, then remove1152 // First, remove the delay slot, then remove
1153 // the branch instruction itself.1153 // the branch instruction itself.
...@@ -1501,7 +1501,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {...@@ -1501,7 +1501,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {
15011501
1502 try self.branch_stack.append(.{});1502 try self.branch_stack.append(.{});
1503 errdefer {1503 errdefer {
1504 _ = self.branch_stack.pop();1504 _ = self.branch_stack.pop().?;
1505 }1505 }
15061506
1507 try self.ensureProcessDeathCapacity(liveness_condbr.then_deaths.len);1507 try self.ensureProcessDeathCapacity(liveness_condbr.then_deaths.len);
...@@ -1512,7 +1512,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {...@@ -1512,7 +1512,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {
15121512
1513 // Revert to the previous register and stack allocation state.1513 // Revert to the previous register and stack allocation state.
15141514
1515 var saved_then_branch = self.branch_stack.pop();1515 var saved_then_branch = self.branch_stack.pop().?;
1516 defer saved_then_branch.deinit(self.gpa);1516 defer saved_then_branch.deinit(self.gpa);
15171517
1518 self.register_manager.registers = parent_registers;1518 self.register_manager.registers = parent_registers;
...@@ -1608,7 +1608,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {...@@ -1608,7 +1608,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {
1608 }1608 }
16091609
1610 {1610 {
1611 var item = self.branch_stack.pop();1611 var item = self.branch_stack.pop().?;
1612 item.deinit(self.gpa);1612 item.deinit(self.gpa);
1613 }1613 }
16141614
src/arch/wasm/CodeGen.zig+11-11
...@@ -1121,11 +1121,11 @@ fn allocLocal(cg: *CodeGen, ty: Type) InnerError!WValue {...@@ -1121,11 +1121,11 @@ fn allocLocal(cg: *CodeGen, ty: Type) InnerError!WValue {
1121 const zcu = cg.pt.zcu;1121 const zcu = cg.pt.zcu;
1122 const valtype = typeToValtype(ty, zcu, cg.target);1122 const valtype = typeToValtype(ty, zcu, cg.target);
1123 const index_or_null = switch (valtype) {1123 const index_or_null = switch (valtype) {
1124 .i32 => cg.free_locals_i32.popOrNull(),1124 .i32 => cg.free_locals_i32.pop(),
1125 .i64 => cg.free_locals_i64.popOrNull(),1125 .i64 => cg.free_locals_i64.pop(),
1126 .f32 => cg.free_locals_f32.popOrNull(),1126 .f32 => cg.free_locals_f32.pop(),
1127 .f64 => cg.free_locals_f64.popOrNull(),1127 .f64 => cg.free_locals_f64.pop(),
1128 .v128 => cg.free_locals_v128.popOrNull(),1128 .v128 => cg.free_locals_v128.pop(),
1129 };1129 };
1130 if (index_or_null) |index| {1130 if (index_or_null) |index| {
1131 log.debug("reusing local ({d}) of type {}", .{ index, valtype });1131 log.debug("reusing local ({d}) of type {}", .{ index, valtype });
...@@ -1309,7 +1309,7 @@ fn functionInner(cg: *CodeGen, any_returns: bool) InnerError!Function {...@@ -1309,7 +1309,7 @@ fn functionInner(cg: *CodeGen, any_returns: bool) InnerError!Function {
1309 try cg.branches.append(cg.gpa, .{});1309 try cg.branches.append(cg.gpa, .{});
1310 // clean up outer branch1310 // clean up outer branch
1311 defer {1311 defer {
1312 var outer_branch = cg.branches.pop();1312 var outer_branch = cg.branches.pop().?;
1313 outer_branch.deinit(cg.gpa);1313 outer_branch.deinit(cg.gpa);
1314 assert(cg.branches.items.len == 0); // missing branch merge1314 assert(cg.branches.items.len == 0); // missing branch merge
1315 }1315 }
...@@ -3482,7 +3482,7 @@ fn airCondBr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -3482,7 +3482,7 @@ fn airCondBr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
3482 cg.branches.appendAssumeCapacity(.{});3482 cg.branches.appendAssumeCapacity(.{});
3483 try cg.currentBranch().values.ensureUnusedCapacity(cg.gpa, @as(u32, @intCast(liveness_condbr.else_deaths.len)));3483 try cg.currentBranch().values.ensureUnusedCapacity(cg.gpa, @as(u32, @intCast(liveness_condbr.else_deaths.len)));
3484 defer {3484 defer {
3485 var else_stack = cg.branches.pop();3485 var else_stack = cg.branches.pop().?;
3486 else_stack.deinit(cg.gpa);3486 else_stack.deinit(cg.gpa);
3487 }3487 }
3488 try cg.genBody(else_body);3488 try cg.genBody(else_body);
...@@ -3494,7 +3494,7 @@ fn airCondBr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -3494,7 +3494,7 @@ fn airCondBr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
3494 cg.branches.appendAssumeCapacity(.{});3494 cg.branches.appendAssumeCapacity(.{});
3495 try cg.currentBranch().values.ensureUnusedCapacity(cg.gpa, @as(u32, @intCast(liveness_condbr.then_deaths.len)));3495 try cg.currentBranch().values.ensureUnusedCapacity(cg.gpa, @as(u32, @intCast(liveness_condbr.then_deaths.len)));
3496 defer {3496 defer {
3497 var then_stack = cg.branches.pop();3497 var then_stack = cg.branches.pop().?;
3498 then_stack.deinit(cg.gpa);3498 then_stack.deinit(cg.gpa);
3499 }3499 }
3500 try cg.genBody(then_body);3500 try cg.genBody(then_body);
...@@ -4132,7 +4132,7 @@ fn airSwitchBr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4132,7 +4132,7 @@ fn airSwitchBr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4132 cg.branches.appendAssumeCapacity(.{});4132 cg.branches.appendAssumeCapacity(.{});
4133 try cg.currentBranch().values.ensureUnusedCapacity(cg.gpa, liveness.deaths[index].len);4133 try cg.currentBranch().values.ensureUnusedCapacity(cg.gpa, liveness.deaths[index].len);
4134 defer {4134 defer {
4135 var case_branch = cg.branches.pop();4135 var case_branch = cg.branches.pop().?;
4136 case_branch.deinit(cg.gpa);4136 case_branch.deinit(cg.gpa);
4137 }4137 }
4138 try cg.genBody(case.body);4138 try cg.genBody(case.body);
...@@ -4144,7 +4144,7 @@ fn airSwitchBr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4144,7 +4144,7 @@ fn airSwitchBr(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4144 const else_deaths = liveness.deaths.len - 1;4144 const else_deaths = liveness.deaths.len - 1;
4145 try cg.currentBranch().values.ensureUnusedCapacity(cg.gpa, liveness.deaths[else_deaths].len);4145 try cg.currentBranch().values.ensureUnusedCapacity(cg.gpa, liveness.deaths[else_deaths].len);
4146 defer {4146 defer {
4147 var else_branch = cg.branches.pop();4147 var else_branch = cg.branches.pop().?;
4148 else_branch.deinit(cg.gpa);4148 else_branch.deinit(cg.gpa);
4149 }4149 }
4150 try cg.genBody(else_body);4150 try cg.genBody(else_body);
...@@ -6459,7 +6459,7 @@ fn lowerTry(...@@ -6459,7 +6459,7 @@ fn lowerTry(
6459 try cg.branches.append(cg.gpa, .{});6459 try cg.branches.append(cg.gpa, .{});
6460 try cg.currentBranch().values.ensureUnusedCapacity(cg.gpa, liveness.else_deaths.len + liveness.then_deaths.len);6460 try cg.currentBranch().values.ensureUnusedCapacity(cg.gpa, liveness.else_deaths.len + liveness.then_deaths.len);
6461 defer {6461 defer {
6462 var branch = cg.branches.pop();6462 var branch = cg.branches.pop().?;
6463 branch.deinit(cg.gpa);6463 branch.deinit(cg.gpa);
6464 }6464 }
6465 try cg.genBody(body);6465 try cg.genBody(body);
src/link.zig+1-1
...@@ -1888,7 +1888,7 @@ pub fn resolveInputs(...@@ -1888,7 +1888,7 @@ pub fn resolveInputs(
1888 // that this library search logic can be applied to them.1888 // that this library search logic can be applied to them.
1889 mem.reverse(UnresolvedInput, unresolved_inputs.items);1889 mem.reverse(UnresolvedInput, unresolved_inputs.items);
18901890
1891 syslib: while (unresolved_inputs.popOrNull()) |unresolved_input| {1891 syslib: while (unresolved_inputs.pop()) |unresolved_input| {
1892 const name_query: UnresolvedInput.NameQuery = switch (unresolved_input) {1892 const name_query: UnresolvedInput.NameQuery = switch (unresolved_input) {
1893 .name_query => |nq| nq,1893 .name_query => |nq| nq,
1894 .ambiguous_name => |an| an: {1894 .ambiguous_name => |an| an: {
src/link/Coff.zig+4-4
...@@ -707,7 +707,7 @@ pub fn allocateSymbol(coff: *Coff) !u32 {...@@ -707,7 +707,7 @@ pub fn allocateSymbol(coff: *Coff) !u32 {
707 try coff.locals.ensureUnusedCapacity(gpa, 1);707 try coff.locals.ensureUnusedCapacity(gpa, 1);
708708
709 const index = blk: {709 const index = blk: {
710 if (coff.locals_free_list.popOrNull()) |index| {710 if (coff.locals_free_list.pop()) |index| {
711 log.debug(" (reusing symbol index {d})", .{index});711 log.debug(" (reusing symbol index {d})", .{index});
712 break :blk index;712 break :blk index;
713 } else {713 } else {
...@@ -735,7 +735,7 @@ fn allocateGlobal(coff: *Coff) !u32 {...@@ -735,7 +735,7 @@ fn allocateGlobal(coff: *Coff) !u32 {
735 try coff.globals.ensureUnusedCapacity(gpa, 1);735 try coff.globals.ensureUnusedCapacity(gpa, 1);
736736
737 const index = blk: {737 const index = blk: {
738 if (coff.globals_free_list.popOrNull()) |index| {738 if (coff.globals_free_list.pop()) |index| {
739 log.debug(" (reusing global index {d})", .{index});739 log.debug(" (reusing global index {d})", .{index});
740 break :blk index;740 break :blk index;
741 } else {741 } else {
...@@ -861,7 +861,7 @@ fn writeAtom(coff: *Coff, atom_index: Atom.Index, code: []u8) !void {...@@ -861,7 +861,7 @@ fn writeAtom(coff: *Coff, atom_index: Atom.Index, code: []u8) !void {
861 try coff.pwriteAll(code, file_offset);861 try coff.pwriteAll(code, file_offset);
862862
863 // Now we can mark the relocs as resolved.863 // Now we can mark the relocs as resolved.
864 while (relocs.popOrNull()) |reloc| {864 while (relocs.pop()) |reloc| {
865 reloc.dirty = false;865 reloc.dirty = false;
866 }866 }
867}867}
...@@ -3670,7 +3670,7 @@ const ImportTable = struct {...@@ -3670,7 +3670,7 @@ const ImportTable = struct {
3670 fn addImport(itab: *ImportTable, allocator: Allocator, target: SymbolWithLoc) !ImportIndex {3670 fn addImport(itab: *ImportTable, allocator: Allocator, target: SymbolWithLoc) !ImportIndex {
3671 try itab.entries.ensureUnusedCapacity(allocator, 1);3671 try itab.entries.ensureUnusedCapacity(allocator, 1);
3672 const index: u32 = blk: {3672 const index: u32 = blk: {
3673 if (itab.free_list.popOrNull()) |index| {3673 if (itab.free_list.pop()) |index| {
3674 log.debug(" (reusing import entry index {d})", .{index});3674 log.debug(" (reusing import entry index {d})", .{index});
3675 break :blk index;3675 break :blk index;
3676 } else {3676 } else {
src/link/Dwarf.zig+4-4
...@@ -363,7 +363,7 @@ pub const Section = struct {...@@ -363,7 +363,7 @@ pub const Section = struct {
363 fn popUnit(sec: *Section, gpa: std.mem.Allocator) void {363 fn popUnit(sec: *Section, gpa: std.mem.Allocator) void {
364 const unit_index: Unit.Index = @enumFromInt(sec.units.items.len - 1);364 const unit_index: Unit.Index = @enumFromInt(sec.units.items.len - 1);
365 sec.unlinkUnit(unit_index);365 sec.unlinkUnit(unit_index);
366 var unit = sec.units.pop();366 var unit = sec.units.pop().?;
367 unit.deinit(gpa);367 unit.deinit(gpa);
368 }368 }
369369
...@@ -1559,7 +1559,7 @@ pub const WipNav = struct {...@@ -1559,7 +1559,7 @@ pub const WipNav = struct {
15591559
1560 pub fn leaveBlock(wip_nav: *WipNav, code_off: u64) UpdateError!void {1560 pub fn leaveBlock(wip_nav: *WipNav, code_off: u64) UpdateError!void {
1561 const block_bytes = comptime uleb128Bytes(@intFromEnum(AbbrevCode.block));1561 const block_bytes = comptime uleb128Bytes(@intFromEnum(AbbrevCode.block));
1562 const block = wip_nav.blocks.pop();1562 const block = wip_nav.blocks.pop().?;
1563 if (wip_nav.any_children)1563 if (wip_nav.any_children)
1564 try uleb128(wip_nav.debug_info.writer(wip_nav.dwarf.gpa), @intFromEnum(AbbrevCode.null))1564 try uleb128(wip_nav.debug_info.writer(wip_nav.dwarf.gpa), @intFromEnum(AbbrevCode.null))
1565 else1565 else
...@@ -1599,7 +1599,7 @@ pub const WipNav = struct {...@@ -1599,7 +1599,7 @@ pub const WipNav = struct {
15991599
1600 pub fn leaveInlineFunc(wip_nav: *WipNav, func: InternPool.Index, code_off: u64) UpdateError!void {1600 pub fn leaveInlineFunc(wip_nav: *WipNav, func: InternPool.Index, code_off: u64) UpdateError!void {
1601 const inlined_func_bytes = comptime uleb128Bytes(@intFromEnum(AbbrevCode.inlined_func));1601 const inlined_func_bytes = comptime uleb128Bytes(@intFromEnum(AbbrevCode.inlined_func));
1602 const block = wip_nav.blocks.pop();1602 const block = wip_nav.blocks.pop().?;
1603 if (wip_nav.any_children)1603 if (wip_nav.any_children)
1604 try uleb128(wip_nav.debug_info.writer(wip_nav.dwarf.gpa), @intFromEnum(AbbrevCode.null))1604 try uleb128(wip_nav.debug_info.writer(wip_nav.dwarf.gpa), @intFromEnum(AbbrevCode.null))
1605 else1605 else
...@@ -2054,7 +2054,7 @@ pub const WipNav = struct {...@@ -2054,7 +2054,7 @@ pub const WipNav = struct {
20542054
2055 fn updateLazy(wip_nav: *WipNav, src_loc: Zcu.LazySrcLoc) UpdateError!void {2055 fn updateLazy(wip_nav: *WipNav, src_loc: Zcu.LazySrcLoc) UpdateError!void {
2056 const ip = &wip_nav.pt.zcu.intern_pool;2056 const ip = &wip_nav.pt.zcu.intern_pool;
2057 while (wip_nav.pending_lazy.popOrNull()) |val| switch (ip.typeOf(val)) {2057 while (wip_nav.pending_lazy.pop()) |val| switch (ip.typeOf(val)) {
2058 .type_type => try wip_nav.dwarf.updateLazyType(wip_nav.pt, src_loc, val, &wip_nav.pending_lazy),2058 .type_type => try wip_nav.dwarf.updateLazyType(wip_nav.pt, src_loc, val, &wip_nav.pending_lazy),
2059 else => try wip_nav.dwarf.updateLazyValue(wip_nav.pt, src_loc, val, &wip_nav.pending_lazy),2059 else => try wip_nav.dwarf.updateLazyValue(wip_nav.pt, src_loc, val, &wip_nav.pending_lazy),
2060 };2060 };
src/link/Plan9.zig+2-2
...@@ -515,7 +515,7 @@ fn updateFinish(self: *Plan9, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index...@@ -515,7 +515,7 @@ fn updateFinish(self: *Plan9, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index
515515
516fn allocateSymbolIndex(self: *Plan9) !usize {516fn allocateSymbolIndex(self: *Plan9) !usize {
517 const gpa = self.base.comp.gpa;517 const gpa = self.base.comp.gpa;
518 if (self.syms_index_free_list.popOrNull()) |i| {518 if (self.syms_index_free_list.pop()) |i| {
519 return i;519 return i;
520 } else {520 } else {
521 _ = try self.syms.addOne(gpa);521 _ = try self.syms.addOne(gpa);
...@@ -524,7 +524,7 @@ fn allocateSymbolIndex(self: *Plan9) !usize {...@@ -524,7 +524,7 @@ fn allocateSymbolIndex(self: *Plan9) !usize {
524}524}
525525
526fn allocateGotIndex(self: *Plan9) usize {526fn allocateGotIndex(self: *Plan9) usize {
527 if (self.got_index_free_list.popOrNull()) |i| {527 if (self.got_index_free_list.pop()) |i| {
528 return i;528 return i;
529 } else {529 } else {
530 self.got_len += 1;530 self.got_len += 1;
src/link/table_section.zig+1-1
...@@ -13,7 +13,7 @@ pub fn TableSection(comptime Entry: type) type {...@@ -13,7 +13,7 @@ pub fn TableSection(comptime Entry: type) type {
13 pub fn allocateEntry(self: *Self, allocator: Allocator, entry: Entry) Allocator.Error!Index {13 pub fn allocateEntry(self: *Self, allocator: Allocator, entry: Entry) Allocator.Error!Index {
14 try self.entries.ensureUnusedCapacity(allocator, 1);14 try self.entries.ensureUnusedCapacity(allocator, 1);
15 const index = blk: {15 const index = blk: {
16 if (self.free_list.popOrNull()) |index| {16 if (self.free_list.pop()) |index| {
17 log.debug(" (reusing entry index {d})", .{index});17 log.debug(" (reusing entry index {d})", .{index});
18 break :blk index;18 break :blk index;
19 } else {19 } else {
tools/process_headers.zig+3-3
...@@ -192,7 +192,7 @@ pub fn main() !void {...@@ -192,7 +192,7 @@ pub fn main() !void {
192 var dir_stack = std.ArrayList([]const u8).init(allocator);192 var dir_stack = std.ArrayList([]const u8).init(allocator);
193 try dir_stack.append(target_include_dir);193 try dir_stack.append(target_include_dir);
194194
195 while (dir_stack.popOrNull()) |full_dir_name| {195 while (dir_stack.pop()) |full_dir_name| {
196 var dir = std.fs.cwd().openDir(full_dir_name, .{ .iterate = true }) catch |err| switch (err) {196 var dir = std.fs.cwd().openDir(full_dir_name, .{ .iterate = true }) catch |err| switch (err) {
197 error.FileNotFound => continue :search,197 error.FileNotFound => continue :search,
198 error.AccessDenied => continue :search,198 error.AccessDenied => continue :search,
...@@ -273,14 +273,14 @@ pub fn main() !void {...@@ -273,14 +273,14 @@ pub fn main() !void {
273 }273 }
274 }274 }
275 std.mem.sort(*Contents, contents_list.items, {}, Contents.hitCountLessThan);275 std.mem.sort(*Contents, contents_list.items, {}, Contents.hitCountLessThan);
276 const best_contents = contents_list.popOrNull().?;276 const best_contents = contents_list.pop().?;
277 if (best_contents.hit_count > 1) {277 if (best_contents.hit_count > 1) {
278 // worth it to make it generic278 // worth it to make it generic
279 const full_path = try std.fs.path.join(allocator, &[_][]const u8{ out_dir, generic_name, path_kv.key_ptr.* });279 const full_path = try std.fs.path.join(allocator, &[_][]const u8{ out_dir, generic_name, path_kv.key_ptr.* });
280 try std.fs.cwd().makePath(std.fs.path.dirname(full_path).?);280 try std.fs.cwd().makePath(std.fs.path.dirname(full_path).?);
281 try std.fs.cwd().writeFile(.{ .sub_path = full_path, .data = best_contents.bytes });281 try std.fs.cwd().writeFile(.{ .sub_path = full_path, .data = best_contents.bytes });
282 best_contents.is_generic = true;282 best_contents.is_generic = true;
283 while (contents_list.popOrNull()) |contender| {283 while (contents_list.pop()) |contender| {
284 if (contender.hit_count > 1) {284 if (contender.hit_count > 1) {
285 const this_missed_bytes = contender.hit_count * contender.bytes.len;285 const this_missed_bytes = contender.hit_count * contender.bytes.len;
286 missed_opportunity_bytes += this_missed_bytes;286 missed_opportunity_bytes += this_missed_bytes;
tools/update-linux-headers.zig+3-3
...@@ -189,7 +189,7 @@ pub fn main() !void {...@@ -189,7 +189,7 @@ pub fn main() !void {
189 var dir_stack = std.ArrayList([]const u8).init(arena);189 var dir_stack = std.ArrayList([]const u8).init(arena);
190 try dir_stack.append(target_include_dir);190 try dir_stack.append(target_include_dir);
191191
192 while (dir_stack.popOrNull()) |full_dir_name| {192 while (dir_stack.pop()) |full_dir_name| {
193 var dir = std.fs.cwd().openDir(full_dir_name, .{ .iterate = true }) catch |err| switch (err) {193 var dir = std.fs.cwd().openDir(full_dir_name, .{ .iterate = true }) catch |err| switch (err) {
194 error.FileNotFound => continue :search,194 error.FileNotFound => continue :search,
195 error.AccessDenied => continue :search,195 error.AccessDenied => continue :search,
...@@ -270,14 +270,14 @@ pub fn main() !void {...@@ -270,14 +270,14 @@ pub fn main() !void {
270 }270 }
271 }271 }
272 std.mem.sort(*Contents, contents_list.items, {}, Contents.hitCountLessThan);272 std.mem.sort(*Contents, contents_list.items, {}, Contents.hitCountLessThan);
273 const best_contents = contents_list.popOrNull().?;273 const best_contents = contents_list.pop().?;
274 if (best_contents.hit_count > 1) {274 if (best_contents.hit_count > 1) {
275 // worth it to make it generic275 // worth it to make it generic
276 const full_path = try std.fs.path.join(arena, &[_][]const u8{ out_dir, generic_name, path_kv.key_ptr.* });276 const full_path = try std.fs.path.join(arena, &[_][]const u8{ out_dir, generic_name, path_kv.key_ptr.* });
277 try std.fs.cwd().makePath(std.fs.path.dirname(full_path).?);277 try std.fs.cwd().makePath(std.fs.path.dirname(full_path).?);
278 try std.fs.cwd().writeFile(.{ .sub_path = full_path, .data = best_contents.bytes });278 try std.fs.cwd().writeFile(.{ .sub_path = full_path, .data = best_contents.bytes });
279 best_contents.is_generic = true;279 best_contents.is_generic = true;
280 while (contents_list.popOrNull()) |contender| {280 while (contents_list.pop()) |contender| {
281 if (contender.hit_count > 1) {281 if (contender.hit_count > 1) {
282 const this_missed_bytes = contender.hit_count * contender.bytes.len;282 const this_missed_bytes = contender.hit_count * contender.bytes.len;
283 missed_opportunity_bytes += this_missed_bytes;283 missed_opportunity_bytes += this_missed_bytes;