Skip to content

refactor(lowering): extract rebuild_match_arm helper method#9709

Open
GarmashAlex wants to merge 2 commits intostarkware-libs:mainfrom
GarmashAlex:refactor/extract-rebuild-match-arm
Open

refactor(lowering): extract rebuild_match_arm helper method#9709
GarmashAlex wants to merge 2 commits intostarkware-libs:mainfrom
GarmashAlex:refactor/extract-rebuild-match-arm

Conversation

@GarmashAlex
Copy link
Contributor

Summary

Extract the common logic into a new rebuild_match_arm helper method to improve maintainability and reduce code duplication.


Type of change

  • Style, wording, formatting, or typo-only change

Why is this change needed?

The rebuild_end function contained identical MatchArm rebuilding logic duplicated across all three MatchInfo variants (Extern, Enum, Value).

@chatgpt-codex-connector
Copy link

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@reviewable-StarkWare
Copy link

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.

@orizi reviewed all commit messages and made 2 comments.
Reviewable status: 0 of 1 files reviewed, 2 unresolved discussions (waiting on GarmashAlex).


crates/cairo-lang-lowering/src/utils.rs line 116 at r1 (raw file):

    /// Rebuilds a match arm with renamed var and block ids.
    fn rebuild_match_arm(&mut self, arm: &MatchArm<'db>) -> MatchArm<'db> {

move helper to after usage function.


crates/cairo-lang-lowering/src/utils.rs line 141 at r1 (raw file):

                        function: stmt.function,
                        inputs: stmt.inputs.iter().map(|v| self.map_var_usage(*v)).collect(),
                        arms: stmt.arms.iter().map(|arm| self.rebuild_match_arm(arm)).collect(),

it seems the .iter().map(...).collect() should possibly be part of the helper function.

@GarmashAlex
Copy link
Contributor Author

@orizi reviewed all commit messages and made 2 comments.
Reviewable status: 0 of 1 files reviewed, 2 unresolved discussions (waiting on GarmashAlex).

crates/cairo-lang-lowering/src/utils.rs line 116 at r1 (raw file):

    /// Rebuilds a match arm with renamed var and block ids.
    fn rebuild_match_arm(&mut self, arm: &MatchArm<'db>) -> MatchArm<'db> {

move helper to after usage function.

crates/cairo-lang-lowering/src/utils.rs line 141 at r1 (raw file):

                        function: stmt.function,
                        inputs: stmt.inputs.iter().map(|v| self.map_var_usage(*v)).collect(),
                        arms: stmt.arms.iter().map(|arm| self.rebuild_match_arm(arm)).collect(),

it seems the .iter().map(...).collect() should possibly be part of the helper function.

That's 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.

@orizi made 1 comment and resolved 2 discussions.
Reviewable status: 0 of 1 files reviewed, 1 unresolved discussion (waiting on GarmashAlex).


crates/cairo-lang-lowering/src/utils.rs line 160 at r2 (raw file):

    /// Rebuilds a match arm with renamed var and block ids.
    fn rebuild_match_arm(&mut self, arm: &MatchArm<'db>) -> MatchArm<'db> {

useless function. inline it.

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