authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-08-26 11:23:25-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-08-26 11:23:25-04:00
log6569bfc85e7de5229dd5b665e84070970d28653d
tree305c57ec295673dbe7d1913b83c777bc0f87407a
parente1a4bcbdfd338d85f55aa8da318e203b299a2b91
signaturelock-open Commit is signed but in an unrecognized format.

fix some std lib dependency loops


2 files changed, 15 insertions(+), 13 deletions(-)

src/analyze.cpp+3-4
......@@ -984,8 +984,7 @@ static Error type_val_resolve_zero_bits(CodeGen *g, ConstExprValue *type_val, Zi
984984 type_val->data.x_type->data.structure.resolve_loop_flag_zero_bits) ||
985985 (type_val->data.x_type->id == ZigTypeIdUnion &&
986986 type_val->data.x_type->data.unionation.resolve_loop_flag_zero_bits) ||
987 (type_val->data.x_type->id == ZigTypeIdPointer &&
988 type_val->data.x_type->data.pointer.resolve_loop_flag_zero_bits))
987 type_val->data.x_type->id == ZigTypeIdPointer)
989988 {
990989 // Does a struct/union which contains a pointer field to itself have bits? Yes.
991990 *is_zero_bits = false;
......@@ -2162,7 +2161,7 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) {
21622161 if (enum_type->data.enumeration.resolve_status != ResolveStatusInvalid) {
21632162 enum_type->data.enumeration.resolve_status = ResolveStatusInvalid;
21642163 g->trace_err = add_node_error(g, decl_node,
2165 buf_sprintf("dependency loop: whether enum '%s' has non-zero size",
2164 buf_sprintf("enum '%s' depends on itself",
21662165 buf_ptr(&enum_type->name)));
21672166 }
21682167 return ErrorSemanticAnalyzeFail;
......@@ -2532,7 +2531,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
25322531 if (union_type->data.unionation.resolve_status != ResolveStatusInvalid) {
25332532 union_type->data.unionation.resolve_status = ResolveStatusInvalid;
25342533 g->trace_err = add_node_error(g, decl_node,
2535 buf_sprintf("dependency loop: whether union '%s' has non-zero size",
2534 buf_sprintf("union '%s' depends on itself",
25362535 buf_ptr(&union_type->name)));
25372536 }
25382537 return ErrorSemanticAnalyzeFail;
std/array_list.zig+12-9
......@@ -6,20 +6,23 @@ const mem = std.mem;
66const Allocator = mem.Allocator;
77
88pub fn ArrayList(comptime T: type) type {
9 return AlignedArrayList(T, @alignOf(T));
9 return AlignedArrayList(T, null);
1010}
1111
12pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
12pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type {
1313 return struct {
1414 const Self = @This();
1515
1616 /// Use toSlice instead of slicing this directly, because if you don't
1717 /// specify the end position of the slice, this will potentially give
1818 /// you uninitialized memory.
19 items: []align(A) T,
19 items: Slice,
2020 len: usize,
2121 allocator: *Allocator,
2222
23 pub const Slice = if (alignment) |a| ([]align(a) T) else []T;
24 pub const SliceConst = if (alignment) |a| ([]align(a) const T) else []const T;
25
2326 /// Deinitialize with `deinit` or use `toOwnedSlice`.
2427 pub fn init(allocator: *Allocator) Self {
2528 return Self{
......@@ -33,11 +36,11 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
3336 self.allocator.free(self.items);
3437 }
3538
36 pub fn toSlice(self: Self) []align(A) T {
39 pub fn toSlice(self: Self) Slice {
3740 return self.items[0..self.len];
3841 }
3942
40 pub fn toSliceConst(self: Self) []align(A) const T {
43 pub fn toSliceConst(self: Self) SliceConst {
4144 return self.items[0..self.len];
4245 }
4346
......@@ -69,7 +72,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
6972 /// ArrayList takes ownership of the passed in slice. The slice must have been
7073 /// allocated with `allocator`.
7174 /// Deinitialize with `deinit` or use `toOwnedSlice`.
72 pub fn fromOwnedSlice(allocator: *Allocator, slice: []align(A) T) Self {
75 pub fn fromOwnedSlice(allocator: *Allocator, slice: Slice) Self {
7376 return Self{
7477 .items = slice,
7578 .len = slice.len,
......@@ -78,7 +81,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
7881 }
7982
8083 /// The caller owns the returned memory. ArrayList becomes empty.
81 pub fn toOwnedSlice(self: *Self) []align(A) T {
84 pub fn toOwnedSlice(self: *Self) Slice {
8285 const allocator = self.allocator;
8386 const result = allocator.shrink(self.items, self.len);
8487 self.* = init(allocator);
......@@ -93,7 +96,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
9396 self.items[n] = item;
9497 }
9598
96 pub fn insertSlice(self: *Self, n: usize, items: []align(A) const T) !void {
99 pub fn insertSlice(self: *Self, n: usize, items: SliceConst) !void {
97100 try self.ensureCapacity(self.len + items.len);
98101 self.len += items.len;
99102
......@@ -141,7 +144,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
141144 return self.swapRemove(i);
142145 }
143146
144 pub fn appendSlice(self: *Self, items: []align(A) const T) !void {
147 pub fn appendSlice(self: *Self, items: SliceConst) !void {
145148 try self.ensureCapacity(self.len + items.len);
146149 mem.copy(T, self.items[self.len..], items);
147150 self.len += items.len;