zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit fbe9fcd243c646e62dc19f87d3e03b7e3f458a84 (tree)
parent 5fa260ba065f28632af133d07441d8a611fba15b
Author: mlugg <mlugg@mlugg.co.uk>
Date:   Wed, 20 Sep 2023 18:46:45 +0100

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:
Msrc/Autodoc.zig | 16++++++++++++++++
1 file changed, 16 insertions(+), 0 deletions(-)

diff --git 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];