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

fix(parser): don't panic on $(...) without operator in macro calls (#9993) - #10005

Merged
orizi merged 1 commit into
mainfrom
orizi/05-29-fix_parser_don_t_panic_on_._without_operator_in_macro_calls_9993_
May 31, 2026
Merged

orizi merged 1 commit into
mainfrom
orizi/05-29-fix_parser_don_t_panic_on_._without_operator_in_macro_calls_9993_

Conversation

@orizi

@orizi orizi commented May 29, 2026

Copy link
Copy Markdown
Collaborator

Summary

In the parser, a missing repetition operator inside a macro call site ($(...) without ?, +, or *) previously hit an unreachable!() panic. The operator arm now produces a MacroRepetition​Operator::missing node instead, deferring validation to the semantic layer. Macro definitions continue to emit a hard parse error (E1031) when the operator is absent.


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?

At a macro call site, $(x) without a trailing operator is syntactically ambiguous but not necessarily illegal — the semantic layer is responsible for checking whether the shape matches the macro declaration. Hitting unreachable!() in the parser caused a panic instead of a recoverable missing-node, preventing any downstream diagnostic or recovery.


What was the behavior or documentation before?

Parsing a macro invocation containing $(...) with no repetition operator caused the parser to panic via unreachable!().


What is the behavior or documentation after?

The parser emits a MacroRepetitionOperator::missing node and continues without a diagnostic. The semantic layer is then responsible for deciding whether the missing operator is valid given the macro declaration. A new test case (expect_diagnostics: false) confirms that foo!($(x)) parses cleanly. Macro definitions still produce E1031 when the operator is missing, as validated by an additional test case (expect_diagnostics: true).


Related issue or discussion (if any)


Additional context

The distinction between call-site leniency and definition-site strictness is now documented with an inline comment in parser.rs.

…9993)

Macro-call token trees previously hit unreachable!() when a $(...) group
lacked a repetition operator. Replace with MacroRepetitionOperator::missing
and leave validation to the semantic layer — the macro declaration is the
authoritative source of truth on whether the call shape is legal.
Definition-site parsing keeps its existing E1031 diagnostic, now also
exercised on the RHS body of a definition by a new regression test.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@cursor

cursor Bot commented May 29, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
Parser-only behavior split between call sites and definitions; semantics unchanged except recoverable errors instead of panics.

Overview
Inline macro call sites no longer interpret $, ?, +, or * as macro matcher syntax. parse_token_tree only builds parenthesized subtrees or plain token leaves, so inputs like foo!($(x)) parse as a $ leaf plus nested tokens instead of hitting an unreachable!() when a repetition operator is missing.

Macro definitions still use structured parsing in try_parse_macro_element (repetitions, parameters, E1031 for a missing operator after $(...)).

New parser, expansion, and semantic regression tests cover opaque call-site tokens, literal + matching, and #9993 (mymac!($(x)) → no ICE, semantic “no matching rule”).

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

@reviewable-StarkWare

Copy link
Copy Markdown

This change is Reviewable

@orizi orizi linked an issue May 29, 2026 that may be closed by this pull request

@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 5 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 added this pull request to the merge queue May 31, 2026

@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 5 files and all commit messages, and made 1 comment.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on orizi).

Merged via the queue into main with commit ef0410a May 31, 2026
54 checks passed
@orizi
orizi deleted the orizi/05-29-fix_parser_don_t_panic_on_._without_operator_in_macro_calls_9993_ branch May 31, 2026 09:46
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.

bug: Macro-call missing repetition operator crashes parser

4 participants