refactor(fmt): use canonical layouts#15845
Draft
DaniPopes wants to merge 22 commits into
Draft
Conversation
Replace source-span width estimates for wrapped line comments with named document groups. Track emitted breaks separately from overflowing unbreakable content and measure retained strings by display characters.
Replace assignment and initializer span-size arithmetic with structural formatter groups and continuation breaks. Keep lvalue and declaration heads stable while nested RHS documents choose their own layout.
Let retained document groups choose call-chain, assignment, and conditional layouts. Remove source-span estimators, remaining-space probes, callee byte counts, and block-depth width bookkeeping.
This reverts commit b9bcfa8.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This replaces formatter-side source-span and remaining-space estimates with retained canonical documents whose groups, fit probes, alternatives, conditional layout, and line suffixes are resolved by the renderer. It migrates declarations, assignments, function headers, call chains, comments, inline statements, and Yul layout to renderer-owned decisions, removes the duplicated size-estimation helpers, and measures layout in display columns rather than UTF-8 bytes.
Review-driven stabilization fixed the noncanonical header, declaration RHS, disabled-span, Yul comment, binary continuation, call-chain, struct, tuple-assignment, return, comment-alignment, and force/flatten interactions exposed during the migration. Assignment layout now composes a transparent RHS baseline with ordinary continuation and list indentation, avoiding source-dependent or first-nested-call state.
A final repository-wide fixture pass added adaptive call-chain continuations, preserved compact named calls on assignment continuations, and made single-line binary-return blocks depend on canonical rendered fit. Wrapping binary returns and their nested or if/else ancestors conservatively retain braces. Existing formatter golden outputs and repository Solidity fixtures are unchanged, while focused regressions cover the reviewed layout boundaries and second-pass convergence. Three independent final reviews found no remaining actionable issues.
AI assistance was used to research pretty-printing architectures, implement the retained-document migration, and independently review the resulting changes.