Skip to content

Remove stale TODO(port) comments and delete dead code#31746

Merged
Jarred-Sumner merged 14 commits into
mainfrom
claude/remove-stale-port-todos
Jun 3, 2026
Merged

Remove stale TODO(port) comments and delete dead code#31746
Jarred-Sumner merged 14 commits into
mainfrom
claude/remove-stale-port-todos

Conversation

@Jarred-Sumner

@Jarred-Sumner Jarred-Sumner commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

What

Two commits:

  1. Removes 804 stale TODO(port) / TODO(b2-*) / TODO(audit) comments whose described work has already landed — out of 3,276 such comments audited across src/.
  2. Deletes the dead code that was hiding behind #[allow(dead_code)] escapes, and drops the escapes that had gone stale.

Plus one review-driven follow-up: ChromeProcess.rs DevToolsActivePort discovery carried an NB comment claiming bun_core::getenv_z is stubbed to None on Windows — no longer true (it walks the WTF-8 env block via getenv_z_any_case). Deleted the stale comment and unified the Windows arm onto getenv_z(zstr!("LOCALAPPDATA")), matching the Zig reference's bun.getenvZ("LOCALAPPDATA") and dropping the std::env::var workaround.

How

Comment sweep (commit 1): every tagged TODO was checked against the current code (and the .zig reference sibling where relevant). Only comments confirmed stale were removed. 2,472 TODOs describing genuinely remaining work are untouched.

Dead-code sweep (commit 2): stripped all 261 item-level #[allow(dead_code)] attributes and ran cargo check --workspace for every CI target triple (linux gnu/musl ×2 arches, macOS ×2, windows ×2, freebsd, android) in both dev and release profiles, then triaged every diagnostic:

  • Dead on every target that compiles it → deleted (~380 lines): unused Windows errno consts, os_environ_ptr, x86 cpuid/sysctlbyname TSC leftovers, platform::linux splice/RWFFlagSupport/ioctl_ficlone, Mutex::ExternImpl, INotifyWatcher::unwatch, WindowsWatcher::{EventListIndex, Timeout::Minimal}, the non-macOS on_machport_change stub, unused encoding discriminants, FakeTimers::AssertMode (collapsed into assert_locked), the never-wired jsc/config.rs and jsc/static_export.rs modules, and subprocess::Poll/WaitThreadPoll (explicitly marked "dead code per LIFETIMES.tsv").
  • Used on every target → attribute dropped (~170 stale escapes, e.g. all 53 in sys/windows/mod.rs).
  • Used on a subset of platforms / only in release-stripped or test paths → attribute kept: CoreGraphics image backend (macOS-only callers), libinfo DNS, ConPTY paths, POSIX pollables compiled-but-unused on Windows, debug_assert!-only helpers, and macro-template hygiene attrs in derive/FFI macros.

Test

test/internal/dead-code-escapes.test.ts pins the audited per-file inventory of item-level #[allow(dead_code)] escapes (ratchet, same pattern as ban-words.test.ts): a new escape — or one reappearing in a cleaned file — fails with instructions to delete the dead code or justify and re-inventory; deletions must update the snapshot. The test fails on the pre-sweep tree (31 files over limit) and passes after it.

Verification

  • cargo check --workspace clean (zero warnings, dead_code = deny intact) for all 10 target triples, dev and release profiles
  • cargo check -p bun_shim_impl clean with and without shim_standalone
  • cargo clippy --workspace --no-deps clean
  • bun bd debug build links and runs; spot-ran fake-timers, dns, watcher, encoding, and spawn test files

An audit of all TODO(port)/TODO(b2-*)/TODO(audit) comments found 804 whose
described work has already landed. Remove those comments (and only the
comments — trailing comments are trimmed from otherwise-unchanged lines).
Comments describing genuinely remaining work are untouched.
@robobun

robobun commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator
Updated 4:04 AM PT - Jun 3rd, 2026

@robobun, your commit 655f9cd9329e92a653306963a9d97ebce392cafa passed in Build #60149! 🎉


🧪   To try this PR locally:

bunx bun-pr 31746

That installs a local version of the PR into your bun-31746 executable, so you can run:

bun-31746 --bun

@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

This PR may be a duplicate of:

  1. Purge remaining port-batch markers missed by the phase cleanup #30885 - Also removes stale port-process marker comments (Phase, Round, PORT_NOTES_PLAN, etc.) left over from the Zig-to-Rust port

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@robobun, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 6 minutes and 2 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: f6ba6813-9514-463b-8723-dde119b16586

📥 Commits

Reviewing files that changed from the base of the PR and between f6c564e and 655f9cd.

📒 Files selected for processing (1)
  • src/errno/windows_errno.rs

Walkthrough

Adds Expr::as_string_z, implements destructuring-to-binding conversion and JSX closing-tag validation, finalizes CLI option parsing, improves Windows errno mapping, adjusts help formatting, updates user-agent export Sync, refactors FakeTimers assertions, removes Linux splice/RWF/ioctl wrappers, prunes modules, and broadly deletes porting comments.

Changes

Core parser/runtime updates and cleanup

Layer / File(s) Summary
Parser conversions and validation
src/js_parser/*
Implements convert_expr_to_binding, initializer handling, and JSX closing-tag name match with diagnostics; lexer/printer small fixes.
CLI argument parsing and prompts
src/install/PackageManager/CommandLineArguments.rs, security_scanner.rs
Parses --network-concurrency (u16) and --minimum-release-age (ms); reads stdin for warning prompts.
Runtime/platform adjustments
src/errno/windows_errno.rs, src/platform/linux.rs, src/bun_core/Global.rs, src/jsc/lib.rs
Adds NTSTATUS errno mapping; removes Linux splice/RWF/ioctl_ficlone; wraps Bun__userAgent with Sync; removes jsc static_export/config modules.
Install/bin/linking behaviors
src/install/bin.rs
Defines Value::init_none, refines shim/symlink recovery, and expands NamesIterator fields.
Timers and event loop
src/runtime/test_runner/timers/FakeTimers.rs
Replaces mode-based assertions with assert_locked and centralizes lock guard helper.
Expr/string helpers
src/ast/expr.rs
Adds Expr::as_string_z accessor for string literal fast-paths.
Help formatting
src/clap/lib.rs
Uses CountingWriter to measure param widths and align help output.
Cleanup across codebase
...
Removes numerous TODO/porting comments and dead_code allows without behavioral changes.

Possibly related PRs

  • oven-sh/bun#30886: Also updates src/perf/hw_timer.rs around cpuid/sysctl gating, overlapping low-level timer/platform adjustments.

Suggested reviewers

  • dylan-conway

Comment thread src/css/properties/border_image.rs Outdated
@Jarred-Sumner

Copy link
Copy Markdown
Collaborator Author

@robobun adopt and delete all the dead code

@robobun

robobun commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

✅ Adopted and done — pushed 2e70d8e: audited all 261 #[allow(dead_code)] escapes against per-target cargo check (all 10 CI triples, dev and release profiles).

  • Deleted everything dead on every target that compiles it (−551 lines): windows errno consts, os_environ_ptr, x86 cpuid/sysctl TSC leftovers, splice/RWFFlagSupport/ioctl_ficlone, Mutex::ExternImpl, watcher leftovers, the never-wired jsc/config.rs + jsc/static_export.rs modules, subprocess::Poll/WaitThreadPoll, and more
  • Dropped ~170 stale attrs whose items are actually used (e.g. all 53 in sys/windows/mod.rs)
  • Kept only load-bearing ones: platform-subset usage (CoreGraphics, libinfo DNS, ConPTY), debug_assert!-only helpers, macro-template hygiene

Verified: cargo check --workspace zero warnings on all 10 targets × both profiles with dead_code = deny intact, clippy clean, bun bd builds and runs.

All review feedback addressed, latest in 655f9cd: ratchet test hardened (whole-file scan, attribute-fenced regex, trailing meta items, HEAD-tracked files only — inventory byte-identical throughout), plus cleaned up every comment the deletions orphaned (jsc/config.rs / ioctl_ficlone / splice mentions, stale "getenv is stubbed on Windows" claims, the get_errno NTSTATUS doc). Branch is merged up to main; all review threads resolved.

While validating the ratchet test's regenerate-then-check flow, found an unrelated pre-existing bug: a plain bun <file>.test.ts run poisons the runtime transpiler cache so a later bun test of the same bytes silently registers zero tests. Fixed separately in #31758.

@Jarred-Sumner

Copy link
Copy Markdown
Collaborator Author

@robobun push

Audited every #[allow(dead_code)] in the workspace by stripping the
attribute and running cargo check for all 10 CI target triples, in both
dev and release profiles:

- Deleted items that are dead on every target that compiles them:
  unused Windows errno consts and get_errno_ntstatus, os_environ_ptr,
  the x86 cpuid/sysctlbyname TSC-frequency leftovers, platform::linux
  splice/RWFFlagSupport/ioctl_ficlone, Mutex ExternImpl aliases,
  INotifyWatcher::unwatch, WindowsWatcher EventListIndex and
  Timeout::Minimal, WindowsBufferedReader::enable_keeping_process_alive,
  WindowsHandlers::on_read, the non-macOS on_machport_change stub,
  unused encoding discriminant consts, FakeTimers AssertMode::Unlocked
  (enum collapsed into assert_locked), O_DIRECT, shell WatchFd,
  Path OsUnit, IN4ADDR_LOOPBACK, ssl_renegotiate_mode_t, SSL_CTX_up_ref,
  and the never-wired jsc config.rs / static_export.rs modules plus
  subprocess Poll/WaitThreadPoll (marked dead-per-LIFETIMES.tsv).

- Dropped ~170 stale attributes whose items are in fact used on every
  target (the escape had outlived its reason).

- Kept the attribute only where it is load-bearing: items used on a
  subset of platforms (CoreGraphics image backend, libinfo DNS,
  ConPTY paths, posix pollables compiled-but-unused on Windows),
  debug_assert-only helpers that are dead in release, test-only items,
  and macro-template hygiene in derive/FFI macros.

Verified: cargo check --workspace clean for all 10 rust targets in dev
and release profiles, clippy clean, debug build runs.
@robobun robobun changed the title Remove stale TODO(port) comments describing completed work Remove stale TODO(port) comments and delete dead code Jun 3, 2026
Comment thread src/runtime/webview/ChromeProcess.rs Outdated
The workspace denies dead_code, so every item-level #[allow(dead_code)]
is a deliberate escape hatch. The sweep audited all of them against
per-target cargo check (dev and release profiles), deleted the code that
was dead everywhere, and kept only escapes whose items are live on some
target or profile.

Pin that inventory per file, following the ban-words.test.ts ratchet
pattern: a new escape (or one reappearing in a cleaned file) fails the
test with instructions to delete the dead code or justify and
re-inventory; deletions must update the snapshot so it stays accurate.
@Jarred-Sumner

Copy link
Copy Markdown
Collaborator Author

@robobun fix the commetns

robobun added 3 commits June 3, 2026 05:31
The NB comment claimed bun_core::getenv_z is stubbed to None on
cfg(windows); it now walks the WTF-8 env block via getenv_z_any_case,
so the std::env::var("LOCALAPPDATA") workaround is unnecessary. Unify
both platforms onto getenv_z, matching the Zig reference
(ChromeProcess.zig readDevToolsActivePort).
The lifetime decision it tracked has landed: the field is an owned ZBox
populated by ensure_cache_directory, with process lifetime via the
leaked PackageManager singleton. Keep the invariant as plain prose.
Comment thread src/platform/linux.rs
Comment thread src/patch/lib.rs
Comment thread src/platform/linux.rs
Comment thread src/patch/lib.rs
Comment thread src/jsc/lib.rs
Comment thread src/runtime/webview/ChromeProcess.rs
robobun added 2 commits June 3, 2026 07:08
…getenv claim

- dead-code-escapes ratchet: scan whole files so rustfmt-wrapped
  #[cfg_attr(...)] attributes are counted (strip full-line comments
  first); regenerated inventory is byte-identical
- schema.rs: drop deleted jsc/config.rs from the ResolveMode doc
- init_command.rs: delete the false 'getenv_z_any_case is a TODO stub
  on Windows' claim and use bun_core::getenv_z_any_case(USER) instead
  of the std::env::var workaround, matching the ChromeProcess.rs fix
Editors and git stash round-trips can leave stray .rs files in the
working tree (e.g. files this branch deletes being temporarily
restored); those must not fail the escape ratchet. Skip anything not
in `git ls-tree -r HEAD`, falling back to counting everything when
git is unavailable. CI runs against the committed tree, so every real
file stays covered.
Comment thread src/errno/windows_errno.rs Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/runtime/test_runner/timers/FakeTimers.rs`:
- Around line 113-122: The assert_locked function currently calls
owner.lock.try_lock(), which if successful acquires the lock and is never
released; change the logic to capture the result of try_lock(), and if it
succeeds explicitly release/drop the acquired guard before performing the
assertion failure path. Concretely, in assert_locked (referencing
owner.lock.try_lock()) store the guard/option/result, if it indicates the lock
was acquired drop/unlock it immediately, then run the debug_assert that the lock
should not have been acquirable.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 3e33b0e1-3fca-4d04-a0a1-8acf7b633025

📥 Commits

Reviewing files that changed from the base of the PR and between 233ccf4 and f6c564e.

📒 Files selected for processing (41)
  • src/bun_alloc/heap_breakdown.rs
  • src/bun_alloc/lib.rs
  • src/bun_bin/lib.rs
  • src/bun_core/lib.rs
  • src/css/properties/border_image.rs
  • src/css/properties/box_shadow.rs
  • src/errno/windows_errno.rs
  • src/install/PackageManager.rs
  • src/install/dependency.rs
  • src/install/isolated_install.rs
  • src/install/windows-shim/bun_shim_impl.rs
  • src/io/PipeReader.rs
  • src/io/PipeWriter.rs
  • src/io/lib.rs
  • src/io/posix_event_loop.rs
  • src/js_parser/visit/visit_expr.rs
  • src/jsc/config.rs
  • src/jsc/lib.rs
  • src/jsc/static_export.rs
  • src/options_types/schema.rs
  • src/paths/Path.rs
  • src/paths/string_paths.rs
  • src/perf/hw_timer.rs
  • src/platform/lib.rs
  • src/platform/linux.rs
  • src/runtime/api/bun/h2_frame_parser.rs
  • src/runtime/api/bun/subprocess.rs
  • src/runtime/cli/init_command.rs
  • src/runtime/cli/test/parallel/Channel.rs
  • src/runtime/dns_jsc/dns.rs
  • src/runtime/ffi/ffi_body.rs
  • src/runtime/jsc_hooks.rs
  • src/runtime/node/fs_events.rs
  • src/runtime/node/node_fs_constant.rs
  • src/runtime/node/win_watcher.rs
  • src/runtime/shell/util.rs
  • src/runtime/socket/SocketAddress.rs
  • src/runtime/socket/tls_socket_functions.rs
  • src/runtime/test_runner/timers/FakeTimers.rs
  • src/runtime/webcore/encoding.rs
  • src/runtime/webview/ChromeProcess.rs
💤 Files with no reviewable changes (22)
  • src/css/properties/box_shadow.rs
  • src/jsc/config.rs
  • src/io/posix_event_loop.rs
  • src/runtime/shell/util.rs
  • src/paths/string_paths.rs
  • src/css/properties/border_image.rs
  • src/jsc/static_export.rs
  • src/runtime/api/bun/subprocess.rs
  • src/io/lib.rs
  • src/install/dependency.rs
  • src/runtime/node/win_watcher.rs
  • src/runtime/node/fs_events.rs
  • src/install/isolated_install.rs
  • src/runtime/cli/test/parallel/Channel.rs
  • src/jsc/lib.rs
  • src/install/windows-shim/bun_shim_impl.rs
  • src/runtime/node/node_fs_constant.rs
  • src/perf/hw_timer.rs
  • src/runtime/dns_jsc/dns.rs
  • src/io/PipeWriter.rs
  • src/io/PipeReader.rs
  • src/errno/windows_errno.rs

Comment thread src/runtime/test_runner/timers/FakeTimers.rs
Comment thread src/patch/lib.rs
…a items

The whole-file scan's [\s\S]+? predicate could extend past an unrelated
cfg_attr's closing bracket and swallow every intervening escape into a
single match (undercount), and the tail rejected allow(dead_code)
followed by another meta item. Use [^\]] in both spots so a match can
never cross a ] and trailing meta items before the attribute close are
accepted. Inventory regenerates byte-identical.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants