authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-08-24 16:16:53+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-08-27 00:44:35+01:00
log6808ce27bdca14d3876ac607c94f75ea054db7b8
treec30b229113d60243a1257fad597ec919c99e3dad
parenta3a737e9a68fae96519743a644209b4a30cf3b58
signaturelock-open Commit is signed but in an unrecognized format.

compiler,lib,test,langref: migrate `@setCold` to `@branchHint`


42 files changed, 94 insertions(+), 96 deletions(-)

doc/langref.html.in+7-9
......@@ -4340,6 +4340,13 @@ comptime {
43404340 {#see_also|@sizeOf|@typeInfo#}
43414341 {#header_close#}
43424342
4343 {#header_open|@branchHint#}
4344 <pre>{#syntax#}@branchHint(hint: BranchHint) void{#endsyntax#}</pre>
4345 <p>Hints to the optimizer how likely a given branch of control flow is to be reached.</p>
4346 <p>{#syntax#}BranchHint{#endsyntax#} can be found with {#syntax#}@import("std").builtin.BranchHint{#endsyntax#}.</p>
4347 <p>This function is only valid as the first statement in a control flow branch, or the first statement in a function.</p>
4348 {#header_close#}
4349
43434350 {#header_open|@breakpoint#}
43444351 <pre>{#syntax#}@breakpoint() void{#endsyntax#}</pre>
43454352 <p>
......@@ -5242,15 +5249,6 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
52425249 </p>
52435250 {#header_close#}
52445251
5245 {#header_open|@setCold#}
5246 <pre>{#syntax#}@setCold(comptime is_cold: bool) void{#endsyntax#}</pre>
5247 <p>
5248 Tells the optimizer that the current function is (or is not) rarely called.
5249
5250 This function is only valid within function scope.
5251 </p>
5252 {#header_close#}
5253
52545252 {#header_open|@setEvalBranchQuota#}
52555253 <pre>{#syntax#}@setEvalBranchQuota(comptime new_quota: u32) void{#endsyntax#}</pre>
52565254 <p>
doc/langref/test_functions.zig+2-2
......@@ -27,9 +27,9 @@ const WINAPI: std.builtin.CallingConvention = if (native_arch == .x86) .Stdcall
2727extern "kernel32" fn ExitProcess(exit_code: u32) callconv(WINAPI) noreturn;
2828extern "c" fn atan2(a: f64, b: f64) f64;
2929
30// The @setCold builtin tells the optimizer that a function is rarely called.
30// The @branchHint builtin can be used to tell the optimizer that a function is rarely called ("cold").
3131fn abort() noreturn {
32 @setCold(true);
32 @branchHint(.cold);
3333 while (true) {}
3434}
3535
lib/c.zig+1-1
......@@ -46,7 +46,7 @@ comptime {
4646// Avoid dragging in the runtime safety mechanisms into this .o file,
4747// unless we're trying to test this file.
4848pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {
49 @setCold(true);
49 @branchHint(.cold);
5050 _ = error_return_trace;
5151 if (builtin.is_test) {
5252 std.debug.panic("{s}", .{msg});
lib/compiler/aro/aro/Driver/Filesystem.zig+4-4
......@@ -4,7 +4,7 @@ const builtin = @import("builtin");
44const is_windows = builtin.os.tag == .windows;
55
66fn readFileFake(entries: []const Filesystem.Entry, path: []const u8, buf: []u8) ?[]const u8 {
7 @setCold(true);
7 @branchHint(.cold);
88 for (entries) |entry| {
99 if (mem.eql(u8, entry.path, path)) {
1010 const len = @min(entry.contents.len, buf.len);
......@@ -16,7 +16,7 @@ fn readFileFake(entries: []const Filesystem.Entry, path: []const u8, buf: []u8)
1616}
1717
1818fn findProgramByNameFake(entries: []const Filesystem.Entry, name: []const u8, path: ?[]const u8, buf: []u8) ?[]const u8 {
19 @setCold(true);
19 @branchHint(.cold);
2020 if (mem.indexOfScalar(u8, name, '/') != null) {
2121 @memcpy(buf[0..name.len], name);
2222 return buf[0..name.len];
......@@ -35,7 +35,7 @@ fn findProgramByNameFake(entries: []const Filesystem.Entry, name: []const u8, pa
3535}
3636
3737fn canExecuteFake(entries: []const Filesystem.Entry, path: []const u8) bool {
38 @setCold(true);
38 @branchHint(.cold);
3939 for (entries) |entry| {
4040 if (mem.eql(u8, entry.path, path)) {
4141 return entry.executable;
......@@ -45,7 +45,7 @@ fn canExecuteFake(entries: []const Filesystem.Entry, path: []const u8) bool {
4545}
4646
4747fn existsFake(entries: []const Filesystem.Entry, path: []const u8) bool {
48 @setCold(true);
48 @branchHint(.cold);
4949 var buf: [std.fs.max_path_bytes]u8 = undefined;
5050 var fib = std.heap.FixedBufferAllocator.init(&buf);
5151 const resolved = std.fs.path.resolvePosix(fib.allocator(), &.{path}) catch return false;
lib/compiler/aro/aro/Parser.zig+5-5
......@@ -385,12 +385,12 @@ fn errExpectedToken(p: *Parser, expected: Token.Id, actual: Token.Id) Error {
385385}
386386
387387pub fn errStr(p: *Parser, tag: Diagnostics.Tag, tok_i: TokenIndex, str: []const u8) Compilation.Error!void {
388 @setCold(true);
388 @branchHint(.cold);
389389 return p.errExtra(tag, tok_i, .{ .str = str });
390390}
391391
392392pub fn errExtra(p: *Parser, tag: Diagnostics.Tag, tok_i: TokenIndex, extra: Diagnostics.Message.Extra) Compilation.Error!void {
393 @setCold(true);
393 @branchHint(.cold);
394394 const tok = p.pp.tokens.get(tok_i);
395395 var loc = tok.loc;
396396 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
407407}
408408
409409pub fn errTok(p: *Parser, tag: Diagnostics.Tag, tok_i: TokenIndex) Compilation.Error!void {
410 @setCold(true);
410 @branchHint(.cold);
411411 return p.errExtra(tag, tok_i, .{ .none = {} });
412412}
413413
414414pub fn err(p: *Parser, tag: Diagnostics.Tag) Compilation.Error!void {
415 @setCold(true);
415 @branchHint(.cold);
416416 return p.errExtra(tag, p.tok_i, .{ .none = {} });
417417}
418418
......@@ -638,7 +638,7 @@ fn pragma(p: *Parser) Compilation.Error!bool {
638638
639639/// Issue errors for top-level definitions whose type was never completed.
640640fn diagnoseIncompleteDefinitions(p: *Parser) !void {
641 @setCold(true);
641 @branchHint(.cold);
642642
643643 const node_slices = p.nodes.slice();
644644 const tags = node_slices.items(.tag);
lib/compiler/resinator/main.zig+4-4
......@@ -421,7 +421,7 @@ fn cliDiagnosticsToErrorBundle(
421421 gpa: std.mem.Allocator,
422422 diagnostics: *cli.Diagnostics,
423423) !ErrorBundle {
424 @setCold(true);
424 @branchHint(.cold);
425425
426426 var bundle: ErrorBundle.Wip = undefined;
427427 try bundle.init(gpa);
......@@ -468,7 +468,7 @@ fn diagnosticsToErrorBundle(
468468 diagnostics: *Diagnostics,
469469 mappings: SourceMappings,
470470) !ErrorBundle {
471 @setCold(true);
471 @branchHint(.cold);
472472
473473 var bundle: ErrorBundle.Wip = undefined;
474474 try bundle.init(gpa);
......@@ -559,7 +559,7 @@ fn flushErrorMessageIntoBundle(wip: *ErrorBundle.Wip, msg: ErrorBundle.ErrorMess
559559}
560560
561561fn errorStringToErrorBundle(allocator: std.mem.Allocator, comptime format: []const u8, args: anytype) !ErrorBundle {
562 @setCold(true);
562 @branchHint(.cold);
563563 var bundle: ErrorBundle.Wip = undefined;
564564 try bundle.init(allocator);
565565 errdefer bundle.deinit();
......@@ -574,7 +574,7 @@ fn aroDiagnosticsToErrorBundle(
574574 fail_msg: []const u8,
575575 comp: *aro.Compilation,
576576) !ErrorBundle {
577 @setCold(true);
577 @branchHint(.cold);
578578
579579 var bundle: ErrorBundle.Wip = undefined;
580580 try bundle.init(gpa);
lib/compiler_rt/common.zig+1-1
......@@ -72,7 +72,7 @@ pub const want_sparc_abi = builtin.cpu.arch.isSPARC();
7272pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {
7373 _ = error_return_trace;
7474 if (builtin.is_test) {
75 @setCold(true);
75 @branchHint(.cold);
7676 std.debug.panic("{s}", .{msg});
7777 } else {
7878 unreachable;
lib/std/Thread/Futex.zig+4-4
......@@ -27,7 +27,7 @@ const atomic = std.atomic;
2727/// The checking of `ptr` and `expect`, along with blocking the caller, is done atomically
2828/// and totally ordered (sequentially consistent) with respect to other wait()/wake() calls on the same `ptr`.
2929pub fn wait(ptr: *const atomic.Value(u32), expect: u32) void {
30 @setCold(true);
30 @branchHint(.cold);
3131
3232 Impl.wait(ptr, expect, null) catch |err| switch (err) {
3333 error.Timeout => unreachable, // null timeout meant to wait forever
......@@ -43,7 +43,7 @@ pub fn wait(ptr: *const atomic.Value(u32), expect: u32) void {
4343/// The checking of `ptr` and `expect`, along with blocking the caller, is done atomically
4444/// and totally ordered (sequentially consistent) with respect to other wait()/wake() calls on the same `ptr`.
4545pub fn timedWait(ptr: *const atomic.Value(u32), expect: u32, timeout_ns: u64) error{Timeout}!void {
46 @setCold(true);
46 @branchHint(.cold);
4747
4848 // Avoid calling into the OS for no-op timeouts.
4949 if (timeout_ns == 0) {
......@@ -56,7 +56,7 @@ pub fn timedWait(ptr: *const atomic.Value(u32), expect: u32, timeout_ns: u64) er
5656
5757/// Unblocks at most `max_waiters` callers blocked in a `wait()` call on `ptr`.
5858pub fn wake(ptr: *const atomic.Value(u32), max_waiters: u32) void {
59 @setCold(true);
59 @branchHint(.cold);
6060
6161 // Avoid calling into the OS if there's nothing to wake up.
6262 if (max_waiters == 0) {
......@@ -1048,7 +1048,7 @@ pub const Deadline = struct {
10481048 /// - A spurious wake occurs.
10491049 /// - The deadline expires; In which case `error.Timeout` is returned.
10501050 pub fn wait(self: *Deadline, ptr: *const atomic.Value(u32), expect: u32) error{Timeout}!void {
1051 @setCold(true);
1051 @branchHint(.cold);
10521052
10531053 // Check if we actually have a timeout to wait until.
10541054 // If not just wait "forever".
lib/std/Thread/Mutex.zig+1-1
......@@ -169,7 +169,7 @@ const FutexImpl = struct {
169169 }
170170
171171 fn lockSlow(self: *@This()) void {
172 @setCold(true);
172 @branchHint(.cold);
173173
174174 // Avoid doing an atomic swap below if we already know the state is contended.
175175 // An atomic swap unconditionally stores which marks the cache-line as modified unnecessarily.
lib/std/Thread/ResetEvent.zig+1-1
......@@ -107,7 +107,7 @@ const FutexImpl = struct {
107107 }
108108
109109 fn waitUntilSet(self: *Impl, timeout: ?u64) error{Timeout}!void {
110 @setCold(true);
110 @branchHint(.cold);
111111
112112 // Try to set the state from `unset` to `waiting` to indicate
113113 // to the set() thread that others are blocked on the ResetEvent.
lib/std/builtin.zig+7-7
......@@ -779,7 +779,7 @@ else
779779/// This function is used by the Zig language code generation and
780780/// therefore must be kept in sync with the compiler implementation.
781781pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace, ret_addr: ?usize) noreturn {
782 @setCold(true);
782 @branchHint(.cold);
783783
784784 // For backends that cannot handle the language features depended on by the
785785 // default panic handler, we have a simpler panic handler:
......@@ -896,27 +896,27 @@ pub fn checkNonScalarSentinel(expected: anytype, actual: @TypeOf(expected)) void
896896}
897897
898898pub fn panicSentinelMismatch(expected: anytype, actual: @TypeOf(expected)) noreturn {
899 @setCold(true);
899 @branchHint(.cold);
900900 std.debug.panicExtra(null, @returnAddress(), "sentinel mismatch: expected {any}, found {any}", .{ expected, actual });
901901}
902902
903903pub fn panicUnwrapError(st: ?*StackTrace, err: anyerror) noreturn {
904 @setCold(true);
904 @branchHint(.cold);
905905 std.debug.panicExtra(st, @returnAddress(), "attempt to unwrap error: {s}", .{@errorName(err)});
906906}
907907
908908pub fn panicOutOfBounds(index: usize, len: usize) noreturn {
909 @setCold(true);
909 @branchHint(.cold);
910910 std.debug.panicExtra(null, @returnAddress(), "index out of bounds: index {d}, len {d}", .{ index, len });
911911}
912912
913913pub fn panicStartGreaterThanEnd(start: usize, end: usize) noreturn {
914 @setCold(true);
914 @branchHint(.cold);
915915 std.debug.panicExtra(null, @returnAddress(), "start index {d} is larger than end index {d}", .{ start, end });
916916}
917917
918918pub fn panicInactiveUnionField(active: anytype, wanted: @TypeOf(active)) noreturn {
919 @setCold(true);
919 @branchHint(.cold);
920920 std.debug.panicExtra(null, @returnAddress(), "access of union field '{s}' while field '{s}' is active", .{ @tagName(wanted), @tagName(active) });
921921}
922922
......@@ -949,7 +949,7 @@ pub const panic_messages = struct {
949949};
950950
951951pub noinline fn returnError(st: *StackTrace) void {
952 @setCold(true);
952 @branchHint(.cold);
953953 @setRuntimeSafety(false);
954954 addErrRetTraceAddr(st, @returnAddress());
955955}
lib/std/debug.zig+3-3
......@@ -409,7 +409,7 @@ pub fn assertReadable(slice: []const volatile u8) void {
409409}
410410
411411pub fn panic(comptime format: []const u8, args: anytype) noreturn {
412 @setCold(true);
412 @branchHint(.cold);
413413
414414 panicExtra(@errorReturnTrace(), @returnAddress(), format, args);
415415}
......@@ -422,7 +422,7 @@ pub fn panicExtra(
422422 comptime format: []const u8,
423423 args: anytype,
424424) noreturn {
425 @setCold(true);
425 @branchHint(.cold);
426426
427427 const size = 0x1000;
428428 const trunc_msg = "(msg truncated)";
......@@ -450,7 +450,7 @@ threadlocal var panic_stage: usize = 0;
450450// `panicImpl` could be useful in implementing a custom panic handler which
451451// calls the default handler (on supported platforms)
452452pub fn panicImpl(trace: ?*const std.builtin.StackTrace, first_trace_addr: ?usize, msg: []const u8) noreturn {
453 @setCold(true);
453 @branchHint(.cold);
454454
455455 if (enable_segfault_handler) {
456456 // If a segfault happens while panicking, we want it to actually segfault, not trigger
lib/std/fmt/parse_float/convert_slow.zig+1-1
......@@ -36,7 +36,7 @@ pub fn getShift(n: usize) usize {
3636/// Note that this function needs a lot of stack space and is marked
3737/// cold to hint against inlining into the caller.
3838pub fn convertSlow(comptime T: type, s: []const u8) BiasedFp(T) {
39 @setCold(true);
39 @branchHint(.cold);
4040
4141 const MantissaT = mantissaType(T);
4242 const min_exponent = -(1 << (math.floatExponentBits(T) - 1)) + 1;
lib/std/hash/xxhash.zig+6-6
......@@ -593,7 +593,7 @@ pub const XxHash3 = struct {
593593 }
594594
595595 fn hash3(seed: u64, input: anytype, noalias secret: *const [192]u8) u64 {
596 @setCold(true);
596 @branchHint(.cold);
597597 std.debug.assert(input.len > 0 and input.len < 4);
598598
599599 const flip: [2]u32 = @bitCast(secret[0..8].*);
......@@ -609,7 +609,7 @@ pub const XxHash3 = struct {
609609 }
610610
611611 fn hash8(seed: u64, input: anytype, noalias secret: *const [192]u8) u64 {
612 @setCold(true);
612 @branchHint(.cold);
613613 std.debug.assert(input.len >= 4 and input.len <= 8);
614614
615615 const flip: [2]u64 = @bitCast(secret[8..24].*);
......@@ -625,7 +625,7 @@ pub const XxHash3 = struct {
625625 }
626626
627627 fn hash16(seed: u64, input: anytype, noalias secret: *const [192]u8) u64 {
628 @setCold(true);
628 @branchHint(.cold);
629629 std.debug.assert(input.len > 8 and input.len <= 16);
630630
631631 const flip: [4]u64 = @bitCast(secret[24..56].*);
......@@ -641,7 +641,7 @@ pub const XxHash3 = struct {
641641 }
642642
643643 fn hash128(seed: u64, input: anytype, noalias secret: *const [192]u8) u64 {
644 @setCold(true);
644 @branchHint(.cold);
645645 std.debug.assert(input.len > 16 and input.len <= 128);
646646
647647 var acc = XxHash64.prime_1 *% @as(u64, input.len);
......@@ -657,7 +657,7 @@ pub const XxHash3 = struct {
657657 }
658658
659659 fn hash240(seed: u64, input: anytype, noalias secret: *const [192]u8) u64 {
660 @setCold(true);
660 @branchHint(.cold);
661661 std.debug.assert(input.len > 128 and input.len <= 240);
662662
663663 var acc = XxHash64.prime_1 *% @as(u64, input.len);
......@@ -676,7 +676,7 @@ pub const XxHash3 = struct {
676676 }
677677
678678 noinline fn hashLong(seed: u64, input: []const u8) u64 {
679 @setCold(true);
679 @branchHint(.cold);
680680 std.debug.assert(input.len >= 240);
681681
682682 const block_count = ((input.len - 1) / @sizeOf(Block)) * @sizeOf(Block);
lib/std/hash_map.zig+1-1
......@@ -1657,7 +1657,7 @@ pub fn HashMapUnmanaged(
16571657 }
16581658
16591659 fn grow(self: *Self, allocator: Allocator, new_capacity: Size, ctx: Context) Allocator.Error!void {
1660 @setCold(true);
1660 @branchHint(.cold);
16611661 const new_cap = @max(new_capacity, minimal_capacity);
16621662 assert(new_cap > self.capacity());
16631663 assert(std.math.isPowerOfTwo(new_cap));
lib/std/heap/WasmPageAllocator.zig+1-1
......@@ -61,7 +61,7 @@ const FreeBlock = struct {
6161 const not_found = maxInt(usize);
6262
6363 fn useRecycled(self: FreeBlock, num_pages: usize, log2_align: u8) usize {
64 @setCold(true);
64 @branchHint(.cold);
6565 for (self.data, 0..) |segment, i| {
6666 const spills_into_next = @as(i128, @bitCast(segment)) < 0;
6767 const has_enough_bits = @popCount(segment) >= num_pages;
lib/std/log.zig+1-1
......@@ -171,7 +171,7 @@ pub fn scoped(comptime scope: @Type(.EnumLiteral)) type {
171171 comptime format: []const u8,
172172 args: anytype,
173173 ) void {
174 @setCold(true);
174 @branchHint(.cold);
175175 log(.err, scope, format, args);
176176 }
177177
lib/std/once.zig+1-1
......@@ -25,7 +25,7 @@ pub fn Once(comptime f: fn () void) type {
2525 }
2626
2727 fn callSlow(self: *@This()) void {
28 @setCold(true);
28 @branchHint(.cold);
2929
3030 self.mutex.lock();
3131 defer self.mutex.unlock();
lib/std/posix.zig+1-1
......@@ -654,7 +654,7 @@ fn getRandomBytesDevURandom(buf: []u8) !void {
654654/// it raises SIGABRT followed by SIGKILL and finally lo
655655/// Invokes the current signal handler for SIGABRT, if any.
656656pub fn abort() noreturn {
657 @setCold(true);
657 @branchHint(.cold);
658658 // MSVCRT abort() sometimes opens a popup window which is undesirable, so
659659 // even when linking libc on Windows we use our own abort implementation.
660660 // See https://github.com/ziglang/zig/issues/2071 for more details.
lib/std/sort/pdq.zig+2-2
......@@ -203,7 +203,7 @@ fn partitionEqual(a: usize, b: usize, pivot: usize, context: anytype) usize {
203203///
204204/// returns `true` if the slice is sorted at the end. This function is `O(n)` worst-case.
205205fn partialInsertionSort(a: usize, b: usize, context: anytype) bool {
206 @setCold(true);
206 @branchHint(.cold);
207207
208208 // maximum number of adjacent out-of-order pairs that will get shifted
209209 const max_steps = 5;
......@@ -247,7 +247,7 @@ fn partialInsertionSort(a: usize, b: usize, context: anytype) bool {
247247}
248248
249249fn breakPatterns(a: usize, b: usize, context: anytype) void {
250 @setCold(true);
250 @branchHint(.cold);
251251
252252 const len = b - a;
253253 if (len < 8) return;
lib/std/zig/AstGen.zig+4-4
......@@ -11435,7 +11435,7 @@ fn appendErrorNodeNotes(
1143511435 args: anytype,
1143611436 notes: []const u32,
1143711437) Allocator.Error!void {
11438 @setCold(true);
11438 @branchHint(.cold);
1143911439 const string_bytes = &astgen.string_bytes;
1144011440 const msg: Zir.NullTerminatedString = @enumFromInt(string_bytes.items.len);
1144111441 try string_bytes.writer(astgen.gpa).print(format ++ "\x00", args);
......@@ -11526,7 +11526,7 @@ fn appendErrorTokNotesOff(
1152611526 args: anytype,
1152711527 notes: []const u32,
1152811528) !void {
11529 @setCold(true);
11529 @branchHint(.cold);
1153011530 const gpa = astgen.gpa;
1153111531 const string_bytes = &astgen.string_bytes;
1153211532 const msg: Zir.NullTerminatedString = @enumFromInt(string_bytes.items.len);
......@@ -11563,7 +11563,7 @@ fn errNoteTokOff(
1156311563 comptime format: []const u8,
1156411564 args: anytype,
1156511565) Allocator.Error!u32 {
11566 @setCold(true);
11566 @branchHint(.cold);
1156711567 const string_bytes = &astgen.string_bytes;
1156811568 const msg: Zir.NullTerminatedString = @enumFromInt(string_bytes.items.len);
1156911569 try string_bytes.writer(astgen.gpa).print(format ++ "\x00", args);
......@@ -11582,7 +11582,7 @@ fn errNoteNode(
1158211582 comptime format: []const u8,
1158311583 args: anytype,
1158411584) Allocator.Error!u32 {
11585 @setCold(true);
11585 @branchHint(.cold);
1158611586 const string_bytes = &astgen.string_bytes;
1158711587 const msg: Zir.NullTerminatedString = @enumFromInt(string_bytes.items.len);
1158811588 try string_bytes.writer(astgen.gpa).print(format ++ "\x00", args);
lib/std/zig/Parse.zig+6-6
......@@ -81,7 +81,7 @@ fn addExtra(p: *Parse, extra: anytype) Allocator.Error!Node.Index {
8181}
8282
8383fn warnExpected(p: *Parse, expected_token: Token.Tag) error{OutOfMemory}!void {
84 @setCold(true);
84 @branchHint(.cold);
8585 try p.warnMsg(.{
8686 .tag = .expected_token,
8787 .token = p.tok_i,
......@@ -90,12 +90,12 @@ fn warnExpected(p: *Parse, expected_token: Token.Tag) error{OutOfMemory}!void {
9090}
9191
9292fn warn(p: *Parse, error_tag: AstError.Tag) error{OutOfMemory}!void {
93 @setCold(true);
93 @branchHint(.cold);
9494 try p.warnMsg(.{ .tag = error_tag, .token = p.tok_i });
9595}
9696
9797fn warnMsg(p: *Parse, msg: Ast.Error) error{OutOfMemory}!void {
98 @setCold(true);
98 @branchHint(.cold);
9999 switch (msg.tag) {
100100 .expected_semi_after_decl,
101101 .expected_semi_after_stmt,
......@@ -141,12 +141,12 @@ fn warnMsg(p: *Parse, msg: Ast.Error) error{OutOfMemory}!void {
141141}
142142
143143fn fail(p: *Parse, tag: Ast.Error.Tag) error{ ParseError, OutOfMemory } {
144 @setCold(true);
144 @branchHint(.cold);
145145 return p.failMsg(.{ .tag = tag, .token = p.tok_i });
146146}
147147
148148fn failExpected(p: *Parse, expected_token: Token.Tag) error{ ParseError, OutOfMemory } {
149 @setCold(true);
149 @branchHint(.cold);
150150 return p.failMsg(.{
151151 .tag = .expected_token,
152152 .token = p.tok_i,
......@@ -155,7 +155,7 @@ fn failExpected(p: *Parse, expected_token: Token.Tag) error{ ParseError, OutOfMe
155155}
156156
157157fn failMsg(p: *Parse, msg: Ast.Error) error{ ParseError, OutOfMemory } {
158 @setCold(true);
158 @branchHint(.cold);
159159 try p.warnMsg(msg);
160160 return error.ParseError;
161161}
src/Compilation.zig+4-4
......@@ -5785,7 +5785,7 @@ fn failCObj(
57855785 comptime format: []const u8,
57865786 args: anytype,
57875787) SemaError {
5788 @setCold(true);
5788 @branchHint(.cold);
57895789 const diag_bundle = blk: {
57905790 const diag_bundle = try comp.gpa.create(CObject.Diag.Bundle);
57915791 diag_bundle.* = .{};
......@@ -5809,7 +5809,7 @@ fn failCObjWithOwnedDiagBundle(
58095809 c_object: *CObject,
58105810 diag_bundle: *CObject.Diag.Bundle,
58115811) SemaError {
5812 @setCold(true);
5812 @branchHint(.cold);
58135813 assert(diag_bundle.diags.len > 0);
58145814 {
58155815 comp.mutex.lock();
......@@ -5825,7 +5825,7 @@ fn failCObjWithOwnedDiagBundle(
58255825}
58265826
58275827fn failWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, comptime format: []const u8, args: anytype) SemaError {
5828 @setCold(true);
5828 @branchHint(.cold);
58295829 var bundle: ErrorBundle.Wip = undefined;
58305830 try bundle.init(comp.gpa);
58315831 errdefer bundle.deinit();
......@@ -5852,7 +5852,7 @@ fn failWin32ResourceWithOwnedBundle(
58525852 win32_resource: *Win32Resource,
58535853 err_bundle: ErrorBundle,
58545854) SemaError {
5855 @setCold(true);
5855 @branchHint(.cold);
58565856 {
58575857 comp.mutex.lock();
58585858 defer comp.mutex.unlock();
src/Sema.zig+2-2
......@@ -2471,7 +2471,7 @@ fn addFieldErrNote(
24712471 comptime format: []const u8,
24722472 args: anytype,
24732473) !void {
2474 @setCold(true);
2474 @branchHint(.cold);
24752475 const type_src = container_ty.srcLocOrNull(sema.pt.zcu) orelse return;
24762476 const field_src: LazySrcLoc = .{
24772477 .base_node_inst = type_src.base_node_inst,
......@@ -2507,7 +2507,7 @@ pub fn fail(
25072507}
25082508
25092509pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Zcu.ErrorMsg) error{ AnalysisFail, OutOfMemory } {
2510 @setCold(true);
2510 @branchHint(.cold);
25112511 const gpa = sema.gpa;
25122512 const zcu = sema.pt.zcu;
25132513
src/arch/aarch64/CodeGen.zig+2-2
......@@ -6357,14 +6357,14 @@ fn wantSafety(self: *Self) bool {
63576357}
63586358
63596359fn fail(self: *Self, comptime format: []const u8, args: anytype) InnerError {
6360 @setCold(true);
6360 @branchHint(.cold);
63616361 assert(self.err_msg == null);
63626362 self.err_msg = try ErrorMsg.create(self.gpa, self.src_loc, format, args);
63636363 return error.CodegenFail;
63646364}
63656365
63666366fn failSymbol(self: *Self, comptime format: []const u8, args: anytype) InnerError {
6367 @setCold(true);
6367 @branchHint(.cold);
63686368 assert(self.err_msg == null);
63696369 self.err_msg = try ErrorMsg.create(self.gpa, self.src_loc, format, args);
63706370 return error.CodegenFail;
src/arch/aarch64/Emit.zig+1-1
......@@ -430,7 +430,7 @@ fn writeInstruction(emit: *Emit, instruction: Instruction) !void {
430430}
431431
432432fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {
433 @setCold(true);
433 @branchHint(.cold);
434434 assert(emit.err_msg == null);
435435 const comp = emit.bin_file.comp;
436436 const gpa = comp.gpa;
src/arch/arm/CodeGen.zig+2-2
......@@ -6313,7 +6313,7 @@ fn wantSafety(self: *Self) bool {
63136313}
63146314
63156315fn fail(self: *Self, comptime format: []const u8, args: anytype) InnerError {
6316 @setCold(true);
6316 @branchHint(.cold);
63176317 assert(self.err_msg == null);
63186318 const gpa = self.gpa;
63196319 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 {
63216321}
63226322
63236323fn failSymbol(self: *Self, comptime format: []const u8, args: anytype) InnerError {
6324 @setCold(true);
6324 @branchHint(.cold);
63256325 assert(self.err_msg == null);
63266326 const gpa = self.gpa;
63276327 self.err_msg = try ErrorMsg.create(gpa, self.src_loc, format, args);
src/arch/arm/Emit.zig+1-1
......@@ -348,7 +348,7 @@ fn writeInstruction(emit: *Emit, instruction: Instruction) !void {
348348}
349349
350350fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {
351 @setCold(true);
351 @branchHint(.cold);
352352 assert(emit.err_msg == null);
353353 const comp = emit.bin_file.comp;
354354 const gpa = comp.gpa;
src/arch/riscv64/CodeGen.zig+2-2
......@@ -8223,14 +8223,14 @@ fn wantSafety(func: *Func) bool {
82238223}
82248224
82258225fn fail(func: *Func, comptime format: []const u8, args: anytype) InnerError {
8226 @setCold(true);
8226 @branchHint(.cold);
82278227 assert(func.err_msg == null);
82288228 func.err_msg = try ErrorMsg.create(func.gpa, func.src_loc, format, args);
82298229 return error.CodegenFail;
82308230}
82318231
82328232fn failSymbol(func: *Func, comptime format: []const u8, args: anytype) InnerError {
8233 @setCold(true);
8233 @branchHint(.cold);
82348234 assert(func.err_msg == null);
82358235 func.err_msg = try ErrorMsg.create(func.gpa, func.src_loc, format, args);
82368236 return error.CodegenFail;
src/arch/riscv64/Lower.zig+1-1
......@@ -583,7 +583,7 @@ fn pushPopRegList(lower: *Lower, comptime spilling: bool, reg_list: Mir.Register
583583}
584584
585585pub fn fail(lower: *Lower, comptime format: []const u8, args: anytype) Error {
586 @setCold(true);
586 @branchHint(.cold);
587587 assert(lower.err_msg == null);
588588 lower.err_msg = try ErrorMsg.create(lower.allocator, lower.src_loc, format, args);
589589 return error.LowerFail;
src/arch/sparc64/CodeGen.zig+1-1
......@@ -3533,7 +3533,7 @@ fn errUnionPayload(self: *Self, error_union_mcv: MCValue, error_union_ty: Type)
35333533}
35343534
35353535fn fail(self: *Self, comptime format: []const u8, args: anytype) InnerError {
3536 @setCold(true);
3536 @branchHint(.cold);
35373537 assert(self.err_msg == null);
35383538 const gpa = self.gpa;
35393539 self.err_msg = try ErrorMsg.create(gpa, self.src_loc, format, args);
src/arch/sparc64/Emit.zig+1-1
......@@ -511,7 +511,7 @@ fn dbgAdvancePCAndLine(emit: *Emit, line: u32, column: u32) !void {
511511}
512512
513513fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {
514 @setCold(true);
514 @branchHint(.cold);
515515 assert(emit.err_msg == null);
516516 const comp = emit.bin_file.comp;
517517 const gpa = comp.gpa;
src/arch/wasm/Emit.zig+1-1
......@@ -252,7 +252,7 @@ fn offset(self: Emit) u32 {
252252}
253253
254254fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {
255 @setCold(true);
255 @branchHint(.cold);
256256 std.debug.assert(emit.error_msg == null);
257257 const comp = emit.bin_file.base.comp;
258258 const zcu = comp.zcu.?;
src/arch/x86_64/CodeGen.zig+2-2
......@@ -19203,7 +19203,7 @@ fn resolveCallingConventionValues(
1920319203}
1920419204
1920519205fn fail(self: *Self, comptime format: []const u8, args: anytype) InnerError {
19206 @setCold(true);
19206 @branchHint(.cold);
1920719207 assert(self.err_msg == null);
1920819208 const gpa = self.gpa;
1920919209 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 {
1921119211}
1921219212
1921319213fn failSymbol(self: *Self, comptime format: []const u8, args: anytype) InnerError {
19214 @setCold(true);
19214 @branchHint(.cold);
1921519215 assert(self.err_msg == null);
1921619216 const gpa = self.gpa;
1921719217 self.err_msg = try ErrorMsg.create(gpa, self.src_loc, format, args);
src/arch/x86_64/Lower.zig+1-1
......@@ -293,7 +293,7 @@ pub fn lowerMir(lower: *Lower, index: Mir.Inst.Index) Error!struct {
293293}
294294
295295pub fn fail(lower: *Lower, comptime format: []const u8, args: anytype) Error {
296 @setCold(true);
296 @branchHint(.cold);
297297 assert(lower.err_msg == null);
298298 lower.err_msg = try Zcu.ErrorMsg.create(lower.allocator, lower.src_loc, format, args);
299299 return error.LowerFail;
src/codegen/c.zig+1-1
......@@ -626,7 +626,7 @@ pub const DeclGen = struct {
626626 }
627627
628628 fn fail(dg: *DeclGen, comptime format: []const u8, args: anytype) error{ AnalysisFail, OutOfMemory } {
629 @setCold(true);
629 @branchHint(.cold);
630630 const zcu = dg.pt.zcu;
631631 const src_loc = zcu.navSrcLoc(dg.pass.nav);
632632 dg.error_msg = try Zcu.ErrorMsg.create(dg.gpa, src_loc, format, args);
src/codegen/llvm.zig+2-2
......@@ -4618,7 +4618,7 @@ pub const NavGen = struct {
46184618 }
46194619
46204620 fn todo(ng: *NavGen, comptime format: []const u8, args: anytype) Error {
4621 @setCold(true);
4621 @branchHint(.cold);
46224622 assert(ng.err_msg == null);
46234623 const o = ng.object;
46244624 const gpa = o.gpa;
......@@ -4784,7 +4784,7 @@ pub const FuncGen = struct {
47844784 }
47854785
47864786 fn todo(self: *FuncGen, comptime format: []const u8, args: anytype) Error {
4787 @setCold(true);
4787 @branchHint(.cold);
47884788 return self.ng.todo(format, args);
47894789 }
47904790
src/codegen/spirv.zig+1-1
......@@ -410,7 +410,7 @@ const NavGen = struct {
410410 }
411411
412412 pub fn fail(self: *NavGen, comptime format: []const u8, args: anytype) Error {
413 @setCold(true);
413 @branchHint(.cold);
414414 const zcu = self.pt.zcu;
415415 const src_loc = zcu.navSrcLoc(self.owner_nav);
416416 assert(self.error_msg == null);
src/crash_report.zig+1-1
......@@ -153,8 +153,8 @@ fn writeFilePath(file: *Zcu.File, writer: anytype) !void {
153153}
154154
155155pub fn compilerPanic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace, maybe_ret_addr: ?usize) noreturn {
156 @branchHint(.cold);
156157 PanicSwitch.preDispatch();
157 @setCold(true);
158158 const ret_addr = maybe_ret_addr orelse @returnAddress();
159159 const stack_ctx: StackContext = .{ .current = .{ .ret_addr = ret_addr } };
160160 PanicSwitch.dispatch(error_return_trace, stack_ctx, msg);
test/behavior/basic.zig+1-1
......@@ -113,7 +113,7 @@ test "cold function" {
113113}
114114
115115fn thisIsAColdFn() void {
116 @setCold(true);
116 @branchHint(.cold);
117117}
118118
119119test "unicode escape in character literal" {
test/behavior/builtin_functions_returning_void_or_noreturn.zig+1-1
......@@ -22,7 +22,7 @@ test {
2222 try testing.expectEqual(noreturn, @TypeOf(if (true) @panic("") else {}));
2323 try testing.expectEqual({}, @prefetch(&val, .{}));
2424 try testing.expectEqual({}, @setAlignStack(16));
25 try testing.expectEqual({}, @setCold(true));
25 try testing.expectEqual({}, @branchHint(.cold));
2626 try testing.expectEqual({}, @setEvalBranchQuota(0));
2727 try testing.expectEqual({}, @setFloatMode(.optimized));
2828 try testing.expectEqual({}, @setRuntimeSafety(true));
test/cases/compile_errors/function-only_builtins_outside_function.zig+2-2
......@@ -3,7 +3,7 @@ comptime {
33}
44
55comptime {
6 @setCold(true);
6 @branchHint(.cold);
77}
88
99comptime {
......@@ -55,7 +55,7 @@ comptime {
5555// target=native
5656//
5757// :2:5: error: '@setAlignStack' outside function scope
58// :6:5: error: '@setCold' outside function scope
58// :6:5: error: '@branchHint' outside function scope
5959// :10:5: error: '@src' outside function scope
6060// :14:5: error: '@returnAddress' outside function scope
6161// :18:5: error: '@frameAddress' outside function scope