Skip to content

refactor(formatter): Remove HardSpace IR#20958

Merged
graphite-app[bot] merged 1 commit intomainfrom
04-02-refactor_formatter_remove_hardspace_ir
Apr 2, 2026
Merged

refactor(formatter): Remove HardSpace IR#20958
graphite-app[bot] merged 1 commit intomainfrom
04-02-refactor_formatter_remove_hardspace_ir

Conversation

@leaysgur
Copy link
Copy Markdown
Member

@leaysgur leaysgur commented Apr 2, 2026

Refs: #20954 (comment)

HardSpace was only used in one place in oxc_formatter: TSTypeOperator formatting (print/mod.rs).
Replacing it with Space caused no issues.

Biome also uses hard_space (via soft_line_indent_or_hard_space) in only one place in JS formatting. For arrow functions with conditional expression bodies.

https://github.com/biomejs/biome/blob/main/crates/biome_js_formatter/src/js/expressions/arrow_function_expression.rs#L156

However, oxc_formatter already uses soft_line_indent_or_space (not hard_space) for that same case, with no issues.


I also attempted to align the Space handling with Ruff's approach, resolving Space immediately via print_text(" ") / fits_text(" ") instead of deferring it through pending_space. But this caused significant conformance regressions. 😓

The root cause appears to be that oxc_formatter's IR generation is less strict about where Space elements appear (e.g., trailing spaces in line_suffix), relying on the Printer's deferred pending_space mechanism to silently discard unresolved spaces.

So, leave it for now.

@leaysgur leaysgur requested a review from Dunqing as a code owner April 2, 2026 09:14
Copy link
Copy Markdown
Member Author

leaysgur commented Apr 2, 2026


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent changes, fast-track this PR to the front of the merge queue

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@leaysgur leaysgur changed the title refactor(formatter): Remove HardSpace IR refactor(formatter): Remove HardSpace IR Apr 2, 2026
@github-actions github-actions Bot added A-cli Area - CLI A-formatter Area - Formatter C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior labels Apr 2, 2026
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 2, 2026

Merging this PR will not alter performance

✅ 44 untouched benchmarks
⏩ 7 skipped benchmarks1


Comparing 04-02-refactor_formatter_remove_hardspace_ir (772e482) with main (d10df39)2

Open in CodSpeed

Footnotes

  1. 7 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on main (d9389c1) during the generation of this report, so d10df39 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

Copy link
Copy Markdown
Member

@Dunqing Dunqing left a comment

Choose a reason for hiding this comment

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

Well explanation!

@Dunqing Dunqing added the 0-merge Merge with Graphite Merge Queue label Apr 2, 2026
Copy link
Copy Markdown
Member

Dunqing commented Apr 2, 2026

Merge activity

Refs: #20954 (comment)

`HardSpace` was only used in one place in `oxc_formatter`: `TSTypeOperator` formatting (`print/mod.rs`).
Replacing it with `Space` caused no issues.

Biome also uses `hard_space` (via `soft_line_indent_or_hard_space`) in only one place in JS formatting. For arrow functions with conditional expression bodies.

> https://github.com/biomejs/biome/blob/main/crates/biome_js_formatter/src/js/expressions/arrow_function_expression.rs#L156

However, `oxc_formatter` already uses `soft_line_indent_or_space` (not `hard_space`) for that same case, with no issues.

---

I also attempted to align the `Space` handling with Ruff's approach, resolving `Space` immediately via `print_text(" ")` / `fits_text(" ")` instead of deferring it through `pending_space`. But this caused significant conformance regressions. 😓

The root cause appears to be that `oxc_formatter`'s IR generation is less strict about where `Space` elements appear (e.g., trailing spaces in `line_suffix`), relying on the Printer's deferred `pending_space` mechanism to silently discard unresolved spaces.

So, leave it for now.
@graphite-app graphite-app Bot force-pushed the 04-02-refactor_formatter_remove_hardspace_ir branch from 772e482 to fc82a7c Compare April 2, 2026 12:57
@graphite-app graphite-app Bot merged commit fc82a7c into main Apr 2, 2026
26 checks passed
@graphite-app graphite-app Bot removed the 0-merge Merge with Graphite Merge Queue label Apr 2, 2026
@graphite-app graphite-app Bot deleted the 04-02-refactor_formatter_remove_hardspace_ir branch April 2, 2026 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-cli Area - CLI A-formatter Area - Formatter C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants