diff --git a/src/bun_core/env_var.rs b/src/bun_core/env_var.rs index fbbe06a15913..1148327a73ab 100644 --- a/src/bun_core/env_var.rs +++ b/src/bun_core/env_var.rs @@ -442,7 +442,7 @@ pub(crate) mod kind { }; match cached { StoredType::Unknown => { - crate::hint::cold(); + core::hint::cold_path(); CacheOutput::Unknown } StoredType::NotSet => CacheOutput::NotSet, @@ -567,7 +567,7 @@ pub(crate) mod kind { pub(crate) fn get_cached(&self) -> Output { match self.value.load(Ordering::Relaxed) { UNKNOWN_SENTINEL => { - crate::hint::cold(); + core::hint::cold_path(); CacheOutput::Unknown } NOT_SET_SENTINEL => CacheOutput::NotSet, @@ -708,7 +708,7 @@ macro_rules! platform_specific_new { // Inline the logic from get() without calling assert_platform_supported() match CACHE.get_cached() { CacheOutput::Unknown => { - $crate::hint::cold(); + ::core::hint::cold_path(); let env_var = $crate::getenv_z(k); let maybe_reloaded = CACHE.deser_and_invalidate(env_var); diff --git a/src/bun_core/hint.rs b/src/bun_core/hint.rs deleted file mode 100644 index 8ec6e309541e..000000000000 --- a/src/bun_core/hint.rs +++ /dev/null @@ -1,20 +0,0 @@ -//! Branch-prediction hints. - -/// Mark the surrounding branch as cold/unlikely. -/// -/// Calling a `#[cold]` callee makes LLVM treat the *call site's* basic block -/// as cold and lay it out off the hot path. `#[inline(never)]` is required: -/// if the empty body is inlined the call instruction — and with it the hint — -/// disappears. Do NOT mark this `#[inline]` / `#[inline(always)]`. -/// -/// ```ignore -/// if rare { -/// bun_core::hint::cold(); -/// return Err(e); -/// } -/// ``` -// TODO: replace with `core::hint::cold_path()` once rust-lang/rust#117174 -// stabilizes (then drop `#[inline(never)]`). -#[cold] -#[inline(never)] -pub const fn cold() {} diff --git a/src/bun_core/lib.rs b/src/bun_core/lib.rs index 8428018adcc5..f6c6714b8a3d 100644 --- a/src/bun_core/lib.rs +++ b/src/bun_core/lib.rs @@ -18,7 +18,6 @@ pub mod Global; pub mod atomic_cell; pub mod comptime_string_map; pub mod error; -pub mod hint; pub mod result; pub mod thread_id; pub mod tty; diff --git a/src/bun_core/string/immutable.rs b/src/bun_core/string/immutable.rs index 46f64171aaf5..a7d5c2ef8bfb 100644 --- a/src/bun_core/string/immutable.rs +++ b/src/bun_core/string/immutable.rs @@ -2183,7 +2183,7 @@ pub fn percent_encode_write( remaining = &remaining[j..]; let code_point_len: usize = wtf8_byte_sequence_length_with_invalid(remaining[0]) as usize; if remaining.len() < code_point_len { - crate::hint::cold(); + core::hint::cold_path(); return Err(PercentEncodeError::IncompleteUTF8); } diff --git a/src/http_jsc/websocket_client.rs b/src/http_jsc/websocket_client.rs index 8c284d83d56b..92a4d1639348 100644 --- a/src/http_jsc/websocket_client.rs +++ b/src/http_jsc/websocket_client.rs @@ -2069,7 +2069,7 @@ impl Mask { *mask_buf = Self::generate(global_this); let skip_mask = u32::from_ne_bytes(*mask_buf) == 0; if input.is_empty() { - bun_core::hint::cold(); + core::hint::cold_path(); return; } bun_highway::fill_with_skip_mask(*mask_buf, &mut output[..input.len()], input, skip_mask); @@ -2081,7 +2081,7 @@ impl Mask { *mask_buf = Self::generate(global_this); let skip_mask = u32::from_ne_bytes(*mask_buf) == 0; if buf.is_empty() { - bun_core::hint::cold(); + core::hint::cold_path(); return; } bun_highway::fill_with_skip_mask_inplace(*mask_buf, buf, skip_mask); diff --git a/src/jsc/VirtualMachine.rs b/src/jsc/VirtualMachine.rs index 3a0e43b786b6..21356a15e133 100644 --- a/src/jsc/VirtualMachine.rs +++ b/src/jsc/VirtualMachine.rs @@ -2751,7 +2751,7 @@ impl VirtualMachine { // Check if Module.runMain was patched. if self.has_patched_run_main { - bun_core::hint::cold(); + core::hint::cold_path(); self.pending_internal_promise = None; self.pending_internal_promise_is_protected = false; let global_ref = self.global(); diff --git a/src/jsc/event_loop.rs b/src/jsc/event_loop.rs index b1eb57abaa7d..7985a8715649 100644 --- a/src/jsc/event_loop.rs +++ b/src/jsc/event_loop.rs @@ -931,7 +931,7 @@ impl EventLoop { // loop (the recursion check). if unsafe { (*this).next_immediate_tasks.capacity() } > 0 { // this would only occur if we were recursively running tickImmediateTasks. - bun_core::hint::cold(); + core::hint::cold_path(); // SAFETY: as above. let next = core::mem::take(unsafe { &mut (*this).next_immediate_tasks }); // SAFETY: as above. diff --git a/src/resolver/resolver.rs b/src/resolver/resolver.rs index 1e45ac9687a1..c0380fbfdc57 100644 --- a/src/resolver/resolver.rs +++ b/src/resolver/resolver.rs @@ -1861,8 +1861,7 @@ impl<'a> Resolver<'a> { if check_relative { if let Some(custom_paths) = self.custom_dir_paths { - // @branchHint(.unlikely) - bun_core::hint::cold(); + core::hint::cold_path(); for custom_path in custom_paths { let custom_utf8 = custom_path.to_utf8_without_ref(); match self.check_relative_path( @@ -2002,7 +2001,7 @@ impl<'a> Resolver<'a> { } if let Some(custom_paths) = self.custom_dir_paths { - bun_core::hint::cold(); + core::hint::cold_path(); for custom_path in custom_paths { let custom_utf8 = custom_path.to_utf8_without_ref(); match self.check_package_path( diff --git a/src/runtime/bake/DevServer.rs b/src/runtime/bake/DevServer.rs index 31723fac9a87..44a6ab38998f 100644 --- a/src/runtime/bake/DevServer.rs +++ b/src/runtime/bake/DevServer.rs @@ -5694,10 +5694,10 @@ impl DevServer { /// `Cell`-based, so a shared borrow suffices. JS-thread only. pub(crate) fn inspector(&self) -> Option<&BunFrontendDevServerAgent> { if let Some(debugger) = self.vm().debugger.as_ref() { - bun_core::hint::cold(); + core::hint::cold_path(); let agent = BunFrontendDevServerAgent::from_slot(&debugger.extension_agent); if agent.is_enabled() { - bun_core::hint::cold(); + core::hint::cold_path(); return Some(agent); } } diff --git a/src/runtime/cli/create/SourceFileProjectGenerator.rs b/src/runtime/cli/create/SourceFileProjectGenerator.rs index 3301ba5e0523..473dbd973e63 100644 --- a/src/runtime/cli/create/SourceFileProjectGenerator.rs +++ b/src/runtime/cli/create/SourceFileProjectGenerator.rs @@ -647,7 +647,7 @@ fn find_react_component_export<'r>(bundler: &'r BundleV2<'_>) -> Option<&'r [u8] let filename = source.path.name().non_unique_name_string_base(); if filename.is_empty() { - bun_core::hint::cold(); + core::hint::cold_path(); continue; } diff --git a/src/runtime/ipc.rs b/src/runtime/ipc.rs index a3f94d08bea4..872c4238732a 100644 --- a/src/runtime/ipc.rs +++ b/src/runtime/ipc.rs @@ -501,7 +501,7 @@ mod json { json_ipc_data_string_free_cb, ); if s.tag() == bun_core::Tag::Dead { - bun_core::hint::cold(); + core::hint::cold_path(); return Err(IPCDecodeError::Js(JsError::OutOfMemory)); } s diff --git a/src/runtime/jsc_hooks.rs b/src/runtime/jsc_hooks.rs index 248e0bfe178d..45442b5eea17 100644 --- a/src/runtime/jsc_hooks.rs +++ b/src/runtime/jsc_hooks.rs @@ -4463,7 +4463,7 @@ unsafe fn transpile_file( // ── force_loader / require.extensions override ────────────────────────── if let Some(loader_type) = force_loader_type { - // Note: `@branchHint(.unlikely)` dropped (no stable Rust equiv). + core::hint::cold_path(); debug_assert!(!is_commonjs_require); lr.loader = Some(loader_type); } else if is_commonjs_require diff --git a/src/runtime/server/server_body.rs b/src/runtime/server/server_body.rs index 5b5f40098dd9..064849370d83 100644 --- a/src/runtime/server/server_body.rs +++ b/src/runtime/server/server_body.rs @@ -1384,9 +1384,9 @@ impl NewServer { /// the per-transport `RequestContext` bounds. pub(super) fn notify_inspector_server_stopped(&mut self) { if self.inspector_server_id.get() != 0 { - bun_core::hint::cold(); + core::hint::cold_path(); if let Some(debugger) = &self.vm().as_mut().debugger { - bun_core::hint::cold(); + core::hint::cold_path(); // NOTE (layering): the `HTTPServerAgent.notifyServerStopped` // wrapper lives in // `super::http_server_agent` so this crate-tier call doesn't @@ -2679,7 +2679,7 @@ where let addr = match SocketAddress::init(address_bytes, port) { Ok(a) => a, Err(_) => { - bun_core::hint::cold(); + core::hint::cold_path(); return Ok(JSValue::NULL); } }; @@ -2697,7 +2697,7 @@ where let addr = match SocketAddress::init(address_bytes, port) { Ok(a) => a, Err(_) => { - bun_core::hint::cold(); + core::hint::cold_path(); return Ok(JSValue::NULL); } }; diff --git a/src/runtime/shell/EnvStr.rs b/src/runtime/shell/EnvStr.rs index 9aa0975f9277..b82a976529dc 100644 --- a/src/runtime/shell/EnvStr.rs +++ b/src/runtime/shell/EnvStr.rs @@ -139,7 +139,7 @@ impl EnvStr { break 'brk 1; }; if divisor == 0 { - bun_core::hint::cold(); + core::hint::cold_path(); return 0; } diff --git a/src/runtime/valkey_jsc/js_valkey.rs b/src/runtime/valkey_jsc/js_valkey.rs index 8bea145e70f2..f45938b20fca 100644 --- a/src/runtime/valkey_jsc/js_valkey.rs +++ b/src/runtime/valkey_jsc/js_valkey.rs @@ -1196,7 +1196,7 @@ impl JSValkeyClient { // No reconnecting on a VM that is exiting: its stop phase would only // have to close the new socket again. if self.vm().is_shutting_down() { - bun_core::hint::cold(); + core::hint::cold_path(); return Ok(()); } @@ -1597,7 +1597,7 @@ impl JSValkeyClient { if self.client.get().status != valkey::Status::NeverConnected { return; } - bun_core::hint::cold(); + core::hint::cold_path(); match self.connect() { // The command is queued as for a dial in flight; the deferred diff --git a/src/runtime/valkey_jsc/valkey.rs b/src/runtime/valkey_jsc/valkey.rs index 15c5173ae933..c089c918ac38 100644 --- a/src/runtime/valkey_jsc/valkey.rs +++ b/src/runtime/valkey_jsc/valkey.rs @@ -967,7 +967,7 @@ impl ValkeyClient { } else { // We should rarely reach this point. If we're guaranteed to be handling a subscribe/unsubscribe, // then this is an unexpected path. - bun_core::hint::cold(); + core::hint::cold_path(); self.fail( b"Push message is not a subscription message.", RedisError::InvalidResponseType, @@ -1164,7 +1164,7 @@ impl ValkeyClient { return Ok(()); } } else { - bun_core::hint::cold(); + core::hint::cold_path(); self.fail( b"Unexpected push message kind without promise", RedisError::InvalidResponseType, diff --git a/src/sql_jsc/mysql/MySQLRequestQueue.rs b/src/sql_jsc/mysql/MySQLRequestQueue.rs index a1852d5f214e..324e10d0b14d 100644 --- a/src/sql_jsc/mysql/MySQLRequestQueue.rs +++ b/src/sql_jsc/mysql/MySQLRequestQueue.rs @@ -73,7 +73,7 @@ impl MySQLRequestQueue { .get() .unwrap_or(false) { - // @branchHint(.unlikely) — no stable Rust equivalent; left as plain branch. + core::hint::cold_path(); return false; } diff --git a/src/sql_jsc/postgres/DataCell.rs b/src/sql_jsc/postgres/DataCell.rs index c76aaac5ecd4..a1e6e6a3fce3 100644 --- a/src/sql_jsc/postgres/DataCell.rs +++ b/src/sql_jsc/postgres/DataCell.rs @@ -588,7 +588,7 @@ fn parse_array( // postgres dont really support arrays with more than 2^31 elements, 2ˆ32 is the max we support, but users should never reach this branch if !reached_end || array.len() > u32::MAX as usize { - bun_core::hint::cold(); + core::hint::cold_path(); return Err(AnyPostgresError::UnsupportedArrayFormat); } diff --git a/src/sql_jsc/postgres/PostgresSQLConnection.rs b/src/sql_jsc/postgres/PostgresSQLConnection.rs index f575ab14d4f8..5f0affa2b503 100644 --- a/src/sql_jsc/postgres/PostgresSQLConnection.rs +++ b/src/sql_jsc/postgres/PostgresSQLConnection.rs @@ -1598,7 +1598,7 @@ impl PostgresSQLConnection { .get() .unwrap_or(false) { - bun_core::hint::cold(); + core::hint::cold_path(); return false; } diff --git a/test/internal/source-lints/port-era-markers.test.ts b/test/internal/source-lints/port-era-markers.test.ts index 97b42cc0b489..33b5c3bea926 100644 --- a/test/internal/source-lints/port-era-markers.test.ts +++ b/test/internal/source-lints/port-era-markers.test.ts @@ -45,6 +45,10 @@ const banned: { pattern: RegExp; reason: string }[] = [ pattern: /\bun-gated\b/i, reason: "'un-gated' is port-era progress narrative, not useful documentation", }, + { + pattern: /@branchHint\b/i, + reason: "'@branchHint' notes describe a hint the port dropped; the Rust spelling is core::hint::cold_path()", + }, ]; const rustSources = globAllSources().rust.filter(p => p.endsWith(".rs"));