-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Allow exception-patterns under or-patterns #1568
Conversation
349efb6
to
a9f0cdf
Compare
bytecomp/matching.ml
Outdated
@@ -2824,6 +2825,7 @@ let find_in_pat pred = | |||
find_rec p || find_rec q | |||
| Tpat_constant _ | Tpat_var _ | |||
| Tpat_any | Tpat_variant (_,None,_) -> false | |||
| Tpat_exception _ -> assert false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there an indentation issue or did it mean something else ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like indentation/copy-paste failure on my part; it's now fixed.
Thanks!
a9f0cdf
to
aa3dc64
Compare
Generated with ocaml/ocaml#1568 $ cat test3.ml exception A of int let y = match Random.int 2 with | 0 as i | exception A (2 as i) -> i | i -> i+1 | exception A i -> i+2 $ cat test4.ml exception A of int let y = match Random.int 2 with | 0 as i | exception A (2 as i) -> i | i -> i+1 jbuilder build compiler/js_of_ocaml.bc && _build/default/compiler/js_of_ocaml.bc --debug main test3.cmo assert false jbuilder build compiler/js_of_ocaml.bc && _build/default/compiler/js_of_ocaml.bc --debug main test4.cmo stackoverflow
aa3dc64
to
2195817
Compare
41e078a
to
a1992b3
Compare
757ca8d
to
2834938
Compare
I rebased this once more! I also pinged @gasche by email to get some review, who (for obscure reasons) said it wasn't reasonable (sic) for him to review this.
|
Yes -- it looks to me as though |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excuse the nit, which is #1148-related
flags = "-g" | ||
ocamlrunparam += ",b=1" | ||
* bytecode | ||
reference = "${test_source_directory}/backtrace_or_exception.byte.reference" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is over 80 chars!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not anymore! :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thank you - now that the an off-by-one error in the Travis CI script is fixed, it'll even get scanned next time 🙂
@yallop: thanks! I pushed a commit doing the simplification. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've reviewed the type-checking stuff and it looks fine. Since the other parts have already been reviewed, I think this is ready to merge.
Thanks for the review! I'll rebase and merge this on Monday, unless someone objects. |
7d5455c
to
593e0e1
Compare
Revival of #305 .
A few things of note compared to the previous version:
Parmatch
andMatching
alwaysassert false
when they see aTpat_exception
Parmatch.pressure_variants
is called on the value and exception patterns independently.This wasn't done in the previous version and was the cause of PR#7083.
Parmatch.check_ambiguous_bindings
is called independently on the value and exception patterns. As for the other operations in parmatch, it wouldn't make sense to mix both kind of patterns in a single matrix.Rec_check
I believe I handle cases containing only exception-patterns in exactly the same way as before. However, I wonder if perhaps this special casing could not simply be dropped (considering thatTpat_exception
is not a destructuring pattern). I didn't try to understand how the check works though (nor do I plan to right now) so I'm going to leave things as is unless @yallop says it can be simplified.Translcore
I make sure to remember (i.e. save intry_ids
) all the names given to the exception of an exception pattern so that reraise works properly. I also added a test to make sure reraise works as intended when raising from a branch when we either match or catch an exception.Apart from that everything should be as in #305, in particular : mixing value and exception patterns under a guard is still disallowed.
Off-topic:
Parmatch.check_ambiguous_bindings
is delayed when the matching contains polymorphic variants (and I didn't change it here) but I don't think that is necessary.This PR is based on top of Register all idents relevant for reraise. #1567 , so the first 3 commits can be disregarded.