Skip to content

feature(semantic): Recognize Span<T> in fixed-size array patterns#9826

Merged
ilyalesokhin-starkware merged 1 commit intomainfrom
ilya/span_pattern_semantic
Apr 12, 2026
Merged

feature(semantic): Recognize Span<T> in fixed-size array patterns#9826
ilyalesokhin-starkware merged 1 commit intomainfrom
ilya/span_pattern_semantic

Conversation

@ilyalesokhin-starkware
Copy link
Copy Markdown
Contributor

@ilyalesokhin-starkware ilyalesokhin-starkware commented Apr 9, 2026

Teach the semantic layer to accept [a, b, c] patterns when matching on Span<T>, converting the pattern type to @[T; N]. The lowering layer reports an unsupported-type diagnostic for now; full lowering support will follow in a subsequent PR.


Note

Medium Risk
Changes semantic pattern typing so [a, b, ...] may type-check against Span<T>, which can affect type inference and diagnostics in match/let-else. Lowering explicitly rejects these patterns for now, so there’s limited runtime impact but potential for new compile-time behaviors/regressions.

Overview
Enables fixed-size array patterns like [a, b] to be semantically valid when the matched expression has type Span<T>, by treating the match as a fixed-size array of length N (with snapshot-wrapped element type) and updating tuple-like pattern validation logic accordingly.

Lowering is not implemented yet: when matching on a struct type, lowering now detects FixedSizeArray patterns (Span destructures) and emits an UnsupportedMatchedType match diagnostic instead of attempting struct deconstruction. Diagnostics and test expectations were updated (notably E2106) and new tests cover valid Span destructuring plus common error cases (non-Span structs, Array<T> vs Span<T>, and trait inference failures).

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

@reviewable-StarkWare
Copy link
Copy Markdown

This change is Reviewable

@ilyalesokhin-starkware
Copy link
Copy Markdown
Contributor Author

crates/cairo-lang-semantic/src/expr/test_data/let_statement line 156 at r1 (raw file):

                    ^^^^^^^^^

error[E2106]: Unexpected type for fixed size array pattern. "(<missing>, <missing>, <missing>)" is not a fixed size array or a span.

The error go a bit wierd, what do you think about doing something like:
#9825

Code quote:

error[E2106]: Unexpected type for fixed size array pattern. "(<missing>, <missing>, <missing>)" is not a fixed size array or a span.

Copy link
Copy Markdown

@cursor cursor Bot left a comment

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 219b96d. Configure here.

Comment thread crates/cairo-lang-semantic/src/expr/compute.rs
@ilyalesokhin-starkware ilyalesokhin-starkware force-pushed the ilya/span_pattern_semantic branch from 219b96d to 8741730 Compare April 9, 2026 08:38
Copy link
Copy Markdown
Contributor Author

ilyalesokhin-starkware commented Apr 9, 2026

Copy link
Copy Markdown
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@orizi reviewed 5 files and all commit messages, and made 1 comment.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on eytan-starkware and ilyalesokhin-starkware).


crates/cairo-lang-semantic/src/expr/test_data/let_statement line 156 at r1 (raw file):

Previously, ilyalesokhin-starkware wrote…

The error go a bit wierd, what do you think about doing something like:
#9825

lgtmed it.

Copy link
Copy Markdown
Contributor Author

@ilyalesokhin-starkware ilyalesokhin-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ilyalesokhin-starkware resolved 2 discussions.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on eytan-starkware).

@ilyalesokhin-starkware ilyalesokhin-starkware removed the request for review from eytan-starkware April 9, 2026 13:03
Teach the semantic layer to accept `[a, b, c]` patterns when matching
on `Span<T>`, converting the pattern type to `@[T; N]`. The lowering
layer reports an unsupported-type diagnostic for now; full lowering
support will follow in a subsequent PR.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@ilyalesokhin-starkware ilyalesokhin-starkware force-pushed the ilya/span_pattern_semantic branch from 8741730 to 0e8eb8f Compare April 9, 2026 13:19
Copy link
Copy Markdown
Contributor Author

@ilyalesokhin-starkware ilyalesokhin-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ilyalesokhin-starkware made 1 comment.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on ilyalesokhin-starkware).

Comment thread crates/cairo-lang-semantic/src/expr/compute.rs
Copy link
Copy Markdown
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@orizi reviewed 2 files and all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on ilyalesokhin-starkware).

Copy link
Copy Markdown
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

@orizi made 1 comment.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on ilyalesokhin-starkware).

@ilyalesokhin-starkware ilyalesokhin-starkware added this pull request to the merge queue Apr 12, 2026
Merged via the queue into main with commit dad17c0 Apr 12, 2026
54 checks passed
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