-
Notifications
You must be signed in to change notification settings - Fork 89
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
Raise an error when type nonrec
is encountered
#118
Conversation
This feature has two different implementations in the AST: - in 4.02.3, it is an annotation on a type, - in >= 4.03.0 it is straight in the constructor. Note that this can break existing programs; however relying on `ppx_deriving` to do the right thing seems dangerous. Maybe an escape hatch could be added so that the recursive version is derived nonetheless. It is an intermediate solution to ocaml-ppx#116. Solving it is tricky because it would be necessary to expose this to the plugins, breaking the API. It is probably easier to do so once 4.02.3 support is dropped, since the per-type semantics are difficult to handle.
What API do you propose? |
I was thinking about extending the type of the Alternatively, maybe this could be encoded in the So far I haven't tried to make a plugin nonrec-aware, so I'm not sure about the implications on that side. |
How about adding a |
Absolutely, that would probably work too. |
@emillon poke? Any chance you could implement this? |
Hi, I had a look at this, and there are two challenges:
These do not seem to be show stoppers but this is a bit more involved than I initially thought. |
Thanks for the analysis. I would really appreciate any implementation, yours or by anyone else. |
Regarding code generation, the scheme I would propose is to turn let rec fn_foo = ...
and fn_bar = ... into let rec fn_foo_nonrec = ...
and fn_bar_nonrec = ...
let fn_foo = fn_foo_nonrec
and fn_bar = fn_bar_nonrec or a variant of this that hides the let fn_foo, fn_bar =
let rec fn_foo_nonrec = ...
and fn_bar_nonrec = ....
in fn_foo_nonrec, fn_bar_nonrec Note in particular that occurrences of It is not immediate to implement this, and I think there is no solution that is both good and backward-compatible with the previous API. (One reason in particular is that currently it is the plugin's duty to generate the whole str-item, so this has to be changed plugin-wise and we need to pass them more information as @emillon suggests). |
I agree on giving up backwards compatibility. |
This feature has two different implementations in the AST:
Note that this can break existing programs; however relying on
ppx_deriving
to do the right thing in that case seems dangerous.Maybe an escape hatch could be added so that the recursive version is derived nonetheless.
It is an intermediate solution to #116. Solving it is tricky because it would be necessary to expose this to the plugins, breaking the API. It is probably easier to do so once 4.02.3 support is dropped, since the per-type semantics are difficult to handle.
Let me know what you think about these changes.
Thanks!