-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Parse parameters in name qualifiers. #3988
Parse parameters in name qualifiers. #3988
Conversation
Parse the name of a declaration as a sequence of name qualifiers -- which have a name, possibly parameters, and a trailing period -- followed by a name and possibly parameters. Cases like namespaces that can't actually have parameters are now diagnosed in check instead of in parse.
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 not familiar with #3848, and I'm having trouble loading it because it has merge errors. Does this PR indicate that leads have in effect approved the proposal? Is there some reference for what design you're trying to implement?
Co-authored-by: Jon Ross-Perkins <[email protected]>
I believe the PR is only intending to add its p3848.md file and the rest of the changes listed there are spurious.
We've not approved the proposal but we have consensus on the main points (including #3860, which is directly relevant here). But even without #3848, I think it'd still make sense to use the same parse rules (including parameters) for all names, and do any declaration-kind-specific checking in check. The main impact that #3848 has here is that this PR emits a TODO error for parameterless functions, rather than adding a proper diagnostic in check, because under #3848 they will be valid.
The main purpose of this PR of this is to support declarations of members of parameterized types:
The most recent / specific proposal on that is #3763. I think this syntax has been part of the intended design for generics for a while, but we don't seem to have any examples of this in /docs/design yet :( |
// _repeated_: NameQualifier | ||
// _external_: IdentifierName | ||
// _optional_ _external_: ImplicitParamList | ||
// _optional_ _external_: TuplePattern | ||
// _declaration name_ |
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.
This comment is unclear to me: it offers a tree structure that, as far as I can tell, does not exist. Had you considered a non-tree-like representation?
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.
How would you like this to be presented?
Alternatively: how would you feel about removing all of these structure comments now that we have typed_nodes.h
that describes the structure?
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.
Removing all these comments seems fair.
// ??? | ||
// ^ |
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.
What happened here?
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.
This is trying to say: if we're in the DeclNameAndParams
state, and the first token isn't a name, that's an error and we're done. (We don't check there's a name next before pushing the state.)
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.
Maybe this comment could be made clearer?
// name [ ... ] ( ... ) . | ||
// ^ | ||
// 1. DeclNameAndParams | ||
// | ||
// name [ ... ] ( ... ) ... | ||
// ^ | ||
// (state done) |
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 confused, how are these two inputs different? The .
versus ...
looks like a typo.
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 first rule says: if the next token is a .
, then consume it (because it's underlined), and continue in state DeclNameAndParams
.
The second rule says: if the next token is anything else (per the comment at the start of the file: "...
indicates a sequence of tokens handled by some other state"), then consume nothing and we're done.
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.
Okay, but maybe the comment could be clearer? Maybe this is a problem with using ...
without any extra annotation, it makes .
look like a typo.
Thanks -- to be sure, I really meant, it wasn't loading for me to try and find the proposal file. The link helped. |
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, although with some hesitance around bracketing.
Co-authored-by: Jon Ross-Perkins <[email protected]>
Parse the name of a declaration as a sequence of
NameQualifier
s -- which have a name, possibly parameters, and a trailing period -- followed by a name and possibly parameters. This prepares us for parsing declarations of members of generic classes and similar cases, but actually supporting such member redeclarations is left to a future change.We previously required functions to have parameters, but no longer do, following the direction of #3848. Cases like namespaces that can't actually have parameters are now diagnosed in check instead of in parse.