liveBook · Manning

@compileLog

As explained in Systems Programming with Zig

@compileLog is a Zig builtin that emits compile-time diagnostic output and prevents successful final compilation.

@compileLog emits diagnostic output while Zig evaluates code at compile time. It is useful for inspecting comptime results, but any program containing it fails to compile—even when the code is otherwise valid. section 4.1.3

comptime {
    @compileLog(words);
}

A comptime block logs the parsed wordlist so its contents can be checked during compilation. section 4.1.3

Remove the logging statement after checking the output. Referencing the value can also expose errors that lazy evaluation might otherwise leave unevaluated. section 4.1.3

How Systems Programming with Zig covers it

How deep it goes
Demonstrates logging a computed value and explains that its presence prevents successful compilation.
Examples
Logs a parsed, embedded wordlist from a comptime block for visual inspection.
What you can do after
Debug comptime results by logging them, then remove the statement to allow compilation to succeed.
How it connects
Connects comptime evaluation with lazy evaluation and @embedFile.

This explainer was generated by Manning's knowledge graph from the text of Systems Programming with Zig. The section links point to the parts of the book it draws on.