Skip to content

doc(semantic): document the macro expansion error arms as defensive - #10314

Open
orizi wants to merge 1 commit into
graph-plan/2026-08-03-macro-fixes/separator-grammar.sep-trailing-f13from
graph-plan/2026-08-03-macro-fixes/doc-expansion-error-defensive
Open

orizi wants to merge 1 commit into
graph-plan/2026-08-03-macro-fixes/separator-grammar.sep-trailing-f13from
graph-plan/2026-08-03-macro-fixes/doc-expansion-error-defensive

Conversation

@orizi

@orizi orizi commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

E2202's two arms are unreachable from user code: each is foreclosed by a
declaration-time check (E2193/E2198/E2199/E2203/E2204). State that on the
enum, and complete the expand_placeholder note with why an out-of-range
group index cannot occur.

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

@reviewable-StarkWare

Copy link
Copy Markdown

This change is Reviewable

orizi commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator Author

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

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

@orizi
orizi force-pushed the graph-plan/2026-08-03-macro-fixes/doc-expansion-error-defensive branch 2 times, most recently from b559512 to 71fa44b Compare August 4, 2026 08:56
@orizi
orizi force-pushed the graph-plan/2026-08-03-macro-fixes/separator-grammar.sep-trailing-f13 branch from 0c024e9 to ec48061 Compare August 4, 2026 08:56
@orizi
orizi force-pushed the graph-plan/2026-08-03-macro-fixes/doc-expansion-error-defensive branch from 71fa44b to 61861f5 Compare August 5, 2026 10:54
@orizi
orizi marked this pull request as ready for review August 5, 2026 11:10
@cursor

cursor Bot commented Aug 5, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
Comment-only changes in macro expansion code; no behavior or diagnostics logic is modified.

Overview
Documentation-only update clarifying that MacroExpansionFailure (reported as E2202 at expansion time) is a defensive layer: valid user macros should never hit these paths because declaration-time checks already reject the same situations.

The enum-level doc now states that purpose and links each variant to the foreclosing SemanticDiagnosticKind (e.g. MissingRepetitionDriverMacroRepetitionWithoutRepeatingPlaceholder, MissingCapture → undefined/depth/duplicate placeholder errors). Comments in expand_placeholder and group_count are aligned—explaining why an out-of-range group index cannot occur at runtime, and pointing readers to MacroExpansionFailure instead of duplicating the “verify at expansion” rationale.

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

@orizi
orizi force-pushed the graph-plan/2026-08-03-macro-fixes/doc-expansion-error-defensive branch from 61861f5 to 581b678 Compare August 5, 2026 15:15
@orizi
orizi force-pushed the graph-plan/2026-08-03-macro-fixes/separator-grammar.sep-trailing-f13 branch from 0be1ab1 to 36bb10c Compare August 5, 2026 15:15
@orizi
orizi force-pushed the graph-plan/2026-08-03-macro-fixes/separator-grammar.sep-trailing-f13 branch from e02e2e6 to e367efd Compare August 17, 2026 19:07
@orizi
orizi force-pushed the graph-plan/2026-08-03-macro-fixes/doc-expansion-error-defensive branch 2 times, most recently from c6ccdef to a454a87 Compare August 23, 2026 08:43
@orizi
orizi force-pushed the graph-plan/2026-08-03-macro-fixes/separator-grammar.sep-trailing-f13 branch from e367efd to 45f9002 Compare August 23, 2026 08:43
@orizi
orizi force-pushed the graph-plan/2026-08-03-macro-fixes/doc-expansion-error-defensive branch from a454a87 to d5a0d2d Compare August 23, 2026 08:50
@orizi
orizi force-pushed the graph-plan/2026-08-03-macro-fixes/separator-grammar.sep-trailing-f13 branch from 45f9002 to 6f2de0a Compare August 23, 2026 08:50
@orizi
orizi force-pushed the graph-plan/2026-08-03-macro-fixes/doc-expansion-error-defensive branch from d5a0d2d to d621f68 Compare August 23, 2026 10:31
@orizi
orizi force-pushed the graph-plan/2026-08-03-macro-fixes/separator-grammar.sep-trailing-f13 branch from 51cb00c to ba86d3d Compare August 23, 2026 11:22
@orizi
orizi force-pushed the graph-plan/2026-08-03-macro-fixes/doc-expansion-error-defensive branch from d621f68 to 8b23a11 Compare August 23, 2026 11:22

@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 and resolved 3 discussions.
Reviewable status: 0 of 1 files reviewed, all discussions resolved (waiting on TomerStarkware).


crates/cairo-lang-semantic/src/items/macro_declaration.rs line 1077 at r2 (raw file):

Previously, eytan-starkware+AGNT (Agent AGNT for eytan-starkware) wrote…

a flat list of five checks for three variants doesn't say which check forecloses which arm - that mapping is the only useful part of this doc. and see the notes at the construction sites over-promises: of the five, only UndefinedMacroPlaceholder and MacroPlaceholderRepDepthMismatch are actually named at a construction site (the MissingCapture note); MacroRepetitionWithoutRepeatingPlaceholder, MacroPlaceholderRepDriverMismatch and DuplicateMacroPlaceholder are not named at any of the three. put one line on each variant instead:

/// No user-writable program currently reaches any of these variants: expansion only runs on rules
/// that have passed the declaration-time checks, and each variant below names the check
/// foreclosing it. They are kept as a backstop, so that a rule a future matcher or checker change
/// lets through fails with a diagnostic instead of expanding to something arbitrary.

and on the arms - MissingRepetitionDriver: foreclosed by
[SemanticDiagnosticKind::MacroRepetitionWithoutRepeatingPlaceholder]; ConflictingRepetitionDrivers: by [SemanticDiagnosticKind::MacroPlaceholderRepDriverMismatch]; MissingCapture: by [SemanticDiagnosticKind::UndefinedMacroPlaceholder], [SemanticDiagnosticKind::MacroPlaceholderRepDepthMismatch] and [SemanticDiagnosticKind::DuplicateMacroPlaceholder].

Taken - the enum doc is the suggested paragraph and each variant names the check foreclosing it.


crates/cairo-lang-semantic/src/items/macro_declaration.rs line 1078 at r2 (raw file):

Previously, eytan-starkware+AGNT (Agent AGNT for eytan-starkware) wrote…

this sentence is already in group_count's doc, almost verbatim ("so that a pattern the checks do not cover fails with a diagnostic instead of expanding to something arbitrary"). say it once - here on the enum - and drop it there, or vice versa.

Said once, on the enum - group_count's doc now defers to it.


crates/cairo-lang-semantic/src/items/macro_declaration.rs line 1235 at r2 (raw file):

Previously, eytan-starkware+AGNT (Agent AGNT for eytan-starkware) wrote…

"scanned this placeholder's tree" isn't the argument - group_count skips a placeholder whose at gives a Leaf or None, so a scan by itself bounds nothing. the actual reason is that a Seq of a different length is rejected as ConflictingRepetitionDrivers, and a Leaf is returned by at for any remaining indices. state that:

            // index cannot land here: every index came from `group_count` on an enclosing block,
            // which scanned this placeholder (a descendant of that block) before descending - so
            // its tree is either a `Seq` of exactly that length, a shorter one having been
            // rejected as `ConflictingRepetitionDrivers`, or a `Leaf`, which `at` returns for any
            // remaining indices.

Taken as suggested.

@orizi
orizi force-pushed the graph-plan/2026-08-03-macro-fixes/separator-grammar.sep-trailing-f13 branch from ba86d3d to 7292851 Compare August 23, 2026 12:03
@orizi
orizi force-pushed the graph-plan/2026-08-03-macro-fixes/doc-expansion-error-defensive branch from 8b23a11 to fb44fb8 Compare August 23, 2026 12:03
@orizi
orizi force-pushed the graph-plan/2026-08-03-macro-fixes/separator-grammar.sep-trailing-f13 branch from 7292851 to aec79ab Compare August 25, 2026 12:30
@orizi
orizi force-pushed the graph-plan/2026-08-03-macro-fixes/doc-expansion-error-defensive branch from fb44fb8 to 083c15c Compare August 25, 2026 12:30
@orizi
orizi force-pushed the graph-plan/2026-08-03-macro-fixes/separator-grammar.sep-trailing-f13 branch from aec79ab to 8553fee Compare August 26, 2026 19:59
@orizi
orizi force-pushed the graph-plan/2026-08-03-macro-fixes/doc-expansion-error-defensive branch 2 times, most recently from 0d8844c to ca492eb Compare August 27, 2026 04:32
@orizi
orizi force-pushed the graph-plan/2026-08-03-macro-fixes/separator-grammar.sep-trailing-f13 branch from 8553fee to c0f9af3 Compare August 27, 2026 04:32
@orizi
orizi force-pushed the graph-plan/2026-08-03-macro-fixes/doc-expansion-error-defensive branch from ca492eb to 77b3591 Compare August 27, 2026 13:33
@orizi
orizi force-pushed the graph-plan/2026-08-03-macro-fixes/separator-grammar.sep-trailing-f13 branch 2 times, most recently from 2ba390a to de086ba Compare August 28, 2026 10:07
@orizi
orizi force-pushed the graph-plan/2026-08-03-macro-fixes/doc-expansion-error-defensive branch 2 times, most recently from 2bc894b to 8b3f58b Compare August 28, 2026 12:58
@orizi
orizi force-pushed the graph-plan/2026-08-03-macro-fixes/separator-grammar.sep-trailing-f13 branch from de086ba to 5f84d2e Compare August 28, 2026 12:58
@orizi
orizi force-pushed the graph-plan/2026-08-03-macro-fixes/doc-expansion-error-defensive branch from 8b3f58b to ce3f35c Compare September 14, 2026 04:51
@orizi
orizi force-pushed the graph-plan/2026-08-03-macro-fixes/separator-grammar.sep-trailing-f13 branch from 5f84d2e to 59bc381 Compare September 14, 2026 04:51
E2202's two arms are unreachable from user code: each is foreclosed by a
declaration-time check (E2193/E2198/E2199/E2203/E2204). State that on the
enum, and complete the expand_placeholder note with why an out-of-range
group index cannot occur.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@orizi
orizi force-pushed the graph-plan/2026-08-03-macro-fixes/separator-grammar.sep-trailing-f13 branch from 59bc381 to f2e70ec Compare September 14, 2026 06:56
@orizi
orizi force-pushed the graph-plan/2026-08-03-macro-fixes/doc-expansion-error-defensive branch from ce3f35c to ea8bb08 Compare September 14, 2026 06:56
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