The comment above is fairly accurate. A feature like this doesn’t really work for Zig, because comptime isn’t acting on the AST, so we can’t really recover Zig code from it. Implementation-wise, comptime is essentially an interpreter for Zig code. When executing at runtime, it’s essentially an interpreter which emits runtime instructions instead of actually doing the computation. In your specific example of inline for
, the loop condition is interpreted at comptime, so the compiler itself is looping 4 times (over each of those types); and the body of the loop is being “interpreted” in a runtime sense, so it emits runtime code for each iteration rather than actually trying to comptime-eval std.debug.print
.
To try and understand the execution of comptime code, note the existence of @compileLog
, which allows you to print arbitrary values at comptime. Try replacing your std.debug.print
call with @compileLog(@typeInfo(T).Int.bits)
for example.