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 for otherwise pattern in match for enums #4557

Merged
merged 1 commit into from
Dec 17, 2023

Conversation

TomerStarkware
Copy link
Collaborator

@TomerStarkware TomerStarkware commented Dec 13, 2023

This change is Reviewable

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 3 files at r1, all commit messages.
Reviewable status: 1 of 3 files reviewed, 1 unresolved discussion (waiting on @gilbens-starkware and @TomerStarkware)


crates/cairo-lang-lowering/src/test_data/match line 761 at r1 (raw file):


//! > lowering_diagnostics
error: Enum variant `VariantId(test::Three)` not covered.

improve message

Code quote:

`VariantId(test::Three)`

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: 1 of 3 files reviewed, 1 unresolved discussion (waiting on @gilbens-starkware and @orizi)


crates/cairo-lang-lowering/src/test_data/match line 761 at r1 (raw file):

Previously, orizi wrote…

improve message

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 2 files at r2, all commit messages.
Reviewable status: 2 of 3 files reviewed, 2 unresolved discussions (waiting on @gilbens-starkware and @TomerStarkware)


crates/cairo-lang-lowering/src/lower/mod.rs line 1121 at r2 (raw file):

            let block_id = subscope.block_id;

            let arm_index = variant_map

report all missing variants.


crates/cairo-lang-lowering/src/lower/mod.rs line 1255 at r2 (raw file):

                Pattern::EnumVariant(PatternEnumVariant { inner_pattern: None, .. })
                | Pattern::Otherwise(_) => Ok(()),
                _ => unreachable!(),

explain why in the macro string.

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: 1 of 3 files reviewed, 2 unresolved discussions (waiting on @gilbens-starkware and @orizi)


crates/cairo-lang-lowering/src/lower/mod.rs line 1121 at r2 (raw file):

Previously, orizi wrote…

report all missing variants.

Done.


crates/cairo-lang-lowering/src/lower/mod.rs line 1255 at r2 (raw file):

Previously, orizi wrote…

explain why in the macro string.

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 2 files at r3, all commit messages.
Reviewable status: 2 of 3 files reviewed, 1 unresolved discussion (waiting on @gilbens-starkware and @TomerStarkware)


crates/cairo-lang-lowering/src/lower/mod.rs line 1052 at r3 (raw file):

) -> LoweringResult<UnorderedHashMap<semantic::ConcreteVariant, usize>> {
    let mut map: UnorderedHashMap<_, _> = UnorderedHashMap::default();
    for (arm_index, arm) in arms.enumerate() {

Suggestion:

/// Returns a map from variants to their corresponding arm index.
fn get_variant_to_arm_map<'a>(
    ctx: &mut LoweringContext<'_, '_>,
    arms: impl Iterator<Item = &'a semantic::MatchArm>,
    concrete_enum_id: semantic::ConcreteEnumId,
) -> LoweringResult<UnorderedHashMap<semantic::ConcreteVariant, usize>> {
    let mut map: UnorderedHashMap<_, _> = UnorderedHashMap::default();
    for (arm_index, arm) in arms.enumerate() {

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 2 files at r4, all commit messages.
Reviewable status: 2 of 3 files reviewed, 4 unresolved discussions (waiting on @gilbens-starkware and @TomerStarkware)


crates/cairo-lang-lowering/src/lower/mod.rs line 1051 at r4 (raw file):

    concrete_enum_id: semantic::ConcreteEnumId,
) -> LoweringResult<UnorderedHashMap<semantic::ConcreteVariant, usize>> {
    let mut map: UnorderedHashMap<_, _> = UnorderedHashMap::default();

Suggestion:

    let mut map = UnorderedHashMap::default();

crates/cairo-lang-lowering/src/lower/mod.rs line 1109 at r4 (raw file):

    let otherwise_variant = get_underscore_pattern_index(ctx, &expr.arms);
    let variant_map: UnorderedHashMap<_, _> = get_variant_to_arm_map(
        ctx,

Suggestion:

    let variant_map = get_variant_to_arm_map(
        ctx,

crates/cairo-lang-lowering/src/test_data/match line 781 at r4 (raw file):

//! > ==========================================================================

//! > Test match on enum tuples.

is this related to this pr?


crates/cairo-lang-lowering/src/test_data/match line 788 at r4 (raw file):

//! > function
fn foo(a: A,b: A) -> felt252 {
  match (a,b) {

format code

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:

Reviewed 2 of 2 files at r5, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @gilbens-starkware)

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: :shipit: complete! all files reviewed, all discussions resolved (waiting on @gilbens-starkware)


crates/cairo-lang-lowering/src/lower/mod.rs line 1051 at r4 (raw file):

    concrete_enum_id: semantic::ConcreteEnumId,
) -> LoweringResult<UnorderedHashMap<semantic::ConcreteVariant, usize>> {
    let mut map: UnorderedHashMap<_, _> = UnorderedHashMap::default();

Done.


crates/cairo-lang-lowering/src/lower/mod.rs line 1109 at r4 (raw file):

    let otherwise_variant = get_underscore_pattern_index(ctx, &expr.arms);
    let variant_map: UnorderedHashMap<_, _> = get_variant_to_arm_map(
        ctx,

Done.


crates/cairo-lang-lowering/src/test_data/match line 781 at r4 (raw file):

Previously, orizi wrote…

is this related to this pr?

no,removed


crates/cairo-lang-lowering/src/test_data/match line 788 at r4 (raw file):

Previously, orizi wrote…

format code

removed

@TomerStarkware TomerStarkware added this pull request to the merge queue Dec 17, 2023
Merged via the queue into main with commit 2eb9a2d Dec 17, 2023
@orizi orizi deleted the tomer/match_otherwise branch December 18, 2023 07:16
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.

2 participants