authorgravatar for kappaloris@gmail.comLoris Cro <kappaloris@gmail.com> 2022-03-31 19:07:57+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-07-19 19:10:11-07:00
log919b8e400ca7b2885221a4a93ba5ab3192046480
treeca16326ccc5769b3f03510a910576ca19e9b0821
parent72e5b4fb747908d4cf4e5039c671ec729e5b7716

autodoc: more typechecking in main.js


1 files changed, 200 insertions(+), 133 deletions(-)

lib/docs/main.js+200-133
...@@ -56,31 +56,39 @@...@@ -56,31 +56,39 @@
56*/56*/
5757
58/**58/**
59 * @typedef {59 * @typedef {{
60 | { kind: number, name: string; src: number; privDecls: number[]; pubDecls: number[]; fields: WalkResult[] } // Struct, Enum, Union60 kind: number,
61 } ContainerType61 name: string,
62 src: number,
63 privDecls: number[],
64 pubDecls: number[],
65 fields: WalkResult[]
66}} ContainerType
67*/
68
69/**
70 * @typedef {{
71 kind: number,
72 name: string,
73 src: number,
74 ret: WalkResult,
75 params: WalkResult[]
76 }} Fn
62*/77*/
6378
79
64/**80/**
65 * @typedef {81 * @typedef {
66 | { kind: number, name: string } // Type, Void, Bool, NoReturn, Int, Float, ComptimeExpr, ComptimeFloat, ComptimeInt, Undefined, Null, ErrorUnion, BoundFn, Opaque, Frame, AnyFrame, Vector, EnumLiteral82 | { kind: number, name: string } // Type, Void, Bool, NoReturn, Int, Float, ComptimeExpr, ComptimeFloat, ComptimeInt, Undefined, Null, ErrorUnion, BoundFn, Opaque, Frame, AnyFrame, Vector, EnumLiteral
67 | { kind: number, name: string; child: TypeRef } // Optional83 | { kind: number, name: string; child: WalkResult } // Optional
68 | { kind: number, len: WalkResult; child: TypeRef } // Array84 | { kind: number, len: WalkResult; child: WalkResult } // Array
69 | { kind: number, name: string; fields: { name: string; docs: string }[] } // ErrorSet85 | { kind: number, name: string; fields: { name: string; docs: string }[] } // ErrorSet
70 | { kind: number, size: "One" | "Many" | "Slice" | "C"; child: TypeRef } // Pointer86 | { kind: number, size: "One" | "Many" | "Slice" | "C"; child: WalkResult } // Pointer
71 | ContainerType87 | ContainerType
72 | { kind: number, name: string; src: number; ret: WalkResult; params: WalkResult[] } // Fn88 | Fn
73 } Type89 } Type
74*/90*/
7591
76/**
77 * @typedef {{
78 name: string,
79 src: number | null,
80 ret: WalkResult,
81 params: WalkResult[] | null,
82 }} Fn
83*/
8492
85/**93/**
86 * @typedef {{94 * @typedef {{
...@@ -109,6 +117,7 @@...@@ -109,6 +117,7 @@
109 src: number,117 src: number,
110 value: WalkResult,118 value: WalkResult,
111 decltest?: number,119 decltest?: number,
120 isTest: bool,
112 }} Decl121 }} Decl
113*/122*/
114123
...@@ -117,7 +126,7 @@...@@ -117,7 +126,7 @@
117 name: string,126 name: string,
118 file: number,127 file: number,
119 main: number,128 main: number,
120 table: { root: number },129 table: Record<string, number>,
121 }} Package130 }} Package
122*/131*/
123132
...@@ -225,17 +234,34 @@ var zigAnalysis;...@@ -225,17 +234,34 @@ var zigAnalysis;
225 /** @type Object<string, string> */234 /** @type Object<string, string> */
226 var escapeHtmlReplacements = { "&": "&amp;", '"': "&quot;", "<": "&lt;", ">": "&gt;" };235 var escapeHtmlReplacements = { "&": "&amp;", '"': "&quot;", "<": "&lt;", ">": "&gt;" };
227236
228 var typeKinds = indexTypeKinds();237 var typeKinds = /** @type {Record<string, number>} */(indexTypeKinds());
229 var typeTypeId = findTypeTypeId();238 var typeTypeId = /** @type {number} */ (findTypeTypeId());
230 var pointerSizeEnum = { One: 0, Many: 1, Slice: 2, C: 3 };239 var pointerSizeEnum = { One: 0, Many: 1, Slice: 2, C: 3 };
231240
232 // for each package, is an array with packages to get to this one241 // for each package, is an array with packages to get to this one
233 var canonPkgPaths = computeCanonicalPackagePaths();242 var canonPkgPaths = computeCanonicalPackagePaths();
243
244 /** @typedef {{declNames: string[], pkgNames: string[]}} CanonDecl */
245
234 // for each decl, is an array with {declNames, pkgNames} to get to this one246 // for each decl, is an array with {declNames, pkgNames} to get to this one
247 /** @type CanonDecl[] | null */
235 var canonDeclPaths = null; // lazy; use getCanonDeclPath248 var canonDeclPaths = null; // lazy; use getCanonDeclPath
249
236 // for each type, is an array with {declNames, pkgNames} to get to this one250 // for each type, is an array with {declNames, pkgNames} to get to this one
251 /** @type number[] | null */
237 var canonTypeDecls = null; // lazy; use getCanonTypeDecl252 var canonTypeDecls = null; // lazy; use getCanonTypeDecl
238253
254 /** @typedef {{
255 * showPrivDecls: bool,
256 * pkgNames: string[],
257 * pkgObjs: Package[],
258 * declNames: string[],
259 * declObjs: Decl[],
260 * callName: any,
261 * }} CurNav
262 */
263
264 /** @type {CurNav} */
239 var curNav = {265 var curNav = {
240 showPrivDecls: false,266 showPrivDecls: false,
241 // each element is a package name, e.g. @import("a") then within there @import("b")267 // each element is a package name, e.g. @import("a") then within there @import("b")
...@@ -252,6 +278,7 @@ var zigAnalysis;...@@ -252,6 +278,7 @@ var zigAnalysis;
252 // (a, b, c, d) comptime call; result is the value the docs refer to278 // (a, b, c, d) comptime call; result is the value the docs refer to
253 callName: null,279 callName: null,
254 };280 };
281
255 var curNavSearch = "";282 var curNavSearch = "";
256 var curSearchIndex = -1;283 var curSearchIndex = -1;
257 var imFeelingLucky = false;284 var imFeelingLucky = false;
...@@ -606,7 +633,7 @@ var zigAnalysis;...@@ -606,7 +633,7 @@ var zigAnalysis;
606 if (instantiations == null && calls == null) {633 if (instantiations == null && calls == null) {
607 domFnNoExamples.classList.remove("hidden");634 domFnNoExamples.classList.remove("hidden");
608 } else if (calls != null) {635 } else if (calls != null) {
609 if (fnObj.combined === undefined) fnObj.combined = allCompTimeFnCallsResult(calls);636 // if (fnObj.combined === undefined) fnObj.combined = allCompTimeFnCallsResult(calls);
610 if (fnObj.combined != null) renderContainer(fnObj.combined);637 if (fnObj.combined != null) renderContainer(fnObj.combined);
611638
612 resizeDomList(domListFnExamples, calls.length, '<li></li>');639 resizeDomList(domListFnExamples, calls.length, '<li></li>');
...@@ -848,6 +875,14 @@ var zigAnalysis;...@@ -848,6 +875,14 @@ var zigAnalysis;
848 }875 }
849 }876 }
850877
878 /**
879 * @param {WalkResult} typeValue,
880 * @param {boolean} wantHtml,
881 * @param {boolean} wantLink,
882 * @param {number} [fnDecl],
883 * @param {string} [linkFnNameDecl],
884 * @return {string}
885 */
851 function typeValueName(typeValue, wantHtml, wantLink, fnDecl, linkFnNameDecl) {886 function typeValueName(typeValue, wantHtml, wantLink, fnDecl, linkFnNameDecl) {
852887
853 if ("int" in typeValue) {888 if ("int" in typeValue) {
...@@ -984,6 +1019,14 @@ var zigAnalysis;...@@ -984,6 +1019,14 @@ var zigAnalysis;
984 }1019 }
985 }1020 }
9861021
1022 /**
1023 * @param {Type} typeObj,
1024 * @param {boolean} wantHtml,
1025 * @param {boolean} wantSubLink,
1026 * @param {number} [fnDecl],
1027 * @param {string} [linkFnNameDecl],
1028 * @return {string}
1029 */
987 function typeName(typeObj, wantHtml, wantSubLink, fnDecl, linkFnNameDecl) {1030 function typeName(typeObj, wantHtml, wantSubLink, fnDecl, linkFnNameDecl) {
988 switch (typeObj.kind) {1031 switch (typeObj.kind) {
989 case typeKinds.Array:1032 case typeKinds.Array:
...@@ -1294,111 +1337,113 @@ var zigAnalysis;...@@ -1294,111 +1337,113 @@ var zigAnalysis;
1294 domSectFnErrors.classList.remove("hidden");1337 domSectFnErrors.classList.remove("hidden");
1295 }1338 }
12961339
1297 function allCompTimeFnCallsHaveTypeResult(typeIndex, value) {1340// function allCompTimeFnCallsHaveTypeResult(typeIndex, value) {
1298 var srcIndex = zigAnalysis.fns[value].src;1341// var srcIndex = zigAnalysis.fns[value].src;
1299 var calls = nodesToCallsMap[srcIndex];1342// var calls = nodesToCallsMap[srcIndex];
1300 if (calls == null) return false;1343// if (calls == null) return false;
1301 for (var i = 0; i < calls.length; i += 1) {1344// for (var i = 0; i < calls.length; i += 1) {
1302 var call = zigAnalysis.calls[calls[i]];1345// var call = zigAnalysis.calls[calls[i]];
1303 if (call.result.type !== typeTypeId) return false;1346// if (call.result.type !== typeTypeId) return false;
1304 }1347// }
1305 return true;1348// return true;
1306 }1349// }
13071350//
1308 function allCompTimeFnCallsResult(calls) {1351// function allCompTimeFnCallsResult(calls) {
1309 var firstTypeObj = null;1352// var firstTypeObj = null;
1310 var containerObj = {1353// var containerObj = {
1311 privDecls: [],1354// privDecls: [],
1312 };1355// };
1313 for (var callI = 0; callI < calls.length; callI += 1) {1356// for (var callI = 0; callI < calls.length; callI += 1) {
1314 var call = zigAnalysis.calls[calls[callI]];1357// var call = zigAnalysis.calls[calls[callI]];
1315 if (call.result.type !== typeTypeId) return null;1358// if (call.result.type !== typeTypeId) return null;
1316 var typeObj = zigAnalysis.types[call.result.value];1359// var typeObj = zigAnalysis.types[call.result.value];
1317 if (!typeKindIsContainer(typeObj.kind)) return null;1360// if (!typeKindIsContainer(typeObj.kind)) return null;
1318 if (firstTypeObj == null) {1361// if (firstTypeObj == null) {
1319 firstTypeObj = typeObj;1362// firstTypeObj = typeObj;
1320 containerObj.src = typeObj.src;1363// containerObj.src = typeObj.src;
1321 } else if (firstTypeObj.src !== typeObj.src) {1364// } else if (firstTypeObj.src !== typeObj.src) {
1322 return null;1365// return null;
1323 }1366// }
13241367//
1325 if (containerObj.fields == null) {1368// if (containerObj.fields == null) {
1326 containerObj.fields = (typeObj.fields || []).concat([]);1369// containerObj.fields = (typeObj.fields || []).concat([]);
1327 } else for (var fieldI = 0; fieldI < typeObj.fields.length; fieldI += 1) {1370// } else for (var fieldI = 0; fieldI < typeObj.fields.length; fieldI += 1) {
1328 var prev = containerObj.fields[fieldI];1371// var prev = containerObj.fields[fieldI];
1329 var next = typeObj.fields[fieldI];1372// var next = typeObj.fields[fieldI];
1330 if (prev === next) continue;1373// if (prev === next) continue;
1331 if (typeof(prev) === 'object') {1374// if (typeof(prev) === 'object') {
1332 if (prev[next] == null) prev[next] = typeObj;1375// if (prev[next] == null) prev[next] = typeObj;
1333 } else {1376// } else {
1334 containerObj.fields[fieldI] = {};1377// containerObj.fields[fieldI] = {};
1335 containerObj.fields[fieldI][prev] = firstTypeObj;1378// containerObj.fields[fieldI][prev] = firstTypeObj;
1336 containerObj.fields[fieldI][next] = typeObj;1379// containerObj.fields[fieldI][next] = typeObj;
1337 }1380// }
1338 }1381// }
13391382//
1340 if (containerObj.pubDecls == null) {1383// if (containerObj.pubDecls == null) {
1341 containerObj.pubDecls = (typeObj.pubDecls || []).concat([]);1384// containerObj.pubDecls = (typeObj.pubDecls || []).concat([]);
1342 } else for (var declI = 0; declI < typeObj.pubDecls.length; declI += 1) {1385// } else for (var declI = 0; declI < typeObj.pubDecls.length; declI += 1) {
1343 var prev = containerObj.pubDecls[declI];1386// var prev = containerObj.pubDecls[declI];
1344 var next = typeObj.pubDecls[declI];1387// var next = typeObj.pubDecls[declI];
1345 if (prev === next) continue;1388// if (prev === next) continue;
1346 // TODO instead of showing "examples" as the public declarations,1389// // TODO instead of showing "examples" as the public declarations,
1347 // do logic like this:1390// // do logic like this:
1348 //if (typeof(prev) !== 'object') {1391// //if (typeof(prev) !== 'object') {
1349 // var newDeclId = zigAnalysis.decls.length;1392// // var newDeclId = zigAnalysis.decls.length;
1350 // prev = clone(zigAnalysis.decls[prev]);1393// // prev = clone(zigAnalysis.decls[prev]);
1351 // prev.id = newDeclId;1394// // prev.id = newDeclId;
1352 // zigAnalysis.decls.push(prev);1395// // zigAnalysis.decls.push(prev);
1353 // containerObj.pubDecls[declI] = prev;1396// // containerObj.pubDecls[declI] = prev;
1354 //}1397// //}
1355 //mergeDecls(prev, next, firstTypeObj, typeObj);1398// //mergeDecls(prev, next, firstTypeObj, typeObj);
1356 }1399// }
1357 }1400// }
1358 for (var declI = 0; declI < containerObj.pubDecls.length; declI += 1) {1401// for (var declI = 0; declI < containerObj.pubDecls.length; declI += 1) {
1359 var decl = containerObj.pubDecls[declI];1402// var decl = containerObj.pubDecls[declI];
1360 if (typeof(decl) === 'object') {1403// if (typeof(decl) === 'object') {
1361 containerObj.pubDecls[declI] = containerObj.pubDecls[declI].id;1404// containerObj.pubDecls[declI] = containerObj.pubDecls[declI].id;
1362 }1405// }
1363 }1406// }
1364 return containerObj;1407// return containerObj;
1365 }1408// }
13661409
1367 function mergeDecls(declObj, nextDeclIndex, firstTypeObj, typeObj) {
1368 var nextDeclObj = zigAnalysis.decls[nextDeclIndex];
1369 if (declObj.type != null && nextDeclObj.type != null && declObj.type !== nextDeclObj.type) {
1370 if (typeof(declObj.type) !== 'object') {
1371 var prevType = declObj.type;
1372 declObj.type = {};
1373 declObj.type[prevType] = firstTypeObj;
1374 declObj.value = null;
1375 }
1376 declObj.type[nextDeclObj.type] = typeObj;
1377 } else if (declObj.type == null && nextDeclObj != null) {
1378 declObj.type = nextDeclObj.type;
1379 }
1380 if (declObj.value != null && nextDeclObj.value != null && declObj.value !== nextDeclObj.value) {
1381 if (typeof(declObj.value) !== 'object') {
1382 var prevValue = declObj.value;
1383 declObj.value = {};
1384 declObj.value[prevValue] = firstTypeObj;
1385 }
1386 declObj.value[nextDeclObj.value] = typeObj;
1387 } else if (declObj.value == null && nextDeclObj.value != null) {
1388 declObj.value = nextDeclObj.value;
1389 }
1390 }
13911410
1411 // function mergeDecls(declObj, nextDeclIndex, firstTypeObj, typeObj) {
1412 // var nextDeclObj = zigAnalysis.decls[nextDeclIndex];
1413 // if (declObj.type != null && nextDeclObj.type != null && declObj.type !== nextDeclObj.type) {
1414 // if (typeof(declObj.type) !== 'object') {
1415 // var prevType = declObj.type;
1416 // declObj.type = {};
1417 // declObj.type[prevType] = firstTypeObj;
1418 // declObj.value = null;
1419 // }
1420 // declObj.type[nextDeclObj.type] = typeObj;
1421 // } else if (declObj.type == null && nextDeclObj != null) {
1422 // declObj.type = nextDeclObj.type;
1423 // }
1424 // if (declObj.value != null && nextDeclObj.value != null && declObj.value !== nextDeclObj.value) {
1425 // if (typeof(declObj.value) !== 'object') {
1426 // var prevValue = declObj.value;
1427 // declObj.value = {};
1428 // declObj.value[prevValue] = firstTypeObj;
1429 // }
1430 // declObj.value[nextDeclObj.value] = typeObj;
1431 // } else if (declObj.value == null && nextDeclObj.value != null) {
1432 // declObj.value = nextDeclObj.value;
1433 // }
1434 // }
1435
1436 /** @param {Decl} decl */
1392 function renderValue(decl) {1437 function renderValue(decl) {
13931438
1394 var declTypeRef = typeOfDecl(decl);1439 var declTypeRef = typeOfDecl(decl);
1395 var declValueText = "";1440 var declValueText = "";
1396 switch(Object.keys(decl.value)[0]) {1441 switch(Object.keys(decl.value)[0]) {
1397 case "int":1442 case "int":
1398 declValueText += decl.value.int.value;1443 declValueText += /** @type {{int: {value: number}}} */(decl.value).int.value;
1399 break;1444 break;
1400 case "float":1445 case "float":
1401 declValueText += decl.value.float.value;1446 declValueText += /** @type {{float: {value: number}}} */(decl.value).float.value;
1402 break;1447 break;
1403 case "comptimeExpr":1448 case "comptimeExpr":
1404 declValueText += "[ComptimeExpr]";1449 declValueText += "[ComptimeExpr]";
...@@ -1421,6 +1466,7 @@ var zigAnalysis;...@@ -1421,6 +1466,7 @@ var zigAnalysis;
1421 domFnProto.classList.remove("hidden");1466 domFnProto.classList.remove("hidden");
1422 }1467 }
14231468
1469 /** @param {Decl} decl */
1424 function renderVar(decl) {1470 function renderVar(decl) {
1425 var declTypeRef = typeOfDecl(decl);1471 var declTypeRef = typeOfDecl(decl);
1426 domFnProtoCode.innerHTML = '<span class="tok-kw">var</span> ' +1472 domFnProtoCode.innerHTML = '<span class="tok-kw">var</span> ' +
...@@ -1438,7 +1484,13 @@ var zigAnalysis;...@@ -1438,7 +1484,13 @@ var zigAnalysis;
14381484
1439 /**1485 /**
1440 * @param {number[]} decls1486 * @param {number[]} decls
1441 * @param {Decl[]} typesList, namespacesList, errSetsList, fnsList, varsList, valsList, testsList1487 * @param {Decl[]} typesList
1488 * @param {Decl[]} namespacesList,
1489 * @param {Decl[]} errSetsList,
1490 * @param {Decl[]} fnsList,
1491 * @param {Decl[]} varsList,
1492 * @param {Decl[]} valsList,
1493 * @param {Decl[]} testsList
1442 */1494 */
1443 function categorizeDecls(decls,1495 function categorizeDecls(decls,
1444 typesList, namespacesList, errSetsList,1496 typesList, namespacesList, errSetsList,
...@@ -1482,7 +1534,7 @@ var zigAnalysis;...@@ -1482,7 +1534,7 @@ var zigAnalysis;
1482 var kind = value.kind;1534 var kind = value.kind;
1483 if (kind === typeKinds.Fn) {1535 if (kind === typeKinds.Fn) {
1484 // TODO: handle CTE return types when we know their type.1536 // TODO: handle CTE return types when we know their type.
1485 const resVal = resolveValue(value.ret);1537 const resVal = resolveValue(/** @type {Fn} */(value).ret);
1486 if ("type" in resVal && resVal.type == typeTypeId) {1538 if ("type" in resVal && resVal.type == typeTypeId) {
1487 typesList.push(decl);1539 typesList.push(decl);
1488 } else {1540 } else {
...@@ -1610,20 +1662,17 @@ var zigAnalysis;...@@ -1610,20 +1662,17 @@ var zigAnalysis;
1610 for (var i = 0; i < containerNode.fields.length; i += 1) {1662 for (var i = 0; i < containerNode.fields.length; i += 1) {
1611 var fieldNode = zigAnalysis.astNodes[containerNode.fields[i]];1663 var fieldNode = zigAnalysis.astNodes[containerNode.fields[i]];
1612 var divDom = domListFields.children[i];1664 var divDom = domListFields.children[i];
1665 let fieldName = /** @type {string} */(fieldNode.name);
16131666
1614 var html = '<div class="mobile-scroll-container"><pre class="scroll-item">' + escapeHtml(fieldNode.name);1667 var html = '<div class="mobile-scroll-container"><pre class="scroll-item">' + escapeHtml(fieldName);
16151668
1616 if (container.kind === typeKinds.Enum) {1669 if (container.kind === typeKinds.Enum) {
1617 html += ' = <span class="tok-number">' + field + '</span>';1670 html += ' = <span class="tok-number">' + fieldName + '</span>';
1618 } else {1671 } else {
1619 var field = container.fields[i];1672 var field = container.fields[i];
1620 html += ": ";1673 html += ": ";
1621 if (field.failure === true) {1674 var name = typeValueName(field);
1622 html += '<span class="tok-kw" style="color:red;">#FAILURE#</span>';1675 html += '<span class="tok-kw">'+ name +'</span>';
1623 } else {
1624 var name = typeValueName(field);
1625 html += '<span class="tok-kw">'+ name +'</span>';
1626 }
1627 }1676 }
16281677
1629 html += ',</pre></div>';1678 html += ',</pre></div>';
...@@ -1719,6 +1768,11 @@ var zigAnalysis;...@@ -1719,6 +1768,11 @@ var zigAnalysis;
1719 }1768 }
1720 }1769 }
17211770
1771
1772 /**
1773 * @param {string | number} a
1774 * @param {string | number} b
1775 */
1722 function operatorCompare(a, b) {1776 function operatorCompare(a, b) {
1723 if (a === b) {1777 if (a === b) {
1724 return 0;1778 return 0;
...@@ -1741,7 +1795,7 @@ var zigAnalysis;...@@ -1741,7 +1795,7 @@ var zigAnalysis;
1741 }1795 }
17421796
1743 function indexTypeKinds() {1797 function indexTypeKinds() {
1744 var map = {};1798 var map = /** @type {Record<string, number>} */({});
1745 for (var i = 0; i < zigAnalysis.typeKinds.length; i += 1) {1799 for (var i = 0; i < zigAnalysis.typeKinds.length; i += 1) {
1746 map[zigAnalysis.typeKinds[i]] = i;1800 map[zigAnalysis.typeKinds[i]] = i;
1747 }1801 }
...@@ -1765,12 +1819,14 @@ var zigAnalysis;...@@ -1765,12 +1819,14 @@ var zigAnalysis;
1765 }1819 }
17661820
1767 function updateCurNav() {1821 function updateCurNav() {
1822
1768 curNav = {1823 curNav = {
1769 showPrivDecls: false,1824 showPrivDecls: false,
1770 pkgNames: [],1825 pkgNames: [],
1771 pkgObjs: [],1826 pkgObjs: [],
1772 declNames: [],1827 declNames: [],
1773 declObjs: [],1828 declObjs: [],
1829 callName: null,
1774 };1830 };
1775 curNavSearch = "";1831 curNavSearch = "";
17761832
...@@ -1814,6 +1870,10 @@ var zigAnalysis;...@@ -1814,6 +1870,10 @@ var zigAnalysis;
1814 }1870 }
1815 }1871 }
18161872
1873 /**
1874 * @param {ContainerType} parentType
1875 * @param {string} childName
1876 */
1817 function findSubDecl(parentType, childName) {1877 function findSubDecl(parentType, childName) {
1818 if (!parentType.pubDecls) return null;1878 if (!parentType.pubDecls) return null;
1819 for (var i = 0; i < parentType.pubDecls.length; i += 1) {1879 for (var i = 0; i < parentType.pubDecls.length; i += 1) {
...@@ -1843,11 +1903,11 @@ var zigAnalysis;...@@ -1843,11 +1903,11 @@ var zigAnalysis;
1843 var rootPkg = zigAnalysis.packages[zigAnalysis.rootPkg];1903 var rootPkg = zigAnalysis.packages[zigAnalysis.rootPkg];
1844 // Breadth-first to keep the path shortest possible.1904 // Breadth-first to keep the path shortest possible.
1845 var stack = [{1905 var stack = [{
1846 path: [],1906 path: /** @type {string[]} */([]),
1847 pkg: rootPkg,1907 pkg: rootPkg,
1848 }];1908 }];
1849 while (stack.length !== 0) {1909 while (stack.length !== 0) {
1850 var item = stack.shift();1910 var item = /** @type {{path: string[], pkg: Package}} */(stack.shift());
1851 for (var key in item.pkg.table) {1911 for (var key in item.pkg.table) {
1852 var childPkgIndex = item.pkg.table[key];1912 var childPkgIndex = item.pkg.table[key];
1853 if (list[childPkgIndex] != null) continue;1913 if (list[childPkgIndex] != null) continue;
...@@ -1866,6 +1926,7 @@ var zigAnalysis;...@@ -1866,6 +1926,7 @@ var zigAnalysis;
1866 }1926 }
18671927
18681928
1929 /** @return {CanonDecl[]} */
1869 function computeCanonDeclPaths() {1930 function computeCanonDeclPaths() {
1870 var list = new Array(zigAnalysis.decls.length);1931 var list = new Array(zigAnalysis.decls.length);
1871 canonTypeDecls = new Array(zigAnalysis.types.length);1932 canonTypeDecls = new Array(zigAnalysis.types.length);
...@@ -1875,16 +1936,18 @@ var zigAnalysis;...@@ -1875,16 +1936,18 @@ var zigAnalysis;
1875 var pkg = zigAnalysis.packages[pkgI];1936 var pkg = zigAnalysis.packages[pkgI];
1876 var pkgNames = canonPkgPaths[pkgI];1937 var pkgNames = canonPkgPaths[pkgI];
1877 var stack = [{1938 var stack = [{
1878 declNames: [],1939 declNames: /** @type {string[]} */([]),
1879 type: zigAnalysis.types[pkg.main],1940 type: zigAnalysis.types[pkg.main],
1880 }];1941 }];
1881 while (stack.length !== 0) {1942 while (stack.length !== 0) {
1882 var item = stack.shift();1943 var item = /** @type {{declNames: string[], type: Type}} */(stack.shift());
18831944
1884 if (isContainerType(item.type)) {1945 if (isContainerType(item.type)) {
1885 var len = item.type.pubDecls ? item.type.pubDecls.length : 0;1946 let t = /** @type {ContainerType} */(item.type);
1947
1948 var len = t.pubDecls ? t.pubDecls.length : 0;
1886 for (var declI = 0; declI < len; declI += 1) {1949 for (var declI = 0; declI < len; declI += 1) {
1887 var mainDeclIndex = item.type.pubDecls[declI];1950 var mainDeclIndex = t.pubDecls[declI];
1888 if (list[mainDeclIndex] != null) continue;1951 if (list[mainDeclIndex] != null) continue;
18891952
1890 var decl = zigAnalysis.decls[mainDeclIndex];1953 var decl = zigAnalysis.decls[mainDeclIndex];
...@@ -1915,16 +1978,20 @@ var zigAnalysis;...@@ -1915,16 +1978,20 @@ var zigAnalysis;
1915 return list;1978 return list;
1916 }1979 }
19171980
1981 /** @param {number} index */
1918 function getCanonDeclPath(index) {1982 function getCanonDeclPath(index) {
1919 if (canonDeclPaths == null) {1983 if (canonDeclPaths == null) {
1920 canonDeclPaths = computeCanonDeclPaths();1984 canonDeclPaths = computeCanonDeclPaths();
1921 }1985 }
1922 return canonDeclPaths[index];1986 let cd = /** @type {CanonDecl[]}*/(canonDeclPaths);
1987 return cd[index];
1923 }1988 }
19241989
1990 /** @param {number} index */
1925 function getCanonTypeDecl(index) {1991 function getCanonTypeDecl(index) {
1926 getCanonDeclPath(0);1992 getCanonDeclPath(0);
1927 return canonTypeDecls[index];1993 let ct = /** @type {number[]}*/(canonTypeDecls);
1994 return ct[index];
1928 }1995 }
19291996
1930 /** @param {string} text */1997 /** @param {string} text */