Skip to content

Ppx syntax extension - #75

Merged
8 commits merged into
masterfrom
ppx
Sep 24, 2014
Merged

8 commits merged into
masterfrom
ppx

Conversation

@Drup

@Drup Drup commented Aug 16, 2014

Copy link
Copy Markdown
Member

So, I think it's ready now. There is still a small opam issue (see ocaml/opam#1572) but we can take care of that later.

@diml : I added documentation and the code is ready to be looked at.

There is annoying point here but there is no clean solution with oasis.

cc @whitequark

Comment thread _oasis Outdated

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why do we need this here? There should be a tag use_ppx_lwt in _tags with some flag statements in myocamlbuild.ml to add the right -ppx argument.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I have no idea how to get in myocamlbuild.ml which one of the executables (byte/native) OASIS will build.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You can access the variables in setup.data with BaseEnvLight.var_get (it is already used in myocamlbuild.ml). You can use the is_native variable to guess whether oasis will build the .byte or .native.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@Drup Would you please make OASIS jump through the burning ring here? I feel you'll do it better than me.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done.

@Drup

Drup commented Sep 13, 2014

Copy link
Copy Markdown
Member Author

I rebased, so it's mergeable, and I added the necessary flag to detect byte/native extension for the ppx.

@ghost

ghost commented Sep 15, 2014

Copy link
Copy Markdown

I had a quick look and it seems fine to me. Though I do find the syntax for finally highly unintuitive as [%finally] is syntactically just another branch while it is unconditionally executed. If there is no better syntax I'd rather see it disabled for now.

@whitequark

Copy link
Copy Markdown
Contributor

@diml No, there is no better syntax, and I completely disagree with disabling it. To begin with, I already have code which uses this feature. Then, right now, the two syntax extensions have 1:1 feature parity. I certainly don't want the ppx one to be inferior.

I'm not sure there ever will be better syntax. @alainfrisch? Could we use something else than a fake match case for [%finally]? Currently it looks like try x with Exn1 -> y | [%finally] -> z.

@alainfrisch

Copy link
Copy Markdown

Looking for a nice syntax for a finally statement? What about piggy-backing the syntax for application:

(try ... with ...) [%finally ...]

(which could also be written with "begin ... end")

@whitequark

Copy link
Copy Markdown
Contributor

It looks really terrible to me ಠ_ಠ Much more so than piggybacking the branch. @diml?

@gasche

gasche commented Sep 16, 2014

Copy link
Copy Markdown
Contributor

I would rather prefer Alain's suggestion as it makes it clear that the finally part is evaluated regardless of the way the function returns control -- in particular, also if one of the with ... handlers raises an exception itself, which is not at all apparent with the piggyback-branch syntax.

@whitequark

Copy link
Copy Markdown
Contributor

@gasche I agree; you have a point.

Any other suggestions?

@ghost

ghost commented Sep 16, 2014

Copy link
Copy Markdown

I'm fine with @alainfrisch suggestion. I guess one slight disadvantage is that it make it seems that the finally is executed after the with ... handlers which is not the case.

@Drup

Drup commented Sep 22, 2014

Copy link
Copy Markdown
Member Author

What do we do about try%lwt ... with [%finally] -> ... ?

Letting it like that make the syntax inconsistent.

@whitequark

Copy link
Copy Markdown
Contributor

Oh, I just realized Alain's suggestion is actually composable, as it piggybacks application syntax. I.e. this way you can "finalize" any expression at all, not just try..with. Now I really like it!

I suggest recognizing two forms:

  1. (..) [%lwt.finally ..]
  2. (try%lwt .. with ..) [%finally]

This way, it will be clearly namespaced either way.

@Drup

Drup commented Sep 22, 2014

Copy link
Copy Markdown
Member Author

Why not just use [@finally ... ] ? No point on using application, it's just attached to a node in the end.

@whitequark

Copy link
Copy Markdown
Contributor

@Drup That would be ignored if you forget to include lwt.ppx.

@Drup

Drup commented Sep 22, 2014

Copy link
Copy Markdown
Member Author

Err, right.

If feels slightly wrong.

@Drup

Drup commented Sep 24, 2014

Copy link
Copy Markdown
Member Author

I implemented the new syntax for finally. I also fixed a small issue with attributes.

@whitequark

Copy link
Copy Markdown
Contributor

@Drup LGTM.

@ghost

ghost commented Sep 24, 2014

Copy link
Copy Markdown

The e [%finally] form looks good to me but not the (try% e with c)[%finally f] one. I think for consistency it should behave the same as:

let e' = try%lwt e with c in
e' [%finally f]

So f should be executed after c, not before.

@Drup

Drup commented Sep 24, 2014

Copy link
Copy Markdown
Member Author

I don't understand, what do you want to change ? the equivalent of the old try ... with .. finally ... should be accessible, and I don't want to change Lwt's semantic.

@gasche

gasche commented Sep 24, 2014

Copy link
Copy Markdown
Contributor

@diml so the one with the right semantics is try e [%finally f] with c, isn't it?

@ghost

ghost commented Sep 24, 2014

Copy link
Copy Markdown

@Drup, either don't special case (try%lwt e with c) [%finally f] and let the ast mapper handle both forms independently. Or change the expansion of the exception handler to (fun e -> Lwt.finalise (function c) (fun () -> f). The first solution seems simpler.

TBH honest I think the old try_lwt ... with .. finally ... was a bit of a mistake and the new ppx should avoid it.

@gasche, try e [%finally f] with c is to be seen as try (e [%finally f]) with c, which makes it explicit what happens. Basically I think there should be no special case for try ... with ... finally.

In the camlp4 extension, try e with c finally f and try e finally f with c are treated as (ignoring the lwt monad):

match e with
  | x -> f (); (match x with c)
  | exception e -> f (); raise e

I don't claim that this was the best choice, and I wish I didn't introduced this form. With the new syntax I claim that expanding (try e with c) [%finally f] to the above is even worse as the parentheses suggest that f is executed after c.

@whitequark

Copy link
Copy Markdown
Contributor

@diml Good points. I now see the problem with ordering of [%finally]. I now think too that try and finally should be made fully orthogonal.

@gasche

gasche commented Sep 24, 2014

Copy link
Copy Markdown
Contributor

I think you rather mean

match e with
  | x -> f (); x
  | exception e -> f (); (match e with c)

If retrospectively people agree that this is not a very nice construct, why not just drop it? I understand the desire to be feature-compatible with the camlp4 implementation as a point of principle, and also to help users migrate code, but maybe this is also a good occasion to fix a design mistake.

@ghost

ghost commented Sep 24, 2014

Copy link
Copy Markdown

I think you rather mean

match e with
  | x -> f (); x
  | exception e -> f (); (match e with c)

Indeed, thanks.

If retrospectively people agree that this is not a very nice construct, why not just drop it? I understand the desire to be feature-compatible with the camlp4 implementation as a point of principle, and also to help users migrate code, but maybe this is also a good occasion to fix a design mistake.

Yes, that's what I'm suggesting.

@Drup

Drup commented Sep 24, 2014

Copy link
Copy Markdown
Member Author

Done. This changes also makes the code quite simpler.

ghost pushed a commit that referenced this pull request Sep 24, 2014
@ghost
ghost merged commit 59d9917 into master Sep 24, 2014
@ghost

ghost commented Sep 24, 2014

Copy link
Copy Markdown

Merged, thanks!

@aantron
aantron deleted the ppx branch October 6, 2016 00:05
This pull request was closed.
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.

6 participants