Skip to content

Remove dead Windows error tables - #31995

Closed
alii wants to merge 7 commits into
mainfrom
claude/split/windows-tables
Closed

Remove dead Windows error tables#31995
alii wants to merge 7 commits into
mainfrom
claude/split/windows-tables

Conversation

@alii

@alii alii commented Jun 8, 2026

Copy link
Copy Markdown
Member

What this does

Removes dead Windows error-handling code and dedups the errno enum listings. Zero intended behavior change.

  • src/sys/windows/mod.rs: deletes the #[cfg(any())]-parked 1,188-variant MS-ERREF reference table (never compiled) and win_sock_error_to_zig_error, which had no callers.
  • src/windows_sys/externs.rs: deletes the WinsockError newtype, whose only consumer was that converter. bun_windows_sys::Win32Error remains the single compiled WSA table (already the one bun_errno uses).
  • src/errno/windows_errno.rs: enum E and enum SystemErrno were two hand-maintained 138-variant listings that must stay in lockstep (ordinals drive SystemErrno::to_e). Both are now emitted from one shared for_each_linux_errno! X-macro list, the same pattern the existing for_each_uv_errno! tail already uses.

Net -3.2k lines. Split from #31912 (closed in favor of module-scoped splits).

Verification

  • win_sock_error_to_zig_error and WinsockError have no references outside their own definition sites on main.
  • Macro expansion of bun_errno (-Zunpretty=expanded, x86_64-pc-windows-msvc) before and after: the enum E and enum SystemErrno bodies are identical in variant names, values, and order. The only textual difference is a doc comment on ENOTSUP that became a regular comment in the macro list.
  • cargo check --workspace passes for x86_64-pc-windows-msvc and aarch64-pc-windows-msvc, the only targets that compile windows_errno.rs and sys/windows/mod.rs (both #[cfg(windows)]-gated; the externs.rs hunk removes declarations only). rust-check-all also passed all 10 targets on the original commit.

No runtime test accompanies this PR because there is no behavior to pin down: the deleted items had zero references, and the enum dedup expands to identical code, so no test can distinguish before from after on any platform. The expansion diff above is the equivalence proof.

@robobun

robobun commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator
Updated 4:58 AM PT - Jul 13th, 2026

@robobun, your commit db908ad has 1 failures in Build #72419 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 31995

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

bun-31995 --bun

@alii
alii marked this pull request as ready for review June 9, 2026 20:18
@alii

alii commented Jun 9, 2026

Copy link
Copy Markdown
Member Author

@robobun adopt

@alii
alii force-pushed the claude/split/windows-tables branch from b500c6b to 4e22c28 Compare June 9, 2026 20:19
@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 5cfcceb6-fa50-4dda-ab53-370263d9fa30

📥 Commits

Reviewing files that changed from the base of the PR and between c49743f and f6f3c1b.

📒 Files selected for processing (1)
  • src/windows_sys/externs.rs

Walkthrough

The pull request refactors Windows errno enum generation to use a unified X-macro scheme combining Linux and UV error lists, removes the WinsockError public type from Winsock bindings, and clarifies the design intent for Win32Error API stability.

Changes

Windows errno enum generation refactoring

Layer / File(s) Summary
Errno macro system documentation and design
src/errno/windows_errno.rs
Expanded comments explain how the Linux error head and UV error tail lists remain in lockstep and drive discriminant/ordinal assignment for both enum E and enum SystemErrno.
Errno X-macro implementation and E enum generation
src/errno/windows_errno.rs
Introduces for_each_linux_errno!, __errno_enum_add_uv_tail, and __errno_enum macros that generate #[repr(u16)] enums from the combined Linux head and UV tail variants; replaces the prior explicit E enum body with macro-driven emission.
SystemErrno enum generation via unified macros
src/errno/windows_errno.rs
Replaces explicit SystemErrno enum definition with a macro invocation that emits the prefixed variant from the same Linux head plus UV tail mechanism.

Windows error API surface updates

Layer / File(s) Summary
WinsockError type and constants removal
src/windows_sys/externs.rs
Removes the WinsockError(pub u16) newtype and its table of WSA*/WSAE* Winsock constants from the ws2_32 extern module.
Win32Error API design clarification
src/windows_sys/externs.rs
Updates the Win32Error documentation to clarify that only the subset referenced by lower-tier crates is exposed and that new MS-ERREF constants can be added without ABI breakage.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Remove dead Windows error tables' accurately summarizes the main objective of deleting unused Windows error-handling code and deduplicating enum listings.
Description check ✅ Passed The pull request description covers both required sections: it explains what the PR does (deletions and refactoring) and provides detailed verification steps (checked references, macro expansion, cargo check results).
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

@robobun

robobun commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

Closed: the dead code this PR targeted landed on main independently (#35002 removed the cfg(any()) table; #36937 removed win_sock_error_to_zig_error and WinsockError). See the closing comment for the two small leftovers (errno enum dedup, stale Win32Error comment) that could go in a fresh PR.

@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/windows_sys/externs.rs`:
- Around line 952-954: Update the doc comment in externs.rs so it correctly
describes the tiering: state that the subset referenced by lower-tier crates is
the named subset, while errno/bun_errno mapping is a higher-tier concern (i.e.,
T0 must not depend on T1), not the other way around; specifically, replace the
sentence that says "`errno` is a lower-tier crate" with wording that identifies
`bun_errno`/`errno` as the higher-tier mapping and clarifies that new MS-ERREF
consts may be added without ABI change, matching the T0/T1 contract referenced
elsewhere.
🪄 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: 4fd69d21-3e89-4ca9-a634-5e407a3ff86e

📥 Commits

Reviewing files that changed from the base of the PR and between a988615 and c49743f.

📒 Files selected for processing (3)
  • src/errno/windows_errno.rs
  • src/sys/windows/mod.rs
  • src/windows_sys/externs.rs

Comment thread src/windows_sys/externs.rs Outdated
Jarred-Sumner pushed a commit that referenced this pull request Jun 20, 2026
…nts (#32519)

## What

Cleans up comments left behind from the incremental Zig→Rust port that
claim code is "cfg-gated", "blocked_on X", or "will un-gate when Y
lands", where X/Y have since landed and the claim is no longer true.
Also collapses a handful of local shims whose only justification was one
of those stale comments.

Before: 158 such markers across 87 files.
After: 8 remaining, all of which accurately describe real
platform/feature `#[cfg(...)]` gating (macOS/Windows image clipboard,
POSIX/Windows stdio alias, WASM timer selection, Win32 x64 callconv
extern blocks, debug-assertions context, the `#[cfg(any())]` Win32Error
table handled by #31995).

## Shims collapsed into canonical impls

- **`src/runtime/cli/repl.rs`**: removed `global_clear_exception`,
`global_to_js_value`, `vm_set_execution_forbidden`, `vm_mut` (48 lines).
Comment claimed "the canonical impls live in cfg-gated JSGlobalObject.rs
/ VM.rs (see src/jsc/lib.rs \`_gated\`)"; no `_gated` module exists and
`JSGlobalObject::clear_exception` / `::to_js_value`,
`VM::set_execution_forbidden`, `VirtualMachine::as_mut` are all public
and un-gated. 25 call sites rewired.
- **`src/standalone_graph/StandaloneModuleGraph.rs`**: replaced
hand-inlined open+mkdir+retry with `bun_sys::File::make_open`. Comment
claimed "`src/sys/File.rs` is still cfg-gated upstream"; `make_open` is
public at `src/sys/file.rs:112` and already used from
`build_command.rs`.
- **`src/js_parser/visit/mod.rs`**: removed local
`stmts_to_single_stmt_` (duplicate of `P::stmts_to_single_stmt`).
Comment claimed it was "``-gated (P.rs:6267, blocked on S::Block
Default)".
- **`src/js_parser/lower/lower_esm_exports_hmr.rs`**: removed local
`generate_temp_ref` (duplicate of `P::generate_temp_ref`). Comment
claimed "`P::generate_temp_ref` is ``-gated in P.rs (round-6 re-gate)".
- **`src/js_parser/visit/mod.rs`**: removed dead `let _ = &mut j;`
keep-alive whose comment said "keep 'outer label live until #[cfg]
un-gates".
- **`src/css/selectors/selector.rs`**: removed two dead `let _ =
arguments;` lines after real `arguments.to_css_raw(dest)?` calls.

## Comments rewritten or deleted

The rest are comment-only changes removing port-progress narrative
("cycle-5", "round-D/E/G/H", "phase-c/d", "tier-0", "reconciler-6
re-gate", "`` gates carry blocked_on notes") and stale blocker lists
that name dependencies which now exist. Where a comment carried useful
non-port information (aliasing rationale, init-order invariants,
layering notes), that part is kept; only the stale gating claim is
removed.

A few `blocked_on` comments in `src/css/` described genuinely incomplete
code (e.g. `Property::longhand`'s no-op `lh()` stub, the CSS-modules
ref-arm in `selector_has_composes_for_property`); those were reworded to
plain TODOs rather than deleted.

## Verification

```
cargo check --workspace              # clean
bun run rust:check-all                # 10/10 targets ok
bun bd test test/js/bun/repl/repl.test.ts         # 117 pass
bun bd test test/js/bun/util/csrf.test.ts         # 24 pass
bun bd test test/bundler/esbuild/css.test.ts      # 53 pass
bun bd test test/bundler/css/css-modules.test.ts  # 4 pass
bun bd test test/bake/dev/bundle.test.ts          # 20 pass
```

80 files changed, +171/-796.

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
…tables

# Conflicts:
#	src/sys/windows/mod.rs

@claude claude 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.

No issues found — the dead-code deletions are clearly safe and the -Zunpretty=expanded equivalence proof for the X-macro refactor is convincing, but since this restructures the load-bearing E/SystemErrno discriminant generation it's worth a quick human glance before merge.

Extended reasoning...

Overview

This PR touches three Windows-only Rust files:

  • src/sys/windows/mod.rs — deletes a #[cfg(any())]-parked 1,188-variant MS-ERREF reference table (never compiled into any target) and the uncalled win_sock_error_to_zig_error converter.
  • src/windows_sys/externs.rs — removes the WinsockError newtype and its ~85 WSA* consts (sole consumer was the deleted converter; Win32Error already carries the WSA consts that are actually used), and rewords a tiering comment per resolved CodeRabbit feedback.
  • src/errno/windows_errno.rs — replaces two hand-maintained 138-variant enum bodies (E and SystemErrno) with a single for_each_linux_errno! X-macro list, chained through the existing for_each_uv_errno! tail and a new __errno_enum! emitter with @bare/@prefixed arms.

I verified that no remaining Rust code references WinsockError or win_sock_error_to_zig_error, and traced the macro expansion: the 138 [BARE PREFIXED = N] rows match the original variant names/values exactly, the #[strum(serialize = "2BIG")] attribute is correctly applied only to the @bare arm (matching the original where only E::_2BIG carried it), and the derive list / #[repr(u16)] are unchanged.

Security risks

None. This is dead-code removal plus a macro-driven dedup of two enum definitions; no auth, crypto, input parsing, or trust-boundary code is touched.

Level of scrutiny

Moderate. The pure deletions (#[cfg(any())]-gated table, unreferenced WinsockError newtype) are trivially safe. The X-macro refactor is well-verified — the author diffed -Zunpretty=expanded output and confirmed identical variant names, values, and order — but it restructures the single source of truth for Windows errno discriminants, where order is explicitly load-bearing (enum_map::Enum ordinals + SystemErrno::to_e transmute). A subtle drift here would mis-map every Windows syscall error. The 3-level macro chain (for_each_linux_errno!__errno_enum_add_uv_tail!for_each_uv_errno!__errno_enum!) is also non-trivial enough that a maintainer should confirm they're comfortable with the pattern going forward.

Other factors

  • Bug-hunting system found nothing.
  • CodeRabbit's only finding (doc-comment tiering wording) was addressed in f6f3c1b and the thread is resolved.
  • Windows CI lanes passed; the red lanes are documented Linux-only flakes unrelated to this Windows-gated diff.
  • No CODEOWNERS cover these paths.
  • This is a split-out from a larger closed PR (#31912), so it's already been scoped down for reviewability.

…tables

# Conflicts:
#	src/sys/windows/mod.rs

@claude claude 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.

I didn't find any issues. The dead-code deletions (#[cfg(any())] MS-ERREF table, win_sock_error_to_zig_error, WinsockError) are trivially safe — I confirmed zero remaining references. The for_each_linux_errno! refactor looks correct and follows the existing for_each_uv_errno! pattern, but since it replaces the hand-listed bodies of two enums whose discriminant lockstep backs an unsafe transmute (SystemErrno::to_e), it's worth a maintainer sign-off on the macro approach.

Checked: all 138 [bare prefixed = N] rows match both original enum bodies (names, values, order); the #[strum(serialize = "2BIG")] attr correctly applies only to E::_2BIG via the @bare arm; the @emit arm's derives/#[repr(u16)] match the originals; the ENOTSUP doc-comment loss is cosmetic only.

Extended reasoning...

Overview

Three files touched, net −3.2k lines:

  • src/sys/windows/mod.rs: deletes a #[cfg(any())]-gated 1188-const MS-ERREF reference table (never compiled) and win_sock_error_to_zig_error (no callers — verified via grep on current HEAD). Updates one doc comment.
  • src/windows_sys/externs.rs: deletes the WinsockError newtype + consts (only consumer was the deleted converter — verified). Rewords one doc comment per resolved CodeRabbit feedback.
  • src/errno/windows_errno.rs: replaces two hand-maintained 138-variant enum bodies (E and SystemErrno) with a shared for_each_linux_errno! X-macro plus a __errno_enum! emitter that has @bare/@prefixed arms selecting the first vs. second ident from each row. Chains through the pre-existing for_each_uv_errno! for the tail.

Security risks

None. Windows-only error-code enum definitions and dead-code removal; no input parsing, auth, crypto, or permission surfaces.

Level of scrutiny

The deletions are mechanical and trivially verifiable (I grepped: no references to win_sock_error_to_zig_error or WinsockError remain in src/; the #[cfg(any())] block was never compiled). Those alone would be an easy approve.

The windows_errno.rs refactor is where the substance is. SystemErrno::to_e does transmute::<u16, E>(self as u16), so the two enums' discriminants and enum_map::Enum ordinals must stay identical — that invariant is now enforced by macro-generating both from one list rather than by hand-maintaining parallel listings. The PR author and robobun both verified via -Zunpretty=expanded on x86_64-pc-windows-msvc that the expanded enum bodies are byte-identical to before (224 variants each, same names/values/order), and I spot-checked the 138 macro rows against both deleted enum bodies: all match. The pattern is not new — for_each_uv_errno! already drives the tail of both enums the same way.

That said, this introduces ~100 lines of new declarative-macro machinery (for_each_linux_errno!, __errno_enum_add_uv_tail!, __errno_enum! with three arms) governing a safety-critical invariant. It's a design choice about how these enums are maintained going forward, and per the approval guidelines that's the kind of thing a maintainer should explicitly sign off on rather than a bot.

Other factors

  • No CODEOWNERS coverage for these paths.
  • CodeRabbit's one inline comment (tiering wording in a doc comment) was addressed in f6f3c1b and marked resolved.
  • robobun adopted, re-merged main (resolving a conflict from #33909 rewriting the deleted function's signature), and re-verified expansion equivalence + Windows cargo check after the merge.
  • No prior review from me on this PR.
  • The bug-hunting system found nothing.

@alii

alii commented Aug 10, 2026

Copy link
Copy Markdown
Member Author

@robobun get this mergeable — or close it if the changes are already covered on main / too stale to salvage.

@robobun

robobun commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

Closing: the dead code this PR removes has since landed on main independently. The #[cfg(any())] MS-ERREF table went in #35002, and win_sock_error_to_zig_error plus WinsockError went in #36937. The branch is 772 commits behind and conflicting, so there is nothing left to merge under this title.

Two small pieces of this PR are not on main: the for_each_linux_errno! dedup of the E/SystemErrno bodies in windows_errno.rs (those bodies are unchanged on main, so it still applies), and the Win32Error comment in externs.rs, which still says "lower-tier crates (errno)" and points at the 1188-variant table that no longer exists. Both are a different change from this PR's purpose; happy to open a fresh, narrowly scoped PR for them if wanted.

@robobun robobun closed this Aug 10, 2026
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