aboutsummaryrefslogtreecommitdiff
path: root/lib/std
diff options
context:
space:
mode:
authorMeghan Denny <hello@nektro.net>2025-02-09 20:21:31 -0800
committerGitHub <noreply@github.com>2025-02-10 04:21:31 +0000
commit91424823724de866776c8b6a999ea45f1ca9d374 (patch)
tree43c794431c7e5d83dc434117cca5884d8e01c672 /lib/std
parent75df7e502c05e7e6a9b00a5a28854ae4a1aa8ea6 (diff)
downloadzig-91424823724de866776c8b6a999ea45f1ca9d374.tar.gz
zig-91424823724de866776c8b6a999ea45f1ca9d374.zip
std.ArrayList: popOrNull() -> pop() [v2] (#22720)
Diffstat (limited to 'lib/std')
-rw-r--r--lib/std/Build/Step/ConfigHeader.zig2
-rw-r--r--lib/std/array_list.zig47
-rw-r--r--lib/std/debug/Dwarf/expression.zig136
-rw-r--r--lib/std/debug/SelfInfo.zig2
-rw-r--r--lib/std/fs/Dir.zig4
-rw-r--r--lib/std/heap.zig2
-rw-r--r--lib/std/heap/debug_allocator.zig6
-rw-r--r--lib/std/json/dynamic.zig4
8 files changed, 94 insertions, 109 deletions
diff --git a/lib/std/Build/Step/ConfigHeader.zig b/lib/std/Build/Step/ConfigHeader.zig
index fe16532dc3..f474c38ff0 100644
--- a/lib/std/Build/Step/ConfigHeader.zig
+++ b/lib/std/Build/Step/ConfigHeader.zig
@@ -616,7 +616,7 @@ fn expand_variables_cmake(
// no open bracket, preserve as a literal
break :blk;
}
- const open_pos = var_stack.pop();
+ const open_pos = var_stack.pop().?;
if (source_offset == open_pos.source) {
source_offset += open_var.len;
}
diff --git a/lib/std/array_list.zig b/lib/std/array_list.zig
index 55b6e3cc40..11419f975a 100644
--- a/lib/std/array_list.zig
+++ b/lib/std/array_list.zig
@@ -289,10 +289,10 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
/// Asserts that the list is not empty.
/// Asserts that the index is in bounds.
pub fn swapRemove(self: *Self, i: usize) T {
- if (self.items.len - 1 == i) return self.pop();
+ if (self.items.len - 1 == i) return self.pop().?;
const old_item = self.items[i];
- self.items[i] = self.pop();
+ self.items[i] = self.pop().?;
return old_item;
}
@@ -555,23 +555,15 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
return self.items[prev_len..][0..n];
}
- /// Remove and return the last element from the list.
- /// Invalidates element pointers to the removed element.
- /// Asserts that the list is not empty.
- pub fn pop(self: *Self) T {
+ /// Remove and return the last element from the list, or return `null` if list is empty.
+ /// Invalidates element pointers to the removed element, if any.
+ pub fn pop(self: *Self) ?T {
+ if (self.items.len == 0) return null;
const val = self.items[self.items.len - 1];
self.items.len -= 1;
return val;
}
- /// Remove and return the last element from the list, or
- /// return `null` if list is empty.
- /// Invalidates element pointers to the removed element, if any.
- pub fn popOrNull(self: *Self) ?T {
- if (self.items.len == 0) return null;
- return self.pop();
- }
-
/// Returns a slice of all the items plus the extra capacity, whose memory
/// contents are `undefined`.
pub fn allocatedSlice(self: Self) Slice {
@@ -897,10 +889,10 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
/// Asserts that the list is not empty.
/// Asserts that the index is in bounds.
pub fn swapRemove(self: *Self, i: usize) T {
- if (self.items.len - 1 == i) return self.pop();
+ if (self.items.len - 1 == i) return self.pop().?;
const old_item = self.items[i];
- self.items[i] = self.pop();
+ self.items[i] = self.pop().?;
return old_item;
}
@@ -1190,22 +1182,15 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
}
/// Remove and return the last element from the list.
+ /// If the list is empty, returns `null`.
/// Invalidates pointers to last element.
- /// Asserts that the list is not empty.
- pub fn pop(self: *Self) T {
+ pub fn pop(self: *Self) ?T {
+ if (self.items.len == 0) return null;
const val = self.items[self.items.len - 1];
self.items.len -= 1;
return val;
}
- /// Remove and return the last element from the list.
- /// If the list is empty, returns `null`.
- /// Invalidates pointers to last element.
- pub fn popOrNull(self: *Self) ?T {
- if (self.items.len == 0) return null;
- return self.pop();
- }
-
/// Returns a slice of all the items plus the extra capacity, whose memory
/// contents are `undefined`.
pub fn allocatedSlice(self: Self) Slice {
@@ -2184,7 +2169,7 @@ test "ArrayList(u0)" {
try testing.expectEqual(count, 3);
}
-test "ArrayList(?u32).popOrNull()" {
+test "ArrayList(?u32).pop()" {
const a = testing.allocator;
var list = ArrayList(?u32).init(a);
@@ -2195,10 +2180,10 @@ test "ArrayList(?u32).popOrNull()" {
try list.append(2);
try testing.expectEqual(list.items.len, 3);
- try testing.expect(list.popOrNull().? == @as(u32, 2));
- try testing.expect(list.popOrNull().? == @as(u32, 1));
- try testing.expect(list.popOrNull().? == null);
- try testing.expect(list.popOrNull() == null);
+ try testing.expect(list.pop().? == @as(u32, 2));
+ try testing.expect(list.pop().? == @as(u32, 1));
+ try testing.expect(list.pop().? == null);
+ try testing.expect(list.pop() == null);
}
test "ArrayList(u32).getLast()" {
diff --git a/lib/std/debug/Dwarf/expression.zig b/lib/std/debug/Dwarf/expression.zig
index 38bce2614c..c0ebea7504 100644
--- a/lib/std/debug/Dwarf/expression.zig
+++ b/lib/std/debug/Dwarf/expression.zig
@@ -527,14 +527,14 @@ pub fn StackMachine(comptime options: Options) type {
},
OP.@"and" => {
if (self.stack.items.len < 2) return error.InvalidExpression;
- const a = try self.stack.pop().asIntegral();
+ const a = try self.stack.pop().?.asIntegral();
self.stack.items[self.stack.items.len - 1] = .{
.generic = a & try self.stack.items[self.stack.items.len - 1].asIntegral(),
};
},
OP.div => {
if (self.stack.items.len < 2) return error.InvalidExpression;
- const a: isize = @bitCast(try self.stack.pop().asIntegral());
+ const a: isize = @bitCast(try self.stack.pop().?.asIntegral());
const b: isize = @bitCast(try self.stack.items[self.stack.items.len - 1].asIntegral());
self.stack.items[self.stack.items.len - 1] = .{
.generic = @bitCast(try std.math.divTrunc(isize, b, a)),
@@ -542,14 +542,14 @@ pub fn StackMachine(comptime options: Options) type {
},
OP.minus => {
if (self.stack.items.len < 2) return error.InvalidExpression;
- const b = try self.stack.pop().asIntegral();
+ const b = try self.stack.pop().?.asIntegral();
self.stack.items[self.stack.items.len - 1] = .{
.generic = try std.math.sub(addr_type, try self.stack.items[self.stack.items.len - 1].asIntegral(), b),
};
},
OP.mod => {
if (self.stack.items.len < 2) return error.InvalidExpression;
- const a: isize = @bitCast(try self.stack.pop().asIntegral());
+ const a: isize = @bitCast(try self.stack.pop().?.asIntegral());
const b: isize = @bitCast(try self.stack.items[self.stack.items.len - 1].asIntegral());
self.stack.items[self.stack.items.len - 1] = .{
.generic = @bitCast(@mod(b, a)),
@@ -557,7 +557,7 @@ pub fn StackMachine(comptime options: Options) type {
},
OP.mul => {
if (self.stack.items.len < 2) return error.InvalidExpression;
- const a: isize = @bitCast(try self.stack.pop().asIntegral());
+ const a: isize = @bitCast(try self.stack.pop().?.asIntegral());
const b: isize = @bitCast(try self.stack.items[self.stack.items.len - 1].asIntegral());
self.stack.items[self.stack.items.len - 1] = .{
.generic = @bitCast(@mulWithOverflow(a, b)[0]),
@@ -581,14 +581,14 @@ pub fn StackMachine(comptime options: Options) type {
},
OP.@"or" => {
if (self.stack.items.len < 2) return error.InvalidExpression;
- const a = try self.stack.pop().asIntegral();
+ const a = try self.stack.pop().?.asIntegral();
self.stack.items[self.stack.items.len - 1] = .{
.generic = a | try self.stack.items[self.stack.items.len - 1].asIntegral(),
};
},
OP.plus => {
if (self.stack.items.len < 2) return error.InvalidExpression;
- const b = try self.stack.pop().asIntegral();
+ const b = try self.stack.pop().?.asIntegral();
self.stack.items[self.stack.items.len - 1] = .{
.generic = try std.math.add(addr_type, try self.stack.items[self.stack.items.len - 1].asIntegral(), b),
};
@@ -602,7 +602,7 @@ pub fn StackMachine(comptime options: Options) type {
},
OP.shl => {
if (self.stack.items.len < 2) return error.InvalidExpression;
- const a = try self.stack.pop().asIntegral();
+ const a = try self.stack.pop().?.asIntegral();
const b = try self.stack.items[self.stack.items.len - 1].asIntegral();
self.stack.items[self.stack.items.len - 1] = .{
.generic = std.math.shl(usize, b, a),
@@ -610,7 +610,7 @@ pub fn StackMachine(comptime options: Options) type {
},
OP.shr => {
if (self.stack.items.len < 2) return error.InvalidExpression;
- const a = try self.stack.pop().asIntegral();
+ const a = try self.stack.pop().?.asIntegral();
const b = try self.stack.items[self.stack.items.len - 1].asIntegral();
self.stack.items[self.stack.items.len - 1] = .{
.generic = std.math.shr(usize, b, a),
@@ -618,7 +618,7 @@ pub fn StackMachine(comptime options: Options) type {
},
OP.shra => {
if (self.stack.items.len < 2) return error.InvalidExpression;
- const a = try self.stack.pop().asIntegral();
+ const a = try self.stack.pop().?.asIntegral();
const b: isize = @bitCast(try self.stack.items[self.stack.items.len - 1].asIntegral());
self.stack.items[self.stack.items.len - 1] = .{
.generic = @bitCast(std.math.shr(isize, b, a)),
@@ -626,7 +626,7 @@ pub fn StackMachine(comptime options: Options) type {
},
OP.xor => {
if (self.stack.items.len < 2) return error.InvalidExpression;
- const a = try self.stack.pop().asIntegral();
+ const a = try self.stack.pop().?.asIntegral();
self.stack.items[self.stack.items.len - 1] = .{
.generic = a ^ try self.stack.items[self.stack.items.len - 1].asIntegral(),
};
@@ -641,7 +641,7 @@ pub fn StackMachine(comptime options: Options) type {
OP.ne,
=> {
if (self.stack.items.len < 2) return error.InvalidExpression;
- const a = self.stack.pop();
+ const a = self.stack.pop().?;
const b = self.stack.items[self.stack.items.len - 1];
if (a == .generic and b == .generic) {
@@ -667,7 +667,7 @@ pub fn StackMachine(comptime options: Options) type {
const branch_offset = operand.?.branch_offset;
const condition = if (opcode == OP.bra) blk: {
if (self.stack.items.len == 0) return error.InvalidExpression;
- break :blk try self.stack.pop().asIntegral() != 0;
+ break :blk try self.stack.pop().?.asIntegral() != 0;
} else true;
if (condition) {
@@ -1080,7 +1080,7 @@ test "DWARF expressions" {
for (0..32) |i| {
const expected = 31 - i;
- try testing.expectEqual(expected, stack_machine.stack.popOrNull().?.generic);
+ try testing.expectEqual(expected, stack_machine.stack.pop().?.generic);
}
}
@@ -1141,7 +1141,7 @@ test "DWARF expressions" {
_ = try stack_machine.run(program.items, allocator, context, 0);
- const const_type = stack_machine.stack.popOrNull().?.const_type;
+ const const_type = stack_machine.stack.pop().?.const_type;
try testing.expectEqual(die_offset, const_type.type_offset);
try testing.expectEqualSlices(u8, type_bytes, const_type.value_bytes);
@@ -1162,7 +1162,7 @@ test "DWARF expressions" {
};
inline for (expected) |e| {
- try testing.expectEqual(@as(e[0], e[1]), @as(e[2], @bitCast(stack_machine.stack.popOrNull().?.generic)));
+ try testing.expectEqual(@as(e[0], e[1]), @as(e[2], @bitCast(stack_machine.stack.pop().?.generic)));
}
}
@@ -1199,14 +1199,14 @@ test "DWARF expressions" {
_ = try stack_machine.run(program.items, allocator, context, 0);
- const regval_type = stack_machine.stack.popOrNull().?.regval_type;
+ const regval_type = stack_machine.stack.pop().?.regval_type;
try testing.expectEqual(@as(usize, 400), regval_type.type_offset);
try testing.expectEqual(@as(u8, @sizeOf(usize)), regval_type.type_size);
try testing.expectEqual(@as(usize, 0xee), regval_type.value);
- try testing.expectEqual(@as(usize, 303), stack_machine.stack.popOrNull().?.generic);
- try testing.expectEqual(@as(usize, 202), stack_machine.stack.popOrNull().?.generic);
- try testing.expectEqual(@as(usize, 101), stack_machine.stack.popOrNull().?.generic);
+ try testing.expectEqual(@as(usize, 303), stack_machine.stack.pop().?.generic);
+ try testing.expectEqual(@as(usize, 202), stack_machine.stack.pop().?.generic);
+ try testing.expectEqual(@as(usize, 101), stack_machine.stack.pop().?.generic);
} else |err| {
switch (err) {
error.UnimplementedArch,
@@ -1227,15 +1227,15 @@ test "DWARF expressions" {
try b.writeConst(writer, u8, 1);
try b.writeOpcode(writer, OP.dup);
_ = try stack_machine.run(program.items, allocator, context, null);
- try testing.expectEqual(@as(usize, 1), stack_machine.stack.popOrNull().?.generic);
- try testing.expectEqual(@as(usize, 1), stack_machine.stack.popOrNull().?.generic);
+ try testing.expectEqual(@as(usize, 1), stack_machine.stack.pop().?.generic);
+ try testing.expectEqual(@as(usize, 1), stack_machine.stack.pop().?.generic);
stack_machine.reset();
program.clearRetainingCapacity();
try b.writeConst(writer, u8, 1);
try b.writeOpcode(writer, OP.drop);
_ = try stack_machine.run(program.items, allocator, context, null);
- try testing.expect(stack_machine.stack.popOrNull() == null);
+ try testing.expect(stack_machine.stack.pop() == null);
stack_machine.reset();
program.clearRetainingCapacity();
@@ -1244,7 +1244,7 @@ test "DWARF expressions" {
try b.writeConst(writer, u8, 6);
try b.writePick(writer, 2);
_ = try stack_machine.run(program.items, allocator, context, null);
- try testing.expectEqual(@as(usize, 4), stack_machine.stack.popOrNull().?.generic);
+ try testing.expectEqual(@as(usize, 4), stack_machine.stack.pop().?.generic);
stack_machine.reset();
program.clearRetainingCapacity();
@@ -1253,7 +1253,7 @@ test "DWARF expressions" {
try b.writeConst(writer, u8, 6);
try b.writeOpcode(writer, OP.over);
_ = try stack_machine.run(program.items, allocator, context, null);
- try testing.expectEqual(@as(usize, 5), stack_machine.stack.popOrNull().?.generic);
+ try testing.expectEqual(@as(usize, 5), stack_machine.stack.pop().?.generic);
stack_machine.reset();
program.clearRetainingCapacity();
@@ -1261,8 +1261,8 @@ test "DWARF expressions" {
try b.writeConst(writer, u8, 6);
try b.writeOpcode(writer, OP.swap);
_ = try stack_machine.run(program.items, allocator, context, null);
- try testing.expectEqual(@as(usize, 5), stack_machine.stack.popOrNull().?.generic);
- try testing.expectEqual(@as(usize, 6), stack_machine.stack.popOrNull().?.generic);
+ try testing.expectEqual(@as(usize, 5), stack_machine.stack.pop().?.generic);
+ try testing.expectEqual(@as(usize, 6), stack_machine.stack.pop().?.generic);
stack_machine.reset();
program.clearRetainingCapacity();
@@ -1271,9 +1271,9 @@ test "DWARF expressions" {
try b.writeConst(writer, u8, 6);
try b.writeOpcode(writer, OP.rot);
_ = try stack_machine.run(program.items, allocator, context, null);
- try testing.expectEqual(@as(usize, 5), stack_machine.stack.popOrNull().?.generic);
- try testing.expectEqual(@as(usize, 4), stack_machine.stack.popOrNull().?.generic);
- try testing.expectEqual(@as(usize, 6), stack_machine.stack.popOrNull().?.generic);
+ try testing.expectEqual(@as(usize, 5), stack_machine.stack.pop().?.generic);
+ try testing.expectEqual(@as(usize, 4), stack_machine.stack.pop().?.generic);
+ try testing.expectEqual(@as(usize, 6), stack_machine.stack.pop().?.generic);
const deref_target: usize = @truncate(0xffeeffee_ffeeffee);
@@ -1282,7 +1282,7 @@ test "DWARF expressions" {
try b.writeAddr(writer, @intFromPtr(&deref_target));
try b.writeOpcode(writer, OP.deref);
_ = try stack_machine.run(program.items, allocator, context, null);
- try testing.expectEqual(deref_target, stack_machine.stack.popOrNull().?.generic);
+ try testing.expectEqual(deref_target, stack_machine.stack.pop().?.generic);
stack_machine.reset();
program.clearRetainingCapacity();
@@ -1290,14 +1290,14 @@ test "DWARF expressions" {
try b.writeAddr(writer, @intFromPtr(&deref_target));
try b.writeOpcode(writer, OP.xderef);
_ = try stack_machine.run(program.items, allocator, context, null);
- try testing.expectEqual(deref_target, stack_machine.stack.popOrNull().?.generic);
+ try testing.expectEqual(deref_target, stack_machine.stack.pop().?.generic);
stack_machine.reset();
program.clearRetainingCapacity();
try b.writeAddr(writer, @intFromPtr(&deref_target));
try b.writeDerefSize(writer, 1);
_ = try stack_machine.run(program.items, allocator, context, null);
- try testing.expectEqual(@as(usize, @as(*const u8, @ptrCast(&deref_target)).*), stack_machine.stack.popOrNull().?.generic);
+ try testing.expectEqual(@as(usize, @as(*const u8, @ptrCast(&deref_target)).*), stack_machine.stack.pop().?.generic);
stack_machine.reset();
program.clearRetainingCapacity();
@@ -1305,7 +1305,7 @@ test "DWARF expressions" {
try b.writeAddr(writer, @intFromPtr(&deref_target));
try b.writeXDerefSize(writer, 1);
_ = try stack_machine.run(program.items, allocator, context, null);
- try testing.expectEqual(@as(usize, @as(*const u8, @ptrCast(&deref_target)).*), stack_machine.stack.popOrNull().?.generic);
+ try testing.expectEqual(@as(usize, @as(*const u8, @ptrCast(&deref_target)).*), stack_machine.stack.pop().?.generic);
const type_offset: usize = @truncate(0xaabbaabb_aabbaabb);
@@ -1314,7 +1314,7 @@ test "DWARF expressions" {
try b.writeAddr(writer, @intFromPtr(&deref_target));
try b.writeDerefType(writer, 1, type_offset);
_ = try stack_machine.run(program.items, allocator, context, null);
- const deref_type = stack_machine.stack.popOrNull().?.regval_type;
+ const deref_type = stack_machine.stack.pop().?.regval_type;
try testing.expectEqual(type_offset, deref_type.type_offset);
try testing.expectEqual(@as(u8, 1), deref_type.type_size);
try testing.expectEqual(@as(usize, @as(*const u8, @ptrCast(&deref_target)).*), deref_type.value);
@@ -1325,7 +1325,7 @@ test "DWARF expressions" {
try b.writeAddr(writer, @intFromPtr(&deref_target));
try b.writeXDerefType(writer, 1, type_offset);
_ = try stack_machine.run(program.items, allocator, context, null);
- const xderef_type = stack_machine.stack.popOrNull().?.regval_type;
+ const xderef_type = stack_machine.stack.pop().?.regval_type;
try testing.expectEqual(type_offset, xderef_type.type_offset);
try testing.expectEqual(@as(u8, 1), xderef_type.type_size);
try testing.expectEqual(@as(usize, @as(*const u8, @ptrCast(&deref_target)).*), xderef_type.value);
@@ -1336,7 +1336,7 @@ test "DWARF expressions" {
program.clearRetainingCapacity();
try b.writeOpcode(writer, OP.push_object_address);
_ = try stack_machine.run(program.items, allocator, context, null);
- try testing.expectEqual(@as(usize, @intFromPtr(context.object_address.?)), stack_machine.stack.popOrNull().?.generic);
+ try testing.expectEqual(@as(usize, @intFromPtr(context.object_address.?)), stack_machine.stack.pop().?.generic);
// TODO: Test OP.form_tls_address
@@ -1346,7 +1346,7 @@ test "DWARF expressions" {
program.clearRetainingCapacity();
try b.writeOpcode(writer, OP.call_frame_cfa);
_ = try stack_machine.run(program.items, allocator, context, null);
- try testing.expectEqual(context.cfa.?, stack_machine.stack.popOrNull().?.generic);
+ try testing.expectEqual(context.cfa.?, stack_machine.stack.pop().?.generic);
}
// Arithmetic and Logical Operations
@@ -1358,7 +1358,7 @@ test "DWARF expressions" {
try b.writeConst(writer, i16, -4096);
try b.writeOpcode(writer, OP.abs);
_ = try stack_machine.run(program.items, allocator, context, null);
- try testing.expectEqual(@as(usize, 4096), stack_machine.stack.popOrNull().?.generic);
+ try testing.expectEqual(@as(usize, 4096), stack_machine.stack.pop().?.generic);
stack_machine.reset();
program.clearRetainingCapacity();
@@ -1366,7 +1366,7 @@ test "DWARF expressions" {
try b.writeConst(writer, u16, 0xf0ff);
try b.writeOpcode(writer, OP.@"and");
_ = try stack_machine.run(program.items, allocator, context, null);
- try testing.expectEqual(@as(usize, 0xf00f), stack_machine.stack.popOrNull().?.generic);
+ try testing.expectEqual(@as(usize, 0xf00f), stack_machine.stack.pop().?.generic);
stack_machine.reset();
program.clearRetainingCapacity();
@@ -1374,7 +1374,7 @@ test "DWARF expressions" {
try b.writeConst(writer, i16, 100);
try b.writeOpcode(writer, OP.div);
_ = try stack_machine.run(program.items, allocator, context, null);
- try testing.expectEqual(@as(isize, -404 / 100), @as(isize, @bitCast(stack_machine.stack.popOrNull().?.generic)));
+ try testing.expectEqual(@as(isize, -404 / 100), @as(isize, @bitCast(stack_machine.stack.pop().?.generic)));
stack_machine.reset();
program.clearRetainingCapacity();
@@ -1382,7 +1382,7 @@ test "DWARF expressions" {
try b.writeConst(writer, u16, 50);
try b.writeOpcode(writer, OP.minus);
_ = try stack_machine.run(program.items, allocator, context, null);
- try testing.expectEqual(@as(usize, 150), stack_machine.stack.popOrNull().?.generic);
+ try testing.expectEqual(@as(usize, 150), stack_machine.stack.pop().?.generic);
stack_machine.reset();
program.clearRetainingCapacity();
@@ -1390,7 +1390,7 @@ test "DWARF expressions" {
try b.writeConst(writer, u16, 100);
try b.writeOpcode(writer, OP.mod);
_ = try stack_machine.run(program.items, allocator, context, null);
- try testing.expectEqual(@as(usize, 23), stack_machine.stack.popOrNull().?.generic);
+ try testing.expectEqual(@as(usize, 23), stack_machine.stack.pop().?.generic);
stack_machine.reset();
program.clearRetainingCapacity();
@@ -1398,7 +1398,7 @@ test "DWARF expressions" {
try b.writeConst(writer, u16, 0xee);
try b.writeOpcode(writer, OP.mul);
_ = try stack_machine.run(program.items, allocator, context, null);
- try testing.expectEqual(@as(usize, 0xed12), stack_machine.stack.popOrNull().?.generic);
+ try testing.expectEqual(@as(usize, 0xed12), stack_machine.stack.pop().?.generic);
stack_machine.reset();
program.clearRetainingCapacity();
@@ -1407,15 +1407,15 @@ test "DWARF expressions" {
try b.writeConst(writer, i16, -6);
try b.writeOpcode(writer, OP.neg);
_ = try stack_machine.run(program.items, allocator, context, null);
- try testing.expectEqual(@as(usize, 6), stack_machine.stack.popOrNull().?.generic);
- try testing.expectEqual(@as(isize, -5), @as(isize, @bitCast(stack_machine.stack.popOrNull().?.generic)));
+ try testing.expectEqual(@as(usize, 6), stack_machine.stack.pop().?.generic);
+ try testing.expectEqual(@as(isize, -5), @as(isize, @bitCast(stack_machine.stack.pop().?.generic)));
stack_machine.reset();
program.clearRetainingCapacity();
try b.writeConst(writer, u16, 0xff0f);
try b.writeOpcode(writer, OP.not);
_ = try stack_machine.run(program.items, allocator, context, null);
- try testing.expectEqual(~@as(usize, 0xff0f), stack_machine.stack.popOrNull().?.generic);
+ try testing.expectEqual(~@as(usize, 0xff0f), stack_machine.stack.pop().?.generic);
stack_machine.reset();
program.clearRetainingCapacity();
@@ -1423,7 +1423,7 @@ test "DWARF expressions" {
try b.writeConst(writer, u16, 0xf0ff);
try b.writeOpcode(writer, OP.@"or");
_ = try stack_machine.run(program.items, allocator, context, null);
- try testing.expectEqual(@as(usize, 0xffff), stack_machine.stack.popOrNull().?.generic);
+ try testing.expectEqual(@as(usize, 0xffff), stack_machine.stack.pop().?.generic);
stack_machine.reset();
program.clearRetainingCapacity();
@@ -1431,14 +1431,14 @@ test "DWARF expressions" {
try b.writeConst(writer, i16, 100);
try b.writeOpcode(writer, OP.plus);
_ = try stack_machine.run(program.items, allocator, context, null);
- try testing.expectEqual(@as(usize, 502), stack_machine.stack.popOrNull().?.generic);
+ try testing.expectEqual(@as(usize, 502), stack_machine.stack.pop().?.generic);
stack_machine.reset();
program.clearRetainingCapacity();
try b.writeConst(writer, u16, 4096);
try b.writePlusUconst(writer, @as(usize, 8192));
_ = try stack_machine.run(program.items, allocator, context, null);
- try testing.expectEqual(@as(usize, 4096 + 8192), stack_machine.stack.popOrNull().?.generic);
+ try testing.expectEqual(@as(usize, 4096 + 8192), stack_machine.stack.pop().?.generic);
stack_machine.reset();
program.clearRetainingCapacity();
@@ -1446,7 +1446,7 @@ test "DWARF expressions" {
try b.writeConst(writer, u16, 1);
try b.writeOpcode(writer, OP.shl);
_ = try stack_machine.run(program.items, allocator, context, null);
- try testing.expectEqual(@as(usize, 0xfff << 1), stack_machine.stack.popOrNull().?.generic);
+ try testing.expectEqual(@as(usize, 0xfff << 1), stack_machine.stack.pop().?.generic);
stack_machine.reset();
program.clearRetainingCapacity();
@@ -1454,7 +1454,7 @@ test "DWARF expressions" {
try b.writeConst(writer, u16, 1);
try b.writeOpcode(writer, OP.shr);
_ = try stack_machine.run(program.items, allocator, context, null);
- try testing.expectEqual(@as(usize, 0xfff >> 1), stack_machine.stack.popOrNull().?.generic);
+ try testing.expectEqual(@as(usize, 0xfff >> 1), stack_machine.stack.pop().?.generic);
stack_machine.reset();
program.clearRetainingCapacity();
@@ -1462,7 +1462,7 @@ test "DWARF expressions" {
try b.writeConst(writer, u16, 1);
try b.writeOpcode(writer, OP.shr);
_ = try stack_machine.run(program.items, allocator, context, null);
- try testing.expectEqual(@as(usize, @bitCast(@as(isize, 0xfff) >> 1)), stack_machine.stack.popOrNull().?.generic);
+ try testing.expectEqual(@as(usize, @bitCast(@as(isize, 0xfff) >> 1)), stack_machine.stack.pop().?.generic);
stack_machine.reset();
program.clearRetainingCapacity();
@@ -1470,7 +1470,7 @@ test "DWARF expressions" {
try b.writeConst(writer, u16, 0xff0f);
try b.writeOpcode(writer, OP.xor);
_ = try stack_machine.run(program.items, allocator, context, null);
- try testing.expectEqual(@as(usize, 0x0ff0), stack_machine.stack.popOrNull().?.generic);
+ try testing.expectEqual(@as(usize, 0x0ff0), stack_machine.stack.pop().?.generic);
}
// Control Flow Operations
@@ -1499,9 +1499,9 @@ test "DWARF expressions" {
try b.writeConst(writer, u16, 0);
try b.writeOpcode(writer, e[0]);
_ = try stack_machine.run(program.items, allocator, context, null);
- try testing.expectEqual(@as(usize, e[3]), stack_machine.stack.popOrNull().?.generic);
- try testing.expectEqual(@as(usize, e[2]), stack_machine.stack.popOrNull().?.generic);
- try testing.expectEqual(@as(usize, e[1]), stack_machine.stack.popOrNull().?.generic);
+ try testing.expectEqual(@as(usize, e[3]), stack_machine.stack.pop().?.generic);
+ try testing.expectEqual(@as(usize, e[2]), stack_machine.stack.pop().?.generic);
+ try testing.expectEqual(@as(usize, e[1]), stack_machine.stack.pop().?.generic);
}
stack_machine.reset();
@@ -1510,7 +1510,7 @@ test "DWARF expressions" {
try b.writeSkip(writer, 1);
try b.writeLiteral(writer, 3);
_ = try stack_machine.run(program.items, allocator, context, null);
- try testing.expectEqual(@as(usize, 2), stack_machine.stack.popOrNull().?.generic);
+ try testing.expectEqual(@as(usize, 2), stack_machine.stack.pop().?.generic);
stack_machine.reset();
program.clearRetainingCapacity();
@@ -1522,9 +1522,9 @@ test "DWARF expressions" {
try b.writeLiteral(writer, 4);
try b.writeLiteral(writer, 5);
_ = try stack_machine.run(program.items, allocator, context, null);
- try testing.expectEqual(@as(usize, 5), stack_machine.stack.popOrNull().?.generic);
- try testing.expectEqual(@as(usize, 4), stack_machine.stack.popOrNull().?.generic);
- try testing.expect(stack_machine.stack.popOrNull() == null);
+ try testing.expectEqual(@as(usize, 5), stack_machine.stack.pop().?.generic);
+ try testing.expectEqual(@as(usize, 4), stack_machine.stack.pop().?.generic);
+ try testing.expect(stack_machine.stack.pop() == null);
// TODO: Test call2, call4, call_ref once implemented
@@ -1548,7 +1548,7 @@ test "DWARF expressions" {
try b.writeConstType(writer, @as(usize, 0), &value_bytes);
try b.writeConvert(writer, @as(usize, 0));
_ = try stack_machine.run(program.items, allocator, context, null);
- try testing.expectEqual(value, stack_machine.stack.popOrNull().?.generic);
+ try testing.expectEqual(value, stack_machine.stack.pop().?.generic);
// Reinterpret to generic type
stack_machine.reset();
@@ -1556,7 +1556,7 @@ test "DWARF expressions" {
try b.writeConstType(writer, @as(usize, 0), &value_bytes);
try b.writeReinterpret(writer, @as(usize, 0));
_ = try stack_machine.run(program.items, allocator, context, null);
- try testing.expectEqual(value, stack_machine.stack.popOrNull().?.generic);
+ try testing.expectEqual(value, stack_machine.stack.pop().?.generic);
// Reinterpret to new type
const die_offset: usize = 0xffee;
@@ -1566,7 +1566,7 @@ test "DWARF expressions" {
try b.writeConstType(writer, @as(usize, 0), &value_bytes);
try b.writeReinterpret(writer, die_offset);
_ = try stack_machine.run(program.items, allocator, context, null);
- const const_type = stack_machine.stack.popOrNull().?.const_type;
+ const const_type = stack_machine.stack.pop().?.const_type;
try testing.expectEqual(die_offset, const_type.type_offset);
stack_machine.reset();
@@ -1574,7 +1574,7 @@ test "DWARF expressions" {
try b.writeLiteral(writer, 0);
try b.writeReinterpret(writer, die_offset);
_ = try stack_machine.run(program.items, allocator, context, null);
- const regval_type = stack_machine.stack.popOrNull().?.regval_type;
+ const regval_type = stack_machine.stack.pop().?.regval_type;
try testing.expectEqual(die_offset, regval_type.type_offset);
}
@@ -1586,7 +1586,7 @@ test "DWARF expressions" {
program.clearRetainingCapacity();
try b.writeOpcode(writer, OP.nop);
_ = try stack_machine.run(program.items, allocator, context, null);
- try testing.expect(stack_machine.stack.popOrNull() == null);
+ try testing.expect(stack_machine.stack.pop() == null);
// Sub-expression
{
@@ -1599,7 +1599,7 @@ test "DWARF expressions" {
program.clearRetainingCapacity();
try b.writeEntryValue(writer, sub_program.items);
_ = try stack_machine.run(program.items, allocator, context, null);
- try testing.expectEqual(@as(usize, 3), stack_machine.stack.popOrNull().?.generic);
+ try testing.expectEqual(@as(usize, 3), stack_machine.stack.pop().?.generic);
}
// Register location description
@@ -1626,7 +1626,7 @@ test "DWARF expressions" {
program.clearRetainingCapacity();
try b.writeEntryValue(writer, sub_program.items);
_ = try stack_machine.run(program.items, allocator, context, null);
- try testing.expectEqual(@as(usize, 0xee), stack_machine.stack.popOrNull().?.generic);
+ try testing.expectEqual(@as(usize, 0xee), stack_machine.stack.pop().?.generic);
} else |err| {
switch (err) {
error.UnimplementedArch,
diff --git a/lib/std/debug/SelfInfo.zig b/lib/std/debug/SelfInfo.zig
index b51a8f18d2..3c4260b212 100644
--- a/lib/std/debug/SelfInfo.zig
+++ b/lib/std/debug/SelfInfo.zig
@@ -2138,7 +2138,7 @@ pub const VirtualMachine = struct {
self.current_row.copy_on_write = true;
},
.restore_state => {
- const restored_columns = self.stack.popOrNull() orelse return error.InvalidOperation;
+ const restored_columns = self.stack.pop() orelse return error.InvalidOperation;
self.columns.shrinkRetainingCapacity(self.columns.items.len - self.current_row.columns.len);
try self.columns.ensureUnusedCapacity(allocator, restored_columns.len);
diff --git a/lib/std/fs/Dir.zig b/lib/std/fs/Dir.zig
index eda4067beb..39aad8d42d 100644
--- a/lib/std/fs/Dir.zig
+++ b/lib/std/fs/Dir.zig
@@ -682,7 +682,7 @@ pub const Walker = struct {
// walking if they want, which means that we need to pop the directory
// that errored from the stack. Otherwise, all future `next` calls would
// likely just fail with the same error.
- var item = self.stack.pop();
+ var item = self.stack.pop().?;
if (self.stack.items.len != 0) {
item.iter.dir.close();
}
@@ -718,7 +718,7 @@ pub const Walker = struct {
.kind = base.kind,
};
} else {
- var item = self.stack.pop();
+ var item = self.stack.pop().?;
if (self.stack.items.len != 0) {
item.iter.dir.close();
}
diff --git a/lib/std/heap.zig b/lib/std/heap.zig
index b728d0da7e..5cc26e6beb 100644
--- a/lib/std/heap.zig
+++ b/lib/std/heap.zig
@@ -681,7 +681,7 @@ pub fn testAllocatorAlignedShrink(base_allocator: mem.Allocator) !void {
try stuff_to_free.append(slice);
slice = try allocator.alignedAlloc(u8, 16, alloc_size);
}
- while (stuff_to_free.popOrNull()) |item| {
+ while (stuff_to_free.pop()) |item| {
allocator.free(item);
}
slice[0] = 0x12;
diff --git a/lib/std/heap/debug_allocator.zig b/lib/std/heap/debug_allocator.zig
index 296014aa3f..44e7a4c943 100644
--- a/lib/std/heap/debug_allocator.zig
+++ b/lib/std/heap/debug_allocator.zig
@@ -1070,7 +1070,7 @@ test "small allocations - free in reverse order" {
try list.append(ptr);
}
- while (list.popOrNull()) |ptr| {
+ while (list.pop()) |ptr| {
allocator.destroy(ptr);
}
}
@@ -1227,7 +1227,7 @@ test "shrink large object to large object with larger alignment" {
try stuff_to_free.append(slice);
slice = try allocator.alignedAlloc(u8, 16, alloc_size);
}
- while (stuff_to_free.popOrNull()) |item| {
+ while (stuff_to_free.pop()) |item| {
allocator.free(item);
}
slice[0] = 0x12;
@@ -1299,7 +1299,7 @@ test "realloc large object to larger alignment" {
try stuff_to_free.append(slice);
slice = try allocator.alignedAlloc(u8, 16, default_page_size * 2 + 50);
}
- while (stuff_to_free.popOrNull()) |item| {
+ while (stuff_to_free.pop()) |item| {
allocator.free(item);
}
slice[0] = 0x12;
diff --git a/lib/std/json/dynamic.zig b/lib/std/json/dynamic.zig
index dae9ba836d..a5aa80a888 100644
--- a/lib/std/json/dynamic.zig
+++ b/lib/std/json/dynamic.zig
@@ -124,7 +124,7 @@ pub const Value = union(enum) {
.array_begin => {
try stack.append(Value{ .array = Array.init(allocator) });
},
- .array_end => return try handleCompleteValue(&stack, allocator, source, stack.pop(), options) orelse continue,
+ .array_end => return try handleCompleteValue(&stack, allocator, source, stack.pop().?, options) orelse continue,
else => unreachable,
}
@@ -171,7 +171,7 @@ fn handleCompleteValue(stack: *Array, allocator: Allocator, source: anytype, val
switch (try source.nextAllocMax(allocator, .alloc_always, options.max_value_len.?)) {
.object_end => {
// This object is complete.
- value = stack.pop();
+ value = stack.pop().?;
// Effectively recurse now that we have a complete value.
if (stack.items.len == 0) return value;
continue;