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
signature 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...@@ -984,8 +984,7 @@ static Error type_val_resolve_zero_bits(CodeGen *g, ConstExprValue *type_val, Zi
984 type_val->data.x_type->data.structure.resolve_loop_flag_zero_bits) ||984 type_val->data.x_type->data.structure.resolve_loop_flag_zero_bits) ||
985 (type_val->data.x_type->id == ZigTypeIdUnion &&985 (type_val->data.x_type->id == ZigTypeIdUnion &&
986 type_val->data.x_type->data.unionation.resolve_loop_flag_zero_bits) ||986 type_val->data.x_type->data.unionation.resolve_loop_flag_zero_bits) ||
987 (type_val->data.x_type->id == ZigTypeIdPointer &&987 type_val->data.x_type->id == ZigTypeIdPointer)
988 type_val->data.x_type->data.pointer.resolve_loop_flag_zero_bits))
989 {988 {
990 // Does a struct/union which contains a pointer field to itself have bits? Yes.989 // Does a struct/union which contains a pointer field to itself have bits? Yes.
991 *is_zero_bits = false;990 *is_zero_bits = false;
...@@ -2162,7 +2161,7 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) {...@@ -2162,7 +2161,7 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) {
2162 if (enum_type->data.enumeration.resolve_status != ResolveStatusInvalid) {2161 if (enum_type->data.enumeration.resolve_status != ResolveStatusInvalid) {
2163 enum_type->data.enumeration.resolve_status = ResolveStatusInvalid;2162 enum_type->data.enumeration.resolve_status = ResolveStatusInvalid;
2164 g->trace_err = add_node_error(g, decl_node,2163 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",
2166 buf_ptr(&enum_type->name)));2165 buf_ptr(&enum_type->name)));
2167 }2166 }
2168 return ErrorSemanticAnalyzeFail;2167 return ErrorSemanticAnalyzeFail;
...@@ -2532,7 +2531,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {...@@ -2532,7 +2531,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
2532 if (union_type->data.unionation.resolve_status != ResolveStatusInvalid) {2531 if (union_type->data.unionation.resolve_status != ResolveStatusInvalid) {
2533 union_type->data.unionation.resolve_status = ResolveStatusInvalid;2532 union_type->data.unionation.resolve_status = ResolveStatusInvalid;
2534 g->trace_err = add_node_error(g, decl_node,2533 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",
2536 buf_ptr(&union_type->name)));2535 buf_ptr(&union_type->name)));
2537 }2536 }
2538 return ErrorSemanticAnalyzeFail;2537 return ErrorSemanticAnalyzeFail;
std/array_list.zig+12-9
...@@ -6,20 +6,23 @@ const mem = std.mem;...@@ -6,20 +6,23 @@ const mem = std.mem;
6const Allocator = mem.Allocator;6const Allocator = mem.Allocator;
77
8pub fn ArrayList(comptime T: type) type {8pub fn ArrayList(comptime T: type) type {
9 return AlignedArrayList(T, @alignOf(T));9 return AlignedArrayList(T, null);
10}10}
1111
12pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {12pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type {
13 return struct {13 return struct {
14 const Self = @This();14 const Self = @This();
1515
16 /// Use toSlice instead of slicing this directly, because if you don't16 /// Use toSlice instead of slicing this directly, because if you don't
17 /// specify the end position of the slice, this will potentially give17 /// specify the end position of the slice, this will potentially give
18 /// you uninitialized memory.18 /// you uninitialized memory.
19 items: []align(A) T,19 items: Slice,
20 len: usize,20 len: usize,
21 allocator: *Allocator,21 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
23 /// Deinitialize with `deinit` or use `toOwnedSlice`.26 /// Deinitialize with `deinit` or use `toOwnedSlice`.
24 pub fn init(allocator: *Allocator) Self {27 pub fn init(allocator: *Allocator) Self {
25 return Self{28 return Self{
...@@ -33,11 +36,11 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {...@@ -33,11 +36,11 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
33 self.allocator.free(self.items);36 self.allocator.free(self.items);
34 }37 }
3538
36 pub fn toSlice(self: Self) []align(A) T {39 pub fn toSlice(self: Self) Slice {
37 return self.items[0..self.len];40 return self.items[0..self.len];
38 }41 }
3942
40 pub fn toSliceConst(self: Self) []align(A) const T {43 pub fn toSliceConst(self: Self) SliceConst {
41 return self.items[0..self.len];44 return self.items[0..self.len];
42 }45 }
4346
...@@ -69,7 +72,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {...@@ -69,7 +72,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
69 /// ArrayList takes ownership of the passed in slice. The slice must have been72 /// ArrayList takes ownership of the passed in slice. The slice must have been
70 /// allocated with `allocator`.73 /// allocated with `allocator`.
71 /// Deinitialize with `deinit` or use `toOwnedSlice`.74 /// 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 {
73 return Self{76 return Self{
74 .items = slice,77 .items = slice,
75 .len = slice.len,78 .len = slice.len,
...@@ -78,7 +81,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {...@@ -78,7 +81,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
78 }81 }
7982
80 /// The caller owns the returned memory. ArrayList becomes empty.83 /// 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 {
82 const allocator = self.allocator;85 const allocator = self.allocator;
83 const result = allocator.shrink(self.items, self.len);86 const result = allocator.shrink(self.items, self.len);
84 self.* = init(allocator);87 self.* = init(allocator);
...@@ -93,7 +96,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {...@@ -93,7 +96,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
93 self.items[n] = item;96 self.items[n] = item;
94 }97 }
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 {
97 try self.ensureCapacity(self.len + items.len);100 try self.ensureCapacity(self.len + items.len);
98 self.len += items.len;101 self.len += items.len;
99102
...@@ -141,7 +144,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {...@@ -141,7 +144,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
141 return self.swapRemove(i);144 return self.swapRemove(i);
142 }145 }
143146
144 pub fn appendSlice(self: *Self, items: []align(A) const T) !void {147 pub fn appendSlice(self: *Self, items: SliceConst) !void {
145 try self.ensureCapacity(self.len + items.len);148 try self.ensureCapacity(self.len + items.len);
146 mem.copy(T, self.items[self.len..], items);149 mem.copy(T, self.items[self.len..], items);
147 self.len += items.len;150 self.len += items.len;