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
Get extension slot #273
Get extension slot #273
Conversation
If we go this way, I would argue in favor of a new dedicated type to represent extension slot (e.g. As for the choice of the syntax: I'm not very fond of the use of the |
I agree with the proposed changes. I didn't do it initially to avoid breaking the API but it's better to have a specific type indeed. I'll update the patch. |
I'm in favor of accepting this PR, but I'd like to get others' opinion on the use of an extension node for something actually interpreted by the type-checker. Should we rather use some new ad hoc syntax? A minor technical glitch is that since ocamldep does not look inside extension nodes, it won't report a dependency created purely by this new form. An alternative way could be to rely on the existing Obj.extension_slot function, which would be implemented as a primitive with some custom behavior in the code generator to detect when the argument has a known head constructor, so that one could write |
Personally I'm fine with using extension points for things that are more expert details of the language. It avoids introducing keywords while still making important features available. But if someone comes up with a combination of keywords that make sense I have nothing against it.
Good point, I didn't thought about it. Although I think that if we accept that the compiler interprets
I prefer
|
I would suggest to add a constructor for this in the parsetree (which would be parsed as an extension point, and reprinted as such). ocamldep (and other tools) works on the parsetree, so that would automatically handle this. |
Xavier would like us to find a better name than "extension slot" for this concept, described by Leo and Mark in stereo as "the thing that gets allocated when we declare a new extension constructor". If we have a better name, this can go in trunk. (Before mid-december would be important, as after that we will have the feature freeze for 4.03) (Of course I think it is fine to keep |
IIUC, this "extension slot" is extremely similar to an object ID, so I'd propose "extension ID" or "constructor ID". |
Would "extension constructor id" be too verbose? (Possibly abbreviated extcon_id?) ( @damiendoligez (alone) is going to like this next suggestion: if we use excon_id (please ignore the dubious accidental pun) we get to not specify whether it is an "extension constructor" or an "exception constructor" ) |
I think it's fine to be verbose for such (I assume) rarely used features. I dislike |
One case where this can be used a lot is when one wants to build values of an open type from C as all constructors have to be registered using this. That said I prefer an explicit name and I'm fine with I just have one reservation against using On the other hand the manual describe this value as an exception identifier (for exceptions) so maybe it's fine. We can use this API in val extension_constructor_id : _ -> extension_constructor_id
val extension_constructor_unique_integer_id : extension_constructor_id -> int
val extension_constructor_name : extension_constructor_id -> string |
Given the API you describe |
Except that a constructor is not a value, so the analogy with |
I didn't think of the conflict with |
|
We should leave all choices of function names to @mshinwell :-) More seriously, I'm fine with "extension_constructor_id". |
How about just using "extension_constructor"? The values are exactly the runtime representations of such. |
So that we can create constants of type [extension_constructor]
Rename Obj.extension_slot to Obj.extension_constructor as well
Translate [%ocaml.extension_constructor <path>] to the runtime-representation of the extension constructor denoted by <path>. This allows one to get the extension constructor without having to create a dummy value.
Make ocamldep inspect the payload of [%extension_constructor]
I updated the patch to use |
Thanks all for this exciting naming session! Naming is fun. |
* Make Var_in_binding_pos satisfy Bindable and use it instead of Bindable_variable_in_terms * Remove middle_end/flambda2/naming/bindable_variable_in_terms.ml{,i} * Rename naming/ -> nominal/ * Introduce bound_identifiers/ directory * Rename modules in bound_identifiers/ * Reformat * Update CODEOWNERS
This patch adds support for
[%extension_slot <path>]
. The compiler expands it to the slot of the extension constructor denoted by<path>
. For instance:The motivation for this request is ppx rewriters that needs to register a value associated to and extension constructor, such as what sexplib does for exceptions, and should do soon for all open types.
Currently the only way to get the extension slot is to build a dummy value, which is difficult to do in a ppx rewriter. In sexplib for instance we have a module Exn_magic that is full of
Obj.magic
to deal with that.