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

Parse parameters in name qualifiers. #3988

Merged
merged 7 commits into from
May 29, 2024

Conversation

zygoloid
Copy link
Contributor

Parse the name of a declaration as a sequence of NameQualifiers -- 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.

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.
Copy link
Contributor

@jonmeow jonmeow left a 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?

toolchain/check/decl_name_stack.cpp Outdated Show resolved Hide resolved
Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
@zygoloid
Copy link
Contributor Author

zygoloid commented May 28, 2024

I'm not familiar with #3848, and I'm having trouble loading it because it has merge errors.

I believe the PR is only intending to add its p3848.md file and the rest of the changes listed there are spurious.

Does this PR indicate that leads have in effect approved the proposal?

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.

Is there some reference for what design you're trying to implement?

The main purpose of this PR of this is to support declarations of members of parameterized types:

class C(T:! type) {
  fn F();
}
fn C(T:! type).F() {}

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 :(

Comment on lines +220 to +224
// _repeated_: NameQualifier
// _external_: IdentifierName
// _optional_ _external_: ImplicitParamList
// _optional_ _external_: TuplePattern
// _declaration name_
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Comment on lines +248 to +249
// ???
// ^
Copy link
Contributor

Choose a reason for hiding this comment

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

What happened here?

Copy link
Contributor Author

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.)

Copy link
Contributor

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?

toolchain/parse/state.def Outdated Show resolved Hide resolved
Comment on lines +269 to +275
// name [ ... ] ( ... ) .
// ^
// 1. DeclNameAndParams
//
// name [ ... ] ( ... ) ...
// ^
// (state done)
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

toolchain/parse/handle_decl_name_and_params.cpp Outdated Show resolved Hide resolved
toolchain/check/handle_function.cpp Show resolved Hide resolved
@jonmeow
Copy link
Contributor

jonmeow commented May 28, 2024

I'm not familiar with #3848, and I'm having trouble loading it because it has merge errors.

I believe the PR is only intending to add its p3848.md file and the rest of the changes listed there are spurious.

Thanks -- to be sure, I really meant, it wasn't loading for me to try and find the proposal file. The link helped.

Copy link
Contributor

@jonmeow jonmeow left a 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.

zygoloid and others added 2 commits May 28, 2024 15:36
Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
@zygoloid zygoloid added this pull request to the merge queue May 28, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 29, 2024
@zygoloid zygoloid added this pull request to the merge queue May 29, 2024
Merged via the queue into carbon-language:trunk with commit 28170c7 May 29, 2024
7 checks passed
@zygoloid zygoloid deleted the toolchain-generic-members branch May 29, 2024 00:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants