Commit 6808ce27bd
Changed files (42)
doc
lib
compiler
aro
aro
Driver
resinator
compiler_rt
std
fmt
parse_float
hash
sort
src
arch
aarch64
riscv64
sparc64
wasm
x86_64
test
cases
compile_errors
doc/langref/test_functions.zig
@@ -27,9 +27,9 @@ const WINAPI: std.builtin.CallingConvention = if (native_arch == .x86) .Stdcall
extern "kernel32" fn ExitProcess(exit_code: u32) callconv(WINAPI) noreturn;
extern "c" fn atan2(a: f64, b: f64) f64;
-// The @setCold builtin tells the optimizer that a function is rarely called.
+// The @branchHint builtin can be used to tell the optimizer that a function is rarely called ("cold").
fn abort() noreturn {
- @setCold(true);
+ @branchHint(.cold);
while (true) {}
}
doc/langref.html.in
@@ -4340,6 +4340,13 @@ comptime {
{#see_also|@sizeOf|@typeInfo#}
{#header_close#}
+ {#header_open|@branchHint#}
+ <pre>{#syntax#}@branchHint(hint: BranchHint) void{#endsyntax#}</pre>
+ <p>Hints to the optimizer how likely a given branch of control flow is to be reached.</p>
+ <p>{#syntax#}BranchHint{#endsyntax#} can be found with {#syntax#}@import("std").builtin.BranchHint{#endsyntax#}.</p>
+ <p>This function is only valid as the first statement in a control flow branch, or the first statement in a function.</p>
+ {#header_close#}
+
{#header_open|@breakpoint#}
<pre>{#syntax#}@breakpoint() void{#endsyntax#}</pre>
<p>
@@ -5242,15 +5249,6 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
</p>
{#header_close#}
- {#header_open|@setCold#}
- <pre>{#syntax#}@setCold(comptime is_cold: bool) void{#endsyntax#}</pre>
- <p>
- Tells the optimizer that the current function is (or is not) rarely called.
-
- This function is only valid within function scope.
- </p>
- {#header_close#}
-
{#header_open|@setEvalBranchQuota#}
<pre>{#syntax#}@setEvalBranchQuota(comptime new_quota: u32) void{#endsyntax#}</pre>
<p>
lib/compiler/aro/aro/Driver/Filesystem.zig
@@ -4,7 +4,7 @@ const builtin = @import("builtin");
const is_windows = builtin.os.tag == .windows;
fn readFileFake(entries: []const Filesystem.Entry, path: []const u8, buf: []u8) ?[]const u8 {
- @setCold(true);
+ @branchHint(.cold);
for (entries) |entry| {
if (mem.eql(u8, entry.path, path)) {
const len = @min(entry.contents.len, buf.len);
@@ -16,7 +16,7 @@ fn readFileFake(entries: []const Filesystem.Entry, path: []const u8, buf: []u8)
}
fn findProgramByNameFake(entries: []const Filesystem.Entry, name: []const u8, path: ?[]const u8, buf: []u8) ?[]const u8 {
- @setCold(true);
+ @branchHint(.cold);
if (mem.indexOfScalar(u8, name, '/') != null) {
@memcpy(buf[0..name.len], name);
return buf[0..name.len];
@@ -35,7 +35,7 @@ fn findProgramByNameFake(entries: []const Filesystem.Entry, name: []const u8, pa
}
fn canExecuteFake(entries: []const Filesystem.Entry, path: []const u8) bool {
- @setCold(true);
+ @branchHint(.cold);
for (entries) |entry| {
if (mem.eql(u8, entry.path, path)) {
return entry.executable;
@@ -45,7 +45,7 @@ fn canExecuteFake(entries: []const Filesystem.Entry, path: []const u8) bool {
}
fn existsFake(entries: []const Filesystem.Entry, path: []const u8) bool {
- @setCold(true);
+ @branchHint(.cold);
var buf: [std.fs.max_path_bytes]u8 = undefined;
var fib = std.heap.FixedBufferAllocator.init(&buf);
const resolved = std.fs.path.resolvePosix(fib.allocator(), &.{path}) catch return false;
lib/compiler/aro/aro/Parser.zig
@@ -385,12 +385,12 @@ fn errExpectedToken(p: *Parser, expected: Token.Id, actual: Token.Id) Error {
}
pub fn errStr(p: *Parser, tag: Diagnostics.Tag, tok_i: TokenIndex, str: []const u8) Compilation.Error!void {
- @setCold(true);
+ @branchHint(.cold);
return p.errExtra(tag, tok_i, .{ .str = str });
}
pub fn errExtra(p: *Parser, tag: Diagnostics.Tag, tok_i: TokenIndex, extra: Diagnostics.Message.Extra) Compilation.Error!void {
- @setCold(true);
+ @branchHint(.cold);
const tok = p.pp.tokens.get(tok_i);
var loc = tok.loc;
if (tok_i != 0 and tok.id == .eof) {
@@ -407,12 +407,12 @@ pub fn errExtra(p: *Parser, tag: Diagnostics.Tag, tok_i: TokenIndex, extra: Diag
}
pub fn errTok(p: *Parser, tag: Diagnostics.Tag, tok_i: TokenIndex) Compilation.Error!void {
- @setCold(true);
+ @branchHint(.cold);
return p.errExtra(tag, tok_i, .{ .none = {} });
}
pub fn err(p: *Parser, tag: Diagnostics.Tag) Compilation.Error!void {
- @setCold(true);
+ @branchHint(.cold);
return p.errExtra(tag, p.tok_i, .{ .none = {} });
}
@@ -638,7 +638,7 @@ fn pragma(p: *Parser) Compilation.Error!bool {
/// Issue errors for top-level definitions whose type was never completed.
fn diagnoseIncompleteDefinitions(p: *Parser) !void {
- @setCold(true);
+ @branchHint(.cold);
const node_slices = p.nodes.slice();
const tags = node_slices.items(.tag);
lib/compiler/resinator/main.zig
@@ -421,7 +421,7 @@ fn cliDiagnosticsToErrorBundle(
gpa: std.mem.Allocator,
diagnostics: *cli.Diagnostics,
) !ErrorBundle {
- @setCold(true);
+ @branchHint(.cold);
var bundle: ErrorBundle.Wip = undefined;
try bundle.init(gpa);
@@ -468,7 +468,7 @@ fn diagnosticsToErrorBundle(
diagnostics: *Diagnostics,
mappings: SourceMappings,
) !ErrorBundle {
- @setCold(true);
+ @branchHint(.cold);
var bundle: ErrorBundle.Wip = undefined;
try bundle.init(gpa);
@@ -559,7 +559,7 @@ fn flushErrorMessageIntoBundle(wip: *ErrorBundle.Wip, msg: ErrorBundle.ErrorMess
}
fn errorStringToErrorBundle(allocator: std.mem.Allocator, comptime format: []const u8, args: anytype) !ErrorBundle {
- @setCold(true);
+ @branchHint(.cold);
var bundle: ErrorBundle.Wip = undefined;
try bundle.init(allocator);
errdefer bundle.deinit();
@@ -574,7 +574,7 @@ fn aroDiagnosticsToErrorBundle(
fail_msg: []const u8,
comp: *aro.Compilation,
) !ErrorBundle {
- @setCold(true);
+ @branchHint(.cold);
var bundle: ErrorBundle.Wip = undefined;
try bundle.init(gpa);
lib/compiler_rt/common.zig
@@ -72,7 +72,7 @@ pub const want_sparc_abi = builtin.cpu.arch.isSPARC();
pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {
_ = error_return_trace;
if (builtin.is_test) {
- @setCold(true);
+ @branchHint(.cold);
std.debug.panic("{s}", .{msg});
} else {
unreachable;
lib/std/fmt/parse_float/convert_slow.zig
@@ -36,7 +36,7 @@ pub fn getShift(n: usize) usize {
/// Note that this function needs a lot of stack space and is marked
/// cold to hint against inlining into the caller.
pub fn convertSlow(comptime T: type, s: []const u8) BiasedFp(T) {
- @setCold(true);
+ @branchHint(.cold);
const MantissaT = mantissaType(T);
const min_exponent = -(1 << (math.floatExponentBits(T) - 1)) + 1;
lib/std/hash/xxhash.zig
@@ -593,7 +593,7 @@ pub const XxHash3 = struct {
}
fn hash3(seed: u64, input: anytype, noalias secret: *const [192]u8) u64 {
- @setCold(true);
+ @branchHint(.cold);
std.debug.assert(input.len > 0 and input.len < 4);
const flip: [2]u32 = @bitCast(secret[0..8].*);
@@ -609,7 +609,7 @@ pub const XxHash3 = struct {
}
fn hash8(seed: u64, input: anytype, noalias secret: *const [192]u8) u64 {
- @setCold(true);
+ @branchHint(.cold);
std.debug.assert(input.len >= 4 and input.len <= 8);
const flip: [2]u64 = @bitCast(secret[8..24].*);
@@ -625,7 +625,7 @@ pub const XxHash3 = struct {
}
fn hash16(seed: u64, input: anytype, noalias secret: *const [192]u8) u64 {
- @setCold(true);
+ @branchHint(.cold);
std.debug.assert(input.len > 8 and input.len <= 16);
const flip: [4]u64 = @bitCast(secret[24..56].*);
@@ -641,7 +641,7 @@ pub const XxHash3 = struct {
}
fn hash128(seed: u64, input: anytype, noalias secret: *const [192]u8) u64 {
- @setCold(true);
+ @branchHint(.cold);
std.debug.assert(input.len > 16 and input.len <= 128);
var acc = XxHash64.prime_1 *% @as(u64, input.len);
@@ -657,7 +657,7 @@ pub const XxHash3 = struct {
}
fn hash240(seed: u64, input: anytype, noalias secret: *const [192]u8) u64 {
- @setCold(true);
+ @branchHint(.cold);
std.debug.assert(input.len > 128 and input.len <= 240);
var acc = XxHash64.prime_1 *% @as(u64, input.len);
@@ -676,7 +676,7 @@ pub const XxHash3 = struct {
}
noinline fn hashLong(seed: u64, input: []const u8) u64 {
- @setCold(true);
+ @branchHint(.cold);
std.debug.assert(input.len >= 240);
const block_count = ((input.len - 1) / @sizeOf(Block)) * @sizeOf(Block);
lib/std/heap/WasmPageAllocator.zig
@@ -61,7 +61,7 @@ const FreeBlock = struct {
const not_found = maxInt(usize);
fn useRecycled(self: FreeBlock, num_pages: usize, log2_align: u8) usize {
- @setCold(true);
+ @branchHint(.cold);
for (self.data, 0..) |segment, i| {
const spills_into_next = @as(i128, @bitCast(segment)) < 0;
const has_enough_bits = @popCount(segment) >= num_pages;
lib/std/sort/pdq.zig
@@ -203,7 +203,7 @@ fn partitionEqual(a: usize, b: usize, pivot: usize, context: anytype) usize {
///
/// returns `true` if the slice is sorted at the end. This function is `O(n)` worst-case.
fn partialInsertionSort(a: usize, b: usize, context: anytype) bool {
- @setCold(true);
+ @branchHint(.cold);
// maximum number of adjacent out-of-order pairs that will get shifted
const max_steps = 5;
@@ -247,7 +247,7 @@ fn partialInsertionSort(a: usize, b: usize, context: anytype) bool {
}
fn breakPatterns(a: usize, b: usize, context: anytype) void {
- @setCold(true);
+ @branchHint(.cold);
const len = b - a;
if (len < 8) return;
lib/std/Thread/Futex.zig
@@ -27,7 +27,7 @@ const atomic = std.atomic;
/// The checking of `ptr` and `expect`, along with blocking the caller, is done atomically
/// and totally ordered (sequentially consistent) with respect to other wait()/wake() calls on the same `ptr`.
pub fn wait(ptr: *const atomic.Value(u32), expect: u32) void {
- @setCold(true);
+ @branchHint(.cold);
Impl.wait(ptr, expect, null) catch |err| switch (err) {
error.Timeout => unreachable, // null timeout meant to wait forever
@@ -43,7 +43,7 @@ pub fn wait(ptr: *const atomic.Value(u32), expect: u32) void {
/// The checking of `ptr` and `expect`, along with blocking the caller, is done atomically
/// and totally ordered (sequentially consistent) with respect to other wait()/wake() calls on the same `ptr`.
pub fn timedWait(ptr: *const atomic.Value(u32), expect: u32, timeout_ns: u64) error{Timeout}!void {
- @setCold(true);
+ @branchHint(.cold);
// Avoid calling into the OS for no-op timeouts.
if (timeout_ns == 0) {
@@ -56,7 +56,7 @@ pub fn timedWait(ptr: *const atomic.Value(u32), expect: u32, timeout_ns: u64) er
/// Unblocks at most `max_waiters` callers blocked in a `wait()` call on `ptr`.
pub fn wake(ptr: *const atomic.Value(u32), max_waiters: u32) void {
- @setCold(true);
+ @branchHint(.cold);
// Avoid calling into the OS if there's nothing to wake up.
if (max_waiters == 0) {
@@ -1048,7 +1048,7 @@ pub const Deadline = struct {
/// - A spurious wake occurs.
/// - The deadline expires; In which case `error.Timeout` is returned.
pub fn wait(self: *Deadline, ptr: *const atomic.Value(u32), expect: u32) error{Timeout}!void {
- @setCold(true);
+ @branchHint(.cold);
// Check if we actually have a timeout to wait until.
// If not just wait "forever".
lib/std/Thread/Mutex.zig
@@ -169,7 +169,7 @@ const FutexImpl = struct {
}
fn lockSlow(self: *@This()) void {
- @setCold(true);
+ @branchHint(.cold);
// Avoid doing an atomic swap below if we already know the state is contended.
// An atomic swap unconditionally stores which marks the cache-line as modified unnecessarily.
lib/std/Thread/ResetEvent.zig
@@ -107,7 +107,7 @@ const FutexImpl = struct {
}
fn waitUntilSet(self: *Impl, timeout: ?u64) error{Timeout}!void {
- @setCold(true);
+ @branchHint(.cold);
// Try to set the state from `unset` to `waiting` to indicate
// to the set() thread that others are blocked on the ResetEvent.
lib/std/zig/AstGen.zig
@@ -11435,7 +11435,7 @@ fn appendErrorNodeNotes(
args: anytype,
notes: []const u32,
) Allocator.Error!void {
- @setCold(true);
+ @branchHint(.cold);
const string_bytes = &astgen.string_bytes;
const msg: Zir.NullTerminatedString = @enumFromInt(string_bytes.items.len);
try string_bytes.writer(astgen.gpa).print(format ++ "\x00", args);
@@ -11526,7 +11526,7 @@ fn appendErrorTokNotesOff(
args: anytype,
notes: []const u32,
) !void {
- @setCold(true);
+ @branchHint(.cold);
const gpa = astgen.gpa;
const string_bytes = &astgen.string_bytes;
const msg: Zir.NullTerminatedString = @enumFromInt(string_bytes.items.len);
@@ -11563,7 +11563,7 @@ fn errNoteTokOff(
comptime format: []const u8,
args: anytype,
) Allocator.Error!u32 {
- @setCold(true);
+ @branchHint(.cold);
const string_bytes = &astgen.string_bytes;
const msg: Zir.NullTerminatedString = @enumFromInt(string_bytes.items.len);
try string_bytes.writer(astgen.gpa).print(format ++ "\x00", args);
@@ -11582,7 +11582,7 @@ fn errNoteNode(
comptime format: []const u8,
args: anytype,
) Allocator.Error!u32 {
- @setCold(true);
+ @branchHint(.cold);
const string_bytes = &astgen.string_bytes;
const msg: Zir.NullTerminatedString = @enumFromInt(string_bytes.items.len);
try string_bytes.writer(astgen.gpa).print(format ++ "\x00", args);
lib/std/zig/Parse.zig
@@ -81,7 +81,7 @@ fn addExtra(p: *Parse, extra: anytype) Allocator.Error!Node.Index {
}
fn warnExpected(p: *Parse, expected_token: Token.Tag) error{OutOfMemory}!void {
- @setCold(true);
+ @branchHint(.cold);
try p.warnMsg(.{
.tag = .expected_token,
.token = p.tok_i,
@@ -90,12 +90,12 @@ fn warnExpected(p: *Parse, expected_token: Token.Tag) error{OutOfMemory}!void {
}
fn warn(p: *Parse, error_tag: AstError.Tag) error{OutOfMemory}!void {
- @setCold(true);
+ @branchHint(.cold);
try p.warnMsg(.{ .tag = error_tag, .token = p.tok_i });
}
fn warnMsg(p: *Parse, msg: Ast.Error) error{OutOfMemory}!void {
- @setCold(true);
+ @branchHint(.cold);
switch (msg.tag) {
.expected_semi_after_decl,
.expected_semi_after_stmt,
@@ -141,12 +141,12 @@ fn warnMsg(p: *Parse, msg: Ast.Error) error{OutOfMemory}!void {
}
fn fail(p: *Parse, tag: Ast.Error.Tag) error{ ParseError, OutOfMemory } {
- @setCold(true);
+ @branchHint(.cold);
return p.failMsg(.{ .tag = tag, .token = p.tok_i });
}
fn failExpected(p: *Parse, expected_token: Token.Tag) error{ ParseError, OutOfMemory } {
- @setCold(true);
+ @branchHint(.cold);
return p.failMsg(.{
.tag = .expected_token,
.token = p.tok_i,
@@ -155,7 +155,7 @@ fn failExpected(p: *Parse, expected_token: Token.Tag) error{ ParseError, OutOfMe
}
fn failMsg(p: *Parse, msg: Ast.Error) error{ ParseError, OutOfMemory } {
- @setCold(true);
+ @branchHint(.cold);
try p.warnMsg(msg);
return error.ParseError;
}
lib/std/builtin.zig
@@ -779,7 +779,7 @@ else
/// This function is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace, ret_addr: ?usize) noreturn {
- @setCold(true);
+ @branchHint(.cold);
// For backends that cannot handle the language features depended on by the
// default panic handler, we have a simpler panic handler:
@@ -896,27 +896,27 @@ pub fn checkNonScalarSentinel(expected: anytype, actual: @TypeOf(expected)) void
}
pub fn panicSentinelMismatch(expected: anytype, actual: @TypeOf(expected)) noreturn {
- @setCold(true);
+ @branchHint(.cold);
std.debug.panicExtra(null, @returnAddress(), "sentinel mismatch: expected {any}, found {any}", .{ expected, actual });
}
pub fn panicUnwrapError(st: ?*StackTrace, err: anyerror) noreturn {
- @setCold(true);
+ @branchHint(.cold);
std.debug.panicExtra(st, @returnAddress(), "attempt to unwrap error: {s}", .{@errorName(err)});
}
pub fn panicOutOfBounds(index: usize, len: usize) noreturn {
- @setCold(true);
+ @branchHint(.cold);
std.debug.panicExtra(null, @returnAddress(), "index out of bounds: index {d}, len {d}", .{ index, len });
}
pub fn panicStartGreaterThanEnd(start: usize, end: usize) noreturn {
- @setCold(true);
+ @branchHint(.cold);
std.debug.panicExtra(null, @returnAddress(), "start index {d} is larger than end index {d}", .{ start, end });
}
pub fn panicInactiveUnionField(active: anytype, wanted: @TypeOf(active)) noreturn {
- @setCold(true);
+ @branchHint(.cold);
std.debug.panicExtra(null, @returnAddress(), "access of union field '{s}' while field '{s}' is active", .{ @tagName(wanted), @tagName(active) });
}
@@ -949,7 +949,7 @@ pub const panic_messages = struct {
};
pub noinline fn returnError(st: *StackTrace) void {
- @setCold(true);
+ @branchHint(.cold);
@setRuntimeSafety(false);
addErrRetTraceAddr(st, @returnAddress());
}
lib/std/debug.zig
@@ -409,7 +409,7 @@ pub fn assertReadable(slice: []const volatile u8) void {
}
pub fn panic(comptime format: []const u8, args: anytype) noreturn {
- @setCold(true);
+ @branchHint(.cold);
panicExtra(@errorReturnTrace(), @returnAddress(), format, args);
}
@@ -422,7 +422,7 @@ pub fn panicExtra(
comptime format: []const u8,
args: anytype,
) noreturn {
- @setCold(true);
+ @branchHint(.cold);
const size = 0x1000;
const trunc_msg = "(msg truncated)";
@@ -450,7 +450,7 @@ threadlocal var panic_stage: usize = 0;
// `panicImpl` could be useful in implementing a custom panic handler which
// calls the default handler (on supported platforms)
pub fn panicImpl(trace: ?*const std.builtin.StackTrace, first_trace_addr: ?usize, msg: []const u8) noreturn {
- @setCold(true);
+ @branchHint(.cold);
if (enable_segfault_handler) {
// If a segfault happens while panicking, we want it to actually segfault, not trigger
lib/std/hash_map.zig
@@ -1657,7 +1657,7 @@ pub fn HashMapUnmanaged(
}
fn grow(self: *Self, allocator: Allocator, new_capacity: Size, ctx: Context) Allocator.Error!void {
- @setCold(true);
+ @branchHint(.cold);
const new_cap = @max(new_capacity, minimal_capacity);
assert(new_cap > self.capacity());
assert(std.math.isPowerOfTwo(new_cap));
lib/std/log.zig
@@ -171,7 +171,7 @@ pub fn scoped(comptime scope: @Type(.EnumLiteral)) type {
comptime format: []const u8,
args: anytype,
) void {
- @setCold(true);
+ @branchHint(.cold);
log(.err, scope, format, args);
}
lib/std/once.zig
@@ -25,7 +25,7 @@ pub fn Once(comptime f: fn () void) type {
}
fn callSlow(self: *@This()) void {
- @setCold(true);
+ @branchHint(.cold);
self.mutex.lock();
defer self.mutex.unlock();
lib/std/posix.zig
@@ -654,7 +654,7 @@ fn getRandomBytesDevURandom(buf: []u8) !void {
/// it raises SIGABRT followed by SIGKILL and finally lo
/// Invokes the current signal handler for SIGABRT, if any.
pub fn abort() noreturn {
- @setCold(true);
+ @branchHint(.cold);
// MSVCRT abort() sometimes opens a popup window which is undesirable, so
// even when linking libc on Windows we use our own abort implementation.
// See https://github.com/ziglang/zig/issues/2071 for more details.
lib/c.zig
@@ -46,7 +46,7 @@ comptime {
// Avoid dragging in the runtime safety mechanisms into this .o file,
// unless we're trying to test this file.
pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {
- @setCold(true);
+ @branchHint(.cold);
_ = error_return_trace;
if (builtin.is_test) {
std.debug.panic("{s}", .{msg});
src/arch/aarch64/CodeGen.zig
@@ -6357,14 +6357,14 @@ fn wantSafety(self: *Self) bool {
}
fn fail(self: *Self, comptime format: []const u8, args: anytype) InnerError {
- @setCold(true);
+ @branchHint(.cold);
assert(self.err_msg == null);
self.err_msg = try ErrorMsg.create(self.gpa, self.src_loc, format, args);
return error.CodegenFail;
}
fn failSymbol(self: *Self, comptime format: []const u8, args: anytype) InnerError {
- @setCold(true);
+ @branchHint(.cold);
assert(self.err_msg == null);
self.err_msg = try ErrorMsg.create(self.gpa, self.src_loc, format, args);
return error.CodegenFail;
src/arch/aarch64/Emit.zig
@@ -430,7 +430,7 @@ fn writeInstruction(emit: *Emit, instruction: Instruction) !void {
}
fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {
- @setCold(true);
+ @branchHint(.cold);
assert(emit.err_msg == null);
const comp = emit.bin_file.comp;
const gpa = comp.gpa;
src/arch/arm/CodeGen.zig
@@ -6313,7 +6313,7 @@ fn wantSafety(self: *Self) bool {
}
fn fail(self: *Self, comptime format: []const u8, args: anytype) InnerError {
- @setCold(true);
+ @branchHint(.cold);
assert(self.err_msg == null);
const gpa = self.gpa;
self.err_msg = try ErrorMsg.create(gpa, self.src_loc, format, args);
@@ -6321,7 +6321,7 @@ fn fail(self: *Self, comptime format: []const u8, args: anytype) InnerError {
}
fn failSymbol(self: *Self, comptime format: []const u8, args: anytype) InnerError {
- @setCold(true);
+ @branchHint(.cold);
assert(self.err_msg == null);
const gpa = self.gpa;
self.err_msg = try ErrorMsg.create(gpa, self.src_loc, format, args);
src/arch/arm/Emit.zig
@@ -348,7 +348,7 @@ fn writeInstruction(emit: *Emit, instruction: Instruction) !void {
}
fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {
- @setCold(true);
+ @branchHint(.cold);
assert(emit.err_msg == null);
const comp = emit.bin_file.comp;
const gpa = comp.gpa;
src/arch/riscv64/CodeGen.zig
@@ -8223,14 +8223,14 @@ fn wantSafety(func: *Func) bool {
}
fn fail(func: *Func, comptime format: []const u8, args: anytype) InnerError {
- @setCold(true);
+ @branchHint(.cold);
assert(func.err_msg == null);
func.err_msg = try ErrorMsg.create(func.gpa, func.src_loc, format, args);
return error.CodegenFail;
}
fn failSymbol(func: *Func, comptime format: []const u8, args: anytype) InnerError {
- @setCold(true);
+ @branchHint(.cold);
assert(func.err_msg == null);
func.err_msg = try ErrorMsg.create(func.gpa, func.src_loc, format, args);
return error.CodegenFail;
src/arch/riscv64/Lower.zig
@@ -583,7 +583,7 @@ fn pushPopRegList(lower: *Lower, comptime spilling: bool, reg_list: Mir.Register
}
pub fn fail(lower: *Lower, comptime format: []const u8, args: anytype) Error {
- @setCold(true);
+ @branchHint(.cold);
assert(lower.err_msg == null);
lower.err_msg = try ErrorMsg.create(lower.allocator, lower.src_loc, format, args);
return error.LowerFail;
src/arch/sparc64/CodeGen.zig
@@ -3533,7 +3533,7 @@ fn errUnionPayload(self: *Self, error_union_mcv: MCValue, error_union_ty: Type)
}
fn fail(self: *Self, comptime format: []const u8, args: anytype) InnerError {
- @setCold(true);
+ @branchHint(.cold);
assert(self.err_msg == null);
const gpa = self.gpa;
self.err_msg = try ErrorMsg.create(gpa, self.src_loc, format, args);
src/arch/sparc64/Emit.zig
@@ -511,7 +511,7 @@ fn dbgAdvancePCAndLine(emit: *Emit, line: u32, column: u32) !void {
}
fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {
- @setCold(true);
+ @branchHint(.cold);
assert(emit.err_msg == null);
const comp = emit.bin_file.comp;
const gpa = comp.gpa;
src/arch/wasm/Emit.zig
@@ -252,7 +252,7 @@ fn offset(self: Emit) u32 {
}
fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {
- @setCold(true);
+ @branchHint(.cold);
std.debug.assert(emit.error_msg == null);
const comp = emit.bin_file.base.comp;
const zcu = comp.zcu.?;
src/arch/x86_64/CodeGen.zig
@@ -19203,7 +19203,7 @@ fn resolveCallingConventionValues(
}
fn fail(self: *Self, comptime format: []const u8, args: anytype) InnerError {
- @setCold(true);
+ @branchHint(.cold);
assert(self.err_msg == null);
const gpa = self.gpa;
self.err_msg = try ErrorMsg.create(gpa, self.src_loc, format, args);
@@ -19211,7 +19211,7 @@ fn fail(self: *Self, comptime format: []const u8, args: anytype) InnerError {
}
fn failSymbol(self: *Self, comptime format: []const u8, args: anytype) InnerError {
- @setCold(true);
+ @branchHint(.cold);
assert(self.err_msg == null);
const gpa = self.gpa;
self.err_msg = try ErrorMsg.create(gpa, self.src_loc, format, args);
src/arch/x86_64/Lower.zig
@@ -293,7 +293,7 @@ pub fn lowerMir(lower: *Lower, index: Mir.Inst.Index) Error!struct {
}
pub fn fail(lower: *Lower, comptime format: []const u8, args: anytype) Error {
- @setCold(true);
+ @branchHint(.cold);
assert(lower.err_msg == null);
lower.err_msg = try Zcu.ErrorMsg.create(lower.allocator, lower.src_loc, format, args);
return error.LowerFail;
src/codegen/c.zig
@@ -626,7 +626,7 @@ pub const DeclGen = struct {
}
fn fail(dg: *DeclGen, comptime format: []const u8, args: anytype) error{ AnalysisFail, OutOfMemory } {
- @setCold(true);
+ @branchHint(.cold);
const zcu = dg.pt.zcu;
const src_loc = zcu.navSrcLoc(dg.pass.nav);
dg.error_msg = try Zcu.ErrorMsg.create(dg.gpa, src_loc, format, args);
src/codegen/llvm.zig
@@ -4618,7 +4618,7 @@ pub const NavGen = struct {
}
fn todo(ng: *NavGen, comptime format: []const u8, args: anytype) Error {
- @setCold(true);
+ @branchHint(.cold);
assert(ng.err_msg == null);
const o = ng.object;
const gpa = o.gpa;
@@ -4784,7 +4784,7 @@ pub const FuncGen = struct {
}
fn todo(self: *FuncGen, comptime format: []const u8, args: anytype) Error {
- @setCold(true);
+ @branchHint(.cold);
return self.ng.todo(format, args);
}
src/codegen/spirv.zig
@@ -410,7 +410,7 @@ const NavGen = struct {
}
pub fn fail(self: *NavGen, comptime format: []const u8, args: anytype) Error {
- @setCold(true);
+ @branchHint(.cold);
const zcu = self.pt.zcu;
const src_loc = zcu.navSrcLoc(self.owner_nav);
assert(self.error_msg == null);
src/Compilation.zig
@@ -5785,7 +5785,7 @@ fn failCObj(
comptime format: []const u8,
args: anytype,
) SemaError {
- @setCold(true);
+ @branchHint(.cold);
const diag_bundle = blk: {
const diag_bundle = try comp.gpa.create(CObject.Diag.Bundle);
diag_bundle.* = .{};
@@ -5809,7 +5809,7 @@ fn failCObjWithOwnedDiagBundle(
c_object: *CObject,
diag_bundle: *CObject.Diag.Bundle,
) SemaError {
- @setCold(true);
+ @branchHint(.cold);
assert(diag_bundle.diags.len > 0);
{
comp.mutex.lock();
@@ -5825,7 +5825,7 @@ fn failCObjWithOwnedDiagBundle(
}
fn failWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, comptime format: []const u8, args: anytype) SemaError {
- @setCold(true);
+ @branchHint(.cold);
var bundle: ErrorBundle.Wip = undefined;
try bundle.init(comp.gpa);
errdefer bundle.deinit();
@@ -5852,7 +5852,7 @@ fn failWin32ResourceWithOwnedBundle(
win32_resource: *Win32Resource,
err_bundle: ErrorBundle,
) SemaError {
- @setCold(true);
+ @branchHint(.cold);
{
comp.mutex.lock();
defer comp.mutex.unlock();
src/crash_report.zig
@@ -153,8 +153,8 @@ fn writeFilePath(file: *Zcu.File, writer: anytype) !void {
}
pub fn compilerPanic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace, maybe_ret_addr: ?usize) noreturn {
+ @branchHint(.cold);
PanicSwitch.preDispatch();
- @setCold(true);
const ret_addr = maybe_ret_addr orelse @returnAddress();
const stack_ctx: StackContext = .{ .current = .{ .ret_addr = ret_addr } };
PanicSwitch.dispatch(error_return_trace, stack_ctx, msg);
src/Sema.zig
@@ -2471,7 +2471,7 @@ fn addFieldErrNote(
comptime format: []const u8,
args: anytype,
) !void {
- @setCold(true);
+ @branchHint(.cold);
const type_src = container_ty.srcLocOrNull(sema.pt.zcu) orelse return;
const field_src: LazySrcLoc = .{
.base_node_inst = type_src.base_node_inst,
@@ -2507,7 +2507,7 @@ pub fn fail(
}
pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Zcu.ErrorMsg) error{ AnalysisFail, OutOfMemory } {
- @setCold(true);
+ @branchHint(.cold);
const gpa = sema.gpa;
const zcu = sema.pt.zcu;
test/behavior/basic.zig
@@ -113,7 +113,7 @@ test "cold function" {
}
fn thisIsAColdFn() void {
- @setCold(true);
+ @branchHint(.cold);
}
test "unicode escape in character literal" {
test/behavior/builtin_functions_returning_void_or_noreturn.zig
@@ -22,7 +22,7 @@ test {
try testing.expectEqual(noreturn, @TypeOf(if (true) @panic("") else {}));
try testing.expectEqual({}, @prefetch(&val, .{}));
try testing.expectEqual({}, @setAlignStack(16));
- try testing.expectEqual({}, @setCold(true));
+ try testing.expectEqual({}, @branchHint(.cold));
try testing.expectEqual({}, @setEvalBranchQuota(0));
try testing.expectEqual({}, @setFloatMode(.optimized));
try testing.expectEqual({}, @setRuntimeSafety(true));
test/cases/compile_errors/function-only_builtins_outside_function.zig
@@ -3,7 +3,7 @@ comptime {
}
comptime {
- @setCold(true);
+ @branchHint(.cold);
}
comptime {
@@ -55,7 +55,7 @@ comptime {
// target=native
//
// :2:5: error: '@setAlignStack' outside function scope
-// :6:5: error: '@setCold' outside function scope
+// :6:5: error: '@branchHint' outside function scope
// :10:5: error: '@src' outside function scope
// :14:5: error: '@returnAddress' outside function scope
// :18:5: error: '@frameAddress' outside function scope