ocaml-ppx / ppx_tools_versioned

Tools for authors of ppx rewriters
MIT License
17 stars 12 forks source link

A "current" version, equivalent to Migrate_parsetree.Versions.current #5

Closed hcarty closed 6 years ago

hcarty commented 6 years ago

Would this be possible? I'm not sure what trade-offs would be involved here.

let-def commented 6 years ago

What would be the purpose!?

hcarty commented 6 years ago

The question came up originally in https://github.com/zepalmer/ocaml-monadic/pull/6#issuecomment-375426704, asking what the implication of using a specific AST version from OMP would mean for users of newer compilers. Based on my understanding and (very) limited testing, it looks like using a ppx based on a specific OMP + ppx_tools_versioned AST limits a user's code to features from that release of OCaml.

As a somewhat contrived example, using 4.02's AST in an OMP+ppx_tools_versioned-based ppx prevents someone using that ppx from using 4.03's inline records in their code, even if the ppx doesn't touch type definitions.

If I understand correctly, for relatively simple ppx transforms it may be useful to have use the current AST in OMP + ppx_tools_versioned to provide some extra level of future-compatibility. I may be missing some significant issue(s) here though.

let-def commented 6 years ago

We thought about that in ocaml-migrate-parsetree. There is no real point in solving this issue in ppx_tools_versioned (using ppx_tools, not versioned, should get you the behavior you are looking for I think).

However ocaml-migrate-parsetree could, in theory, encode unsupported constructions and only fail when the target compiler has the wrong version. Rewriting 4.06 ast with a rewriter designed for 4.02 would work, even if a construction not supported is submitted to the rewriter. The other way would fail: compiling with 4.02 an AST that, after being rewritten by a 4.06 rewriter, contains unsupported construction.

But we decided to not implement this feature so far:

So ocaml-migrate-parsetree helps authors by only having to maintain a single version of the rewriter, but it is still their job to update for newer versions.

hcarty commented 6 years ago

Thank you for the detailed explanation! I'm happy to live with that, particularly when the change is (usually) so small when a new OCaml release comes out.

Closing.