-
-
Notifications
You must be signed in to change notification settings - Fork 608
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 named argument parsing support #14475
Conversation
|
Thanks for your pull request and interest in making D better, @dkorpel! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + dmd#14475" |
df84791
to
ac2b9ce
Compare
|
Are the argument pairs really expressions? |
| * | ||
| * Examples: `f(x: 3)`, `g!(T: int)` | ||
| */ | ||
| extern (C++) class NamedArgExp : Expression |
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.
It might make the semantic analysis easier if (I just though of this now) if a NamedArgExp is actually a call expression with named arguments.
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.
Currently this being part of the expression hierarchy sounds like a bad idea
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.
The argument matching needs to be done lexically and semantically so having them as expressions has some potential for wacky shit to happen
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 don't know what you mean with "argument matching needs to be done lexically and semantically".
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.
It might make the semantic analysis easier if (I just though of this now) if a
NamedArgExpis actually a call expression with named arguments.
A CallExp has an Expressions* arguments, where would I store the names of the named arguments if not in a NamedArgExp?
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.
Implementing the semantic analysis for function calls to normal functions is fairly easy, implementing the semantic analysis to anything with an overload (ESPECIALLY a template overload) is absolutely hell on earth because it tries to save references to the arguments all over the place so if you start overwriting them piecemeal as you go through them stuff just randomly breaks.
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 think about it, you overwrite the array, any error message, AST dump etc., now prints something which is complete gibberish since it's printing what the compiler lowered the arguments into not how the user wrote them down - even worse, this is actually still wrong because the arguments are supposed to be evaluated in lexical order which is now not the order in the AST.
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.
NamedArgExp as proposed here is nice, for example this can be reused for struct literals or I dont know what else in the future (theoritically).
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.
Still not an expression
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.
Indeed, you have to follow the DIP.
|
@dkorpel : My approach, when I looked at this, was to use a |
|
If it turns out we need a |
|
It should be a struct containing an array of pairs of names and expressions. It cannot be just an array because there's needs to be an opaque migration path away from the rest of the compiler using .args directly |
|
I think my branch might be on my GitHub somewhere, I've bumped into all of these problems already. We should start by splitting of the affected logic into callsem.d or something first |
Start implementing https://www.dlang.org/dips/1030 Named (template) arguments are parsed to a `NamedArgExp`, which result in a "not implemented" error during semantic analysis.
ac2b9ce
to
fecf892
Compare
@Geod24 @maxhaton I now have #14575 so you can see where this PR is going towards. Can you re-review based on that? |
|
@dkorpel I think you should just keep the DIP implementation in a single PR but with multiple, independent commits, if possible. Having the implementation scattered over multiple dependent PRs makes it hard to navigate through the changes. |
|
@dkorpel Are you still working on this? |
|
Parsing is now implemented without |
Start implementing https://www.dlang.org/dips/1030
Does not do the hard part yet, but it's a start. Named (template) arguments are parsed to a
NamedArgExp, which result in a "not implemented" error during semantic analysis.