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
Add parameter location information to parsetree/typedtree #12391
Add parameter location information to parsetree/typedtree #12391
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.
Overall I like this PR, we want to keep Merlin happy and adding more locations is rarely a bad move. I decided to add some decision fatigue with a bike-sheddy question on the parsetree definition, to resolve before merging. Otherwise I read the code and it is fine.
and function_param = | ||
{ pparam_loc : Location.t; | ||
pparam_desc : function_param_desc; | ||
} |
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 am not sure whether one should rather use this or something like
and function_param = function_param_desc loc
which is isomorphic.
Today in the parsetree codebase:
- We only use the
_desc / _loc
patterns for records that have other metadata fields than just locations (typically attributes, sometimes more). This suggests using ` loc . - We only use
foo loc
for "external" foos that are themselves defined in Parsetree, typicallystring
orlabel
orstring option
. This suggests using a_desc / _loc
record.
Any opinion?
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.
My opinion is that we should use a dedicated record for the second reason you gave. As another point in that direction, the two fields of loc
are loc
and txt
, and txt
does not seem like a very good name for a field that contains the parsed function parameter.
Thanks Nick. I didn't have a close look at the code but the proposed changes should effectively allow Merlin to give more relevant information when queried on the enclosing parenthesis or another token that is not part of the parameter name itself. |
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.
My bike-shedding question has been answered, I think this is good to go.
(This needs a rebase apparently?) |
ff1d647
to
694ed0a
Compare
All rebased. |
694ed0a
to
93e918d
Compare
I rebased to resolve a small merge conflict with #12428. |
(cc @panglesd) |
Thanks @ncik-roberts, and apologies for missing the merge window last time. |
Thanks @gasche for the ping! I opened ocaml-ppx/ppxlib#451 two days ago when discovering #12044 and #12236, but I keep missing parsetree changes PRs until after they are merged... On #12236, when writing the migration functions, I indeed noticed that some locations were missing. I will update my PR with this one to check if the migrations can now be written successfully. If the new parsetree does not include at least all the information for a downgrade migration, using ppxlib with an old version of OCaml will mean working with a parsetree where some informations have been lost... By the way, I liked the |
The lack of label was a lapse on my side, I have fixed it, but this sounds like a task well-suited for a bot. |
@panglesd would you like to contribute some form of automation that enforces a label on PRs that modify parsetree.mli? One way I personally know how to do it is to reuse the logic in the "typo" CI check that looks for Changes modifications, and can be disabled by using the no-changes-related label. (The UI if we do this would be: if people forget to add the label, they get a CI failure. It is more manual than an entirely automated labelling, but better than what we have today.) |
Sure! Thanks for the idea, I think with the typo example I should be able to do it. (Also, that's on github's size but I would love to be able to "watch" a specific label, but that seems to not be possible...) |
Tests from: - ocaml/ocaml#12236 (and the corresponding updates to outputs found in ocaml/ocaml#12386 and ocaml/ocaml#12391) - ocaml/ocaml#12496 (not merged)
Tests from: - ocaml/ocaml#12236 (and the corresponding updates to outputs found in ocaml/ocaml#12386 and ocaml/ocaml#12391) - ocaml/ocaml#12496 (not merged)
Tests from: - ocaml/ocaml#12236 (and the corresponding updates to outputs found in ocaml/ocaml#12386 and ocaml/ocaml#12391) - ocaml/ocaml#12496 (not merged)
Tests from: - ocaml/ocaml#12236 (and the corresponding updates to outputs found in ocaml/ocaml#12386 and ocaml/ocaml#12391) - ocaml/ocaml#12496 (not merged)
Tests from: - ocaml/ocaml#12236 (and the corresponding updates to outputs found in ocaml/ocaml#12386 and ocaml/ocaml#12391) - ocaml/ocaml#12496 (not merged)
Tests from: - ocaml/ocaml#12236 (and the corresponding updates to outputs found in ocaml/ocaml#12386 and ocaml/ocaml#12391) - ocaml/ocaml#12496 (not merged)
Tests from: - ocaml/ocaml#12236 (and the corresponding updates to outputs found in ocaml/ocaml#12386 and ocaml/ocaml#12391) - ocaml/ocaml#12496 (not merged)
Tests from: - ocaml/ocaml#12236 (and the corresponding updates to outputs found in ocaml/ocaml#12386 and ocaml/ocaml#12391) - ocaml/ocaml#12496 (not merged)
Tests from: - ocaml/ocaml#12236 (and the corresponding updates to outputs found in ocaml/ocaml#12386 and ocaml/ocaml#12391) - ocaml/ocaml#12496 (not merged)
Tests from: - ocaml/ocaml#12236 (and the corresponding updates to outputs found in ocaml/ocaml#12386 and ocaml/ocaml#12391) - ocaml/ocaml#12496 (not merged)
* Newtypes * Constraint/coercion * Add map_half_typed_cases * Implement type-checking/translation This also promotes tests whose output changes. * Add upstream tests Tests from: - ocaml/ocaml#12236 (and the corresponding updates to outputs found in ocaml/ocaml#12386 and ocaml/ocaml#12391) - ocaml/ocaml#12496 (not merged) * Fix ocamldoc * Update chamelon minimizer * Respond to requested changes to minimizer * update new test brought in from rebase * Fix bug in chunking code * `make bootstrap` * Add Ast_invariant check * Fix type-directed disambiguation of optional arg defaults * Minor comments from review * Run syntactic-arity test, update output, and fix printing bug * Remove unnecessary call to escape * Backport changes from upstream to comparative alloc tests * Avoid the confusing [Split_function_ty] module * Comment [split_function_ty] better. * [contains_gadt] as variant instead of bool * Calculate is_final_val_param on the fly rather than precomputing indexes * Note suboptimality * Get typecore typechecking * Finish resolving merge conflicts and run tests * make bootstrap * Add iteration on / mapping over locations and attributes * Reduce diff and fix typo in comment: * promote change to zero-alloc arg structure * Undo unintentional formatting changes to chamelon * Fix minimizer * Minimize diff * Fix bug with local-returning method * Fix regression where polymorphic parameters weren't allowed to be used in same parameter list as GADTs * Fix merge conflicts and make bootstrap * Apply expected diff to zero-alloc test changed in this PR
As a follow-up to #12236, this PR adds parameter locations to the parsetree/typedtree for merlin's benefit. I discussed this change with @voodoos, who suggested this PR would be a good idea — maybe he would be a good reviewer as a merlin maintainer?
As an example:
Prior to #12236:
where
exp_loc1
is for the outerTexp_function
andexp_loc2
is for the innerTexp_function
.After #12236:
There's now just a single
Texp_function
. Notably, there's no location that identifies the tilde or the opening paren as being associated with they
param — previously this could have been obtained from the start position of theexp_loc2
location.After this PR:
(
pat_loc1
andpat_loc2
are the same as the previous example.) Now, merlin can see if the user's cursor is on any part of the parameter, including the tilde or the surrounding parens.I also take this opportunity to reverse a change in the column number indicated by a
Match_failure
exception that was introduced in #12236 and that we discussed in the comments. It seems better to avoid changing the exception's arguments if we can, and this PR makes it easy to do this.