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.

updateTimeReportCompile

WebServer.updateTimeReportCompile
pub fn updateTimeReportCompile(ws: *WebServer, opts: struct

File

lib/compiler/Maker/WebServer.zig:666

Code

pub fn updateTimeReportCompile(ws: *WebServer, opts: struct {
    compile_step: Configuration.Step.Index,

    use_llvm: bool,
    stats: abi.time_report.CompileResult.Stats,
    ns_total: u64,

    llvm_pass_timings_len: u32,
    files_len: u32,
    decls_len: u32,

    /// The trailing data of `abi.time_report.CompileResult`, except the step name.
    trailing: []const u8,
}) void {
    const graph = ws.graph;
    const io = graph.io;
    const configured = &ws.configured.?;
    const maker = configured.maker;
    const gpa = maker.gpa;
    const all_steps = maker.step_stack.keys();

    const step_idx: u32 = for (all_steps, 0..) |s, i| {
        if (s == opts.compile_step) break @intCast(i);
    } else unreachable;

    const old_buf = old: {
        configured.time_report_mutex.lock(io) catch return;
        defer configured.time_report_mutex.unlock(io);
        const old = configured.time_report_msgs[step_idx];
        configured.time_report_msgs[step_idx] = &.{};
        break :old old;
    };
    const buf = gpa.realloc(old_buf, @sizeOf(abi.time_report.CompileResult) + opts.trailing.len) catch @panic("out of memory");

    const out_header: *align(1) abi.time_report.CompileResult = @ptrCast(buf[0..@sizeOf(abi.time_report.CompileResult)]);
    out_header.* = .{
        .step_idx = step_idx,
        .flags = .{
            .use_llvm = opts.use_llvm,
        },
        .stats = opts.stats,
        .ns_total = opts.ns_total,
        .llvm_pass_timings_len = opts.llvm_pass_timings_len,
        .files_len = opts.files_len,
        .decls_len = opts.decls_len,
    };
    @memcpy(buf[@sizeOf(abi.time_report.CompileResult)..], opts.trailing);

    {
        configured.time_report_mutex.lock(io) catch return;
        defer configured.time_report_mutex.unlock(io);
        assert(configured.time_report_msgs[step_idx].len == 0);
        configured.time_report_msgs[step_idx] = buf;
        configured.time_report_update_times[step_idx] = ws.now();
    }
    ws.notifyUpdate();
}