From 5fc6ededc0b0d74bb4bfd7cfc6a51df2be40ff8d Mon Sep 17 00:00:00 2001 From: robobun <117481402+robobun@users.noreply.github.com> Date: Mon, 20 Jul 2026 03:32:27 +0000 Subject: [PATCH 1/5] router: remove dead public items with zero references Removes pub items in bun_router that have no callers anywhere in the workspace, in generated code, or across the FFI boundary. These were ported from the Zig router but their call sites were never ported (or went through a different path in Rust). - RouteConfig::from_loaded_routes - Router::get_public_paths - Router::route_index_by_hash - TinyPtr::to_string_pointer - type RoutePtr - Match::params_iterator - Match::name_with_basename - RouteIndexList::items_public_path (only caller was get_public_paths) - api::StringPointer re-export + PathnameScanner import (orphaned by above) --- src/router/lib.rs | 61 ----------------------------------------------- 1 file changed, 61 deletions(-) diff --git a/src/router/lib.rs b/src/router/lib.rs index bb1bbabf2519..d0e05121a7aa 100644 --- a/src/router/lib.rs +++ b/src/router/lib.rs @@ -16,7 +16,6 @@ use bun_collections::{ArrayHashMap, StringHashMap}; use bun_core::strings; use bun_paths::{self, PathBuffer, SEP, SEP_STR}; use bun_sys::Fd; -use bun_url::PathnameScanner; use bun_http_types::URLPath::URLPath; @@ -38,10 +37,7 @@ use bun_resolver::DirInfoRef; use bun_resolver::fs as Fs; use bun_resolver::fs::FileSystem; -// peechy schema types: `StringPointer` lives in `bun_core::schema::api` (T0); -// the route-config pair lives in `bun_options_types::schema::api`. mod api { - pub(crate) use bun_core::schema::api::StringPointer; pub(crate) use bun_options_types::schema::api::{LoadedRouteConfig, RouteConfig}; } @@ -114,18 +110,6 @@ impl RouteConfig { } } - pub fn from_loaded_routes(loaded: api::LoadedRouteConfig) -> RouteConfig { - RouteConfig { - extensions: loaded.extensions, - routes_enabled: !loaded.dir.is_empty(), - static_dir_enabled: !loaded.static_dir.is_empty(), - dir: loaded.dir, - asset_prefix_path: loaded.asset_prefix, - static_dir: loaded.static_dir, - possible_dirs: Box::default(), - } - } - pub fn from_api(router_: &api::RouteConfig) -> Result { use bun_core::strings::{trim_left, trim_right}; @@ -230,22 +214,6 @@ impl<'a> Router<'a> { self.routes.list.items_filepath() } - pub fn get_public_paths(&self) -> &[&'static [u8]] { - self.routes.list.items_public_path() - } - - pub fn route_index_by_hash(&self, hash: u32) -> Option { - if hash == INDEX_ROUTE_HASH { - return self.routes.index_id; - } - - self.routes - .list - .items_hash() - .iter() - .position(|&h| h == hash) - } - pub fn get_names(&self) -> &[&'static [u8]] { self.routes.list.items_name() } @@ -393,10 +361,6 @@ impl RouteIndexList { &self.filepath } #[inline] - pub fn items_public_path(&self) -> &[&'static [u8]] { - &self.public_path - } - #[inline] pub fn items_hash(&self) -> &[u32] { &self.hash } @@ -939,14 +903,6 @@ impl TinyPtr { } } - #[inline] - pub fn to_string_pointer(self) -> api::StringPointer { - api::StringPointer { - offset: self.offset() as u32, - length: self.len() as u32, - } - } - #[inline] pub fn eql(a: TinyPtr, b: TinyPtr) -> bool { a == b @@ -1004,9 +960,6 @@ pub struct Route { pub has_uppercase: bool, } -// TODO(b1): inherent assoc types unstable; module-level alias instead. -pub type RoutePtr = TinyPtr; - impl Route { pub const INDEX_ROUTE_NAME: &'static [u8] = b"/"; @@ -1473,20 +1426,6 @@ impl<'a> Match<'a> { unsafe { (*self.params).len() > 0 } } - pub fn params_iterator(&self) -> PathnameScanner<'_> { - // SAFETY: see `has_params`. - PathnameScanner::init(self.pathname, self.name, unsafe { &*self.params }) - } - - pub fn name_with_basename<'s>(file_path: &'s [u8], dir: &[u8]) -> &'s [u8] { - let mut name = file_path; - if let Some(i) = strings::index_of(name, dir) { - name = &name[i + dir.len()..]; - } - - &name[0..name.len() - bun_paths::extension(name).len()] - } - pub fn pathname_without_leading_slash(&self) -> &[u8] { strings::trim_left(self.pathname, b"/") } From 824e22d1a6e349b1c894b14d9ea9445b0eb22c88 Mon Sep 17 00:00:00 2001 From: robobun <117481402+robobun@users.noreply.github.com> Date: Tue, 21 Jul 2026 04:17:46 +0000 Subject: [PATCH 2/5] router: remove cascaded dead items flagged in review route_index_by_hash's removal orphaned RouteIndexList::items_hash and left Routes.index_id write-only; with items_public_path gone the public_path/hash SoA columns (and the RouteIndex and Route fields feeding them) were write-only too. --- src/router/lib.rs | 54 +++++++++-------------------------------------- 1 file changed, 10 insertions(+), 44 deletions(-) diff --git a/src/router/lib.rs b/src/router/lib.rs index d0e05121a7aa..6f026426163d 100644 --- a/src/router/lib.rs +++ b/src/router/lib.rs @@ -301,8 +301,6 @@ struct RouteIndex { name: &'static [u8], match_name: &'static [u8], filepath: &'static [u8], - public_path: &'static [u8], - hash: u32, } // TODO(b2-blocked): bun_collections::MultiArrayElement derive — proc-macro not @@ -318,8 +316,6 @@ pub struct RouteIndexList { name: Vec<&'static [u8]>, match_name: Vec<&'static [u8]>, filepath: Vec<&'static [u8]>, - public_path: Vec<&'static [u8]>, - hash: Vec, } impl RouteIndexList { @@ -328,8 +324,6 @@ impl RouteIndexList { self.name.reserve_exact(cap); self.match_name.reserve_exact(cap); self.filepath.reserve_exact(cap); - self.public_path.reserve_exact(cap); - self.hash.reserve_exact(cap); Ok(()) } pub(crate) fn push(&mut self, item: RouteIndex) { @@ -337,8 +331,6 @@ impl RouteIndexList { self.name.push(item.name); self.match_name.push(item.match_name); self.filepath.push(item.filepath); - self.public_path.push(item.public_path); - self.hash.push(item.hash); } #[inline] pub fn len(&self) -> usize { @@ -360,10 +352,6 @@ impl RouteIndexList { pub fn items_filepath(&self) -> &[&'static [u8]] { &self.filepath } - #[inline] - pub fn items_hash(&self) -> &[u32] { - &self.hash - } } pub struct Routes { @@ -386,7 +374,6 @@ pub struct Routes { /// `list.route`). Stored as `NonNull` (not `&'a Route`) so `Routes` claims /// no borrow it doesn't actually take; matches `static_` above. pub index: Option>, - pub index_id: Option, // allocator dropped — global mimalloc pub config: RouteConfig, @@ -404,7 +391,6 @@ impl Default for Routes { dynamic_len: 0, static_: StringHashMap::new(), index: None, - index_id: Some(0), config: RouteConfig::default(), client_framework_enabled: false, } @@ -722,17 +708,12 @@ impl<'a> RouteLoader<'a> { index_id = Some(i); } - let (filepath, match_name, public_path) = ( - route.abs_path.as_bytes(), - route.match_name.as_bytes(), - route.public_path.as_bytes(), - ); + let (filepath, match_name) = + (route.abs_path.as_bytes(), route.match_name.as_bytes()); route_list.push(RouteIndex { name: route.name, filepath, match_name, - public_path, - hash: route.full_hash, route, }); } @@ -758,7 +739,6 @@ impl<'a> RouteLoader<'a> { // pointer. index: this.index, config, - index_id, client_framework_enabled: false, } } @@ -950,11 +930,6 @@ pub struct Route { pub abs_path: AbsPath, - /// URL-safe path for the route's transpiled script relative to project's top level directory - /// - It might not share a prefix with the absolute path due to symlinks. - /// - It has a leading slash - pub public_path: Interned, - pub kind: pattern::Tag, pub has_uppercase: bool, @@ -1054,11 +1029,11 @@ impl Route { let is_index = name.is_empty(); let mut has_uppercase = false; - // NOTE: reshaped for borrowck — both arms intern via DirnameStore - // (process-lifetime arena → `&'static`), so the post-if bindings are - // 'static and the route_file_buf borrow is dropped before the - // abs-path block below needs it mutably. - let (public_path, name, match_name): (&'static [u8], &'static [u8], &'static [u8]) = + // NOTE: reshaped for borrowck — the non-index arm interns via + // DirnameStore (process-lifetime arena → `&'static`), so the + // post-if bindings are 'static and the route_file_buf borrow is + // dropped before the abs-path block below needs it mutably. + let (name, match_name): (&'static [u8], &'static [u8]) = if !name.is_empty() { validation_result = match Pattern::validate(&name[1..], log) { Some(v) => v, @@ -1092,16 +1067,9 @@ impl Route { debug_assert!(match_name[0] != b'/'); debug_assert!(name[0] == b'/'); - (public_path, name, match_name) + (name, match_name) } else { - let dirname_store = FileSystem::instance().dirname_store(); - let public_path: &'static [u8] = - dirname_store.append(public_path).expect("unreachable"); - ( - public_path, - Route::INDEX_ROUTE_NAME, - Route::INDEX_ROUTE_NAME, - ) + (Route::INDEX_ROUTE_NAME, Route::INDEX_ROUTE_NAME) }; if abs_path_str.is_empty() { @@ -1212,14 +1180,13 @@ impl Route { #[cfg(all(debug_assertions, windows))] { debug_assert!(!strings::index_of_char(name, b'\\').is_some()); - debug_assert!(!strings::index_of_char(public_path, b'\\').is_some()); debug_assert!(!strings::index_of_char(match_name, b'\\').is_some()); debug_assert!(!strings::index_of_char(abs_path.as_bytes(), b'\\').is_some()); // SAFETY: read-only reborrow; the `&mut` write above is dead. debug_assert!(!strings::index_of_char(unsafe { &*entry }.base(), b'\\').is_some()); } - // NOTE: name/match_name/public_path are already `&'static` via + // NOTE: name/match_name are already `&'static` via // DirnameStore::append above. `entry.base()` borrows the entry (it // may be inline-stored for ≤31-byte names); intern it // explicitly to get `&'static` without a lifetime transmute. @@ -1232,7 +1199,6 @@ impl Route { Some(Route { name, basename, - public_path: Interned::from_static(public_path), match_name: Interned::from_static(match_name), full_hash: if is_index { INDEX_ROUTE_HASH From a99cf2397127be55a4ad99eae04dc21a40155d54 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Tue, 21 Jul 2026 04:19:48 +0000 Subject: [PATCH 3/5] [autofix.ci] apply automated fixes --- src/router/lib.rs | 72 +++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 37 deletions(-) diff --git a/src/router/lib.rs b/src/router/lib.rs index 6f026426163d..994fcc3d928f 100644 --- a/src/router/lib.rs +++ b/src/router/lib.rs @@ -708,8 +708,7 @@ impl<'a> RouteLoader<'a> { index_id = Some(i); } - let (filepath, match_name) = - (route.abs_path.as_bytes(), route.match_name.as_bytes()); + let (filepath, match_name) = (route.abs_path.as_bytes(), route.match_name.as_bytes()); route_list.push(RouteIndex { name: route.name, filepath, @@ -1033,45 +1032,44 @@ impl Route { // DirnameStore (process-lifetime arena → `&'static`), so the // post-if bindings are 'static and the route_file_buf borrow is // dropped before the abs-path block below needs it mutably. - let (name, match_name): (&'static [u8], &'static [u8]) = - if !name.is_empty() { - validation_result = match Pattern::validate(&name[1..], log) { - Some(v) => v, - None => return None, - }; - - let mut name_i: usize = 0; - while !has_uppercase && name_i < public_path.len() { - has_uppercase = public_path[name_i] >= b'A' && public_path[name_i] <= b'Z'; - name_i += 1; - } + let (name, match_name): (&'static [u8], &'static [u8]) = if !name.is_empty() { + validation_result = match Pattern::validate(&name[1..], log) { + Some(v) => v, + None => return None, + }; + + let mut name_i: usize = 0; + while !has_uppercase && name_i < public_path.len() { + has_uppercase = public_path[name_i] >= b'A' && public_path[name_i] <= b'Z'; + name_i += 1; + } - let name_offset = name.as_ptr() as usize - public_path.as_ptr() as usize; - let name_len = name.len(); - - // NOTE: DirnameStore::append returns `&'static [u8]` (process- - // lifetime arena), so rebinding here drops the borrow on - // `route_file_buf` and avoids needing lifetime transmutes - // below. - let dirname_store = FileSystem::instance().dirname_store(); - let public_path: &'static [u8] = - dirname_store.append(public_path).expect("unreachable"); - let name: &'static [u8] = &public_path[name_offset..][0..name_len]; - let match_name: &'static [u8] = if has_uppercase { - dirname_store - .append_lower_case(&name[1..]) - .expect("unreachable") - } else { - &name[1..] - }; - - debug_assert!(match_name[0] != b'/'); - debug_assert!(name[0] == b'/'); - (name, match_name) + let name_offset = name.as_ptr() as usize - public_path.as_ptr() as usize; + let name_len = name.len(); + + // NOTE: DirnameStore::append returns `&'static [u8]` (process- + // lifetime arena), so rebinding here drops the borrow on + // `route_file_buf` and avoids needing lifetime transmutes + // below. + let dirname_store = FileSystem::instance().dirname_store(); + let public_path: &'static [u8] = + dirname_store.append(public_path).expect("unreachable"); + let name: &'static [u8] = &public_path[name_offset..][0..name_len]; + let match_name: &'static [u8] = if has_uppercase { + dirname_store + .append_lower_case(&name[1..]) + .expect("unreachable") } else { - (Route::INDEX_ROUTE_NAME, Route::INDEX_ROUTE_NAME) + &name[1..] }; + debug_assert!(match_name[0] != b'/'); + debug_assert!(name[0] == b'/'); + (name, match_name) + } else { + (Route::INDEX_ROUTE_NAME, Route::INDEX_ROUTE_NAME) + }; + if abs_path_str.is_empty() { // The reads of `cache().fd` and the `set_abs_path` write below // rewrite the cached `Entry`; serialize them on the per-entry From 09379f8a6c9dae53c15c386fe1888ead0799f8ef Mon Sep 17 00:00:00 2001 From: robobun <117481402+robobun@users.noreply.github.com> Date: Tue, 21 Jul 2026 04:34:43 +0000 Subject: [PATCH 4/5] router: intern route name directly instead of re-slicing from public_path With Route.public_path removed, the full public_path intern existed only as a substrate to rebuild name via pointer offsets. --- src/router/lib.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/router/lib.rs b/src/router/lib.rs index 994fcc3d928f..5982f367312d 100644 --- a/src/router/lib.rs +++ b/src/router/lib.rs @@ -1044,17 +1044,12 @@ impl Route { name_i += 1; } - let name_offset = name.as_ptr() as usize - public_path.as_ptr() as usize; - let name_len = name.len(); - // NOTE: DirnameStore::append returns `&'static [u8]` (process- // lifetime arena), so rebinding here drops the borrow on // `route_file_buf` and avoids needing lifetime transmutes // below. let dirname_store = FileSystem::instance().dirname_store(); - let public_path: &'static [u8] = - dirname_store.append(public_path).expect("unreachable"); - let name: &'static [u8] = &public_path[name_offset..][0..name_len]; + let name: &'static [u8] = dirname_store.append(name).expect("unreachable"); let match_name: &'static [u8] = if has_uppercase { dirname_store .append_lower_case(&name[1..]) From 27d5ee27b3fab0b50336a1d4de35319f9f630319 Mon Sep 17 00:00:00 2001 From: robobun <117481402+robobun@users.noreply.github.com> Date: Tue, 21 Jul 2026 04:43:43 +0000 Subject: [PATCH 5/5] router: trim borrowck comments to three lines --- src/router/lib.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/router/lib.rs b/src/router/lib.rs index 5982f367312d..2f37a3e5303f 100644 --- a/src/router/lib.rs +++ b/src/router/lib.rs @@ -1028,10 +1028,9 @@ impl Route { let is_index = name.is_empty(); let mut has_uppercase = false; - // NOTE: reshaped for borrowck — the non-index arm interns via - // DirnameStore (process-lifetime arena → `&'static`), so the - // post-if bindings are 'static and the route_file_buf borrow is - // dropped before the abs-path block below needs it mutably. + // NOTE: the non-index arm interns via DirnameStore (process-lifetime + // arena → `&'static`), so the post-if bindings drop the + // route_file_buf borrow before the abs-path block reborrows it. let (name, match_name): (&'static [u8], &'static [u8]) = if !name.is_empty() { validation_result = match Pattern::validate(&name[1..], log) { Some(v) => v, @@ -1044,10 +1043,9 @@ impl Route { name_i += 1; } - // NOTE: DirnameStore::append returns `&'static [u8]` (process- - // lifetime arena), so rebinding here drops the borrow on - // `route_file_buf` and avoids needing lifetime transmutes - // below. + // NOTE: DirnameStore::append returns `&'static [u8]`, so + // rebinding drops the route_file_buf borrow without a + // lifetime transmute. let dirname_store = FileSystem::instance().dirname_store(); let name: &'static [u8] = dirname_store.append(name).expect("unreachable"); let match_name: &'static [u8] = if has_uppercase {