Skip to content

bugfix(defs): Name macro-call modules by macro name and offset, not raw call text.#10197

Merged
eytan-starkware merged 1 commit into
mainfrom
eytan_graphite/bugfix_defs_name_macro-call_modules_by_macro_name_and_offset_not_raw_call_text
Jul 8, 2026
Merged

bugfix(defs): Name macro-call modules by macro name and offset, not raw call text.#10197
eytan-starkware merged 1 commit into
mainfrom
eytan_graphite/bugfix_defs_name_macro-call_modules_by_macro_name_and_offset_not_raw_call_text

Conversation

@eytan-starkware

@eytan-starkware eytan-starkware commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Anonymous modules generated by item-level inline macro calls are now named after the invoked macro and disambiguated by the call-site byte offset in the file (e.g., make_pair_75) instead of using the full raw syntax text of the call as the module name.


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?

Previously, the name of the hidden module wrapping items produced by a top-level inline macro call was derived from the entire raw syntax text of the macro invocation, which produced unwieldy and fragile identifiers. When the same macro is invoked multiple times, each call needs a distinct, stable, and human-readable module name so that full paths of generated items (e.g., free functions) are predictable and debuggable.


What was the behavior or documentation before?

The anonymous macro-call module was named by calling get_text_without_trivia on the entire syntax node of the macro call, yielding the raw invocation text as the module name.


What is the behavior or documentation after?

The module is named <macro_name>_<byte_offset>, where <macro_name> is the final identifier of the macro's path and <byte_offset> is the call's offset within the source file. For example, two calls to make_pair!() at offsets 75 and 90 produce modules named make_pair_75 and make_pair_90, giving generated functions full paths like test::make_pair_75::a and test::make_pair_90::b. For macros invoked via a qualified path (e.g., helpers::make_pair!()), only the final identifier is used.

A new test file (macro_call_test.rs) and accompanying test data (tests/macro_call) are added to verify full paths for: a single macro call, repeated macro calls producing distinct modules, and a macro invoked via a qualified path.


Related issue or discussion (if any)


Additional context

The offset-based disambiguation ensures that two calls to the same macro always produce different module names without requiring any global counter or additional state.

@reviewable-StarkWare

Copy link
Copy Markdown

This change is Reviewable

Copy link
Copy Markdown
Contributor Author

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

@eytan-starkware eytan-starkware marked this pull request as ready for review July 8, 2026 11:14
@cursor

cursor Bot commented Jul 8, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Changing macro-call module naming alters full paths and diagnostic text across the compiler; behavior is intentional but any external reliance on the old raw-text module names would break.

Overview
Item-level inline macro calls no longer use the full raw invocation text as the anonymous module name. ModuleId::MacroCall::name now builds {macro_identifier}!_#{byte_offset} from the macro path’s final identifier and the call’s syntax offset (qualified paths still use only the macro name, e.g. make_impl!_#156).

Semantic tests were added so repeated make_impl!() calls produce distinct module paths in trait-conflict diagnostics, including when the macro is invoked as helpers::make_impl!().

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

Comment thread crates/cairo-lang-defs/src/ids.rs Outdated
@eytan-starkware eytan-starkware force-pushed the eytan_graphite/bugfix_defs_name_macro-call_modules_by_macro_name_and_offset_not_raw_call_text branch from 6076d33 to fe17ea6 Compare July 8, 2026 11:19

@orizi orizi 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.

@orizi made 1 comment.
Reviewable status: 0 of 4 files reviewed, 2 unresolved discussions (waiting on eytan-starkware and TomerStarkware).


crates/cairo-lang-semantic/src/items/macro_call_test.rs line 23 at r1 (raw file):

/// modules generated by item-level inline macro calls.
fn test_macro_call_item_full_paths(
    inputs: &OrderedHashMap<String, String>,

i think you can use diagnostics to "expose" the actual path we provide.

Comment thread crates/cairo-lang-defs/src/ids.rs Outdated
@eytan-starkware eytan-starkware force-pushed the eytan_graphite/bugfix_defs_name_macro-call_modules_by_macro_name_and_offset_not_raw_call_text branch from fe17ea6 to c2ab364 Compare July 8, 2026 11:41

@eytan-starkware eytan-starkware left a comment

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.

@eytan-starkware made 1 comment.
Reviewable status: 0 of 5 files reviewed, 1 unresolved discussion (waiting on orizi and TomerStarkware).


crates/cairo-lang-semantic/src/items/macro_call_test.rs line 23 at r1 (raw file):

Previously, orizi wrote…

i think you can use diagnostics to "expose" the actual path we provide.

Done.

@eytan-starkware eytan-starkware force-pushed the eytan_graphite/bugfix_defs_name_macro-call_modules_by_macro_name_and_offset_not_raw_call_text branch from c2ab364 to 9075a01 Compare July 8, 2026 11:46

@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 9075a01. Configure here.

Comment thread crates/cairo-lang-defs/src/ids.rs Outdated

@orizi orizi 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:

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

@eytan-starkware eytan-starkware force-pushed the eytan_graphite/bugfix_defs_name_macro-call_modules_by_macro_name_and_offset_not_raw_call_text branch from 9075a01 to 4c314ab Compare July 8, 2026 11:58

@orizi orizi 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:

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

@eytan-starkware eytan-starkware added this pull request to the merge queue Jul 8, 2026
Merged via the queue into main with commit b585bc3 Jul 8, 2026
55 checks passed

Copy link
Copy Markdown

Security scan complete — no issues detected.


Generated by Claude Code

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.

4 participants