ocaml-ppx/ocaml-migrate-parsetree

--dump-ast: write the same version of AST that was read

aantron opened this issue · 0 comments

So, if reading, e.g., a version 4.02 binary AST, writing with --dump-ast should produce a version 4.02 binary AST.

Right now, it produces an AST of whatever compiler version the driver was compiled with.

I believe this is the ultimate place where the decision to write the same version is not made:

| Intf (_, sg) -> Ast_io.Intf ((module OCaml_current), sg)
| Impl (_, st) -> Ast_io.Impl ((module OCaml_current), st)

I guess we would need to note the source version on loading. On writing, we would need to migrate the AST to the target version (instead of to the current version, wherever this is done), and then write that. If the source version is not available (because we read a source file), we can write according to the version with which the driver was compiled, as now.

If this is approved, I can try to make the change.