-
Notifications
You must be signed in to change notification settings - Fork 463
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
Conversation
21d50c8
to
be89110
Compare
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.
⚠️ 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: a47a3cb | Previous: e1b7fb7 | Ratio |
---|---|---|---|
Parse RedBlackTree.res - time/run |
1.3690002266666665 ms |
1.2123143266666667 ms |
1.13 |
Parse Napkinscript.res - time/run |
42.84875455333333 ms |
39.28006235333333 ms |
1.09 |
Parse HeroGraphic.res - time/run |
5.7314326866666665 ms |
5.13472718 ms |
1.12 |
This comment was automatically generated by workflow using github-action-benchmark.
So, for my understanding, this moves the location from |
Yes. It's been used in different ast nodes. The current state of the PR covers a subset of them. |
res.namedArgLoc
attribute and store the location information directly into the label.
analysis/src/CompletionFrontEnd.ml
Outdated
@@ -1444,10 +1447,10 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor | |||
functionContextPath = ctxPath; | |||
argumentLabel = | |||
(match lbl with | |||
| Nolabel -> | |||
| Nolbl -> |
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.
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.
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.
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.
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.
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.
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.
Here is how things look when using identical variant names for the two types: with and without locations: #7254
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.
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
.
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.
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. LikeLloc_label
/Lloc_nolabel
vs. the existingLabel
/Nolabel
.
I've tried putting the definition without location inside an inner module Noloc
(and leave the rest as is).
Only a few changes needed to add Noloc.
prefix..
It might be the lowest friction way, and the definition with loc can probably be renamed back to the original name hopefully with no more changes. How does it sound?
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.
Sounds great!
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.
Sounds great!
OK done, the renaming worked.
@@ -8,7 +8,7 @@ module Foo = { | |||
external component: React.componentLike<props<int, string>, React.element> = "component" | |||
} | |||
|
|||
let t = React.createElement(Foo.component, {a: 1, b: "1"}) | |||
let t = React.createElement(Foo.component, {a: 1, b: {"1"}}) |
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.
Is this test output change ok/expected?
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.
Note that this is not a printing test, but shows the result of the jsx transform. So it aims to show the effect of the transformation.
That said, the braces {
were present in the source, so it's likely that these are preserved better now because there are no res.namedArgLoc
attributes around to confuse the printing logic.
@@ -51,7 +51,7 @@ module Bar = { | |||
@res.jsxComponentProps | |||
type props = {} | |||
|
|||
let make = (_: props) => React.jsx(Foo.make, {callback: (_, _, _) => ()}) | |||
let make = (_: props) => React.jsx(Foo.make, {callback: {(_, _, _) => ()}}) |
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.
And this one?
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.
same comment as for the other ppx test
@@ -21,7 +21,7 @@ module V4C = { | |||
~props={ | |||
type_: "text", | |||
?className, | |||
ref: ?(Js.Nullable.toOption(ref)->Belt.Option.map(React.Ref.domRef)), | |||
ref: ?{Js.Nullable.toOption(ref)->Belt.Option.map(React.Ref.domRef)}, |
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.
And this one?
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.
same comment as for the other ppx test
0656d1d
to
8697ecc
Compare
This should be good to go, after checking on a real project. Though the changes should only be about formatting, as label location does not affect compilation. |
8697ecc
to
1a3869f
Compare
Also tested an LGTM. Needs a rebase now because of the CHANGELOG though. |
Preserve `isMobile={isMobile}` when it's like that in the source, instead of reformatting to `isMobile`. Do we want that?
1a3869f
to
a47a3cb
Compare
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.
Thanks!
Instead of the attribute
res.namedArgLoc
, there's nowAsttypes.arg_label_loc
to store labels with location.