Skip to content
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

Remove res.namedArgLoc attribute and store the location information directly into the label. #7247

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

cristianoc
Copy link
Collaborator

@cristianoc cristianoc commented Jan 14, 2025

Instead of the attribute res.namedArgLoc, there's now Asttypes.arg_label_loc to store labels with location.

@cristianoc cristianoc force-pushed the named-arg-loc-fundef branch 2 times, most recently from b5e4037 to 3fa4bdd Compare January 17, 2025 14:42
@cristianoc cristianoc force-pushed the named-arg-loc-fundef branch from 21d50c8 to be89110 Compare January 21, 2025 15:42
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Syntax Benchmarks'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.05.

Benchmark suite Current: 0e03792 Previous: e1b7fb7 Ratio
Parse RedBlackTree.res - time/run 1.357723 ms 1.2123143266666667 ms 1.12
Parse Napkinscript.res - time/run 42.30374833333333 ms 39.28006235333333 ms 1.08
Parse HeroGraphic.res - time/run 5.706828313333333 ms 5.13472718 ms 1.11

This comment was automatically generated by workflow using github-action-benchmark.

@nojaf
Copy link
Contributor

nojaf commented Jan 21, 2025

So, for my understanding, this moves the location from @res.namedArgLoc to named argument node?

@cristianoc
Copy link
Collaborator Author

So, for my understanding, this moves the location from @res.namedArgLoc to named argument node?

Yes. It's been used in different ast nodes. The current state of the PR covers a subset of them.

@cristianoc cristianoc changed the title Experiment with storing the location of function named arguments in t… Remove res.namedArgLoc attribute and store the location information directly into the label. Jan 24, 2025
@@ -1444,10 +1447,10 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
functionContextPath = ctxPath;
argumentLabel =
(match lbl with
| Nolabel ->
| Nolbl ->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to nitpick, but is there any rational for these shorter names?
As a novice to all this, I'd say it make it all a bit more obscure.
But perhaps this has a reason.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No special plan for naming at the moment.
The situation is there's an existing variant type, without locations on labels.
Here I have introduced a new variant type, with locations.
The old type still exists, as labels are used e.g. in Tarrow in types.mli, and those are generated by the compiler without reference to any source location (e.g. via unification or other reasons).

So for now I have different variant names for the new type definition, as there are quite a few places where the type is inferred by the name.
One could have 2 types with identical variants names, though that might actually add more confusion (and need to explicitly add more type annotations to indicate which type is intended).
One could try to make the payload of labelled case a type variable, to be instantiated with either string or a string plus location depending on context. I haven't tried this, not sure how that would look.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One could also use a single type and stuff a lot of Location.none when that type is not supposed to have a location. Not particularly keen on that as it becomes unclear where to expect a location and where not.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is how things look when using identical variant names for the two types: with and without locations: #7254

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One could have 2 types with identical variants names, though that might actually add more confusion (and need to explicitly add more type annotations to indicate which type is intended).

I also think this probably causes more confusion.

Another idea might be to use some prefix for disambiguation, similar to Pexp_xxx vs. Texp_xxx etc. Like Lloc_label / Lloc_nolabel vs. the existing Label / Nolabel.

@cristianoc cristianoc requested review from cknitt and zth January 24, 2025 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants