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

pattern-matching compiler: refactor the toplevel handling of partiality #9651

Merged
merged 3 commits into from Nov 21, 2020

Conversation

gasche
Copy link
Member

@gasche gasche commented Jun 7, 2020

This PR is built on top of #9647, it shares the toplevel logic to call pattern-matching compilation functions.

(The PR contains a change to the handling of the Unused exception by for_tupled_function. I believe the change is correct, and I checked with @maranget who agrees in principle but isn't sure about the details.)

(cc @maranget @trefis @Octachron)

@gasche
Copy link
Member Author

gasche commented Jul 7, 2020

This pattern-matching refactoring PR is still open. Anyone is free to help reviewing it!

@gasche
Copy link
Member Author

gasche commented Oct 20, 2020

(recently I wondered about which of the pattern-matching PR are still in-flight; this one is)

with Unused -> assert false

(* ; partial_function loc () *)
List.fold_right2 (bind Strict) idl paraml lam, total
Copy link
Member

Choose a reason for hiding this comment

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

This moves the bindings below the handler for the match failure. However, making variables more local seems good.

handler (fun partial pm ->
compile_match ~scopes None partial
(Context.start (List.length paraml)) pm
)
Copy link
Member

Choose a reason for hiding this comment

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

Beyond the removal of the Unused handler that indeed seemed erroneous, this also optimizes the Total case by avoiding creating a default environment and checking if we need to install a match failure handler.

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

The factorization of toplevel handlers seems a worthwhile simplification.

Indeed, both do_for_multiple_match and compile_match re-implemented independently an equivalent Partial and Total branch.

The fact that the remaining handler, for_tupled_function only implemented the Partial branch is another point in favor of the PR.

Concerning the Unused exception, the new assert false seems as correct as the preexisting one in the non-optimized compilation path: if it is possible to reach this assert false, with for_tupled_function, the same pattern match compiled with for_function should also reach it.

@gasche
Copy link
Member Author

gasche commented Nov 18, 2020

I just rebased the PR against trunk. The rebase was non-obvious due to the interaction with the Cannot_flatten change in do_for_multiple_match (#9650), but the diff is essentially unchanged.

Changes Outdated Show resolved Hide resolved
This comes from a suggestion by Florian Angeletti in
  ocaml#9447 (comment)
This appears to change the function behavior with respect to the
Unused exception, but we believe that the change is correct. It makes
the code more consistent with other toplevel compilation functions.
@gasche gasche merged commit 1abdcac into ocaml:trunk Nov 21, 2020
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.

None yet

2 participants