From 6808ce27bdca14d3876ac607c94f75ea054db7b8 Mon Sep 17 00:00:00 2001 From: mlugg Date: Sat, 24 Aug 2024 16:16:53 +0100 Subject: [PATCH] compiler,lib,test,langref: migrate `@setCold` to `@branchHint` --- doc/langref.html.in | 16 +++++++--------- doc/langref/test_functions.zig | 4 ++-- lib/c.zig | 2 +- lib/compiler/aro/aro/Driver/Filesystem.zig | 8 ++++---- lib/compiler/aro/aro/Parser.zig | 10 +++++----- lib/compiler/resinator/main.zig | 8 ++++---- lib/compiler_rt/common.zig | 2 +- lib/std/Thread/Futex.zig | 8 ++++---- lib/std/Thread/Mutex.zig | 2 +- lib/std/Thread/ResetEvent.zig | 2 +- lib/std/builtin.zig | 14 +++++++------- lib/std/debug.zig | 6 +++--- lib/std/fmt/parse_float/convert_slow.zig | 2 +- lib/std/hash/xxhash.zig | 12 ++++++------ lib/std/hash_map.zig | 2 +- lib/std/heap/WasmPageAllocator.zig | 2 +- lib/std/log.zig | 2 +- lib/std/once.zig | 2 +- lib/std/posix.zig | 2 +- lib/std/sort/pdq.zig | 4 ++-- lib/std/zig/AstGen.zig | 8 ++++---- lib/std/zig/Parse.zig | 12 ++++++------ src/Compilation.zig | 8 ++++---- src/Sema.zig | 4 ++-- src/arch/aarch64/CodeGen.zig | 4 ++-- src/arch/aarch64/Emit.zig | 2 +- src/arch/arm/CodeGen.zig | 4 ++-- src/arch/arm/Emit.zig | 2 +- src/arch/riscv64/CodeGen.zig | 4 ++-- src/arch/riscv64/Lower.zig | 2 +- src/arch/sparc64/CodeGen.zig | 2 +- src/arch/sparc64/Emit.zig | 2 +- src/arch/wasm/Emit.zig | 2 +- src/arch/x86_64/CodeGen.zig | 4 ++-- src/arch/x86_64/Lower.zig | 2 +- src/codegen/c.zig | 2 +- src/codegen/llvm.zig | 4 ++-- src/codegen/spirv.zig | 2 +- src/crash_report.zig | 2 +- test/behavior/basic.zig | 2 +- ...ltin_functions_returning_void_or_noreturn.zig | 2 +- .../function-only_builtins_outside_function.zig | 4 ++-- 42 files changed, 94 insertions(+), 96 deletions(-) diff --git a/doc/langref.html.in b/doc/langref.html.in index 9702f5a351..73ffbb0de8 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -4340,6 +4340,13 @@ comptime { {#see_also|@sizeOf|@typeInfo#} {#header_close#} + {#header_open|@branchHint#} +
{#syntax#}@branchHint(hint: BranchHint) void{#endsyntax#}
+

Hints to the optimizer how likely a given branch of control flow is to be reached.

+

{#syntax#}BranchHint{#endsyntax#} can be found with {#syntax#}@import("std").builtin.BranchHint{#endsyntax#}.

+

This function is only valid as the first statement in a control flow branch, or the first statement in a function.

+ {#header_close#} + {#header_open|@breakpoint#}
{#syntax#}@breakpoint() void{#endsyntax#}

@@ -5242,15 +5249,6 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val

{#header_close#} - {#header_open|@setCold#} -
{#syntax#}@setCold(comptime is_cold: bool) void{#endsyntax#}
-

- Tells the optimizer that the current function is (or is not) rarely called. - - This function is only valid within function scope. -

- {#header_close#} - {#header_open|@setEvalBranchQuota#}
{#syntax#}@setEvalBranchQuota(comptime new_quota: u32) void{#endsyntax#}

diff --git a/doc/langref/test_functions.zig b/doc/langref/test_functions.zig index 0c0a136950..10e334793e 100644 --- a/doc/langref/test_functions.zig +++ b/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) {} } diff --git a/lib/c.zig b/lib/c.zig index aa54def73d..d742258607 100644 --- a/lib/c.zig +++ b/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}); diff --git a/lib/compiler/aro/aro/Driver/Filesystem.zig b/lib/compiler/aro/aro/Driver/Filesystem.zig index 3889ec73b3..a81f313753 100644 --- a/lib/compiler/aro/aro/Driver/Filesystem.zig +++ b/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; diff --git a/lib/compiler/aro/aro/Parser.zig b/lib/compiler/aro/aro/Parser.zig index 1cb5e18934..d8d6f9d71c 100644 --- a/lib/compiler/aro/aro/Parser.zig +++ b/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); diff --git a/lib/compiler/resinator/main.zig b/lib/compiler/resinator/main.zig index e056e80252..c09801096c 100644 --- a/lib/compiler/resinator/main.zig +++ b/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); diff --git a/lib/compiler_rt/common.zig b/lib/compiler_rt/common.zig index 552fc07efd..1645a3951d 100644 --- a/lib/compiler_rt/common.zig +++ b/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; diff --git a/lib/std/Thread/Futex.zig b/lib/std/Thread/Futex.zig index c067368041..fe22fa2011 100644 --- a/lib/std/Thread/Futex.zig +++ b/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". diff --git a/lib/std/Thread/Mutex.zig b/lib/std/Thread/Mutex.zig index 032c19b7dd..be421c4c94 100644 --- a/lib/std/Thread/Mutex.zig +++ b/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. diff --git a/lib/std/Thread/ResetEvent.zig b/lib/std/Thread/ResetEvent.zig index b7e5758780..cbc5a2a31c 100644 --- a/lib/std/Thread/ResetEvent.zig +++ b/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. diff --git a/lib/std/builtin.zig b/lib/std/builtin.zig index 9dcefd2b11..6028db83a0 100644 --- a/lib/std/builtin.zig +++ b/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()); } diff --git a/lib/std/debug.zig b/lib/std/debug.zig index 826978abe4..4672f7ac06 100644 --- a/lib/std/debug.zig +++ b/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 diff --git a/lib/std/fmt/parse_float/convert_slow.zig b/lib/std/fmt/parse_float/convert_slow.zig index e4539937bd..9232bc8bce 100644 --- a/lib/std/fmt/parse_float/convert_slow.zig +++ b/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; diff --git a/lib/std/hash/xxhash.zig b/lib/std/hash/xxhash.zig index 1d7c8399fc..eb3d4ea2b9 100644 --- a/lib/std/hash/xxhash.zig +++ b/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); diff --git a/lib/std/hash_map.zig b/lib/std/hash_map.zig index 905d44c368..c0ae4596dc 100644 --- a/lib/std/hash_map.zig +++ b/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)); diff --git a/lib/std/heap/WasmPageAllocator.zig b/lib/std/heap/WasmPageAllocator.zig index 0fb45b70d4..7cb85561d8 100644 --- a/lib/std/heap/WasmPageAllocator.zig +++ b/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; diff --git a/lib/std/log.zig b/lib/std/log.zig index b2c05112b0..1533161cba 100644 --- a/lib/std/log.zig +++ b/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); } diff --git a/lib/std/once.zig b/lib/std/once.zig index ee3a8b7a35..326487df07 100644 --- a/lib/std/once.zig +++ b/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(); diff --git a/lib/std/posix.zig b/lib/std/posix.zig index 665ea17788..fcd923ad9c 100644 --- a/lib/std/posix.zig +++ b/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. diff --git a/lib/std/sort/pdq.zig b/lib/std/sort/pdq.zig index 61d78797c5..55bd17ae93 100644 --- a/lib/std/sort/pdq.zig +++ b/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; diff --git a/lib/std/zig/AstGen.zig b/lib/std/zig/AstGen.zig index 83765c8ad4..4e36e3e365 100644 --- a/lib/std/zig/AstGen.zig +++ b/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); diff --git a/lib/std/zig/Parse.zig b/lib/std/zig/Parse.zig index c43868a7d4..6f557a0f55 100644 --- a/lib/std/zig/Parse.zig +++ b/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; } diff --git a/src/Compilation.zig b/src/Compilation.zig index 61f1a30a6b..3ba53083ea 100644 --- a/src/Compilation.zig +++ b/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(); diff --git a/src/Sema.zig b/src/Sema.zig index ef72016b7b..7f39762cb2 100644 --- a/src/Sema.zig +++ b/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; diff --git a/src/arch/aarch64/CodeGen.zig b/src/arch/aarch64/CodeGen.zig index 9472bdecfd..0ed37b79d7 100644 --- a/src/arch/aarch64/CodeGen.zig +++ b/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; diff --git a/src/arch/aarch64/Emit.zig b/src/arch/aarch64/Emit.zig index 641a6fd920..6c56307183 100644 --- a/src/arch/aarch64/Emit.zig +++ b/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; diff --git a/src/arch/arm/CodeGen.zig b/src/arch/arm/CodeGen.zig index 9e71bff381..90bd360630 100644 --- a/src/arch/arm/CodeGen.zig +++ b/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); diff --git a/src/arch/arm/Emit.zig b/src/arch/arm/Emit.zig index dd68f2397d..c1b5baad57 100644 --- a/src/arch/arm/Emit.zig +++ b/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; diff --git a/src/arch/riscv64/CodeGen.zig b/src/arch/riscv64/CodeGen.zig index d7e882ddbe..2df0dbc328 100644 --- a/src/arch/riscv64/CodeGen.zig +++ b/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; diff --git a/src/arch/riscv64/Lower.zig b/src/arch/riscv64/Lower.zig index 0b96868bdd..a9ae9df898 100644 --- a/src/arch/riscv64/Lower.zig +++ b/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; diff --git a/src/arch/sparc64/CodeGen.zig b/src/arch/sparc64/CodeGen.zig index 06611a2804..e6c5a6d217 100644 --- a/src/arch/sparc64/CodeGen.zig +++ b/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); diff --git a/src/arch/sparc64/Emit.zig b/src/arch/sparc64/Emit.zig index 165ee1c45e..4e49bcf5b4 100644 --- a/src/arch/sparc64/Emit.zig +++ b/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; diff --git a/src/arch/wasm/Emit.zig b/src/arch/wasm/Emit.zig index 087f0dff6b..e02067f8ca 100644 --- a/src/arch/wasm/Emit.zig +++ b/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.?; diff --git a/src/arch/x86_64/CodeGen.zig b/src/arch/x86_64/CodeGen.zig index d5661fc193..5693a6da23 100644 --- a/src/arch/x86_64/CodeGen.zig +++ b/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); diff --git a/src/arch/x86_64/Lower.zig b/src/arch/x86_64/Lower.zig index 69cd548cc3..33ba0c7629 100644 --- a/src/arch/x86_64/Lower.zig +++ b/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; diff --git a/src/codegen/c.zig b/src/codegen/c.zig index eb5d2921ad..8703e9b124 100644 --- a/src/codegen/c.zig +++ b/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); diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index f49e1c333b..eec46b8379 100644 --- a/src/codegen/llvm.zig +++ b/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); } diff --git a/src/codegen/spirv.zig b/src/codegen/spirv.zig index 68961d2241..d1df1ba77e 100644 --- a/src/codegen/spirv.zig +++ b/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); diff --git a/src/crash_report.zig b/src/crash_report.zig index 67ec0e0eb0..c0a90d8705 100644 --- a/src/crash_report.zig +++ b/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); diff --git a/test/behavior/basic.zig b/test/behavior/basic.zig index ebe0468ca2..b96ab2fb06 100644 --- a/test/behavior/basic.zig +++ b/test/behavior/basic.zig @@ -113,7 +113,7 @@ test "cold function" { } fn thisIsAColdFn() void { - @setCold(true); + @branchHint(.cold); } test "unicode escape in character literal" { diff --git a/test/behavior/builtin_functions_returning_void_or_noreturn.zig b/test/behavior/builtin_functions_returning_void_or_noreturn.zig index 721a3f0320..c69d0f66a8 100644 --- a/test/behavior/builtin_functions_returning_void_or_noreturn.zig +++ b/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)); diff --git a/test/cases/compile_errors/function-only_builtins_outside_function.zig b/test/cases/compile_errors/function-only_builtins_outside_function.zig index 3484b5ca46..a9871e2b59 100644 --- a/test/cases/compile_errors/function-only_builtins_outside_function.zig +++ b/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