From b735764898412c5b9388fdf729c8ad8db43ddde5 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sun, 9 Jun 2019 19:24:24 -0400 Subject: different array literal syntax when inferring the size old syntax: []i32{1, 2, 3} new syntax: [_]i32{1, 2, 3} closes #1797 --- src-self-hosted/compilation.zig | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src-self-hosted/compilation.zig') diff --git a/src-self-hosted/compilation.zig b/src-self-hosted/compilation.zig index 450fde7219..5171b80ddc 100644 --- a/src-self-hosted/compilation.zig +++ b/src-self-hosted/compilation.zig @@ -102,8 +102,8 @@ pub const ZigCompiler = struct { /// Must be called only once, ever. Sets global state. pub fn setLlvmArgv(allocator: *Allocator, llvm_argv: []const []const u8) !void { if (llvm_argv.len != 0) { - var c_compatible_args = try std.cstr.NullTerminated2DArray.fromSlices(allocator, [][]const []const u8{ - [][]const u8{"zig (LLVM option parsing)"}, + var c_compatible_args = try std.cstr.NullTerminated2DArray.fromSlices(allocator, [_][]const []const u8{ + [_][]const u8{"zig (LLVM option parsing)"}, llvm_argv, }); defer c_compatible_args.deinit(); @@ -421,20 +421,20 @@ pub const Compilation = struct { .strip = false, .is_static = is_static, .linker_rdynamic = false, - .clang_argv = [][]const u8{}, - .lib_dirs = [][]const u8{}, - .rpath_list = [][]const u8{}, - .assembly_files = [][]const u8{}, - .link_objects = [][]const u8{}, + .clang_argv = [_][]const u8{}, + .lib_dirs = [_][]const u8{}, + .rpath_list = [_][]const u8{}, + .assembly_files = [_][]const u8{}, + .link_objects = [_][]const u8{}, .fn_link_set = event.Locked(FnLinkSet).init(loop, FnLinkSet.init()), .windows_subsystem_windows = false, .windows_subsystem_console = false, .link_libs_list = undefined, .libc_link_lib = null, .err_color = errmsg.Color.Auto, - .darwin_frameworks = [][]const u8{}, + .darwin_frameworks = [_][]const u8{}, .darwin_version_min = DarwinVersionMin.None, - .test_filters = [][]const u8{}, + .test_filters = [_][]const u8{}, .test_name_prefix = null, .emit_file_type = Emit.Binary, .link_out_file = null, @@ -487,7 +487,7 @@ pub const Compilation = struct { comp.name = try Buffer.init(comp.arena(), name); comp.llvm_triple = try target.getTriple(comp.arena()); comp.llvm_target = try Target.llvmTargetFromTriple(comp.llvm_triple); - comp.zig_std_dir = try std.fs.path.join(comp.arena(), [][]const u8{ zig_lib_dir, "std" }); + comp.zig_std_dir = try std.fs.path.join(comp.arena(), [_][]const u8{ zig_lib_dir, "std" }); const opt_level = switch (build_mode) { builtin.Mode.Debug => llvm.CodeGenLevelNone, @@ -1196,7 +1196,7 @@ pub const Compilation = struct { const file_name = try std.fmt.allocPrint(self.gpa(), "{}{}", file_prefix[0..], suffix); defer self.gpa().free(file_name); - const full_path = try std.fs.path.join(self.gpa(), [][]const u8{ tmp_dir, file_name[0..] }); + const full_path = try std.fs.path.join(self.gpa(), [_][]const u8{ tmp_dir, file_name[0..] }); errdefer self.gpa().free(full_path); return Buffer.fromOwnedSlice(self.gpa(), full_path); @@ -1217,7 +1217,7 @@ pub const Compilation = struct { const zig_dir_path = try getZigDir(self.gpa()); defer self.gpa().free(zig_dir_path); - const tmp_dir = try std.fs.path.join(self.arena(), [][]const u8{ zig_dir_path, comp_dir_name[0..] }); + const tmp_dir = try std.fs.path.join(self.arena(), [_][]const u8{ zig_dir_path, comp_dir_name[0..] }); try std.fs.makePath(self.gpa(), tmp_dir); return tmp_dir; } -- cgit v1.2.3 From ed41d10a068065ea80f93736926d9c3240d62c49 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Sat, 4 May 2019 13:54:28 +1000 Subject: std: existing LinkedList is actually a TailQueue --- src-self-hosted/compilation.zig | 2 +- src-self-hosted/value.zig | 2 +- std/atomic/queue.zig | 2 +- std/child_process.zig | 6 +++--- std/event/net.zig | 2 +- std/heap.zig | 6 +++--- std/linked_list.zig | 19 ++++++++++++------- std/std.zig | 2 +- 8 files changed, 23 insertions(+), 18 deletions(-) (limited to 'src-self-hosted/compilation.zig') diff --git a/src-self-hosted/compilation.zig b/src-self-hosted/compilation.zig index 5171b80ddc..bd20442d4b 100644 --- a/src-self-hosted/compilation.zig +++ b/src-self-hosted/compilation.zig @@ -160,7 +160,7 @@ pub const Compilation = struct { /// it uses an optional pointer so that tombstone removals are possible fn_link_set: event.Locked(FnLinkSet), - pub const FnLinkSet = std.LinkedList(?*Value.Fn); + pub const FnLinkSet = std.TailQueue(?*Value.Fn); windows_subsystem_windows: bool, windows_subsystem_console: bool, diff --git a/src-self-hosted/value.zig b/src-self-hosted/value.zig index 328646d2cd..6908307c56 100644 --- a/src-self-hosted/value.zig +++ b/src-self-hosted/value.zig @@ -186,7 +186,7 @@ pub const Value = struct { /// Path to the object file that contains this function containing_object: Buffer, - link_set_node: *std.LinkedList(?*Value.Fn).Node, + link_set_node: *std.TailQueue(?*Value.Fn).Node, /// Creates a Fn value with 1 ref /// Takes ownership of symbol_name diff --git a/std/atomic/queue.zig b/std/atomic/queue.zig index bf5700c51e..e8d03c4f13 100644 --- a/std/atomic/queue.zig +++ b/std/atomic/queue.zig @@ -14,7 +14,7 @@ pub fn Queue(comptime T: type) type { mutex: std.Mutex, pub const Self = @This(); - pub const Node = std.LinkedList(T).Node; + pub const Node = std.TailQueue(T).Node; pub fn init() Self { return Self{ diff --git a/std/child_process.zig b/std/child_process.zig index 2a2a294e9b..8e4c086d1d 100644 --- a/std/child_process.zig +++ b/std/child_process.zig @@ -13,7 +13,7 @@ const BufMap = std.BufMap; const Buffer = std.Buffer; const builtin = @import("builtin"); const Os = builtin.Os; -const LinkedList = std.LinkedList; +const TailQueue = std.TailQueue; const maxInt = std.math.maxInt; pub const ChildProcess = struct { @@ -48,7 +48,7 @@ pub const ChildProcess = struct { pub cwd: ?[]const u8, err_pipe: if (os.windows.is_the_target) void else [2]os.fd_t, - llnode: if (os.windows.is_the_target) void else LinkedList(*ChildProcess).Node, + llnode: if (os.windows.is_the_target) void else TailQueue(*ChildProcess).Node, pub const SpawnError = error{OutOfMemory} || os.ExecveError || os.SetIdError || os.ChangeCurDirError || windows.CreateProcessError; @@ -388,7 +388,7 @@ pub const ChildProcess = struct { self.pid = pid; self.err_pipe = err_pipe; - self.llnode = LinkedList(*ChildProcess).Node.init(self); + self.llnode = TailQueue(*ChildProcess).Node.init(self); self.term = null; if (self.stdin_behavior == StdIo.Pipe) { diff --git a/std/event/net.zig b/std/event/net.zig index f4398196e3..413bf1432c 100644 --- a/std/event/net.zig +++ b/std/event/net.zig @@ -19,7 +19,7 @@ pub const Server = struct { waiting_for_emfile_node: PromiseNode, listen_resume_node: event.Loop.ResumeNode, - const PromiseNode = std.LinkedList(promise).Node; + const PromiseNode = std.TailQueue(promise).Node; pub fn init(loop: *Loop) Server { // TODO can't initialize handler coroutine here because we need well defined copy elision diff --git a/std/heap.zig b/std/heap.zig index 7d7774f453..ba2b4c816c 100644 --- a/std/heap.zig +++ b/std/heap.zig @@ -347,10 +347,10 @@ pub const ArenaAllocator = struct { pub allocator: Allocator, child_allocator: *Allocator, - buffer_list: std.LinkedList([]u8), + buffer_list: std.TailQueue([]u8), end_index: usize, - const BufNode = std.LinkedList([]u8).Node; + const BufNode = std.TailQueue([]u8).Node; pub fn init(child_allocator: *Allocator) ArenaAllocator { return ArenaAllocator{ @@ -359,7 +359,7 @@ pub const ArenaAllocator = struct { .shrinkFn = shrink, }, .child_allocator = child_allocator, - .buffer_list = std.LinkedList([]u8).init(), + .buffer_list = std.TailQueue([]u8).init(), .end_index = 0, }; } diff --git a/std/linked_list.zig b/std/linked_list.zig index c4ad525913..65fbd707f5 100644 --- a/std/linked_list.zig +++ b/std/linked_list.zig @@ -5,8 +5,13 @@ const testing = std.testing; const mem = std.mem; const Allocator = mem.Allocator; -/// Generic doubly linked list. -pub fn LinkedList(comptime T: type) type { +/// A tail queue is headed by a pair of pointers, one to the head of the +/// list and the other to the tail of the list. The elements are doubly +/// linked so that an arbitrary element can be removed without a need to +/// traverse the list. New elements can be added to the list before or +/// after an existing element, at the head of the list, or at the end of +/// the list. A tail queue may be traversed in either direction. +pub fn TailQueue(comptime T: type) type { return struct { const Self = @This(); @@ -219,9 +224,9 @@ pub fn LinkedList(comptime T: type) type { }; } -test "basic linked list test" { +test "basic TailQueue test" { const allocator = debug.global_allocator; - var list = LinkedList(u32).init(); + var list = TailQueue(u32).init(); var one = try list.createNode(1, allocator); var two = try list.createNode(2, allocator); @@ -271,10 +276,10 @@ test "basic linked list test" { testing.expect(list.len == 2); } -test "linked list concatenation" { +test "TailQueue concatenation" { const allocator = debug.global_allocator; - var list1 = LinkedList(u32).init(); - var list2 = LinkedList(u32).init(); + var list1 = TailQueue(u32).init(); + var list2 = TailQueue(u32).init(); var one = try list1.createNode(1, allocator); defer list1.destroyNode(one, allocator); diff --git a/std/std.zig b/std/std.zig index a621af1e84..d429ca8a21 100644 --- a/std/std.zig +++ b/std/std.zig @@ -7,7 +7,6 @@ pub const Buffer = @import("buffer.zig").Buffer; pub const BufferOutStream = @import("io.zig").BufferOutStream; pub const DynLib = @import("dynamic_library.zig").DynLib; pub const HashMap = @import("hash_map.zig").HashMap; -pub const LinkedList = @import("linked_list.zig").LinkedList; pub const Mutex = @import("mutex.zig").Mutex; pub const PackedIntArrayEndian = @import("packed_int_array.zig").PackedIntArrayEndian; pub const PackedIntArray = @import("packed_int_array.zig").PackedIntArray; @@ -18,6 +17,7 @@ pub const StaticallyInitializedMutex = @import("statically_initialized_mutex.zig pub const SegmentedList = @import("segmented_list.zig").SegmentedList; pub const SpinLock = @import("spinlock.zig").SpinLock; pub const ChildProcess = @import("child_process.zig").ChildProcess; +pub const TailQueue = @import("linked_list.zig").TailQueue; pub const Thread = @import("thread.zig").Thread; pub const atomic = @import("atomic.zig"); -- cgit v1.2.3