Zig 0.17.0-dev (Split by item)

This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.

fetchRemoveRefEntries

Given a list of instructions, returns a list of all instructions which are a ref of one of the originals, from astgen.ref_table, non-recursively. The entries are removed from astgen.ref_table, and the returned slice can then be treated as its own body, to append ref instructions to a body other than the one they would normally exist in.

This is used when lowering functions. Very rarely, the callconv expression, align expression, etc may reference function parameters via &param; in this case, we need to lower to a ref instruction in the callconv/align/etc body, rather than in the declaration body. However, we don't append these bodies to extra until we've evaluated all of the bodies into a big GenZir stack. Therefore, we use this function to pull out these per-body ref instructions which must be emitted.

AstGen.fetchRemoveRefEntries
fn fetchRemoveRefEntries(astgen: *AstGen, param_insts: []const Zir.Inst.Index) ![]Zir.Inst.Index

File

lib/std/zig/AstGen.zig:13576

Code

fn fetchRemoveRefEntries(astgen: *AstGen, param_insts: []const Zir.Inst.Index) ![]Zir.Inst.Index {
    var refs: std.ArrayList(Zir.Inst.Index) = .empty;
    for (param_insts) |param_inst| {
        if (astgen.ref_table.fetchRemove(param_inst)) |kv| {
            try refs.append(astgen.arena, kv.value);
        }
    }
    return refs.items;
}