-
Notifications
You must be signed in to change notification settings - Fork 596
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support match on felt252 #4284
support match on felt252 #4284
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 0 of 7 files reviewed, 3 unresolved discussions (waiting on @orizi and @TomerStarkware)
-- commits
line 7 at r1:
Squash as disscussed.
Code quote:
- 4b715d6: support match on felt252
- 282637c: mend
- 656bd54: mend
crates/cairo-lang-lowering/src/test_data/match
line 24 at r1 (raw file):
//! > lowering_diagnostics error: Unsupported match arm - variants must be the same order as enum declaration.
That's not an enum match, change the diagnostic.
crates/cairo-lang-lowering/src/test_data/match
line 287 at r1 (raw file):
//! > lowering_diagnostics error: Match is Non Exhaustive - ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern
If possible, add an error specific for the match of felt252
, the "pattern" is more about enums.
a8f3707
to
0030670
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 0 of 8 files reviewed, 2 unresolved discussions (waiting on @gilbens-starkware and @orizi)
Previously, gilbens-starkware (Gil Ben-Shachar) wrote…
Squash as disscussed.
Done.
crates/cairo-lang-lowering/src/test_data/match
line 24 at r1 (raw file):
Previously, gilbens-starkware (Gil Ben-Shachar) wrote…
That's not an enum match, change the diagnostic.
Done.
crates/cairo-lang-lowering/src/test_data/match
line 287 at r1 (raw file):
Previously, gilbens-starkware (Gil Ben-Shachar) wrote…
If possible, add an error specific for the match of
felt252
, the "pattern" is more about enums.
Done
825ee22
to
61de349
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 2 of 7 files at r1, 1 of 4 files at r2, 2 of 3 files at r4, 1 of 1 files at r6.
Reviewable status: 6 of 9 files reviewed, 3 unresolved discussions (waiting on @gilbens-starkware and @TomerStarkware)
examples/fib_match.cairo
line 10 at r6 (raw file):
4 => 5, _ => { fib(n - 1) + fib(n - 2) } }
consider (just to make getting the extra values make algorithmic sense)
Suggestion:
match n {
0 => 1,
1 => 1,
2 => 2,
3 => 3,
4 => 5,
_ => { 5 * fib(n - 4) + 3 * fib(n - 5) }
}
61de349
to
f720efa
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 4 files at r2, 1 of 1 files at r5.
Reviewable status: 5 of 9 files reviewed, 7 unresolved discussions (waiting on @gilbens-starkware and @TomerStarkware)
crates/cairo-lang-lowering/src/test_data/match
line 17 at r6 (raw file):
//! > function_name foo1
Suggestion:
//! > function
fn foo(a: felt252) -> felt252 {
let b=match a {
5=> {550},
6 => {70},
_=>{90}
};
return b;
}
//! > function_name
foo
crates/cairo-lang-lowering/src/test_data/match
line 256 at r6 (raw file):
//! > lowering_diagnostics error: Unsupported match arm - numbers must be sequential starting from 0 --> lib.cairo:4:7
Suggestion:
error: Unsupported match arm - numbers must be sequential starting from 0.
--> lib.cairo:4:7
crates/cairo-lang-lowering/src/test_data/match
line 287 at r6 (raw file):
//! > lowering_diagnostics error: Match is Non Exhaustive - ensure that all possible cases are being handled by adding a match arm with a wildcard pattern
Suggestion:
Match is non exhaustive - ensure that all possible cases are being handled by adding a match arm with a wildcard pattern.
crates/cairo-lang-sierra-generator/src/block_generator_test_data/match
line 54 at r7 (raw file):
Match(match core::felt252_is_zero(v0) { IsZeroResult::Zero => blk1, IsZeroResult::NonZero(v3) => blk2,
can you prevent the ids here from changing?
(or explain well enough why they should change)
Code quote:
(v3)
f720efa
to
bec6641
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 3 of 3 files at r7.
Reviewable status: 7 of 9 files reviewed, 6 unresolved discussions (waiting on @gilbens-starkware and @TomerStarkware)
23cdeb4
to
79f0d10
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 4 of 9 files reviewed, 6 unresolved discussions (waiting on @gilbens-starkware and @orizi)
crates/cairo-lang-lowering/src/test_data/match
line 17 at r6 (raw file):
//! > function_name foo1
Done.
crates/cairo-lang-lowering/src/test_data/match
line 256 at r6 (raw file):
//! > lowering_diagnostics error: Unsupported match arm - numbers must be sequential starting from 0 --> lib.cairo:4:7
Done.
crates/cairo-lang-lowering/src/test_data/match
line 287 at r6 (raw file):
//! > lowering_diagnostics error: Match is Non Exhaustive - ensure that all possible cases are being handled by adding a match arm with a wildcard pattern
Done.
examples/fib_match.cairo
line 10 at r6 (raw file):
Previously, orizi wrote…
consider (just to make getting the extra values make algorithmic sense)
Done
crates/cairo-lang-sierra-generator/src/block_generator_test_data/match
line 54 at r7 (raw file):
Previously, orizi wrote…
can you prevent the ids here from changing?
(or explain well enough why they should change)
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 1 files at r8, 1 of 2 files at r9, 2 of 3 files at r10.
Reviewable status: 8 of 9 files reviewed, 4 unresolved discussions (waiting on @gilbens-starkware and @TomerStarkware)
crates/cairo-lang-lowering/src/lower/mod.rs
line 1169 at r10 (raw file):
} fn lower_felt252_arm_block(
Doc
crates/cairo-lang-lowering/src/lower/mod.rs
line 1184 at r10 (raw file):
} fn lower_expr_felt252_arm(
Doc
79f0d10
to
8750768
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 8 of 9 files reviewed, 4 unresolved discussions (waiting on @gilbens-starkware and @orizi)
crates/cairo-lang-lowering/src/lower/mod.rs
line 1169 at r10 (raw file):
Previously, orizi wrote…
Doc
Done.
crates/cairo-lang-lowering/src/lower/mod.rs
line 1184 at r10 (raw file):
Previously, orizi wrote…
Doc
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed all commit messages.
Reviewable status: 8 of 9 files reviewed, 2 unresolved discussions (waiting on @gilbens-starkware)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 7 files at r1, 1 of 3 files at r4, 2 of 3 files at r7, 1 of 1 files at r8, 1 of 2 files at r9, 2 of 3 files at r10, 1 of 1 files at r11, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @TomerStarkware)
crates/cairo-lang-lowering/src/diagnostic.rs
line 82 at r11 (raw file):
"Unsupported match arm - numbers must be sequential starting from 0.".into(), LoweringDiagnosticKind::NonExhaustiveMatch => { "Match is non exhaustive - ensure that all possible cases are being handled by adding a match arm with a wildcard pattern."
I think it should be clearer that numerical match must have a wildcard pattern (or ~2^251
arms).
Suggestion:
"Match is non exhaustive - match over a numerical value must have a wildcard card pattern (`_`).
crates/cairo-lang-lowering/src/diagnostic.rs
line 98 at r11 (raw file):
} LoweringDiagnosticKind::LiteralError(literal_error) => literal_error.format(db),
remove.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @TomerStarkware)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @TomerStarkware)
8750768
to
1d45555
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 1 files at r12, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @TomerStarkware)
71e191d
to
42182f8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 8 of 9 files reviewed, 3 unresolved discussions (waiting on @gilbens-starkware and @TomerStarkware)
crates/cairo-lang-lowering/src/diagnostic.rs
line 80 at r13 (raw file):
LoweringDiagnosticKind::UnsupportedMatchArmNonSequential=> "Unsupported match arm - numbers must be sequential starting from 0.".into(), LoweringDiagnosticKind::NonExhaustiveMatch => {
If the diag now only makes sense for match on numeric values, rename err variant as well.
Code quote:
NonExhaustiveMatch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 1 files at r13, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @TomerStarkware)
42182f8
to
e19776c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 2 of 2 files at r14, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @TomerStarkware)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @orizi)
crates/cairo-lang-lowering/src/diagnostic.rs
line 80 at r13 (raw file):
Previously, orizi wrote…
If the diag now only makes sense for match on numeric values, rename err variant as well.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed all commit messages.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on @TomerStarkware)
This change is