-
Notifications
You must be signed in to change notification settings - Fork 29
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
implement new syntax for type declaration #68
Conversation
Thanks a lot for this PR @tatchi! From a @ejgallego, will you have time to review this? There's no rush! I'm just checking in case you were expecting me to review or similar. |
I can review this, but of course any help would be very welcome! |
While I get cycles to look at this, adding a CHANGES entry would help @tatchi |
I added a change entry. We should probably also adapt the examples in the readme. What syntax do you want to emphasize? ` |
What would be the plan for this, should we start a 2.0 branch? If so, should we allow ppx_import 1.x to be coinstallable with 2.x ? |
5f93803
to
546d799
Compare
Hey, I forgot to mention but I rebased on top of master branch now that #69 is merged.
I'm not the one who can decide that, but IMO it would make sense yes.
I have no idea 😅 cc @pitag-ha do you have any thoughts? |
Thanks @tatchi , no idea either on what would be the best path for the 2.0 branch, I cc @gasche and @kit-ty-kate in case they'd like to weight in. |
Sorry for the very long time without answering!
Yes, I agree.
My opinion on this is that |
@ejgallego, that's a good question, and I'm probably not the right one to answer this. My naive way of seeing this is that it's both simpler and better if they're not co-installable. Better because that way the ecosystem is likely going to switch faster to 2.x once the first packages have started doing so. |
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.
(I'm commenting this as a ppxlib maintainer)
Looks good!
My comments in code summed up here are:
- A test for
[%%import type t = Location.t]
(without the:
) should be added - A suggestion for supporting
type%import t = Location.t and t2 = Location.t2
- An unrelated suggestion for error reporting!
I also have another remark. @pitag-ha mentioned the improvement in performance, due to not having to do another pass.
Unfortunately, since ppx_import
has to be run as a staged_pps
, its pass won't be merged with other ppx (apart from the staged ones)...
Finally, the README should be modified, but I understand this modification cannot be merged until the new version is released (or, in a 2.0 branch). In this README, I think it should be emphasized that the [@@deriving]
attribute should be put inside the [%%import]
!
Location.raise_errorf ~loc | ||
"[%%import] cannot import a functor application %s" | ||
(string_of_lid lid) |
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.
Again, this comment is not really related to the PR, but it is a bad practice to raise errors with ppxlib, as it prevents other rewriters to work and more importantly it prevents merlin to work...
Instead, errors should be embedded. I have written a section in the ppxlib manual about his here, which includes a guide for migrating from raising to embedding.
I understand that this should most certainly be part of another PR!
Oh, right! |
Thanks for the careful review @panglesd 🙏
I adapted one of the tests to this syntax, and also one with
Thanks, that definitely makes sense and seems easy to support 😁. I made the changes in 19b230e
Interesting, I'll read the doc and see if I can avoid raising errors (that will be for another PR) |
Thanks for all the work folks, so I guess it is time to create a 1.x branch and start thinking about merging this in master. I agree that having a 2.0 release with the same package name is simpler, however the opam repos would need a pretty large patch to introduce a Is this the standard operating procedure? |
yes, it is totally normal and should be merged rather quickly. In this case you can even use |
Thanks for the feedback @kit-ty-kate ! So I'm happy to go ahead with that then, @tatchi what's the status of this PR from your part? |
I should have addressed all the points @panglesd mentioned in #68 (review). Except for the improvement of the errors for which I opened a separate draft PR #73 There's also the README that needs to be adapted, but I believe we can do it in a separate PR too. |
Great! I think then this is ready to go, I'll do a last review pass and some internal testing ASAP. |
(* or *) | ||
type%import loc = Location.t | ||
``` | ||
|
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.
Would it be possible to explain how the other parts of the syntax work? In particular the with foo := bar
alias.
Maybe it is better just to update the readme in this PR too? Indeed, it could be a good idea to keep the documentation of the code in sync.
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.
LGTM, thanks a lot!
I am not sure however if we should merge this PR without an update to the README; personally I'd prefer to keep the doc in sync at all times.
I will proceed to setup the right branches and opam repository constraints , then merge this PR.
@@ -35,7 +35,7 @@ Syntax | |||
For example: | |||
|
|||
``` ocaml | |||
# type loc = [%import: Location.t];; | |||
# type%import loc = Location.t;; | |||
type loc = Location.t = { loc_start : Lexing.position; loc_end : Lexing.position; loc_ghost : bool; } | |||
# module type Hashable = [%import: (module Hashtbl.HashedType)];; |
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.
As I mentioned in #68 (comment), that would be nice to change the syntax of module type declaration too.
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.
Happy to open a follow-up PR to address that :)
I updated the readme with the new syntax. Note that the module type declaration syntax hasn't been modified (because it's already written as a context-free rule). IMO, it would make sense to update it to |
Yes! If you think it is a good idea to keep track of this, please open an issue and assign the 2.0 milestone to it. |
Thanks a lot for all the work, I've created the |
This is my attempt at implementing the new syntax as proposed in #62.
It only changes the
type declaration
and not themodule type declaration
as the latter is already defined as a regular context-free rule. However, and for consistency purposes, I think that it would make sense to also change the syntax of themodule type declaration
. Somodule type Hashable = [%import: (module Hashtbl.HashedType)]
would become
[%%import: module type Hashable = Hashtbl.HashedType]
ormodule type%import Hashable = Hashtbl.HashedType
I've some local changes that partially address that but if you agree, I would prefer to address that in a separate PR as it seems trickier/requires more changes to the actual implementation.