Skip to content

refactor(formatter): SortImportsTransform::transform return Vec not Option<Vec>#22073

Merged
graphite-app[bot] merged 1 commit into
mainfrom
om/05-02-refactor_formatter_sortimportstransform_transform_return_vec_not_option_vec_
May 7, 2026
Merged

refactor(formatter): SortImportsTransform::transform return Vec not Option<Vec>#22073
graphite-app[bot] merged 1 commit into
mainfrom
om/05-02-refactor_formatter_sortimportstransform_transform_return_vec_not_option_vec_

Conversation

@overlookmotel

@overlookmotel overlookmotel commented May 2, 2026

Copy link
Copy Markdown
Member

After #22065, the "return None if empty file" case can never fire, since it's only ever called with a segment of IR containing at least one ImportDeclaration. So remove the check, and make transform return Vec<FormatElement>, instead of Option<Vec<FormatElement>>.

overlookmotel commented May 2, 2026

Copy link
Copy Markdown
Member Author

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.

@overlookmotel overlookmotel changed the title refactor(formatter): SortImportsTransform::transform return Vec not Option<Vec>` refactor(formatter): SortImportsTransform::transform return Vec not Option<Vec> May 2, 2026
@overlookmotel overlookmotel marked this pull request as ready for review May 2, 2026 10:54
Copilot AI review requested due to automatic review settings May 2, 2026 10:54
@overlookmotel overlookmotel added C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior A-formatter Area - Formatter labels May 2, 2026
@codspeed-hq

codspeed-hq Bot commented May 2, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 44 untouched benchmarks
⏩ 7 skipped benchmarks1


Comparing om/05-02-refactor_formatter_sortimportstransform_transform_return_vec_not_option_vec_ (51ec2d4) with main (2fd907d)

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.

Copilot AI 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.

Pull request overview

This PR refactors the formatter’s import-sorting IR transform to remove an unreachable empty-input branch introduced for the legacy whole-document case. Since import sorting is now driven on streaming “import chunks” (post-#22065) that always contain at least one ImportDeclaration, SortImportsTransform::transform no longer needs to return Option.

Changes:

  • Change SortImportsTransform::transform to return ArenaVec<FormatElement> instead of Option<ArenaVec<...>>.
  • Simplify sort_imports_chunk by removing the unreachable None handling and always splicing the sorted output back into the buffer.
  • Add a debug_assert! that the transform output ends with the synthesized Line(Hard) terminator.

@overlookmotel overlookmotel force-pushed the om/05-02-refactor_formatter_sortimportstransform_transform_return_vec_not_option_vec_ branch from b7045ab to f539758 Compare May 2, 2026 12:50
@overlookmotel overlookmotel force-pushed the om/05-02-perf_formatter_sort_imports_during_ir_construction branch from 331ffe6 to c744bdd Compare May 2, 2026 12:50
@graphite-app graphite-app Bot changed the base branch from om/05-02-perf_formatter_sort_imports_during_ir_construction to graphite-base/22073 May 3, 2026 20:44
@graphite-app graphite-app Bot force-pushed the graphite-base/22073 branch from c744bdd to 2fd907d Compare May 3, 2026 20:49
@graphite-app graphite-app Bot force-pushed the om/05-02-refactor_formatter_sortimportstransform_transform_return_vec_not_option_vec_ branch from f539758 to 801f277 Compare May 3, 2026 20:49
@graphite-app graphite-app Bot changed the base branch from graphite-base/22073 to main May 3, 2026 20:49
@graphite-app graphite-app Bot force-pushed the om/05-02-refactor_formatter_sortimportstransform_transform_return_vec_not_option_vec_ branch from 801f277 to 51ec2d4 Compare May 3, 2026 20:49
@graphite-app graphite-app Bot added the 0-merge Merge with Graphite Merge Queue label May 7, 2026
@graphite-app

graphite-app Bot commented May 7, 2026

Copy link
Copy Markdown
Contributor

Merge activity

…ot `Option<Vec>` (#22073)

After #22065, the "return `None` if empty file" case can never fire, since it's only ever called with a segment of IR containing at least one `ImportDeclaration`. So remove the check, and make `transform` return `Vec<FormatElement>`, instead of `Option<Vec<FormatElement>>`.
@graphite-app graphite-app Bot force-pushed the om/05-02-refactor_formatter_sortimportstransform_transform_return_vec_not_option_vec_ branch from 51ec2d4 to 5de13ff Compare May 7, 2026 02:22
@graphite-app graphite-app Bot merged commit 5de13ff into main May 7, 2026
28 checks passed
@graphite-app graphite-app Bot removed the 0-merge Merge with Graphite Merge Queue label May 7, 2026
@graphite-app graphite-app Bot deleted the om/05-02-refactor_formatter_sortimportstransform_transform_return_vec_not_option_vec_ branch May 7, 2026 02:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

3 participants