-
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
Track params in the parser #4777
Conversation
Just glancing, did you notice this is regressing the diagnostic location? i.e., before it pointed at parameters:
Now it points at the node after the parameters (and doesn't explain why this name can't have parameters):
Also, the PR description is empty, should it have a little more detail about what's changing (and motivation)? e.g., it looks like you're adding node kinds, maybe the PR could explain the approach? |
I should also note, #3988 had moved validation from parse to check in order to get more uniform handling. It might be good to explain how the changes there are adapted here in that context, particularly since this is changing diagnostics (are incorrectly placed parameters ever diagnosed in check after this change?) edit: something like
(also, |
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 for looking as well Jon, this is definitely a challenging review for my first auto-assignment 😆
The IdentifierNameNotBeforeParams
and IdentifierNameBeforeParams
change seems nice, in that its making check a little more straightforward. Given the convo above, I am not sure about the DeclNameAndParams part of the change though, as it seems to be limiting things a bit more than it should? Are these two tired together necessarily? That's hard for me to tell, but it might be nice to just do the IdentifierNameNotBeforeParams part of the PR independently, if that doesn't change how diagnostics are being reported, and then it'll be easier to think about the other part.
np, happy to look. Also, @geoffromer, I think you need to re-add tests of how this behaves in check. The parse tree still contains the pattern, so it needs to be correctly handled (i.e., as currently implemented, the pattern block still neds to be pushed). I'm actually not sure that this change is removing the need for any of the work being done in check. (it may be that the TODOs are incorrect as a consequence -- the logic in check may need to stay) |
Oh, I think I'm understanding part of this now. You're using the different parse node to only push a param block for when there's a pattern. Regardless, I think that still needs to be tested -- we need to make sure we aren't crashing on invalid code. |
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
IdentifierNameNotBeforeParams
andIdentifierNameBeforeParams
change seems nice, in that its making check a little more straightforward. Given the convo above, I am not sure about the DeclNameAndParams part of the change though, as it seems to be limiting things a bit more than it should? Are these two tired together necessarily? That's hard for me to tell, but it might be nice to just do the IdentifierNameNotBeforeParams part of the PR independently, if that doesn't change how diagnostics are being reported, and then it'll be easier to think about the other part.
Oh, that's a good idea. Yes, they do turn out to be separable, so I've removed the DeclNameAndParams
parts from this PR. I think that makes the other top-level comments moot, but let me know if I've missed anything.
Note that this means that this PR no longer resolves those TODOs as stated, but still removes them. I'm going to seek clarification on Discord about whether the folks who asked for them still want another PR with the parser diagnostic changes.
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.
A couple questions to help me understand
// to be followed by parameters. | ||
using IdentifierNameBeforeParams = | ||
LeafNode<NodeKind::IdentifierNameBeforeParams, Lex::IdentifierTokenIndex, | ||
NodeCategory::MemberName | NodeCategory::NonExprIdentifierName>; |
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 come IdentifierName
was not NodeCategory::NonExprIdentifierName
before, but this is now?
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.
That category didn't exist before; I introduced it in this PR in order to use AnyNonExprIdentifierName
to talk about identifiers when we don't care whether they're followed by parameters.
Ideally I would have called this category IdentifierName
, like the thing it's replacing, but my concern was that AnyIdentifierName
sounds like it would encompass IdentifierNameExpr
, so I went with a more specific name. I also considered adding NonExpr
to the names of these two node types, but I just couldn't stomach the verbosity of e.g. NonExprIdentifierNameNotBeforeParams
.
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.
FWIW, one thing to mull might be if IdentifierNameExpr
could actually be NameRef
(since it looks like it's always translated to SemIR::NameRef
), which might avoid the ambiguity of this
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.
True, although SemIR::NameRef
s can also be created from other node kinds, so they don't line up perfectly. Definitely an option to consider, though.
@@ -252,18 +253,16 @@ TEST_F(TypedNodeTest, VerifyExtractTraceClassDecl) { | |||
EXPECT_THAT(err.message(), testing::MatchesRegex( | |||
R"Trace(Aggregate [^:]*: begin | |||
Aggregate [^:]*: begin | |||
Aggregate [^:]*: begin |
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 makes this go away? (Not really sure what to make of these tests yet..)
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.
Honestly, I have no idea; I don't really understand this test. I just took the failing test result, pasted the actual output back into the code, and replaced the mangled type names with regexes.
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 think before, NameAndParams
existed as a member aggregate. It's gone without a replacement [ed: not an aggregate one anyways].
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.
Generally looks good, and as mentioned I think it makes sense to keep the param validation in check.
Just some minor questions, but these changes generally look good to me.
Co-authored-by: Jon Ross-Perkins <[email protected]>
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, this looks good!
This change splits
NodeKind::IdentifierName
into separate node kinds depending on whether the identifier is followed by parameters, and similarly splitsNameQualifier
based on whether the qualifier has parameters. This enables us to only push a pattern block when it's actually needed, rather than "defensively" pushing one when it might be needed.