From 178d69191ba008dffd70d2854df09cec556b59dd Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 12 Sep 2018 13:55:02 -0400 Subject: windows: std.fs functions support concurrent ops when reading and writing the same file descriptors --- std/event/fs.zig | 75 +++++++++++++++++++++++++----------------------------- std/event/loop.zig | 46 ++++++++++++++++++++++----------- 2 files changed, 66 insertions(+), 55 deletions(-) (limited to 'std/event') diff --git a/std/event/fs.zig b/std/event/fs.zig index 5e7e24ff43..c13a940a36 100644 --- a/std/event/fs.zig +++ b/std/event/fs.zig @@ -109,30 +109,28 @@ pub async fn pwriteWindows(loop: *Loop, fd: os.FileHandle, data: []const u8, off .base = Loop.ResumeNode{ .id = Loop.ResumeNode.Id.Basic, .handle = @handle(), + .overlapped = windows.OVERLAPPED{ + .Internal = 0, + .InternalHigh = 0, + .Offset = @truncate(u32, offset), + .OffsetHigh = @truncate(u32, offset >> 32), + .hEvent = null, + }, }, }; - const completion_key = @ptrToInt(&resume_node.base); - // TODO support concurrent async ops on the file handle - // we can do this by ignoring completion key and using @fieldParentPtr with the *Overlapped - _ = try os.windowsCreateIoCompletionPort(fd, loop.os_data.io_port, completion_key, undefined); - var overlapped = windows.OVERLAPPED{ - .Internal = 0, - .InternalHigh = 0, - .Offset = @truncate(u32, offset), - .OffsetHigh = @truncate(u32, offset >> 32), - .hEvent = null, - }; + // TODO only call create io completion port once per fd + _ = try os.windowsCreateIoCompletionPort(fd, loop.os_data.io_port, undefined, undefined); loop.beginOneEvent(); errdefer loop.finishOneEvent(); errdefer { - _ = windows.CancelIoEx(fd, &overlapped); + _ = windows.CancelIoEx(fd, &resume_node.base.overlapped); } suspend { - _ = windows.WriteFile(fd, data.ptr, @intCast(windows.DWORD, data.len), null, &overlapped); + _ = windows.WriteFile(fd, data.ptr, @intCast(windows.DWORD, data.len), null, &resume_node.base.overlapped); } var bytes_transferred: windows.DWORD = undefined; - if (windows.GetOverlappedResult(fd, &overlapped, &bytes_transferred, windows.FALSE) == 0) { + if (windows.GetOverlappedResult(fd, &resume_node.base.overlapped, &bytes_transferred, windows.FALSE) == 0) { const err = windows.GetLastError(); return switch (err) { windows.ERROR.IO_PENDING => unreachable, @@ -243,30 +241,28 @@ pub async fn preadWindows(loop: *Loop, fd: os.FileHandle, data: []u8, offset: u6 .base = Loop.ResumeNode{ .id = Loop.ResumeNode.Id.Basic, .handle = @handle(), + .overlapped = windows.OVERLAPPED{ + .Internal = 0, + .InternalHigh = 0, + .Offset = @truncate(u32, offset), + .OffsetHigh = @truncate(u32, offset >> 32), + .hEvent = null, + }, }, }; - const completion_key = @ptrToInt(&resume_node.base); - // TODO support concurrent async ops on the file handle - // we can do this by ignoring completion key and using @fieldParentPtr with the *Overlapped - _ = try os.windowsCreateIoCompletionPort(fd, loop.os_data.io_port, completion_key, undefined); - var overlapped = windows.OVERLAPPED{ - .Internal = 0, - .InternalHigh = 0, - .Offset = @truncate(u32, offset), - .OffsetHigh = @truncate(u32, offset >> 32), - .hEvent = null, - }; + // TODO only call create io completion port once per fd + _ = try os.windowsCreateIoCompletionPort(fd, loop.os_data.io_port, undefined, undefined); loop.beginOneEvent(); errdefer loop.finishOneEvent(); errdefer { - _ = windows.CancelIoEx(fd, &overlapped); + _ = windows.CancelIoEx(fd, &resume_node.base.overlapped); } suspend { - _ = windows.ReadFile(fd, data.ptr, @intCast(windows.DWORD, data.len), null, &overlapped); + _ = windows.ReadFile(fd, data.ptr, @intCast(windows.DWORD, data.len), null, &resume_node.base.overlapped); } var bytes_transferred: windows.DWORD = undefined; - if (windows.GetOverlappedResult(fd, &overlapped, &bytes_transferred, windows.FALSE) == 0) { + if (windows.GetOverlappedResult(fd, &resume_node.base.overlapped, &bytes_transferred, windows.FALSE) == 0) { const err = windows.GetLastError(); return switch (err) { windows.ERROR.IO_PENDING => unreachable, @@ -1074,23 +1070,22 @@ pub fn Watch(comptime V: type) type { .base = Loop.ResumeNode{ .id = Loop.ResumeNode.Id.Basic, .handle = @handle(), + .overlapped = windows.OVERLAPPED{ + .Internal = 0, + .InternalHigh = 0, + .Offset = 0, + .OffsetHigh = 0, + .hEvent = null, + }, }, }; - const completion_key = @ptrToInt(&resume_node.base); - var overlapped = windows.OVERLAPPED{ - .Internal = 0, - .InternalHigh = 0, - .Offset = 0, - .OffsetHigh = 0, - .hEvent = null, - }; var event_buf: [4096]u8 align(@alignOf(windows.FILE_NOTIFY_INFORMATION)) = undefined; // TODO handle this error not in the channel but in the setup _ = os.windowsCreateIoCompletionPort( dir_handle, self.channel.loop.os_data.io_port, - completion_key, + undefined, undefined, ) catch |err| { await (async self.channel.put(err) catch unreachable); @@ -1103,7 +1098,7 @@ pub fn Watch(comptime V: type) type { self.channel.loop.beginOneEvent(); errdefer self.channel.loop.finishOneEvent(); errdefer { - _ = windows.CancelIoEx(dir_handle, &overlapped); + _ = windows.CancelIoEx(dir_handle, &resume_node.base.overlapped); } suspend { _ = windows.ReadDirectoryChangesW( @@ -1116,13 +1111,13 @@ pub fn Watch(comptime V: type) type { windows.FILE_NOTIFY_CHANGE_LAST_WRITE | windows.FILE_NOTIFY_CHANGE_LAST_ACCESS | windows.FILE_NOTIFY_CHANGE_CREATION | windows.FILE_NOTIFY_CHANGE_SECURITY, null, // number of bytes transferred (unused for async) - &overlapped, + &resume_node.base.overlapped, null, // completion routine - unused because we use IOCP ); } } var bytes_transferred: windows.DWORD = undefined; - if (windows.GetOverlappedResult(dir_handle, &overlapped, &bytes_transferred, windows.FALSE) == 0) { + if (windows.GetOverlappedResult(dir_handle, &resume_node.base.overlapped, &bytes_transferred, windows.FALSE) == 0) { const errno = windows.GetLastError(); const err = switch (errno) { else => os.unexpectedErrorWindows(errno), diff --git a/std/event/loop.zig b/std/event/loop.zig index 733112549d..6cd22ff69e 100644 --- a/std/event/loop.zig +++ b/std/event/loop.zig @@ -27,6 +27,19 @@ pub const Loop = struct { pub const ResumeNode = struct { id: Id, handle: promise, + overlapped: Overlapped, + + const overlapped_init = switch (builtin.os) { + builtin.Os.windows => windows.OVERLAPPED{ + .Internal = 0, + .InternalHigh = 0, + .Offset = 0, + .OffsetHigh = 0, + .hEvent = null, + }, + else => {}, + }; + const Overlapped = @typeOf(overlapped_init); pub const Id = enum { Basic, @@ -101,6 +114,7 @@ pub const Loop = struct { .final_resume_node = ResumeNode{ .id = ResumeNode.Id.Stop, .handle = undefined, + .overlapped = ResumeNode.overlapped_init, }, }; const extra_thread_count = thread_count - 1; @@ -153,6 +167,7 @@ pub const Loop = struct { .base = ResumeNode{ .id = ResumeNode.Id.EventFd, .handle = undefined, + .overlapped = ResumeNode.overlapped_init, }, .eventfd = try os.linuxEventFd(1, posix.EFD_CLOEXEC | posix.EFD_NONBLOCK), .epoll_op = posix.EPOLL_CTL_ADD, @@ -225,6 +240,7 @@ pub const Loop = struct { .base = ResumeNode{ .id = ResumeNode.Id.EventFd, .handle = undefined, + .overlapped = ResumeNode.overlapped_init, }, // this one is for sending events .kevent = posix.Kevent{ @@ -311,6 +327,7 @@ pub const Loop = struct { .base = ResumeNode{ .id = ResumeNode.Id.EventFd, .handle = undefined, + .overlapped = ResumeNode.overlapped_init, }, // this one is for sending events .completion_key = @ptrToInt(&eventfd_node.data.base), @@ -325,8 +342,8 @@ pub const Loop = struct { var i: usize = 0; while (i < extra_thread_index) : (i += 1) { while (true) { - const overlapped = @intToPtr(?*windows.OVERLAPPED, 0x1); - os.windowsPostQueuedCompletionStatus(self.os_data.io_port, undefined, @ptrToInt(&self.final_resume_node), overlapped) catch continue; + const overlapped = &self.final_resume_node.overlapped; + os.windowsPostQueuedCompletionStatus(self.os_data.io_port, undefined, undefined, overlapped) catch continue; break; } } @@ -413,6 +430,7 @@ pub const Loop = struct { .base = ResumeNode{ .id = ResumeNode.Id.Basic, .handle = @handle(), + .overlapped = ResumeNode.overlapped_init, }, .kev = undefined, }; @@ -489,15 +507,11 @@ pub const Loop = struct { }; }, builtin.Os.windows => { - // this value is never dereferenced but we need it to be non-null so that - // the consumer code can decide whether to read the completion key. - // it has to do this for normal I/O, so we match that behavior here. - const overlapped = @intToPtr(?*windows.OVERLAPPED, 0x1); os.windowsPostQueuedCompletionStatus( self.os_data.io_port, undefined, - eventfd_node.completion_key, - overlapped, + undefined, + &eventfd_node.base.overlapped, ) catch { self.next_tick_queue.unget(next_tick_node); self.available_eventfd_resume_nodes.push(resume_stack_node); @@ -606,8 +620,8 @@ pub const Loop = struct { var i: usize = 0; while (i < self.extra_threads.len + 1) : (i += 1) { while (true) { - const overlapped = @intToPtr(?*windows.OVERLAPPED, 0x1); - os.windowsPostQueuedCompletionStatus(self.os_data.io_port, undefined, @ptrToInt(&self.final_resume_node), overlapped) catch continue; + const overlapped = &self.final_resume_node.overlapped; + os.windowsPostQueuedCompletionStatus(self.os_data.io_port, undefined, undefined, overlapped) catch continue; break; } } @@ -680,17 +694,19 @@ pub const Loop = struct { }, builtin.Os.windows => { var completion_key: usize = undefined; - while (true) { + const overlapped = while (true) { var nbytes: windows.DWORD = undefined; var overlapped: ?*windows.OVERLAPPED = undefined; - switch (os.windowsGetQueuedCompletionStatus(self.os_data.io_port, &nbytes, &completion_key, &overlapped, windows.INFINITE)) { + switch (os.windowsGetQueuedCompletionStatus(self.os_data.io_port, &nbytes, &completion_key, + &overlapped, windows.INFINITE)) + { os.WindowsWaitResult.Aborted => return, os.WindowsWaitResult.Normal => {}, os.WindowsWaitResult.Cancelled => continue, } - if (overlapped != null) break; - } - const resume_node = @intToPtr(*ResumeNode, completion_key); + if (overlapped) |o| break o; + } else unreachable; // TODO else unreachable should not be necessary + const resume_node = @fieldParentPtr(ResumeNode, "overlapped", overlapped); const handle = resume_node.handle; const resume_node_id = resume_node.id; switch (resume_node_id) { -- cgit v1.2.3 From a75753338657b85588fe6c54a40fecac0584b336 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 12 Sep 2018 14:26:21 -0400 Subject: fix zig fmt on windows closes #1069 --- std/coff.zig | 52 +++++++------- std/crypto/x25519.zig | 2 +- std/debug/index.zig | 23 ++++--- std/event/fs.zig | 15 +++-- std/event/loop.zig | 10 +-- std/event/tcp.zig | 1 + std/os/child_process.zig | 12 +++- std/os/windows/kernel32.zig | 1 - std/os/windows/util.zig | 4 +- std/pdb.zig | 161 +++++++++++++++++++++++++++----------------- 10 files changed, 161 insertions(+), 120 deletions(-) (limited to 'std/event') diff --git a/std/coff.zig b/std/coff.zig index 379fd1af42..bf5a93ef30 100644 --- a/std/coff.zig +++ b/std/coff.zig @@ -8,9 +8,9 @@ const ArrayList = std.ArrayList; // CoffHeader.machine values // see https://msdn.microsoft.com/en-us/library/windows/desktop/ms680313(v=vs.85).aspx -const IMAGE_FILE_MACHINE_I386 = 0x014c; -const IMAGE_FILE_MACHINE_IA64 = 0x0200; -const IMAGE_FILE_MACHINE_AMD64 = 0x8664; +const IMAGE_FILE_MACHINE_I386 = 0x014c; +const IMAGE_FILE_MACHINE_IA64 = 0x0200; +const IMAGE_FILE_MACHINE_AMD64 = 0x8664; // OptionalHeader.magic values // see https://msdn.microsoft.com/en-us/library/windows/desktop/ms680339(v=vs.85).aspx @@ -20,7 +20,7 @@ const IMAGE_NT_OPTIONAL_HDR64_MAGIC = 0x20b; const IMAGE_NUMBEROF_DIRECTORY_ENTRIES = 16; const DEBUG_DIRECTORY = 6; -pub const CoffError = error { +pub const CoffError = error{ InvalidPEMagic, InvalidPEHeader, InvalidMachine, @@ -56,24 +56,21 @@ pub const Coff = struct { var pe_header_magic: [4]u8 = undefined; try in.readNoEof(pe_header_magic[0..]); - if (!mem.eql(u8, pe_header_magic, []u8{'P', 'E', 0, 0})) + if (!mem.eql(u8, pe_header_magic, []u8{ 'P', 'E', 0, 0 })) return error.InvalidPEHeader; - self.coff_header = CoffHeader { + self.coff_header = CoffHeader{ .machine = try in.readIntLe(u16), - .number_of_sections = try in.readIntLe(u16), - .timedate_stamp = try in.readIntLe(u32), - .pointer_to_symbol_table = try in.readIntLe(u32), - .number_of_symbols = try in.readIntLe(u32), - .size_of_optional_header = try in.readIntLe(u16), - .characteristics = try in.readIntLe(u16), + .number_of_sections = try in.readIntLe(u16), + .timedate_stamp = try in.readIntLe(u32), + .pointer_to_symbol_table = try in.readIntLe(u32), + .number_of_symbols = try in.readIntLe(u32), + .size_of_optional_header = try in.readIntLe(u16), + .characteristics = try in.readIntLe(u16), }; switch (self.coff_header.machine) { - IMAGE_FILE_MACHINE_I386, - IMAGE_FILE_MACHINE_AMD64, - IMAGE_FILE_MACHINE_IA64 - => {}, + IMAGE_FILE_MACHINE_I386, IMAGE_FILE_MACHINE_AMD64, IMAGE_FILE_MACHINE_IA64 => {}, else => return error.InvalidMachine, } @@ -89,11 +86,9 @@ pub const Coff = struct { var skip_size: u16 = undefined; if (self.pe_header.magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC) { skip_size = 2 * @sizeOf(u8) + 8 * @sizeOf(u16) + 18 * @sizeOf(u32); - } - else if (self.pe_header.magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC) { + } else if (self.pe_header.magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC) { skip_size = 2 * @sizeOf(u8) + 8 * @sizeOf(u16) + 12 * @sizeOf(u32) + 5 * @sizeOf(u64); - } - else + } else return error.InvalidPEMagic; try self.in_file.seekForward(skip_size); @@ -103,7 +98,7 @@ pub const Coff = struct { return error.InvalidPEHeader; for (self.pe_header.data_directory) |*data_dir| { - data_dir.* = OptionalHeader.DataDirectory { + data_dir.* = OptionalHeader.DataDirectory{ .virtual_address = try in.readIntLe(u32), .size = try in.readIntLe(u32), }; @@ -114,7 +109,7 @@ pub const Coff = struct { try self.loadSections(); const header = (self.getSection(".rdata") orelse return error.MissingCoffSection).header; - // The linker puts a chunk that contains the .pdb path right after the + // The linker puts a chunk that contains the .pdb path right after the // debug_directory. const debug_dir = &self.pe_header.data_directory[DEBUG_DIRECTORY]; const file_offset = debug_dir.virtual_address - header.virtual_address + header.pointer_to_raw_data; @@ -159,10 +154,10 @@ pub const Coff = struct { var i: u16 = 0; while (i < self.coff_header.number_of_sections) : (i += 1) { try in.readNoEof(name[0..]); - try self.sections.append(Section { - .header = SectionHeader { + try self.sections.append(Section{ + .header = SectionHeader{ .name = name, - .misc = SectionHeader.Misc { .physical_address = try in.readIntLe(u32) }, + .misc = SectionHeader.Misc{ .physical_address = try in.readIntLe(u32) }, .virtual_address = try in.readIntLe(u32), .size_of_raw_data = try in.readIntLe(u32), .pointer_to_raw_data = try in.readIntLe(u32), @@ -184,7 +179,6 @@ pub const Coff = struct { } return null; } - }; const CoffHeader = struct { @@ -194,13 +188,13 @@ const CoffHeader = struct { pointer_to_symbol_table: u32, number_of_symbols: u32, size_of_optional_header: u16, - characteristics: u16 + characteristics: u16, }; const OptionalHeader = struct { const DataDirectory = struct { virtual_address: u32, - size: u32 + size: u32, }; magic: u16, @@ -214,7 +208,7 @@ pub const Section = struct { const SectionHeader = struct { const Misc = union { physical_address: u32, - virtual_size: u32 + virtual_size: u32, }; name: [8]u8, diff --git a/std/crypto/x25519.zig b/std/crypto/x25519.zig index 41b2ff0959..bf78511f9a 100644 --- a/std/crypto/x25519.zig +++ b/std/crypto/x25519.zig @@ -115,7 +115,7 @@ pub const X25519 = struct { return !zerocmp(u8, out); } - pub fn createPublicKey(public_key: [] u8, private_key: []const u8) bool { + pub fn createPublicKey(public_key: []u8, private_key: []const u8) bool { var base_point = []u8{9} ++ []u8{0} ** 31; return create(public_key, private_key, base_point); } diff --git a/std/debug/index.zig b/std/debug/index.zig index 8db7c75d2c..14e8b9197a 100644 --- a/std/debug/index.zig +++ b/std/debug/index.zig @@ -242,9 +242,12 @@ pub fn writeCurrentStackTrace(out_stream: var, debug_info: *DebugInfo, tty_color } } -pub fn writeCurrentStackTraceWindows(out_stream: var, debug_info: *DebugInfo, - tty_color: bool, start_addr: ?usize) !void -{ +pub fn writeCurrentStackTraceWindows( + out_stream: var, + debug_info: *DebugInfo, + tty_color: bool, + start_addr: ?usize, +) !void { var addr_buf: [1024]usize = undefined; const casted_len = @intCast(u32, addr_buf.len); // TODO shouldn't need this cast const n = windows.RtlCaptureStackBackTrace(0, casted_len, @ptrCast(**c_void, &addr_buf), null); @@ -391,7 +394,7 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres break :subsections null; } }; - + if (tty_color) { setTtyColor(TtyColor.White); if (opt_line_info) |li| { @@ -438,7 +441,7 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres } } -const TtyColor = enum{ +const TtyColor = enum { Red, Green, Cyan, @@ -465,18 +468,16 @@ fn setTtyColor(tty_color: TtyColor) void { // TODO handle errors switch (tty_color) { TtyColor.Red => { - _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_RED|windows.FOREGROUND_INTENSITY); + _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_RED | windows.FOREGROUND_INTENSITY); }, TtyColor.Green => { - _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_GREEN|windows.FOREGROUND_INTENSITY); + _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_GREEN | windows.FOREGROUND_INTENSITY); }, TtyColor.Cyan => { - _ = windows.SetConsoleTextAttribute(stderr_file.handle, - windows.FOREGROUND_GREEN|windows.FOREGROUND_BLUE|windows.FOREGROUND_INTENSITY); + _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_GREEN | windows.FOREGROUND_BLUE | windows.FOREGROUND_INTENSITY); }, TtyColor.White, TtyColor.Bold => { - _ = windows.SetConsoleTextAttribute(stderr_file.handle, - windows.FOREGROUND_RED|windows.FOREGROUND_GREEN|windows.FOREGROUND_BLUE|windows.FOREGROUND_INTENSITY); + _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_RED | windows.FOREGROUND_GREEN | windows.FOREGROUND_BLUE | windows.FOREGROUND_INTENSITY); }, TtyColor.Dim => { _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_INTENSITY); diff --git a/std/event/fs.zig b/std/event/fs.zig index c13a940a36..5635471212 100644 --- a/std/event/fs.zig +++ b/std/event/fs.zig @@ -119,7 +119,7 @@ pub async fn pwriteWindows(loop: *Loop, fd: os.FileHandle, data: []const u8, off }, }; // TODO only call create io completion port once per fd - _ = try os.windowsCreateIoCompletionPort(fd, loop.os_data.io_port, undefined, undefined); + _ = windows.CreateIoCompletionPort(fd, loop.os_data.io_port, undefined, undefined); loop.beginOneEvent(); errdefer loop.finishOneEvent(); @@ -251,7 +251,7 @@ pub async fn preadWindows(loop: *Loop, fd: os.FileHandle, data: []u8, offset: u6 }, }; // TODO only call create io completion port once per fd - _ = try os.windowsCreateIoCompletionPort(fd, loop.os_data.io_port, undefined, undefined); + _ = windows.CreateIoCompletionPort(fd, loop.os_data.io_port, undefined, undefined); loop.beginOneEvent(); errdefer loop.finishOneEvent(); @@ -264,12 +264,13 @@ pub async fn preadWindows(loop: *Loop, fd: os.FileHandle, data: []u8, offset: u6 var bytes_transferred: windows.DWORD = undefined; if (windows.GetOverlappedResult(fd, &resume_node.base.overlapped, &bytes_transferred, windows.FALSE) == 0) { const err = windows.GetLastError(); - return switch (err) { + switch (err) { windows.ERROR.IO_PENDING => unreachable, - windows.ERROR.OPERATION_ABORTED => error.OperationAborted, - windows.ERROR.BROKEN_PIPE => error.BrokenPipe, - else => os.unexpectedErrorWindows(err), - }; + windows.ERROR.OPERATION_ABORTED => return error.OperationAborted, + windows.ERROR.BROKEN_PIPE => return error.BrokenPipe, + windows.ERROR.HANDLE_EOF => return usize(bytes_transferred), + else => return os.unexpectedErrorWindows(err), + } } return usize(bytes_transferred); } diff --git a/std/event/loop.zig b/std/event/loop.zig index 6cd22ff69e..e87e928049 100644 --- a/std/event/loop.zig +++ b/std/event/loop.zig @@ -29,7 +29,7 @@ pub const Loop = struct { handle: promise, overlapped: Overlapped, - const overlapped_init = switch (builtin.os) { + pub const overlapped_init = switch (builtin.os) { builtin.Os.windows => windows.OVERLAPPED{ .Internal = 0, .InternalHigh = 0, @@ -39,7 +39,7 @@ pub const Loop = struct { }, else => {}, }; - const Overlapped = @typeOf(overlapped_init); + pub const Overlapped = @typeOf(overlapped_init); pub const Id = enum { Basic, @@ -415,6 +415,7 @@ pub const Loop = struct { .base = ResumeNode{ .id = ResumeNode.Id.Basic, .handle = @handle(), + .overlapped = ResumeNode.overlapped_init, }, }; try self.linuxAddFd(fd, &resume_node.base, flags); @@ -697,11 +698,10 @@ pub const Loop = struct { const overlapped = while (true) { var nbytes: windows.DWORD = undefined; var overlapped: ?*windows.OVERLAPPED = undefined; - switch (os.windowsGetQueuedCompletionStatus(self.os_data.io_port, &nbytes, &completion_key, - &overlapped, windows.INFINITE)) - { + switch (os.windowsGetQueuedCompletionStatus(self.os_data.io_port, &nbytes, &completion_key, &overlapped, windows.INFINITE)) { os.WindowsWaitResult.Aborted => return, os.WindowsWaitResult.Normal => {}, + os.WindowsWaitResult.EOF => {}, os.WindowsWaitResult.Cancelled => continue, } if (overlapped) |o| break o; diff --git a/std/event/tcp.zig b/std/event/tcp.zig index 491acab39d..69b143dda0 100644 --- a/std/event/tcp.zig +++ b/std/event/tcp.zig @@ -32,6 +32,7 @@ pub const Server = struct { .listen_resume_node = event.Loop.ResumeNode{ .id = event.Loop.ResumeNode.Id.Basic, .handle = undefined, + .overlapped = event.Loop.ResumeNode.overlapped_init, }, }; } diff --git a/std/os/child_process.zig b/std/os/child_process.zig index a8f307f3b6..8b76a3cb9e 100644 --- a/std/os/child_process.zig +++ b/std/os/child_process.zig @@ -658,8 +658,16 @@ fn windowsCreateProcess(app_name: [*]u16, cmd_line: [*]u16, envp_ptr: ?[*]u16, c // environment variables to programs that were not, which seems unlikely. // More investigation is needed. if (windows.CreateProcessW( - app_name, cmd_line, null, null, windows.TRUE, windows.CREATE_UNICODE_ENVIRONMENT, - @ptrCast(?*c_void, envp_ptr), cwd_ptr, lpStartupInfo, lpProcessInformation, + app_name, + cmd_line, + null, + null, + windows.TRUE, + windows.CREATE_UNICODE_ENVIRONMENT, + @ptrCast(?*c_void, envp_ptr), + cwd_ptr, + lpStartupInfo, + lpProcessInformation, ) == 0) { const err = windows.GetLastError(); switch (err) { diff --git a/std/os/windows/kernel32.zig b/std/os/windows/kernel32.zig index 1a7b28eac2..94b339fa6e 100644 --- a/std/os/windows/kernel32.zig +++ b/std/os/windows/kernel32.zig @@ -206,7 +206,6 @@ pub const FILE_NOTIFY_CHANGE_DIR_NAME = 2; pub const FILE_NOTIFY_CHANGE_FILE_NAME = 1; pub const FILE_NOTIFY_CHANGE_ATTRIBUTES = 4; - pub const CONSOLE_SCREEN_BUFFER_INFO = extern struct { dwSize: COORD, dwCursorPosition: COORD, diff --git a/std/os/windows/util.zig b/std/os/windows/util.zig index 2a1a82a963..6534d16f5e 100644 --- a/std/os/windows/util.zig +++ b/std/os/windows/util.zig @@ -223,7 +223,7 @@ pub fn windowsFindFirstFile( dir_path: []const u8, find_file_data: *windows.WIN32_FIND_DATAW, ) !windows.HANDLE { - const dir_path_w = try sliceToPrefixedSuffixedFileW(dir_path, []u16{'\\', '*', 0}); + const dir_path_w = try sliceToPrefixedSuffixedFileW(dir_path, []u16{ '\\', '*', 0 }); const handle = windows.FindFirstFileW(&dir_path_w, find_file_data); if (handle == windows.INVALID_HANDLE_VALUE) { @@ -278,6 +278,7 @@ pub const WindowsWaitResult = enum { Normal, Aborted, Cancelled, + EOF, }; pub fn windowsGetQueuedCompletionStatus(completion_port: windows.HANDLE, bytes_transferred_count: *windows.DWORD, lpCompletionKey: *usize, lpOverlapped: *?*windows.OVERLAPPED, dwMilliseconds: windows.DWORD) WindowsWaitResult { @@ -286,6 +287,7 @@ pub fn windowsGetQueuedCompletionStatus(completion_port: windows.HANDLE, bytes_t switch (err) { windows.ERROR.ABANDONED_WAIT_0 => return WindowsWaitResult.Aborted, windows.ERROR.OPERATION_ABORTED => return WindowsWaitResult.Cancelled, + windows.ERROR.HANDLE_EOF => return WindowsWaitResult.EOF, else => { if (std.debug.runtime_safety) { std.debug.panic("unexpected error: {}\n", err); diff --git a/std/pdb.zig b/std/pdb.zig index 907eddff04..3bb6c9d58d 100644 --- a/std/pdb.zig +++ b/std/pdb.zig @@ -64,19 +64,35 @@ pub const ModInfo = packed struct { }; pub const SectionMapHeader = packed struct { - Count: u16, /// Number of segment descriptors - LogCount: u16, /// Number of logical segment descriptors + /// Number of segment descriptors + Count: u16, + + /// Number of logical segment descriptors + LogCount: u16, }; pub const SectionMapEntry = packed struct { - Flags: u16 , /// See the SectionMapEntryFlags enum below. - Ovl: u16 , /// Logical overlay number - Group: u16 , /// Group index into descriptor array. - Frame: u16 , - SectionName: u16 , /// Byte index of segment / group name in string table, or 0xFFFF. - ClassName: u16 , /// Byte index of class in string table, or 0xFFFF. - Offset: u32 , /// Byte offset of the logical segment within physical segment. If group is set in flags, this is the offset of the group. - SectionLength: u32 , /// Byte count of the segment or group. + /// See the SectionMapEntryFlags enum below. + Flags: u16, + + /// Logical overlay number + Ovl: u16, + + /// Group index into descriptor array. + Group: u16, + Frame: u16, + + /// Byte index of segment / group name in string table, or 0xFFFF. + SectionName: u16, + + /// Byte index of class in string table, or 0xFFFF. + ClassName: u16, + + /// Byte offset of the logical segment within physical segment. If group is set in flags, this is the offset of the group. + Offset: u32, + + /// Byte count of the segment or group. + SectionLength: u32, }; pub const StreamType = enum(u16) { @@ -290,13 +306,13 @@ pub const SymbolKind = packed enum(u16) { pub const TypeIndex = u32; pub const ProcSym = packed struct { - Parent: u32 , - End: u32 , - Next: u32 , - CodeSize: u32 , - DbgStart: u32 , - DbgEnd: u32 , - FunctionType: TypeIndex , + Parent: u32, + End: u32, + Next: u32, + CodeSize: u32, + DbgStart: u32, + DbgEnd: u32, + FunctionType: TypeIndex, CodeOffset: u32, Segment: u16, Flags: ProcSymFlags, @@ -315,25 +331,34 @@ pub const ProcSymFlags = packed struct { HasOptimizedDebugInfo: bool, }; -pub const SectionContrSubstreamVersion = enum(u32) { - Ver60 = 0xeffe0000 + 19970605, - V2 = 0xeffe0000 + 20140516 +pub const SectionContrSubstreamVersion = enum(u32) { + Ver60 = 0xeffe0000 + 19970605, + V2 = 0xeffe0000 + 20140516, }; pub const RecordPrefix = packed struct { - RecordLen: u16, /// Record length, starting from &RecordKind. - RecordKind: SymbolKind, /// Record kind enum (SymRecordKind or TypeRecordKind) + /// Record length, starting from &RecordKind. + RecordLen: u16, + + /// Record kind enum (SymRecordKind or TypeRecordKind) + RecordKind: SymbolKind, }; pub const LineFragmentHeader = packed struct { - RelocOffset: u32, /// Code offset of line contribution. - RelocSegment: u16, /// Code segment of line contribution. + /// Code offset of line contribution. + RelocOffset: u32, + + /// Code segment of line contribution. + RelocSegment: u16, Flags: LineFlags, - CodeSize: u32, /// Code size of this line contribution. + + /// Code size of this line contribution. + CodeSize: u32, }; pub const LineFlags = packed struct { - LF_HaveColumns: bool, /// CV_LINES_HAVE_COLUMNS + /// CV_LINES_HAVE_COLUMNS + LF_HaveColumns: bool, unused: u15, }; @@ -348,12 +373,14 @@ pub const LineBlockFragmentHeader = packed struct { /// table of the actual name. NameIndex: u32, NumLines: u32, - BlockSize: u32, /// code size of block, in bytes -}; + /// code size of block, in bytes + BlockSize: u32, +}; pub const LineNumberEntry = packed struct { - Offset: u32, /// Offset to start of code bytes for line number + /// Offset to start of code bytes for line number + Offset: u32, Flags: u32, /// TODO runtime crash when I make the actual type of Flags this @@ -371,42 +398,53 @@ pub const ColumnNumberEntry = packed struct { /// Checksum bytes follow. pub const FileChecksumEntryHeader = packed struct { - FileNameOffset: u32, /// Byte offset of filename in global string table. - ChecksumSize: u8, /// Number of bytes of checksum. - ChecksumKind: u8, /// FileChecksumKind + /// Byte offset of filename in global string table. + FileNameOffset: u32, + + /// Number of bytes of checksum. + ChecksumSize: u8, + + /// FileChecksumKind + ChecksumKind: u8, }; pub const DebugSubsectionKind = packed enum(u32) { - None = 0, - Symbols = 0xf1, - Lines = 0xf2, - StringTable = 0xf3, - FileChecksums = 0xf4, - FrameData = 0xf5, - InlineeLines = 0xf6, - CrossScopeImports = 0xf7, - CrossScopeExports = 0xf8, - - // These appear to relate to .Net assembly info. - ILLines = 0xf9, - FuncMDTokenMap = 0xfa, - TypeMDTokenMap = 0xfb, - MergedAssemblyInput = 0xfc, - - CoffSymbolRVA = 0xfd, + None = 0, + Symbols = 0xf1, + Lines = 0xf2, + StringTable = 0xf3, + FileChecksums = 0xf4, + FrameData = 0xf5, + InlineeLines = 0xf6, + CrossScopeImports = 0xf7, + CrossScopeExports = 0xf8, + + // These appear to relate to .Net assembly info. + ILLines = 0xf9, + FuncMDTokenMap = 0xfa, + TypeMDTokenMap = 0xfb, + MergedAssemblyInput = 0xfc, + + CoffSymbolRVA = 0xfd, }; - pub const DebugSubsectionHeader = packed struct { - Kind: DebugSubsectionKind, /// codeview::DebugSubsectionKind enum - Length: u32, /// number of bytes occupied by this record. -}; + /// codeview::DebugSubsectionKind enum + Kind: DebugSubsectionKind, + /// number of bytes occupied by this record. + Length: u32, +}; pub const PDBStringTableHeader = packed struct { - Signature: u32, /// PDBStringTableSignature - HashVersion: u32, /// 1 or 2 - ByteSize: u32, /// Number of bytes of names buffer. + /// PDBStringTableSignature + Signature: u32, + + /// 1 or 2 + HashVersion: u32, + + /// Number of bytes of names buffer. + ByteSize: u32, }; pub const Pdb = struct { @@ -456,7 +494,7 @@ const Msf = struct { switch (superblock.BlockSize) { // llvm only supports 4096 but we can handle any of these values 512, 1024, 2048, 4096 => {}, - else => return error.InvalidDebugInfo + else => return error.InvalidDebugInfo, } if (superblock.NumBlocks * superblock.BlockSize != try file.getEndPos()) @@ -536,7 +574,6 @@ const SuperBlock = packed struct { /// The number of ulittle32_t’s in this array is given by /// ceil(NumDirectoryBytes / BlockSize). BlockMapAddr: u32, - }; const MsfStream = struct { @@ -552,14 +589,12 @@ const MsfStream = struct { pub const Stream = io.InStream(Error); fn init(block_size: u32, block_count: u32, pos: usize, file: os.File, allocator: *mem.Allocator) !MsfStream { - var stream = MsfStream { + var stream = MsfStream{ .in_file = file, .pos = 0, .blocks = try allocator.alloc(u32, block_count), .block_size = block_size, - .stream = Stream { - .readFn = readFn, - }, + .stream = Stream{ .readFn = readFn }, }; var file_stream = io.FileInStream.init(file); @@ -597,7 +632,7 @@ const MsfStream = struct { var size: usize = 0; for (buffer) |*byte| { - byte.* = try in.readByte(); + byte.* = try in.readByte(); offset += 1; size += 1; -- cgit v1.2.3 From c06a61e9bf93810174255474598cfeae785cfbd6 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 13 Sep 2018 16:34:33 -0400 Subject: remove `this`. add `@This()`. closes #1283 --- doc/langref.html.in | 13 ++------ src-self-hosted/type.zig | 12 ------- src/all_types.hpp | 4 +-- src/analyze.cpp | 68 +++----------------------------------- src/analyze.hpp | 1 - src/ast_render.cpp | 7 ---- src/codegen.cpp | 13 +------- src/ir.cpp | 81 ++++++++++++---------------------------------- src/parser.cpp | 9 +----- src/tokenizer.cpp | 2 -- src/tokenizer.hpp | 1 - std/array_list.zig | 2 +- std/atomic/int.zig | 2 +- std/atomic/queue.zig | 2 +- std/atomic/stack.zig | 2 +- std/build.zig | 2 +- std/crypto/blake2.zig | 4 +-- std/crypto/hmac.zig | 2 +- std/crypto/md5.zig | 2 +- std/crypto/poly1305.zig | 2 +- std/crypto/sha1.zig | 2 +- std/crypto/sha2.zig | 4 +-- std/crypto/sha3.zig | 2 +- std/event/channel.zig | 2 +- std/event/fs.zig | 2 +- std/event/future.zig | 2 +- std/event/group.zig | 2 +- std/event/locked.zig | 2 +- std/event/rwlocked.zig | 2 +- std/event/tcp.zig | 2 +- std/fmt/index.zig | 2 +- std/hash/crc.zig | 4 +-- std/hash/fnv.zig | 2 +- std/hash/siphash.zig | 2 +- std/hash_map.zig | 4 +-- std/heap.zig | 2 +- std/io.zig | 12 +++---- std/lazy_init.zig | 2 +- std/linked_list.zig | 2 +- std/math/complex/index.zig | 2 +- std/mem.zig | 2 +- std/net.zig | 2 +- std/os/index.zig | 2 +- std/segmented_list.zig | 2 +- std/zig/ast.zig | 4 +-- std/zig/parser_test.zig | 2 +- std/zig/render.zig | 2 +- test/cases/cast.zig | 4 +-- test/cases/eval.zig | 2 +- test/cases/misc.zig | 3 -- test/cases/reflection.zig | 2 +- test/cases/struct.zig | 4 +-- test/cases/this.zig | 13 ++------ test/cases/type_info.zig | 4 +-- test/compile_errors.zig | 28 ++++++++-------- 55 files changed, 97 insertions(+), 266 deletions(-) (limited to 'std/event') diff --git a/doc/langref.html.in b/doc/langref.html.in index aefbfc5650..3f2e741e36 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -478,13 +478,9 @@ pub fn main() void { undefined used to leave a value unspecified - - this - refers to the thing in immediate scope - - {#see_also|Optionals|this#} + {#see_also|Optionals#} {#header_close#} {#header_open|String Literals#} {#code_begin|test#} @@ -4186,11 +4182,6 @@ fn foo() void {} {#code_end#} {#header_close#} - {#header_open|this#} -

TODO: example of this referring to Self struct

-

TODO: example of this referring to recursion function

-

TODO: example of this referring to basic block for @setRuntimeSafety

- {#header_close#} {#header_open|comptime#}

Zig places importance on the concept of whether an expression is known at compile-time. @@ -7744,7 +7735,7 @@ ArrayType : "[" option(Expression) "]" option("align" "(" Expression option(":" GroupedExpression = "(" Expression ")" -KeywordLiteral = "true" | "false" | "null" | "undefined" | "error" | "this" | "unreachable" | "suspend" +KeywordLiteral = "true" | "false" | "null" | "undefined" | "error" | "unreachable" | "suspend" ErrorSetDecl = "error" "{" list(Symbol, ",") "}" diff --git a/src-self-hosted/type.zig b/src-self-hosted/type.zig index 47dd3772e5..aa00bb876d 100644 --- a/src-self-hosted/type.zig +++ b/src-self-hosted/type.zig @@ -40,7 +40,6 @@ pub const Type = struct { Id.Enum => @fieldParentPtr(Enum, "base", base).destroy(comp), Id.Union => @fieldParentPtr(Union, "base", base).destroy(comp), Id.Namespace => @fieldParentPtr(Namespace, "base", base).destroy(comp), - Id.Block => @fieldParentPtr(Block, "base", base).destroy(comp), Id.BoundFn => @fieldParentPtr(BoundFn, "base", base).destroy(comp), Id.ArgTuple => @fieldParentPtr(ArgTuple, "base", base).destroy(comp), Id.Opaque => @fieldParentPtr(Opaque, "base", base).destroy(comp), @@ -74,7 +73,6 @@ pub const Type = struct { Id.Enum => return @fieldParentPtr(Enum, "base", base).getLlvmType(allocator, llvm_context), Id.Union => return @fieldParentPtr(Union, "base", base).getLlvmType(allocator, llvm_context), Id.Namespace => unreachable, - Id.Block => unreachable, Id.BoundFn => return @fieldParentPtr(BoundFn, "base", base).getLlvmType(allocator, llvm_context), Id.ArgTuple => unreachable, Id.Opaque => return @fieldParentPtr(Opaque, "base", base).getLlvmType(allocator, llvm_context), @@ -90,7 +88,6 @@ pub const Type = struct { Id.Undefined, Id.Null, Id.Namespace, - Id.Block, Id.BoundFn, Id.ArgTuple, Id.Opaque, @@ -124,7 +121,6 @@ pub const Type = struct { Id.Undefined, Id.Null, Id.Namespace, - Id.Block, Id.BoundFn, Id.ArgTuple, Id.Opaque, @@ -1012,14 +1008,6 @@ pub const Type = struct { } }; - pub const Block = struct { - base: Type, - - pub fn destroy(self: *Block, comp: *Compilation) void { - comp.gpa().destroy(self); - } - }; - pub const BoundFn = struct { base: Type, diff --git a/src/all_types.hpp b/src/all_types.hpp index 27871156d6..fefbae0fe3 100644 --- a/src/all_types.hpp +++ b/src/all_types.hpp @@ -283,7 +283,6 @@ struct ConstExprValue { ConstArrayValue x_array; ConstPtrValue x_ptr; ImportTableEntry *x_import; - Scope *x_block; ConstArgTuple x_arg_tuple; // populated if special == ConstValSpecialRuntime @@ -413,7 +412,6 @@ enum NodeType { NodeTypeBoolLiteral, NodeTypeNullLiteral, NodeTypeUndefinedLiteral, - NodeTypeThisLiteral, NodeTypeUnreachable, NodeTypeIfBoolExpr, NodeTypeWhileExpr, @@ -1205,7 +1203,6 @@ enum ZigTypeId { ZigTypeIdUnion, ZigTypeIdFn, ZigTypeIdNamespace, - ZigTypeIdBlock, ZigTypeIdBoundFn, ZigTypeIdArgTuple, ZigTypeIdOpaque, @@ -1413,6 +1410,7 @@ enum BuiltinFnId { BuiltinFnIdSetEvalBranchQuota, BuiltinFnIdAlignCast, BuiltinFnIdOpaqueType, + BuiltinFnIdThis, BuiltinFnIdSetAlignStack, BuiltinFnIdArgType, BuiltinFnIdExport, diff --git a/src/analyze.cpp b/src/analyze.cpp index 9a9e9a0513..9af4f7347c 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -246,7 +246,6 @@ AstNode *type_decl_node(ZigType *type_entry) { case ZigTypeIdErrorSet: case ZigTypeIdFn: case ZigTypeIdNamespace: - case ZigTypeIdBlock: case ZigTypeIdBoundFn: case ZigTypeIdArgTuple: case ZigTypeIdPromise: @@ -284,7 +283,6 @@ bool type_is_complete(ZigType *type_entry) { case ZigTypeIdErrorSet: case ZigTypeIdFn: case ZigTypeIdNamespace: - case ZigTypeIdBlock: case ZigTypeIdBoundFn: case ZigTypeIdArgTuple: case ZigTypeIdPromise: @@ -320,7 +318,6 @@ bool type_has_zero_bits_known(ZigType *type_entry) { case ZigTypeIdErrorSet: case ZigTypeIdFn: case ZigTypeIdNamespace: - case ZigTypeIdBlock: case ZigTypeIdBoundFn: case ZigTypeIdArgTuple: case ZigTypeIdOpaque: @@ -1414,7 +1411,6 @@ static bool type_allowed_in_packed_struct(ZigType *type_entry) { case ZigTypeIdErrorUnion: case ZigTypeIdErrorSet: case ZigTypeIdNamespace: - case ZigTypeIdBlock: case ZigTypeIdBoundFn: case ZigTypeIdArgTuple: case ZigTypeIdOpaque: @@ -1455,7 +1451,6 @@ static bool type_allowed_in_extern(CodeGen *g, ZigType *type_entry) { case ZigTypeIdErrorUnion: case ZigTypeIdErrorSet: case ZigTypeIdNamespace: - case ZigTypeIdBlock: case ZigTypeIdBoundFn: case ZigTypeIdArgTuple: case ZigTypeIdPromise: @@ -1613,7 +1608,6 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc case ZigTypeIdComptimeFloat: case ZigTypeIdComptimeInt: case ZigTypeIdNamespace: - case ZigTypeIdBlock: case ZigTypeIdBoundFn: case ZigTypeIdMetaType: case ZigTypeIdVoid: @@ -1703,7 +1697,6 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc case ZigTypeIdComptimeFloat: case ZigTypeIdComptimeInt: case ZigTypeIdNamespace: - case ZigTypeIdBlock: case ZigTypeIdBoundFn: case ZigTypeIdMetaType: case ZigTypeIdUnreachable: @@ -3437,7 +3430,6 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) { case NodeTypeBoolLiteral: case NodeTypeNullLiteral: case NodeTypeUndefinedLiteral: - case NodeTypeThisLiteral: case NodeTypeSymbol: case NodeTypePrefixOpExpr: case NodeTypePointerType: @@ -3497,7 +3489,6 @@ ZigType *validate_var_type(CodeGen *g, AstNode *source_node, ZigType *type_entry case ZigTypeIdUnreachable: case ZigTypeIdUndefined: case ZigTypeIdNull: - case ZigTypeIdBlock: case ZigTypeIdArgTuple: case ZigTypeIdOpaque: add_node_error(g, source_node, buf_sprintf("variable of type '%s' not allowed", @@ -3798,34 +3789,6 @@ ZigFn *scope_fn_entry(Scope *scope) { return nullptr; } -ZigFn *scope_get_fn_if_root(Scope *scope) { - assert(scope); - scope = scope->parent; - while (scope) { - switch (scope->id) { - case ScopeIdBlock: - return nullptr; - case ScopeIdDecls: - case ScopeIdDefer: - case ScopeIdDeferExpr: - case ScopeIdVarDecl: - case ScopeIdCImport: - case ScopeIdLoop: - case ScopeIdSuspend: - case ScopeIdCompTime: - case ScopeIdCoroPrelude: - case ScopeIdRuntime: - scope = scope->parent; - continue; - case ScopeIdFnDef: - ScopeFnDef *fn_scope = (ScopeFnDef *)scope; - return fn_scope->fn_entry; - } - zig_unreachable(); - } - return nullptr; -} - TypeEnumField *find_enum_type_field(ZigType *enum_type, Buf *name) { assert(enum_type->id == ZigTypeIdEnum); if (enum_type->data.enumeration.src_field_count == 0) @@ -3907,7 +3870,6 @@ static bool is_container(ZigType *type_entry) { case ZigTypeIdErrorSet: case ZigTypeIdFn: case ZigTypeIdNamespace: - case ZigTypeIdBlock: case ZigTypeIdBoundFn: case ZigTypeIdArgTuple: case ZigTypeIdOpaque: @@ -3966,7 +3928,6 @@ void resolve_container_type(CodeGen *g, ZigType *type_entry) { case ZigTypeIdErrorSet: case ZigTypeIdFn: case ZigTypeIdNamespace: - case ZigTypeIdBlock: case ZigTypeIdBoundFn: case ZigTypeIdInvalid: case ZigTypeIdArgTuple: @@ -4427,7 +4388,6 @@ bool handle_is_ptr(ZigType *type_entry) { case ZigTypeIdUndefined: case ZigTypeIdNull: case ZigTypeIdNamespace: - case ZigTypeIdBlock: case ZigTypeIdBoundFn: case ZigTypeIdArgTuple: case ZigTypeIdOpaque: @@ -4842,8 +4802,6 @@ static uint32_t hash_const_val(ConstExprValue *const_val) { return const_val->data.x_err_set->value ^ 2630160122; case ZigTypeIdNamespace: return hash_ptr(const_val->data.x_import); - case ZigTypeIdBlock: - return hash_ptr(const_val->data.x_block); case ZigTypeIdBoundFn: case ZigTypeIdInvalid: case ZigTypeIdUnreachable: @@ -4904,7 +4862,6 @@ static bool can_mutate_comptime_var_state(ConstExprValue *value) { case ZigTypeIdNamespace: case ZigTypeIdBoundFn: case ZigTypeIdFn: - case ZigTypeIdBlock: case ZigTypeIdOpaque: case ZigTypeIdPromise: case ZigTypeIdErrorSet: @@ -4971,7 +4928,6 @@ static bool return_type_is_cacheable(ZigType *return_type) { case ZigTypeIdNamespace: case ZigTypeIdBoundFn: case ZigTypeIdFn: - case ZigTypeIdBlock: case ZigTypeIdOpaque: case ZigTypeIdPromise: case ZigTypeIdErrorSet: @@ -5083,7 +5039,6 @@ bool type_requires_comptime(ZigType *type_entry) { case ZigTypeIdNull: case ZigTypeIdMetaType: case ZigTypeIdNamespace: - case ZigTypeIdBlock: case ZigTypeIdBoundFn: case ZigTypeIdArgTuple: return true; @@ -5615,8 +5570,6 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) { zig_panic("TODO"); case ZigTypeIdNamespace: return a->data.x_import == b->data.x_import; - case ZigTypeIdBlock: - return a->data.x_block == b->data.x_block; case ZigTypeIdArgTuple: return a->data.x_arg_tuple.start_index == b->data.x_arg_tuple.start_index && a->data.x_arg_tuple.end_index == b->data.x_arg_tuple.end_index; @@ -5795,12 +5748,6 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) { } case ZigTypeIdPointer: return render_const_val_ptr(g, buf, const_val, type_entry); - case ZigTypeIdBlock: - { - AstNode *node = const_val->data.x_block->source_node; - buf_appendf(buf, "(scope:%" ZIG_PRI_usize ":%" ZIG_PRI_usize ")", node->line + 1, node->column + 1); - return; - } case ZigTypeIdArray: { ZigType *child_type = type_entry->data.array.child_type; @@ -5980,7 +5927,6 @@ uint32_t type_id_hash(TypeId x) { case ZigTypeIdUnion: case ZigTypeIdFn: case ZigTypeIdNamespace: - case ZigTypeIdBlock: case ZigTypeIdBoundFn: case ZigTypeIdArgTuple: case ZigTypeIdPromise: @@ -6027,7 +5973,6 @@ bool type_id_eql(TypeId a, TypeId b) { case ZigTypeIdUnion: case ZigTypeIdFn: case ZigTypeIdNamespace: - case ZigTypeIdBlock: case ZigTypeIdBoundFn: case ZigTypeIdArgTuple: case ZigTypeIdOpaque: @@ -6153,7 +6098,6 @@ static const ZigTypeId all_type_ids[] = { ZigTypeIdUnion, ZigTypeIdFn, ZigTypeIdNamespace, - ZigTypeIdBlock, ZigTypeIdBoundFn, ZigTypeIdArgTuple, ZigTypeIdOpaque, @@ -6215,16 +6159,14 @@ size_t type_id_index(ZigType *entry) { return 18; case ZigTypeIdNamespace: return 19; - case ZigTypeIdBlock: - return 20; case ZigTypeIdBoundFn: - return 21; + return 20; case ZigTypeIdArgTuple: - return 22; + return 21; case ZigTypeIdOpaque: - return 23; + return 22; case ZigTypeIdPromise: - return 24; + return 23; } zig_unreachable(); } @@ -6273,8 +6215,6 @@ const char *type_id_name(ZigTypeId id) { return "Fn"; case ZigTypeIdNamespace: return "Namespace"; - case ZigTypeIdBlock: - return "Block"; case ZigTypeIdBoundFn: return "BoundFn"; case ZigTypeIdArgTuple: diff --git a/src/analyze.hpp b/src/analyze.hpp index d69265f974..02f3d65800 100644 --- a/src/analyze.hpp +++ b/src/analyze.hpp @@ -87,7 +87,6 @@ ZigFn *create_fn(AstNode *proto_node); ZigFn *create_fn_raw(FnInline inline_value, GlobalLinkageId linkage); void init_fn_type_id(FnTypeId *fn_type_id, AstNode *proto_node, size_t param_count_alloc); AstNode *get_param_decl_node(ZigFn *fn_entry, size_t index); -ZigFn *scope_get_fn_if_root(Scope *scope); bool type_requires_comptime(ZigType *type_entry); Error ATTRIBUTE_MUST_USE ensure_complete_type(CodeGen *g, ZigType *type_entry); Error ATTRIBUTE_MUST_USE type_ensure_zero_bits_known(CodeGen *g, ZigType *type_entry); diff --git a/src/ast_render.cpp b/src/ast_render.cpp index 984b4230b1..37d4221eef 100644 --- a/src/ast_render.cpp +++ b/src/ast_render.cpp @@ -193,8 +193,6 @@ static const char *node_type_str(NodeType node_type) { return "NullLiteral"; case NodeTypeUndefinedLiteral: return "UndefinedLiteral"; - case NodeTypeThisLiteral: - return "ThisLiteral"; case NodeTypeIfBoolExpr: return "IfBoolExpr"; case NodeTypeWhileExpr: @@ -897,11 +895,6 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) { } break; } - case NodeTypeThisLiteral: - { - fprintf(ar->f, "this"); - break; - } case NodeTypeBoolLiteral: { const char *bool_str = node->data.bool_literal.value ? "true" : "false"; diff --git a/src/codegen.cpp b/src/codegen.cpp index 38f31074d0..86ede7411d 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -5479,7 +5479,6 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con case ZigTypeIdErrorUnion: case ZigTypeIdErrorSet: case ZigTypeIdNamespace: - case ZigTypeIdBlock: case ZigTypeIdBoundFn: case ZigTypeIdArgTuple: case ZigTypeIdVoid: @@ -5954,7 +5953,6 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c case ZigTypeIdUndefined: case ZigTypeIdNull: case ZigTypeIdNamespace: - case ZigTypeIdBlock: case ZigTypeIdBoundFn: case ZigTypeIdArgTuple: case ZigTypeIdOpaque: @@ -6477,12 +6475,6 @@ static void define_builtin_types(CodeGen *g) { entry->zero_bits = true; g->builtin_types.entry_namespace = entry; } - { - ZigType *entry = new_type_table_entry(ZigTypeIdBlock); - buf_init_from_str(&entry->name, "(block)"); - entry->zero_bits = true; - g->builtin_types.entry_block = entry; - } { ZigType *entry = new_type_table_entry(ZigTypeIdComptimeFloat); buf_init_from_str(&entry->name, "comptime_float"); @@ -6763,6 +6755,7 @@ static void define_builtin_fns(CodeGen *g) { create_builtin_fn(g, BuiltinFnIdErrSetCast, "errSetCast", 2); create_builtin_fn(g, BuiltinFnIdToBytes, "sliceToBytes", 1); create_builtin_fn(g, BuiltinFnIdFromBytes, "bytesToSlice", 2); + create_builtin_fn(g, BuiltinFnIdThis, "This", 0); } static const char *bool_to_str(bool b) { @@ -6944,7 +6937,6 @@ Buf *codegen_generate_builtin_source(CodeGen *g) { " Union: Union,\n" " Fn: Fn,\n" " Namespace: void,\n" - " Block: void,\n" " BoundFn: Fn,\n" " ArgTuple: void,\n" " Opaque: void,\n" @@ -7589,7 +7581,6 @@ static void prepend_c_type_to_decl_list(CodeGen *g, GenH *gen_h, ZigType *type_e case ZigTypeIdUndefined: case ZigTypeIdNull: case ZigTypeIdNamespace: - case ZigTypeIdBlock: case ZigTypeIdBoundFn: case ZigTypeIdArgTuple: case ZigTypeIdErrorUnion: @@ -7768,7 +7759,6 @@ static void get_c_type(CodeGen *g, GenH *gen_h, ZigType *type_entry, Buf *out_bu case ZigTypeIdMetaType: case ZigTypeIdBoundFn: case ZigTypeIdNamespace: - case ZigTypeIdBlock: case ZigTypeIdComptimeFloat: case ZigTypeIdComptimeInt: case ZigTypeIdUndefined: @@ -7921,7 +7911,6 @@ static void gen_h_file(CodeGen *g) { case ZigTypeIdErrorUnion: case ZigTypeIdErrorSet: case ZigTypeIdNamespace: - case ZigTypeIdBlock: case ZigTypeIdBoundFn: case ZigTypeIdArgTuple: case ZigTypeIdOptional: diff --git a/src/ir.cpp b/src/ir.cpp index 6f1a7a741a..7448d3fffe 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -1029,12 +1029,6 @@ static IrInstruction *ir_create_const_fn(IrBuilder *irb, Scope *scope, AstNode * return &const_instruction->base; } -static IrInstruction *ir_build_const_fn(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigFn *fn_entry) { - IrInstruction *instruction = ir_create_const_fn(irb, scope, source_node, fn_entry); - ir_instruction_append(irb->current_basic_block, instruction); - return instruction; -} - static IrInstruction *ir_build_const_import(IrBuilder *irb, Scope *scope, AstNode *source_node, ImportTableEntry *import) { IrInstructionConst *const_instruction = ir_build_instruction(irb, scope, source_node); const_instruction->base.value.type = irb->codegen->builtin_types.entry_namespace; @@ -1043,16 +1037,6 @@ static IrInstruction *ir_build_const_import(IrBuilder *irb, Scope *scope, AstNod return &const_instruction->base; } -static IrInstruction *ir_build_const_scope(IrBuilder *irb, Scope *parent_scope, AstNode *source_node, - Scope *target_scope) -{ - IrInstructionConst *const_instruction = ir_build_instruction(irb, parent_scope, source_node); - const_instruction->base.value.type = irb->codegen->builtin_types.entry_block; - const_instruction->base.value.special = ConstValSpecialStatic; - const_instruction->base.value.data.x_block = target_scope; - return &const_instruction->base; -} - static IrInstruction *ir_build_const_bool(IrBuilder *irb, Scope *scope, AstNode *source_node, bool value) { IrInstructionConst *const_instruction = ir_build_instruction(irb, scope, source_node); const_instruction->base.value.type = irb->codegen->builtin_types.entry_bool; @@ -3892,6 +3876,21 @@ static IrInstruction *ir_gen_overflow_op(IrBuilder *irb, Scope *scope, AstNode * return ir_build_overflow_op(irb, scope, node, op, type_value, op1, op2, result_ptr, nullptr); } +static IrInstruction *ir_gen_this(IrBuilder *irb, Scope *orig_scope, AstNode *node) { + for (Scope *it_scope = orig_scope; it_scope != nullptr; it_scope = it_scope->parent) { + if (it_scope->id == ScopeIdDecls) { + ScopeDecls *decls_scope = (ScopeDecls *)it_scope; + ZigType *container_type = decls_scope->container_type; + if (container_type != nullptr) { + return ir_build_const_type(irb, orig_scope, node, container_type); + } else { + return ir_build_const_import(irb, orig_scope, node, decls_scope->import); + } + } + } + zig_unreachable(); +} + static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval) { assert(node->type == NodeTypeFnCallExpr); @@ -4830,6 +4829,11 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo IrInstruction *opaque_type = ir_build_opaque_type(irb, scope, node); return ir_lval_wrap(irb, scope, opaque_type, lval); } + case BuiltinFnIdThis: + { + IrInstruction *this_inst = ir_gen_this(irb, scope, node); + return ir_lval_wrap(irb, scope, this_inst, lval); + } case BuiltinFnIdSetAlignStack: { AstNode *arg0_node = node->data.fn_call_expr.params.at(0); @@ -5681,33 +5685,6 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo return ir_build_phi(irb, parent_scope, node, incoming_blocks.length, incoming_blocks.items, incoming_values.items); } -static IrInstruction *ir_gen_this_literal(IrBuilder *irb, Scope *scope, AstNode *node) { - assert(node->type == NodeTypeThisLiteral); - - if (!scope->parent) - return ir_build_const_import(irb, scope, node, node->owner); - - ZigFn *fn_entry = scope_get_fn_if_root(scope); - if (fn_entry) - return ir_build_const_fn(irb, scope, node, fn_entry); - - while (scope->id != ScopeIdBlock && scope->id != ScopeIdDecls) { - scope = scope->parent; - } - - if (scope->id == ScopeIdDecls) { - ScopeDecls *decls_scope = (ScopeDecls *)scope; - ZigType *container_type = decls_scope->container_type; - assert(container_type); - return ir_build_const_type(irb, scope, node, container_type); - } - - if (scope->id == ScopeIdBlock) - return ir_build_const_scope(irb, scope, node, scope); - - zig_unreachable(); -} - static IrInstruction *ir_gen_bool_literal(IrBuilder *irb, Scope *scope, AstNode *node) { assert(node->type == NodeTypeBoolLiteral); return ir_build_const_bool(irb, scope, node, node->data.bool_literal.value); @@ -7285,8 +7262,6 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop return ir_build_load_ptr(irb, scope, node, unwrapped_ptr); } - case NodeTypeThisLiteral: - return ir_lval_wrap(irb, scope, ir_gen_this_literal(irb, scope, node), lval); case NodeTypeBoolLiteral: return ir_lval_wrap(irb, scope, ir_gen_bool_literal(irb, scope, node), lval); case NodeTypeArrayType: @@ -11621,7 +11596,6 @@ static ZigType *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op case ZigTypeIdFn: case ZigTypeIdOpaque: case ZigTypeIdNamespace: - case ZigTypeIdBlock: case ZigTypeIdBoundFn: case ZigTypeIdArgTuple: case ZigTypeIdPromise: @@ -12822,7 +12796,6 @@ static ZigType *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructionExpor case ZigTypeIdErrorUnion: case ZigTypeIdErrorSet: case ZigTypeIdNamespace: - case ZigTypeIdBlock: case ZigTypeIdBoundFn: case ZigTypeIdArgTuple: case ZigTypeIdOpaque: @@ -12847,7 +12820,6 @@ static ZigType *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructionExpor case ZigTypeIdErrorSet: zig_panic("TODO export const value of type %s", buf_ptr(&target->value.type->name)); case ZigTypeIdNamespace: - case ZigTypeIdBlock: case ZigTypeIdBoundFn: case ZigTypeIdArgTuple: case ZigTypeIdOpaque: @@ -13905,7 +13877,6 @@ static ZigType *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op_instru case ZigTypeIdUnion: case ZigTypeIdFn: case ZigTypeIdNamespace: - case ZigTypeIdBlock: case ZigTypeIdBoundFn: case ZigTypeIdArgTuple: case ZigTypeIdPromise: @@ -15263,7 +15234,6 @@ static ZigType *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructionTypeO case ZigTypeIdUndefined: case ZigTypeIdNull: case ZigTypeIdNamespace: - case ZigTypeIdBlock: case ZigTypeIdBoundFn: case ZigTypeIdMetaType: case ZigTypeIdVoid: @@ -15516,7 +15486,6 @@ static ZigType *ir_analyze_instruction_slice_type(IrAnalyze *ira, case ZigTypeIdUnreachable: case ZigTypeIdUndefined: case ZigTypeIdNull: - case ZigTypeIdBlock: case ZigTypeIdArgTuple: case ZigTypeIdOpaque: ir_add_error_node(ira, slice_type_instruction->base.source_node, @@ -15627,7 +15596,6 @@ static ZigType *ir_analyze_instruction_array_type(IrAnalyze *ira, case ZigTypeIdUnreachable: case ZigTypeIdUndefined: case ZigTypeIdNull: - case ZigTypeIdBlock: case ZigTypeIdArgTuple: case ZigTypeIdOpaque: ir_add_error_node(ira, array_type_instruction->base.source_node, @@ -15698,7 +15666,6 @@ static ZigType *ir_analyze_instruction_size_of(IrAnalyze *ira, case ZigTypeIdUnreachable: case ZigTypeIdUndefined: case ZigTypeIdNull: - case ZigTypeIdBlock: case ZigTypeIdComptimeFloat: case ZigTypeIdComptimeInt: case ZigTypeIdBoundFn: @@ -16184,7 +16151,6 @@ static ZigType *ir_analyze_instruction_switch_target(IrAnalyze *ira, case ZigTypeIdUndefined: case ZigTypeIdNull: case ZigTypeIdOptional: - case ZigTypeIdBlock: case ZigTypeIdBoundFn: case ZigTypeIdArgTuple: case ZigTypeIdOpaque: @@ -16705,7 +16671,6 @@ static ZigType *ir_analyze_min_max(IrAnalyze *ira, IrInstruction *source_instruc case ZigTypeIdUnion: case ZigTypeIdFn: case ZigTypeIdNamespace: - case ZigTypeIdBlock: case ZigTypeIdBoundFn: case ZigTypeIdArgTuple: case ZigTypeIdOpaque: @@ -17368,7 +17333,6 @@ static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstE case ZigTypeIdUndefined: case ZigTypeIdNull: case ZigTypeIdNamespace: - case ZigTypeIdBlock: case ZigTypeIdArgTuple: case ZigTypeIdOpaque: *out = nullptr; @@ -19341,7 +19305,6 @@ static ZigType *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstructionAli case ZigTypeIdUndefined: case ZigTypeIdNull: case ZigTypeIdNamespace: - case ZigTypeIdBlock: case ZigTypeIdBoundFn: case ZigTypeIdArgTuple: case ZigTypeIdVoid: @@ -20102,7 +20065,6 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue case ZigTypeIdBoundFn: case ZigTypeIdArgTuple: case ZigTypeIdNamespace: - case ZigTypeIdBlock: case ZigTypeIdUnreachable: case ZigTypeIdComptimeFloat: case ZigTypeIdComptimeInt: @@ -20169,7 +20131,6 @@ static void buf_read_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue case ZigTypeIdBoundFn: case ZigTypeIdArgTuple: case ZigTypeIdNamespace: - case ZigTypeIdBlock: case ZigTypeIdUnreachable: case ZigTypeIdComptimeFloat: case ZigTypeIdComptimeInt: @@ -20249,7 +20210,6 @@ static ZigType *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstructionBit case ZigTypeIdBoundFn: case ZigTypeIdArgTuple: case ZigTypeIdNamespace: - case ZigTypeIdBlock: case ZigTypeIdUnreachable: case ZigTypeIdComptimeFloat: case ZigTypeIdComptimeInt: @@ -20275,7 +20235,6 @@ static ZigType *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstructionBit case ZigTypeIdBoundFn: case ZigTypeIdArgTuple: case ZigTypeIdNamespace: - case ZigTypeIdBlock: case ZigTypeIdUnreachable: case ZigTypeIdComptimeFloat: case ZigTypeIdComptimeInt: diff --git a/src/parser.cpp b/src/parser.cpp index 453ab7ce2c..8e6076c5e5 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -700,7 +700,7 @@ static AstNode *ast_parse_comptime_expr(ParseContext *pc, size_t *token_index, b /* PrimaryExpression = Integer | Float | String | CharLiteral | KeywordLiteral | GroupedExpression | BlockExpression(BlockOrExpression) | Symbol | ("@" Symbol FnCallExpression) | ArrayType | FnProto | AsmExpression | ContainerDecl | ("continue" option(":" Symbol)) | ErrorSetDecl | PromiseType -KeywordLiteral = "true" | "false" | "null" | "undefined" | "error" | "this" | "unreachable" | "suspend" +KeywordLiteral = "true" | "false" | "null" | "undefined" | "error" | "unreachable" | "suspend" ErrorSetDecl = "error" "{" list(Symbol, ",") "}" */ static AstNode *ast_parse_primary_expr(ParseContext *pc, size_t *token_index, bool mandatory) { @@ -756,10 +756,6 @@ static AstNode *ast_parse_primary_expr(ParseContext *pc, size_t *token_index, bo AstNode *node = ast_create_node(pc, NodeTypeUndefinedLiteral, token); *token_index += 1; return node; - } else if (token->id == TokenIdKeywordThis) { - AstNode *node = ast_create_node(pc, NodeTypeThisLiteral, token); - *token_index += 1; - return node; } else if (token->id == TokenIdKeywordUnreachable) { AstNode *node = ast_create_node(pc, NodeTypeUnreachable, token); *token_index += 1; @@ -3021,9 +3017,6 @@ void ast_visit_node_children(AstNode *node, void (*visit)(AstNode **, void *cont case NodeTypeUndefinedLiteral: // none break; - case NodeTypeThisLiteral: - // none - break; case NodeTypeIfBoolExpr: visit_field(&node->data.if_bool_expr.condition, visit, context); visit_field(&node->data.if_bool_expr.then_block, visit, context); diff --git a/src/tokenizer.cpp b/src/tokenizer.cpp index 1d3db5567a..84d1d90518 100644 --- a/src/tokenizer.cpp +++ b/src/tokenizer.cpp @@ -146,7 +146,6 @@ static const struct ZigKeyword zig_keywords[] = { {"suspend", TokenIdKeywordSuspend}, {"switch", TokenIdKeywordSwitch}, {"test", TokenIdKeywordTest}, - {"this", TokenIdKeywordThis}, {"true", TokenIdKeywordTrue}, {"try", TokenIdKeywordTry}, {"undefined", TokenIdKeywordUndefined}, @@ -1588,7 +1587,6 @@ const char * token_name(TokenId id) { case TokenIdKeywordStruct: return "struct"; case TokenIdKeywordSwitch: return "switch"; case TokenIdKeywordTest: return "test"; - case TokenIdKeywordThis: return "this"; case TokenIdKeywordTrue: return "true"; case TokenIdKeywordTry: return "try"; case TokenIdKeywordUndefined: return "undefined"; diff --git a/src/tokenizer.hpp b/src/tokenizer.hpp index 75c7feb476..cae6835d0f 100644 --- a/src/tokenizer.hpp +++ b/src/tokenizer.hpp @@ -87,7 +87,6 @@ enum TokenId { TokenIdKeywordSuspend, TokenIdKeywordSwitch, TokenIdKeywordTest, - TokenIdKeywordThis, TokenIdKeywordTrue, TokenIdKeywordTry, TokenIdKeywordUndefined, diff --git a/std/array_list.zig b/std/array_list.zig index dda6f176eb..3ee425fe14 100644 --- a/std/array_list.zig +++ b/std/array_list.zig @@ -11,7 +11,7 @@ pub fn ArrayList(comptime T: type) type { pub fn AlignedArrayList(comptime T: type, comptime A: u29) type { return struct { - const Self = this; + 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 diff --git a/std/atomic/int.zig b/std/atomic/int.zig index 4103d52719..6e07ef571a 100644 --- a/std/atomic/int.zig +++ b/std/atomic/int.zig @@ -6,7 +6,7 @@ pub fn Int(comptime T: type) type { return struct { unprotected_value: T, - pub const Self = this; + pub const Self = @This(); pub fn init(init_val: T) Self { return Self{ .unprotected_value = init_val }; diff --git a/std/atomic/queue.zig b/std/atomic/queue.zig index 6948af43ba..c1e2a4c98b 100644 --- a/std/atomic/queue.zig +++ b/std/atomic/queue.zig @@ -12,7 +12,7 @@ pub fn Queue(comptime T: type) type { tail: ?*Node, mutex: std.Mutex, - pub const Self = this; + pub const Self = @This(); pub const Node = std.LinkedList(T).Node; pub fn init() Self { diff --git a/std/atomic/stack.zig b/std/atomic/stack.zig index 16d5c9503b..71896c66df 100644 --- a/std/atomic/stack.zig +++ b/std/atomic/stack.zig @@ -9,7 +9,7 @@ pub fn Stack(comptime T: type) type { root: ?*Node, lock: u8, - pub const Self = this; + pub const Self = @This(); pub const Node = struct { next: ?*Node, diff --git a/std/build.zig b/std/build.zig index 5800e69c62..f9fed6ad2f 100644 --- a/std/build.zig +++ b/std/build.zig @@ -1890,7 +1890,7 @@ const InstallArtifactStep = struct { artifact: *LibExeObjStep, dest_file: []const u8, - const Self = this; + const Self = @This(); pub fn create(builder: *Builder, artifact: *LibExeObjStep) *Self { const dest_dir = switch (artifact.kind) { diff --git a/std/crypto/blake2.zig b/std/crypto/blake2.zig index 467ddde5db..dc68d806d2 100644 --- a/std/crypto/blake2.zig +++ b/std/crypto/blake2.zig @@ -33,7 +33,7 @@ pub const Blake2s256 = Blake2s(256); fn Blake2s(comptime out_len: usize) type { return struct { - const Self = this; + const Self = @This(); const block_length = 64; const digest_length = out_len / 8; @@ -266,7 +266,7 @@ pub const Blake2b512 = Blake2b(512); fn Blake2b(comptime out_len: usize) type { return struct { - const Self = this; + const Self = @This(); const block_length = 128; const digest_length = out_len / 8; diff --git a/std/crypto/hmac.zig b/std/crypto/hmac.zig index 23eeff2a00..996c96062c 100644 --- a/std/crypto/hmac.zig +++ b/std/crypto/hmac.zig @@ -9,7 +9,7 @@ pub const HmacSha256 = Hmac(crypto.Sha256); pub fn Hmac(comptime Hash: type) type { return struct { - const Self = this; + const Self = @This(); pub const mac_length = Hash.digest_length; pub const minimum_key_length = 0; diff --git a/std/crypto/md5.zig b/std/crypto/md5.zig index 20334ec7d8..8663fa751f 100644 --- a/std/crypto/md5.zig +++ b/std/crypto/md5.zig @@ -28,7 +28,7 @@ fn Rp(a: usize, b: usize, c: usize, d: usize, k: usize, s: u32, t: u32) RoundPar } pub const Md5 = struct { - const Self = this; + const Self = @This(); const block_length = 64; const digest_length = 16; diff --git a/std/crypto/poly1305.zig b/std/crypto/poly1305.zig index f5e11fc0a1..a5d9fcdf57 100644 --- a/std/crypto/poly1305.zig +++ b/std/crypto/poly1305.zig @@ -10,7 +10,7 @@ const readInt = std.mem.readInt; const writeInt = std.mem.writeInt; pub const Poly1305 = struct { - const Self = this; + const Self = @This(); pub const mac_length = 16; pub const minimum_key_length = 32; diff --git a/std/crypto/sha1.zig b/std/crypto/sha1.zig index 6d6b4dbd3f..1cb0b17434 100644 --- a/std/crypto/sha1.zig +++ b/std/crypto/sha1.zig @@ -25,7 +25,7 @@ fn Rp(a: usize, b: usize, c: usize, d: usize, e: usize, i: u32) RoundParam { } pub const Sha1 = struct { - const Self = this; + const Self = @This(); const block_length = 64; const digest_length = 20; diff --git a/std/crypto/sha2.zig b/std/crypto/sha2.zig index 8a25fecc43..7e9749364b 100644 --- a/std/crypto/sha2.zig +++ b/std/crypto/sha2.zig @@ -77,7 +77,7 @@ pub const Sha256 = Sha2_32(Sha256Params); fn Sha2_32(comptime params: Sha2Params32) type { return struct { - const Self = this; + const Self = @This(); const block_length = 64; const digest_length = params.out_len / 8; @@ -418,7 +418,7 @@ pub const Sha512 = Sha2_64(Sha512Params); fn Sha2_64(comptime params: Sha2Params64) type { return struct { - const Self = this; + const Self = @This(); const block_length = 128; const digest_length = params.out_len / 8; diff --git a/std/crypto/sha3.zig b/std/crypto/sha3.zig index 827bbd0680..881370e686 100644 --- a/std/crypto/sha3.zig +++ b/std/crypto/sha3.zig @@ -12,7 +12,7 @@ pub const Sha3_512 = Keccak(512, 0x06); fn Keccak(comptime bits: usize, comptime delim: u8) type { return struct { - const Self = this; + const Self = @This(); const block_length = 200; const digest_length = bits / 8; diff --git a/std/event/channel.zig b/std/event/channel.zig index 9ea75a2dd8..133ce1c69c 100644 --- a/std/event/channel.zig +++ b/std/event/channel.zig @@ -25,7 +25,7 @@ pub fn Channel(comptime T: type) type { buffer_index: usize, buffer_len: usize, - const SelfChannel = this; + const SelfChannel = @This(); const GetNode = struct { tick_node: *Loop.NextTickNode, data: Data, diff --git a/std/event/fs.zig b/std/event/fs.zig index 5635471212..bde5a306b6 100644 --- a/std/event/fs.zig +++ b/std/event/fs.zig @@ -724,7 +724,7 @@ pub fn Watch(comptime V: type) type { const FileToHandle = std.AutoHashMap([]const u8, promise); - const Self = this; + const Self = @This(); pub const Event = struct { id: Id, diff --git a/std/event/future.zig b/std/event/future.zig index 8abdce7d02..d61768b198 100644 --- a/std/event/future.zig +++ b/std/event/future.zig @@ -21,7 +21,7 @@ pub fn Future(comptime T: type) type { /// 2 - finished available: u8, - const Self = this; + const Self = @This(); const Queue = std.atomic.Queue(promise); pub fn init(loop: *Loop) Self { diff --git a/std/event/group.zig b/std/event/group.zig index 2b5a517b2f..0bb3298cf8 100644 --- a/std/event/group.zig +++ b/std/event/group.zig @@ -13,7 +13,7 @@ pub fn Group(comptime ReturnType: type) type { alloc_stack: Stack, lock: Lock, - const Self = this; + const Self = @This(); const Error = switch (@typeInfo(ReturnType)) { builtin.TypeId.ErrorUnion => |payload| payload.error_set, diff --git a/std/event/locked.zig b/std/event/locked.zig index 7df56c4571..6718b1bf9c 100644 --- a/std/event/locked.zig +++ b/std/event/locked.zig @@ -10,7 +10,7 @@ pub fn Locked(comptime T: type) type { lock: Lock, private_data: T, - const Self = this; + const Self = @This(); pub const HeldLock = struct { value: *T, diff --git a/std/event/rwlocked.zig b/std/event/rwlocked.zig index 1a6e77c27a..d305b1791e 100644 --- a/std/event/rwlocked.zig +++ b/std/event/rwlocked.zig @@ -10,7 +10,7 @@ pub fn RwLocked(comptime T: type) type { lock: RwLock, locked_data: T, - const Self = this; + const Self = @This(); pub const HeldReadLock = struct { value: *const T, diff --git a/std/event/tcp.zig b/std/event/tcp.zig index 69b143dda0..5715e46a62 100644 --- a/std/event/tcp.zig +++ b/std/event/tcp.zig @@ -132,7 +132,7 @@ test "listen on a port, send bytes, receive bytes" { const MyServer = struct { tcp_server: Server, - const Self = this; + const Self = @This(); async<*mem.Allocator> fn handler(tcp_server: *Server, _addr: *const std.net.Address, _socket: *const std.os.File) void { const self = @fieldParentPtr(Self, "tcp_server", tcp_server); var socket = _socket.*; // TODO https://github.com/ziglang/zig/issues/733 diff --git a/std/fmt/index.zig b/std/fmt/index.zig index 80af750f3d..14c944e9d5 100644 --- a/std/fmt/index.zig +++ b/std/fmt/index.zig @@ -1183,7 +1183,7 @@ test "fmt.format" { //custom type format { const Vec2 = struct { - const SelfType = this; + const SelfType = @This(); x: f32, y: f32, diff --git a/std/hash/crc.zig b/std/hash/crc.zig index c455140785..c4bd92884a 100644 --- a/std/hash/crc.zig +++ b/std/hash/crc.zig @@ -20,7 +20,7 @@ pub const Crc32 = Crc32WithPoly(Polynomial.IEEE); // slicing-by-8 crc32 implementation. pub fn Crc32WithPoly(comptime poly: u32) type { return struct { - const Self = this; + const Self = @This(); const lookup_tables = comptime block: { @setEvalBranchQuota(20000); var tables: [8][256]u32 = undefined; @@ -117,7 +117,7 @@ test "crc32 castagnoli" { // half-byte lookup table implementation. pub fn Crc32SmallWithPoly(comptime poly: u32) type { return struct { - const Self = this; + const Self = @This(); const lookup_table = comptime block: { var table: [16]u32 = undefined; diff --git a/std/hash/fnv.zig b/std/hash/fnv.zig index 447c996772..9bb18f14b3 100644 --- a/std/hash/fnv.zig +++ b/std/hash/fnv.zig @@ -13,7 +13,7 @@ pub const Fnv1a_128 = Fnv1a(u128, 0x1000000000000000000013b, 0x6c62272e07bb01426 fn Fnv1a(comptime T: type, comptime prime: T, comptime offset: T) type { return struct { - const Self = this; + const Self = @This(); value: T, diff --git a/std/hash/siphash.zig b/std/hash/siphash.zig index cdad77e59e..0fe958c38b 100644 --- a/std/hash/siphash.zig +++ b/std/hash/siphash.zig @@ -25,7 +25,7 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize) debug.assert(c_rounds > 0 and d_rounds > 0); return struct { - const Self = this; + const Self = @This(); const digest_size = 64; const block_size = 64; diff --git a/std/hash_map.zig b/std/hash_map.zig index 9654d612a5..1b299eff78 100644 --- a/std/hash_map.zig +++ b/std/hash_map.zig @@ -22,7 +22,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3 // this is used to detect bugs where a hashtable is edited while an iterator is running. modification_count: debug_u32, - const Self = this; + const Self = @This(); pub const KV = struct { key: K, @@ -472,7 +472,6 @@ pub fn autoHash(key: var, comptime rng: *std.rand.Random, comptime HashInt: type builtin.TypeId.Promise, builtin.TypeId.Fn => return autoHash(@ptrToInt(key), rng), builtin.TypeId.Namespace, - builtin.TypeId.Block, builtin.TypeId.BoundFn, builtin.TypeId.ComptimeFloat, builtin.TypeId.ComptimeInt, @@ -517,7 +516,6 @@ pub fn autoEql(a: var, b: @typeOf(a)) bool { builtin.TypeId.ComptimeFloat, builtin.TypeId.ComptimeInt, builtin.TypeId.Namespace, - builtin.TypeId.Block, builtin.TypeId.Promise, builtin.TypeId.Enum, builtin.TypeId.BoundFn, diff --git a/std/heap.zig b/std/heap.zig index f5e0484b25..58a9961d79 100644 --- a/std/heap.zig +++ b/std/heap.zig @@ -385,7 +385,7 @@ pub fn stackFallback(comptime size: usize, fallback_allocator: *Allocator) Stack pub fn StackFallbackAllocator(comptime size: usize) type { return struct { - const Self = this; + const Self = @This(); buffer: [size]u8, allocator: Allocator, diff --git a/std/io.zig b/std/io.zig index 2b31bc0548..c10fdcbbe2 100644 --- a/std/io.zig +++ b/std/io.zig @@ -76,7 +76,7 @@ pub const FileOutStream = struct { pub fn InStream(comptime ReadError: type) type { return struct { - const Self = this; + const Self = @This(); pub const Error = ReadError; /// Return the number of bytes read. If the number read is smaller than buf.len, it @@ -218,7 +218,7 @@ pub fn InStream(comptime ReadError: type) type { pub fn OutStream(comptime WriteError: type) type { return struct { - const Self = this; + const Self = @This(); pub const Error = WriteError; writeFn: fn (self: *Self, bytes: []const u8) Error!void, @@ -291,7 +291,7 @@ pub fn BufferedInStream(comptime Error: type) type { pub fn BufferedInStreamCustom(comptime buffer_size: usize, comptime Error: type) type { return struct { - const Self = this; + const Self = @This(); const Stream = InStream(Error); pub stream: Stream, @@ -361,7 +361,7 @@ pub fn BufferedInStreamCustom(comptime buffer_size: usize, comptime Error: type) /// This makes look-ahead style parsing much easier. pub fn PeekStream(comptime buffer_size: usize, comptime InStreamError: type) type { return struct { - const Self = this; + const Self = @This(); pub const Error = InStreamError; pub const Stream = InStream(Error); @@ -424,7 +424,7 @@ pub fn PeekStream(comptime buffer_size: usize, comptime InStreamError: type) typ } pub const SliceInStream = struct { - const Self = this; + const Self = @This(); pub const Error = error{}; pub const Stream = InStream(Error); @@ -505,7 +505,7 @@ pub fn BufferedOutStream(comptime Error: type) type { pub fn BufferedOutStreamCustom(comptime buffer_size: usize, comptime OutStreamError: type) type { return struct { - const Self = this; + const Self = @This(); pub const Stream = OutStream(Error); pub const Error = OutStreamError; diff --git a/std/lazy_init.zig b/std/lazy_init.zig index c46c067810..f08c01e874 100644 --- a/std/lazy_init.zig +++ b/std/lazy_init.zig @@ -18,7 +18,7 @@ fn LazyInit(comptime T: type) type { state: u8, // TODO make this an enum data: Data, - const Self = this; + const Self = @This(); // TODO this isn't working for void, investigate and then remove this special case const Data = if (@sizeOf(T) == 0) u8 else T; diff --git a/std/linked_list.zig b/std/linked_list.zig index 130ddbce5d..46cbeb03c4 100644 --- a/std/linked_list.zig +++ b/std/linked_list.zig @@ -7,7 +7,7 @@ const Allocator = mem.Allocator; /// Generic doubly linked list. pub fn LinkedList(comptime T: type) type { return struct { - const Self = this; + const Self = @This(); /// Node inside the linked list wrapping the actual data. pub const Node = struct { diff --git a/std/math/complex/index.zig b/std/math/complex/index.zig index 63a2616984..171c4c5829 100644 --- a/std/math/complex/index.zig +++ b/std/math/complex/index.zig @@ -25,7 +25,7 @@ pub const tan = @import("tan.zig").tan; pub fn Complex(comptime T: type) type { return struct { - const Self = this; + const Self = @This(); re: T, im: T, diff --git a/std/mem.zig b/std/mem.zig index 4390f8ad5b..dd5adc06c2 100644 --- a/std/mem.zig +++ b/std/mem.zig @@ -3,7 +3,7 @@ const debug = std.debug; const assert = debug.assert; const math = std.math; const builtin = @import("builtin"); -const mem = this; +const mem = @This(); pub const Allocator = struct { pub const Error = error{OutOfMemory}; diff --git a/std/net.zig b/std/net.zig index 8c1aeb92d7..c20435893a 100644 --- a/std/net.zig +++ b/std/net.zig @@ -1,7 +1,7 @@ const std = @import("index.zig"); const builtin = @import("builtin"); const assert = std.debug.assert; -const net = this; +const net = @This(); const posix = std.os.posix; const mem = std.mem; diff --git a/std/os/index.zig b/std/os/index.zig index 8e92fc23c5..d4110bd759 100644 --- a/std/os/index.zig +++ b/std/os/index.zig @@ -6,7 +6,7 @@ const is_posix = switch (builtin.os) { builtin.Os.linux, builtin.Os.macosx => true, else => false, }; -const os = this; +const os = @This(); test "std.os" { _ = @import("child_process.zig"); diff --git a/std/segmented_list.zig b/std/segmented_list.zig index c6d8effdd2..93942dde9b 100644 --- a/std/segmented_list.zig +++ b/std/segmented_list.zig @@ -75,7 +75,7 @@ const Allocator = std.mem.Allocator; /// size is small. `prealloc_item_count` must be 0, or a power of 2. pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type { return struct { - const Self = this; + const Self = @This(); const prealloc_exp = blk: { // we don't use the prealloc_exp constant when prealloc_item_count is 0. assert(prealloc_item_count != 0); diff --git a/std/zig/ast.zig b/std/zig/ast.zig index 0046dff1a2..9ca77d4950 100644 --- a/std/zig/ast.zig +++ b/std/zig/ast.zig @@ -231,7 +231,7 @@ pub const Error = union(enum) { fn SingleTokenError(comptime msg: []const u8) type { return struct { - const ThisError = this; + const ThisError = @This(); token: TokenIndex, @@ -244,7 +244,7 @@ pub const Error = union(enum) { fn SimpleError(comptime msg: []const u8) type { return struct { - const ThisError = this; + const ThisError = @This(); token: TokenIndex, diff --git a/std/zig/parser_test.zig b/std/zig/parser_test.zig index 7f3ce7bd8a..3cee9b98dd 100644 --- a/std/zig/parser_test.zig +++ b/std/zig/parser_test.zig @@ -1354,7 +1354,7 @@ test "zig fmt: indexing" { test "zig fmt: struct declaration" { try testCanonical( \\const S = struct { - \\ const Self = this; + \\ const Self = @This(); \\ f1: u8, \\ pub f3: u8, \\ diff --git a/std/zig/render.zig b/std/zig/render.zig index 868902a0d1..050f172ae8 100644 --- a/std/zig/render.zig +++ b/std/zig/render.zig @@ -20,7 +20,7 @@ pub fn render(allocator: *mem.Allocator, stream: var, tree: *ast.Tree) (@typeOf( // make a passthrough stream that checks whether something changed const MyStream = struct { - const MyStream = this; + const MyStream = @This(); const StreamError = @typeOf(stream).Child.Error; const Stream = std.io.OutStream(StreamError); diff --git a/test/cases/cast.zig b/test/cases/cast.zig index 94fbda7899..e2b67f036d 100644 --- a/test/cases/cast.zig +++ b/test/cases/cast.zig @@ -64,7 +64,7 @@ test "implicitly cast a container to a const pointer of it" { fn Struct(comptime T: type) type { return struct { - const Self = this; + const Self = @This(); x: T, fn pointer(self: *const Self) Self { @@ -106,7 +106,7 @@ const Enum = enum { test "implicitly cast indirect pointer to maybe-indirect pointer" { const S = struct { - const Self = this; + const Self = @This(); x: u8, fn constConst(p: *const *const Self) u8 { return p.*.x; diff --git a/test/cases/eval.zig b/test/cases/eval.zig index 4286821183..7e9c9a739d 100644 --- a/test/cases/eval.zig +++ b/test/cases/eval.zig @@ -628,7 +628,7 @@ test "call method with comptime pass-by-non-copying-value self parameter" { const S = struct { a: u8, - fn b(comptime s: this) u8 { + fn b(comptime s: @This()) u8 { return s.a; } }; diff --git a/test/cases/misc.zig b/test/cases/misc.zig index 1c0189571b..4343cb3b90 100644 --- a/test/cases/misc.zig +++ b/test/cases/misc.zig @@ -510,9 +510,6 @@ test "@typeId" { assert(@typeId(AUnion) == Tid.Union); assert(@typeId(fn () void) == Tid.Fn); assert(@typeId(@typeOf(builtin)) == Tid.Namespace); - assert(@typeId(@typeOf(x: { - break :x this; - })) == Tid.Block); // TODO bound fn // TODO arg tuple // TODO opaque diff --git a/test/cases/reflection.zig b/test/cases/reflection.zig index 3d3af3c889..677fd90192 100644 --- a/test/cases/reflection.zig +++ b/test/cases/reflection.zig @@ -1,6 +1,6 @@ const assert = @import("std").debug.assert; const mem = @import("std").mem; -const reflection = this; +const reflection = @This(); test "reflection: array, pointer, optional, error union type child" { comptime { diff --git a/test/cases/struct.zig b/test/cases/struct.zig index 20d46999d5..163c69e670 100644 --- a/test/cases/struct.zig +++ b/test/cases/struct.zig @@ -423,10 +423,10 @@ fn alloc(comptime T: type) []T { test "call method with mutable reference to struct with no fields" { const S = struct { - fn doC(s: *const this) bool { + fn doC(s: *const @This()) bool { return true; } - fn do(s: *this) bool { + fn do(s: *@This()) bool { return true; } }; diff --git a/test/cases/this.zig b/test/cases/this.zig index ba51d0ac90..c7be074f36 100644 --- a/test/cases/this.zig +++ b/test/cases/this.zig @@ -1,10 +1,10 @@ const assert = @import("std").debug.assert; -const module = this; +const module = @This(); fn Point(comptime T: type) type { return struct { - const Self = this; + const Self = @This(); x: T, y: T, @@ -19,11 +19,6 @@ fn add(x: i32, y: i32) i32 { return x + y; } -fn factorial(x: i32) i32 { - const selfFn = this; - return if (x == 0) 1 else x * selfFn(x - 1); -} - test "this refer to module call private fn" { assert(module.add(1, 2) == 3); } @@ -37,7 +32,3 @@ test "this refer to container" { assert(pt.x == 13); assert(pt.y == 35); } - -test "this refer to fn" { - assert(factorial(5) == 120); -} diff --git a/test/cases/type_info.zig b/test/cases/type_info.zig index b8fc4cf14e..6f99268c08 100644 --- a/test/cases/type_info.zig +++ b/test/cases/type_info.zig @@ -166,7 +166,7 @@ fn testUnion() void { assert(TypeId(typeinfo_info) == TypeId.Union); assert(typeinfo_info.Union.layout == TypeInfo.ContainerLayout.Auto); assert(typeinfo_info.Union.tag_type.? == TypeId); - assert(typeinfo_info.Union.fields.len == 25); + assert(typeinfo_info.Union.fields.len == 24); assert(typeinfo_info.Union.fields[4].enum_field != null); assert(typeinfo_info.Union.fields[4].enum_field.?.value == 4); assert(typeinfo_info.Union.fields[4].field_type == @typeOf(@typeInfo(u8).Int)); @@ -217,7 +217,7 @@ fn testStruct() void { } const TestStruct = packed struct { - const Self = this; + const Self = @This(); fieldA: usize, fieldB: void, diff --git a/test/compile_errors.zig b/test/compile_errors.zig index 750794c909..6bdbca9ff5 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -3813,11 +3813,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ return struct { \\ b: B(), \\ - \\ const Self = this; + \\ const Self = @This(); \\ \\ fn B() type { \\ return struct { - \\ const Self = this; + \\ const Self = @This(); \\ }; \\ } \\ }; @@ -4314,12 +4314,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ var a = undefined; \\ var b = 1; \\ var c = 1.0; - \\ var d = this; - \\ var e = null; - \\ var f = opaque.*; - \\ var g = i32; - \\ var h = @import("std",); - \\ var i = (Foo {}).bar; + \\ var d = null; + \\ var e = opaque.*; + \\ var f = i32; + \\ var g = @import("std",); + \\ var h = (Foo {}).bar; \\ \\ var z: noreturn = return; \\} @@ -4332,13 +4331,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { ".tmp_source.zig:7:4: error: variable of type '(undefined)' must be const or comptime", ".tmp_source.zig:8:4: error: variable of type 'comptime_int' must be const or comptime", ".tmp_source.zig:9:4: error: variable of type 'comptime_float' must be const or comptime", - ".tmp_source.zig:10:4: error: variable of type '(block)' must be const or comptime", - ".tmp_source.zig:11:4: error: variable of type '(null)' must be const or comptime", - ".tmp_source.zig:12:4: error: variable of type 'Opaque' not allowed", - ".tmp_source.zig:13:4: error: variable of type 'type' must be const or comptime", - ".tmp_source.zig:14:4: error: variable of type '(namespace)' must be const or comptime", - ".tmp_source.zig:15:4: error: variable of type '(bound fn(*const Foo) void)' must be const or comptime", - ".tmp_source.zig:17:4: error: unreachable code", + ".tmp_source.zig:10:4: error: variable of type '(null)' must be const or comptime", + ".tmp_source.zig:11:4: error: variable of type 'Opaque' not allowed", + ".tmp_source.zig:12:4: error: variable of type 'type' must be const or comptime", + ".tmp_source.zig:13:4: error: variable of type '(namespace)' must be const or comptime", + ".tmp_source.zig:14:4: error: variable of type '(bound fn(*const Foo) void)' must be const or comptime", + ".tmp_source.zig:16:4: error: unreachable code", ); cases.add( -- cgit v1.2.3