Sitelet https://github.com/starkware-libs/cairo/pull/10150
Skip to content

bugfix(formatter): Made formatter merge in use more consistent. - #10150

Merged
orizi merged 1 commit into
mainfrom
orizi/06-22-bugfix_formatter_made_formatter_merge_in_use_more_consistent
Jun 23, 2026
Merged

orizi merged 1 commit into
mainfrom
orizi/06-22-bugfix_formatter_made_formatter_merge_in_use_more_consistent

Conversation

@orizi

@orizi orizi commented Jun 22, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes incorrect sorting of nested use path groups containing Multi variants.

The compare_use_paths function previously fell back to an empty string when comparing Multi use path variants, causing incorrect sort ordering for groups like {self, m} and {a, m}. The comparison now recurses via compare_use_paths itself to find the minimum child path, producing a correct and stable ordering.


Type of change

Please check one:

  • Bug fix (fixes incorrect behavior)
  • New feature
  • Performance improvement
  • Documentation change with concrete technical impact
  • Style, wording, formatting, or typo-only change

Why is this change needed?

When sorting nested use import groups, the Multi variant was assigned an empty string as its sort key instead of being compared recursively. This caused use x::{{self, m}, {a, m}}; and similar patterns to be ordered incorrectly.


What was the behavior or documentation before?

Nested use path groups with Multi variants were compared using an empty string fallback, so their relative ordering was undefined and incorrect. For example, {self, m} and {a, m} were not sorted by their actual minimum child paths.


What is the behavior or documentation after?

Nested use path groups are sorted by recursively comparing their minimum child paths using compare_use_paths, producing a correct and stable ordering. The expected sort order for several existing test cases is also corrected as a result.


Related issue or discussion (if any)

None.


Additional context

A new test case use x::{{self, m}, {a, m}}; is added to sort_inner_use.cairo to cover the previously broken multi-group comparison. The get_min_child closure is simplified by replacing the manual key extraction with a direct call to compare_use_paths, removing the need for the empty_string fallback variable.

@reviewable-StarkWare

Copy link
Copy Markdown

This change is Reviewable

orizi commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator Author

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

@orizi
orizi force-pushed the orizi/06-22-bugfix_formatter_made_formatter_merge_in_use_more_consistent branch from f7a6366 to 7a52914 Compare June 22, 2026 12:20

@TomerStarkware TomerStarkware left a comment

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.

:lgtm:

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

@orizi
orizi marked this pull request as ready for review June 23, 2026 07:50
@orizi
orizi added this pull request to the merge queue Jun 23, 2026
@cursor

cursor Bot commented Jun 23, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
Formatter-only sort/merge behavior for use statements; no compilation, runtime, or security impact.

Overview
Fixes incorrect ordering when the formatter sorts nested use path groups that contain Multi branches (e.g. use x::{{self, m}, {a, m}}).

In compare_use_paths, comparing two UsePath::Multi nodes no longer picks a minimum child via min_by_key on leaf/single idents with an empty-string fallback for nested multis. get_min_child now uses min_by(|a, b| compare_use_paths(a, b, db)), so sibling groups are ordered by their true minimum path under the same rules as the rest of the sorter.

Formatter tests add use x::{{self, m}, {a, m}} and refresh expected output for a few existing nested-a cases so golden files match the corrected sort.

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

Merged via the queue into main with commit 792625f Jun 23, 2026
55 checks passed
@orizi
orizi deleted the orizi/06-22-bugfix_formatter_made_formatter_merge_in_use_more_consistent branch June 23, 2026 08:03
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