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.

Fork

Maker.Fork
const Fork = struct

File

lib/compiler/Maker.zig:3413

Code

const Fork = struct {
    path: Path,
    manifest_ast: std.zig.Ast,
    manifest: Package.Manifest,
    error_bundle: std.zig.ErrorBundle.Wip,
    failed: bool,
    arena_allocator: std.heap.ArenaAllocator,

    fn init(cwd_relative_path: []const u8) Fork {
        return .{
            .manifest_ast = undefined,
            .manifest = undefined,
            .error_bundle = undefined,
            .arena_allocator = undefined,
            .path = .{
                .root_dir = .cwd(),
                .sub_path = cwd_relative_path,
            },
            .failed = false,
        };
    }

    fn load(io: Io, gpa: Allocator, fork: *Fork, color: Color) Io.Cancelable!void {
        loadFallible(io, gpa, fork, color) catch |err| switch (err) {
            error.Canceled => |e| return e,
            error.AlreadyReported => fork.failed = true,
            else => |e| {
                log.err("failed to load fork at {f}: {t}", .{ fork.path, e });
                fork.failed = true;
            },
        };
    }

    fn loadFallible(io: Io, gpa: Allocator, fork: *Fork, color: Color) !void {
        fork.arena_allocator = .init(gpa);
        const arena = fork.arena_allocator.allocator();

        var error_bundle: std.zig.ErrorBundle.Wip = undefined;
        try error_bundle.init(gpa);
        defer error_bundle.deinit();

        const manifest_path = try fork.path.join(arena, Package.Manifest.basename);

        Package.Manifest.load(
            io,
            arena,
            manifest_path,
            &fork.manifest_ast,
            &error_bundle,
            &fork.manifest,
            true,
        ) catch |err| switch (err) {
            error.Canceled => |e| return e,
            error.ErrorsBundled => {
                assert(error_bundle.root_list.items.len > 0);
                var errors = try error_bundle.toOwnedBundle("");
                errors.renderToStderr(io, .{}, color) catch {};
                return error.AlreadyReported;
            },
            else => |e| {
                log.err("failed to load package manifest {f}: {t}", .{ manifest_path, e });
                return error.AlreadyReported;
            },
        };
    }

    fn deinitList(forks: []Fork) void {
        for (forks) |*fork| fork.arena_allocator.deinit();
    }
}