Skip to content

fix(formatter): stop adding trailing separators in macro call token trees - #10354

Merged
orizi merged 1 commit into
mainfrom
graph-plan/2026-08-03-macro-fixes/formatter-no-macro-trailing-separator
Aug 28, 2026
Merged

orizi merged 1 commit into
mainfrom
graph-plan/2026-08-03-macro-fixes/formatter-no-macro-trailing-separator

Conversation

@orizi

@orizi orizi commented Aug 23, 2026

Copy link
Copy Markdown
Collaborator

A trailing separator is meaningful to a user-defined macro's matcher -
the rules decide whether to accept it - so breaking a long macro call
across lines must not introduce one. Legacy plugin macros tolerate
either form, so the suppression applies to every token tree the
formatter routes through the arg-list rules.

Co-Authored-By: Claude Fable 5 noreply@anthropic.com

@reviewable-StarkWare

Copy link
Copy Markdown

This change is Reviewable

orizi commented Aug 23, 2026 •

Copy link
Copy Markdown
Collaborator Author

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

@cursor

cursor Bot commented Aug 23, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
Formatter-only behavior for macro/token-tree argument lists; no runtime or compilation semantics beyond how source is printed.

Overview
The Cairo formatter no longer injects trailing commas when it wraps long macro invocations (and other token trees handled as wrapped arg lists), and it keeps a trailing comma in the source when the macro matcher can see it.

Implementation: FormatterImpl tracks in_macro_token_tree while formatting token trees parsed as wrapped arg lists. In that mode, trailing break points do not use comma-if-broken (same idea as after comments), and TerminalComma is emitted even when list formatting would normally drop a trailing separator.

Tests: New linebreaking.cairo cases cover user macros with and without a trailing comma; expected snapshots are updated (including array! and similar macro calls that share this path).

Reviewed by Cursor Bugbot for commit 796d776. Bugbot is set up for automated code reviews on this repo. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit c8a4835. Configure here.

Comment thread crates/cairo-lang-formatter/src/formatter_impl.rs

@orizi orizi left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@orizi+AGNT made 1 comment and resolved 1 discussion.
Reviewable status: 0 of 32 files reviewed, all discussions resolved (waiting on eytan-starkware).

Comment thread crates/cairo-lang-formatter/src/formatter_impl.rs

@eytan-starkware eytan-starkware 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.

@eytan-starkware reviewed 32 files and all commit messages, and made 2 comments.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on orizi).


corelib/src/test/language_features/const_test.cairo line 385 at r2 (raw file):

                (starknet::ContractAddress, starknet::ClassHash),
                value::Const<starknet::ContractAddress, 1000>,
                value::Const<starknet::ClassHash, 1001>,

Why did this one disappear?


crates/cairo-lang-starknet/src/plugin/plugin_test_data/contracts/with_component_diagnostics line 1455 at r2 (raw file):

use starknet::storage::Map as LegacyMap;
#[cfg(target: 'test')]
pub const TEST_CLASS_HASH: starknet::ClassHash = 0x215c44bbf0e7c3b987e93bf1597778322461e87fd0059894735b0464ce94aff.try_into().unwrap();

Why did this change?

@orizi orizi left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@orizi+AGNT made 2 comments.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on eytan-starkware).


corelib/src/test/language_features/const_test.cairo line 385 at r2 (raw file):

Previously, eytan-starkware wrote…

Why did this one disappear?

It is this PR's change applied repo-wide: assert! is a macro call, so its arguments are a macro token tree, and the formatter no longer introduces a trailing comma when breaking one across lines. All the disappearing commas in this file (19 of them) are that - previously the formatter added them on the break; they were never written by hand. For assert! the comma was harmless, but the formatter cannot tell a plugin macro from a user-defined one, where the matcher sees the extra token.


crates/cairo-lang-starknet/src/plugin/plugin_test_data/contracts/with_component_diagnostics line 1455 at r2 (raw file):

Previously, eytan-starkware wrote…

Why did this change?

Downstream of the same reformat: the component! call in this test's contract lost its formatter-added trailing comma, so the contract's source text changed - and TEST_CLASS_HASH is computed from that source, so re-blessing updated the hash (and the diagnostic snippet quoting the call).

@eytan-starkware eytan-starkware 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.

@eytan-starkware made 1 comment and resolved 1 discussion.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on orizi+AGNT).


corelib/src/test/language_features/const_test.cairo line 385 at r2 (raw file):

Previously, orizi+AGNT (Agent AGNT for orizi) wrote…

It is this PR's change applied repo-wide: assert! is a macro call, so its arguments are a macro token tree, and the formatter no longer introduces a trailing comma when breaking one across lines. All the disappearing commas in this file (19 of them) are that - previously the formatter added them on the break; they were never written by hand. For assert! the comma was harmless, but the formatter cannot tell a plugin macro from a user-defined one, where the matcher sees the extra token.

But the comma I am talking about is in the generic arguments of const

@orizi orizi left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@orizi+AGNT made 3 comments.
Reviewable status: 1 of 32 files reviewed, 1 unresolved discussion (waiting on eytan-starkware).


corelib/src/test/language_features/const_test.cairo line 385 at r2 (raw file):

Previously, eytan-starkware wrote…

But the comma I am talking about is in the generic arguments of const

Update: the PR was reworked and this diff is gone. Ori's point stands - a comma the author wrote is just as matcher-visible as one the formatter would add - so the formatter now keeps a macro token tree's trailing separator exactly as written: never added, never removed. With that, the repo-wide reformat (including this file) vanished; the PR is down to the formatter change and its tests.


crates/cairo-lang-starknet/src/plugin/plugin_test_data/contracts/with_component_diagnostics line 1455 at r2 (raw file):

Previously, orizi+AGNT (Agent AGNT for orizi) wrote…

Downstream of the same reformat: the component! call in this test's contract lost its formatter-added trailing comma, so the contract's source text changed - and TEST_CLASS_HASH is computed from that source, so re-blessing updated the hash (and the diagnostic snippet quoting the call).

Update: gone after the rework - the formatter now preserves the separator as written instead of normalizing it, so this golden (and its class hash) reverted to main.

Comment thread crates/cairo-lang-formatter/src/formatter_impl.rs
@orizi
orizi enabled auto-merge August 25, 2026 12:34

@eytan-starkware eytan-starkware 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.

@eytan-starkware reviewed 31 files and all commit messages, made 1 comment, and resolved 1 discussion.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on orizi).


crates/cairo-lang-formatter/src/formatter_impl.rs line 937 at r3 (raw file):

    /// Whether the node being formatted came from a macro call's token tree. A trailing
    /// separator is meaningful to a user-defined macro's matcher - the rules decide whether to
    /// accept it - so the formatter keeps it exactly as written: one is neither introduced when

prosy

…ritten

A trailing separator is meaningful to a user-defined macro's matcher - the rules decide
whether to accept it - so the formatter neither introduces one when breaking the call
across lines nor removes one the author wrote.
@orizi
orizi force-pushed the graph-plan/2026-08-03-macro-fixes/formatter-no-macro-trailing-separator branch from b90a8cd to 796d776 Compare August 26, 2026 19:59

@orizi orizi left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@orizi+AGNT made 1 comment.
Reviewable status: 31 of 32 files reviewed, 1 unresolved discussion (waiting on eytan-starkware).


crates/cairo-lang-formatter/src/formatter_impl.rs line 937 at r3 (raw file):

Previously, eytan-starkware wrote…

prosy

Tightened to two lines.

@eytan-starkware eytan-starkware 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.

:lgtm:

@eytan-starkware reviewed 1 file and all commit messages, made 1 comment, and resolved 1 discussion.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on orizi).

@orizi
orizi added this pull request to the merge queue Aug 28, 2026
Merged via the queue into main with commit 3943815 Aug 28, 2026
55 checks passed
@orizi
orizi deleted the graph-plan/2026-08-03-macro-fixes/formatter-no-macro-trailing-separator branch August 31, 2026 12:49
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.

3 participants