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 {...@@ -4340,6 +4340,13 @@ comptime {
4340 {#see_also|@sizeOf|@typeInfo#}4340 {#see_also|@sizeOf|@typeInfo#}
4341 {#header_close#}4341 {#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
4343 {#header_open|@breakpoint#}4350 {#header_open|@breakpoint#}
4344 <pre>{#syntax#}@breakpoint() void{#endsyntax#}</pre>4351 <pre>{#syntax#}@breakpoint() void{#endsyntax#}</pre>
4345 <p>4352 <p>
...@@ -5242,15 +5249,6 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val...@@ -5242,15 +5249,6 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
5242 </p>5249 </p>
5243 {#header_close#}5250 {#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
5254 {#header_open|@setEvalBranchQuota#}5252 {#header_open|@setEvalBranchQuota#}
5255 <pre>{#syntax#}@setEvalBranchQuota(comptime new_quota: u32) void{#endsyntax#}</pre>5253 <pre>{#syntax#}@setEvalBranchQuota(comptime new_quota: u32) void{#endsyntax#}</pre>
5256 <p>5254 <p>
doc/langref/test_functions.zig+2-2
...@@ -27,9 +27,9 @@ const WINAPI: std.builtin.CallingConvention = if (native_arch == .x86) .Stdcall...@@ -27,9 +27,9 @@ const WINAPI: std.builtin.CallingConvention = if (native_arch == .x86) .Stdcall
27extern "kernel32" fn ExitProcess(exit_code: u32) callconv(WINAPI) noreturn;27extern "kernel32" fn ExitProcess(exit_code: u32) callconv(WINAPI) noreturn;
28extern "c" fn atan2(a: f64, b: f64) f64;28extern "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").
31fn abort() noreturn {31fn abort() noreturn {
32 @setCold(true);32 @branchHint(.cold);
33 while (true) {}33 while (true) {}
34}34}
3535
lib/c.zig+1-1
...@@ -46,7 +46,7 @@ comptime {...@@ -46,7 +46,7 @@ comptime {
46// Avoid dragging in the runtime safety mechanisms into this .o file,46// Avoid dragging in the runtime safety mechanisms into this .o file,
47// unless we're trying to test this file.47// unless we're trying to test this file.
48pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {48pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {
49 @setCold(true);49 @branchHint(.cold);
50 _ = error_return_trace;50 _ = error_return_trace;
51 if (builtin.is_test) {51 if (builtin.is_test) {
52 std.debug.panic("{s}", .{msg});52 std.debug.panic("{s}", .{msg});
lib/compiler/aro/aro/Driver/Filesystem.zig+4-4
...@@ -4,7 +4,7 @@ const builtin = @import("builtin");...@@ -4,7 +4,7 @@ const builtin = @import("builtin");
4const is_windows = builtin.os.tag == .windows;4const is_windows = builtin.os.tag == .windows;
55
6fn readFileFake(entries: []const Filesystem.Entry, path: []const u8, buf: []u8) ?[]const u8 {6fn readFileFake(entries: []const Filesystem.Entry, path: []const u8, buf: []u8) ?[]const u8 {
7 @setCold(true);7 @branchHint(.cold);
8 for (entries) |entry| {8 for (entries) |entry| {
9 if (mem.eql(u8, entry.path, path)) {9 if (mem.eql(u8, entry.path, path)) {
10 const len = @min(entry.contents.len, buf.len);10 const len = @min(entry.contents.len, buf.len);
...@@ -16,7 +16,7 @@ fn readFileFake(entries: []const Filesystem.Entry, path: []const u8, buf: []u8)...@@ -16,7 +16,7 @@ fn readFileFake(entries: []const Filesystem.Entry, path: []const u8, buf: []u8)
16}16}
1717
18fn findProgramByNameFake(entries: []const Filesystem.Entry, name: []const u8, path: ?[]const u8, buf: []u8) ?[]const u8 {18fn findProgramByNameFake(entries: []const Filesystem.Entry, name: []const u8, path: ?[]const u8, buf: []u8) ?[]const u8 {
19 @setCold(true);19 @branchHint(.cold);
20 if (mem.indexOfScalar(u8, name, '/') != null) {20 if (mem.indexOfScalar(u8, name, '/') != null) {
21 @memcpy(buf[0..name.len], name);21 @memcpy(buf[0..name.len], name);
22 return buf[0..name.len];22 return buf[0..name.len];
...@@ -35,7 +35,7 @@ fn findProgramByNameFake(entries: []const Filesystem.Entry, name: []const u8, pa...@@ -35,7 +35,7 @@ fn findProgramByNameFake(entries: []const Filesystem.Entry, name: []const u8, pa
35}35}
3636
37fn canExecuteFake(entries: []const Filesystem.Entry, path: []const u8) bool {37fn canExecuteFake(entries: []const Filesystem.Entry, path: []const u8) bool {
38 @setCold(true);38 @branchHint(.cold);
39 for (entries) |entry| {39 for (entries) |entry| {
40 if (mem.eql(u8, entry.path, path)) {40 if (mem.eql(u8, entry.path, path)) {
41 return entry.executable;41 return entry.executable;
...@@ -45,7 +45,7 @@ fn canExecuteFake(entries: []const Filesystem.Entry, path: []const u8) bool {...@@ -45,7 +45,7 @@ fn canExecuteFake(entries: []const Filesystem.Entry, path: []const u8) bool {
45}45}
4646
47fn existsFake(entries: []const Filesystem.Entry, path: []const u8) bool {47fn existsFake(entries: []const Filesystem.Entry, path: []const u8) bool {
48 @setCold(true);48 @branchHint(.cold);
49 var buf: [std.fs.max_path_bytes]u8 = undefined;49 var buf: [std.fs.max_path_bytes]u8 = undefined;
50 var fib = std.heap.FixedBufferAllocator.init(&buf);50 var fib = std.heap.FixedBufferAllocator.init(&buf);
51 const resolved = std.fs.path.resolvePosix(fib.allocator(), &.{path}) catch return false;51 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 {...@@ -385,12 +385,12 @@ fn errExpectedToken(p: *Parser, expected: Token.Id, actual: Token.Id) Error {
385}385}
386386
387pub fn errStr(p: *Parser, tag: Diagnostics.Tag, tok_i: TokenIndex, str: []const u8) Compilation.Error!void {387pub fn errStr(p: *Parser, tag: Diagnostics.Tag, tok_i: TokenIndex, str: []const u8) Compilation.Error!void {
388 @setCold(true);388 @branchHint(.cold);
389 return p.errExtra(tag, tok_i, .{ .str = str });389 return p.errExtra(tag, tok_i, .{ .str = str });
390}390}
391391
392pub fn errExtra(p: *Parser, tag: Diagnostics.Tag, tok_i: TokenIndex, extra: Diagnostics.Message.Extra) Compilation.Error!void {392pub fn errExtra(p: *Parser, tag: Diagnostics.Tag, tok_i: TokenIndex, extra: Diagnostics.Message.Extra) Compilation.Error!void {
393 @setCold(true);393 @branchHint(.cold);
394 const tok = p.pp.tokens.get(tok_i);394 const tok = p.pp.tokens.get(tok_i);
395 var loc = tok.loc;395 var loc = tok.loc;
396 if (tok_i != 0 and tok.id == .eof) {396 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...@@ -407,12 +407,12 @@ pub fn errExtra(p: *Parser, tag: Diagnostics.Tag, tok_i: TokenIndex, extra: Diag
407}407}
408408
409pub fn errTok(p: *Parser, tag: Diagnostics.Tag, tok_i: TokenIndex) Compilation.Error!void {409pub fn errTok(p: *Parser, tag: Diagnostics.Tag, tok_i: TokenIndex) Compilation.Error!void {
410 @setCold(true);410 @branchHint(.cold);
411 return p.errExtra(tag, tok_i, .{ .none = {} });411 return p.errExtra(tag, tok_i, .{ .none = {} });
412}412}
413413
414pub fn err(p: *Parser, tag: Diagnostics.Tag) Compilation.Error!void {414pub fn err(p: *Parser, tag: Diagnostics.Tag) Compilation.Error!void {
415 @setCold(true);415 @branchHint(.cold);
416 return p.errExtra(tag, p.tok_i, .{ .none = {} });416 return p.errExtra(tag, p.tok_i, .{ .none = {} });
417}417}
418418
...@@ -638,7 +638,7 @@ fn pragma(p: *Parser) Compilation.Error!bool {...@@ -638,7 +638,7 @@ fn pragma(p: *Parser) Compilation.Error!bool {
638638
639/// Issue errors for top-level definitions whose type was never completed.639/// Issue errors for top-level definitions whose type was never completed.
640fn diagnoseIncompleteDefinitions(p: *Parser) !void {640fn diagnoseIncompleteDefinitions(p: *Parser) !void {
641 @setCold(true);641 @branchHint(.cold);
642642
643 const node_slices = p.nodes.slice();643 const node_slices = p.nodes.slice();
644 const tags = node_slices.items(.tag);644 const tags = node_slices.items(.tag);
lib/compiler/resinator/main.zig+4-4
...@@ -421,7 +421,7 @@ fn cliDiagnosticsToErrorBundle(...@@ -421,7 +421,7 @@ fn cliDiagnosticsToErrorBundle(
421 gpa: std.mem.Allocator,421 gpa: std.mem.Allocator,
422 diagnostics: *cli.Diagnostics,422 diagnostics: *cli.Diagnostics,
423) !ErrorBundle {423) !ErrorBundle {
424 @setCold(true);424 @branchHint(.cold);
425425
426 var bundle: ErrorBundle.Wip = undefined;426 var bundle: ErrorBundle.Wip = undefined;
427 try bundle.init(gpa);427 try bundle.init(gpa);
...@@ -468,7 +468,7 @@ fn diagnosticsToErrorBundle(...@@ -468,7 +468,7 @@ fn diagnosticsToErrorBundle(
468 diagnostics: *Diagnostics,468 diagnostics: *Diagnostics,
469 mappings: SourceMappings,469 mappings: SourceMappings,
470) !ErrorBundle {470) !ErrorBundle {
471 @setCold(true);471 @branchHint(.cold);
472472
473 var bundle: ErrorBundle.Wip = undefined;473 var bundle: ErrorBundle.Wip = undefined;
474 try bundle.init(gpa);474 try bundle.init(gpa);
...@@ -559,7 +559,7 @@ fn flushErrorMessageIntoBundle(wip: *ErrorBundle.Wip, msg: ErrorBundle.ErrorMess...@@ -559,7 +559,7 @@ fn flushErrorMessageIntoBundle(wip: *ErrorBundle.Wip, msg: ErrorBundle.ErrorMess
559}559}
560560
561fn errorStringToErrorBundle(allocator: std.mem.Allocator, comptime format: []const u8, args: anytype) !ErrorBundle {561fn errorStringToErrorBundle(allocator: std.mem.Allocator, comptime format: []const u8, args: anytype) !ErrorBundle {
562 @setCold(true);562 @branchHint(.cold);
563 var bundle: ErrorBundle.Wip = undefined;563 var bundle: ErrorBundle.Wip = undefined;
564 try bundle.init(allocator);564 try bundle.init(allocator);
565 errdefer bundle.deinit();565 errdefer bundle.deinit();
...@@ -574,7 +574,7 @@ fn aroDiagnosticsToErrorBundle(...@@ -574,7 +574,7 @@ fn aroDiagnosticsToErrorBundle(
574 fail_msg: []const u8,574 fail_msg: []const u8,
575 comp: *aro.Compilation,575 comp: *aro.Compilation,
576) !ErrorBundle {576) !ErrorBundle {
577 @setCold(true);577 @branchHint(.cold);
578578
579 var bundle: ErrorBundle.Wip = undefined;579 var bundle: ErrorBundle.Wip = undefined;
580 try bundle.init(gpa);580 try bundle.init(gpa);
lib/compiler_rt/common.zig+1-1
...@@ -72,7 +72,7 @@ pub const want_sparc_abi = builtin.cpu.arch.isSPARC();...@@ -72,7 +72,7 @@ pub const want_sparc_abi = builtin.cpu.arch.isSPARC();
72pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {72pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {
73 _ = error_return_trace;73 _ = error_return_trace;
74 if (builtin.is_test) {74 if (builtin.is_test) {
75 @setCold(true);75 @branchHint(.cold);
76 std.debug.panic("{s}", .{msg});76 std.debug.panic("{s}", .{msg});
77 } else {77 } else {
78 unreachable;78 unreachable;
lib/std/Thread/Futex.zig+4-4
...@@ -27,7 +27,7 @@ const atomic = std.atomic;...@@ -27,7 +27,7 @@ const atomic = std.atomic;
27/// The checking of `ptr` and `expect`, along with blocking the caller, is done atomically27/// The checking of `ptr` and `expect`, along with blocking the caller, is done atomically
28/// and totally ordered (sequentially consistent) with respect to other wait()/wake() calls on the same `ptr`.28/// and totally ordered (sequentially consistent) with respect to other wait()/wake() calls on the same `ptr`.
29pub fn wait(ptr: *const atomic.Value(u32), expect: u32) void {29pub fn wait(ptr: *const atomic.Value(u32), expect: u32) void {
30 @setCold(true);30 @branchHint(.cold);
3131
32 Impl.wait(ptr, expect, null) catch |err| switch (err) {32 Impl.wait(ptr, expect, null) catch |err| switch (err) {
33 error.Timeout => unreachable, // null timeout meant to wait forever33 error.Timeout => unreachable, // null timeout meant to wait forever
...@@ -43,7 +43,7 @@ pub fn wait(ptr: *const atomic.Value(u32), expect: u32) void {...@@ -43,7 +43,7 @@ pub fn wait(ptr: *const atomic.Value(u32), expect: u32) void {
43/// The checking of `ptr` and `expect`, along with blocking the caller, is done atomically43/// The checking of `ptr` and `expect`, along with blocking the caller, is done atomically
44/// and totally ordered (sequentially consistent) with respect to other wait()/wake() calls on the same `ptr`.44/// and totally ordered (sequentially consistent) with respect to other wait()/wake() calls on the same `ptr`.
45pub fn timedWait(ptr: *const atomic.Value(u32), expect: u32, timeout_ns: u64) error{Timeout}!void {45pub fn timedWait(ptr: *const atomic.Value(u32), expect: u32, timeout_ns: u64) error{Timeout}!void {
46 @setCold(true);46 @branchHint(.cold);
4747
48 // Avoid calling into the OS for no-op timeouts.48 // Avoid calling into the OS for no-op timeouts.
49 if (timeout_ns == 0) {49 if (timeout_ns == 0) {
...@@ -56,7 +56,7 @@ pub fn timedWait(ptr: *const atomic.Value(u32), expect: u32, timeout_ns: u64) er...@@ -56,7 +56,7 @@ pub fn timedWait(ptr: *const atomic.Value(u32), expect: u32, timeout_ns: u64) er
5656
57/// Unblocks at most `max_waiters` callers blocked in a `wait()` call on `ptr`.57/// Unblocks at most `max_waiters` callers blocked in a `wait()` call on `ptr`.
58pub fn wake(ptr: *const atomic.Value(u32), max_waiters: u32) void {58pub fn wake(ptr: *const atomic.Value(u32), max_waiters: u32) void {
59 @setCold(true);59 @branchHint(.cold);
6060
61 // Avoid calling into the OS if there's nothing to wake up.61 // Avoid calling into the OS if there's nothing to wake up.
62 if (max_waiters == 0) {62 if (max_waiters == 0) {
...@@ -1048,7 +1048,7 @@ pub const Deadline = struct {...@@ -1048,7 +1048,7 @@ pub const Deadline = struct {
1048 /// - A spurious wake occurs.1048 /// - A spurious wake occurs.
1049 /// - The deadline expires; In which case `error.Timeout` is returned.1049 /// - The deadline expires; In which case `error.Timeout` is returned.
1050 pub fn wait(self: *Deadline, ptr: *const atomic.Value(u32), expect: u32) error{Timeout}!void {1050 pub fn wait(self: *Deadline, ptr: *const atomic.Value(u32), expect: u32) error{Timeout}!void {
1051 @setCold(true);1051 @branchHint(.cold);
10521052
1053 // Check if we actually have a timeout to wait until.1053 // Check if we actually have a timeout to wait until.
1054 // If not just wait "forever".1054 // If not just wait "forever".
lib/std/Thread/Mutex.zig+1-1
...@@ -169,7 +169,7 @@ const FutexImpl = struct {...@@ -169,7 +169,7 @@ const FutexImpl = struct {
169 }169 }
170170
171 fn lockSlow(self: *@This()) void {171 fn lockSlow(self: *@This()) void {
172 @setCold(true);172 @branchHint(.cold);
173173
174 // Avoid doing an atomic swap below if we already know the state is contended.174 // Avoid doing an atomic swap below if we already know the state is contended.
175 // An atomic swap unconditionally stores which marks the cache-line as modified unnecessarily.175 // 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 {...@@ -107,7 +107,7 @@ const FutexImpl = struct {
107 }107 }
108108
109 fn waitUntilSet(self: *Impl, timeout: ?u64) error{Timeout}!void {109 fn waitUntilSet(self: *Impl, timeout: ?u64) error{Timeout}!void {
110 @setCold(true);110 @branchHint(.cold);
111111
112 // Try to set the state from `unset` to `waiting` to indicate112 // Try to set the state from `unset` to `waiting` to indicate
113 // to the set() thread that others are blocked on the ResetEvent.113 // to the set() thread that others are blocked on the ResetEvent.
lib/std/builtin.zig+7-7
...@@ -779,7 +779,7 @@ else...@@ -779,7 +779,7 @@ else
779/// This function is used by the Zig language code generation and779/// This function is used by the Zig language code generation and
780/// therefore must be kept in sync with the compiler implementation.780/// therefore must be kept in sync with the compiler implementation.
781pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace, ret_addr: ?usize) noreturn {781pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace, ret_addr: ?usize) noreturn {
782 @setCold(true);782 @branchHint(.cold);
783783
784 // For backends that cannot handle the language features depended on by the784 // For backends that cannot handle the language features depended on by the
785 // default panic handler, we have a simpler panic handler:785 // default panic handler, we have a simpler panic handler:
...@@ -896,27 +896,27 @@ pub fn checkNonScalarSentinel(expected: anytype, actual: @TypeOf(expected)) void...@@ -896,27 +896,27 @@ pub fn checkNonScalarSentinel(expected: anytype, actual: @TypeOf(expected)) void
896}896}
897897
898pub fn panicSentinelMismatch(expected: anytype, actual: @TypeOf(expected)) noreturn {898pub fn panicSentinelMismatch(expected: anytype, actual: @TypeOf(expected)) noreturn {
899 @setCold(true);899 @branchHint(.cold);
900 std.debug.panicExtra(null, @returnAddress(), "sentinel mismatch: expected {any}, found {any}", .{ expected, actual });900 std.debug.panicExtra(null, @returnAddress(), "sentinel mismatch: expected {any}, found {any}", .{ expected, actual });
901}901}
902902
903pub fn panicUnwrapError(st: ?*StackTrace, err: anyerror) noreturn {903pub fn panicUnwrapError(st: ?*StackTrace, err: anyerror) noreturn {
904 @setCold(true);904 @branchHint(.cold);
905 std.debug.panicExtra(st, @returnAddress(), "attempt to unwrap error: {s}", .{@errorName(err)});905 std.debug.panicExtra(st, @returnAddress(), "attempt to unwrap error: {s}", .{@errorName(err)});
906}906}
907907
908pub fn panicOutOfBounds(index: usize, len: usize) noreturn {908pub fn panicOutOfBounds(index: usize, len: usize) noreturn {
909 @setCold(true);909 @branchHint(.cold);
910 std.debug.panicExtra(null, @returnAddress(), "index out of bounds: index {d}, len {d}", .{ index, len });910 std.debug.panicExtra(null, @returnAddress(), "index out of bounds: index {d}, len {d}", .{ index, len });
911}911}
912912
913pub fn panicStartGreaterThanEnd(start: usize, end: usize) noreturn {913pub fn panicStartGreaterThanEnd(start: usize, end: usize) noreturn {
914 @setCold(true);914 @branchHint(.cold);
915 std.debug.panicExtra(null, @returnAddress(), "start index {d} is larger than end index {d}", .{ start, end });915 std.debug.panicExtra(null, @returnAddress(), "start index {d} is larger than end index {d}", .{ start, end });
916}916}
917917
918pub fn panicInactiveUnionField(active: anytype, wanted: @TypeOf(active)) noreturn {918pub fn panicInactiveUnionField(active: anytype, wanted: @TypeOf(active)) noreturn {
919 @setCold(true);919 @branchHint(.cold);
920 std.debug.panicExtra(null, @returnAddress(), "access of union field '{s}' while field '{s}' is active", .{ @tagName(wanted), @tagName(active) });920 std.debug.panicExtra(null, @returnAddress(), "access of union field '{s}' while field '{s}' is active", .{ @tagName(wanted), @tagName(active) });
921}921}
922922
...@@ -949,7 +949,7 @@ pub const panic_messages = struct {...@@ -949,7 +949,7 @@ pub const panic_messages = struct {
949};949};
950950
951pub noinline fn returnError(st: *StackTrace) void {951pub noinline fn returnError(st: *StackTrace) void {
952 @setCold(true);952 @branchHint(.cold);
953 @setRuntimeSafety(false);953 @setRuntimeSafety(false);
954 addErrRetTraceAddr(st, @returnAddress());954 addErrRetTraceAddr(st, @returnAddress());
955}955}
lib/std/debug.zig+3-3
...@@ -409,7 +409,7 @@ pub fn assertReadable(slice: []const volatile u8) void {...@@ -409,7 +409,7 @@ pub fn assertReadable(slice: []const volatile u8) void {
409}409}
410410
411pub fn panic(comptime format: []const u8, args: anytype) noreturn {411pub fn panic(comptime format: []const u8, args: anytype) noreturn {
412 @setCold(true);412 @branchHint(.cold);
413413
414 panicExtra(@errorReturnTrace(), @returnAddress(), format, args);414 panicExtra(@errorReturnTrace(), @returnAddress(), format, args);
415}415}
...@@ -422,7 +422,7 @@ pub fn panicExtra(...@@ -422,7 +422,7 @@ pub fn panicExtra(
422 comptime format: []const u8,422 comptime format: []const u8,
423 args: anytype,423 args: anytype,
424) noreturn {424) noreturn {
425 @setCold(true);425 @branchHint(.cold);
426426
427 const size = 0x1000;427 const size = 0x1000;
428 const trunc_msg = "(msg truncated)";428 const trunc_msg = "(msg truncated)";
...@@ -450,7 +450,7 @@ threadlocal var panic_stage: usize = 0;...@@ -450,7 +450,7 @@ threadlocal var panic_stage: usize = 0;
450// `panicImpl` could be useful in implementing a custom panic handler which450// `panicImpl` could be useful in implementing a custom panic handler which
451// calls the default handler (on supported platforms)451// calls the default handler (on supported platforms)
452pub fn panicImpl(trace: ?*const std.builtin.StackTrace, first_trace_addr: ?usize, msg: []const u8) noreturn {452pub fn panicImpl(trace: ?*const std.builtin.StackTrace, first_trace_addr: ?usize, msg: []const u8) noreturn {
453 @setCold(true);453 @branchHint(.cold);
454454
455 if (enable_segfault_handler) {455 if (enable_segfault_handler) {
456 // If a segfault happens while panicking, we want it to actually segfault, not trigger456 // 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 {...@@ -36,7 +36,7 @@ pub fn getShift(n: usize) usize {
36/// Note that this function needs a lot of stack space and is marked36/// Note that this function needs a lot of stack space and is marked
37/// cold to hint against inlining into the caller.37/// cold to hint against inlining into the caller.
38pub fn convertSlow(comptime T: type, s: []const u8) BiasedFp(T) {38pub fn convertSlow(comptime T: type, s: []const u8) BiasedFp(T) {
39 @setCold(true);39 @branchHint(.cold);
4040
41 const MantissaT = mantissaType(T);41 const MantissaT = mantissaType(T);
42 const min_exponent = -(1 << (math.floatExponentBits(T) - 1)) + 1;42 const min_exponent = -(1 << (math.floatExponentBits(T) - 1)) + 1;
lib/std/hash/xxhash.zig+6-6
...@@ -593,7 +593,7 @@ pub const XxHash3 = struct {...@@ -593,7 +593,7 @@ pub const XxHash3 = struct {
593 }593 }
594594
595 fn hash3(seed: u64, input: anytype, noalias secret: *const [192]u8) u64 {595 fn hash3(seed: u64, input: anytype, noalias secret: *const [192]u8) u64 {
596 @setCold(true);596 @branchHint(.cold);
597 std.debug.assert(input.len > 0 and input.len < 4);597 std.debug.assert(input.len > 0 and input.len < 4);
598598
599 const flip: [2]u32 = @bitCast(secret[0..8].*);599 const flip: [2]u32 = @bitCast(secret[0..8].*);
...@@ -609,7 +609,7 @@ pub const XxHash3 = struct {...@@ -609,7 +609,7 @@ pub const XxHash3 = struct {
609 }609 }
610610
611 fn hash8(seed: u64, input: anytype, noalias secret: *const [192]u8) u64 {611 fn hash8(seed: u64, input: anytype, noalias secret: *const [192]u8) u64 {
612 @setCold(true);612 @branchHint(.cold);
613 std.debug.assert(input.len >= 4 and input.len <= 8);613 std.debug.assert(input.len >= 4 and input.len <= 8);
614614
615 const flip: [2]u64 = @bitCast(secret[8..24].*);615 const flip: [2]u64 = @bitCast(secret[8..24].*);
...@@ -625,7 +625,7 @@ pub const XxHash3 = struct {...@@ -625,7 +625,7 @@ pub const XxHash3 = struct {
625 }625 }
626626
627 fn hash16(seed: u64, input: anytype, noalias secret: *const [192]u8) u64 {627 fn hash16(seed: u64, input: anytype, noalias secret: *const [192]u8) u64 {
628 @setCold(true);628 @branchHint(.cold);
629 std.debug.assert(input.len > 8 and input.len <= 16);629 std.debug.assert(input.len > 8 and input.len <= 16);
630630
631 const flip: [4]u64 = @bitCast(secret[24..56].*);631 const flip: [4]u64 = @bitCast(secret[24..56].*);
...@@ -641,7 +641,7 @@ pub const XxHash3 = struct {...@@ -641,7 +641,7 @@ pub const XxHash3 = struct {
641 }641 }
642642
643 fn hash128(seed: u64, input: anytype, noalias secret: *const [192]u8) u64 {643 fn hash128(seed: u64, input: anytype, noalias secret: *const [192]u8) u64 {
644 @setCold(true);644 @branchHint(.cold);
645 std.debug.assert(input.len > 16 and input.len <= 128);645 std.debug.assert(input.len > 16 and input.len <= 128);
646646
647 var acc = XxHash64.prime_1 *% @as(u64, input.len);647 var acc = XxHash64.prime_1 *% @as(u64, input.len);
...@@ -657,7 +657,7 @@ pub const XxHash3 = struct {...@@ -657,7 +657,7 @@ pub const XxHash3 = struct {
657 }657 }
658658
659 fn hash240(seed: u64, input: anytype, noalias secret: *const [192]u8) u64 {659 fn hash240(seed: u64, input: anytype, noalias secret: *const [192]u8) u64 {
660 @setCold(true);660 @branchHint(.cold);
661 std.debug.assert(input.len > 128 and input.len <= 240);661 std.debug.assert(input.len > 128 and input.len <= 240);
662662
663 var acc = XxHash64.prime_1 *% @as(u64, input.len);663 var acc = XxHash64.prime_1 *% @as(u64, input.len);
...@@ -676,7 +676,7 @@ pub const XxHash3 = struct {...@@ -676,7 +676,7 @@ pub const XxHash3 = struct {
676 }676 }
677677
678 noinline fn hashLong(seed: u64, input: []const u8) u64 {678 noinline fn hashLong(seed: u64, input: []const u8) u64 {
679 @setCold(true);679 @branchHint(.cold);
680 std.debug.assert(input.len >= 240);680 std.debug.assert(input.len >= 240);
681681
682 const block_count = ((input.len - 1) / @sizeOf(Block)) * @sizeOf(Block);682 const block_count = ((input.len - 1) / @sizeOf(Block)) * @sizeOf(Block);
lib/std/hash_map.zig+1-1
...@@ -1657,7 +1657,7 @@ pub fn HashMapUnmanaged(...@@ -1657,7 +1657,7 @@ pub fn HashMapUnmanaged(
1657 }1657 }
16581658
1659 fn grow(self: *Self, allocator: Allocator, new_capacity: Size, ctx: Context) Allocator.Error!void {1659 fn grow(self: *Self, allocator: Allocator, new_capacity: Size, ctx: Context) Allocator.Error!void {
1660 @setCold(true);1660 @branchHint(.cold);
1661 const new_cap = @max(new_capacity, minimal_capacity);1661 const new_cap = @max(new_capacity, minimal_capacity);
1662 assert(new_cap > self.capacity());1662 assert(new_cap > self.capacity());
1663 assert(std.math.isPowerOfTwo(new_cap));1663 assert(std.math.isPowerOfTwo(new_cap));
lib/std/heap/WasmPageAllocator.zig+1-1
...@@ -61,7 +61,7 @@ const FreeBlock = struct {...@@ -61,7 +61,7 @@ const FreeBlock = struct {
61 const not_found = maxInt(usize);61 const not_found = maxInt(usize);
6262
63 fn useRecycled(self: FreeBlock, num_pages: usize, log2_align: u8) usize {63 fn useRecycled(self: FreeBlock, num_pages: usize, log2_align: u8) usize {
64 @setCold(true);64 @branchHint(.cold);
65 for (self.data, 0..) |segment, i| {65 for (self.data, 0..) |segment, i| {
66 const spills_into_next = @as(i128, @bitCast(segment)) < 0;66 const spills_into_next = @as(i128, @bitCast(segment)) < 0;
67 const has_enough_bits = @popCount(segment) >= num_pages;67 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 {...@@ -171,7 +171,7 @@ pub fn scoped(comptime scope: @Type(.EnumLiteral)) type {
171 comptime format: []const u8,171 comptime format: []const u8,
172 args: anytype,172 args: anytype,
173 ) void {173 ) void {
174 @setCold(true);174 @branchHint(.cold);
175 log(.err, scope, format, args);175 log(.err, scope, format, args);
176 }176 }
177177
lib/std/once.zig+1-1
...@@ -25,7 +25,7 @@ pub fn Once(comptime f: fn () void) type {...@@ -25,7 +25,7 @@ pub fn Once(comptime f: fn () void) type {
25 }25 }
2626
27 fn callSlow(self: *@This()) void {27 fn callSlow(self: *@This()) void {
28 @setCold(true);28 @branchHint(.cold);
2929
30 self.mutex.lock();30 self.mutex.lock();
31 defer self.mutex.unlock();31 defer self.mutex.unlock();
lib/std/posix.zig+1-1
...@@ -654,7 +654,7 @@ fn getRandomBytesDevURandom(buf: []u8) !void {...@@ -654,7 +654,7 @@ fn getRandomBytesDevURandom(buf: []u8) !void {
654/// it raises SIGABRT followed by SIGKILL and finally lo654/// it raises SIGABRT followed by SIGKILL and finally lo
655/// Invokes the current signal handler for SIGABRT, if any.655/// Invokes the current signal handler for SIGABRT, if any.
656pub fn abort() noreturn {656pub fn abort() noreturn {
657 @setCold(true);657 @branchHint(.cold);
658 // MSVCRT abort() sometimes opens a popup window which is undesirable, so658 // MSVCRT abort() sometimes opens a popup window which is undesirable, so
659 // even when linking libc on Windows we use our own abort implementation.659 // even when linking libc on Windows we use our own abort implementation.
660 // See https://github.com/ziglang/zig/issues/2071 for more details.660 // 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 {...@@ -203,7 +203,7 @@ fn partitionEqual(a: usize, b: usize, pivot: usize, context: anytype) usize {
203///203///
204/// returns `true` if the slice is sorted at the end. This function is `O(n)` worst-case.204/// returns `true` if the slice is sorted at the end. This function is `O(n)` worst-case.
205fn partialInsertionSort(a: usize, b: usize, context: anytype) bool {205fn partialInsertionSort(a: usize, b: usize, context: anytype) bool {
206 @setCold(true);206 @branchHint(.cold);
207207
208 // maximum number of adjacent out-of-order pairs that will get shifted208 // maximum number of adjacent out-of-order pairs that will get shifted
209 const max_steps = 5;209 const max_steps = 5;
...@@ -247,7 +247,7 @@ fn partialInsertionSort(a: usize, b: usize, context: anytype) bool {...@@ -247,7 +247,7 @@ fn partialInsertionSort(a: usize, b: usize, context: anytype) bool {
247}247}
248248
249fn breakPatterns(a: usize, b: usize, context: anytype) void {249fn breakPatterns(a: usize, b: usize, context: anytype) void {
250 @setCold(true);250 @branchHint(.cold);
251251
252 const len = b - a;252 const len = b - a;
253 if (len < 8) return;253 if (len < 8) return;
lib/std/zig/AstGen.zig+4-4
...@@ -11435,7 +11435,7 @@ fn appendErrorNodeNotes(...@@ -11435,7 +11435,7 @@ fn appendErrorNodeNotes(
11435 args: anytype,11435 args: anytype,
11436 notes: []const u32,11436 notes: []const u32,
11437) Allocator.Error!void {11437) Allocator.Error!void {
11438 @setCold(true);11438 @branchHint(.cold);
11439 const string_bytes = &astgen.string_bytes;11439 const string_bytes = &astgen.string_bytes;
11440 const msg: Zir.NullTerminatedString = @enumFromInt(string_bytes.items.len);11440 const msg: Zir.NullTerminatedString = @enumFromInt(string_bytes.items.len);
11441 try string_bytes.writer(astgen.gpa).print(format ++ "\x00", args);11441 try string_bytes.writer(astgen.gpa).print(format ++ "\x00", args);
...@@ -11526,7 +11526,7 @@ fn appendErrorTokNotesOff(...@@ -11526,7 +11526,7 @@ fn appendErrorTokNotesOff(
11526 args: anytype,11526 args: anytype,
11527 notes: []const u32,11527 notes: []const u32,
11528) !void {11528) !void {
11529 @setCold(true);11529 @branchHint(.cold);
11530 const gpa = astgen.gpa;11530 const gpa = astgen.gpa;
11531 const string_bytes = &astgen.string_bytes;11531 const string_bytes = &astgen.string_bytes;
11532 const msg: Zir.NullTerminatedString = @enumFromInt(string_bytes.items.len);11532 const msg: Zir.NullTerminatedString = @enumFromInt(string_bytes.items.len);
...@@ -11563,7 +11563,7 @@ fn errNoteTokOff(...@@ -11563,7 +11563,7 @@ fn errNoteTokOff(
11563 comptime format: []const u8,11563 comptime format: []const u8,
11564 args: anytype,11564 args: anytype,
11565) Allocator.Error!u32 {11565) Allocator.Error!u32 {
11566 @setCold(true);11566 @branchHint(.cold);
11567 const string_bytes = &astgen.string_bytes;11567 const string_bytes = &astgen.string_bytes;
11568 const msg: Zir.NullTerminatedString = @enumFromInt(string_bytes.items.len);11568 const msg: Zir.NullTerminatedString = @enumFromInt(string_bytes.items.len);
11569 try string_bytes.writer(astgen.gpa).print(format ++ "\x00", args);11569 try string_bytes.writer(astgen.gpa).print(format ++ "\x00", args);
...@@ -11582,7 +11582,7 @@ fn errNoteNode(...@@ -11582,7 +11582,7 @@ fn errNoteNode(
11582 comptime format: []const u8,11582 comptime format: []const u8,
11583 args: anytype,11583 args: anytype,
11584) Allocator.Error!u32 {11584) Allocator.Error!u32 {
11585 @setCold(true);11585 @branchHint(.cold);
11586 const string_bytes = &astgen.string_bytes;11586 const string_bytes = &astgen.string_bytes;
11587 const msg: Zir.NullTerminatedString = @enumFromInt(string_bytes.items.len);11587 const msg: Zir.NullTerminatedString = @enumFromInt(string_bytes.items.len);
11588 try string_bytes.writer(astgen.gpa).print(format ++ "\x00", args);11588 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 {...@@ -81,7 +81,7 @@ fn addExtra(p: *Parse, extra: anytype) Allocator.Error!Node.Index {
81}81}
8282
83fn warnExpected(p: *Parse, expected_token: Token.Tag) error{OutOfMemory}!void {83fn warnExpected(p: *Parse, expected_token: Token.Tag) error{OutOfMemory}!void {
84 @setCold(true);84 @branchHint(.cold);
85 try p.warnMsg(.{85 try p.warnMsg(.{
86 .tag = .expected_token,86 .tag = .expected_token,
87 .token = p.tok_i,87 .token = p.tok_i,
...@@ -90,12 +90,12 @@ fn warnExpected(p: *Parse, expected_token: Token.Tag) error{OutOfMemory}!void {...@@ -90,12 +90,12 @@ fn warnExpected(p: *Parse, expected_token: Token.Tag) error{OutOfMemory}!void {
90}90}
9191
92fn warn(p: *Parse, error_tag: AstError.Tag) error{OutOfMemory}!void {92fn warn(p: *Parse, error_tag: AstError.Tag) error{OutOfMemory}!void {
93 @setCold(true);93 @branchHint(.cold);
94 try p.warnMsg(.{ .tag = error_tag, .token = p.tok_i });94 try p.warnMsg(.{ .tag = error_tag, .token = p.tok_i });
95}95}
9696
97fn warnMsg(p: *Parse, msg: Ast.Error) error{OutOfMemory}!void {97fn warnMsg(p: *Parse, msg: Ast.Error) error{OutOfMemory}!void {
98 @setCold(true);98 @branchHint(.cold);
99 switch (msg.tag) {99 switch (msg.tag) {
100 .expected_semi_after_decl,100 .expected_semi_after_decl,
101 .expected_semi_after_stmt,101 .expected_semi_after_stmt,
...@@ -141,12 +141,12 @@ fn warnMsg(p: *Parse, msg: Ast.Error) error{OutOfMemory}!void {...@@ -141,12 +141,12 @@ fn warnMsg(p: *Parse, msg: Ast.Error) error{OutOfMemory}!void {
141}141}
142142
143fn fail(p: *Parse, tag: Ast.Error.Tag) error{ ParseError, OutOfMemory } {143fn fail(p: *Parse, tag: Ast.Error.Tag) error{ ParseError, OutOfMemory } {
144 @setCold(true);144 @branchHint(.cold);
145 return p.failMsg(.{ .tag = tag, .token = p.tok_i });145 return p.failMsg(.{ .tag = tag, .token = p.tok_i });
146}146}
147147
148fn failExpected(p: *Parse, expected_token: Token.Tag) error{ ParseError, OutOfMemory } {148fn failExpected(p: *Parse, expected_token: Token.Tag) error{ ParseError, OutOfMemory } {
149 @setCold(true);149 @branchHint(.cold);
150 return p.failMsg(.{150 return p.failMsg(.{
151 .tag = .expected_token,151 .tag = .expected_token,
152 .token = p.tok_i,152 .token = p.tok_i,
...@@ -155,7 +155,7 @@ fn failExpected(p: *Parse, expected_token: Token.Tag) error{ ParseError, OutOfMe...@@ -155,7 +155,7 @@ fn failExpected(p: *Parse, expected_token: Token.Tag) error{ ParseError, OutOfMe
155}155}
156156
157fn failMsg(p: *Parse, msg: Ast.Error) error{ ParseError, OutOfMemory } {157fn failMsg(p: *Parse, msg: Ast.Error) error{ ParseError, OutOfMemory } {
158 @setCold(true);158 @branchHint(.cold);
159 try p.warnMsg(msg);159 try p.warnMsg(msg);
160 return error.ParseError;160 return error.ParseError;
161}161}
src/Compilation.zig+4-4
...@@ -5785,7 +5785,7 @@ fn failCObj(...@@ -5785,7 +5785,7 @@ fn failCObj(
5785 comptime format: []const u8,5785 comptime format: []const u8,
5786 args: anytype,5786 args: anytype,
5787) SemaError {5787) SemaError {
5788 @setCold(true);5788 @branchHint(.cold);
5789 const diag_bundle = blk: {5789 const diag_bundle = blk: {
5790 const diag_bundle = try comp.gpa.create(CObject.Diag.Bundle);5790 const diag_bundle = try comp.gpa.create(CObject.Diag.Bundle);
5791 diag_bundle.* = .{};5791 diag_bundle.* = .{};
...@@ -5809,7 +5809,7 @@ fn failCObjWithOwnedDiagBundle(...@@ -5809,7 +5809,7 @@ fn failCObjWithOwnedDiagBundle(
5809 c_object: *CObject,5809 c_object: *CObject,
5810 diag_bundle: *CObject.Diag.Bundle,5810 diag_bundle: *CObject.Diag.Bundle,
5811) SemaError {5811) SemaError {
5812 @setCold(true);5812 @branchHint(.cold);
5813 assert(diag_bundle.diags.len > 0);5813 assert(diag_bundle.diags.len > 0);
5814 {5814 {
5815 comp.mutex.lock();5815 comp.mutex.lock();
...@@ -5825,7 +5825,7 @@ fn failCObjWithOwnedDiagBundle(...@@ -5825,7 +5825,7 @@ fn failCObjWithOwnedDiagBundle(
5825}5825}
58265826
5827fn failWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, comptime format: []const u8, args: anytype) SemaError {5827fn failWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, comptime format: []const u8, args: anytype) SemaError {
5828 @setCold(true);5828 @branchHint(.cold);
5829 var bundle: ErrorBundle.Wip = undefined;5829 var bundle: ErrorBundle.Wip = undefined;
5830 try bundle.init(comp.gpa);5830 try bundle.init(comp.gpa);
5831 errdefer bundle.deinit();5831 errdefer bundle.deinit();
...@@ -5852,7 +5852,7 @@ fn failWin32ResourceWithOwnedBundle(...@@ -5852,7 +5852,7 @@ fn failWin32ResourceWithOwnedBundle(
5852 win32_resource: *Win32Resource,5852 win32_resource: *Win32Resource,
5853 err_bundle: ErrorBundle,5853 err_bundle: ErrorBundle,
5854) SemaError {5854) SemaError {
5855 @setCold(true);5855 @branchHint(.cold);
5856 {5856 {
5857 comp.mutex.lock();5857 comp.mutex.lock();
5858 defer comp.mutex.unlock();5858 defer comp.mutex.unlock();
src/Sema.zig+2-2
...@@ -2471,7 +2471,7 @@ fn addFieldErrNote(...@@ -2471,7 +2471,7 @@ fn addFieldErrNote(
2471 comptime format: []const u8,2471 comptime format: []const u8,
2472 args: anytype,2472 args: anytype,
2473) !void {2473) !void {
2474 @setCold(true);2474 @branchHint(.cold);
2475 const type_src = container_ty.srcLocOrNull(sema.pt.zcu) orelse return;2475 const type_src = container_ty.srcLocOrNull(sema.pt.zcu) orelse return;
2476 const field_src: LazySrcLoc = .{2476 const field_src: LazySrcLoc = .{
2477 .base_node_inst = type_src.base_node_inst,2477 .base_node_inst = type_src.base_node_inst,
...@@ -2507,7 +2507,7 @@ pub fn fail(...@@ -2507,7 +2507,7 @@ pub fn fail(
2507}2507}
25082508
2509pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Zcu.ErrorMsg) error{ AnalysisFail, OutOfMemory } {2509pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Zcu.ErrorMsg) error{ AnalysisFail, OutOfMemory } {
2510 @setCold(true);2510 @branchHint(.cold);
2511 const gpa = sema.gpa;2511 const gpa = sema.gpa;
2512 const zcu = sema.pt.zcu;2512 const zcu = sema.pt.zcu;
25132513
src/arch/aarch64/CodeGen.zig+2-2
...@@ -6357,14 +6357,14 @@ fn wantSafety(self: *Self) bool {...@@ -6357,14 +6357,14 @@ fn wantSafety(self: *Self) bool {
6357}6357}
63586358
6359fn fail(self: *Self, comptime format: []const u8, args: anytype) InnerError {6359fn fail(self: *Self, comptime format: []const u8, args: anytype) InnerError {
6360 @setCold(true);6360 @branchHint(.cold);
6361 assert(self.err_msg == null);6361 assert(self.err_msg == null);
6362 self.err_msg = try ErrorMsg.create(self.gpa, self.src_loc, format, args);6362 self.err_msg = try ErrorMsg.create(self.gpa, self.src_loc, format, args);
6363 return error.CodegenFail;6363 return error.CodegenFail;
6364}6364}
63656365
6366fn failSymbol(self: *Self, comptime format: []const u8, args: anytype) InnerError {6366fn failSymbol(self: *Self, comptime format: []const u8, args: anytype) InnerError {
6367 @setCold(true);6367 @branchHint(.cold);
6368 assert(self.err_msg == null);6368 assert(self.err_msg == null);
6369 self.err_msg = try ErrorMsg.create(self.gpa, self.src_loc, format, args);6369 self.err_msg = try ErrorMsg.create(self.gpa, self.src_loc, format, args);
6370 return error.CodegenFail;6370 return error.CodegenFail;
src/arch/aarch64/Emit.zig+1-1
...@@ -430,7 +430,7 @@ fn writeInstruction(emit: *Emit, instruction: Instruction) !void {...@@ -430,7 +430,7 @@ fn writeInstruction(emit: *Emit, instruction: Instruction) !void {
430}430}
431431
432fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {432fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {
433 @setCold(true);433 @branchHint(.cold);
434 assert(emit.err_msg == null);434 assert(emit.err_msg == null);
435 const comp = emit.bin_file.comp;435 const comp = emit.bin_file.comp;
436 const gpa = comp.gpa;436 const gpa = comp.gpa;
src/arch/arm/CodeGen.zig+2-2
...@@ -6313,7 +6313,7 @@ fn wantSafety(self: *Self) bool {...@@ -6313,7 +6313,7 @@ fn wantSafety(self: *Self) bool {
6313}6313}
63146314
6315fn fail(self: *Self, comptime format: []const u8, args: anytype) InnerError {6315fn fail(self: *Self, comptime format: []const u8, args: anytype) InnerError {
6316 @setCold(true);6316 @branchHint(.cold);
6317 assert(self.err_msg == null);6317 assert(self.err_msg == null);
6318 const gpa = self.gpa;6318 const gpa = self.gpa;
6319 self.err_msg = try ErrorMsg.create(gpa, self.src_loc, format, args);6319 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 {...@@ -6321,7 +6321,7 @@ fn fail(self: *Self, comptime format: []const u8, args: anytype) InnerError {
6321}6321}
63226322
6323fn failSymbol(self: *Self, comptime format: []const u8, args: anytype) InnerError {6323fn failSymbol(self: *Self, comptime format: []const u8, args: anytype) InnerError {
6324 @setCold(true);6324 @branchHint(.cold);
6325 assert(self.err_msg == null);6325 assert(self.err_msg == null);
6326 const gpa = self.gpa;6326 const gpa = self.gpa;
6327 self.err_msg = try ErrorMsg.create(gpa, self.src_loc, format, args);6327 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 {...@@ -348,7 +348,7 @@ fn writeInstruction(emit: *Emit, instruction: Instruction) !void {
348}348}
349349
350fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {350fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {
351 @setCold(true);351 @branchHint(.cold);
352 assert(emit.err_msg == null);352 assert(emit.err_msg == null);
353 const comp = emit.bin_file.comp;353 const comp = emit.bin_file.comp;
354 const gpa = comp.gpa;354 const gpa = comp.gpa;
src/arch/riscv64/CodeGen.zig+2-2
...@@ -8223,14 +8223,14 @@ fn wantSafety(func: *Func) bool {...@@ -8223,14 +8223,14 @@ fn wantSafety(func: *Func) bool {
8223}8223}
82248224
8225fn fail(func: *Func, comptime format: []const u8, args: anytype) InnerError {8225fn fail(func: *Func, comptime format: []const u8, args: anytype) InnerError {
8226 @setCold(true);8226 @branchHint(.cold);
8227 assert(func.err_msg == null);8227 assert(func.err_msg == null);
8228 func.err_msg = try ErrorMsg.create(func.gpa, func.src_loc, format, args);8228 func.err_msg = try ErrorMsg.create(func.gpa, func.src_loc, format, args);
8229 return error.CodegenFail;8229 return error.CodegenFail;
8230}8230}
82318231
8232fn failSymbol(func: *Func, comptime format: []const u8, args: anytype) InnerError {8232fn failSymbol(func: *Func, comptime format: []const u8, args: anytype) InnerError {
8233 @setCold(true);8233 @branchHint(.cold);
8234 assert(func.err_msg == null);8234 assert(func.err_msg == null);
8235 func.err_msg = try ErrorMsg.create(func.gpa, func.src_loc, format, args);8235 func.err_msg = try ErrorMsg.create(func.gpa, func.src_loc, format, args);
8236 return error.CodegenFail;8236 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...@@ -583,7 +583,7 @@ fn pushPopRegList(lower: *Lower, comptime spilling: bool, reg_list: Mir.Register
583}583}
584584
585pub fn fail(lower: *Lower, comptime format: []const u8, args: anytype) Error {585pub fn fail(lower: *Lower, comptime format: []const u8, args: anytype) Error {
586 @setCold(true);586 @branchHint(.cold);
587 assert(lower.err_msg == null);587 assert(lower.err_msg == null);
588 lower.err_msg = try ErrorMsg.create(lower.allocator, lower.src_loc, format, args);588 lower.err_msg = try ErrorMsg.create(lower.allocator, lower.src_loc, format, args);
589 return error.LowerFail;589 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)...@@ -3533,7 +3533,7 @@ fn errUnionPayload(self: *Self, error_union_mcv: MCValue, error_union_ty: Type)
3533}3533}
35343534
3535fn fail(self: *Self, comptime format: []const u8, args: anytype) InnerError {3535fn fail(self: *Self, comptime format: []const u8, args: anytype) InnerError {
3536 @setCold(true);3536 @branchHint(.cold);
3537 assert(self.err_msg == null);3537 assert(self.err_msg == null);
3538 const gpa = self.gpa;3538 const gpa = self.gpa;
3539 self.err_msg = try ErrorMsg.create(gpa, self.src_loc, format, args);3539 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 {...@@ -511,7 +511,7 @@ fn dbgAdvancePCAndLine(emit: *Emit, line: u32, column: u32) !void {
511}511}
512512
513fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {513fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {
514 @setCold(true);514 @branchHint(.cold);
515 assert(emit.err_msg == null);515 assert(emit.err_msg == null);
516 const comp = emit.bin_file.comp;516 const comp = emit.bin_file.comp;
517 const gpa = comp.gpa;517 const gpa = comp.gpa;
src/arch/wasm/Emit.zig+1-1
...@@ -252,7 +252,7 @@ fn offset(self: Emit) u32 {...@@ -252,7 +252,7 @@ fn offset(self: Emit) u32 {
252}252}
253253
254fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {254fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {
255 @setCold(true);255 @branchHint(.cold);
256 std.debug.assert(emit.error_msg == null);256 std.debug.assert(emit.error_msg == null);
257 const comp = emit.bin_file.base.comp;257 const comp = emit.bin_file.base.comp;
258 const zcu = comp.zcu.?;258 const zcu = comp.zcu.?;
src/arch/x86_64/CodeGen.zig+2-2
...@@ -19203,7 +19203,7 @@ fn resolveCallingConventionValues(...@@ -19203,7 +19203,7 @@ fn resolveCallingConventionValues(
19203}19203}
1920419204
19205fn fail(self: *Self, comptime format: []const u8, args: anytype) InnerError {19205fn fail(self: *Self, comptime format: []const u8, args: anytype) InnerError {
19206 @setCold(true);19206 @branchHint(.cold);
19207 assert(self.err_msg == null);19207 assert(self.err_msg == null);
19208 const gpa = self.gpa;19208 const gpa = self.gpa;
19209 self.err_msg = try ErrorMsg.create(gpa, self.src_loc, format, args);19209 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 {...@@ -19211,7 +19211,7 @@ fn fail(self: *Self, comptime format: []const u8, args: anytype) InnerError {
19211}19211}
1921219212
19213fn failSymbol(self: *Self, comptime format: []const u8, args: anytype) InnerError {19213fn failSymbol(self: *Self, comptime format: []const u8, args: anytype) InnerError {
19214 @setCold(true);19214 @branchHint(.cold);
19215 assert(self.err_msg == null);19215 assert(self.err_msg == null);
19216 const gpa = self.gpa;19216 const gpa = self.gpa;
19217 self.err_msg = try ErrorMsg.create(gpa, self.src_loc, format, args);19217 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 {...@@ -293,7 +293,7 @@ pub fn lowerMir(lower: *Lower, index: Mir.Inst.Index) Error!struct {
293}293}
294294
295pub fn fail(lower: *Lower, comptime format: []const u8, args: anytype) Error {295pub fn fail(lower: *Lower, comptime format: []const u8, args: anytype) Error {
296 @setCold(true);296 @branchHint(.cold);
297 assert(lower.err_msg == null);297 assert(lower.err_msg == null);
298 lower.err_msg = try Zcu.ErrorMsg.create(lower.allocator, lower.src_loc, format, args);298 lower.err_msg = try Zcu.ErrorMsg.create(lower.allocator, lower.src_loc, format, args);
299 return error.LowerFail;299 return error.LowerFail;
src/codegen/c.zig+1-1
...@@ -626,7 +626,7 @@ pub const DeclGen = struct {...@@ -626,7 +626,7 @@ pub const DeclGen = struct {
626 }626 }
627627
628 fn fail(dg: *DeclGen, comptime format: []const u8, args: anytype) error{ AnalysisFail, OutOfMemory } {628 fn fail(dg: *DeclGen, comptime format: []const u8, args: anytype) error{ AnalysisFail, OutOfMemory } {
629 @setCold(true);629 @branchHint(.cold);
630 const zcu = dg.pt.zcu;630 const zcu = dg.pt.zcu;
631 const src_loc = zcu.navSrcLoc(dg.pass.nav);631 const src_loc = zcu.navSrcLoc(dg.pass.nav);
632 dg.error_msg = try Zcu.ErrorMsg.create(dg.gpa, src_loc, format, args);632 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 {...@@ -4618,7 +4618,7 @@ pub const NavGen = struct {
4618 }4618 }
46194619
4620 fn todo(ng: *NavGen, comptime format: []const u8, args: anytype) Error {4620 fn todo(ng: *NavGen, comptime format: []const u8, args: anytype) Error {
4621 @setCold(true);4621 @branchHint(.cold);
4622 assert(ng.err_msg == null);4622 assert(ng.err_msg == null);
4623 const o = ng.object;4623 const o = ng.object;
4624 const gpa = o.gpa;4624 const gpa = o.gpa;
...@@ -4784,7 +4784,7 @@ pub const FuncGen = struct {...@@ -4784,7 +4784,7 @@ pub const FuncGen = struct {
4784 }4784 }
47854785
4786 fn todo(self: *FuncGen, comptime format: []const u8, args: anytype) Error {4786 fn todo(self: *FuncGen, comptime format: []const u8, args: anytype) Error {
4787 @setCold(true);4787 @branchHint(.cold);
4788 return self.ng.todo(format, args);4788 return self.ng.todo(format, args);
4789 }4789 }
47904790
src/codegen/spirv.zig+1-1
...@@ -410,7 +410,7 @@ const NavGen = struct {...@@ -410,7 +410,7 @@ const NavGen = struct {
410 }410 }
411411
412 pub fn fail(self: *NavGen, comptime format: []const u8, args: anytype) Error {412 pub fn fail(self: *NavGen, comptime format: []const u8, args: anytype) Error {
413 @setCold(true);413 @branchHint(.cold);
414 const zcu = self.pt.zcu;414 const zcu = self.pt.zcu;
415 const src_loc = zcu.navSrcLoc(self.owner_nav);415 const src_loc = zcu.navSrcLoc(self.owner_nav);
416 assert(self.error_msg == null);416 assert(self.error_msg == null);
src/crash_report.zig+1-1
...@@ -153,8 +153,8 @@ fn writeFilePath(file: *Zcu.File, writer: anytype) !void {...@@ -153,8 +153,8 @@ fn writeFilePath(file: *Zcu.File, writer: anytype) !void {
153}153}
154154
155pub fn compilerPanic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace, maybe_ret_addr: ?usize) noreturn {155pub fn compilerPanic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace, maybe_ret_addr: ?usize) noreturn {
156 @branchHint(.cold);
156 PanicSwitch.preDispatch();157 PanicSwitch.preDispatch();
157 @setCold(true);
158 const ret_addr = maybe_ret_addr orelse @returnAddress();158 const ret_addr = maybe_ret_addr orelse @returnAddress();
159 const stack_ctx: StackContext = .{ .current = .{ .ret_addr = ret_addr } };159 const stack_ctx: StackContext = .{ .current = .{ .ret_addr = ret_addr } };
160 PanicSwitch.dispatch(error_return_trace, stack_ctx, msg);160 PanicSwitch.dispatch(error_return_trace, stack_ctx, msg);
test/behavior/basic.zig+1-1
...@@ -113,7 +113,7 @@ test "cold function" {...@@ -113,7 +113,7 @@ test "cold function" {
113}113}
114114
115fn thisIsAColdFn() void {115fn thisIsAColdFn() void {
116 @setCold(true);116 @branchHint(.cold);
117}117}
118118
119test "unicode escape in character literal" {119test "unicode escape in character literal" {
test/behavior/builtin_functions_returning_void_or_noreturn.zig+1-1
...@@ -22,7 +22,7 @@ test {...@@ -22,7 +22,7 @@ test {
22 try testing.expectEqual(noreturn, @TypeOf(if (true) @panic("") else {}));22 try testing.expectEqual(noreturn, @TypeOf(if (true) @panic("") else {}));
23 try testing.expectEqual({}, @prefetch(&val, .{}));23 try testing.expectEqual({}, @prefetch(&val, .{}));
24 try testing.expectEqual({}, @setAlignStack(16));24 try testing.expectEqual({}, @setAlignStack(16));
25 try testing.expectEqual({}, @setCold(true));25 try testing.expectEqual({}, @branchHint(.cold));
26 try testing.expectEqual({}, @setEvalBranchQuota(0));26 try testing.expectEqual({}, @setEvalBranchQuota(0));
27 try testing.expectEqual({}, @setFloatMode(.optimized));27 try testing.expectEqual({}, @setFloatMode(.optimized));
28 try testing.expectEqual({}, @setRuntimeSafety(true));28 try testing.expectEqual({}, @setRuntimeSafety(true));
test/cases/compile_errors/function-only_builtins_outside_function.zig+2-2
...@@ -3,7 +3,7 @@ comptime {...@@ -3,7 +3,7 @@ comptime {
3}3}
44
5comptime {5comptime {
6 @setCold(true);6 @branchHint(.cold);
7}7}
88
9comptime {9comptime {
...@@ -55,7 +55,7 @@ comptime {...@@ -55,7 +55,7 @@ comptime {
55// target=native55// target=native
56//56//
57// :2:5: error: '@setAlignStack' outside function scope57// :2:5: error: '@setAlignStack' outside function scope
58// :6:5: error: '@setCold' outside function scope58// :6:5: error: '@branchHint' outside function scope
59// :10:5: error: '@src' outside function scope59// :10:5: error: '@src' outside function scope
60// :14:5: error: '@returnAddress' outside function scope60// :14:5: error: '@returnAddress' outside function scope
61// :18:5: error: '@frameAddress' outside function scope61// :18:5: error: '@frameAddress' outside function scope