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 refactoring: first-order representation for failure handlers #9647

Merged
merged 2 commits into from
Jul 9, 2020

Conversation

gasche
Copy link
Member

@gasche gasche commented Jun 6, 2020

This PR was not initially planned in #9321, but once you get started...

(cc @trefis @Octachron)

compile_matching uses higher-order functions to decide what code to generate for match failure. The present PR uses a proper datastructure to represent the possible cases, which simplifies the code slightly.

The PR also contains a related improvement to the location used in Matching.for_trywith.

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.

One minor nitpick.

lambda/matching.ml Outdated Show resolved Hide resolved
@gasche
Copy link
Member Author

gasche commented Jun 7, 2020

The CI shows test failures that reveal that improving the location of for_trywith is not a good idea, as it adds noise in the backtraces coming from the reraise actions implicit in partial try..with clauses. (If none of the clause catches an exception, a reraise occurs, but we don't want to see it in the trace.)

I will have to go back to a dummy location there, with an explanation for why this is actually intentional. (I may still ask for a location in the interface, in case this evolves to be useful for other things later.) Ideally we would have a primitive that takes a proper location (for various debugging purposes) but doesn't add it to the backtrace, but this does not seem to exist now.

@gasche gasche force-pushed the rematch-matching-handler-fun branch from 6da72d9 to 878e73f Compare June 8, 2020 07:48
@gasche
Copy link
Member Author

gasche commented Jun 8, 2020

I updated the PR to not use the refined location in reraise failure-handlers, and document why we do this.

@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!

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.

Rereading this PR, the change is both correct and mundane. However, the code ends up being slightly more self-documenting. Conclusion, the PR seems fine to me.

@gasche gasche force-pushed the rematch-matching-handler-fun branch from 878e73f to 954f33b Compare July 8, 2020 20:34
@gasche
Copy link
Member Author

gasche commented Jul 8, 2020

Thanks! This PR is a useful step towards #9651, which would itself have helped my recent work on Cannot_flatten as it simplifies do_for_multiple_match. I just rebased and will merge when the CI agrees.

Actually *using* the location in the failure handler would be
incorrect, as it adds noise to backtraces involving partial exception
handlers. This is now properly documented.

We still take the caller location (which is currently ignored) for
consistency with other toplevel Matching functions, and because that
may become useful if we want to add more error-reporting or warnings
in compile_matching.
@gasche gasche force-pushed the rematch-matching-handler-fun branch from 954f33b to fdf86ad Compare July 8, 2020 20:39
@gasche gasche merged commit 5940632 into ocaml:trunk Jul 9, 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

3 participants