-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Fix regression in #12403: quote source code also for marshalled ASTs #12698
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.
I believe that the change is correct and I find it somewhat ingenious (it is interesting that our infrastructure, despite being a bit ad-hoc and full of mutable state, allows us to do this easily). But I don't like the duplication of "read the whole file at once" logic, that is, the pair of In_channel.input_all
and the explanatory comment, which is reproduced here in a slightly less informative version than it appears below.
This could be fixed by having an auxiliary function that has the logic and the comment, and is called in both cases -- parsing a source file or consuming a serialized ast. This could be a local function set_input_lebxuf : in_channel -> unit
that is in charge of reading the whole source file and storing it in Location.input_lexbuf
. (The caller in the parse-a-source-file case is still responsible for seek_in
.)
Thanks for the suggestion. Pushed a commit in this direction: ddd84f8. |
| exception Sys_error _ -> | ||
() | ||
begin match In_channel.with_open_bin !Location.input_name set_input_lexbuf with | ||
| (_ : Lexing.lexbuf) -> () |
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 nice that your own warning forced you to add an annotation :-)
As mentioend in #12697, it appears that #12403 introduced a regression: when reading marshalled ASTs the compiler no longer quotes any source code in error messages. This is because the compiler no longer reads in the source file corresponding to the marshalled AST.
This PR proposes a fix by reading (if possible) the source file when unmarshalling the AST and making it available to later error printers.
Assigning to @gasche who authored #12403.
Fixes #12697