-
Notifications
You must be signed in to change notification settings - Fork 177
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
Support ;%lwt as sequence syntax -- backwards incompatible in some cases #307
Conversation
This has been nibbling at the back of my mind since support for |
Well, you could always do I see the implementation is trivially using the old implementation of I'll let @aantron decide how he likes it. :p |
Acknowledged. I won't have time to fully evaluate all the issues in this for something like weeks. Comments from others are welcome, however. A thing to consider besides the backwards incompatibility with Given that this is a breaking change, making it would require studying the source code of at least OPAM users ( |
The syntax is, admittedly, unpleasant looking. Lots of
(* Using >> *)
do_a_thing () >>
Logs_lwt.info (fun m -> m "Just did that thing") >>
more_code
(* Using let%lwt *)
let%lwt () = do_a_thing () in
let%lwt () = Logs_lwt.info (fun m -> m "Just did that thing") in
more_code
(* Using >>= *)
do_a_thing () >>= fun () ->
Logs_lwt.info (fun m -> m "Just did that thing") >>= fun () ->
more_code
(* Using ;%lwt *)
do_a_thing ();%lwt
Logs_lwt.info (fun m -> m "Just did that thing");%lwt
more_code |
@aantron If this is going to be accepted I'd like to see it happen for the 3.x release so it can be taken advantage of (and breakage will be exposed) more quickly. I may be able to help with the opam scan if you have a script ready to use. |
Here you go: https://raw.githubusercontent.com/ocsigen/lwt/master/src/util/fetch-dependees.py It'll fetch the source code of each depending package I'll take a closer look at the PPX in the coming days (tomorrow or day after). A bit burned out at the moment. Worst case, we delay 2.7.0 and 3.0.0 slightly, to make sure this gets a proper look and discussion. If we have to break things for this, we can probably give enough warning with an |
In the meantime, if anyone has an opinion on |
Oh, a PPX option can also soften the blow in case we screw some user over, that uses |
And here is a verbose and loud way to make this breaking change:
This is elaborate and perhaps annoying, but it gives people plenty of time to adapt and/or complain. Objections welcome. I haven't fully examined everything, so apologies if some of the above would be redundant. For fixing the build before 4.04, either omit the test, or I think it has to go into its own executable that will be built only if the OCaml version is high enough. In the former case, I'll do a final test manually and it will be sufficient :) |
@hcarty Ok, this is good with the above warnings and flags added (though should probably name the flags |
(Before making that, let's check it actually break anyone's code. I quite doubt it will) |
I doubt anyone deliberately wrote |
When I tried Reason's |
@hcarty That's normal. |
@Drup I think @hcarty means that using @hcarty also, with this change, if I am an Lwt user and my code is supposed to compile both on 4.04 and before 4.04, will it have different meanings if I do end up writing (edit: I think the answer is no, but want to be sure). |
@aantron Yes Currently That might have not been such a good idea after all.... The rational is in the ppx's documentation. |
@Drup - @aantron's response is correct - I was referring to the greater chance of accidental code breakage via
@aantron |
Yes, actually I didn't fully realize that, thanks. That makes this change somewhat more severe. I'm also kind of skeptical that the default But my question is: comparing compiling a program under 4.04 and 4.03, both with this change, will there be any difference? If I wrote out |
Thanks @hcarty, we cross-posted :) |
There is the possibility of removing the ability to use |
I guess this would also have the advantage of making the current special behavior of |
b8b3168
to
0773186
Compare
@aantron Do you want to try to get this into 3.1.0 in some form? I may be able to spend a little time on it. |
Yeah, maybe we should finish it by 4.0.0 – but no rush, I think we will be doing a 3.2.0 anyway. I'll leave a message about that in gitter too, so more people know. |
Closing based on a conversation with @aantron and comments above. There's more important work to do listed in comments above that I'm not likely to get to any time soon. We can re-open later if there's interest. If anyone comes along later and wants to finish the work started in this PR they are more than welcome to use what's here! |
Reopening this based on discussion in #525. I'll rebase onto the latest |
Sounds good; let me know if you want me to rebase it instead and save you a bit of work :) We may want to do it after #534 is merged, in case it introduces more conflicts. |
And cc @kandu! |
5db8365
to
da51e68
Compare
@aantron Rebased - though I'm not sure what happened with the ppx test file... |
Ok, I'm going to release Nobody in opam is actually affected by this PR. I really doubt anyone at all would be affected by it anywhere, but let's test the ability to release Lwt quickly... |
src/ppx/ppx_lwt.ml
Outdated
@@ -133,6 +133,15 @@ let gen_top_binds vbs = | |||
[Vb.mk (Pat.tuple (vbs |> List.map (fun { pvb_pat; _ } -> pvb_pat))) | |||
[%expr Lwt_main.run [%e gen_exp vbs 0]]] | |||
|
|||
let lwt_sequence mapper ~lhs ~rhs = | |||
let pat = if !strict_seq then [%pat? ()] else [%pat? _] in |
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 suggest we remove this, no need to make the new syntax be leaky :) Especially since -no-strict-sequence
is now deprecated. Unless there is a good reason to have non-strict sequence.
src/ppx/ppx_lwt.mli
Outdated
It is possible to sequence Lwt operations: | ||
{[ | ||
[%lwt write stdout "Hello again, "; write stdout "world!"] | ||
]} |
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 wouldn't recommend this syntax. We are trying to get rid of [%lwt ...]
completely because it is fragile to refactoring the inside. We can't actually ban the syntax, but we shouldn't encourage it IMO.
tests/ppx/main.ml
Outdated
@@ -0,0 +1,195 @@ | |||
open Test |
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 the directory was changed to test
instead of tests
.
da51e68
to
1977f63
Compare
Sorry this took a while! I think I've addressed the comments - do you want to take another look @aantron? Thank you for pointing out the test location change too. |
1977f63
to
359b4c5
Compare
Hey, no worries, there is no rush, and I know you've got other things to do :) It looks good. We can't merge the test because it unconditionally requires 4.04 to compile. I think there are two "good" ways to address that, one is to use cppo, and the other is to put the I'm going to merge this without the test for now. I'll take care of fixing the expect tests and add the Thanks! |
All sounds good - thanks! |
This is a particularly useful addition for 4.04.0 and on as it allows non-Lwt
;
sequence and Lwt;%lwt
sequence operations to intermingle without extra parens.Backwards incompatibility
The incompatible change here is that, previously,
[%lwt (); Lwt.return_unit]
would evaluate just fine but with this change it results in a type error because, within the context of%lwt
, both sides of the;
sequence are expected to be promises.