ocaml-ppx / ocaml-migrate-parsetree

DEPRECATED. See https://ocaml.org/changelog/2023-10-23-omp-deprecation. Convert OCaml parsetrees between different major versions
Other
87 stars 43 forks source link

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

Closed aantron closed 4 years ago

aantron commented 5 years ago

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:

https://github.com/ocaml-ppx/ocaml-migrate-parsetree/blob/b7f1862433e598aa9f91f9b96a5639f1caa301e7/src/migrate_parsetree_driver.ml#L429-L430

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.