Skip to content

matching: refactor compile_match* to clarify argument binding#13074

Merged
gasche merged 1 commit intoocaml:trunkfrom
gasche:matching-refactor-combine_handlers
Apr 5, 2024
Merged

matching: refactor compile_match* to clarify argument binding#13074
gasche merged 1 commit intoocaml:trunkfrom
gasche:matching-refactor-combine_handlers

Conversation

@gasche
Copy link
Member

@gasche gasche commented Apr 5, 2024

Currently the code of compile_match_nonempty is a bit strange, because it replaces an arbitrary expression arg by a variable in the argument list of the pattern-matching matrix, but it is not clear which of the two versions will be used to generate code by the sub-functions it calls.

This commit is a minor refactoring to move the variable binding close to the place where the expression argument is turned into a variable argument.

The current oddity came up indirectly in the review of #12555 by @ncik-roberts, and I think that this refactoring would have made the code easier to think about and discuss. I am proposing the refactoring to cleanup this aspect now. It should be "obviously" correct in the sense that it exactly preserves the previous behavior, with just some restructuring of the split into functions.

Currently the code of compile_match_nonempty is a bit strange,
because it replaces an arbitrary expression `arg` by a variable in the
argument list of the pattern-matching matrix, but it is not clear
which of the two versions will be used to generate code by the
sub-functions it calls.

This commit is a minor refactoring to move the variable binding close
to the place where the expression argument is turned into a variable argument.
Copy link
Contributor

@trefis trefis left a comment

Choose a reason for hiding this comment

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

LGTM.

@gasche
Copy link
Member Author

gasche commented Apr 5, 2024

Woah! Thanks.

@gasche gasche added the merge-me label Apr 5, 2024
@gasche gasche merged commit 1a79864 into ocaml:trunk Apr 5, 2024
ncik-roberts added a commit to oxcaml/oxcaml that referenced this pull request Jun 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants