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

Fix regression in #12403: quote source code also for marshalled ASTs #12698

Merged
merged 5 commits into from
Oct 30, 2023

Conversation

nojb
Copy link
Contributor

@nojb nojb commented Oct 29, 2023

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

Copy link
Member

@gasche gasche left a 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.)

@nojb
Copy link
Contributor Author

nojb commented Oct 30, 2023

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.

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) -> ()
Copy link
Member

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 :-)

@gasche gasche merged commit adfd041 into ocaml:trunk Oct 30, 2023
9 checks passed
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.

Errors for marshalled ASTs no longer print relevant source code
2 participants