Skip to content

Fix formatter non-convergence for continuation EOL comments - #2543

Open
kbrunham-intel wants to merge 5 commits into
chipsalliance:masterfrom
kbrunham-intel:fix/2542
Open

Fix formatter non-convergence for continuation EOL comments#2543
kbrunham-intel wants to merge 5 commits into
chipsalliance:masterfrom
kbrunham-intel:fix/2542

Conversation

@kbrunham-intel

@kbrunham-intel kbrunham-intel commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fixes non-convergence when a wrapped assign is followed by column-aligned continuation EOL comments (format(format(x)) != format(x)).
  • CalculateEolCommentColumn now treats newlines in preserved leading whitespace like emit does (reset column after the last \n) instead of counting them as width.
  • Adds regression test ContinuationCommentAfterWrappedAssignConverges.

Fixes #2542

Test plan

Count only the width after the last newline in preserved leading
spaces when placing continuation comments after wrapped lines, so
re-formatting keeps a stable column (issue chipsalliance#2542).
@hzeller

hzeller commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator

Sorry, due to other changes, the formatter_test.cc now needs merging. Can you rebase ?
I have some initial comments.

line.Tokens().end() - 1)) {
AdjustColumnUsingTokenSpacing(ftoken, &column);
column += ftoken.token->text().length();
for (size_t i = 1; i < tokens.size(); ++i) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

since we're using tokens here first, I'd probably move the const auto &tokens = line.Tokens(); right in front of the for loop.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

Comment thread verible/verilog/formatting/formatter.cc Outdated
column += ftoken.token->text().length();
for (size_t i = 1; i < tokens.size(); ++i) {
const auto &ftoken = tokens[i];
switch (ftoken.before.action) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The previous implementation, that put the logic into its own function (AdjustColumnsUsingTokenSpacing()), was nicely separating that dense logic into the function call. Do you think we can do something here as well again ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've created a new helper function here to help with readability.

Resolve formatter_test.cc conflict by keeping
ContinuationCommentAfterWrappedAssignConverges alongside master's
stacked regression tests.
Move tokens lookup before the loop and factor spacing logic back into
AdjustColumnUsingTokenSpacing with the chipsalliance#2542 newline-aware preserve fix
(PR review feedback).
iterator-range and absl core_headers are unused after the chipsalliance#2542
refactor dropped make_range and ABSL_FALLTHROUGH_INTENDED.
@kbrunham-intel

Copy link
Copy Markdown
Contributor Author

Hi @hzeller. I've updated the PR and provided a change to incorporate your feedback. Please approve and merge the change if it is ready, or let me know what other feedback I should look to incorporate.

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.

Verible-verilog format fails when a wrapped assign has a multiline comment

2 participants