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

Update documentation with new behaviour wrt exceptions #457

Merged
merged 4 commits into from
Jan 31, 2024

Conversation

panglesd
Copy link
Collaborator

@panglesd panglesd commented Oct 24, 2023

This is the PR that updates the documentation taking into account the changes made in #447 and #453.

Pinging @Burnleydev1 if you want to review!

This PR makes it "more acceptable" to raise for PPXs, since it is supported and does not harm the other ppx execution. So most of the changes are in the "raising" section of the manual.

@panglesd panglesd added the no changelog Use this label to disable the changelog check github action label Oct 24, 2023
Copy link
Contributor

@Burnleydev1 Burnleydev1 left a comment

Choose a reason for hiding this comment

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

I just had some minor questions, but I think it looks good to me.

[[%ocaml.error "error_message"]] that can be embedded into a valid AST and are interpreted later
as errors, e.g., by the compiler or Merlin. As all extension nodes, they can be
put {{:https://ocaml.org/manual/extensionnodes.html}at many places in the AST}
to replace structure items, expressions, or patterns, for example.

So whenever you're in doubt whether to throw an exception or if to embed the error as
Copy link
Contributor

Choose a reason for hiding this comment

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

Hello @panglesd , I was thinking we update this if there is no longer a preferred way of reporting errors, except the new behaviour does not still make raising as good as embedding.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, even though it's not so important anymore to migrate code from exceptions to embedding, since the behavior is acceptable, it is still better if new PPX adopts the embedding way of reporting errors.
Also, this paragraph speaks about where to embed the errors (as deep as possible) so it makes sense to keep it.

generated code.
- By raising a sepcific exception, letting the ppxlib driver handle the error.

Let us already emphasize that, while exceptions can be practical to quickly fail
Copy link
Contributor

Choose a reason for hiding this comment

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

I am thinking we could maybe remove already in this sentence.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks!

Copy link
Member

@pitag-ha pitag-ha left a comment

Choose a reason for hiding this comment

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

Perfect! Thank you, @panglesd and @Burnleydev1, both for the update of the docs and the implementation of this! Btw, do you want me to have a look at the PRs of the implementation, @panglesd?

doc/good-practices.mld Outdated Show resolved Hide resolved
doc/good-practices.mld Outdated Show resolved Hide resolved
doc/good-practices.mld Outdated Show resolved Hide resolved
Comment on lines 109 to 111
{{!Ppxlib.Location.raise_errorf}[Location.raise_errorf]}. But keep in mind that
in many case, there is a better AST to continue from than the one that was
initially passed to the rewriter.
Copy link
Member

Choose a reason for hiding this comment

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

What do you mean with the "keep in mind" side-note here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I wanted to say that raise_errorf should only be used when there is no advantages to embed the error in the AST. But that's not even true: a PPX can raise a located error, and catch it at the point where it wants to embed the error, instead of using result type.
I'll remove the side-note.

doc/good-practices.mld Outdated Show resolved Hide resolved
@panglesd
Copy link
Collaborator Author

panglesd commented Nov 2, 2023

do you want me to have a look at the PRs of the implementation, @panglesd?

If you have time, yes!
Otherwise, I'll have a look myself (since it's been a long time since I last looked at it, it is like if I were a new reviewer.

Copy link
Collaborator

@NathanReb NathanReb left a comment

Choose a reason for hiding this comment

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

It looks great! Very clear!

My only concern is that it goes quite a bit into detail on how we handle exceptions while we recommend not using them.

Do you have another section in mind where we could document this behaviour and keep this section about what we recommend?

If not I think I would at least swap the order of the sub sections and put the recommendation first and only then explain how we deal with exceptions now!

@panglesd
Copy link
Collaborator Author

panglesd commented Jan 12, 2024

Thanks for the review!

My only concern is that it goes quite a bit into detail on how we handle exceptions while we recommend not using them.

That's a good point!
If we prefer to move the explanation on how the driver handles exceptions, I think a natural place would be in the "driver execution explanation" of the docs.
Would you like to do it yourself? (I can do it otherwise of course!)

For a smaller change, putting this explanation after the better practice of embedding (or even after the documented example) seems a good improvement already.

@NathanReb
Copy link
Collaborator

Sure, happy to take care of it!

panglesd and others added 3 commits January 17, 2024 16:17
Signed-off-by: Paul-Elliot <[email protected]>
Signed-off-by: Nathan Rebours <[email protected]>
Co-authored-by: Sonja Heinze <[email protected]>
Signed-off-by: Paul-Elliot <[email protected]>
Signed-off-by: Nathan Rebours <[email protected]>
@NathanReb
Copy link
Collaborator

Just moved the exception handling section to driver.mld.

@NathanReb
Copy link
Collaborator

@panglesd if this looks good to you, I'll go ahead and merge!

@panglesd
Copy link
Collaborator Author

I can't approve my own PR but I do approve! I think it is good to merge.

I went ahead and added some links (the "exception handling" explanation used the concept of "context-free transformations" that are unavailable in this earlier part of the doc ; and the way exceptions are handled was a bit too disconnected from the good practices part). Feel free to revert if you don't like them!

Copy link
Collaborator

@NathanReb NathanReb left a comment

Choose a reason for hiding this comment

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

Thanks for the added links, it looks much better with them indeed!

@NathanReb NathanReb merged commit 694174a into ocaml-ppx:main Jan 31, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no changelog Use this label to disable the changelog check github action
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants