Skip to content
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

Merged
merged 1 commit into from
Oct 31, 2023
Merged

Conversation

TomerStarkware
Copy link
Collaborator

@TomerStarkware TomerStarkware commented Oct 19, 2023

This change is Reviewable

Copy link
Contributor

@gilbens-starkware gilbens-starkware left a 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.

@TomerStarkware TomerStarkware force-pushed the tomer/sequential_number_match branch from a8f3707 to 0030670 Compare October 19, 2023 13:47
Copy link
Collaborator Author

@TomerStarkware TomerStarkware left a 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)


-- commits line 7 at r1:

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

@TomerStarkware TomerStarkware force-pushed the tomer/sequential_number_match branch 4 times, most recently from 825ee22 to 61de349 Compare October 19, 2023 15:52
Copy link
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.

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) }
    }

@TomerStarkware TomerStarkware force-pushed the tomer/sequential_number_match branch from 61de349 to f720efa Compare October 22, 2023 07:58
Copy link
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.

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)

@TomerStarkware TomerStarkware force-pushed the tomer/sequential_number_match branch from f720efa to bec6641 Compare October 22, 2023 08:06
Copy link
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.

Reviewed 3 of 3 files at r7.
Reviewable status: 7 of 9 files reviewed, 6 unresolved discussions (waiting on @gilbens-starkware and @TomerStarkware)

@TomerStarkware TomerStarkware force-pushed the tomer/sequential_number_match branch 2 times, most recently from 23cdeb4 to 79f0d10 Compare October 22, 2023 09:22
Copy link
Collaborator Author

@TomerStarkware TomerStarkware left a 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

Copy link
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.

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

@TomerStarkware TomerStarkware force-pushed the tomer/sequential_number_match branch from 79f0d10 to 8750768 Compare October 23, 2023 00:14
Copy link
Collaborator Author

@TomerStarkware TomerStarkware left a 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.

Copy link
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.

Reviewed all commit messages.
Reviewable status: 8 of 9 files reviewed, 2 unresolved discussions (waiting on @gilbens-starkware)

Copy link
Contributor

@gilbens-starkware gilbens-starkware left a 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.

Copy link
Contributor

@gilbens-starkware gilbens-starkware left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @TomerStarkware)

Copy link
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:

Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @TomerStarkware)

@TomerStarkware TomerStarkware force-pushed the tomer/sequential_number_match branch from 8750768 to 1d45555 Compare October 29, 2023 08:56
Copy link
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.

Reviewed 1 of 1 files at r12, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @TomerStarkware)

@TomerStarkware TomerStarkware force-pushed the tomer/sequential_number_match branch 2 times, most recently from 71e191d to 42182f8 Compare October 29, 2023 09:39
Copy link
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.

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

Copy link
Contributor

@gilbens-starkware gilbens-starkware left a 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)

@TomerStarkware TomerStarkware force-pushed the tomer/sequential_number_match branch from 42182f8 to e19776c Compare October 30, 2023 04:49
Copy link
Contributor

@gilbens-starkware gilbens-starkware left a 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)

Copy link
Collaborator Author

@TomerStarkware TomerStarkware left a 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.

Copy link
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.

Reviewed all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @TomerStarkware)

@TomerStarkware TomerStarkware added this pull request to the merge queue Oct 31, 2023
Merged via the queue into main with commit 0c88267 Oct 31, 2023
@orizi orizi deleted the tomer/sequential_number_match branch November 6, 2023 07:01
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