authorgravatar for kappaloris@gmail.comLoris Cro <kappaloris@gmail.com> 2023-07-21 18:45:15+02:00
committergravatar for kappaloris@gmail.comLoris Cro <kappaloris@gmail.com> 2023-07-21 18:45:50+02:00
log426e737292ffb3ec1d4c5780bd3c0511d4cdbc2b
treebd09c55cc01565a2a72ec0c272db58f60bd90c12
parent61d5b7c957e63239f1ebbdbfb94105d53f2dbaa4

autodoc: avoid recursing reference loops in call instructions


1 files changed, 537 insertions(+), 54 deletions(-)

src/Autodoc.zig+537-54
...@@ -328,7 +328,14 @@ pub fn generateZirData(self: *Autodoc) !void {...@@ -328,7 +328,14 @@ pub fn generateZirData(self: *Autodoc) !void {
328 });328 });
329 try self.files.put(self.arena, file, main_type_index);329 try self.files.put(self.arena, file, main_type_index);
330330
331 _ = try self.walkInstruction(file, &root_scope, .{}, Zir.main_struct_inst, false);331 _ = try self.walkInstruction(
332 file,
333 &root_scope,
334 .{},
335 Zir.main_struct_inst,
336 false,
337 null,
338 );
332339
333 if (self.ref_paths_pending_on_decls.count() > 0) {340 if (self.ref_paths_pending_on_decls.count() > 0) {
334 @panic("some decl paths were never fully analized (pending on decls)");341 @panic("some decl paths were never fully analized (pending on decls)");
...@@ -979,6 +986,15 @@ const AutodocErrors = error{...@@ -979,6 +986,15 @@ const AutodocErrors = error{
979 UnexpectedEndOfFile,986 UnexpectedEndOfFile,
980} || std.fs.File.OpenError || std.fs.File.ReadError;987} || std.fs.File.OpenError || std.fs.File.ReadError;
981988
989/// `call` instructions will have loopy references to themselves
990/// whenever an as_node is required for a complex expression.
991/// This type is used to keep track of dangerous instruction
992/// numbers that we definitely don't want to recurse into.
993const CallContext = struct {
994 inst: usize,
995 prev: ?*const CallContext,
996};
997
982/// Called when we need to analyze a Zir instruction.998/// Called when we need to analyze a Zir instruction.
983/// For example it gets called by `generateZirData` on instruction 0,999/// For example it gets called by `generateZirData` on instruction 0,
984/// which represents the top-level struct corresponding to the root file.1000/// which represents the top-level struct corresponding to the root file.
...@@ -994,6 +1010,7 @@ fn walkInstruction(...@@ -994,6 +1010,7 @@ fn walkInstruction(
994 parent_src: SrcLocInfo,1010 parent_src: SrcLocInfo,
995 inst_index: usize,1011 inst_index: usize,
996 need_type: bool, // true if the caller needs us to provide also a typeRef1012 need_type: bool, // true if the caller needs us to provide also a typeRef
1013 call_ctx: ?*const CallContext,
997) AutodocErrors!DocData.WalkResult {1014) AutodocErrors!DocData.WalkResult {
998 const tags = file.zir.instructions.items(.tag);1015 const tags = file.zir.instructions.items(.tag);
999 const data = file.zir.instructions.items(.data);1016 const data = file.zir.instructions.items(.data);
...@@ -1082,6 +1099,7 @@ fn walkInstruction(...@@ -1082,6 +1099,7 @@ fn walkInstruction(
1082 .{},1099 .{},
1083 Zir.main_struct_inst,1100 Zir.main_struct_inst,
1084 false,1101 false,
1102 call_ctx,
1085 );1103 );
1086 }1104 }
10871105
...@@ -1113,6 +1131,7 @@ fn walkInstruction(...@@ -1113,6 +1131,7 @@ fn walkInstruction(
1113 .{},1131 .{},
1114 Zir.main_struct_inst,1132 Zir.main_struct_inst,
1115 need_type,1133 need_type,
1134 call_ctx,
1116 );1135 );
1117 },1136 },
1118 .ret_type => {1137 .ret_type => {
...@@ -1123,7 +1142,14 @@ fn walkInstruction(...@@ -1123,7 +1142,14 @@ fn walkInstruction(
1123 },1142 },
1124 .ret_node => {1143 .ret_node => {
1125 const un_node = data[inst_index].un_node;1144 const un_node = data[inst_index].un_node;
1126 return self.walkRef(file, parent_scope, parent_src, un_node.operand, false);1145 return self.walkRef(
1146 file,
1147 parent_scope,
1148 parent_src,
1149 un_node.operand,
1150 false,
1151 call_ctx,
1152 );
1127 },1153 },
1128 .ret_load => {1154 .ret_load => {
1129 const un_node = data[inst_index].un_node;1155 const un_node = data[inst_index].un_node;
...@@ -1154,7 +1180,14 @@ fn walkInstruction(...@@ -1154,7 +1180,14 @@ fn walkInstruction(
1154 }1180 }
11551181
1156 if (result_ref) |rr| {1182 if (result_ref) |rr| {
1157 return self.walkRef(file, parent_scope, parent_src, rr, need_type);1183 return self.walkRef(
1184 file,
1185 parent_scope,
1186 parent_src,
1187 rr,
1188 need_type,
1189 call_ctx,
1190 );
1158 }1191 }
11591192
1160 return DocData.WalkResult{1193 return DocData.WalkResult{
...@@ -1163,11 +1196,25 @@ fn walkInstruction(...@@ -1163,11 +1196,25 @@ fn walkInstruction(
1163 },1196 },
1164 .closure_get => {1197 .closure_get => {
1165 const inst_node = data[inst_index].inst_node;1198 const inst_node = data[inst_index].inst_node;
1166 return try self.walkInstruction(file, parent_scope, parent_src, inst_node.inst, need_type);1199 return try self.walkInstruction(
1200 file,
1201 parent_scope,
1202 parent_src,
1203 inst_node.inst,
1204 need_type,
1205 call_ctx,
1206 );
1167 },1207 },
1168 .closure_capture => {1208 .closure_capture => {
1169 const un_tok = data[inst_index].un_tok;1209 const un_tok = data[inst_index].un_tok;
1170 return try self.walkRef(file, parent_scope, parent_src, un_tok.operand, need_type);1210 return try self.walkRef(
1211 file,
1212 parent_scope,
1213 parent_src,
1214 un_tok.operand,
1215 need_type,
1216 call_ctx,
1217 );
1171 },1218 },
1172 .str => {1219 .str => {
1173 const str = data[inst_index].str.get(file.zir);1220 const str = data[inst_index].str.get(file.zir);
...@@ -1214,6 +1261,7 @@ fn walkInstruction(...@@ -1214,6 +1261,7 @@ fn walkInstruction(
1214 parent_src,1261 parent_src,
1215 un_node.operand,1262 un_node.operand,
1216 false,1263 false,
1264 call_ctx,
1217 );1265 );
12181266
1219 const operand_index = self.exprs.items.len;1267 const operand_index = self.exprs.items.len;
...@@ -1284,6 +1332,7 @@ fn walkInstruction(...@@ -1284,6 +1332,7 @@ fn walkInstruction(
1284 parent_src,1332 parent_src,
1285 extra.data.lhs,1333 extra.data.lhs,
1286 false,1334 false,
1335 call_ctx,
1287 );1336 );
1288 var start: DocData.WalkResult = try self.walkRef(1337 var start: DocData.WalkResult = try self.walkRef(
1289 file,1338 file,
...@@ -1291,6 +1340,7 @@ fn walkInstruction(...@@ -1291,6 +1340,7 @@ fn walkInstruction(
1291 parent_src,1340 parent_src,
1292 extra.data.start,1341 extra.data.start,
1293 false,1342 false,
1343 call_ctx,
1294 );1344 );
12951345
1296 const lhs_index = self.exprs.items.len;1346 const lhs_index = self.exprs.items.len;
...@@ -1317,6 +1367,7 @@ fn walkInstruction(...@@ -1317,6 +1367,7 @@ fn walkInstruction(
1317 parent_src,1367 parent_src,
1318 extra.data.lhs,1368 extra.data.lhs,
1319 false,1369 false,
1370 call_ctx,
1320 );1371 );
1321 var start: DocData.WalkResult = try self.walkRef(1372 var start: DocData.WalkResult = try self.walkRef(
1322 file,1373 file,
...@@ -1324,6 +1375,7 @@ fn walkInstruction(...@@ -1324,6 +1375,7 @@ fn walkInstruction(
1324 parent_src,1375 parent_src,
1325 extra.data.start,1376 extra.data.start,
1326 false,1377 false,
1378 call_ctx,
1327 );1379 );
1328 var end: DocData.WalkResult = try self.walkRef(1380 var end: DocData.WalkResult = try self.walkRef(
1329 file,1381 file,
...@@ -1331,6 +1383,7 @@ fn walkInstruction(...@@ -1331,6 +1383,7 @@ fn walkInstruction(
1331 parent_src,1383 parent_src,
1332 extra.data.end,1384 extra.data.end,
1333 false,1385 false,
1386 call_ctx,
1334 );1387 );
13351388
1336 const lhs_index = self.exprs.items.len;1389 const lhs_index = self.exprs.items.len;
...@@ -1359,6 +1412,7 @@ fn walkInstruction(...@@ -1359,6 +1412,7 @@ fn walkInstruction(
1359 parent_src,1412 parent_src,
1360 extra.data.lhs,1413 extra.data.lhs,
1361 false,1414 false,
1415 call_ctx,
1362 );1416 );
1363 var start: DocData.WalkResult = try self.walkRef(1417 var start: DocData.WalkResult = try self.walkRef(
1364 file,1418 file,
...@@ -1366,6 +1420,7 @@ fn walkInstruction(...@@ -1366,6 +1420,7 @@ fn walkInstruction(
1366 parent_src,1420 parent_src,
1367 extra.data.start,1421 extra.data.start,
1368 false,1422 false,
1423 call_ctx,
1369 );1424 );
1370 var end: DocData.WalkResult = try self.walkRef(1425 var end: DocData.WalkResult = try self.walkRef(
1371 file,1426 file,
...@@ -1373,6 +1428,7 @@ fn walkInstruction(...@@ -1373,6 +1428,7 @@ fn walkInstruction(
1373 parent_src,1428 parent_src,
1374 extra.data.end,1429 extra.data.end,
1375 false,1430 false,
1431 call_ctx,
1376 );1432 );
1377 var sentinel: DocData.WalkResult = try self.walkRef(1433 var sentinel: DocData.WalkResult = try self.walkRef(
1378 file,1434 file,
...@@ -1380,6 +1436,7 @@ fn walkInstruction(...@@ -1380,6 +1436,7 @@ fn walkInstruction(
1380 parent_src,1436 parent_src,
1381 extra.data.sentinel,1437 extra.data.sentinel,
1382 false,1438 false,
1439 call_ctx,
1383 );1440 );
13841441
1385 const lhs_index = self.exprs.items.len;1442 const lhs_index = self.exprs.items.len;
...@@ -1410,6 +1467,7 @@ fn walkInstruction(...@@ -1410,6 +1467,7 @@ fn walkInstruction(
1410 parent_src,1467 parent_src,
1411 extra.data.lhs,1468 extra.data.lhs,
1412 false,1469 false,
1470 call_ctx,
1413 );1471 );
1414 var start: DocData.WalkResult = try self.walkRef(1472 var start: DocData.WalkResult = try self.walkRef(
1415 file,1473 file,
...@@ -1417,6 +1475,7 @@ fn walkInstruction(...@@ -1417,6 +1475,7 @@ fn walkInstruction(
1417 parent_src,1475 parent_src,
1418 extra.data.start,1476 extra.data.start,
1419 false,1477 false,
1478 call_ctx,
1420 );1479 );
1421 var len: DocData.WalkResult = try self.walkRef(1480 var len: DocData.WalkResult = try self.walkRef(
1422 file,1481 file,
...@@ -1424,6 +1483,7 @@ fn walkInstruction(...@@ -1424,6 +1483,7 @@ fn walkInstruction(
1424 parent_src,1483 parent_src,
1425 extra.data.len,1484 extra.data.len,
1426 false,1485 false,
1486 call_ctx,
1427 );1487 );
1428 var sentinel_opt: ?DocData.WalkResult = if (extra.data.sentinel != .none)1488 var sentinel_opt: ?DocData.WalkResult = if (extra.data.sentinel != .none)
1429 try self.walkRef(1489 try self.walkRef(
...@@ -1432,6 +1492,7 @@ fn walkInstruction(...@@ -1432,6 +1492,7 @@ fn walkInstruction(
1432 parent_src,1492 parent_src,
1433 extra.data.sentinel,1493 extra.data.sentinel,
1434 false,1494 false,
1495 call_ctx,
1435 )1496 )
1436 else1497 else
1437 null;1498 null;
...@@ -1492,6 +1553,7 @@ fn walkInstruction(...@@ -1492,6 +1553,7 @@ fn walkInstruction(
1492 parent_src,1553 parent_src,
1493 extra.data.lhs,1554 extra.data.lhs,
1494 false,1555 false,
1556 call_ctx,
1495 );1557 );
1496 var rhs: DocData.WalkResult = try self.walkRef(1558 var rhs: DocData.WalkResult = try self.walkRef(
1497 file,1559 file,
...@@ -1499,6 +1561,7 @@ fn walkInstruction(...@@ -1499,6 +1561,7 @@ fn walkInstruction(
1499 parent_src,1561 parent_src,
1500 extra.data.rhs,1562 extra.data.rhs,
1501 false,1563 false,
1564 call_ctx,
1502 );1565 );
15031566
1504 const lhs_index = self.exprs.items.len;1567 const lhs_index = self.exprs.items.len;
...@@ -1536,6 +1599,7 @@ fn walkInstruction(...@@ -1536,6 +1599,7 @@ fn walkInstruction(
1536 parent_src,1599 parent_src,
1537 extra.data.lhs,1600 extra.data.lhs,
1538 false,1601 false,
1602 call_ctx,
1539 );1603 );
1540 var rhs: DocData.WalkResult = try self.walkRef(1604 var rhs: DocData.WalkResult = try self.walkRef(
1541 file,1605 file,
...@@ -1543,6 +1607,7 @@ fn walkInstruction(...@@ -1543,6 +1607,7 @@ fn walkInstruction(
1543 parent_src,1607 parent_src,
1544 extra.data.rhs,1608 extra.data.rhs,
1545 false,1609 false,
1610 call_ctx,
1546 );1611 );
15471612
1548 const lhs_index = self.exprs.items.len;1613 const lhs_index = self.exprs.items.len;
...@@ -1599,7 +1664,14 @@ fn walkInstruction(...@@ -1599,7 +1664,14 @@ fn walkInstruction(
1599 const un_node = data[inst_index].un_node;1664 const un_node = data[inst_index].un_node;
1600 const bin_index = self.exprs.items.len;1665 const bin_index = self.exprs.items.len;
1601 try self.exprs.append(self.arena, .{ .builtin = .{ .param = 0 } });1666 try self.exprs.append(self.arena, .{ .builtin = .{ .param = 0 } });
1602 const param = try self.walkRef(file, parent_scope, parent_src, un_node.operand, false);1667 const param = try self.walkRef(
1668 file,
1669 parent_scope,
1670 parent_src,
1671 un_node.operand,
1672 false,
1673 call_ctx,
1674 );
16031675
1604 const param_index = self.exprs.items.len;1676 const param_index = self.exprs.items.len;
1605 try self.exprs.append(self.arena, param.expr);1677 try self.exprs.append(self.arena, param.expr);
...@@ -1623,6 +1695,7 @@ fn walkInstruction(...@@ -1623,6 +1695,7 @@ fn walkInstruction(
1623 parent_src,1695 parent_src,
1624 bool_br.lhs,1696 bool_br.lhs,
1625 false,1697 false,
1698 call_ctx,
1626 );1699 );
1627 const lhs_index = self.exprs.items.len;1700 const lhs_index = self.exprs.items.len;
1628 try self.exprs.append(self.arena, lhs.expr);1701 try self.exprs.append(self.arena, lhs.expr);
...@@ -1634,6 +1707,7 @@ fn walkInstruction(...@@ -1634,6 +1707,7 @@ fn walkInstruction(
1634 parent_src,1707 parent_src,
1635 file.zir.extra[extra.end..][extra.data.body_len - 1],1708 file.zir.extra[extra.end..][extra.data.body_len - 1],
1636 false,1709 false,
1710 call_ctx,
1637 );1711 );
1638 const rhs_index = self.exprs.items.len;1712 const rhs_index = self.exprs.items.len;
1639 try self.exprs.append(self.arena, rhs.expr);1713 try self.exprs.append(self.arena, rhs.expr);
...@@ -1656,6 +1730,7 @@ fn walkInstruction(...@@ -1656,6 +1730,7 @@ fn walkInstruction(
1656 parent_src,1730 parent_src,
1657 extra.data.rhs,1731 extra.data.rhs,
1658 false,1732 false,
1733 call_ctx,
1659 );1734 );
16601735
1661 const bin_index = self.exprs.items.len;1736 const bin_index = self.exprs.items.len;
...@@ -1670,6 +1745,7 @@ fn walkInstruction(...@@ -1670,6 +1745,7 @@ fn walkInstruction(
1670 parent_src,1745 parent_src,
1671 extra.data.lhs,1746 extra.data.lhs,
1672 false,1747 false,
1748 call_ctx,
1673 );1749 );
16741750
1675 self.exprs.items[bin_index] = .{ .builtin = .{ .name = @tagName(tags[inst_index]), .param = rhs_index } };1751 self.exprs.items[bin_index] = .{ .builtin = .{ .name = @tagName(tags[inst_index]), .param = rhs_index } };
...@@ -1718,6 +1794,7 @@ fn walkInstruction(...@@ -1718,6 +1794,7 @@ fn walkInstruction(
1718 parent_src,1794 parent_src,
1719 extra.data.lhs,1795 extra.data.lhs,
1720 false,1796 false,
1797 call_ctx,
1721 );1798 );
1722 var rhs: DocData.WalkResult = try self.walkRef(1799 var rhs: DocData.WalkResult = try self.walkRef(
1723 file,1800 file,
...@@ -1725,6 +1802,7 @@ fn walkInstruction(...@@ -1725,6 +1802,7 @@ fn walkInstruction(
1725 parent_src,1802 parent_src,
1726 extra.data.rhs,1803 extra.data.rhs,
1727 false,1804 false,
1805 call_ctx,
1728 );1806 );
17291807
1730 const lhs_index = self.exprs.items.len;1808 const lhs_index = self.exprs.items.len;
...@@ -1748,6 +1826,7 @@ fn walkInstruction(...@@ -1748,6 +1826,7 @@ fn walkInstruction(
1748 parent_src,1826 parent_src,
1749 extra.data.lhs,1827 extra.data.lhs,
1750 false,1828 false,
1829 call_ctx,
1751 );1830 );
1752 var rhs: DocData.WalkResult = try self.walkRef(1831 var rhs: DocData.WalkResult = try self.walkRef(
1753 file,1832 file,
...@@ -1755,6 +1834,7 @@ fn walkInstruction(...@@ -1755,6 +1834,7 @@ fn walkInstruction(
1755 parent_src,1834 parent_src,
1756 extra.data.rhs,1835 extra.data.rhs,
1757 false,1836 false,
1837 call_ctx,
1758 );1838 );
17591839
1760 const type_slot_index = self.types.items.len;1840 const type_slot_index = self.types.items.len;
...@@ -1778,6 +1858,7 @@ fn walkInstruction(...@@ -1778,6 +1858,7 @@ fn walkInstruction(
1778 parent_src,1858 parent_src,
1779 extra.data.lhs,1859 extra.data.lhs,
1780 false,1860 false,
1861 call_ctx,
1781 );1862 );
1782 var rhs: DocData.WalkResult = try self.walkRef(1863 var rhs: DocData.WalkResult = try self.walkRef(
1783 file,1864 file,
...@@ -1785,6 +1866,7 @@ fn walkInstruction(...@@ -1785,6 +1866,7 @@ fn walkInstruction(
1785 parent_src,1866 parent_src,
1786 extra.data.rhs,1867 extra.data.rhs,
1787 false,1868 false,
1869 call_ctx,
1788 );1870 );
1789 const type_slot_index = self.types.items.len;1871 const type_slot_index = self.types.items.len;
1790 try self.types.append(self.arena, .{ .ErrorUnion = .{1872 try self.types.append(self.arena, .{ .ErrorUnion = .{
...@@ -1820,6 +1902,7 @@ fn walkInstruction(...@@ -1820,6 +1902,7 @@ fn walkInstruction(
1820 parent_src,1902 parent_src,
1821 extra.data.elem_type,1903 extra.data.elem_type,
1822 false,1904 false,
1905 call_ctx,
1823 );1906 );
18241907
1825 // @check if `addrspace`, `bit_start` and `host_size` really need to be1908 // @check if `addrspace`, `bit_start` and `host_size` really need to be
...@@ -1827,7 +1910,14 @@ fn walkInstruction(...@@ -1827,7 +1910,14 @@ fn walkInstruction(
1827 var sentinel: ?DocData.Expr = null;1910 var sentinel: ?DocData.Expr = null;
1828 if (ptr.flags.has_sentinel) {1911 if (ptr.flags.has_sentinel) {
1829 const ref = @as(Zir.Inst.Ref, @enumFromInt(file.zir.extra[extra_index]));1912 const ref = @as(Zir.Inst.Ref, @enumFromInt(file.zir.extra[extra_index]));
1830 const ref_result = try self.walkRef(file, parent_scope, parent_src, ref, false);1913 const ref_result = try self.walkRef(
1914 file,
1915 parent_scope,
1916 parent_src,
1917 ref,
1918 false,
1919 call_ctx,
1920 );
1831 sentinel = ref_result.expr;1921 sentinel = ref_result.expr;
1832 extra_index += 1;1922 extra_index += 1;
1833 }1923 }
...@@ -1835,21 +1925,42 @@ fn walkInstruction(...@@ -1835,21 +1925,42 @@ fn walkInstruction(
1835 var @"align": ?DocData.Expr = null;1925 var @"align": ?DocData.Expr = null;
1836 if (ptr.flags.has_align) {1926 if (ptr.flags.has_align) {
1837 const ref = @as(Zir.Inst.Ref, @enumFromInt(file.zir.extra[extra_index]));1927 const ref = @as(Zir.Inst.Ref, @enumFromInt(file.zir.extra[extra_index]));
1838 const ref_result = try self.walkRef(file, parent_scope, parent_src, ref, false);1928 const ref_result = try self.walkRef(
1929 file,
1930 parent_scope,
1931 parent_src,
1932 ref,
1933 false,
1934 call_ctx,
1935 );
1839 @"align" = ref_result.expr;1936 @"align" = ref_result.expr;
1840 extra_index += 1;1937 extra_index += 1;
1841 }1938 }
1842 var address_space: ?DocData.Expr = null;1939 var address_space: ?DocData.Expr = null;
1843 if (ptr.flags.has_addrspace) {1940 if (ptr.flags.has_addrspace) {
1844 const ref = @as(Zir.Inst.Ref, @enumFromInt(file.zir.extra[extra_index]));1941 const ref = @as(Zir.Inst.Ref, @enumFromInt(file.zir.extra[extra_index]));
1845 const ref_result = try self.walkRef(file, parent_scope, parent_src, ref, false);1942 const ref_result = try self.walkRef(
1943 file,
1944 parent_scope,
1945 parent_src,
1946 ref,
1947 false,
1948 call_ctx,
1949 );
1846 address_space = ref_result.expr;1950 address_space = ref_result.expr;
1847 extra_index += 1;1951 extra_index += 1;
1848 }1952 }
1849 var bit_start: ?DocData.Expr = null;1953 var bit_start: ?DocData.Expr = null;
1850 if (ptr.flags.has_bit_range) {1954 if (ptr.flags.has_bit_range) {
1851 const ref = @as(Zir.Inst.Ref, @enumFromInt(file.zir.extra[extra_index]));1955 const ref = @as(Zir.Inst.Ref, @enumFromInt(file.zir.extra[extra_index]));
1852 const ref_result = try self.walkRef(file, parent_scope, parent_src, ref, false);1956 const ref_result = try self.walkRef(
1957 file,
1958 parent_scope,
1959 parent_src,
1960 ref,
1961 false,
1962 call_ctx,
1963 );
1853 address_space = ref_result.expr;1964 address_space = ref_result.expr;
1854 extra_index += 1;1965 extra_index += 1;
1855 }1966 }
...@@ -1857,7 +1968,14 @@ fn walkInstruction(...@@ -1857,7 +1968,14 @@ fn walkInstruction(
1857 var host_size: ?DocData.Expr = null;1968 var host_size: ?DocData.Expr = null;
1858 if (ptr.flags.has_bit_range) {1969 if (ptr.flags.has_bit_range) {
1859 const ref = @as(Zir.Inst.Ref, @enumFromInt(file.zir.extra[extra_index]));1970 const ref = @as(Zir.Inst.Ref, @enumFromInt(file.zir.extra[extra_index]));
1860 const ref_result = try self.walkRef(file, parent_scope, parent_src, ref, false);1971 const ref_result = try self.walkRef(
1972 file,
1973 parent_scope,
1974 parent_src,
1975 ref,
1976 false,
1977 call_ctx,
1978 );
1861 host_size = ref_result.expr;1979 host_size = ref_result.expr;
1862 }1980 }
18631981
...@@ -1888,8 +2006,22 @@ fn walkInstruction(...@@ -1888,8 +2006,22 @@ fn walkInstruction(
1888 const pl_node = data[inst_index].pl_node;2006 const pl_node = data[inst_index].pl_node;
18892007
1890 const bin = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index).data;2008 const bin = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index).data;
1891 const len = try self.walkRef(file, parent_scope, parent_src, bin.lhs, false);2009 const len = try self.walkRef(
1892 const child = try self.walkRef(file, parent_scope, parent_src, bin.rhs, false);2010 file,
2011 parent_scope,
2012 parent_src,
2013 bin.lhs,
2014 false,
2015 call_ctx,
2016 );
2017 const child = try self.walkRef(
2018 file,
2019 parent_scope,
2020 parent_src,
2021 bin.rhs,
2022 false,
2023 call_ctx,
2024 );
18932025
1894 const type_slot_index = self.types.items.len;2026 const type_slot_index = self.types.items.len;
1895 try self.types.append(self.arena, .{2027 try self.types.append(self.arena, .{
...@@ -1907,9 +2039,30 @@ fn walkInstruction(...@@ -1907,9 +2039,30 @@ fn walkInstruction(
1907 .array_type_sentinel => {2039 .array_type_sentinel => {
1908 const pl_node = data[inst_index].pl_node;2040 const pl_node = data[inst_index].pl_node;
1909 const extra = file.zir.extraData(Zir.Inst.ArrayTypeSentinel, pl_node.payload_index);2041 const extra = file.zir.extraData(Zir.Inst.ArrayTypeSentinel, pl_node.payload_index);
1910 const len = try self.walkRef(file, parent_scope, parent_src, extra.data.len, false);2042 const len = try self.walkRef(
1911 const sentinel = try self.walkRef(file, parent_scope, parent_src, extra.data.sentinel, false);2043 file,
1912 const elem_type = try self.walkRef(file, parent_scope, parent_src, extra.data.elem_type, false);2044 parent_scope,
2045 parent_src,
2046 extra.data.len,
2047 false,
2048 call_ctx,
2049 );
2050 const sentinel = try self.walkRef(
2051 file,
2052 parent_scope,
2053 parent_src,
2054 extra.data.sentinel,
2055 false,
2056 call_ctx,
2057 );
2058 const elem_type = try self.walkRef(
2059 file,
2060 parent_scope,
2061 parent_src,
2062 extra.data.elem_type,
2063 false,
2064 call_ctx,
2065 );
19132066
1914 const type_slot_index = self.types.items.len;2067 const type_slot_index = self.types.items.len;
1915 try self.types.append(self.arena, .{2068 try self.types.append(self.arena, .{
...@@ -1931,10 +2084,24 @@ fn walkInstruction(...@@ -1931,10 +2084,24 @@ fn walkInstruction(
1931 const array_data = try self.arena.alloc(usize, operands.len - 1);2084 const array_data = try self.arena.alloc(usize, operands.len - 1);
19322085
1933 std.debug.assert(operands.len > 0);2086 std.debug.assert(operands.len > 0);
1934 var array_type = try self.walkRef(file, parent_scope, parent_src, operands[0], false);2087 var array_type = try self.walkRef(
2088 file,
2089 parent_scope,
2090 parent_src,
2091 operands[0],
2092 false,
2093 call_ctx,
2094 );
19352095
1936 for (operands[1..], 0..) |op, idx| {2096 for (operands[1..], 0..) |op, idx| {
1937 const wr = try self.walkRef(file, parent_scope, parent_src, op, false);2097 const wr = try self.walkRef(
2098 file,
2099 parent_scope,
2100 parent_src,
2101 op,
2102 false,
2103 call_ctx,
2104 );
1938 const expr_index = self.exprs.items.len;2105 const expr_index = self.exprs.items.len;
1939 try self.exprs.append(self.arena, wr.expr);2106 try self.exprs.append(self.arena, wr.expr);
1940 array_data[idx] = expr_index;2107 array_data[idx] = expr_index;
...@@ -1952,7 +2119,14 @@ fn walkInstruction(...@@ -1952,7 +2119,14 @@ fn walkInstruction(
1952 const array_data = try self.arena.alloc(usize, operands.len);2119 const array_data = try self.arena.alloc(usize, operands.len);
19532120
1954 for (operands, 0..) |op, idx| {2121 for (operands, 0..) |op, idx| {
1955 const wr = try self.walkRef(file, parent_scope, parent_src, op, false);2122 const wr = try self.walkRef(
2123 file,
2124 parent_scope,
2125 parent_src,
2126 op,
2127 false,
2128 call_ctx,
2129 );
1956 const expr_index = self.exprs.items.len;2130 const expr_index = self.exprs.items.len;
1957 try self.exprs.append(self.arena, wr.expr);2131 try self.exprs.append(self.arena, wr.expr);
1958 array_data[idx] = expr_index;2132 array_data[idx] = expr_index;
...@@ -1970,10 +2144,24 @@ fn walkInstruction(...@@ -1970,10 +2144,24 @@ fn walkInstruction(
1970 const array_data = try self.arena.alloc(usize, operands.len - 1);2144 const array_data = try self.arena.alloc(usize, operands.len - 1);
19712145
1972 std.debug.assert(operands.len > 0);2146 std.debug.assert(operands.len > 0);
1973 var array_type = try self.walkRef(file, parent_scope, parent_src, operands[0], false);2147 var array_type = try self.walkRef(
2148 file,
2149 parent_scope,
2150 parent_src,
2151 operands[0],
2152 false,
2153 call_ctx,
2154 );
19742155
1975 for (operands[1..], 0..) |op, idx| {2156 for (operands[1..], 0..) |op, idx| {
1976 const wr = try self.walkRef(file, parent_scope, parent_src, op, false);2157 const wr = try self.walkRef(
2158 file,
2159 parent_scope,
2160 parent_src,
2161 op,
2162 false,
2163 call_ctx,
2164 );
1977 const expr_index = self.exprs.items.len;2165 const expr_index = self.exprs.items.len;
1978 try self.exprs.append(self.arena, wr.expr);2166 try self.exprs.append(self.arena, wr.expr);
1979 array_data[idx] = expr_index;2167 array_data[idx] = expr_index;
...@@ -2002,7 +2190,14 @@ fn walkInstruction(...@@ -2002,7 +2190,14 @@ fn walkInstruction(
2002 const array_data = try self.arena.alloc(usize, operands.len);2190 const array_data = try self.arena.alloc(usize, operands.len);
20032191
2004 for (operands, 0..) |op, idx| {2192 for (operands, 0..) |op, idx| {
2005 const wr = try self.walkRef(file, parent_scope, parent_src, op, false);2193 const wr = try self.walkRef(
2194 file,
2195 parent_scope,
2196 parent_src,
2197 op,
2198 false,
2199 call_ctx,
2200 );
2006 const expr_index = self.exprs.items.len;2201 const expr_index = self.exprs.items.len;
2007 try self.exprs.append(self.arena, wr.expr);2202 try self.exprs.append(self.arena, wr.expr);
2008 array_data[idx] = expr_index;2203 array_data[idx] = expr_index;
...@@ -2041,6 +2236,7 @@ fn walkInstruction(...@@ -2041,6 +2236,7 @@ fn walkInstruction(
2041 parent_src,2236 parent_src,
2042 un_node.operand,2237 un_node.operand,
2043 need_type,2238 need_type,
2239 call_ctx,
2044 );2240 );
2045 switch (operand.expr) {2241 switch (operand.expr) {
2046 .int => |*int| int.negated = true,2242 .int => |*int| int.negated = true,
...@@ -2065,6 +2261,7 @@ fn walkInstruction(...@@ -2065,6 +2261,7 @@ fn walkInstruction(
2065 parent_src,2261 parent_src,
2066 un_node.operand,2262 un_node.operand,
2067 false,2263 false,
2264 call_ctx,
2068 );2265 );
2069 const operand_index = self.exprs.items.len;2266 const operand_index = self.exprs.items.len;
2070 try self.exprs.append(self.arena, operand.expr);2267 try self.exprs.append(self.arena, operand.expr);
...@@ -2083,6 +2280,7 @@ fn walkInstruction(...@@ -2083,6 +2280,7 @@ fn walkInstruction(
2083 parent_src,2280 parent_src,
2084 un_node.operand,2281 un_node.operand,
2085 need_type,2282 need_type,
2283 call_ctx,
2086 );2284 );
2087 const operand_index = self.exprs.items.len;2285 const operand_index = self.exprs.items.len;
2088 try self.exprs.append(self.arena, operand.expr);2286 try self.exprs.append(self.arena, operand.expr);
...@@ -2101,6 +2299,7 @@ fn walkInstruction(...@@ -2101,6 +2299,7 @@ fn walkInstruction(
2101 parent_src,2299 parent_src,
2102 un_node.operand,2300 un_node.operand,
2103 false,2301 false,
2302 call_ctx,
2104 );2303 );
2105 const operand_index = self.exprs.items.len;2304 const operand_index = self.exprs.items.len;
2106 try self.exprs.append(self.arena, operand.expr);2305 try self.exprs.append(self.arena, operand.expr);
...@@ -2115,7 +2314,14 @@ fn walkInstruction(...@@ -2115,7 +2314,14 @@ fn walkInstruction(
2115 const pl_node = data[inst_index].pl_node;2314 const pl_node = data[inst_index].pl_node;
2116 const extra = file.zir.extraData(Zir.Inst.SwitchBlock, pl_node.payload_index);2315 const extra = file.zir.extraData(Zir.Inst.SwitchBlock, pl_node.payload_index);
21172316
2118 const switch_cond = try self.walkRef(file, parent_scope, parent_src, extra.data.operand, false);2317 const switch_cond = try self.walkRef(
2318 file,
2319 parent_scope,
2320 parent_src,
2321 extra.data.operand,
2322 false,
2323 call_ctx,
2324 );
2119 const cond_index = self.exprs.items.len;2325 const cond_index = self.exprs.items.len;
2120 try self.exprs.append(self.arena, switch_cond.expr);2326 try self.exprs.append(self.arena, switch_cond.expr);
2121 _ = cond_index;2327 _ = cond_index;
...@@ -2162,6 +2368,7 @@ fn walkInstruction(...@@ -2162,6 +2368,7 @@ fn walkInstruction(
2162 parent_src,2368 parent_src,
2163 un_node.operand,2369 un_node.operand,
2164 need_type,2370 need_type,
2371 call_ctx,
2165 );2372 );
2166 const operand_index = self.exprs.items.len;2373 const operand_index = self.exprs.items.len;
2167 try self.exprs.append(self.arena, operand.expr);2374 try self.exprs.append(self.arena, operand.expr);
...@@ -2181,6 +2388,7 @@ fn walkInstruction(...@@ -2181,6 +2388,7 @@ fn walkInstruction(
2181 parent_src,2388 parent_src,
2182 data[body].@"break".operand,2389 data[body].@"break".operand,
2183 false,2390 false,
2391 call_ctx,
2184 );2392 );
21852393
2186 const operand_index = self.exprs.items.len;2394 const operand_index = self.exprs.items.len;
...@@ -2201,6 +2409,7 @@ fn walkInstruction(...@@ -2201,6 +2409,7 @@ fn walkInstruction(
2201 parent_src,2409 parent_src,
2202 un_node.operand,2410 un_node.operand,
2203 need_type,2411 need_type,
2412 call_ctx,
2204 );2413 );
22052414
2206 const operand_index = self.exprs.items.len;2415 const operand_index = self.exprs.items.len;
...@@ -2214,12 +2423,31 @@ fn walkInstruction(...@@ -2214,12 +2423,31 @@ fn walkInstruction(
2214 .as_node, .as_shift_operand => {2423 .as_node, .as_shift_operand => {
2215 const pl_node = data[inst_index].pl_node;2424 const pl_node = data[inst_index].pl_node;
2216 const extra = file.zir.extraData(Zir.Inst.As, pl_node.payload_index);2425 const extra = file.zir.extraData(Zir.Inst.As, pl_node.payload_index);
2426
2427 // Skip the as_node if the destination type is a call instruction
2428 if (Zir.refToIndex(extra.data.dest_type)) |dti| {
2429 var maybe_cc = call_ctx;
2430 while (maybe_cc) |cc| : (maybe_cc = cc.prev) {
2431 if (cc.inst == dti) {
2432 return try self.walkRef(
2433 file,
2434 parent_scope,
2435 parent_src,
2436 extra.data.operand,
2437 false,
2438 call_ctx,
2439 );
2440 }
2441 }
2442 }
2443
2217 const dest_type_walk = try self.walkRef(2444 const dest_type_walk = try self.walkRef(
2218 file,2445 file,
2219 parent_scope,2446 parent_scope,
2220 parent_src,2447 parent_src,
2221 extra.data.dest_type,2448 extra.data.dest_type,
2222 false,2449 false,
2450 call_ctx,
2223 );2451 );
22242452
2225 const operand = try self.walkRef(2453 const operand = try self.walkRef(
...@@ -2228,6 +2456,7 @@ fn walkInstruction(...@@ -2228,6 +2456,7 @@ fn walkInstruction(
2228 parent_src,2456 parent_src,
2229 extra.data.operand,2457 extra.data.operand,
2230 false,2458 false,
2459 call_ctx,
2231 );2460 );
22322461
2233 const operand_idx = self.exprs.items.len;2462 const operand_idx = self.exprs.items.len;
...@@ -2257,6 +2486,7 @@ fn walkInstruction(...@@ -2257,6 +2486,7 @@ fn walkInstruction(
2257 parent_src,2486 parent_src,
2258 un_node.operand,2487 un_node.operand,
2259 false,2488 false,
2489 call_ctx,
2260 );2490 );
22612491
2262 const operand_idx = self.types.items.len;2492 const operand_idx = self.types.items.len;
...@@ -2332,7 +2562,14 @@ fn walkInstruction(...@@ -2332,7 +2562,14 @@ fn walkInstruction(
2332 }2562 }
2333 }2563 }
23342564
2335 break :blk try self.walkRef(file, parent_scope, parent_src, lhs_ref, false);2565 break :blk try self.walkRef(
2566 file,
2567 parent_scope,
2568 parent_src,
2569 lhs_ref,
2570 false,
2571 call_ctx,
2572 );
2336 };2573 };
2337 try path.append(self.arena, wr.expr);2574 try path.append(self.arena, wr.expr);
23382575
...@@ -2400,6 +2637,7 @@ fn walkInstruction(...@@ -2400,6 +2637,7 @@ fn walkInstruction(
2400 return res;2637 return res;
2401 },2638 },
2402 need_type,2639 need_type,
2640 call_ctx,
2403 );2641 );
2404 },2642 },
2405 .break_inline => {2643 .break_inline => {
...@@ -2410,6 +2648,7 @@ fn walkInstruction(...@@ -2410,6 +2648,7 @@ fn walkInstruction(
2410 parent_src,2648 parent_src,
2411 @"break".operand,2649 @"break".operand,
2412 need_type,2650 need_type,
2651 call_ctx,
2413 );2652 );
2414 },2653 },
2415 .struct_init => {2654 .struct_init => {
...@@ -2448,6 +2687,7 @@ fn walkInstruction(...@@ -2448,6 +2687,7 @@ fn walkInstruction(
2448 field_src,2687 field_src,
2449 field_extra.data.container_type,2688 field_extra.data.container_type,
2450 false,2689 false,
2690 call_ctx,
2451 );2691 );
2452 type_ref = wr.expr;2692 type_ref = wr.expr;
2453 }2693 }
...@@ -2459,6 +2699,7 @@ fn walkInstruction(...@@ -2459,6 +2699,7 @@ fn walkInstruction(
2459 parent_src,2699 parent_src,
2460 init_extra.data.init,2700 init_extra.data.init,
2461 need_type,2701 need_type,
2702 call_ctx,
2462 );2703 );
2463 fv.* = .{ .name = field_name, .val = value };2704 fv.* = .{ .name = field_name, .val = value };
2464 }2705 }
...@@ -2477,6 +2718,7 @@ fn walkInstruction(...@@ -2477,6 +2718,7 @@ fn walkInstruction(
2477 parent_src,2718 parent_src,
2478 un_node.operand,2719 un_node.operand,
2479 false,2720 false,
2721 call_ctx,
2480 );2722 );
24812723
2482 return DocData.WalkResult{2724 return DocData.WalkResult{
...@@ -2503,6 +2745,7 @@ fn walkInstruction(...@@ -2503,6 +2745,7 @@ fn walkInstruction(
2503 parent_src,2745 parent_src,
2504 init_extra.data.init,2746 init_extra.data.init,
2505 need_type,2747 need_type,
2748 call_ctx,
2506 );2749 );
2507 fv.* = .{ .name = field_name, .val = value };2750 fv.* = .{ .name = field_name, .val = value };
2508 idx = init_extra.end;2751 idx = init_extra.end;
...@@ -2576,7 +2819,14 @@ fn walkInstruction(...@@ -2576,7 +2819,14 @@ fn walkInstruction(
2576 const pl_node = data[inst_index].pl_node;2819 const pl_node = data[inst_index].pl_node;
2577 const extra = file.zir.extraData(Zir.Inst.Call, pl_node.payload_index);2820 const extra = file.zir.extraData(Zir.Inst.Call, pl_node.payload_index);
25782821
2579 const callee = try self.walkRef(file, parent_scope, parent_src, extra.data.callee, need_type);2822 const callee = try self.walkRef(
2823 file,
2824 parent_scope,
2825 parent_src,
2826 extra.data.callee,
2827 need_type,
2828 call_ctx,
2829 );
25802830
2581 const args_len = extra.data.flags.args_len;2831 const args_len = extra.data.flags.args_len;
2582 var args = try self.arena.alloc(DocData.Expr, args_len);2832 var args = try self.arena.alloc(DocData.Expr, args_len);
...@@ -2591,7 +2841,17 @@ fn walkInstruction(...@@ -2591,7 +2841,17 @@ fn walkInstruction(
2591 // to show discrepancies between the types of provided2841 // to show discrepancies between the types of provided
2592 // arguments and the types declared in the function2842 // arguments and the types declared in the function
2593 // signature for its parameters.2843 // signature for its parameters.
2594 const wr = try self.walkRef(file, parent_scope, parent_src, ref, false);2844 const wr = try self.walkRef(
2845 file,
2846 parent_scope,
2847 parent_src,
2848 ref,
2849 false,
2850 &.{
2851 .inst = inst_index,
2852 .prev = call_ctx,
2853 },
2854 );
2595 args[i] = wr.expr;2855 args[i] = wr.expr;
2596 }2856 }
25972857
...@@ -2639,6 +2899,7 @@ fn walkInstruction(...@@ -2639,6 +2899,7 @@ fn walkInstruction(
2639 self_ast_node_index,2899 self_ast_node_index,
2640 type_slot_index,2900 type_slot_index,
2641 tags[inst_index] == .func_inferred,2901 tags[inst_index] == .func_inferred,
2902 call_ctx,
2642 );2903 );
26432904
2644 return result;2905 return result;
...@@ -2654,6 +2915,7 @@ fn walkInstruction(...@@ -2654,6 +2915,7 @@ fn walkInstruction(
2654 inst_index,2915 inst_index,
2655 self_ast_node_index,2916 self_ast_node_index,
2656 type_slot_index,2917 type_slot_index,
2918 call_ctx,
2657 );2919 );
26582920
2659 return result;2921 return result;
...@@ -2678,7 +2940,14 @@ fn walkInstruction(...@@ -2678,7 +2940,14 @@ fn walkInstruction(
26782940
2679 var array_type: ?DocData.Expr = null;2941 var array_type: ?DocData.Expr = null;
2680 for (args, 0..) |arg, idx| {2942 for (args, 0..) |arg, idx| {
2681 const wr = try self.walkRef(file, parent_scope, parent_src, arg, idx == 0);2943 const wr = try self.walkRef(
2944 file,
2945 parent_scope,
2946 parent_src,
2947 arg,
2948 idx == 0,
2949 call_ctx,
2950 );
2682 if (idx == 0) {2951 if (idx == 0) {
2683 array_type = wr.typeRef;2952 array_type = wr.typeRef;
2684 }2953 }
...@@ -2740,6 +3009,7 @@ fn walkInstruction(...@@ -2740,6 +3009,7 @@ fn walkInstruction(
2740 src_info,3009 src_info,
2741 &decl_indexes,3010 &decl_indexes,
2742 &priv_decl_indexes,3011 &priv_decl_indexes,
3012 call_ctx,
2743 );3013 );
27443014
2745 self.types.items[type_slot_index] = .{3015 self.types.items[type_slot_index] = .{
...@@ -2778,7 +3048,14 @@ fn walkInstruction(...@@ -2778,7 +3048,14 @@ fn walkInstruction(
2778 if (small.has_lib_name) extra_index += 1;3048 if (small.has_lib_name) extra_index += 1;
2779 if (small.has_align) extra_index += 1;3049 if (small.has_align) extra_index += 1;
27803050
2781 const var_type = try self.walkRef(file, parent_scope, parent_src, extra.data.var_type, need_type);3051 const var_type = try self.walkRef(
3052 file,
3053 parent_scope,
3054 parent_src,
3055 extra.data.var_type,
3056 need_type,
3057 call_ctx,
3058 );
27823059
2783 var value: DocData.WalkResult = .{3060 var value: DocData.WalkResult = .{
2784 .typeRef = var_type.expr,3061 .typeRef = var_type.expr,
...@@ -2787,7 +3064,14 @@ fn walkInstruction(...@@ -2787,7 +3064,14 @@ fn walkInstruction(
27873064
2788 if (small.has_init) {3065 if (small.has_init) {
2789 const var_init_ref = @as(Ref, @enumFromInt(file.zir.extra[extra_index]));3066 const var_init_ref = @as(Ref, @enumFromInt(file.zir.extra[extra_index]));
2790 const var_init = try self.walkRef(file, parent_scope, parent_src, var_init_ref, need_type);3067 const var_init = try self.walkRef(
3068 file,
3069 parent_scope,
3070 parent_src,
3071 var_init_ref,
3072 need_type,
3073 call_ctx,
3074 );
2791 value.expr = var_init.expr;3075 value.expr = var_init.expr;
2792 value.typeRef = var_init.typeRef;3076 value.typeRef = var_init.typeRef;
2793 }3077 }
...@@ -2853,6 +3137,7 @@ fn walkInstruction(...@@ -2853,6 +3137,7 @@ fn walkInstruction(
2853 src_info,3137 src_info,
2854 &decl_indexes,3138 &decl_indexes,
2855 &priv_decl_indexes,3139 &priv_decl_indexes,
3140 call_ctx,
2856 );3141 );
28573142
2858 // Analyze the tag once all decls have been analyzed3143 // Analyze the tag once all decls have been analyzed
...@@ -2862,6 +3147,7 @@ fn walkInstruction(...@@ -2862,6 +3147,7 @@ fn walkInstruction(
2862 parent_src,3147 parent_src,
2863 tt_ref,3148 tt_ref,
2864 false,3149 false,
3150 call_ctx,
2865 )).expr else null;3151 )).expr else null;
28663152
2867 // Fields3153 // Fields
...@@ -2883,6 +3169,7 @@ fn walkInstruction(...@@ -2883,6 +3169,7 @@ fn walkInstruction(
2883 &field_type_refs,3169 &field_type_refs,
2884 &field_name_indexes,3170 &field_name_indexes,
2885 extra_index,3171 extra_index,
3172 call_ctx,
2886 );3173 );
28873174
2888 self.ast_nodes.items[self_ast_node_index].fields = field_name_indexes.items;3175 self.ast_nodes.items[self_ast_node_index].fields = field_name_indexes.items;
...@@ -2948,7 +3235,14 @@ fn walkInstruction(...@@ -2948,7 +3235,14 @@ fn walkInstruction(
2948 const tag_type = file.zir.extra[extra_index];3235 const tag_type = file.zir.extra[extra_index];
2949 extra_index += 1;3236 extra_index += 1;
2950 const tag_ref = @as(Ref, @enumFromInt(tag_type));3237 const tag_ref = @as(Ref, @enumFromInt(tag_type));
2951 const wr = try self.walkRef(file, parent_scope, parent_src, tag_ref, false);3238 const wr = try self.walkRef(
3239 file,
3240 parent_scope,
3241 parent_src,
3242 tag_ref,
3243 false,
3244 call_ctx,
3245 );
2952 break :blk wr.expr;3246 break :blk wr.expr;
2953 } else null;3247 } else null;
29543248
...@@ -2974,6 +3268,7 @@ fn walkInstruction(...@@ -2974,6 +3268,7 @@ fn walkInstruction(
2974 src_info,3268 src_info,
2975 &decl_indexes,3269 &decl_indexes,
2976 &priv_decl_indexes,3270 &priv_decl_indexes,
3271 call_ctx,
2977 );3272 );
29783273
2979 // const body = file.zir.extra[extra_index..][0..body_len];3274 // const body = file.zir.extra[extra_index..][0..body_len];
...@@ -3005,7 +3300,14 @@ fn walkInstruction(...@@ -3005,7 +3300,14 @@ fn walkInstruction(
3005 const value_expr: ?DocData.Expr = if (has_value) blk: {3300 const value_expr: ?DocData.Expr = if (has_value) blk: {
3006 const value_ref = file.zir.extra[extra_index];3301 const value_ref = file.zir.extra[extra_index];
3007 extra_index += 1;3302 extra_index += 1;
3008 const value = try self.walkRef(file, &scope, src_info, @as(Ref, @enumFromInt(value_ref)), false);3303 const value = try self.walkRef(
3304 file,
3305 &scope,
3306 src_info,
3307 @as(Ref, @enumFromInt(value_ref)),
3308 false,
3309 call_ctx,
3310 );
3009 break :blk value.expr;3311 break :blk value.expr;
3010 } else null;3312 } else null;
3011 try field_values.append(self.arena, value_expr);3313 try field_values.append(self.arena, value_expr);
...@@ -3095,14 +3397,28 @@ fn walkInstruction(...@@ -3095,14 +3397,28 @@ fn walkInstruction(
3095 extra_index += 1; // backing_int_body_len3397 extra_index += 1; // backing_int_body_len
3096 if (backing_int_body_len == 0) {3398 if (backing_int_body_len == 0) {
3097 const backing_int_ref = @as(Ref, @enumFromInt(file.zir.extra[extra_index]));3399 const backing_int_ref = @as(Ref, @enumFromInt(file.zir.extra[extra_index]));
3098 const backing_int_res = try self.walkRef(file, &scope, src_info, backing_int_ref, true);3400 const backing_int_res = try self.walkRef(
3401 file,
3402 &scope,
3403 src_info,
3404 backing_int_ref,
3405 true,
3406 call_ctx,
3407 );
3099 backing_int = backing_int_res.expr;3408 backing_int = backing_int_res.expr;
3100 extra_index += 1; // backing_int_ref3409 extra_index += 1; // backing_int_ref
3101 } else {3410 } else {
3102 const backing_int_body = file.zir.extra[extra_index..][0..backing_int_body_len];3411 const backing_int_body = file.zir.extra[extra_index..][0..backing_int_body_len];
3103 const break_inst = backing_int_body[backing_int_body.len - 1];3412 const break_inst = backing_int_body[backing_int_body.len - 1];
3104 const operand = data[break_inst].@"break".operand;3413 const operand = data[break_inst].@"break".operand;
3105 const backing_int_res = try self.walkRef(file, &scope, src_info, operand, true);3414 const backing_int_res = try self.walkRef(
3415 file,
3416 &scope,
3417 src_info,
3418 operand,
3419 true,
3420 call_ctx,
3421 );
3106 backing_int = backing_int_res.expr;3422 backing_int = backing_int_res.expr;
3107 extra_index += backing_int_body_len; // backing_int_body_inst3423 extra_index += backing_int_body_len; // backing_int_body_inst
3108 }3424 }
...@@ -3123,6 +3439,7 @@ fn walkInstruction(...@@ -3123,6 +3439,7 @@ fn walkInstruction(
3123 src_info,3439 src_info,
3124 &decl_indexes,3440 &decl_indexes,
3125 &priv_decl_indexes,3441 &priv_decl_indexes,
3442 call_ctx,
3126 );3443 );
31273444
3128 var field_type_refs: std.ArrayListUnmanaged(DocData.Expr) = .{};3445 var field_type_refs: std.ArrayListUnmanaged(DocData.Expr) = .{};
...@@ -3138,6 +3455,7 @@ fn walkInstruction(...@@ -3138,6 +3455,7 @@ fn walkInstruction(
3138 &field_name_indexes,3455 &field_name_indexes,
3139 extra_index,3456 extra_index,
3140 small.is_tuple,3457 small.is_tuple,
3458 call_ctx,
3141 );3459 );
31423460
3143 self.ast_nodes.items[self_ast_node_index].fields = field_name_indexes.items;3461 self.ast_nodes.items[self_ast_node_index].fields = field_name_indexes.items;
...@@ -3194,7 +3512,14 @@ fn walkInstruction(...@@ -3194,7 +3512,14 @@ fn walkInstruction(
3194 const extra = file.zir.extraData(Zir.Inst.UnNode, extended.operand).data;3512 const extra = file.zir.extraData(Zir.Inst.UnNode, extended.operand).data;
3195 const bin_index = self.exprs.items.len;3513 const bin_index = self.exprs.items.len;
3196 try self.exprs.append(self.arena, .{ .builtin = .{ .param = 0 } });3514 try self.exprs.append(self.arena, .{ .builtin = .{ .param = 0 } });
3197 const param = try self.walkRef(file, parent_scope, parent_src, extra.operand, false);3515 const param = try self.walkRef(
3516 file,
3517 parent_scope,
3518 parent_src,
3519 extra.operand,
3520 false,
3521 call_ctx,
3522 );
31983523
3199 const param_index = self.exprs.items.len;3524 const param_index = self.exprs.items.len;
3200 try self.exprs.append(self.arena, param.expr);3525 try self.exprs.append(self.arena, param.expr);
...@@ -3213,7 +3538,14 @@ fn walkInstruction(...@@ -3213,7 +3538,14 @@ fn walkInstruction(
3213 const extra = file.zir.extraData(Zir.Inst.UnNode, extended.operand).data;3538 const extra = file.zir.extraData(Zir.Inst.UnNode, extended.operand).data;
3214 const bin_index = self.exprs.items.len;3539 const bin_index = self.exprs.items.len;
3215 try self.exprs.append(self.arena, .{ .builtin = .{ .param = 0 } });3540 try self.exprs.append(self.arena, .{ .builtin = .{ .param = 0 } });
3216 const param = try self.walkRef(file, parent_scope, parent_src, extra.operand, false);3541 const param = try self.walkRef(
3542 file,
3543 parent_scope,
3544 parent_src,
3545 extra.operand,
3546 false,
3547 call_ctx,
3548 );
32173549
3218 const param_index = self.exprs.items.len;3550 const param_index = self.exprs.items.len;
3219 try self.exprs.append(self.arena, param.expr);3551 try self.exprs.append(self.arena, param.expr);
...@@ -3241,6 +3573,7 @@ fn walkInstruction(...@@ -3241,6 +3573,7 @@ fn walkInstruction(
3241 parent_src,3573 parent_src,
3242 extra.ptr,3574 extra.ptr,
3243 false,3575 false,
3576 call_ctx,
3244 );3577 );
3245 try self.exprs.append(self.arena, ptr.expr);3578 try self.exprs.append(self.arena, ptr.expr);
32463579
...@@ -3251,6 +3584,7 @@ fn walkInstruction(...@@ -3251,6 +3584,7 @@ fn walkInstruction(
3251 parent_src,3584 parent_src,
3252 extra.expected_value,3585 extra.expected_value,
3253 false,3586 false,
3587 call_ctx,
3254 );3588 );
3255 try self.exprs.append(self.arena, expected_value.expr);3589 try self.exprs.append(self.arena, expected_value.expr);
32563590
...@@ -3261,6 +3595,7 @@ fn walkInstruction(...@@ -3261,6 +3595,7 @@ fn walkInstruction(
3261 parent_src,3595 parent_src,
3262 extra.new_value,3596 extra.new_value,
3263 false,3597 false,
3598 call_ctx,
3264 );3599 );
3265 try self.exprs.append(self.arena, new_value.expr);3600 try self.exprs.append(self.arena, new_value.expr);
32663601
...@@ -3271,6 +3606,7 @@ fn walkInstruction(...@@ -3271,6 +3606,7 @@ fn walkInstruction(
3271 parent_src,3606 parent_src,
3272 extra.success_order,3607 extra.success_order,
3273 false,3608 false,
3609 call_ctx,
3274 );3610 );
3275 try self.exprs.append(self.arena, success_order.expr);3611 try self.exprs.append(self.arena, success_order.expr);
32763612
...@@ -3281,6 +3617,7 @@ fn walkInstruction(...@@ -3281,6 +3617,7 @@ fn walkInstruction(
3281 parent_src,3617 parent_src,
3282 extra.failure_order,3618 extra.failure_order,
3283 false,3619 false,
3620 call_ctx,
3284 );3621 );
3285 try self.exprs.append(self.arena, failure_order.expr);3622 try self.exprs.append(self.arena, failure_order.expr);
32863623
...@@ -3319,6 +3656,7 @@ fn analyzeAllDecls(...@@ -3319,6 +3656,7 @@ fn analyzeAllDecls(
3319 parent_src: SrcLocInfo,3656 parent_src: SrcLocInfo,
3320 decl_indexes: *std.ArrayListUnmanaged(usize),3657 decl_indexes: *std.ArrayListUnmanaged(usize),
3321 priv_decl_indexes: *std.ArrayListUnmanaged(usize),3658 priv_decl_indexes: *std.ArrayListUnmanaged(usize),
3659 call_ctx: ?*const CallContext,
3322) AutodocErrors!usize {3660) AutodocErrors!usize {
3323 const first_decl_indexes_slot = decl_indexes.items.len;3661 const first_decl_indexes_slot = decl_indexes.items.len;
3324 const original_it = file.zir.declIterator(@as(u32, @intCast(parent_inst_index)));3662 const original_it = file.zir.declIterator(@as(u32, @intCast(parent_inst_index)));
...@@ -3358,6 +3696,7 @@ fn analyzeAllDecls(...@@ -3358,6 +3696,7 @@ fn analyzeAllDecls(
3358 decl_indexes,3696 decl_indexes,
3359 priv_decl_indexes,3697 priv_decl_indexes,
3360 d,3698 d,
3699 call_ctx,
3361 );3700 );
3362 },3701 },
3363 }3702 }
...@@ -3387,6 +3726,7 @@ fn analyzeAllDecls(...@@ -3387,6 +3726,7 @@ fn analyzeAllDecls(
3387 decl_indexes,3726 decl_indexes,
3388 priv_decl_indexes,3727 priv_decl_indexes,
3389 d,3728 d,
3729 call_ctx,
3390 );3730 );
3391 }3731 }
33923732
...@@ -3420,6 +3760,7 @@ fn analyzeDecl(...@@ -3420,6 +3760,7 @@ fn analyzeDecl(
3420 decl_indexes: *std.ArrayListUnmanaged(usize),3760 decl_indexes: *std.ArrayListUnmanaged(usize),
3421 priv_decl_indexes: *std.ArrayListUnmanaged(usize),3761 priv_decl_indexes: *std.ArrayListUnmanaged(usize),
3422 d: Zir.DeclIterator.Item,3762 d: Zir.DeclIterator.Item,
3763 call_ctx: ?*const CallContext,
3423) AutodocErrors!void {3764) AutodocErrors!void {
3424 const data = file.zir.instructions.items(.data);3765 const data = file.zir.instructions.items(.data);
3425 const is_pub = @as(u1, @truncate(d.flags >> 0)) != 0;3766 const is_pub = @as(u1, @truncate(d.flags >> 0)) != 0;
...@@ -3497,7 +3838,14 @@ fn analyzeDecl(...@@ -3497,7 +3838,14 @@ fn analyzeDecl(
3497 break :idx idx;3838 break :idx idx;
3498 };3839 };
34993840
3500 const walk_result = try self.walkInstruction(file, scope, decl_src, value_index, true);3841 const walk_result = try self.walkInstruction(
3842 file,
3843 scope,
3844 decl_src,
3845 value_index,
3846 true,
3847 call_ctx,
3848 );
35013849
3502 const kind: []const u8 = if (try self.declIsVar(file, value_pl_node.src_node, parent_src)) "var" else "const";3850 const kind: []const u8 = if (try self.declIsVar(file, value_pl_node.src_node, parent_src)) "var" else "const";
35033851
...@@ -3545,6 +3893,7 @@ fn analyzeUsingnamespaceDecl(...@@ -3545,6 +3893,7 @@ fn analyzeUsingnamespaceDecl(
3545 decl_indexes: *std.ArrayListUnmanaged(usize),3893 decl_indexes: *std.ArrayListUnmanaged(usize),
3546 priv_decl_indexes: *std.ArrayListUnmanaged(usize),3894 priv_decl_indexes: *std.ArrayListUnmanaged(usize),
3547 d: Zir.DeclIterator.Item,3895 d: Zir.DeclIterator.Item,
3896 call_ctx: ?*const CallContext,
3548) AutodocErrors!void {3897) AutodocErrors!void {
3549 const data = file.zir.instructions.items(.data);3898 const data = file.zir.instructions.items(.data);
35503899
...@@ -3574,7 +3923,14 @@ fn analyzeUsingnamespaceDecl(...@@ -3574,7 +3923,14 @@ fn analyzeUsingnamespaceDecl(
3574 break :idx idx;3923 break :idx idx;
3575 };3924 };
35763925
3577 const walk_result = try self.walkInstruction(file, scope, decl_src, value_index, true);3926 const walk_result = try self.walkInstruction(
3927 file,
3928 scope,
3929 decl_src,
3930 value_index,
3931 true,
3932 call_ctx,
3933 );
35783934
3579 const decl_slot_index = self.decls.items.len;3935 const decl_slot_index = self.decls.items.len;
3580 try self.decls.append(self.arena, .{3936 try self.decls.append(self.arena, .{
...@@ -4192,6 +4548,7 @@ fn analyzeFancyFunction(...@@ -4192,6 +4548,7 @@ fn analyzeFancyFunction(
4192 inst_index: usize,4548 inst_index: usize,
4193 self_ast_node_index: usize,4549 self_ast_node_index: usize,
4194 type_slot_index: usize,4550 type_slot_index: usize,
4551 call_ctx: ?*const CallContext,
4195) AutodocErrors!DocData.WalkResult {4552) AutodocErrors!DocData.WalkResult {
4196 const tags = file.zir.instructions.items(.tag);4553 const tags = file.zir.instructions.items(.tag);
4197 const data = file.zir.instructions.items(.data);4554 const data = file.zir.instructions.items(.data);
...@@ -4253,7 +4610,14 @@ fn analyzeFancyFunction(...@@ -4253,7 +4610,14 @@ fn analyzeFancyFunction(
42534610
4254 const break_index = file.zir.extra[extra.end..][extra.data.body_len - 1];4611 const break_index = file.zir.extra[extra.end..][extra.data.body_len - 1];
4255 const break_operand = data[break_index].@"break".operand;4612 const break_operand = data[break_index].@"break".operand;
4256 const param_type_ref = try self.walkRef(file, scope, parent_src, break_operand, false);4613 const param_type_ref = try self.walkRef(
4614 file,
4615 scope,
4616 parent_src,
4617 break_operand,
4618 false,
4619 call_ctx,
4620 );
42574621
4258 param_type_refs.appendAssumeCapacity(param_type_ref.expr);4622 param_type_refs.appendAssumeCapacity(param_type_ref.expr);
4259 },4623 },
...@@ -4277,7 +4641,14 @@ fn analyzeFancyFunction(...@@ -4277,7 +4641,14 @@ fn analyzeFancyFunction(
4277 if (extra.data.bits.has_align_ref) {4641 if (extra.data.bits.has_align_ref) {
4278 const align_ref = @as(Zir.Inst.Ref, @enumFromInt(file.zir.extra[extra_index]));4642 const align_ref = @as(Zir.Inst.Ref, @enumFromInt(file.zir.extra[extra_index]));
4279 align_index = self.exprs.items.len;4643 align_index = self.exprs.items.len;
4280 _ = try self.walkRef(file, scope, parent_src, align_ref, false);4644 _ = try self.walkRef(
4645 file,
4646 scope,
4647 parent_src,
4648 align_ref,
4649 false,
4650 call_ctx,
4651 );
4281 extra_index += 1;4652 extra_index += 1;
4282 } else if (extra.data.bits.has_align_body) {4653 } else if (extra.data.bits.has_align_body) {
4283 const align_body_len = file.zir.extra[extra_index];4654 const align_body_len = file.zir.extra[extra_index];
...@@ -4294,7 +4665,14 @@ fn analyzeFancyFunction(...@@ -4294,7 +4665,14 @@ fn analyzeFancyFunction(
4294 if (extra.data.bits.has_addrspace_ref) {4665 if (extra.data.bits.has_addrspace_ref) {
4295 const addrspace_ref = @as(Zir.Inst.Ref, @enumFromInt(file.zir.extra[extra_index]));4666 const addrspace_ref = @as(Zir.Inst.Ref, @enumFromInt(file.zir.extra[extra_index]));
4296 addrspace_index = self.exprs.items.len;4667 addrspace_index = self.exprs.items.len;
4297 _ = try self.walkRef(file, scope, parent_src, addrspace_ref, false);4668 _ = try self.walkRef(
4669 file,
4670 scope,
4671 parent_src,
4672 addrspace_ref,
4673 false,
4674 call_ctx,
4675 );
4298 extra_index += 1;4676 extra_index += 1;
4299 } else if (extra.data.bits.has_addrspace_body) {4677 } else if (extra.data.bits.has_addrspace_body) {
4300 const addrspace_body_len = file.zir.extra[extra_index];4678 const addrspace_body_len = file.zir.extra[extra_index];
...@@ -4311,7 +4689,14 @@ fn analyzeFancyFunction(...@@ -4311,7 +4689,14 @@ fn analyzeFancyFunction(
4311 if (extra.data.bits.has_section_ref) {4689 if (extra.data.bits.has_section_ref) {
4312 const section_ref = @as(Zir.Inst.Ref, @enumFromInt(file.zir.extra[extra_index]));4690 const section_ref = @as(Zir.Inst.Ref, @enumFromInt(file.zir.extra[extra_index]));
4313 section_index = self.exprs.items.len;4691 section_index = self.exprs.items.len;
4314 _ = try self.walkRef(file, scope, parent_src, section_ref, false);4692 _ = try self.walkRef(
4693 file,
4694 scope,
4695 parent_src,
4696 section_ref,
4697 false,
4698 call_ctx,
4699 );
4315 extra_index += 1;4700 extra_index += 1;
4316 } else if (extra.data.bits.has_section_body) {4701 } else if (extra.data.bits.has_section_body) {
4317 const section_body_len = file.zir.extra[extra_index];4702 const section_body_len = file.zir.extra[extra_index];
...@@ -4327,7 +4712,14 @@ fn analyzeFancyFunction(...@@ -4327,7 +4712,14 @@ fn analyzeFancyFunction(
4327 var cc_index: ?usize = null;4712 var cc_index: ?usize = null;
4328 if (extra.data.bits.has_cc_ref and !extra.data.bits.has_cc_body) {4713 if (extra.data.bits.has_cc_ref and !extra.data.bits.has_cc_body) {
4329 const cc_ref = @as(Zir.Inst.Ref, @enumFromInt(file.zir.extra[extra_index]));4714 const cc_ref = @as(Zir.Inst.Ref, @enumFromInt(file.zir.extra[extra_index]));
4330 const cc_expr = try self.walkRef(file, scope, parent_src, cc_ref, false);4715 const cc_expr = try self.walkRef(
4716 file,
4717 scope,
4718 parent_src,
4719 cc_ref,
4720 false,
4721 call_ctx,
4722 );
43314723
4332 cc_index = self.exprs.items.len;4724 cc_index = self.exprs.items.len;
4333 try self.exprs.append(self.arena, cc_expr.expr);4725 try self.exprs.append(self.arena, cc_expr.expr);
...@@ -4341,7 +4733,14 @@ fn analyzeFancyFunction(...@@ -4341,7 +4733,14 @@ fn analyzeFancyFunction(
4341 // We assume the body ends with a break_inline4733 // We assume the body ends with a break_inline
4342 const break_index = cc_body[cc_body.len - 1];4734 const break_index = cc_body[cc_body.len - 1];
4343 const break_operand = data[break_index].@"break".operand;4735 const break_operand = data[break_index].@"break".operand;
4344 const cc_expr = try self.walkRef(file, scope, parent_src, break_operand, false);4736 const cc_expr = try self.walkRef(
4737 file,
4738 scope,
4739 parent_src,
4740 break_operand,
4741 false,
4742 call_ctx,
4743 );
43454744
4346 cc_index = self.exprs.items.len;4745 cc_index = self.exprs.items.len;
4347 try self.exprs.append(self.arena, cc_expr.expr);4746 try self.exprs.append(self.arena, cc_expr.expr);
...@@ -4357,14 +4756,28 @@ fn analyzeFancyFunction(...@@ -4357,14 +4756,28 @@ fn analyzeFancyFunction(
4357 .none => DocData.Expr{ .void = .{} },4756 .none => DocData.Expr{ .void = .{} },
4358 else => blk: {4757 else => blk: {
4359 const ref = fn_info.ret_ty_ref;4758 const ref = fn_info.ret_ty_ref;
4360 const wr = try self.walkRef(file, scope, parent_src, ref, false);4759 const wr = try self.walkRef(
4760 file,
4761 scope,
4762 parent_src,
4763 ref,
4764 false,
4765 call_ctx,
4766 );
4361 break :blk wr.expr;4767 break :blk wr.expr;
4362 },4768 },
4363 },4769 },
4364 else => blk: {4770 else => blk: {
4365 const last_instr_index = fn_info.ret_ty_body[fn_info.ret_ty_body.len - 1];4771 const last_instr_index = fn_info.ret_ty_body[fn_info.ret_ty_body.len - 1];
4366 const break_operand = data[last_instr_index].@"break".operand;4772 const break_operand = data[last_instr_index].@"break".operand;
4367 const wr = try self.walkRef(file, scope, parent_src, break_operand, false);4773 const wr = try self.walkRef(
4774 file,
4775 scope,
4776 parent_src,
4777 break_operand,
4778 false,
4779 call_ctx,
4780 );
4368 break :blk wr.expr;4781 break :blk wr.expr;
4369 },4782 },
4370 };4783 };
...@@ -4381,6 +4794,7 @@ fn analyzeFancyFunction(...@@ -4381,6 +4794,7 @@ fn analyzeFancyFunction(
4381 scope,4794 scope,
4382 parent_src,4795 parent_src,
4383 fn_info.body[0],4796 fn_info.body[0],
4797 call_ctx,
4384 );4798 );
4385 } else {4799 } else {
4386 break :blk null;4800 break :blk null;
...@@ -4426,6 +4840,7 @@ fn analyzeFunction(...@@ -4426,6 +4840,7 @@ fn analyzeFunction(
4426 self_ast_node_index: usize,4840 self_ast_node_index: usize,
4427 type_slot_index: usize,4841 type_slot_index: usize,
4428 ret_is_inferred_error_set: bool,4842 ret_is_inferred_error_set: bool,
4843 call_ctx: ?*const CallContext,
4429) AutodocErrors!DocData.WalkResult {4844) AutodocErrors!DocData.WalkResult {
4430 const tags = file.zir.instructions.items(.tag);4845 const tags = file.zir.instructions.items(.tag);
4431 const data = file.zir.instructions.items(.data);4846 const data = file.zir.instructions.items(.data);
...@@ -4487,7 +4902,14 @@ fn analyzeFunction(...@@ -4487,7 +4902,14 @@ fn analyzeFunction(
44874902
4488 const break_index = file.zir.extra[extra.end..][extra.data.body_len - 1];4903 const break_index = file.zir.extra[extra.end..][extra.data.body_len - 1];
4489 const break_operand = data[break_index].@"break".operand;4904 const break_operand = data[break_index].@"break".operand;
4490 const param_type_ref = try self.walkRef(file, scope, parent_src, break_operand, false);4905 const param_type_ref = try self.walkRef(
4906 file,
4907 scope,
4908 parent_src,
4909 break_operand,
4910 false,
4911 call_ctx,
4912 );
44914913
4492 param_type_refs.appendAssumeCapacity(param_type_ref.expr);4914 param_type_refs.appendAssumeCapacity(param_type_ref.expr);
4493 },4915 },
...@@ -4500,14 +4922,28 @@ fn analyzeFunction(...@@ -4500,14 +4922,28 @@ fn analyzeFunction(
4500 .none => DocData.Expr{ .void = .{} },4922 .none => DocData.Expr{ .void = .{} },
4501 else => blk: {4923 else => blk: {
4502 const ref = fn_info.ret_ty_ref;4924 const ref = fn_info.ret_ty_ref;
4503 const wr = try self.walkRef(file, scope, parent_src, ref, false);4925 const wr = try self.walkRef(
4926 file,
4927 scope,
4928 parent_src,
4929 ref,
4930 false,
4931 call_ctx,
4932 );
4504 break :blk wr.expr;4933 break :blk wr.expr;
4505 },4934 },
4506 },4935 },
4507 else => blk: {4936 else => blk: {
4508 const last_instr_index = fn_info.ret_ty_body[fn_info.ret_ty_body.len - 1];4937 const last_instr_index = fn_info.ret_ty_body[fn_info.ret_ty_body.len - 1];
4509 const break_operand = data[last_instr_index].@"break".operand;4938 const break_operand = data[last_instr_index].@"break".operand;
4510 const wr = try self.walkRef(file, scope, parent_src, break_operand, false);4939 const wr = try self.walkRef(
4940 file,
4941 scope,
4942 parent_src,
4943 break_operand,
4944 false,
4945 call_ctx,
4946 );
4511 break :blk wr.expr;4947 break :blk wr.expr;
4512 },4948 },
4513 };4949 };
...@@ -4524,6 +4960,7 @@ fn analyzeFunction(...@@ -4524,6 +4960,7 @@ fn analyzeFunction(
4524 scope,4960 scope,
4525 parent_src,4961 parent_src,
4526 fn_info.body[0],4962 fn_info.body[0],
4963 call_ctx,
4527 );4964 );
4528 } else {4965 } else {
4529 break :blk null;4966 break :blk null;
...@@ -4570,6 +5007,7 @@ fn getGenericReturnType(...@@ -4570,6 +5007,7 @@ fn getGenericReturnType(
4570 scope: *Scope,5007 scope: *Scope,
4571 parent_src: SrcLocInfo, // function decl line5008 parent_src: SrcLocInfo, // function decl line
4572 body_main_block: usize,5009 body_main_block: usize,
5010 call_ctx: ?*const CallContext,
4573) !DocData.Expr {5011) !DocData.Expr {
4574 const tags = file.zir.instructions.items(.tag);5012 const tags = file.zir.instructions.items(.tag);
4575 const data = file.zir.instructions.items(.data);5013 const data = file.zir.instructions.items(.data);
...@@ -4581,7 +5019,14 @@ fn getGenericReturnType(...@@ -4581,7 +5019,14 @@ fn getGenericReturnType(
4581 const maybe_ret_node = file.zir.extra[extra.end..][extra.data.body_len - 4];5019 const maybe_ret_node = file.zir.extra[extra.end..][extra.data.body_len - 4];
4582 switch (tags[maybe_ret_node]) {5020 switch (tags[maybe_ret_node]) {
4583 .ret_node, .ret_load => {5021 .ret_node, .ret_load => {
4584 const wr = try self.walkInstruction(file, scope, parent_src, maybe_ret_node, false);5022 const wr = try self.walkInstruction(
5023 file,
5024 scope,
5025 parent_src,
5026 maybe_ret_node,
5027 false,
5028 call_ctx,
5029 );
4585 return wr.expr;5030 return wr.expr;
4586 },5031 },
4587 else => {5032 else => {
...@@ -4599,6 +5044,7 @@ fn collectUnionFieldInfo(...@@ -4599,6 +5044,7 @@ fn collectUnionFieldInfo(
4599 field_type_refs: *std.ArrayListUnmanaged(DocData.Expr),5044 field_type_refs: *std.ArrayListUnmanaged(DocData.Expr),
4600 field_name_indexes: *std.ArrayListUnmanaged(usize),5045 field_name_indexes: *std.ArrayListUnmanaged(usize),
4601 ei: usize,5046 ei: usize,
5047 call_ctx: ?*const CallContext,
4602) !void {5048) !void {
4603 if (fields_len == 0) return;5049 if (fields_len == 0) return;
4604 var extra_index = ei;5050 var extra_index = ei;
...@@ -4641,7 +5087,14 @@ fn collectUnionFieldInfo(...@@ -4641,7 +5087,14 @@ fn collectUnionFieldInfo(
46415087
4642 // type5088 // type
4643 {5089 {
4644 const walk_result = try self.walkRef(file, scope, parent_src, field_type, false);5090 const walk_result = try self.walkRef(
5091 file,
5092 scope,
5093 parent_src,
5094 field_type,
5095 false,
5096 call_ctx,
5097 );
4645 try field_type_refs.append(self.arena, walk_result.expr);5098 try field_type_refs.append(self.arena, walk_result.expr);
4646 }5099 }
46475100
...@@ -4671,6 +5124,7 @@ fn collectStructFieldInfo(...@@ -4671,6 +5124,7 @@ fn collectStructFieldInfo(
4671 field_name_indexes: *std.ArrayListUnmanaged(usize),5124 field_name_indexes: *std.ArrayListUnmanaged(usize),
4672 ei: usize,5125 ei: usize,
4673 is_tuple: bool,5126 is_tuple: bool,
5127 call_ctx: ?*const CallContext,
4674) !void {5128) !void {
4675 if (fields_len == 0) return;5129 if (fields_len == 0) return;
4676 var extra_index = ei;5130 var extra_index = ei;
...@@ -4744,7 +5198,14 @@ fn collectStructFieldInfo(...@@ -4744,7 +5198,14 @@ fn collectStructFieldInfo(
4744 for (fields) |field| {5198 for (fields) |field| {
4745 const type_expr = expr: {5199 const type_expr = expr: {
4746 if (field.type_ref != .none) {5200 if (field.type_ref != .none) {
4747 const walk_result = try self.walkRef(file, scope, parent_src, field.type_ref, false);5201 const walk_result = try self.walkRef(
5202 file,
5203 scope,
5204 parent_src,
5205 field.type_ref,
5206 false,
5207 call_ctx,
5208 );
4748 break :expr walk_result.expr;5209 break :expr walk_result.expr;
4749 }5210 }
47505211
...@@ -4760,7 +5221,14 @@ fn collectStructFieldInfo(...@@ -4760,7 +5221,14 @@ fn collectStructFieldInfo(
4760 .col = 0,5221 .col = 0,
4761 .fields = null, // walkInstruction will fill `fields` if necessary5222 .fields = null, // walkInstruction will fill `fields` if necessary
4762 });5223 });
4763 const walk_result = try self.walkRef(file, scope, parent_src, operand, false);5224 const walk_result = try self.walkRef(
5225 file,
5226 scope,
5227 parent_src,
5228 operand,
5229 false,
5230 call_ctx,
5231 );
4764 break :expr walk_result.expr;5232 break :expr walk_result.expr;
4765 };5233 };
47665234
...@@ -4776,7 +5244,14 @@ fn collectStructFieldInfo(...@@ -4776,7 +5244,14 @@ fn collectStructFieldInfo(
47765244
4777 const break_inst = body[body.len - 1];5245 const break_inst = body[body.len - 1];
4778 const operand = data[break_inst].@"break".operand;5246 const operand = data[break_inst].@"break".operand;
4779 const walk_result = try self.walkRef(file, scope, parent_src, operand, false);5247 const walk_result = try self.walkRef(
5248 file,
5249 scope,
5250 parent_src,
5251 operand,
5252 false,
5253 call_ctx,
5254 );
4780 break :def walk_result.expr;5255 break :def walk_result.expr;
4781 };5256 };
47825257
...@@ -4812,6 +5287,7 @@ fn walkRef(...@@ -4812,6 +5287,7 @@ fn walkRef(
4812 parent_src: SrcLocInfo,5287 parent_src: SrcLocInfo,
4813 ref: Ref,5288 ref: Ref,
4814 need_type: bool, // true when the caller needs also a typeRef for the return value5289 need_type: bool, // true when the caller needs also a typeRef for the return value
5290 call_ctx: ?*const CallContext,
4815) AutodocErrors!DocData.WalkResult {5291) AutodocErrors!DocData.WalkResult {
4816 if (ref == .none) {5292 if (ref == .none) {
4817 return .{ .expr = .{ .comptimeExpr = 0 } };5293 return .{ .expr = .{ .comptimeExpr = 0 } };
...@@ -4824,7 +5300,14 @@ fn walkRef(...@@ -4824,7 +5300,14 @@ fn walkRef(
4824 .expr = .{ .type = @intFromEnum(ref) },5300 .expr = .{ .type = @intFromEnum(ref) },
4825 };5301 };
4826 } else if (Zir.refToIndex(ref)) |zir_index| {5302 } else if (Zir.refToIndex(ref)) |zir_index| {
4827 return self.walkInstruction(file, parent_scope, parent_src, zir_index, need_type);5303 return self.walkInstruction(
5304 file,
5305 parent_scope,
5306 parent_src,
5307 zir_index,
5308 need_type,
5309 call_ctx,
5310 );
4828 } else {5311 } else {
4829 switch (ref) {5312 switch (ref) {
4830 else => {5313 else => {