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

doc(semantic): document the macro expansion error arms as defensive#10314
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

@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 updates with no runtime or diagnostic behavior changes.

Overview
Documentation-only change in macro_declaration.rs; macro expansion behavior is unchanged.

Adds a module-level note on MacroExpansionFailure: user code should not hit these variants today because declaration-time diagnostics block the bad cases, and the enum remains a defensive backstop if matching or expansion checking regresses.

Extends the expand_placeholder comment for the MissingCapture path to explain why an out-of-range group_indices entry cannot occur—indices come from group_count on enclosing $() blocks that already walked the placeholder’s capture tree.

Reviewed by Cursor Bugbot for commit 6067cf6. 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/doc-expansion-error-defensive branch from 581b678 to 92c87f9 Compare August 6, 2026 11:33
@orizi
orizi force-pushed the graph-plan/2026-08-03-macro-fixes/separator-grammar.sep-trailing-f13 branch from 36bb10c to 7905f7c Compare August 6, 2026 11:33
@orizi
orizi force-pushed the graph-plan/2026-08-03-macro-fixes/doc-expansion-error-defensive branch from 92c87f9 to edf9f91 Compare August 12, 2026 20:54
@orizi
orizi force-pushed the graph-plan/2026-08-03-macro-fixes/separator-grammar.sep-trailing-f13 branch from 7905f7c to 52d9322 Compare August 12, 2026 20:54
@orizi
orizi force-pushed the graph-plan/2026-08-03-macro-fixes/doc-expansion-error-defensive branch from edf9f91 to 5284225 Compare August 16, 2026 10:04
@orizi
orizi force-pushed the graph-plan/2026-08-03-macro-fixes/separator-grammar.sep-trailing-f13 branch from 52d9322 to 07e10f2 Compare August 16, 2026 10:04

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

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


a discussion (no related file):
Note: the comments below are from an automatic orizi-review run (Claude agents reviewing in Ori's style, findings adversarially verified before posting). Treat with the usual bot skepticism.


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

/// [`SemanticDiagnosticKind::MacroPlaceholderRepDriverMismatch`],
/// [`SemanticDiagnosticKind::MacroRepetitionWithoutRepeatingPlaceholder`] and
/// [`SemanticDiagnosticKind::DuplicateMacroPlaceholder`] (see the notes at the construction

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].


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

/// [`SemanticDiagnosticKind::MacroRepetitionWithoutRepeatingPlaceholder`] and
/// [`SemanticDiagnosticKind::DuplicateMacroPlaceholder`] (see the notes at the construction
/// sites). The variants are kept as a backstop, so that a rule a future matcher or checker change

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.


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

            // `UndefinedMacroPlaceholder` - or its captures are nested deeper than the blocks it is
            // used in, rejected there by `MacroPlaceholderRepDepthMismatch`. An out-of-range group
            // index cannot land here: every index was produced by `group_count` on an enclosing

"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.

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/doc-expansion-error-defensive branch from 5284225 to 6067cf6 Compare August 16, 2026 11:37
@orizi
orizi force-pushed the graph-plan/2026-08-03-macro-fixes/separator-grammar.sep-trailing-f13 branch from 07e10f2 to 3c518b8 Compare August 16, 2026 11:37
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