Commit 6569bfc85e
Changed files (2)
src
src/analyze.cpp
@@ -984,8 +984,7 @@ static Error type_val_resolve_zero_bits(CodeGen *g, ConstExprValue *type_val, Zi
type_val->data.x_type->data.structure.resolve_loop_flag_zero_bits) ||
(type_val->data.x_type->id == ZigTypeIdUnion &&
type_val->data.x_type->data.unionation.resolve_loop_flag_zero_bits) ||
- (type_val->data.x_type->id == ZigTypeIdPointer &&
- type_val->data.x_type->data.pointer.resolve_loop_flag_zero_bits))
+ type_val->data.x_type->id == ZigTypeIdPointer)
{
// Does a struct/union which contains a pointer field to itself have bits? Yes.
*is_zero_bits = false;
@@ -2162,7 +2161,7 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) {
if (enum_type->data.enumeration.resolve_status != ResolveStatusInvalid) {
enum_type->data.enumeration.resolve_status = ResolveStatusInvalid;
g->trace_err = add_node_error(g, decl_node,
- buf_sprintf("dependency loop: whether enum '%s' has non-zero size",
+ buf_sprintf("enum '%s' depends on itself",
buf_ptr(&enum_type->name)));
}
return ErrorSemanticAnalyzeFail;
@@ -2532,7 +2531,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
if (union_type->data.unionation.resolve_status != ResolveStatusInvalid) {
union_type->data.unionation.resolve_status = ResolveStatusInvalid;
g->trace_err = add_node_error(g, decl_node,
- buf_sprintf("dependency loop: whether union '%s' has non-zero size",
+ buf_sprintf("union '%s' depends on itself",
buf_ptr(&union_type->name)));
}
return ErrorSemanticAnalyzeFail;
std/array_list.zig
@@ -6,20 +6,23 @@ const mem = std.mem;
const Allocator = mem.Allocator;
pub fn ArrayList(comptime T: type) type {
- return AlignedArrayList(T, @alignOf(T));
+ return AlignedArrayList(T, null);
}
-pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
+pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type {
return struct {
const Self = @This();
/// Use toSlice instead of slicing this directly, because if you don't
/// specify the end position of the slice, this will potentially give
/// you uninitialized memory.
- items: []align(A) T,
+ items: Slice,
len: usize,
allocator: *Allocator,
+ pub const Slice = if (alignment) |a| ([]align(a) T) else []T;
+ pub const SliceConst = if (alignment) |a| ([]align(a) const T) else []const T;
+
/// Deinitialize with `deinit` or use `toOwnedSlice`.
pub fn init(allocator: *Allocator) Self {
return Self{
@@ -33,11 +36,11 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
self.allocator.free(self.items);
}
- pub fn toSlice(self: Self) []align(A) T {
+ pub fn toSlice(self: Self) Slice {
return self.items[0..self.len];
}
- pub fn toSliceConst(self: Self) []align(A) const T {
+ pub fn toSliceConst(self: Self) SliceConst {
return self.items[0..self.len];
}
@@ -69,7 +72,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
/// ArrayList takes ownership of the passed in slice. The slice must have been
/// allocated with `allocator`.
/// Deinitialize with `deinit` or use `toOwnedSlice`.
- pub fn fromOwnedSlice(allocator: *Allocator, slice: []align(A) T) Self {
+ pub fn fromOwnedSlice(allocator: *Allocator, slice: Slice) Self {
return Self{
.items = slice,
.len = slice.len,
@@ -78,7 +81,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
}
/// The caller owns the returned memory. ArrayList becomes empty.
- pub fn toOwnedSlice(self: *Self) []align(A) T {
+ pub fn toOwnedSlice(self: *Self) Slice {
const allocator = self.allocator;
const result = allocator.shrink(self.items, self.len);
self.* = init(allocator);
@@ -93,7 +96,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
self.items[n] = item;
}
- pub fn insertSlice(self: *Self, n: usize, items: []align(A) const T) !void {
+ pub fn insertSlice(self: *Self, n: usize, items: SliceConst) !void {
try self.ensureCapacity(self.len + items.len);
self.len += items.len;
@@ -141,7 +144,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
return self.swapRemove(i);
}
- pub fn appendSlice(self: *Self, items: []align(A) const T) !void {
+ pub fn appendSlice(self: *Self, items: SliceConst) !void {
try self.ensureCapacity(self.len + items.len);
mem.copy(T, self.items[self.len..], items);
self.len += items.len;