Skip to content

Fix formatter non-convergence for multi-line macro sums - #2548

Open
kbrunham-intel wants to merge 4 commits into
chipsalliance:masterfrom
kbrunham-intel:fix/2547
Open

Fix formatter non-convergence for multi-line macro sums#2548
kbrunham-intel wants to merge 4 commits into
chipsalliance:masterfrom
kbrunham-intel:fix/2547

Conversation

@kbrunham-intel

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

Copy link
Copy Markdown
Contributor

Summary

  • Fixes Formatter: non-convergence wrapping a multi-line sum of long macros in a localparam #2547: non-convergence when a localparam is initialized to a multi-line sum of long `MACRO identifiers (format(format(x)) != format(x)).
  • Infix + partitions under kParamDeclaration are always attached to the following operand, so partition shape no longer depends on original newlines.
  • Treats spelling-equal MacroIdentifier / MacroIdItem (and MacroCallCloseToEndLine / )) as format-equivalent via shared helper TokensAreWhitespaceDependentFormatEquivalent(), so verification tolerates macros moving relative to ;.
  • Adds regression test LongMacroSumLocalparamConverges.

Fixes #2547

Overlap with #2545

This PR includes the MacroIdentifier/MacroIdItem FormatEquivalent change also proposed in #2545. If #2545 merges first, those equivalence-file hunks should be dropped from this PR (or this PR rebased) to avoid duplicate commits. The tree-unwrapper infix-operator attachment is unique to this fix.

Test plan

Always attach infix-operator-only partitions to the following operand
in localparam expressions, and treat spelling-equal MacroIdentifier and
MacroIdItem as format-equivalent, so long `MACRO + MACRO` sums no
longer oscillate under re-format (issue chipsalliance#2547).
@kbrunham-intel

Copy link
Copy Markdown
Contributor Author

Note on overlap with #2545: this PR also includes treating spelling-equal MacroIdentifier / MacroIdItem as format-equivalent (needed so moving ; onto the last macro in the sum does not fail lexical verification). That change is the same as in #2545.

If #2545 lands first, please drop or rebase away the verilog-equivalence.cc / verilog-equivalence_test.cc hunks here—the remaining tree-unwrapper change (AttachInfixOperatorsToFollowingOperands for kParamDeclaration) is the part unique to #2547.

@hzeller

hzeller commented Jul 19, 2026

Copy link
Copy Markdown
Collaborator

I've changed the Mac CI, can you rebase and see if that resolves that CI failure ?

// Some token enums differ only by surrounding whitespace (e.g. whether a
// macro or ')' ends a line). Treat those pairs as matching enums when the
// spelling is unchanged so FormatEquivalent tolerates re-wrapping.
const bool whitespace_dependent_enum_match =

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.

(similar to the other PR).
Maybe we should have some predicate function getting left/right const Token references and return the context-dependent result ? TODO: find good name for that predicate function)

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 predicate function to help here.

@hzeller

hzeller commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator

Just had a quick look, but maybe we should rebase first so that we can get the formatter test unconflicted.

Resolve formatter_test.cc conflict by keeping LongMacroSumLocalparamConverges
alongside master's stacked regression tests.
Factor MacroCallCloseToEndLine/')' and MacroIdentifier/MacroIdItem
matching into TokensAreWhitespaceDependentFormatEquivalent(), reusing
it in LexicallyEquivalent and FormatEquivalent (PR review feedback).
@kbrunham-intel

Copy link
Copy Markdown
Contributor Author

HI @hzeller Please review this update and let me know if there is any more feedback.

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.

Formatter: non-convergence wrapping a multi-line sum of long macros in a localparam

2 participants