authorgravatar for kappaloris@gmail.comLoris Cro <kappaloris@gmail.com> 2023-01-03 18:19:21+01:00
committergravatar for kappaloris@gmail.comLoris Cro <kappaloris@gmail.com> 2023-01-03 18:20:06+01:00
log755f50a986f429f7395848e883e154c3ab6c3f26
tree0e89b157b00a088919d08d2ea25b6a2fe6ef46bf
parentabd005f302ee81213b3f3a97a08d025cb3b1ecee

autodoc: restore generic function functionality

latest changes to zir encoding broke simple return type detection

1 files changed, 20 insertions(+), 6 deletions(-)

src/Autodoc.zig+20-6
...@@ -3798,7 +3798,7 @@ fn analyzeFancyFunction(...@@ -3798,7 +3798,7 @@ fn analyzeFancyFunction(
3798 file,3798 file,
3799 scope,3799 scope,
3800 parent_src,3800 parent_src,
3801 fn_info.body[fn_info.body.len - 1],3801 fn_info.body[0],
3802 );3802 );
3803 } else {3803 } else {
3804 break :blk null;3804 break :blk null;
...@@ -3936,7 +3936,7 @@ fn analyzeFunction(...@@ -3936,7 +3936,7 @@ fn analyzeFunction(
3936 file,3936 file,
3937 scope,3937 scope,
3938 parent_src,3938 parent_src,
3939 fn_info.body[fn_info.body.len - 1],3939 fn_info.body[0],
3940 );3940 );
3941 } else {3941 } else {
3942 break :blk null;3942 break :blk null;
...@@ -3977,11 +3977,25 @@ fn getGenericReturnType(...@@ -3977,11 +3977,25 @@ fn getGenericReturnType(
3977 file: *File,3977 file: *File,
3978 scope: *Scope,3978 scope: *Scope,
3979 parent_src: SrcLocInfo, // function decl line3979 parent_src: SrcLocInfo, // function decl line
3980 body_end: usize,3980 body_main_block: usize,
3981) !DocData.Expr {3981) !DocData.Expr {
3982 // TODO: compute the correct line offset3982 const tags = file.zir.instructions.items(.tag);
3983 const wr = try self.walkInstruction(file, scope, parent_src, body_end - 3, false);3983 const data = file.zir.instructions.items(.data);
3984 return wr.expr;3984
3985 // We expect `body_main_block` to be the first instruction
3986 // inside the function body, and for it to be a block instruction.
3987 const pl_node = data[body_main_block].pl_node;
3988 const extra = file.zir.extraData(Zir.Inst.Block, pl_node.payload_index);
3989 const maybe_ret_node = file.zir.extra[extra.end..][extra.data.body_len - 4];
3990 switch (tags[maybe_ret_node]) {
3991 .ret_node, .ret_load => {
3992 const wr = try self.walkInstruction(file, scope, parent_src, maybe_ret_node, false);
3993 return wr.expr;
3994 },
3995 else => {
3996 return DocData.Expr{ .comptimeExpr = 0 };
3997 },
3998 }
3985}3999}
39864000
3987fn collectUnionFieldInfo(4001fn collectUnionFieldInfo(