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

Avoid panic when an item-scope inline macro lacks an arg-list bracket - #9961

Merged
orizi merged 1 commit into
mainfrom
orizi/fix-9938-macro-item-scope-no-brackets-ice
May 19, 2026
Merged

orizi merged 1 commit into
mainfrom
orizi/fix-9938-macro-item-scope-no-brackets-ice

Conversation

@orizi

@orizi orizi commented May 18, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes an ICE (Internal Compiler Error) that occurred when a user-defined inline macro was invoked at item scope without argument brackets (e.g., m! with no following (...), [...], or {...}). The Missing variant of WrappedTokenTree was previously marked unreachable!(), causing a panic. It now returns None from is_macro_rule_match, allowing the compiler to emit proper diagnostics instead of crashing.


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 a user-defined inline macro was invoked without an argument list at item scope, the WrappedTokenTree::Missing variant was hit inside is_macro_rule_match, which contained an unreachable!() assertion. This caused the compiler to panic (ICE) rather than report a diagnostic.


What was the behavior or documentation before?

The compiler would ICE when encountering a macro invocation like m! (missing argument brackets) at item scope.


What is the behavior or documentation after?

The compiler now gracefully handles the missing argument list by returning None from is_macro_rule_match, resulting in proper diagnostics:

  • E1006: Missing tokens — expected an argument list wrapped in parentheses, brackets, or braces.
  • E1001: Missing token ;.
  • E2158: No matching rule found in inline macro m.

Related issue or discussion (if any)

Regression fix for #9938.


Additional context

A test case covering this regression has been added to the inline macros test data.

@reviewable-StarkWare

Copy link
Copy Markdown

This change is Reviewable

orizi commented May 18, 2026 •

Copy link
Copy Markdown
Collaborator Author

@orizi
orizi marked this pull request as ready for review May 18, 2026 19:12
@cursor

cursor Bot commented May 18, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
Low risk: a small control-flow change replaces an unreachable!() with a graceful non-match, plus a regression test; main risk is subtle behavior change in macro matching for malformed invocations.

Overview
Fixes an ICE when a user-defined inline macro is invoked at item scope without an argument list (e.g. m!) by treating WrappedTokenTree::Missing as a non-match in is_macro_rule_match instead of panicking.

Adds a regression test case in expr/test_data/inline_macros that asserts the compiler reports the expected missing-argument diagnostics rather than crashing.

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

@orizi
orizi force-pushed the orizi/fix-9936-macro-param-kind-ice branch from 5c574c7 to 873e65e Compare May 19, 2026 05:47
@orizi
orizi force-pushed the orizi/fix-9938-macro-item-scope-no-brackets-ice branch from dd93a77 to 53d4ff2 Compare May 19, 2026 05:47

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

Item-scope invocations like `m!` (no `()` / `[]` / `{}`) construct an
`ItemInlineMacro` whose argument subtree is `WrappedTokenTree::Missing(_)`. The
parser already reports `E1006`; `is_macro_rule_match` then panicked on the
`unreachable!` arm of the bracket-shape dispatch.

Return `None` for the `Missing` arm so the rule simply fails to match and the
caller's `InlineMacroNoMatchingRule` path takes over. Function-scope invocations
already short-circuit before reaching this function, so they are unaffected.

Fixes #9938.
@orizi
orizi changed the base branch from orizi/fix-9936-macro-param-kind-ice to graphite-base/9961 May 19, 2026 07:51
@orizi
orizi force-pushed the orizi/fix-9938-macro-item-scope-no-brackets-ice branch from 53d4ff2 to fd7802d Compare May 19, 2026 07:51
@orizi
orizi force-pushed the graphite-base/9961 branch from 873e65e to 504f0a6 Compare May 19, 2026 07:51
@orizi
orizi changed the base branch from graphite-base/9961 to main May 19, 2026 07:51
@orizi
orizi added this pull request to the merge queue May 19, 2026
Merged via the queue into main with commit adf04c1 May 19, 2026
105 checks passed
@orizi
orizi deleted the orizi/fix-9938-macro-item-scope-no-brackets-ice branch May 19, 2026 12:30
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