diff options
| author | mlugg <mlugg@mlugg.co.uk> | 2023-09-20 18:46:45 +0100 |
|---|---|---|
| committer | mlugg <mlugg@mlugg.co.uk> | 2023-09-23 22:01:08 +0100 |
| commit | fbe9fcd243c646e62dc19f87d3e03b7e3f458a84 (patch) | |
| tree | fee2109667ac27b964065e810d366b706d8b07dc /src | |
| parent | 5fa260ba065f28632af133d07441d8a611fba15b (diff) | |
| download | zig-fbe9fcd243c646e62dc19f87d3e03b7e3f458a84.tar.gz zig-fbe9fcd243c646e62dc19f87d3e03b7e3f458a84.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Autodoc.zig | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/Autodoc.zig b/src/Autodoc.zig index abc80e2138..b45cee1400 100644 --- a/src/Autodoc.zig +++ b/src/Autodoc.zig @@ -45,6 +45,14 @@ ref_paths_pending_on_types: std.AutoHashMapUnmanaged( std.ArrayListUnmanaged(RefPathResumeInfo), ) = .{}, +/// A set of ZIR instruction refs which have a meaning other than the +/// instruction they refer to. For instance, during analysis of the arguments to +/// a `call`, the index of the `call` itself is repurposed to refer to the +/// parameter type. +/// TODO: there should be some kind of proper handling for these instructions; +/// currently we just ignore them! +repurposed_insts: std.AutoHashMapUnmanaged(Zir.Inst.Index, void) = .{}, + const RefPathResumeInfo = struct { file: *File, ref_path: []DocData.Expr, @@ -954,6 +962,11 @@ fn walkInstruction( const tags = file.zir.instructions.items(.tag); const data = file.zir.instructions.items(.data); + if (self.repurposed_insts.contains(@intCast(inst_index))) { + // TODO: better handling here + return .{ .expr = .{ .comptimeExpr = 0 } }; + } + // We assume that the topmost ast_node entry corresponds to our decl const self_ast_node_index = self.ast_nodes.items.len - 1; @@ -3022,6 +3035,9 @@ fn walkInstruction( var args = try self.arena.alloc(DocData.Expr, args_len); const body = file.zir.extra[extra.end..]; + try self.repurposed_insts.put(self.arena, @intCast(inst_index), {}); + defer _ = self.repurposed_insts.remove(@intCast(inst_index)); + var i: usize = 0; while (i < args_len) : (i += 1) { const arg_end = file.zir.extra[extra.end + i]; |
