Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow @src() outside of functions and allow @src().line at comptime #12847

Closed
wants to merge 4 commits into from

Conversation

pfgithub
Copy link
Contributor

@pfgithub pfgithub commented Sep 15, 2022

It seems like @src() is intentionally runtime-only for incremental compilation reasons so this might not be wanted (#12016 (comment)). I would expect that column should be runtime-only then for the same reason.


I was trying to generate shader source code at comptime and ran into these when trying to generate #line directives.

This changes @src() to work when not in a function. SourceLocation.fn_name is set to an empty string, which could potentially be a footgun but it seems hard to run into that by accident.

This also makes @src().line available at comptime.

fn demo() void {
    @compileLog(@src());
}

comptime {
    _ = demo;
    @compileLog(@src());
}

//Compile Log Output:
@as(builtin.SourceLocation, .{.file = "…/a.zig\x00", .fn_name = "\x00", .line = 7, .column = 17})
@as(builtin.SourceLocation, .{.file = "…/a.zig\x00", .fn_name = "demo\x00", .line = 2, .column = 17})

@Vexu
Copy link
Member

Vexu commented Sep 15, 2022

@src is implemented as desired #2029 (comment), if you want to change that go through a proposal.

@Vexu Vexu closed this Sep 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants