-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Consider if @src()
in an inline
function should refer to the caller's location
#21906
Comments
Sounds like alternative to #12093 (comment) and gwenzek#5 |
Note that this is a slight inconvenience for incremental, since we would have to further complicate the dependency mechanism to track dependencies on source location, whereas with status-quo behavior this is avoided by lumping this information into the ZIR source hash when To be honest, I also prefer status quo here from a language design perspective. I think having to pass |
I am of two minds here! I definitely don't mind passing At the same time, passing |
This would also be useful for logging. In C codebases I work with, my logging macros print file+line info of the logging site, but my Zig projects lack that since I don't want to pass |
I think having |
How would that work for a non- |
setting |
Having the language emit a hidden thread-local variable is a non-starter, especially for freestanding. |
I dont imagine this would happen at runtime but rather be tracked during compile time |
A non- |
I don't think support for non-inline function's makes sense. If caller info is wanted for an assert/logging function that you dont want to inline, that could be done with a non-inlined implementation taking a src info parameter and an inline wrapper that passes the caller src info, as follows: inline fn assertEq(expected: anytype, value: @TypeOf(expected)) void {
assertEqImpl(@callerSrc(), expected, value);
}
fn assertEqImpl(
src_info: @TypeOf(@src()),
expected: anytype,
value: @TypeOf(expected),
) void {
// do assert stuff
} |
Currently,
@src()
returns source it's own location, even in inline functions:Given that
inline
functions are inlined semantically, it is theoretically possible to also provideSourceLocation
of the call-site. There are several ways to handle this:@src()
to always be caller's location in an inline function@callerSrc()
which is a syntax error if called outside ofinline fn
caller: ?*SourceLocation
field tostd.builtin.SourceLocation
which is non-null iff@src()
is inside a function. This allows for having several levels of ancestral@src()
if an inline function calls another inline function.If implemented, this feature could enable several patterns. For example, there's a Rust GUI framework that uses equivalent feature to implement Flutter-like memorization: https://github.com/anp/moxie/blob/4f71b6f28340b2db263f07d0883394fa0b233de0/topo/src/lib.rs#L140-L192
Specific use-case I am interested in is this:
That is, I want to write an
assert
function which prints the location of the failure even if the code is compiled with Release, and all debug info is stripped.The text was updated successfully, but these errors were encountered: