-
-
Notifications
You must be signed in to change notification settings - Fork 59
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
Extend marking to local open patterns #113
Conversation
@@ -208,6 +208,9 @@ let translate_pattern = | |||
it makes no sense to match a second time for effects such as | |||
exceptions. *) | |||
| Ppat_exception _ -> [] | |||
| Ppat_open (c, p') -> | |||
translate mark p' | |||
|> List.map (fun (marks, p'') -> marks, Pat.open_ ~loc ~attrs c p'') |
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.
The code change LGTM, but I would suggest that it be moved above the Ppat_exception
case. Otherwise, it looks like the comment above applies to Ppat_open
as well.
@aantron Apologies for the delay, I was on vacation. Updated the code per your requests and added tests. A couple of nits:
|
No problem, hope it was a nice vacation :) Concerning 1 and 2, we currently don't call the pattern rewriter on patterns of Separately, we should probably consider calling the rewriter on Re. 3, I tried introducing an error, and yes it's confusing. I don't remember the output being this bad before. Perhaps open an issue for making it better? This change breaks compilation for OCaml < 4.04, so perhaps we need to rewrite the pattern matching in |
Now I understand. I couldn't help myself in extending the test case. You make good points about the I'm not certain how to handle the |
Would pinning cc @alainfrisch |
Thinking through the problem a bit more ... how would using I'm probably missing something. |
You're right, I misunderstood some |
probably, but we'd have to mirror every pattern structure anyway, so why not use the
Sure. Is there something I can add to this PR ? |
If we don't use the AST directly here, it is
I think it's probably best to open an issue on |
Fine with me, this is your wheelhouse. |
This will take a while to resolve on the I suppose you could adapt/inline the proposal in ocaml-ppx/ppx_tools@1a192b0 and ocaml-ppx/ppx_tools@367ca8b, or solve it any other way (e.g. temporarily depending on I added testing on |
@aantron Sorry for the delay on this one. I ended up using |
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.
Besides inline comments,
- Squashing.. :)
- I think we should edit the
opam
files of existing releases and add a constraint for compiler< "4.04"
. Care to do the honors? :)
@@ -127,3 +127,4 @@ let f x = | |||
let f x = | |||
match x with | |||
| `Foo x | `Bar x -> x | |||
|
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.
Nit: is this adding a stray extra line?
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.
eagle eyes
end | ||
|
||
let f () = | ||
let M.(s) = M.(Foo) in assert (s = M.Foo); |
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 believe the only fully useful tests right now would be match
expressions, where at least one of the cases has an or-pattern, i.e. M.(Foo | Bar)
, M.{i = 3 | 4; _}
, etc.:
- We aren't running the pattern rewriter on
let
expressions at all (Rewrite or patterns in let expressions #115). - If the rewriter generates only one case (because there are no or-patterns), we throw the case away and don't generate a nested
match
expression (bisect_ppx/src/syntax/instrumentPpx.ml
Line 255 in d587132
| [marks, _] ->
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.
True.
I'll add
let s = M.Bar in
match s with
| M.(Foo | Bar) -> assert true
| _ -> assert false
Do you want me to get rid off all the other stuff? Though we don't rewrite the pattern I can make a hand-wavy argument that it is nice to have since one could still write that type of code.
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'd definitely convert all the syntax variants (M.{}
, M.[]
, M.[||]
) to match
, so that we are actually testing those, and insert an or-pattern in more of them. I'd personally delay adding let
cases until #155... but they don't really hurt, besides making the future diff for #155 slightly less clear. But nobody is going to read that diff anyway after it's in master
, so up to you :)
@@ -58,6 +58,24 @@ let _run_int command = | |||
| Unix.WEXITED v -> v | |||
| _ -> _command_failed command | |||
|
|||
let _read_lines_from ~max_lines command = |
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 think it's possible to use Sys.ocaml_version
for this.
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.
Learn something new everyday. I can't remember the reason why I've had to parse that output before.
open Test_helpers | ||
|
||
let tests = | ||
compile_compare (fun () -> with_bisect () ^ " -w +A-32-4") "404_or_greater" |
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.
Nit: I think we should name the directory and test set as "test_ppat_open
" or "test_open_in_patterns
", or something like that.
- From the
4.04
feature list, it seems like the only new thing to deal with. - If something else gets added in
4.05
or later, it won't go into404_or_greater
.
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'll squash past last comment about which tests to keep. |
Nope, pretty much just write changelog and tag (I wrote Since this release would include some slightly messy feature removals by me, would you like to split it up this way: I'll take care of the release notes/tag, and you can do the PR to OPAM, with both the new release and the updates to older On a tangent, what do you think about stopping to update the |
We use CPPO to support multiple OCaml versions. A special case, version dependent is added in the ppat_open directory.
Squashed.
Sure, I'll look out for the tag.
I'm not too wedded to the file. But there is something nice to having the actual log be part of the source as opposed to being a |
Thanks. Tag is pushed. And reasonable – let's keep |
This PR is a WIP to allow bisect_ppx to work on 4.04. The testing for the new local open module feature (ocaml/ocaml#578) isn't complete and unfortunately stalled because of this bug in the
-dsource
output.Trying to fix issue #112