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
Private extensible variants #1253
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing a Changes entry but apart from that looks good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a very good move. I think it was confusing to allow adding constructor to abstract types in signatures. Moreover, the proposed extension reuse an existing "impossible" form in the Parsetree, i.e. removes one invariant for a Parsetree to represent a parsable program.
I've reviewed the code and it looks ok.
Please add the new form to testsuite/tests/parsetree/source.ml (to check roundtrip between concrete and abstract syntax), and a Changelog entry.
This work needs to be merged. @lpw25, would you include a Changes entry? |
45409c5
to
c74d638
Compare
Rebased and added changes entry. Good to merge once tests pass. |
Currently, in signatures, extensible variant constructors can be declared for types of abstract kind:
This is a useful feature allowing constructors to be created by functors without exposing the underlying extensiblity. See the
msg.ml
example in the testsuite for a nice example of this. However, it also allows nonsensical signatures to be created:This doesn't cause any soundness issues but it does cause difficulties for the compiler. For example:
It also makes changes like #792 unnecessarily difficult. In general it is quite awkward to support having constructors available for arbitrary types.
This PR adds a notion of "private" extensible variant type:
which are visibly extensible but cannot actually be extended. This allows us to make it illegal to extend a type which is not known to be extensible:
and so avoid the various problems described above whilst still allowing the use cases previously supported with extensions to abstract types.
This change is not backwards compatible, however extending abstract types is a little used and undocumented feature so I doubt that there will be much disruption.