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 {
328328 });
329329 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
333340 if (self.ref_paths_pending_on_decls.count() > 0) {
334341 @panic("some decl paths were never fully analized (pending on decls)");
......@@ -979,6 +986,15 @@ const AutodocErrors = error{
979986 UnexpectedEndOfFile,
980987} || 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
982998/// Called when we need to analyze a Zir instruction.
983999/// For example it gets called by `generateZirData` on instruction 0,
9841000/// which represents the top-level struct corresponding to the root file.
......@@ -994,6 +1010,7 @@ fn walkInstruction(
9941010 parent_src: SrcLocInfo,
9951011 inst_index: usize,
9961012 need_type: bool, // true if the caller needs us to provide also a typeRef
1013 call_ctx: ?*const CallContext,
9971014) AutodocErrors!DocData.WalkResult {
9981015 const tags = file.zir.instructions.items(.tag);
9991016 const data = file.zir.instructions.items(.data);
......@@ -1082,6 +1099,7 @@ fn walkInstruction(
10821099 .{},
10831100 Zir.main_struct_inst,
10841101 false,
1102 call_ctx,
10851103 );
10861104 }
10871105
......@@ -1113,6 +1131,7 @@ fn walkInstruction(
11131131 .{},
11141132 Zir.main_struct_inst,
11151133 need_type,
1134 call_ctx,
11161135 );
11171136 },
11181137 .ret_type => {
......@@ -1123,7 +1142,14 @@ fn walkInstruction(
11231142 },
11241143 .ret_node => {
11251144 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 );
11271153 },
11281154 .ret_load => {
11291155 const un_node = data[inst_index].un_node;
......@@ -1154,7 +1180,14 @@ fn walkInstruction(
11541180 }
11551181
11561182 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 );
11581191 }
11591192
11601193 return DocData.WalkResult{
......@@ -1163,11 +1196,25 @@ fn walkInstruction(
11631196 },
11641197 .closure_get => {
11651198 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 );
11671207 },
11681208 .closure_capture => {
11691209 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 );
11711218 },
11721219 .str => {
11731220 const str = data[inst_index].str.get(file.zir);
......@@ -1214,6 +1261,7 @@ fn walkInstruction(
12141261 parent_src,
12151262 un_node.operand,
12161263 false,
1264 call_ctx,
12171265 );
12181266
12191267 const operand_index = self.exprs.items.len;
......@@ -1284,6 +1332,7 @@ fn walkInstruction(
12841332 parent_src,
12851333 extra.data.lhs,
12861334 false,
1335 call_ctx,
12871336 );
12881337 var start: DocData.WalkResult = try self.walkRef(
12891338 file,
......@@ -1291,6 +1340,7 @@ fn walkInstruction(
12911340 parent_src,
12921341 extra.data.start,
12931342 false,
1343 call_ctx,
12941344 );
12951345
12961346 const lhs_index = self.exprs.items.len;
......@@ -1317,6 +1367,7 @@ fn walkInstruction(
13171367 parent_src,
13181368 extra.data.lhs,
13191369 false,
1370 call_ctx,
13201371 );
13211372 var start: DocData.WalkResult = try self.walkRef(
13221373 file,
......@@ -1324,6 +1375,7 @@ fn walkInstruction(
13241375 parent_src,
13251376 extra.data.start,
13261377 false,
1378 call_ctx,
13271379 );
13281380 var end: DocData.WalkResult = try self.walkRef(
13291381 file,
......@@ -1331,6 +1383,7 @@ fn walkInstruction(
13311383 parent_src,
13321384 extra.data.end,
13331385 false,
1386 call_ctx,
13341387 );
13351388
13361389 const lhs_index = self.exprs.items.len;
......@@ -1359,6 +1412,7 @@ fn walkInstruction(
13591412 parent_src,
13601413 extra.data.lhs,
13611414 false,
1415 call_ctx,
13621416 );
13631417 var start: DocData.WalkResult = try self.walkRef(
13641418 file,
......@@ -1366,6 +1420,7 @@ fn walkInstruction(
13661420 parent_src,
13671421 extra.data.start,
13681422 false,
1423 call_ctx,
13691424 );
13701425 var end: DocData.WalkResult = try self.walkRef(
13711426 file,
......@@ -1373,6 +1428,7 @@ fn walkInstruction(
13731428 parent_src,
13741429 extra.data.end,
13751430 false,
1431 call_ctx,
13761432 );
13771433 var sentinel: DocData.WalkResult = try self.walkRef(
13781434 file,
......@@ -1380,6 +1436,7 @@ fn walkInstruction(
13801436 parent_src,
13811437 extra.data.sentinel,
13821438 false,
1439 call_ctx,
13831440 );
13841441
13851442 const lhs_index = self.exprs.items.len;
......@@ -1410,6 +1467,7 @@ fn walkInstruction(
14101467 parent_src,
14111468 extra.data.lhs,
14121469 false,
1470 call_ctx,
14131471 );
14141472 var start: DocData.WalkResult = try self.walkRef(
14151473 file,
......@@ -1417,6 +1475,7 @@ fn walkInstruction(
14171475 parent_src,
14181476 extra.data.start,
14191477 false,
1478 call_ctx,
14201479 );
14211480 var len: DocData.WalkResult = try self.walkRef(
14221481 file,
......@@ -1424,6 +1483,7 @@ fn walkInstruction(
14241483 parent_src,
14251484 extra.data.len,
14261485 false,
1486 call_ctx,
14271487 );
14281488 var sentinel_opt: ?DocData.WalkResult = if (extra.data.sentinel != .none)
14291489 try self.walkRef(
......@@ -1432,6 +1492,7 @@ fn walkInstruction(
14321492 parent_src,
14331493 extra.data.sentinel,
14341494 false,
1495 call_ctx,
14351496 )
14361497 else
14371498 null;
......@@ -1492,6 +1553,7 @@ fn walkInstruction(
14921553 parent_src,
14931554 extra.data.lhs,
14941555 false,
1556 call_ctx,
14951557 );
14961558 var rhs: DocData.WalkResult = try self.walkRef(
14971559 file,
......@@ -1499,6 +1561,7 @@ fn walkInstruction(
14991561 parent_src,
15001562 extra.data.rhs,
15011563 false,
1564 call_ctx,
15021565 );
15031566
15041567 const lhs_index = self.exprs.items.len;
......@@ -1536,6 +1599,7 @@ fn walkInstruction(
15361599 parent_src,
15371600 extra.data.lhs,
15381601 false,
1602 call_ctx,
15391603 );
15401604 var rhs: DocData.WalkResult = try self.walkRef(
15411605 file,
......@@ -1543,6 +1607,7 @@ fn walkInstruction(
15431607 parent_src,
15441608 extra.data.rhs,
15451609 false,
1610 call_ctx,
15461611 );
15471612
15481613 const lhs_index = self.exprs.items.len;
......@@ -1599,7 +1664,14 @@ fn walkInstruction(
15991664 const un_node = data[inst_index].un_node;
16001665 const bin_index = self.exprs.items.len;
16011666 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
16041676 const param_index = self.exprs.items.len;
16051677 try self.exprs.append(self.arena, param.expr);
......@@ -1623,6 +1695,7 @@ fn walkInstruction(
16231695 parent_src,
16241696 bool_br.lhs,
16251697 false,
1698 call_ctx,
16261699 );
16271700 const lhs_index = self.exprs.items.len;
16281701 try self.exprs.append(self.arena, lhs.expr);
......@@ -1634,6 +1707,7 @@ fn walkInstruction(
16341707 parent_src,
16351708 file.zir.extra[extra.end..][extra.data.body_len - 1],
16361709 false,
1710 call_ctx,
16371711 );
16381712 const rhs_index = self.exprs.items.len;
16391713 try self.exprs.append(self.arena, rhs.expr);
......@@ -1656,6 +1730,7 @@ fn walkInstruction(
16561730 parent_src,
16571731 extra.data.rhs,
16581732 false,
1733 call_ctx,
16591734 );
16601735
16611736 const bin_index = self.exprs.items.len;
......@@ -1670,6 +1745,7 @@ fn walkInstruction(
16701745 parent_src,
16711746 extra.data.lhs,
16721747 false,
1748 call_ctx,
16731749 );
16741750
16751751 self.exprs.items[bin_index] = .{ .builtin = .{ .name = @tagName(tags[inst_index]), .param = rhs_index } };
......@@ -1718,6 +1794,7 @@ fn walkInstruction(
17181794 parent_src,
17191795 extra.data.lhs,
17201796 false,
1797 call_ctx,
17211798 );
17221799 var rhs: DocData.WalkResult = try self.walkRef(
17231800 file,
......@@ -1725,6 +1802,7 @@ fn walkInstruction(
17251802 parent_src,
17261803 extra.data.rhs,
17271804 false,
1805 call_ctx,
17281806 );
17291807
17301808 const lhs_index = self.exprs.items.len;
......@@ -1748,6 +1826,7 @@ fn walkInstruction(
17481826 parent_src,
17491827 extra.data.lhs,
17501828 false,
1829 call_ctx,
17511830 );
17521831 var rhs: DocData.WalkResult = try self.walkRef(
17531832 file,
......@@ -1755,6 +1834,7 @@ fn walkInstruction(
17551834 parent_src,
17561835 extra.data.rhs,
17571836 false,
1837 call_ctx,
17581838 );
17591839
17601840 const type_slot_index = self.types.items.len;
......@@ -1778,6 +1858,7 @@ fn walkInstruction(
17781858 parent_src,
17791859 extra.data.lhs,
17801860 false,
1861 call_ctx,
17811862 );
17821863 var rhs: DocData.WalkResult = try self.walkRef(
17831864 file,
......@@ -1785,6 +1866,7 @@ fn walkInstruction(
17851866 parent_src,
17861867 extra.data.rhs,
17871868 false,
1869 call_ctx,
17881870 );
17891871 const type_slot_index = self.types.items.len;
17901872 try self.types.append(self.arena, .{ .ErrorUnion = .{
......@@ -1820,6 +1902,7 @@ fn walkInstruction(
18201902 parent_src,
18211903 extra.data.elem_type,
18221904 false,
1905 call_ctx,
18231906 );
18241907
18251908 // @check if `addrspace`, `bit_start` and `host_size` really need to be
......@@ -1827,7 +1910,14 @@ fn walkInstruction(
18271910 var sentinel: ?DocData.Expr = null;
18281911 if (ptr.flags.has_sentinel) {
18291912 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 );
18311921 sentinel = ref_result.expr;
18321922 extra_index += 1;
18331923 }
......@@ -1835,21 +1925,42 @@ fn walkInstruction(
18351925 var @"align": ?DocData.Expr = null;
18361926 if (ptr.flags.has_align) {
18371927 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 );
18391936 @"align" = ref_result.expr;
18401937 extra_index += 1;
18411938 }
18421939 var address_space: ?DocData.Expr = null;
18431940 if (ptr.flags.has_addrspace) {
18441941 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 );
18461950 address_space = ref_result.expr;
18471951 extra_index += 1;
18481952 }
18491953 var bit_start: ?DocData.Expr = null;
18501954 if (ptr.flags.has_bit_range) {
18511955 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 );
18531964 address_space = ref_result.expr;
18541965 extra_index += 1;
18551966 }
......@@ -1857,7 +1968,14 @@ fn walkInstruction(
18571968 var host_size: ?DocData.Expr = null;
18581969 if (ptr.flags.has_bit_range) {
18591970 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 );
18611979 host_size = ref_result.expr;
18621980 }
18631981
......@@ -1888,8 +2006,22 @@ fn walkInstruction(
18882006 const pl_node = data[inst_index].pl_node;
18892007
18902008 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);
1892 const child = try self.walkRef(file, parent_scope, parent_src, bin.rhs, false);
2009 const len = try self.walkRef(
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
18942026 const type_slot_index = self.types.items.len;
18952027 try self.types.append(self.arena, .{
......@@ -1907,9 +2039,30 @@ fn walkInstruction(
19072039 .array_type_sentinel => {
19082040 const pl_node = data[inst_index].pl_node;
19092041 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);
1911 const sentinel = try self.walkRef(file, parent_scope, parent_src, extra.data.sentinel, false);
1912 const elem_type = try self.walkRef(file, parent_scope, parent_src, extra.data.elem_type, false);
2042 const len = try self.walkRef(
2043 file,
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
19142067 const type_slot_index = self.types.items.len;
19152068 try self.types.append(self.arena, .{
......@@ -1931,10 +2084,24 @@ fn walkInstruction(
19312084 const array_data = try self.arena.alloc(usize, operands.len - 1);
19322085
19332086 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
19362096 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 );
19382105 const expr_index = self.exprs.items.len;
19392106 try self.exprs.append(self.arena, wr.expr);
19402107 array_data[idx] = expr_index;
......@@ -1952,7 +2119,14 @@ fn walkInstruction(
19522119 const array_data = try self.arena.alloc(usize, operands.len);
19532120
19542121 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 );
19562130 const expr_index = self.exprs.items.len;
19572131 try self.exprs.append(self.arena, wr.expr);
19582132 array_data[idx] = expr_index;
......@@ -1970,10 +2144,24 @@ fn walkInstruction(
19702144 const array_data = try self.arena.alloc(usize, operands.len - 1);
19712145
19722146 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
19752156 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 );
19772165 const expr_index = self.exprs.items.len;
19782166 try self.exprs.append(self.arena, wr.expr);
19792167 array_data[idx] = expr_index;
......@@ -2002,7 +2190,14 @@ fn walkInstruction(
20022190 const array_data = try self.arena.alloc(usize, operands.len);
20032191
20042192 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 );
20062201 const expr_index = self.exprs.items.len;
20072202 try self.exprs.append(self.arena, wr.expr);
20082203 array_data[idx] = expr_index;
......@@ -2041,6 +2236,7 @@ fn walkInstruction(
20412236 parent_src,
20422237 un_node.operand,
20432238 need_type,
2239 call_ctx,
20442240 );
20452241 switch (operand.expr) {
20462242 .int => |*int| int.negated = true,
......@@ -2065,6 +2261,7 @@ fn walkInstruction(
20652261 parent_src,
20662262 un_node.operand,
20672263 false,
2264 call_ctx,
20682265 );
20692266 const operand_index = self.exprs.items.len;
20702267 try self.exprs.append(self.arena, operand.expr);
......@@ -2083,6 +2280,7 @@ fn walkInstruction(
20832280 parent_src,
20842281 un_node.operand,
20852282 need_type,
2283 call_ctx,
20862284 );
20872285 const operand_index = self.exprs.items.len;
20882286 try self.exprs.append(self.arena, operand.expr);
......@@ -2101,6 +2299,7 @@ fn walkInstruction(
21012299 parent_src,
21022300 un_node.operand,
21032301 false,
2302 call_ctx,
21042303 );
21052304 const operand_index = self.exprs.items.len;
21062305 try self.exprs.append(self.arena, operand.expr);
......@@ -2115,7 +2314,14 @@ fn walkInstruction(
21152314 const pl_node = data[inst_index].pl_node;
21162315 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 );
21192325 const cond_index = self.exprs.items.len;
21202326 try self.exprs.append(self.arena, switch_cond.expr);
21212327 _ = cond_index;
......@@ -2162,6 +2368,7 @@ fn walkInstruction(
21622368 parent_src,
21632369 un_node.operand,
21642370 need_type,
2371 call_ctx,
21652372 );
21662373 const operand_index = self.exprs.items.len;
21672374 try self.exprs.append(self.arena, operand.expr);
......@@ -2181,6 +2388,7 @@ fn walkInstruction(
21812388 parent_src,
21822389 data[body].@"break".operand,
21832390 false,
2391 call_ctx,
21842392 );
21852393
21862394 const operand_index = self.exprs.items.len;
......@@ -2201,6 +2409,7 @@ fn walkInstruction(
22012409 parent_src,
22022410 un_node.operand,
22032411 need_type,
2412 call_ctx,
22042413 );
22052414
22062415 const operand_index = self.exprs.items.len;
......@@ -2214,12 +2423,31 @@ fn walkInstruction(
22142423 .as_node, .as_shift_operand => {
22152424 const pl_node = data[inst_index].pl_node;
22162425 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
22172444 const dest_type_walk = try self.walkRef(
22182445 file,
22192446 parent_scope,
22202447 parent_src,
22212448 extra.data.dest_type,
22222449 false,
2450 call_ctx,
22232451 );
22242452
22252453 const operand = try self.walkRef(
......@@ -2228,6 +2456,7 @@ fn walkInstruction(
22282456 parent_src,
22292457 extra.data.operand,
22302458 false,
2459 call_ctx,
22312460 );
22322461
22332462 const operand_idx = self.exprs.items.len;
......@@ -2257,6 +2486,7 @@ fn walkInstruction(
22572486 parent_src,
22582487 un_node.operand,
22592488 false,
2489 call_ctx,
22602490 );
22612491
22622492 const operand_idx = self.types.items.len;
......@@ -2332,7 +2562,14 @@ fn walkInstruction(
23322562 }
23332563 }
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 );
23362573 };
23372574 try path.append(self.arena, wr.expr);
23382575
......@@ -2400,6 +2637,7 @@ fn walkInstruction(
24002637 return res;
24012638 },
24022639 need_type,
2640 call_ctx,
24032641 );
24042642 },
24052643 .break_inline => {
......@@ -2410,6 +2648,7 @@ fn walkInstruction(
24102648 parent_src,
24112649 @"break".operand,
24122650 need_type,
2651 call_ctx,
24132652 );
24142653 },
24152654 .struct_init => {
......@@ -2448,6 +2687,7 @@ fn walkInstruction(
24482687 field_src,
24492688 field_extra.data.container_type,
24502689 false,
2690 call_ctx,
24512691 );
24522692 type_ref = wr.expr;
24532693 }
......@@ -2459,6 +2699,7 @@ fn walkInstruction(
24592699 parent_src,
24602700 init_extra.data.init,
24612701 need_type,
2702 call_ctx,
24622703 );
24632704 fv.* = .{ .name = field_name, .val = value };
24642705 }
......@@ -2477,6 +2718,7 @@ fn walkInstruction(
24772718 parent_src,
24782719 un_node.operand,
24792720 false,
2721 call_ctx,
24802722 );
24812723
24822724 return DocData.WalkResult{
......@@ -2503,6 +2745,7 @@ fn walkInstruction(
25032745 parent_src,
25042746 init_extra.data.init,
25052747 need_type,
2748 call_ctx,
25062749 );
25072750 fv.* = .{ .name = field_name, .val = value };
25082751 idx = init_extra.end;
......@@ -2576,7 +2819,14 @@ fn walkInstruction(
25762819 const pl_node = data[inst_index].pl_node;
25772820 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
25812831 const args_len = extra.data.flags.args_len;
25822832 var args = try self.arena.alloc(DocData.Expr, args_len);
......@@ -2591,7 +2841,17 @@ fn walkInstruction(
25912841 // to show discrepancies between the types of provided
25922842 // arguments and the types declared in the function
25932843 // 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 );
25952855 args[i] = wr.expr;
25962856 }
25972857
......@@ -2639,6 +2899,7 @@ fn walkInstruction(
26392899 self_ast_node_index,
26402900 type_slot_index,
26412901 tags[inst_index] == .func_inferred,
2902 call_ctx,
26422903 );
26432904
26442905 return result;
......@@ -2654,6 +2915,7 @@ fn walkInstruction(
26542915 inst_index,
26552916 self_ast_node_index,
26562917 type_slot_index,
2918 call_ctx,
26572919 );
26582920
26592921 return result;
......@@ -2678,7 +2940,14 @@ fn walkInstruction(
26782940
26792941 var array_type: ?DocData.Expr = null;
26802942 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 );
26822951 if (idx == 0) {
26832952 array_type = wr.typeRef;
26842953 }
......@@ -2740,6 +3009,7 @@ fn walkInstruction(
27403009 src_info,
27413010 &decl_indexes,
27423011 &priv_decl_indexes,
3012 call_ctx,
27433013 );
27443014
27453015 self.types.items[type_slot_index] = .{
......@@ -2778,7 +3048,14 @@ fn walkInstruction(
27783048 if (small.has_lib_name) extra_index += 1;
27793049 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
27833060 var value: DocData.WalkResult = .{
27843061 .typeRef = var_type.expr,
......@@ -2787,7 +3064,14 @@ fn walkInstruction(
27873064
27883065 if (small.has_init) {
27893066 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 );
27913075 value.expr = var_init.expr;
27923076 value.typeRef = var_init.typeRef;
27933077 }
......@@ -2853,6 +3137,7 @@ fn walkInstruction(
28533137 src_info,
28543138 &decl_indexes,
28553139 &priv_decl_indexes,
3140 call_ctx,
28563141 );
28573142
28583143 // Analyze the tag once all decls have been analyzed
......@@ -2862,6 +3147,7 @@ fn walkInstruction(
28623147 parent_src,
28633148 tt_ref,
28643149 false,
3150 call_ctx,
28653151 )).expr else null;
28663152
28673153 // Fields
......@@ -2883,6 +3169,7 @@ fn walkInstruction(
28833169 &field_type_refs,
28843170 &field_name_indexes,
28853171 extra_index,
3172 call_ctx,
28863173 );
28873174
28883175 self.ast_nodes.items[self_ast_node_index].fields = field_name_indexes.items;
......@@ -2948,7 +3235,14 @@ fn walkInstruction(
29483235 const tag_type = file.zir.extra[extra_index];
29493236 extra_index += 1;
29503237 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 );
29523246 break :blk wr.expr;
29533247 } else null;
29543248
......@@ -2974,6 +3268,7 @@ fn walkInstruction(
29743268 src_info,
29753269 &decl_indexes,
29763270 &priv_decl_indexes,
3271 call_ctx,
29773272 );
29783273
29793274 // const body = file.zir.extra[extra_index..][0..body_len];
......@@ -3005,7 +3300,14 @@ fn walkInstruction(
30053300 const value_expr: ?DocData.Expr = if (has_value) blk: {
30063301 const value_ref = file.zir.extra[extra_index];
30073302 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 );
30093311 break :blk value.expr;
30103312 } else null;
30113313 try field_values.append(self.arena, value_expr);
......@@ -3095,14 +3397,28 @@ fn walkInstruction(
30953397 extra_index += 1; // backing_int_body_len
30963398 if (backing_int_body_len == 0) {
30973399 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 );
30993408 backing_int = backing_int_res.expr;
31003409 extra_index += 1; // backing_int_ref
31013410 } else {
31023411 const backing_int_body = file.zir.extra[extra_index..][0..backing_int_body_len];
31033412 const break_inst = backing_int_body[backing_int_body.len - 1];
31043413 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 );
31063422 backing_int = backing_int_res.expr;
31073423 extra_index += backing_int_body_len; // backing_int_body_inst
31083424 }
......@@ -3123,6 +3439,7 @@ fn walkInstruction(
31233439 src_info,
31243440 &decl_indexes,
31253441 &priv_decl_indexes,
3442 call_ctx,
31263443 );
31273444
31283445 var field_type_refs: std.ArrayListUnmanaged(DocData.Expr) = .{};
......@@ -3138,6 +3455,7 @@ fn walkInstruction(
31383455 &field_name_indexes,
31393456 extra_index,
31403457 small.is_tuple,
3458 call_ctx,
31413459 );
31423460
31433461 self.ast_nodes.items[self_ast_node_index].fields = field_name_indexes.items;
......@@ -3194,7 +3512,14 @@ fn walkInstruction(
31943512 const extra = file.zir.extraData(Zir.Inst.UnNode, extended.operand).data;
31953513 const bin_index = self.exprs.items.len;
31963514 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
31993524 const param_index = self.exprs.items.len;
32003525 try self.exprs.append(self.arena, param.expr);
......@@ -3213,7 +3538,14 @@ fn walkInstruction(
32133538 const extra = file.zir.extraData(Zir.Inst.UnNode, extended.operand).data;
32143539 const bin_index = self.exprs.items.len;
32153540 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
32183550 const param_index = self.exprs.items.len;
32193551 try self.exprs.append(self.arena, param.expr);
......@@ -3241,6 +3573,7 @@ fn walkInstruction(
32413573 parent_src,
32423574 extra.ptr,
32433575 false,
3576 call_ctx,
32443577 );
32453578 try self.exprs.append(self.arena, ptr.expr);
32463579
......@@ -3251,6 +3584,7 @@ fn walkInstruction(
32513584 parent_src,
32523585 extra.expected_value,
32533586 false,
3587 call_ctx,
32543588 );
32553589 try self.exprs.append(self.arena, expected_value.expr);
32563590
......@@ -3261,6 +3595,7 @@ fn walkInstruction(
32613595 parent_src,
32623596 extra.new_value,
32633597 false,
3598 call_ctx,
32643599 );
32653600 try self.exprs.append(self.arena, new_value.expr);
32663601
......@@ -3271,6 +3606,7 @@ fn walkInstruction(
32713606 parent_src,
32723607 extra.success_order,
32733608 false,
3609 call_ctx,
32743610 );
32753611 try self.exprs.append(self.arena, success_order.expr);
32763612
......@@ -3281,6 +3617,7 @@ fn walkInstruction(
32813617 parent_src,
32823618 extra.failure_order,
32833619 false,
3620 call_ctx,
32843621 );
32853622 try self.exprs.append(self.arena, failure_order.expr);
32863623
......@@ -3319,6 +3656,7 @@ fn analyzeAllDecls(
33193656 parent_src: SrcLocInfo,
33203657 decl_indexes: *std.ArrayListUnmanaged(usize),
33213658 priv_decl_indexes: *std.ArrayListUnmanaged(usize),
3659 call_ctx: ?*const CallContext,
33223660) AutodocErrors!usize {
33233661 const first_decl_indexes_slot = decl_indexes.items.len;
33243662 const original_it = file.zir.declIterator(@as(u32, @intCast(parent_inst_index)));
......@@ -3358,6 +3696,7 @@ fn analyzeAllDecls(
33583696 decl_indexes,
33593697 priv_decl_indexes,
33603698 d,
3699 call_ctx,
33613700 );
33623701 },
33633702 }
......@@ -3387,6 +3726,7 @@ fn analyzeAllDecls(
33873726 decl_indexes,
33883727 priv_decl_indexes,
33893728 d,
3729 call_ctx,
33903730 );
33913731 }
33923732
......@@ -3420,6 +3760,7 @@ fn analyzeDecl(
34203760 decl_indexes: *std.ArrayListUnmanaged(usize),
34213761 priv_decl_indexes: *std.ArrayListUnmanaged(usize),
34223762 d: Zir.DeclIterator.Item,
3763 call_ctx: ?*const CallContext,
34233764) AutodocErrors!void {
34243765 const data = file.zir.instructions.items(.data);
34253766 const is_pub = @as(u1, @truncate(d.flags >> 0)) != 0;
......@@ -3497,7 +3838,14 @@ fn analyzeDecl(
34973838 break :idx idx;
34983839 };
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
35023850 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(
35453893 decl_indexes: *std.ArrayListUnmanaged(usize),
35463894 priv_decl_indexes: *std.ArrayListUnmanaged(usize),
35473895 d: Zir.DeclIterator.Item,
3896 call_ctx: ?*const CallContext,
35483897) AutodocErrors!void {
35493898 const data = file.zir.instructions.items(.data);
35503899
......@@ -3574,7 +3923,14 @@ fn analyzeUsingnamespaceDecl(
35743923 break :idx idx;
35753924 };
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
35793935 const decl_slot_index = self.decls.items.len;
35803936 try self.decls.append(self.arena, .{
......@@ -4192,6 +4548,7 @@ fn analyzeFancyFunction(
41924548 inst_index: usize,
41934549 self_ast_node_index: usize,
41944550 type_slot_index: usize,
4551 call_ctx: ?*const CallContext,
41954552) AutodocErrors!DocData.WalkResult {
41964553 const tags = file.zir.instructions.items(.tag);
41974554 const data = file.zir.instructions.items(.data);
......@@ -4253,7 +4610,14 @@ fn analyzeFancyFunction(
42534610
42544611 const break_index = file.zir.extra[extra.end..][extra.data.body_len - 1];
42554612 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
42584622 param_type_refs.appendAssumeCapacity(param_type_ref.expr);
42594623 },
......@@ -4277,7 +4641,14 @@ fn analyzeFancyFunction(
42774641 if (extra.data.bits.has_align_ref) {
42784642 const align_ref = @as(Zir.Inst.Ref, @enumFromInt(file.zir.extra[extra_index]));
42794643 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 );
42814652 extra_index += 1;
42824653 } else if (extra.data.bits.has_align_body) {
42834654 const align_body_len = file.zir.extra[extra_index];
......@@ -4294,7 +4665,14 @@ fn analyzeFancyFunction(
42944665 if (extra.data.bits.has_addrspace_ref) {
42954666 const addrspace_ref = @as(Zir.Inst.Ref, @enumFromInt(file.zir.extra[extra_index]));
42964667 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 );
42984676 extra_index += 1;
42994677 } else if (extra.data.bits.has_addrspace_body) {
43004678 const addrspace_body_len = file.zir.extra[extra_index];
......@@ -4311,7 +4689,14 @@ fn analyzeFancyFunction(
43114689 if (extra.data.bits.has_section_ref) {
43124690 const section_ref = @as(Zir.Inst.Ref, @enumFromInt(file.zir.extra[extra_index]));
43134691 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 );
43154700 extra_index += 1;
43164701 } else if (extra.data.bits.has_section_body) {
43174702 const section_body_len = file.zir.extra[extra_index];
......@@ -4327,7 +4712,14 @@ fn analyzeFancyFunction(
43274712 var cc_index: ?usize = null;
43284713 if (extra.data.bits.has_cc_ref and !extra.data.bits.has_cc_body) {
43294714 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
43324724 cc_index = self.exprs.items.len;
43334725 try self.exprs.append(self.arena, cc_expr.expr);
......@@ -4341,7 +4733,14 @@ fn analyzeFancyFunction(
43414733 // We assume the body ends with a break_inline
43424734 const break_index = cc_body[cc_body.len - 1];
43434735 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
43464745 cc_index = self.exprs.items.len;
43474746 try self.exprs.append(self.arena, cc_expr.expr);
......@@ -4357,14 +4756,28 @@ fn analyzeFancyFunction(
43574756 .none => DocData.Expr{ .void = .{} },
43584757 else => blk: {
43594758 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 );
43614767 break :blk wr.expr;
43624768 },
43634769 },
43644770 else => blk: {
43654771 const last_instr_index = fn_info.ret_ty_body[fn_info.ret_ty_body.len - 1];
43664772 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 );
43684781 break :blk wr.expr;
43694782 },
43704783 };
......@@ -4381,6 +4794,7 @@ fn analyzeFancyFunction(
43814794 scope,
43824795 parent_src,
43834796 fn_info.body[0],
4797 call_ctx,
43844798 );
43854799 } else {
43864800 break :blk null;
......@@ -4426,6 +4840,7 @@ fn analyzeFunction(
44264840 self_ast_node_index: usize,
44274841 type_slot_index: usize,
44284842 ret_is_inferred_error_set: bool,
4843 call_ctx: ?*const CallContext,
44294844) AutodocErrors!DocData.WalkResult {
44304845 const tags = file.zir.instructions.items(.tag);
44314846 const data = file.zir.instructions.items(.data);
......@@ -4487,7 +4902,14 @@ fn analyzeFunction(
44874902
44884903 const break_index = file.zir.extra[extra.end..][extra.data.body_len - 1];
44894904 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
44924914 param_type_refs.appendAssumeCapacity(param_type_ref.expr);
44934915 },
......@@ -4500,14 +4922,28 @@ fn analyzeFunction(
45004922 .none => DocData.Expr{ .void = .{} },
45014923 else => blk: {
45024924 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 );
45044933 break :blk wr.expr;
45054934 },
45064935 },
45074936 else => blk: {
45084937 const last_instr_index = fn_info.ret_ty_body[fn_info.ret_ty_body.len - 1];
45094938 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 );
45114947 break :blk wr.expr;
45124948 },
45134949 };
......@@ -4524,6 +4960,7 @@ fn analyzeFunction(
45244960 scope,
45254961 parent_src,
45264962 fn_info.body[0],
4963 call_ctx,
45274964 );
45284965 } else {
45294966 break :blk null;
......@@ -4570,6 +5007,7 @@ fn getGenericReturnType(
45705007 scope: *Scope,
45715008 parent_src: SrcLocInfo, // function decl line
45725009 body_main_block: usize,
5010 call_ctx: ?*const CallContext,
45735011) !DocData.Expr {
45745012 const tags = file.zir.instructions.items(.tag);
45755013 const data = file.zir.instructions.items(.data);
......@@ -4581,7 +5019,14 @@ fn getGenericReturnType(
45815019 const maybe_ret_node = file.zir.extra[extra.end..][extra.data.body_len - 4];
45825020 switch (tags[maybe_ret_node]) {
45835021 .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 );
45855030 return wr.expr;
45865031 },
45875032 else => {
......@@ -4599,6 +5044,7 @@ fn collectUnionFieldInfo(
45995044 field_type_refs: *std.ArrayListUnmanaged(DocData.Expr),
46005045 field_name_indexes: *std.ArrayListUnmanaged(usize),
46015046 ei: usize,
5047 call_ctx: ?*const CallContext,
46025048) !void {
46035049 if (fields_len == 0) return;
46045050 var extra_index = ei;
......@@ -4641,7 +5087,14 @@ fn collectUnionFieldInfo(
46415087
46425088 // type
46435089 {
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 );
46455098 try field_type_refs.append(self.arena, walk_result.expr);
46465099 }
46475100
......@@ -4671,6 +5124,7 @@ fn collectStructFieldInfo(
46715124 field_name_indexes: *std.ArrayListUnmanaged(usize),
46725125 ei: usize,
46735126 is_tuple: bool,
5127 call_ctx: ?*const CallContext,
46745128) !void {
46755129 if (fields_len == 0) return;
46765130 var extra_index = ei;
......@@ -4744,7 +5198,14 @@ fn collectStructFieldInfo(
47445198 for (fields) |field| {
47455199 const type_expr = expr: {
47465200 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 );
47485209 break :expr walk_result.expr;
47495210 }
47505211
......@@ -4760,7 +5221,14 @@ fn collectStructFieldInfo(
47605221 .col = 0,
47615222 .fields = null, // walkInstruction will fill `fields` if necessary
47625223 });
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 );
47645232 break :expr walk_result.expr;
47655233 };
47665234
......@@ -4776,7 +5244,14 @@ fn collectStructFieldInfo(
47765244
47775245 const break_inst = body[body.len - 1];
47785246 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 );
47805255 break :def walk_result.expr;
47815256 };
47825257
......@@ -4812,6 +5287,7 @@ fn walkRef(
48125287 parent_src: SrcLocInfo,
48135288 ref: Ref,
48145289 need_type: bool, // true when the caller needs also a typeRef for the return value
5290 call_ctx: ?*const CallContext,
48155291) AutodocErrors!DocData.WalkResult {
48165292 if (ref == .none) {
48175293 return .{ .expr = .{ .comptimeExpr = 0 } };
......@@ -4824,7 +5300,14 @@ fn walkRef(
48245300 .expr = .{ .type = @intFromEnum(ref) },
48255301 };
48265302 } 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 );
48285311 } else {
48295312 switch (ref) {
48305313 else => {