-
Notifications
You must be signed in to change notification settings - Fork 455
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
Clean up super errors in syntax #6246
Conversation
I think this should be a lightweight refactoring without any semantic change. Syntax errors are different from type errors and we should not mix them lightly. I think this one should just move some functionality around if possible. CC @ |
CC @cknitt |
Okay, that's good to hear. |
I think if there is some real code duplication/cleanup to be done, this is the time. Let's see what @cknitt thinks. |
When I originally created this issue it was about the duplication between (* Format.formatter -> Location.error -> unit *)
let rec super_error_reporter ppf ({loc; msg; sub} : Location.error) = ... and (* Format.formatter -> string -> Location.error -> unit *)
let super_error_reporter ppf src ({loc; msg} : Location.error) = ... Same functionality except that the first one would read the source from the source file and the second one would get it passed as a string. Now (after the refactorings in #6199 and before this PR) as far as I can see |
In my opinion, they are not redundant. Res_diagnostics_print* is a special implementation for printing Res_diagnostics.error, so it requires a source, unlike Location.print. As I understand it, in order to use Location.print to handle Location.error, it would have to be handled as an exn, like the implementation in this PR. |
You probably have looked into this into much more detail than me, but isn't it possible to unify this in some other way? The source is loaded conditionally here: Couldn't we do something like passing a callback for obtaining the source as an additional argument to the print function? So in one case it would be loaded from a file and in the other case it would just use the provided string? (Provided there are really no other differences in the functions.) |
Ah I missed that part, unifying |
I mentioned a callback instead of an optional arg because I was wondering whether we'd be dragging the dependency on |
Ah! Good point! Let me refactor that way. |
1bb09f1
to
e5d1738
Compare
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! 👍
My only possible concern is as mentioned whether this causes the dependency on Ext_io.load_file
to be dragged into the playground and whether this might cause any issues.
But I'd say let's merge and maybe @ryyppy can rebase his ongoing playground PR and check?
@@ -375,7 +385,7 @@ let rec report_exception_rec n ppf exn = | |||
match error_of_exn exn with | |||
| None -> reraise exn | |||
| Some `Already_displayed -> () | |||
| Some (`Ok err) -> fprintf ppf "@[%a@]@." report_error err | |||
| Some (`Ok err) -> fprintf ppf "@[%a@]@." (report_error ~src:None) err |
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've tried a callback to remove the dependency on the Ext_io
module, but it's hard to implement. Here's the problem. Since it uses %a
, I can't omit it even if I use an optional arg with a defalt value, and I think I'll have to use something like ~src:Ext_io.load_file
if we use a callback. That means we cann't remove the Ext_io
dependency anyway.
And since Jsoo_main and Jsoo_playground are already using Location.report_error function, I'd like to check with @ryyppy about the dependency on Ext_io.
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 recalled that I had to copy / paste some syntax diagnostics code to the playground so I can circumvent the IO issue. I am sure JSOO has a way to replace the Ext_io module with a different impl somehow?
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.
Ah, so referencing Ext_io
is indeed an issue. Good to know, I wasn't sure.
One could also do something like
Location.load_source_file := Ext_io.load_file
on (non-JSOO) compiler startup.
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.
How about skip Ext io.
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.
Or make it platform independent. (After checking if there's some actually observable perf difference).
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 is the code I essentially copied and adapted to get rid of the IO call: https://github.com/rescript-lang/rescript-compiler/blob/5fef8d33fd29bf6ddb3905a687a13c0c9ea147bd/jscomp/jsoo/jsoo_playground_main.ml#L222-L243
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.
I'm looking into the Jsoo_playground_main. It is already dependent to the previous Super_errors
. I'm still not sure if copy/pasting that part would have avoided the IO call.
I think the playground stuff in CONTRIBUTING.md is a bit out of date, but I'll follow it and give the post-build js a spin to check.
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.
Ah, I found this #6201
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.
@ryyppy I applied the changes from PR #6201 to this PR and replaced Res_diagnostics_printing_utils.Super_location.super_error_reporter
with Location.report_error
. Then I built the playground and ran the tests, which resulted in a stack overflow first. When I commented out the part using React.useState, the tests passed.
Does this mean we can consider there are no issues related to the Ext_io dependency?
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.
Yes, if you get to this point, it means the playground compiled successfully. The stack overflow issue is unrelated.
One thing that confuses me: Wasn't the res_diagnostics_printing_utils more up-to-date than the original super_error error reporters? |
If by "more up-to-date" you mean different output, in fact, the output of the old super_error mixed with Location.default_error_reporter is no different from the original test-syntax output. |
So you are saying all the tests are essentially outputting the same error messages? If so, then this looks good to me. |
Yes. |
There's nothing more to do with this PR, shall we merge? |
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.
LGTM. If @cknitt or @cristianoc have no objections, let's merge.
Fine with me, I approved already. 👍 Thanks a lot for your work @mununki! |
I hope @cristianoc doesn't have any objections, and if he does, I'll fix it in a subsequent PR. |
Fixes #5879
This PR removes the super_errors that were left in the syntax. The main changes are as follows:
UseUseLocation.register_error_of_exn
instead ofRes_diagnostics.printReport
to handle syntax error as a Location.errorLocation.report_error
instead of duplicated implementation of super_errors inres_diagnostics_printing_utils
. To do so, the interface is modified to allow you to pass an src that the parser already has as an optional labeled argument.(removed the stale codes)
res_diagnostics_printing_utils.ml
Things to check
Ext_io
inLocation
module would be fine in the playground.The test injscomp/syntax/tests/parsing/errors/*
prints a fatal error, so maybe we need to move it tojscomp/build_tests/super_errors
.