doc(semantic): document the macro expansion error arms as defensive - #10314
Conversation
b559512 to
71fa44b
Compare
0c024e9 to
ec48061
Compare
71fa44b to
61861f5
Compare
PR SummaryLow Risk Overview Adds a module-level note on Extends the Reviewed by Cursor Bugbot for commit 6067cf6. Bugbot is set up for automated code reviews on this repo. Configure here. |
61861f5 to
581b678
Compare
0be1ab1 to
36bb10c
Compare
581b678 to
92c87f9
Compare
36bb10c to
7905f7c
Compare
92c87f9 to
edf9f91
Compare
7905f7c to
52d9322
Compare
edf9f91 to
5284225
Compare
52d9322 to
07e10f2
Compare
eytan-starkware
left a comment
There was a problem hiding this comment.
@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>
5284225 to
6067cf6
Compare
07e10f2 to
3c518b8
Compare

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