Skip to content

unexpected @compileLog behavior in comptime #832

@tgschultz

Description

@tgschultz

When a function containing an @compilelog statement is encountered at comptime, it appears that execution ends as soon as that function returns. @compilelog is not intended to have any side effects other than preventing the actual build.

fn log(comptime x: u32) void {
    comptime {
        @compileLog("logged x: ", x);
    }
}

fn loopLog(comptime x: u32) u32 {
    comptime {
        var i = x;
        @compileLog("printed i: ", i);
        while(i >= 0):(i -= 1) {
            //comment out log(i) to log countdown
            log(i);
            @compileLog("not printed i: ", i);
        }
        @compileLog("result i: ", i);
        return i;
    }
}

test "err in comptime" {
    const x = loopLog(3);
    const y = loopLog(5);
}

With log(i):

| "printed i: ", 3
| "logged x: ", 3
| "printed i: ", 5
| "logged x: ", 5
test.zig:44:9: error: found compile log statement
...

Whitout log(i):

| "printed i: ", 3
| "not printed i: ", 3
| "not printed i: ", 2
| "not printed i: ", 1
| "not printed i: ", 0
| "result i: ", 0
| "printed i: ", 5
| "not printed i: ", 5
| "not printed i: ", 4
| "not printed i: ", 3
| "not printed i: ", 2
| "not printed i: ", 1
| "not printed i: ", 0
| "result i: ", 0
test.zig:44:9: error: found compile log statement
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions