-
Notifications
You must be signed in to change notification settings - Fork 43
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
The magic number checks of Ast_4NN.register
appear to be broken
#97
Comments
…gister` This commit fixes ocaml-ppx#97 which caused segfaults: `Ast_4NN.register` now correctly checks AST magic number against the version-specific magic number instead of using the magic number defined in the `Config` module of the current compiler. Version-specific magic numbers was already defined by overriding `Config` module later in the file: the fix just consists in riding up the overriding of `Config` before the overriding of `Ast_helper`. Following Gabriel Scherer's trick recommended in ocaml-ppx/ppx_deriving#210 (comment) a unit-value `in_ast_4nn` is defined in `Config` module and used in `Ast_helper.register` to ensure that the module are well ordered.
Thinking more about it, I am not completely sure of what is the intended semantics of
Currently it is doing neither: it opens current serialized ASTs but calls a 4NN-rewriter without any conversion, leading to segfaults. My suggestion to change the magic-number check would implement (2). On the other hand, if you/we want (1), then we should (keep expecting the current magic numbers and) add a conversion pass on the rewriter. I believe that the intended semantics should be documented clearly to help avoid issues. (Even without the current bug, if people use (2) may be the more common need (it is rare to compile on a given version of OCaml and expect to produce a working ppx rewriter for an older version of OCaml), but then it is easily expressible by users today with just a single |
…rent AST As Gabriel Scherer explained in ocaml-ppx#97 (comment) there is two possible semantics for `Ast_4NN.register`. (1) register a 4NN-rewriter in such a way that it works on _current_ serialized ASTs (2) register a 4NN-rewriter in such a way that it works on serialized ASTs for OCaml 4NN This commit implements (1) whereas ocaml-ppx#98 implements (2).
@thierry-martinez implemented two fixes that give either semantics: #98 and #99 It would be great to have guidance from someone more familiar with ocaml-migrate-parsetree (in particular someone who could review and make merge decisions!) on which way the tool should go. |
I'm pretty sure we added these by accident since 4.08. The update process of omp is quite complicated, so I'm not surprised this happened. |
You mention that you are planning to remove those erroneous |
There seems to be some register functions in
The upgrade process is not mechanical. It is painfully manual and not very well formalised. For 4.08, it was done by a new person and the fact that the |
I believe this can be closed now. |
BTW, one thing we mentioned in the past with @let-def is that we could narrow the scope of |
Yes, I still think this is a worthwhile simplification. It should just be done carefully to avoid more breakage. |
Indeed. I was looking at the dune-universe and there seems to be quite a few references to |
We were just talking about this with @NathanReb and @avsm, and that seems to be a good problem to throw at the duniverse. More precisely, we could simplify ocaml-migrate-parsetree as one breaking 2.0.0 release and use duniverse to realistically migrate all packages currently relying on the omp driver to ppxlib at once. We started playing with the idea of creating a duniverse with all the ppx projects out there still using the ocaml-migrate-parsetree driver: https://github.com/dune-universe/ppx-duniverse |
After talking to a few people, we are actually going to do this. The overall plan is:
I'll announce this more publicly on discuss shortly. |
@gasche @thierry-martinez when you have some time, I'm also interested to talk about the loader of |
I am trying to understand the cause of a segfault in ppx_deriving (reported by @kit-ty-kate) since we migrated to ppxlib, see ocaml-ppx/ppx_deriving#210 (comment) . @thierry-martinez tracked down the issue to incompatible serialized ASTs (we seem to be calling
input_value
on an AST of some version, and getting a segfault when we try to use it as it was of another version), originating from a call toAst_408.Ast_mapper.register
. This suggests an issue in m-o-p, at least in terms of validation of magic numbers.Indeed, the current source fo Ast_408 and all later versions have an
Ast_mapper.apply_lazy
module that performs magic number check using aConfig
module that appears to be the current compiler-libs config module (so it is checking against the current magic numbers, not 4.08's). There is aConfig
module defined later in the file, which provides the correct 4.08 magic numbers.Magic number checking lines 3843-3847:
https://github.com/ocaml-ppx/ocaml-migrate-parsetree/blob/18c00c9/src/ast_408.ml#L3843-L3847
Re-definition of
Config
lines 4043-4046:https://github.com/ocaml-ppx/ocaml-migrate-parsetree/blob/18c00c9/src/ast_408.ml#L4043-L4046
Questions:
(cc also @rgrinberg @jeremiedimino)
The text was updated successfully, but these errors were encountered: