-
Notifications
You must be signed in to change notification settings - Fork 90
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
Only convert needed parts of the AST instead of converting mapper #221
Only convert needed parts of the AST instead of converting mapper #221
Conversation
This fixes the segmentation fault reported by kit-ty-kate: ocaml-ppx#210 (comment) I don't know where this segmentation fault precisely occurred, but I suppose that converting the mapper makes Migrate_parsetree make a lot of conversion between each sub-tree of the AST. The new approach is a bit more verbose but conceptually simpler and should be more efficient.
Thanks a lot for that, I was really going nowhere trying to understand where the issue came from ^^" The CI failure is a transient failure and can be ignored (or retried). I've launched a check with this branch checking all the opam packages for 4.10 and 4.11, but considering Thanks a lot for that! |
I would prefer if we isolated precisely the issue that causes the segfault, and fixed only this in a minimal way, to make sure that we understand well what the problem is. We can make other improvements suggested by the bug hunt as a separate commits. I don't know if your PR currently has this property. Our current understanding of the segfault is that we are incorrectly using |
|
Wow, the headaches... Let me summarize what I now understand. The code in the current master comes from your original ppxlib PR, /~https://github.com/ocaml-ppx/ppx_deriving/pull/206/files#diff-2e347c45109b096b774cef8af562932aR6, which was on top of previous code to use ocaml-migrate-parsetree for the driver machinery (but not for anything else). In the PR, you redefined There was one remaining issue, though: this code is doing weird driver stuff by inheriting from a base mapper obtained through Now we realize that we need to call
but that sounds very unreasonable, I agree, and it would also break if non-408 features are used in some traversed parts of the AST that we don't care about. Instead what your PR does is to be more careful in the way our code is called, so that it is presented as a |
If my understanding above is correct, then I agree that your PR goes in the right direction. However, then I think we need to do more changes to have a reasonable final state. I don't think it is reasonable to have a |
Ah, but this suggestion has negative implications for backward-compatibility: if the Your PR has the advantage that both the Parsetree fragments and the Ast_mapper API are used at a fixed version, except for the very final call to |
@thierry-martinez I pushed an experiment on top of your PR as gasche@67b118a . I have the impression that the code is cleaner; what do you think? |
@gasche I think that your experiment is not only cleaner but also "more correct" than mine, indeed: |
After checking all the opam packages, I can confirm 167a9fc fixes all the issues I was seeing. Should I check again with the latest commit? |
@kit-ty-kate thanks for the opam checking! I think that we might want to iterate just a bit more to get a nice PR. I would propose that you wait until we decide to merge a final fix, and then it would be very nice if you could another round of testing. |
@thierry-martinez the cookie problem is a good catch, thanks! I realized that I had forgotten a Pexp_tuple expression which was still being type-checked in the "current" AST, while I intended all parsetree-related constructs to be fixed at 4.08. I pushed a supplementary fix in db650a5 . There are subtle differences between my WIP and your proposal. In my proposal, I intended to have all Parsetree logic at OCaml_408, and all the logic is Ppxlib's or Migrate_parsetree's, never compilerlibs. You version feels a more complex because you construct and deconstruct ASTs in different versions (note: I think the copies are neglectible performance-wise, and do not incur any extra risk of dynamic failure), and you mix Ppxlib/Migrate_parstree logic with Compilerlibs logic (which is fine as OCaml_current should be compatible with Compilerlibs). I also realized something unrelated while reading the code. In practice the mapper from this module runs |
Suggested by Gabriel Scherer in ocaml-ppx#221 (comment)
0734b6e
to
995fc34
Compare
src/ppx_deriving_main.cppo.ml
Outdated
| _ -> assert false) |> | ||
add_plugins; | ||
mapper.Current_ast.Ast_mapper.structure mapper tl | ||
| exception Migrate_parsetree.Def.Migration_error -> |
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 raises a syntax error in the CI
@kit-ty-kate oops, fixed! Thanks! |
No worries, but I was more pointing out the |
Sorry, I should have been very more cautious: I didn't notice that |
Yes! The new code looks very nice to me. Is there anything left to do before merging? |
I think everything is OK now. Merging! Thank you very much, @kit-ty-kate and @gasche. |
This fixes the segmentation fault reported by kit-ty-kate:
#210 (comment)
I don't know where this segmentation fault precisely occurred, but I suppose that converting the mapper makes Migrate_parsetree make a lot of conversion between each sub-tree of the AST. The new approach is a bit more verbose but conceptually simpler and should be more efficient.