authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2023-09-20 18:46:45+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2023-09-23 22:01:08+01:00
logfbe9fcd243c646e62dc19f87d3e03b7e3f458a84
treefee2109667ac27b964065e810d366b706d8b07dc
parent5fa260ba065f28632af133d07441d8a611fba15b
signaturelock-open Commit is signed but in an unrecognized format.

Autodoc: prevent infinite recursion when resolving parameter type

Note that this will also be necessary for `switch_block` and `switch_block_ref` once those instructions are correctly implemented.

1 files changed, 16 insertions(+), 0 deletions(-)

src/Autodoc.zig+16
...@@ -45,6 +45,14 @@ ref_paths_pending_on_types: std.AutoHashMapUnmanaged(...@@ -45,6 +45,14 @@ ref_paths_pending_on_types: std.AutoHashMapUnmanaged(
45 std.ArrayListUnmanaged(RefPathResumeInfo),45 std.ArrayListUnmanaged(RefPathResumeInfo),
46) = .{},46) = .{},
4747
48/// A set of ZIR instruction refs which have a meaning other than the
49/// instruction they refer to. For instance, during analysis of the arguments to
50/// a `call`, the index of the `call` itself is repurposed to refer to the
51/// parameter type.
52/// TODO: there should be some kind of proper handling for these instructions;
53/// currently we just ignore them!
54repurposed_insts: std.AutoHashMapUnmanaged(Zir.Inst.Index, void) = .{},
55
48const RefPathResumeInfo = struct {56const RefPathResumeInfo = struct {
49 file: *File,57 file: *File,
50 ref_path: []DocData.Expr,58 ref_path: []DocData.Expr,
...@@ -954,6 +962,11 @@ fn walkInstruction(...@@ -954,6 +962,11 @@ fn walkInstruction(
954 const tags = file.zir.instructions.items(.tag);962 const tags = file.zir.instructions.items(.tag);
955 const data = file.zir.instructions.items(.data);963 const data = file.zir.instructions.items(.data);
956964
965 if (self.repurposed_insts.contains(@intCast(inst_index))) {
966 // TODO: better handling here
967 return .{ .expr = .{ .comptimeExpr = 0 } };
968 }
969
957 // We assume that the topmost ast_node entry corresponds to our decl970 // We assume that the topmost ast_node entry corresponds to our decl
958 const self_ast_node_index = self.ast_nodes.items.len - 1;971 const self_ast_node_index = self.ast_nodes.items.len - 1;
959972
...@@ -3022,6 +3035,9 @@ fn walkInstruction(...@@ -3022,6 +3035,9 @@ fn walkInstruction(
3022 var args = try self.arena.alloc(DocData.Expr, args_len);3035 var args = try self.arena.alloc(DocData.Expr, args_len);
3023 const body = file.zir.extra[extra.end..];3036 const body = file.zir.extra[extra.end..];
30243037
3038 try self.repurposed_insts.put(self.arena, @intCast(inst_index), {});
3039 defer _ = self.repurposed_insts.remove(@intCast(inst_index));
3040
3025 var i: usize = 0;3041 var i: usize = 0;
3026 while (i < args_len) : (i += 1) {3042 while (i < args_len) : (i += 1) {
3027 const arg_end = file.zir.extra[extra.end + i];3043 const arg_end = file.zir.extra[extra.end + i];