From 9da3a058d82573efeaf12fe61ab6a312649175ec Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sun, 29 May 2022 17:54:16 -0700 Subject: stage2: add missing data to ZIR encoding of functions The main purpose of this commit is to prepare to implement support for callconv(), align(), linksection(), and addrspace() annotations on generic functions where the provided expression depends on comptime parameters (making the function generic). It's a rather involved change, so this commit only makes the necessary changes to AstGen without regressing any behavior, and a follow-up commit can finish the task by making the enhancements to Sema. By my quick estimation, the new encoding for functions is a negligible improvement - along the lines of 0.005% fewer total ZIR bytes on average. Still, it's nice that this commit, while adding more data into ZIR, actually ends up reducing the storage size thanks to a slightly more sophisticated encoding. Zir.Inst.ExtendedFunc is renamed to Zir.Inst.FuncFancy to eliminate confusion about it being an extended instruction (it used to be but is no longer). The encoding for this instruction is completely reworked. The encoding for Zir.Inst.Func is also changed slightly - when the return type body length is 1, then only a Zir.Inst.Ref is provided; not a full body. linksection() and addrspace() are now communicated via func_fancy ZIR instruction rather than as part of the corresponding decl. This allows their expressions to observe comptime parameters. --- src/Module.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Module.zig') diff --git a/src/Module.zig b/src/Module.zig index 7c19c4dab6..f8d662ae1f 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -1595,9 +1595,9 @@ pub const Fn = struct { switch (zir_tags[func.zir_body_inst]) { .func => return false, .func_inferred => return true, - .func_extended => { + .func_fancy => { const inst_data = zir.instructions.items(.data)[func.zir_body_inst].pl_node; - const extra = zir.extraData(Zir.Inst.ExtendedFunc, inst_data.payload_index); + const extra = zir.extraData(Zir.Inst.FuncFancy, inst_data.payload_index); return extra.data.bits.is_inferred_error; }, else => unreachable, -- cgit v1.2.3