authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-10-08 18:09:08-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-10-08 18:09:08-04:00
loge0f0e2aace9e819545388c46547188ee6296178b
tree674a78c834c9d440e8f07da8a24bff76f35ecc71
parentf74c29b49a550e5e7029fde46de93068a9eecb46
signaturelock-open Commit is signed but in an unrecognized format.

generated docs: error sets in fn docs


7 files changed, 172 insertions(+), 132 deletions(-)

lib/std/os.zig+41-109
......@@ -183,7 +183,7 @@ pub fn abort() noreturn {
183183 exit(127);
184184}
185185
186pub const RaiseError = error{Unexpected};
186pub const RaiseError = UnexpectedError;
187187
188188pub fn raise(sig: u8) RaiseError!void {
189189 if (builtin.link_libc) {
......@@ -215,10 +215,7 @@ pub fn raise(sig: u8) RaiseError!void {
215215 @compileError("std.os.raise unimplemented for this target");
216216}
217217
218pub const KillError = error{
219 PermissionDenied,
220 Unexpected,
221};
218pub const KillError = error{PermissionDenied} || UnexpectedError;
222219
223220pub fn kill(pid: pid_t, sig: u8) KillError!void {
224221 switch (errno(system.kill(pid, sig))) {
......@@ -266,9 +263,7 @@ pub const ReadError = error{
266263 /// This error occurs when no global event loop is configured,
267264 /// and reading from the file descriptor would block.
268265 WouldBlock,
269
270 Unexpected,
271};
266} || UnexpectedError;
272267
273268/// Returns the number of bytes that were read, which can be less than
274269/// buf.len. If 0 bytes were read, that means EOF.
......@@ -385,8 +380,7 @@ pub const WriteError = error{
385380 BrokenPipe,
386381 SystemResources,
387382 OperationAborted,
388 Unexpected,
389};
383} || UnexpectedError;
390384
391385/// Write to a file descriptor. Keeps trying if it gets interrupted.
392386/// This function is for blocking file descriptors only.
......@@ -548,8 +542,7 @@ pub const OpenError = error{
548542 NotDir,
549543 PathAlreadyExists,
550544 DeviceBusy,
551 Unexpected,
552};
545} || UnexpectedError;
553546
554547/// Open and possibly create a file. Keeps trying if it gets interrupted.
555548/// See also `openC`.
......@@ -748,9 +741,7 @@ pub const ExecveError = error{
748741 ProcessFdQuotaExceeded,
749742 SystemFdQuotaExceeded,
750743 NameTooLong,
751
752 Unexpected,
753};
744} || UnexpectedError;
754745
755746fn execveErrnoToErr(err: usize) ExecveError {
756747 assert(err > 0);
......@@ -808,8 +799,7 @@ pub fn getenvC(key: [*]const u8) ?[]const u8 {
808799pub const GetCwdError = error{
809800 NameTooLong,
810801 CurrentWorkingDirectoryUnlinked,
811 Unexpected,
812};
802} || UnexpectedError;
813803
814804/// The result is a slice of out_buffer, indexed from 0.
815805pub fn getcwd(out_buffer: []u8) GetCwdError![]u8 {
......@@ -846,8 +836,7 @@ pub const SymLinkError = error{
846836 NameTooLong,
847837 InvalidUtf8,
848838 BadPathName,
849 Unexpected,
850};
839} || UnexpectedError;
851840
852841/// Creates a symbolic link named `sym_link_path` which contains the string `target_path`.
853842/// A symbolic link (also known as a soft link) may point to an existing file or to a nonexistent
......@@ -932,7 +921,6 @@ pub const UnlinkError = error{
932921 NotDir,
933922 SystemResources,
934923 ReadOnlyFileSystem,
935 Unexpected,
936924
937925 /// On Windows, file paths must be valid Unicode.
938926 InvalidUtf8,
......@@ -940,7 +928,7 @@ pub const UnlinkError = error{
940928 /// On Windows, file paths cannot contain these characters:
941929 /// '/', '*', '?', '"', '<', '>', '|'
942930 BadPathName,
943};
931} || UnexpectedError;
944932
945933/// Delete a name and possibly the file it refers to.
946934/// See also `unlinkC`.
......@@ -996,8 +984,7 @@ const RenameError = error{
996984 RenameAcrossMountPoints,
997985 InvalidUtf8,
998986 BadPathName,
999 Unexpected,
1000};
987} || UnexpectedError;
1001988
1002989/// Change the name or location of a file.
1003990pub fn rename(old_path: []const u8, new_path: []const u8) RenameError!void {
......@@ -1064,8 +1051,7 @@ pub const MakeDirError = error{
10641051 ReadOnlyFileSystem,
10651052 InvalidUtf8,
10661053 BadPathName,
1067 Unexpected,
1068};
1054} || UnexpectedError;
10691055
10701056/// Create a directory.
10711057/// `mode` is ignored on Windows.
......@@ -1116,8 +1102,7 @@ pub const DeleteDirError = error{
11161102 ReadOnlyFileSystem,
11171103 InvalidUtf8,
11181104 BadPathName,
1119 Unexpected,
1120};
1105} || UnexpectedError;
11211106
11221107/// Deletes an empty directory.
11231108pub fn rmdir(dir_path: []const u8) DeleteDirError!void {
......@@ -1163,8 +1148,7 @@ pub const ChangeCurDirError = error{
11631148 FileNotFound,
11641149 SystemResources,
11651150 NotDir,
1166 Unexpected,
1167};
1151} || UnexpectedError;
11681152
11691153/// Changes the current working directory of the calling process.
11701154/// `dir_path` is recommended to be a UTF-8 encoded string.
......@@ -1206,8 +1190,7 @@ pub const ReadLinkError = error{
12061190 FileNotFound,
12071191 SystemResources,
12081192 NotDir,
1209 Unexpected,
1210};
1193} || UnexpectedError;
12111194
12121195/// Read value of a symbolic link.
12131196/// The return value is a slice of `out_buffer` from index 0.
......@@ -1247,8 +1230,7 @@ pub const SetIdError = error{
12471230 ResourceLimitReached,
12481231 InvalidUserId,
12491232 PermissionDenied,
1250 Unexpected,
1251};
1233} || UnexpectedError;
12521234
12531235pub fn setuid(uid: u32) SetIdError!void {
12541236 switch (errno(system.setuid(uid))) {
......@@ -1357,9 +1339,7 @@ pub const SocketError = error{
13571339
13581340 /// The protocol type or the specified protocol is not supported within this domain.
13591341 ProtocolNotSupported,
1360
1361 Unexpected,
1362};
1342} || UnexpectedError;
13631343
13641344pub fn socket(domain: u32, socket_type: u32, protocol: u32) SocketError!i32 {
13651345 const rc = system.socket(domain, socket_type, protocol);
......@@ -1409,9 +1389,7 @@ pub const BindError = error{
14091389
14101390 /// The socket inode would reside on a read-only filesystem.
14111391 ReadOnlyFileSystem,
1412
1413 Unexpected,
1414};
1392} || UnexpectedError;
14151393
14161394/// addr is `*const T` where T is one of the sockaddr
14171395pub fn bind(fd: i32, addr: *const sockaddr) BindError!void {
......@@ -1448,9 +1426,7 @@ const ListenError = error{
14481426
14491427 /// The socket is not of a type that supports the listen() operation.
14501428 OperationNotSupported,
1451
1452 Unexpected,
1453};
1429} || UnexpectedError;
14541430
14551431pub fn listen(sockfd: i32, backlog: u32) ListenError!void {
14561432 const rc = system.listen(sockfd, backlog);
......@@ -1487,9 +1463,7 @@ pub const AcceptError = error{
14871463
14881464 /// Firewall rules forbid connection.
14891465 BlockedByFirewall,
1490
1491 Unexpected,
1492};
1466} || UnexpectedError;
14931467
14941468/// Accept a connection on a socket. `fd` must be opened in blocking mode.
14951469/// See also `accept4_async`.
......@@ -1559,9 +1533,7 @@ pub const EpollCreateError = error{
15591533
15601534 /// There was insufficient memory to create the kernel object.
15611535 SystemResources,
1562
1563 Unexpected,
1564};
1536} || UnexpectedError;
15651537
15661538pub fn epoll_create1(flags: u32) EpollCreateError!i32 {
15671539 const rc = system.epoll_create1(flags);
......@@ -1600,9 +1572,7 @@ pub const EpollCtlError = error{
16001572 /// The target file fd does not support epoll. This error can occur if fd refers to,
16011573 /// for example, a regular file or a directory.
16021574 FileDescriptorIncompatibleWithEpoll,
1603
1604 Unexpected,
1605};
1575} || UnexpectedError;
16061576
16071577pub fn epoll_ctl(epfd: i32, op: u32, fd: i32, event: ?*epoll_event) EpollCtlError!void {
16081578 const rc = system.epoll_ctl(epfd, op, fd, event);
......@@ -1643,8 +1613,7 @@ pub const EventFdError = error{
16431613 SystemResources,
16441614 ProcessFdQuotaExceeded,
16451615 SystemFdQuotaExceeded,
1646 Unexpected,
1647};
1616} || UnexpectedError;
16481617
16491618pub fn eventfd(initval: u32, flags: u32) EventFdError!i32 {
16501619 const rc = system.eventfd(initval, flags);
......@@ -1663,9 +1632,7 @@ pub fn eventfd(initval: u32, flags: u32) EventFdError!i32 {
16631632pub const GetSockNameError = error{
16641633 /// Insufficient resources were available in the system to perform the operation.
16651634 SystemResources,
1666
1667 Unexpected,
1668};
1635} || UnexpectedError;
16691636
16701637pub fn getsockname(sockfd: i32) GetSockNameError!sockaddr {
16711638 var addr: sockaddr = undefined;
......@@ -1714,9 +1681,7 @@ pub const ConnectError = error{
17141681 /// Timeout while attempting connection. The server may be too busy to accept new connections. Note
17151682 /// that for IP sockets the timeout may be very long when syncookies are enabled on the server.
17161683 ConnectionTimedOut,
1717
1718 Unexpected,
1719};
1684} || UnexpectedError;
17201685
17211686/// Initiate a connection on a socket.
17221687/// This is for blocking file descriptors only.
......@@ -1824,10 +1789,7 @@ pub fn waitpid(pid: i32, flags: u32) u32 {
18241789 }
18251790}
18261791
1827pub const FStatError = error{
1828 SystemResources,
1829 Unexpected,
1830};
1792pub const FStatError = error{SystemResources} || UnexpectedError;
18311793
18321794pub fn fstat(fd: fd_t) FStatError!Stat {
18331795 var stat: Stat = undefined;
......@@ -1856,9 +1818,7 @@ pub const KQueueError = error{
18561818
18571819 /// The system-wide limit on the total number of open files has been reached.
18581820 SystemFdQuotaExceeded,
1859
1860 Unexpected,
1861};
1821} || UnexpectedError;
18621822
18631823pub fn kqueue() KQueueError!i32 {
18641824 const rc = system.kqueue();
......@@ -1922,8 +1882,7 @@ pub const INotifyInitError = error{
19221882 ProcessFdQuotaExceeded,
19231883 SystemFdQuotaExceeded,
19241884 SystemResources,
1925 Unexpected,
1926};
1885} || UnexpectedError;
19271886
19281887/// initialize an inotify instance
19291888pub fn inotify_init1(flags: u32) INotifyInitError!i32 {
......@@ -1944,8 +1903,7 @@ pub const INotifyAddWatchError = error{
19441903 FileNotFound,
19451904 SystemResources,
19461905 UserResourceLimitReached,
1947 Unexpected,
1948};
1906} || UnexpectedError;
19491907
19501908/// add a watch to an initialized inotify instance
19511909pub fn inotify_add_watch(inotify_fd: i32, pathname: []const u8, mask: u32) INotifyAddWatchError!i32 {
......@@ -1992,8 +1950,7 @@ pub const MProtectError = error{
19921950 /// dle of a region currently protected as PROT_READ|PROT_WRITE would result in three map‐
19931951 /// pings: two read/write mappings at each end and a read-only mapping in the middle.)
19941952 OutOfMemory,
1995 Unexpected,
1996};
1953} || UnexpectedError;
19971954
19981955/// `memory.len` must be page-aligned.
19991956pub fn mprotect(memory: []align(mem.page_size) u8, protection: u32) MProtectError!void {
......@@ -2007,10 +1964,7 @@ pub fn mprotect(memory: []align(mem.page_size) u8, protection: u32) MProtectErro
20071964 }
20081965}
20091966
2010pub const ForkError = error{
2011 SystemResources,
2012 Unexpected,
2013};
1967pub const ForkError = error{SystemResources} || UnexpectedError;
20141968
20151969pub fn fork() ForkError!pid_t {
20161970 const rc = system.fork();
......@@ -2037,8 +1991,7 @@ pub const MMapError = error{
20371991 PermissionDenied,
20381992 LockedMemoryLimitExceeded,
20391993 OutOfMemory,
2040 Unexpected,
2041};
1994} || UnexpectedError;
20421995
20431996/// Map files or devices into memory.
20441997/// Use of a mapped region can result in these signals:
......@@ -2101,9 +2054,7 @@ pub const AccessError = error{
21012054
21022055 /// On Windows, file paths must be valid Unicode.
21032056 InvalidUtf8,
2104
2105 Unexpected,
2106};
2057} || UnexpectedError;
21072058
21082059/// check user's permissions for a file
21092060/// TODO currently this assumes `mode` is `F_OK` on Windows.
......@@ -2161,8 +2112,7 @@ pub fn accessW(path: [*]const u16, mode: u32) windows.GetFileAttributesError!voi
21612112pub const PipeError = error{
21622113 SystemFdQuotaExceeded,
21632114 ProcessFdQuotaExceeded,
2164 Unexpected,
2165};
2115} || UnexpectedError;
21662116
21672117/// Creates a unidirectional data channel that can be used for interprocess communication.
21682118pub fn pipe() PipeError![2]fd_t {
......@@ -2193,8 +2143,7 @@ pub const SysCtlError = error{
21932143 PermissionDenied,
21942144 SystemResources,
21952145 NameTooLong,
2196 Unexpected,
2197};
2146} || UnexpectedError;
21982147
21992148pub fn sysctl(
22002149 name: []const c_int,
......@@ -2237,10 +2186,7 @@ pub fn gettimeofday(tv: ?*timeval, tz: ?*timezone) void {
22372186 }
22382187}
22392188
2240pub const SeekError = error{
2241 Unseekable,
2242 Unexpected,
2243};
2189pub const SeekError = error{Unseekable} || UnexpectedError;
22442190
22452191/// Repositions read/write file offset relative to the beginning.
22462192pub fn lseek_SET(fd: fd_t, offset: u64) SeekError!void {
......@@ -2382,9 +2328,7 @@ pub const RealPathError = error{
23822328 InvalidUtf8,
23832329
23842330 PathAlreadyExists,
2385
2386 Unexpected,
2387};
2331} || UnexpectedError;
23882332
23892333/// Return the canonicalized absolute pathname.
23902334/// Expands all symbolic links and resolves references to `.`, `..`, and
......@@ -2548,10 +2492,7 @@ pub fn dl_iterate_phdr(comptime T: type, callback: extern fn (info: *dl_phdr_inf
25482492 return last_r;
25492493}
25502494
2551pub const ClockGetTimeError = error{
2552 UnsupportedClock,
2553 Unexpected,
2554};
2495pub const ClockGetTimeError = error{UnsupportedClock} || UnexpectedError;
25552496
25562497pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void {
25572498 switch (errno(system.clock_gettime(clk_id, tp))) {
......@@ -2571,10 +2512,7 @@ pub fn clock_getres(clk_id: i32, res: *timespec) ClockGetTimeError!void {
25712512 }
25722513}
25732514
2574pub const SchedGetAffinityError = error{
2575 PermissionDenied,
2576 Unexpected,
2577};
2515pub const SchedGetAffinityError = error{PermissionDenied} || UnexpectedError;
25782516
25792517pub fn sched_getaffinity(pid: pid_t) SchedGetAffinityError!cpu_set_t {
25802518 var set: cpu_set_t = undefined;
......@@ -2628,8 +2566,7 @@ pub const SigaltstackError = error{
26282566
26292567 /// Attempted to change the signal stack while it was active.
26302568 PermissionDenied,
2631 Unexpected,
2632};
2569} || UnexpectedError;
26332570
26342571pub fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) SigaltstackError!void {
26352572 if (windows.is_the_target or uefi.is_the_target or wasi.is_the_target)
......@@ -2677,9 +2614,7 @@ pub const FutimensError = error{
26772614 PermissionDenied,
26782615
26792616 ReadOnlyFileSystem,
2680
2681 Unexpected,
2682};
2617} || UnexpectedError;
26832618
26842619pub fn futimens(fd: fd_t, times: *const [2]timespec) FutimensError!void {
26852620 switch (errno(system.futimens(fd, times))) {
......@@ -2694,10 +2629,7 @@ pub fn futimens(fd: fd_t, times: *const [2]timespec) FutimensError!void {
26942629 }
26952630}
26962631
2697pub const GetHostNameError = error{
2698 PermissionDenied,
2699 Unexpected,
2700};
2632pub const GetHostNameError = error{PermissionDenied} || UnexpectedError;
27012633
27022634pub fn gethostname(name_buffer: *[HOST_NAME_MAX]u8) GetHostNameError![]u8 {
27032635 if (builtin.link_libc) {
lib/std/special/docs/index.html+15-2
......@@ -87,7 +87,7 @@
8787 #listPkgs li a {
8888 display: block;
8989 color: #000;
90 padding: 8px 16px;
90 padding: 0.5em 1em;
9191 text-decoration: none;
9292 }
9393 #listPkgs li a:hover {
......@@ -145,6 +145,13 @@
145145 #listSearchResults li.selected {
146146 background-color: #93e196;
147147 }
148
149 #tableFnErrors tr td:first-child{
150 text-align: right;
151 font-weight: bold;
152 vertical-align: top;
153 }
154
148155 .tok-kw {
149156 color: #333;
150157 font-weight: bold;
......@@ -262,7 +269,13 @@
262269 </div>
263270 <h1 id="hdrName" class="hidden"></h1>
264271 <div id="fnDocs" class="hidden"></div>
265 <div id="fnErrors" class="hidden"></div>
272 <div id="sectFnErrors" class="hidden">
273 <h2>Errors</h2>
274 <div id="fnErrorsAnyError">
275 <p><span class="tok-type">anyerror</span> means the error set is known only at runtime.</p>
276 </div>
277 <table id="tableFnErrors"><tbody id="listFnErrors"></tbody></table>
278 </div>
266279 <div id="fnExamples" class="hidden"></div>
267280 <div id="fnNoExamples" class="hidden">
268281 <p>This function is not tested or referenced.</p>
lib/std/special/docs/main.js+70-4
......@@ -13,7 +13,10 @@
1313 var domFnProto = document.getElementById("fnProto");
1414 var domFnProtoCode = document.getElementById("fnProtoCode");
1515 var domFnDocs = document.getElementById("fnDocs");
16 var domFnErrors = document.getElementById("fnErrors");
16 var domSectFnErrors = document.getElementById("sectFnErrors");
17 var domListFnErrors = document.getElementById("listFnErrors");
18 var domTableFnErrors = document.getElementById("tableFnErrors");
19 var domFnErrorsAnyError = document.getElementById("fnErrorsAnyError");
1720 var domFnExamples = document.getElementById("fnExamples");
1821 var domFnNoExamples = document.getElementById("fnNoExamples");
1922 var domSearch = document.getElementById("search");
......@@ -36,6 +39,7 @@
3639 var typeKindFloatId;
3740 var typeKindIntId;
3841 var typeKindBoolId;
42 var typeKindVoidId;
3943 var typeKindErrSetId;
4044 var typeKindErrUnionId;
4145 findTypeKinds();
......@@ -102,9 +106,11 @@
102106 domSectInfo.classList.add("hidden");
103107 domHdrName.classList.add("hidden");
104108 domSectNav.classList.add("hidden");
105 domFnErrors.classList.add("hidden");
109 domSectFnErrors.classList.add("hidden");
106110 domFnExamples.classList.add("hidden");
107111 domFnNoExamples.classList.add("hidden");
112 domFnErrorsAnyError.classList.add("hidden");
113 domTableFnErrors.classList.add("hidden");
108114
109115 renderTitle();
110116 renderInfo();
......@@ -202,6 +208,51 @@
202208 docsSource = srcNode.docs;
203209 }
204210
211 var errSetTypeIndex = null;
212 if (typeObj.ret != null) {
213 var retType = zigAnalysis.types[typeObj.ret];
214 if (retType.kind === typeKindErrSetId) {
215 errSetTypeIndex = typeObj.ret;
216 } else if (retType.kind === typeKindErrUnionId) {
217 errSetTypeIndex = retType.err;
218 }
219 }
220 if (errSetTypeIndex != null) {
221 var errSetType = zigAnalysis.types[errSetTypeIndex];
222 if (errSetType.errors == null) {
223 domFnErrorsAnyError.classList.remove("hidden");
224 } else {
225 var errorList = [];
226 for (var i = 0; i < errSetType.errors.length; i += 1) {
227 var errObj = zigAnalysis.errors[errSetType.errors[i]];
228 var srcObj = zigAnalysis.astNodes[errObj.src];
229 errorList.push({
230 err: errObj,
231 docs: srcObj.docs,
232 });
233 }
234 errorList.sort(function(a, b) {
235 return operatorCompare(a.err.name.toLowerCase(), b.err.name.toLowerCase());
236 });
237
238 resizeDomList(domListFnErrors, errorList.length, '<tr><td></td><td></td></tr>');
239 for (var i = 0; i < errorList.length; i += 1) {
240 var trDom = domListFnErrors.children[i];
241 var nameTdDom = trDom.children[0];
242 var descTdDom = trDom.children[1];
243 nameTdDom.textContent = errorList[i].err.name;
244 var docs = errorList[i].docs;
245 if (docs != null) {
246 descTdDom.innerHTML = markdown(docs);
247 } else {
248 descTdDom.textContent = "";
249 }
250 }
251 domTableFnErrors.classList.remove("hidden");
252 }
253 domSectFnErrors.classList.remove("hidden");
254 }
255
205256 var protoSrcIndex;
206257 if (typeIsGenericFn(fnDecl.type)) {
207258 protoSrcIndex = fnDecl.value;
......@@ -285,9 +336,11 @@
285336 var list = [];
286337 for (var key in rootPkg.table) {
287338 if (key === "root" && rootIsStd) continue;
339 var pkgIndex = rootPkg.table[key];
340 if (zigAnalysis.packages[pkgIndex] == null) continue;
288341 list.push({
289342 name: key,
290 pkg: rootPkg.table[key],
343 pkg: pkgIndex,
291344 });
292345 }
293346 list.sort(function(a, b) {
......@@ -447,6 +500,12 @@
447500 } else {
448501 return "bool";
449502 }
503 case typeKindVoidId:
504 if (wantHtml) {
505 return '<span class="tok-type">void</span>';
506 } else {
507 return "void";
508 }
450509 case typeKindErrSetId:
451510 if (typeObj.errors == null) {
452511 if (wantHtml) {
......@@ -580,6 +639,7 @@
580639 return false;
581640 }
582641 var stdPkg = zigAnalysis.packages[rootPkg.table["std"]];
642 if (stdPkg == null) return false;
583643 return rootPkg.file === stdPkg.file;
584644 }
585645
......@@ -597,6 +657,8 @@
597657 typeKindIntId = i;
598658 } else if (zigAnalysis.typeKinds[i] === "Bool") {
599659 typeKindBoolId = i;
660 } else if (zigAnalysis.typeKinds[i] === "Void") {
661 typeKindVoidId = i;
600662 } else if (zigAnalysis.typeKinds[i] === "ErrorSet") {
601663 typeKindErrSetId = i;
602664 } else if (zigAnalysis.typeKinds[i] === "ErrorUnion") {
......@@ -621,6 +683,9 @@
621683 if (typeKindBoolId == null) {
622684 throw new Error("No type kind 'Bool' found");
623685 }
686 if (typeKindVoidId == null) {
687 throw new Error("No type kind 'Void' found");
688 }
624689 if (typeKindErrSetId == null) {
625690 throw new Error("No type kind 'ErrorSet' found");
626691 }
......@@ -702,10 +767,11 @@
702767 for (var key in item.pkg.table) {
703768 var childPkgIndex = item.pkg.table[key];
704769 if (list[childPkgIndex] != null) continue;
770 var childPkg = zigAnalysis.packages[childPkgIndex];
771 if (childPkg == null) continue;
705772
706773 var newPath = item.path.concat([key])
707774 list[childPkgIndex] = newPath;
708 var childPkg = zigAnalysis.packages[childPkgIndex];
709775 stack.push({
710776 path: newPath,
711777 pkg: childPkg,
src/all_types.hpp+1
......@@ -2146,6 +2146,7 @@ struct ErrorTableEntry {
21462146 Buf name;
21472147 uint32_t value;
21482148 AstNode *decl_node;
2149 ErrorTableEntry *other; // null, or another error decl that was merged into this
21492150 ZigType *set_with_only_this_in_it;
21502151 // If we generate a constant error name value for this error, we memoize it here.
21512152 // The type of this is array
src/dump_analysis.cpp+3
......@@ -892,6 +892,9 @@ static void anal_dump_type(AnalDumpCtx *ctx, ZigType *ty) {
892892 if (type_is_global_error_set(ty)) {
893893 break;
894894 }
895 jw_object_field(jw, "name");
896 jw_string(jw, buf_ptr(&ty->name));
897
895898 if (ty->data.error_set.infer_fn != nullptr) {
896899 jw_object_field(jw, "fn");
897900 anal_dump_fn_ref(ctx, ty->data.error_set.infer_fn);
src/ir.cpp+37-16
......@@ -7892,11 +7892,14 @@ static ZigType *get_error_set_union(CodeGen *g, ErrorTableEntry **errors, ZigTyp
78927892 }
78937893
78947894 uint32_t index = set1->data.error_set.err_count;
7895 bool need_comma = false;
78957896 for (uint32_t i = 0; i < set2->data.error_set.err_count; i += 1) {
78967897 ErrorTableEntry *error_entry = set2->data.error_set.errors[i];
78977898 if (errors[error_entry->value] == nullptr) {
78987899 errors[error_entry->value] = error_entry;
7899 buf_appendf(&err_set_type->name, "%s,", buf_ptr(&error_entry->name));
7900 const char *comma = need_comma ? "," : "";
7901 need_comma = true;
7902 buf_appendf(&err_set_type->name, "%s%s", comma, buf_ptr(&error_entry->name));
79007903 err_set_type->data.error_set.errors[index] = error_entry;
79017904 index += 1;
79027905 }
......@@ -7927,6 +7930,17 @@ static ZigType *make_err_set_with_one_item(CodeGen *g, Scope *parent_scope, AstN
79277930 return err_set_type;
79287931}
79297932
7933static AstNode *ast_field_to_symbol_node(AstNode *err_set_field_node) {
7934 if (err_set_field_node->type == NodeTypeSymbol) {
7935 return err_set_field_node;
7936 } else if (err_set_field_node->type == NodeTypeErrorSetField) {
7937 assert(err_set_field_node->data.err_set_field.field_name->type == NodeTypeSymbol);
7938 return err_set_field_node->data.err_set_field.field_name;
7939 } else {
7940 return err_set_field_node;
7941 }
7942}
7943
79307944static IrInstruction *ir_gen_err_set_decl(IrBuilder *irb, Scope *parent_scope, AstNode *node) {
79317945 assert(node->type == NodeTypeErrorSetDecl);
79327946
......@@ -7946,18 +7960,10 @@ static IrInstruction *ir_gen_err_set_decl(IrBuilder *irb, Scope *parent_scope, A
79467960
79477961 for (uint32_t i = 0; i < err_count; i += 1) {
79487962 AstNode *field_node = node->data.err_set_decl.decls.at(i);
7949 AstNode *symbol_node;
7950 if (field_node->type == NodeTypeSymbol) {
7951 symbol_node = field_node;
7952 } else if (field_node->type == NodeTypeErrorSetField) {
7953 symbol_node = field_node->data.err_set_field.field_name;
7954 } else {
7955 zig_unreachable();
7956 }
7957 assert(symbol_node->type == NodeTypeSymbol);
7963 AstNode *symbol_node = ast_field_to_symbol_node(field_node);
79587964 Buf *err_name = symbol_node->data.symbol_expr.symbol;
79597965 ErrorTableEntry *err = allocate<ErrorTableEntry>(1);
7960 err->decl_node = symbol_node;
7966 err->decl_node = field_node;
79617967 buf_init_from_buf(&err->name, err_name);
79627968
79637969 auto existing_entry = irb->codegen->error_table.put_unique(err_name, err);
......@@ -7973,8 +7979,10 @@ static IrInstruction *ir_gen_err_set_decl(IrBuilder *irb, Scope *parent_scope, A
79737979
79747980 ErrorTableEntry *prev_err = errors[err->value];
79757981 if (prev_err != nullptr) {
7976 ErrorMsg *msg = add_node_error(irb->codegen, err->decl_node, buf_sprintf("duplicate error: '%s'", buf_ptr(&err->name)));
7977 add_error_note(irb->codegen, msg, prev_err->decl_node, buf_sprintf("other error here"));
7982 ErrorMsg *msg = add_node_error(irb->codegen, ast_field_to_symbol_node(err->decl_node),
7983 buf_sprintf("duplicate error: '%s'", buf_ptr(&err->name)));
7984 add_error_note(irb->codegen, msg, ast_field_to_symbol_node(prev_err->decl_node),
7985 buf_sprintf("other error here"));
79787986 return irb->codegen->invalid_instruction;
79797987 }
79807988 errors[err->value] = err;
......@@ -9479,6 +9487,14 @@ static void populate_error_set_table(ErrorTableEntry **errors, ZigType *set) {
94799487 }
94809488}
94819489
9490static ErrorTableEntry *better_documented_error(ErrorTableEntry *preferred, ErrorTableEntry *other) {
9491 if (preferred->decl_node->type == NodeTypeErrorSetField)
9492 return preferred;
9493 if (other->decl_node->type == NodeTypeErrorSetField)
9494 return other;
9495 return preferred;
9496}
9497
94829498static ZigType *get_error_set_intersection(IrAnalyze *ira, ZigType *set1, ZigType *set2,
94839499 AstNode *source_node)
94849500{
......@@ -9505,12 +9521,17 @@ static ZigType *get_error_set_intersection(IrAnalyze *ira, ZigType *set1, ZigTyp
95059521 buf_resize(&err_set_type->name, 0);
95069522 buf_appendf(&err_set_type->name, "error{");
95079523
9524 bool need_comma = false;
95089525 for (uint32_t i = 0; i < set2->data.error_set.err_count; i += 1) {
95099526 ErrorTableEntry *error_entry = set2->data.error_set.errors[i];
95109527 ErrorTableEntry *existing_entry = errors[error_entry->value];
95119528 if (existing_entry != nullptr) {
9512 intersection_list.append(existing_entry);
9513 buf_appendf(&err_set_type->name, "%s,", buf_ptr(&existing_entry->name));
9529 // prefer the one with docs
9530 const char *comma = need_comma ? "," : "";
9531 need_comma = true;
9532 ErrorTableEntry *existing_entry_with_docs = better_documented_error(existing_entry, error_entry);
9533 intersection_list.append(existing_entry_with_docs);
9534 buf_appendf(&err_set_type->name, "%s%s", comma, buf_ptr(&existing_entry_with_docs->name));
95149535 }
95159536 }
95169537 free(errors);
......@@ -12058,7 +12079,7 @@ static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCa
1205812079 ZigList<ErrorTableEntry *> *missing_errors = &cast_result->data.error_set_mismatch->missing_errors;
1205912080 for (size_t i = 0; i < missing_errors->length; i += 1) {
1206012081 ErrorTableEntry *error_entry = missing_errors->at(i);
12061 add_error_note(ira->codegen, parent_msg, error_entry->decl_node,
12082 add_error_note(ira->codegen, parent_msg, ast_field_to_symbol_node(error_entry->decl_node),
1206212083 buf_sprintf("'error.%s' not a member of destination error set", buf_ptr(&error_entry->name)));
1206312084 }
1206412085 break;
src/parser.cpp+5-1
......@@ -498,8 +498,12 @@ static AstNode *ast_parse_root(ParseContext *pc) {
498498}
499499
500500static Token *ast_parse_doc_comments(ParseContext *pc, Buf *buf) {
501 Token *first_doc_token = nullptr;
501502 Token *doc_token = nullptr;
502503 while ((doc_token = eat_token_if(pc, TokenIdDocComment))) {
504 if (first_doc_token == nullptr) {
505 first_doc_token = doc_token;
506 }
503507 if (buf->list.length == 0) {
504508 buf_resize(buf, 0);
505509 }
......@@ -507,7 +511,7 @@ static Token *ast_parse_doc_comments(ParseContext *pc, Buf *buf) {
507511 buf_append_mem(buf, buf_ptr(pc->buf) + doc_token->start_pos + 3,
508512 doc_token->end_pos - doc_token->start_pos - 3);
509513 }
510 return doc_token;
514 return first_doc_token;
511515}
512516
513517// ContainerMembers