Skip to content

pattern-matching refactoring: refactor the make_<foo>_matching functions#9520

Merged
gasche merged 1 commit intoocaml:trunkfrom
trefis:rematch-make_matching-cleanup
May 14, 2020
Merged

pattern-matching refactoring: refactor the make_<foo>_matching functions#9520
gasche merged 1 commit intoocaml:trunkfrom
trefis:rematch-make_matching-cleanup

Conversation

@gasche
Copy link
Copy Markdown
Member

@gasche gasche commented May 2, 2020

This is the next bit of the big pattern-matching refactoring change (#9321) after #9493 has been merged.

(cc @trefis @Octachron)

Before, each head construction had a make_<foo>_matching construct that
was responsible for three things:

  • consuming the argument from the argument list
    (the "argument" is a piece of lambda code to access
    the value of the current scrutinee)
  • building arguments for the subpatterns of the scrutinee
    and pushing them to the argument list
  • building a cell structure out of this, representing a head group
    during compilation

Only the second point is really specific to each construction.

This refactoring turns this second point into a construct-specific
get_expr_args_<foo> function (similarly to get_pat_args_<foo>),
and moves the first and third point to a generic make_matching
function.

Note: this PR contains a minor improvement to the location used to
force (lazy ..) arguments, and also removes the redundant expansion
that was discussed in the last PR. (The latter is a separate commit
to ease separate reviewing.)

@gasche gasche force-pushed the rematch-make_matching-cleanup branch from 2a921ef to 35a3637 Compare May 2, 2020 09:48
let def = Default_environment.specialize head def
and ctx = Context.specialize head ctx in
{ pm = { cases = []; args = argl; default = def }; ctx; discr = head }
let get_expr_args_variant_constant = get_expr_args_constant
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is the only case where a get_expr_args function is reused. Is there any specific reason?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

After discussing more with @Octachron, I will systematically define all constant get_{pat,expr}_args definitions as equal to the _constant one.

@gasche gasche force-pushed the rematch-make_matching-cleanup branch 2 times, most recently from 7c4449f to e58afea Compare May 13, 2020 12:09
@gasche
Copy link
Copy Markdown
Member Author

gasche commented May 13, 2020

@Octachron I rebased the PR.

(On my local machine there is a mysterious failure with a typing-poly-bugs test I don't understand, but I'm going to assume for now that it is an inconsistent-state issue, we should see what the CI says.)

@gasche gasche force-pushed the rematch-make_matching-cleanup branch from e58afea to 2a3a3a7 Compare May 13, 2020 12:30
| _ -> fatal_error "Matching.get_expr_args_constr"
in
let loc = head_loc ~scopes head in
let make_field_accesses binding_kind first_pos last_pos argl =
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Small remark: the function is only called with Alias as a binding_kind.

Copy link
Copy Markdown
Member

@Octachron Octachron left a comment

Choose a reason for hiding this comment

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

This PR extracts the part of make_matching specific to each pattern head and refactorizes the common code. It seems good to merge once the rest of the CI return green.

Before, each head construction had a `make_<foo>_matching` construct that
was responsible for three things:
- consuming the argument from the argument list
  (the "argument" is a piece of lambda code to access
   the value of the current scrutinee)
- building arguments for the subpatterns of the scrutinee
  and pushing them to the argument list
- building a `cell` structure out of this, representing a head group
  during compilation

Only the second point is really specific to each construction.

This refactoring turns this second point into a construct-specific
`get_expr_args_<foo>` function (similarly to `get_pat_args_<foo>`),
and moves the first and third point to a generic `make_matching`
function.

Note: this commit contains a minor improvement to the location used to
force (lazy ..) arguments.
@gasche gasche force-pushed the rematch-make_matching-cleanup branch from 2a3a3a7 to 0651396 Compare May 13, 2020 15:18
@gasche gasche merged commit b343475 into ocaml:trunk May 14, 2020
@gasche
Copy link
Copy Markdown
Member Author

gasche commented May 14, 2020

Merged. Many thanks again (as usual, but still worth saying) for the fine review work. I will prepare the next PR in the stack.

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