Skip to content

Collapse console formatter TagPayload into Tag - #37358

Open
robobun wants to merge 11 commits into
claude/split/install-clifrom
farm/df8b29f2/split-console
Open

Collapse console formatter TagPayload into Tag#37358
robobun wants to merge 11 commits into
claude/split/install-clifrom
farm/df8b29f2/split-console

Conversation

@robobun

@robobun robobun commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

What this does

The console formatter carried two parallel enums, Tag (the discriminant) and TagPayload (the same variants plus a payload on CustomFormattedObject), with a TagPayload::tag() projection and From impls between them. This folds the payload into a custom: Option<CustomFormattedObject> field on TagResult and deletes TagPayload, updating the three consumers (macro evaluator, test-runner pretty printer, VirtualMachine's native-code check).

Split 1 of 8 from #32023, which alii asked to be broken up. Pure code motion and deletion; no intended behavior change. Stacked on claude/split/install-cli (merge order: foundations → install-cli → these, in any order among themselves).

Notes from rebasing against main

console.table was rewritten on main to format each cell once (#32924); the rename is applied on top of that shape. ConsoleObject.rs is the bulk of the diff.

Verification

  • Compiles in isolation against the base (cargo check), and the union of all eight splits is byte-identical to Deduplicate jsc bindings, runtime api, test matchers, and shell builtins #32023's head f29ce8fe4, which CI ran at 285/286 green (the one red was the fleet-wide napi.test.ts GC-timing flake on windows x64-baseline).
  • Locally on the parent head: console-table / bun-inspect-table (68 pass), macro-test (11 pass), expect.test.js pretty-format paths pass.
  • No new tests: this adds no behavior, so the existing suites above are the regression coverage.

alii and others added 11 commits June 9, 2026 13:19
Resolved src/io/posix_event_loop.rs: #32594 added PollMemoryPressure to
is_registered(), which this branch moved into impl_file_poll_flag_methods;
carried the flag into the macro body.

Restored ArrayHashMap::get_index_mut: gained a caller in
react_compiler/collections.rs via #32504.
Resolved src/bun_core/string/mod.rs: #33909 switched return types to
crate::CrateResult<()> in write_pre_quoted_string and quote_for_json,
which this branch restructures into the const-generic
write_pre_quoted_string_inner; carried CrateResult<()> into both the
adapter and _inner signatures.

Resolved src/router/lib.rs and src/sourcemap/Chunk.rs: #33909 touched
return types inside blocks this branch deletes (orphaned router test
scaffolding, uncalled print_source_map_contents); kept the deletions
after re-verifying zero callers on current main.

Restored Node::find_last in src/collections/pool.rs: gained a test
caller via #33311.

@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 reviewed this PR and didn't find any bugs. Because it's a ~500-line diff touching the console formatter (which drives console.log, Bun.inspect, error rendering, and snapshot output), a human look would still be worthwhile.

Checked: is_array_buffer_like() matches exactly the 14 explicit JSType arms it replaces in both files; the deleted pretty_format::{MessageType, ZigFormatter, WriteError} are dead duplicates of the canonical ConsoleObject.rs versions (no pretty_format:: references remain); no residual TagPayload references anywhere in src/; custom: None at the two trait-bridge sites (lib.rs, AsymmetricMatcherFormatter) matches the old From<Tag> behavior whose comment stated CustomFormattedObject is never passed there.

Extended reasoning...

Overview

This PR collapses two parallel enums in the console formatter: TagPayload (a copy of Tag with one payload-carrying variant) is deleted, and its sole payload moves to a new custom: Option<CustomFormattedObject> field on TagResult. Alongside this, it extracts a WrappedWriter::new() constructor (replacing ~20 inline struct literals), inlines the local pf!($s)pfmt!($s, C) macro at each site, replaces two 14-arm typed-array match blocks with t if t.is_array_buffer_like(), and deletes three dead duplicate types from pretty_format.rs. Five files touched; ConsoleObject.rs is the bulk. Split 1 of 8 from #32023, which a maintainer asked to be broken up.

Security risks

None. This is a formatter/type refactor with no I/O, parsing, auth, or untrusted-input handling changes.

Level of scrutiny

Moderate. Each change is individually mechanical, but the console formatter is on the path of console.log, Bun.inspect, error printing, and toMatchInlineSnapshot — a subtle output difference would ripple through many snapshot tests. I verified the specific behavior-preservation claims: JSType::is_array_buffer_like() (JSType.rs:709) matches the identical 14 variants the guard arm replaces, and the guard's position doesn't intercept any later arm; the custom: None at the ConsoleFormatter trait bridge and AsymmetricMatcherFormatter reproduces the old From<Tag> for TagPayload default (whose doc comment already noted CustomFormattedObject is never passed there); the deleted pretty_format types have zero references (the live ones are all console_object::formatter::ZigFormatter / ConsoleObject::MessageType).

Other factors

The PR states the union of all 8 splits is byte-identical to #32023's CI-green head, and the relevant local suites (console-table, bun-inspect-table, macro-test, expect.test.js) pass. No new tests are added, which is appropriate for a no-behavior-change refactor. Deferring rather than approving because the diff is large enough (and the surface user-visible enough) that a maintainer skim of the ConsoleObject.rs hunk is warranted, per this repo's review norms for refactors.

@robobun

robobun commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks, those are the four equivalence points that matter here and they match what I checked when cutting the split. One more data point on the snapshot-ripple concern: the union of the eight splits is byte-identical to #32023's head, and that head ran the full suite at 285/286 (build 72447), which includes every snapshot and inline-snapshot test in the tree; the one red was an unrelated napi GC-timing flake on windows. So any output difference in the formatter would already have shown up there. Over to @alii for the human skim of the ConsoleObject.rs hunk.

@robobun
robobun force-pushed the claude/split/install-cli branch from 2f5dd36 to 9ae3ff5 Compare August 11, 2026 02:09
@robobun

robobun commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator Author
Updated 5:05 AM PT - Aug 11th, 2026

@alii, your commit fb3a859 has some failures in Build #91733 (All Failures)


🧪   To try this PR locally:

bunx bun-pr 37358

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

bun-37358 --bun

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants