Merge pull request #17688 from ziglang/comptime-src
Sema: make `@src().line` comptime-known
This commit is contained in:
@@ -16861,10 +16861,7 @@ fn zirBuiltinSrc(
|
||||
// fn_name: [:0]const u8,
|
||||
func_name_val,
|
||||
// line: u32,
|
||||
try mod.intern(.{ .runtime_value = .{
|
||||
.ty = .u32_type,
|
||||
.val = (try mod.intValue(Type.u32, extra.line + 1)).toIntern(),
|
||||
} }),
|
||||
(try mod.intValue(Type.u32, extra.line + 1)).toIntern(),
|
||||
// column: u32,
|
||||
(try mod.intValue(Type.u32, extra.column + 1)).toIntern(),
|
||||
};
|
||||
|
||||
@@ -63,44 +63,40 @@ pub const Ctx = if (enable) ___tracy_c_zone_context else struct {
|
||||
pub inline fn trace(comptime src: std.builtin.SourceLocation) Ctx {
|
||||
if (!enable) return .{};
|
||||
|
||||
const global = struct {
|
||||
const loc: ___tracy_source_location_data = .{
|
||||
.name = null,
|
||||
.function = src.fn_name.ptr,
|
||||
.file = src.file.ptr,
|
||||
.line = src.line,
|
||||
.color = 0,
|
||||
};
|
||||
};
|
||||
|
||||
if (enable_callstack) {
|
||||
return ___tracy_emit_zone_begin_callstack(&.{
|
||||
.name = null,
|
||||
.function = src.fn_name.ptr,
|
||||
.file = src.file.ptr,
|
||||
.line = src.line,
|
||||
.color = 0,
|
||||
}, callstack_depth, 1);
|
||||
return ___tracy_emit_zone_begin_callstack(&global.loc, callstack_depth, 1);
|
||||
} else {
|
||||
return ___tracy_emit_zone_begin(&.{
|
||||
.name = null,
|
||||
.function = src.fn_name.ptr,
|
||||
.file = src.file.ptr,
|
||||
.line = src.line,
|
||||
.color = 0,
|
||||
}, 1);
|
||||
return ___tracy_emit_zone_begin(&global.loc, 1);
|
||||
}
|
||||
}
|
||||
|
||||
pub inline fn traceNamed(comptime src: std.builtin.SourceLocation, comptime name: [:0]const u8) Ctx {
|
||||
if (!enable) return .{};
|
||||
|
||||
const global = struct {
|
||||
const loc: ___tracy_source_location_data = .{
|
||||
.name = name.ptr,
|
||||
.function = src.fn_name.ptr,
|
||||
.file = src.file.ptr,
|
||||
.line = src.line,
|
||||
.color = 0,
|
||||
};
|
||||
};
|
||||
|
||||
if (enable_callstack) {
|
||||
return ___tracy_emit_zone_begin_callstack(&.{
|
||||
.name = name.ptr,
|
||||
.function = src.fn_name.ptr,
|
||||
.file = src.file.ptr,
|
||||
.line = src.line,
|
||||
.color = 0,
|
||||
}, callstack_depth, 1);
|
||||
return ___tracy_emit_zone_begin_callstack(&global.loc, callstack_depth, 1);
|
||||
} else {
|
||||
return ___tracy_emit_zone_begin(&.{
|
||||
.name = name.ptr,
|
||||
.function = src.fn_name.ptr,
|
||||
.file = src.file.ptr,
|
||||
.line = src.line,
|
||||
.color = 0,
|
||||
}, 1);
|
||||
return ___tracy_emit_zone_begin(&global.loc, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
pub export fn entry1() void {
|
||||
const s = @src();
|
||||
comptime var a: []const u8 = s.file;
|
||||
comptime var b: []const u8 = s.fn_name;
|
||||
comptime var c: u32 = s.column;
|
||||
comptime var d: u32 = s.line;
|
||||
_ = a;
|
||||
_ = b;
|
||||
_ = c;
|
||||
_ = d;
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage2
|
||||
// target=native
|
||||
//
|
||||
// :6:28: error: cannot store runtime value in compile time variable
|
||||
Reference in New Issue
Block a user