findTrackable
Find all tracked ZIR instructions, recursively, within a declaration instruction. Does not recurse through
nested declarations; to find all declarations, call this function recursively on the type declarations discovered
in contents.explicit_types.
This populates an ArrayListUnmanaged because an iterator would need to allocate memory anyway.
Function parameters
Parameters
The data stored at byte offset 0 when ZIR is stored in a file.
Types
- Header
- The data stored at byte offset 0 when ZIR is stored in a file.
- Inst
- These are untyped instructions generated from an Abstract Syntax Tree.
- DeclContents
- `DeclContents` contains all "interesting" instructions found within a declaration by `findTrackable`.
Returns the requested data, as well as the new index which is at the start of the
Functions
- extraData
- Returns the requested data, as well as the new index which is at the start of the
- nullTerminatedString
- Given an index into `string_bytes` returns the null-terminated string found there.
- findTrackable
- Find all tracked ZIR instructions, recursively, within a `declaration` instruction.
- findTrackableRoot
- Like `findTrackable`, but only considers the `main_struct_inst` instruction.
- assertTrackable
- Asserts that a ZIR instruction is tracked across incremental updates, and
When the ZIR update tracking logic must be modified to consider new instructions,
Values
- inst_tracking_version
- When the ZIR update tracking logic must be modified to consider new instructions,
Source
Implementation
pub fn findTrackable(zir: Zir, gpa: Allocator, contents: *DeclContents, decl_inst: Zir.Inst.Index) !void {
contents.clear();
const decl = zir.getDeclaration(decl_inst);
// `defer` instructions duplicate the same body arbitrarily many times, but we only want to traverse
// their contents once per defer. So, we store the extra index of the body here to deduplicate.
var found_defers: std.AutoHashMapUnmanaged(u32, void) = .empty;
defer found_defers.deinit(gpa);
if (decl.type_body) |b| try zir.findTrackableBody(gpa, contents, &found_defers, b);
if (decl.align_body) |b| try zir.findTrackableBody(gpa, contents, &found_defers, b);
if (decl.linksection_body) |b| try zir.findTrackableBody(gpa, contents, &found_defers, b);
if (decl.addrspace_body) |b| try zir.findTrackableBody(gpa, contents, &found_defers, b);
if (decl.value_body) |b| try zir.findTrackableBody(gpa, contents, &found_defers, b);
}