-
Notifications
You must be signed in to change notification settings - Fork 98
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
Allowing multiple errors to be reported in one pass of the context_free phase #453
Conversation
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.
Making good progress!
I reviewed only the "Catching extenders' exceptions". Except for minor comments, it looks good!
The embed_errors
value is not passed from the driver yet, which is probably why the tests do not work yet...
src/context_free.ml
Outdated
(try | ||
E.For_context.convert_res ts ~ctxt ext | ||
|> With_errors.of_result ~default:None | ||
with exn when embed_errors -> (None, [ exn_to_error exn ])) |
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 makes sense to catch the exception in convert_res
rather than here. One would not expect that a *_res
function which returns a result type raises a located exception (the res
suffix is for "result", and the result type is often used to have "more explicit errors". Here it would be a combination of both...)
That would also factor some of the code here!
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 guess one problem here is we only catch when embed_errors
is true
. To preserve that behaviour we'd need to propagate the embed_errors
argument to convert_res
which I'm not sure is a good idea.
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.
It's also unclear to me what would be the best way to deal with an exception from the actual rewriting function here. The errors returned by convert
are Ast_pattern
parsing errors which are slightly different from the ones we're catching here.
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.
Nice progress on the "constant" rewriting!
I left some small comments.
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.
Nice improvements! Only the "special function" rewriting is missing.
I left some comments.
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.
A small batch of comments!
Thank you @panglesd, I have implemented the changes requested. |
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 looks good, great change!
Do we really need to tie this to embed_errors
? Are there good reasons not to do this? It's already on by default when used through dune if I'm not mistaken. I guess this could break tests that rely on the output of the driver. Do you have any other uses cases in mind?
a83582c
to
df9cc61
Compare
The tests are broken it seems. The error extension points are printed backward and some locations were off when running the driver without I think this comes from a change in #447. I suggest we sort errors by location before inserting them in a separate PR so that the order of errors is a bit more reliable than what it is right now. |
…ee transformation. Signed-off-by: Burnleydev1 <[email protected]>
Signed-off-by: Burnleydev1 <[email protected]>
Signed-off-by: Burnleydev1 <[email protected]>
Signed-off-by: Burnleydev1 <[email protected]>
Signed-off-by: Burnleydev1 <[email protected]>
…ontext_free transformation. Signed-off-by: Burnleydev1 <[email protected]>
Signed-off-by: Burnleydev1 <[email protected]>
… errors Signed-off-by: Burnleydev1 <[email protected]>
Signed-off-by: Burnleydev1 <[email protected]>
Signed-off-by: Burnleydev1 <[email protected]>
Signed-off-by: Burnleydev1 <[email protected]>
Signed-off-by: Burnleydev1 <[email protected]>
Signed-off-by: Burnleydev1 <[email protected]>
Signed-off-by: Burnleydev1 <[email protected]>
Signed-off-by: Burnleydev1 <[email protected]>
Signed-off-by: Burnleydev1 <[email protected]>
Signed-off-by: Nathan Rebours <[email protected]>
Signed-off-by: Nathan Rebours <[email protected]>
Signed-off-by: Nathan Rebours <[email protected]>
df9cc61
to
d73ae80
Compare
This should be good to go except for a CI failure with tests on 4.05 and 4.04, I'm looking into it. We discussed a slightly different approach regarding context free transformations throwing exceptions where we would inject the error node directly in the AST in place of the node that needed to be rewritten instead of leaving the original node and inserting the error at the beginning of the AST. I still believe this would be a cleaner solution but at the moment I think the solution we have is good enough to be merged. We can still improve this later on. |
Signed-off-by: Nathan Rebours <[email protected]>
adefd8e
to
c3f3c7a
Compare
Should be good now! |
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.
Thanks @NathanReb for the final work on this PR! I believe it is ready to be merged.
About the other approach of replacing extension nodes by error nodes in case of exceptions: I agree this is a very valid approach, and would definitely accept a PR with the changes. I would also think the current situation is good enough.
For reference, here are the pros and cons of each approach, as discussed in a dev meeting (quoting from the notes):
[Main advantages of current approach:] Coherence with error collecting from other phases, less potential for later coming whole-file transformations to mess up embedded errors. We all agree that the latter shouldn't be taken too much into consideration.
[Main advantages of replacing the extension node:] Coherence with what we ask PPX authors to do (embed the errors themselves) and no duplication of error messages in case of extension nodes, where the compiler will also emit an error if the node doesn't get replaced.
CHANGES: - Fix `Longident.parse` so it properly handles unparenthesized dotted operators such as `+.` or `*.`. (ocaml-ppx/ppxlib#111, @rgrinberg, @NathanReb) - raising an exception does no longer cancel the whole context free phase(ocaml-ppx/ppxlib#453, @Burnleydev1) - Sort embedded errors that are appended to the AST by location so the compiler reports the one closer to the beginning of the file first. (ocaml-ppx/ppxlib#463, @NathanReb) - Update `Attribute.get` to ignore `loc_ghost`. (ocaml-ppx/ppxlib#460, @ceastlund) - Add API to manipulate attributes that are used as flags (ocaml-ppx/ppxlib#408, @dianaoigo) - Update changelog to use ISO 8061 date format: YYYY-MM-DD. (ocaml-ppx/ppxlib#445, @ceastlund) - Replace `Caml` with `Stdlib`. (ocaml-ppx/ppxlib#427, @ceastlund) - When a transformation raises, the last valid AST is used as input to the upcoming transformations. All such errors are collected and appended as extension nodes to the final AST (ocaml-ppx/ppxlib#447, @Burnleydev1) - Fix a small mistake in the man pages: Embededding errors is done by default with `-as-pp`, not with `-dump-ast` (ocaml-ppx/ppxlib#464, @pitag-ha) - Set appropriate binary mode when writing to `stdout` especially for Windows compatibility. (ocaml-ppx/ppxlib#466, @jonahbeckford)
This extra argument that was added in ocaml-ppx#453 caused breakage in `ocsigen-i18n` that was using `Context_free.map_top_down`. Although it's undocumented, this function is still part of the public API. Adding an extra optional argument is not strictly speaking non-breaking but is good enough of an effort considering the status of this function and in particular, the fact that it only has a single public external user for which it prevents breakage. Signed-off-by: Nathan Rebours <[email protected]>
This extra argument that was added in ocaml-ppx#453 caused breakage in `ocsigen-i18n` that was using `Context_free.map_top_down`. Although it's undocumented, this function is still part of the public API. Adding an extra optional argument is not strictly speaking non-breaking but is good enough of an effort considering the status of this function and in particular, the fact that it only has a single public external user for which it prevents breakage. Signed-off-by: Nathan Rebours <[email protected]>
CHANGES: - Add an optional `embed_errors` argument to `Context_free.map_top_down` that controls how to deal with exceptions thrown by context-free rules. (ocaml-ppx/ppxlib#468, @NathanReb) - Fix `Longident.parse` so it properly handles unparenthesized dotted operators such as `+.` or `*.`. (ocaml-ppx/ppxlib#111, @rgrinberg, @NathanReb) - raising an exception does no longer cancel the whole context free phase(ocaml-ppx/ppxlib#453, @Burnleydev1) - Sort embedded errors that are appended to the AST by location so the compiler reports the one closer to the beginning of the file first. (ocaml-ppx/ppxlib#463, @NathanReb) - Update `Attribute.get` to ignore `loc_ghost`. (ocaml-ppx/ppxlib#460, @ceastlund) - Add API to manipulate attributes that are used as flags (ocaml-ppx/ppxlib#408, @dianaoigo) - Update changelog to use ISO 8061 date format: YYYY-MM-DD. (ocaml-ppx/ppxlib#445, @ceastlund) - Replace `Caml` with `Stdlib`. (ocaml-ppx/ppxlib#427, @ceastlund) - When a transformation raises, the last valid AST is used as input to the upcoming transformations. All such errors are collected and appended as extension nodes to the final AST (ocaml-ppx/ppxlib#447, @Burnleydev1) - Fix a small mistake in the man pages: Embededding errors is done by default with `-as-pp`, not with `-dump-ast` (ocaml-ppx/ppxlib#464, @pitag-ha) - Set appropriate binary mode when writing to `stdout` especially for Windows compatibility. (ocaml-ppx/ppxlib#466, @jonahbeckford)
CHANGES: - Add an optional `embed_errors` argument to `Context_free.map_top_down` that controls how to deal with exceptions thrown by context-free rules. (ocaml-ppx/ppxlib#468, @NathanReb) - Fix `Longident.parse` so it properly handles unparenthesized dotted operators such as `+.` or `*.`. (ocaml-ppx/ppxlib#111, @rgrinberg, @NathanReb) - raising an exception does no longer cancel the whole context free phase(ocaml-ppx/ppxlib#453, @Burnleydev1) - Sort embedded errors that are appended to the AST by location so the compiler reports the one closer to the beginning of the file first. (ocaml-ppx/ppxlib#463, @NathanReb) - Update `Attribute.get` to ignore `loc_ghost`. (ocaml-ppx/ppxlib#460, @ceastlund) - Add API to manipulate attributes that are used as flags (ocaml-ppx/ppxlib#408, @dianaoigo) - Update changelog to use ISO 8061 date format: YYYY-MM-DD. (ocaml-ppx/ppxlib#445, @ceastlund) - Replace `Caml` with `Stdlib`. (ocaml-ppx/ppxlib#427, @ceastlund) - When a transformation raises, the last valid AST is used as input to the upcoming transformations. All such errors are collected and appended as extension nodes to the final AST (ocaml-ppx/ppxlib#447, @Burnleydev1) - Fix a small mistake in the man pages: Embededding errors is done by default with `-as-pp`, not with `-dump-ast` (ocaml-ppx/ppxlib#464, @pitag-ha) - Set appropriate binary mode when writing to `stdout` especially for Windows compatibility. (ocaml-ppx/ppxlib#466, @jonahbeckford)
No description provided.