Skip to content
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

Support for old versions of the compiler. #633

Closed
hhugo opened this issue Feb 16, 2019 · 8 comments
Closed

Support for old versions of the compiler. #633

hhugo opened this issue Feb 16, 2019 · 8 comments
Milestone

Comments

@hhugo
Copy link
Collaborator

hhugo commented Feb 16, 2019

Extracted from #630:

@hhugo:

This makes me think that we might need a flag to specify the targeted version of the OCaml compiler.
For instance, it would be incorrect to use the following syntax in 4.07.
module M(_:S) = struct end

@jberdine:

My position has always been to try to support the latest released version and the one preceding for "a while" to make it possible to upgrade non-atomically. That's not very generous, I know. But I'm not sure of the cost:value ratio for supporting old versions for dev tools, especially when they are so closely tied to compiler internals. Also, I don't know if it makes sense to commit/try to ensure that everyone can use the same compiler version to build ocamlformat as to build the code they are formatting. I'm definitely open to alternative, but just to say that I haven't already been convinced that something like dune's approach to legacy support is the right choice here.

For examples like the particular case of module M(_:S) = struct end, would it make more sense wrt community-wide effort to make a ppx that could be used with eg 407 that would convert the 408 ast to the expanded form that 407 can handle?

@hhugo
Copy link
Collaborator Author

hhugo commented Feb 16, 2019

While formatting some part of js_of_ocaml, I had to manually tune few places to stay compatible with ocaml 4.02.3. The churn was not very big, work around were trivial. Unsure if it could become painful overtime.

@gpetiot gpetiot added this to To do in OCaml Platform via automation Sep 3, 2019
@emillon
Copy link
Collaborator

emillon commented Mar 18, 2020

This came up again a couple times:

Initially I was thinking that an option for target version would work, but maintaining concrete syntax seems a better choice in general.

@jberdine
Copy link
Collaborator

Can I just note that there are noteworthy downsides to just punting on such questions and trying to preserve the concrete syntax.

  • Preserving the concrete syntax undermines all the objectives of using an auto-formatter, and should really be left as a last-ditch escape hatch mechanism for when things are necessarily very ad hoc.
  • The use of autoformatters to automatically update code to the current/modern language is blocked by this sort of thing. It would be better if the formatter could automatically rewrite old workaround to new solutions based on a target version.
  • The implementation mechanisms for preserving the concrete syntax will never be as efficient.

Do we know how much of a maintenance burden it would be to add a target version for the generated concrete syntax? Most importantly, do we know if it would interact with other configuration options in a multiplicative or additive way?

@gpetiot
Copy link
Collaborator

gpetiot commented Aug 4, 2021

4.14+

4.13+

4.11+

4.10+

4.08+

4.06+

  • Extended indexing operators, add a new class of
    user-defined indexing operators, obtained by adding at least
    one operator character after the dot symbol to the standard indexing
    operators: e,g ".%()", ".?[]", ".@{}<-": let ( .%() ) = List.nth in [0; 1; 2].%(1) Extended indexing operators ocaml/ocaml#1064

4.04+

4.03+

4.02+

  • Shorten syntax for functor signatures: "functor (M1:S1) (M2:S2) .. -> .." ocaml/ocaml@9e410c0

@emillon
Copy link
Collaborator

emillon commented Aug 4, 2021

A related issue is how automatic we want punning to happen vs preserving concrete syntax. For example, ocamlformat is always formatting{x = x} as {x} (that's a 3.12+ shortcut) or ~x:x as ~x, but for let-punning we always preserve the syntax.

I don't think there's any advantage to preserving concrete syntax for ~x:x, but I wonder if ocamlformat should be auto-punning lets when the target version supports it.

@gpetiot
Copy link
Collaborator

gpetiot commented Aug 4, 2021

I would be in favor of always using the last available syntax according to the target version (since there is a new option --ocaml-version users can select an older syntax) instead of preserving the syntax of the input.

@hhugo
Copy link
Collaborator Author

hhugo commented Aug 7, 2021

I've suggested in the past to preserve as much as possible in fmt_ast and have other pass/tool to rewrite sugars.

@gpetiot
Copy link
Collaborator

gpetiot commented Aug 1, 2022

--ocaml-version should now take care of this (if there are some bugs let's open another issue).

@gpetiot gpetiot closed this as completed Aug 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
OCaml Platform
  
To do
Development

No branches or pull requests

4 participants