Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
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 standard library. Private Function

fetchRemoveRefEntries

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

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.

Params

  • astgen: *AstGen
  • param_insts: []const Zir.Inst.Index

File

zig/AstGen.zig:13612
13612
13613
13614
13615
13616
13617
13618
13619
13620
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;
}